Return an object from a method
Luigi Paioro
luigi at lambrate.inaf.it
Thu May 11 04:42:14 PDT 2006
Hi,
I'm new to DBUS, and I would like to have an information about what
kind of data types a DBUS object method cans return. In particular, is
it possible to get an object instance as returned value from a DBUS
object method call?
Suppose I have a Python object put on the bus:
#!/usr/bin/python
import gobject
import dbus
import dbus.service
if getattr(dbus, 'version', (0,0,0)) >= (0,41,0):
import dbus.glib
class HelloWorldObject(dbus.service.Object):
def __init__(self, bus_name,
object_path='/org/freedesktop/HelloWorldObject'):
dbus.service.Object.__init__(self, bus_name, object_path)
@dbus.service.method('org.freedesktop.HelloWorldIFace')
def hello(self):
return 'Hello from the HelloWorldObject'
@dbus.service.signal('org.freedesktop.HelloWorldIFace')
def HelloSignal(self, message):
pass
session_bus = dbus.SessionBus()
bus_name = dbus.service.BusName('org.freedesktop.HelloWorld',
bus=session_bus)
object = HelloWorldObject(bus_name)
mainloop = gobject.MainLoop()
mainloop.run()
Can I call the HelloSignal signal with an object instance as argument?
Example:
#!/usr/bin/python
import dbus
import gobject
class Msg:
def __init__(self, message=None):
self.message = message
def print_message(message):
print msg.message
bus = dbus.SessionBus()
proxy_obj = bus.get_object('org.freedesktop.HelloWorld',
'/org/freedesktop/HelloWorldObject')
iface = dbus.Interface(proxy_obj, 'org.freedesktop.HelloWorldIFace')
iface.connect_to_signal("HelloSignal", print_message)
msg = Msg("hello")
iface.HelloSignal(msg)
mainloop = gobject.MainLoop()
mainloop.run()
I've tried this code but it doesn't run, so I think that I cannon. But
does it exist a work around to have something like that?
Thank you in advance.
Luigi
More information about the dbus
mailing list