changeset 300:233e6fce0b49

DBus bridge: using new generated bridge
author Goffi <goffi@goffi.org>
date Mon, 21 Feb 2011 01:35:39 +0100
parents e044d1dc37d1
children e33b3a777f10
files src/bridge/DBus.py
diffstat 1 files changed, 18 insertions(+), 13 deletions(-) [+]
line wrap: on
line diff
--- a/src/bridge/DBus.py	Sun Feb 20 23:59:43 2011 +0100
+++ b/src/bridge/DBus.py	Mon Feb 21 01:35:39 2011 +0100
@@ -296,18 +296,18 @@
         return self.cb["subscription"](unicode(sub_type), unicode(entity), unicode(profile_key))
 
     
-    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<len(in_sign):
             if in_sign[i] not in ['b','y','n','i','x','q','u','t','d','s','a']:
                 raise ParseError("Unmanaged attribute type [%c]" % in_sign[i])
 
-            attr_string += ("" if idx==0 else ", ") + ("arg_%i" % idx)
+            attr.append("arg_%i" % idx)
             idx+=1
 
             if in_sign[i] == 'a':
@@ -330,26 +330,31 @@
                         if opening_count == 0:
                             break
             i+=1
-        return attr_string
+        return attr
 
-    def addMethod(self, name, int_suffix, in_sign, out_sign, doc={}):
+    def addMethod(self, name, int_suffix, in_sign, out_sign, async=False, doc={}):
         """Dynamically add a method to Dbus Bridge"""
-        #FIXME: Better way ???
-        attributes = self.__attribute_string(in_sign)
+        _attributes = self.__attributes(in_sign)
+
+        if async:
+            _attributes.extend(['callback','errback'])
+        
+        attributes = ', '.join(_attributes)
 
         code = compile ('def '+name+' (self,'+attributes+'): return self.cb["'+name+'"]('+attributes+')', '<DBus bridge>','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")', '<DBus bridge>','exec')
         exec (code)
@@ -416,12 +421,12 @@
         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))