[patch] [python] Allow binding a service to the default (unique)
name
Wladimir van der Laan
laanwj at gmail.com
Mon Nov 27 07:53:49 PST 2006
Oops, seems my gmail messed up my last message, though the patch got
through my description didn't show up:
This simple patch allows binding a service on the default name,
instead of requesting and owning a name from the bus. This allows for
semi-anonymous sending of signals, in my case, I'm broadcasting
signals from a web interface built with apache and mod_python. As this
spans multiple processes which only exist temporarily I cannot
register a single service name.
A simple example of usage:
----------------------------------------------------------------------------------------------------------
# Sender
import gobject
import dbus
import dbus.service
import dbus.glib
class HelloWorldObject(dbus.service.Object):
def __init__(self, bus_name, object_path='/org/angeltech/Test'):
dbus.service.Object.__init__(self, bus_name, object_path)
@dbus.service.signal ('org.angeltech.TestInterface')
def hello_signal(self, message):
pass
bus = dbus.SessionBus()
bus_name = dbus.service.BusName(bus=bus)
object = HelloWorldObject(bus_name)
object.hello_signal ('I sent a hello signal')
----------------------------------------------------------------------------------------------------------
# Receiver (can be many)
import gobject
import dbus
import dbus.glib
def device_added_callback(udi):
print 'Message received %s' % (udi)
bus = dbus.SessionBus()
bus.add_signal_receiver (device_added_callback,
signal_name='hello_signal',
dbus_interface='org.angeltech.TestInterface',
path='/org/angeltech/Test')
mainloop = gobject.MainLoop()
mainloop.run()
--
Wladimir
Ogre3D Team (http://www.ogre3d.org)
More information about the dbus
mailing list