comparison src/bridge/DBus.py @ 284:c25371424090

dbus bridge: fixed introspection for dynamically added methods and signals
author Goffi <goffi@goffi.org>
date Fri, 04 Feb 2011 00:13:41 +0100
parents c1ad04586edf
children 15c8916317d0
comparison
equal deleted inserted replaced
283:68cd30d982a5 284:c25371424090
340 code = compile ('def '+name+' (self,'+attributes+'): return self.cb["'+name+'"]('+attributes+')', '<DBus bridge>','exec') 340 code = compile ('def '+name+' (self,'+attributes+'): return self.cb["'+name+'"]('+attributes+')', '<DBus bridge>','exec')
341 exec (code) 341 exec (code)
342 method = locals()[name] 342 method = locals()[name]
343 setattr(DbusObject, name, dbus.service.method( 343 setattr(DbusObject, name, dbus.service.method(
344 const_INT_PREFIX+int_suffix, in_signature=in_sign, out_signature=out_sign)(method)) 344 const_INT_PREFIX+int_suffix, in_signature=in_sign, out_signature=out_sign)(method))
345 function = getattr(self, name)
346 func_table = self._dbus_class_table[self.__class__.__module__ + '.' + self.__class__.__name__][function._dbus_interface]
347 func_table[function.__name__] = function #Needed for introspection
345 348
346 def addSignal(self, name, int_suffix, signature): 349 def addSignal(self, name, int_suffix, signature):
347 """Dynamically add a signal to Dbus Bridge""" 350 """Dynamically add a signal to Dbus Bridge"""
348 #FIXME: Better way ??? 351 #FIXME: Better way ???
349 attributes = self.__attribute_string(signature) 352 attributes = self.__attribute_string(signature)
351 code = compile ('def '+name+' (self,'+attributes+'): debug ("'+name+' signal")', '<DBus bridge>','exec') 354 code = compile ('def '+name+' (self,'+attributes+'): debug ("'+name+' signal")', '<DBus bridge>','exec')
352 exec (code) 355 exec (code)
353 signal = locals()[name] 356 signal = locals()[name]
354 setattr(DbusObject, name, dbus.service.signal( 357 setattr(DbusObject, name, dbus.service.signal(
355 const_INT_PREFIX+int_suffix, signature=signature)(signal)) 358 const_INT_PREFIX+int_suffix, signature=signature)(signal))
359 function = getattr(self, name)
360 func_table = self._dbus_class_table[self.__class__.__module__ + '.' + self.__class__.__name__][function._dbus_interface]
361 func_table[function.__name__] = function #Needed for introspection
356 362
357 class DBusBridge(Bridge): 363 class DBusBridge(Bridge):
358 def __init__(self): 364 def __init__(self):
359 dbus.mainloop.glib.DBusGMainLoop(set_as_default=True) 365 dbus.mainloop.glib.DBusGMainLoop(set_as_default=True)
360 Bridge.__init__(self) 366 Bridge.__init__(self)