# HG changeset patch # User Goffi # Date 1298242783 -3600 # Node ID e044d1dc37d1c0da960ba913bdfc2e191660668e # Parent 15c8916317d0d8fb0e070f5b185c0b901a9e74d4 dbus bridge: asynchrone methods management diff -r 15c8916317d0 -r e044d1dc37d1 src/bridge/bridge_constructor/dbus_core_template.py --- a/src/bridge/bridge_constructor/dbus_core_template.py Sun Feb 20 17:21:03 2011 +0100 +++ b/src/bridge/bridge_constructor/dbus_core_template.py Sun Feb 20 23:59:43 2011 +0100 @@ -48,18 +48,18 @@ ##METHODS_PART## - def __attribute_string(self, in_sign): + def __attributes(self, in_sign): """Return arguments to user given a in_sign @param in_sign: in_sign in the short form (using s,a,i,b etc) @return: list of arguments that correspond to a in_sign (e.g.: "sss" return "arg1, arg2, arg3")""" i=0 idx=0 - attr_string="" + attr=[] while i','exec') exec (code) method = locals()[name] + async_callbacks = ('callback', 'errback') if async else None setattr(DbusObject, name, dbus.service.method( - const_INT_PREFIX+int_suffix, in_signature=in_sign, out_signature=out_sign)(method)) + const_INT_PREFIX+int_suffix, in_signature=in_sign, out_signature=out_sign, + async_callbacks=async_callbacks)(method)) function = getattr(self, name) func_table = self._dbus_class_table[self.__class__.__module__ + '.' + self.__class__.__name__][function._dbus_interface] func_table[function.__name__] = function #Needed for introspection def addSignal(self, name, int_suffix, signature, doc={}): """Dynamically add a signal to Dbus Bridge""" - #FIXME: Better way ??? - attributes = self.__attribute_string(signature) + attributes = ', '.join(self.__attributes(signature)) code = compile ('def '+name+' (self,'+attributes+'): debug ("'+name+' signal")', '','exec') exec (code) @@ -127,13 +132,13 @@ debug("registering DBus bridge method [%s]", name) self.dbus_bridge.register(name, callback) - def addMethod(self, name, int_suffix, in_sign, out_sign, method, doc={}): + def addMethod(self, name, int_suffix, in_sign, out_sign, method, async=False, doc={}): """Dynamically add a method to Dbus Bridge""" print ("Adding method [%s] to DBus bridge" % name) - self.dbus_bridge.addMethod(name, int_suffix, in_sign, out_sign) + self.dbus_bridge.addMethod(name, int_suffix, in_sign, out_sign, async, doc) self.register(name, method) def addSignal(self, name, int_suffix, signature, doc={}): - self.dbus_bridge.addSignal(name, int_suffix, signature) + self.dbus_bridge.addSignal(name, int_suffix, signature, doc) setattr(DBusBridge, name, getattr(self.dbus_bridge, name))