'From etoys2.2 of 21 September 2007 [latest update: #1793] on 28 November 2007 at 4:07:11 pm'! "Change Set: DBus-Core-bf-36 Date: 28 November 2007 Author: Bert Freudenberg Name: DBus-Core-bf.36 Author: bf Time: 28 November 2007, 4:04:29 pm UUID: 8973e231-73ac-4336-bdda-86a2eb81866c Ancestors: DBus-Core-bf.35 - fix matching"! !DBusConnection methodsFor: 'matching' stamp: 'bf 11/28/2007 15:10'! addMatch: anArray "add a match. Keys include type, sender, interface, member, path, destination, arg0, arg1 etc. Only string args can be matched. E.g. #(type 'signal' sender 'org.freedesktop.DBus' interface 'org.freedesktop.DBus' member 'Foo' path '/bar/foo' destination ':452345.34') " ^ self primAddMatch: (self matchString: anArray)! ! !DBusConnection methodsFor: 'matching' stamp: 'bf 11/28/2007 15:10'! removeMatch: anArray "Remove a match added by addMatch:" ^ self primRemoveMatch: (self matchString: anArray)! ! !DBusConnection methodsFor: 'private' stamp: 'bf 11/28/2007 15:59'! matchString: anArray "Construct a dbus match string from anArray" ^String streamContents: [:strm | anArray pairsDo: [:key :value | strm position > 0 ifTrue: [strm nextPut: $,]. strm nextPutAll: key; nextPut: $=; print: value squeakToUtf8]]! ! !DBusConnection class methodsFor: 'testing' stamp: 'bf 11/28/2007 15:56'! example "this example show the general low level usage of the dbus plugin" " to start call DBusConnection example to stop the process call DBusConnection new sendMessage: (DBusMessage testMethodCall selector: 'setprocessstatus') send a signal DBusConnection new sendMessage: (DBusMessage testSignal) " | connection msg process appName | appName := 'org.squeak.dbus.example'. "connect tot session bus" connection := DBusConnection connectToSessionBus. "request unique name for squeak example at dbus" connection registerName: appName. "register a match rule to receive a certain signal" connection addMatch: #( type 'signal' interface 'org.squeak.dbus.testinterface'). "register a semaphore witch is signaled when new data arrived for the connection" connection registerSemaphore: Semaphore new. process := true. [ Transcript show: String cr, '--- Begin dbus queue processing ---'; cr. "step the connection" [process] whileTrue: [ [connection dataRemains] whileTrue: [ "read messages" msg := connection popMessage. msg ifNotNil: [Transcript show: 'Received message: ', msg asString; cr. "process message" msg isMethodCall ifTrue: [ ((msg selector = 'setprocessstatus') and: [msg hasArguments]) ifTrue: [ process := (msg arguments at: 1) value ] ifFalse: [ "answer an error" connection sendMessage: (DBusMessageError unknownMethod: msg)] ] ]. ]. process ifTrue: [connection readSemaphore wait]. ]. "release name" connection releaseName: appName. "close connection" connection close. Transcript show: '--- end ---' , String cr. ] forkAt: Processor userBackgroundPriority. " send a quit message DBusConnection new sendMessage: ((DBusMessageMethodCall destination: 'org.squeak.dbus.example' path: '/org/squeak/dbus/example' interface: 'org.squeak.dbus.test' selector: 'setprocessstatus' ) addArgument: (DBusArgument bool: false); reply: false) " ! ! DBusConnection removeSelector: #addMethodMatchForInterface:! DBusConnection removeSelector: #addSignalMatchForInterface:! DBusConnection removeSelector: #removeMethodMatchForInterface:! DBusConnection removeSelector: #removeSignalMatchForInterface:!