tags:

views:

18

answers:

0

I need to create a dbus object in python with method names that are decided at runtime.

The code I've tried is basically this:

import dbus
import dbus.service
from dbus.mainloop.glib import DBusGMainLoop
import gobject

DBusGMainLoop(set_as_default=True)
gobject.threads_init()

class greg(dbus.service.Object):
        def __init__(self):
                dbus.service.Object.__init__(self, bus, "/greg")

        @dbus.service.method(
                dbus_interface="com.blah.blah",
                in_signature="",
                out_signature="")
        def dance(self):
                print "*busts a move*"

def func(self):
    pass
func = dbus.service.method(
        dbus_interface="com.blah.blah",
        in_signature="",
        out_signature="")(func)
setattr(greg, "do_nothing", func)

bus = dbus.SystemBus()
busname = dbus.service.BusName("com.blah.blah", bus)
obj = greg()
loop = gobject.MainLoop()
loop.run()

In this case the function 'dance' is available on the interface but the function 'do_nothing' is not. I don't understand why? Is there a way to do what I'm trying to achieve?