Return an object from a method

Luigi Paioro luigi at
Thu May 11 04:42:14 PDT 2006


   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:


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, 
         dbus.service.Object.__init__(self, bus_name, object_path)

     def hello(self):
         return 'Hello from the HelloWorldObject'

     def HelloSignal(self, message):

session_bus = dbus.SessionBus()
bus_name = dbus.service.BusName('org.freedesktop.HelloWorld', 
object = HelloWorldObject(bus_name)

mainloop = gobject.MainLoop()

Can I call the HelloSignal signal with an object instance as argument? 


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', 
iface = dbus.Interface(proxy_obj, 'org.freedesktop.HelloWorldIFace')
iface.connect_to_signal("HelloSignal", print_message)

msg = Msg("hello")

mainloop = gobject.MainLoop()

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.


More information about the dbus mailing list