1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37
|
#!/usr/bin/env python
# Manually defining the interface and passing it to getRemoteObject()
# prevents the need for DBus object introspection. The primary
# advantage of this is that the proxy object can be successfully
# created even if the remote object does not actually exist. As signal
# registration is a function of the bus itself and not of the actual
# object, this script may be run prior launching signal_server.
#
from twisted.internet import reactor
from txdbus import client
from txdbus.interface import DBusInterface, Signal
iface = DBusInterface( 'org.example.SignalSender',
Signal('tick', 'u')
)
def onSignal( tickCount ):
print 'Got tick signal: ', tickCount
def onErr(err):
print 'Error: ', err.getErrorMessage()
d = client.connect(reactor)
d.addCallback( lambda cli: cli.getRemoteObject( 'org.example',
'/Signaller',
iface) )
d.addCallback( lambda ro: ro.notifyOnSignal( 'tick', onSignal ) )
d.addErrback( onErr )
reactor.run()
|