changeset 469:db4c2b82bab6

D-Bus bridge: fixed getRoomsSubjects call + fixed dynamic addition of methods + added getLastGroupBlogs method
author Goffi <goffi@goffi.org>
date Sun, 01 Apr 2012 19:45:35 +0200
parents c97640c90a94
children 5c916b99d0f6
files src/bridge/DBus.py src/bridge/bridge_constructor/dbus_core_template.py src/bridge/bridge_constructor/dbus_frontend_template.py
diffstat 3 files changed, 27 insertions(+), 23 deletions(-) [+]
line wrap: on
line diff
--- a/src/bridge/DBus.py	Fri Mar 30 09:23:23 2012 +0200
+++ b/src/bridge/DBus.py	Sun Apr 01 19:45:35 2012 +0200
@@ -431,27 +431,29 @@
         """Dynamically add a method to Dbus Bridge"""
         inspect_args = inspect.getargspec(method)
 
-        _attributes = inspect_args.args
+        _arguments = inspect_args.args
         _defaults = list(inspect_args.defaults or [])
         
         if inspect.ismethod(method):
             #if we have a method, we don't want the first argument (usually 'self')
-            del(_attributes[0])
+            del(_arguments[0])
 
+        #first arguments are for the _callback method
+        arguments_callback = ', '.join([repr(name)] + ((_arguments + ['callback=callback','errback=errback']) if async else _arguments))
+        
         if async:
-            _attributes.extend(['callback','errback'])
-            _defaults.extend(['callback', 'errback'])
+            _arguments.extend(['callback','errback'])
+            _defaults.extend([None, None])
         
-        attributes = ', '.join(_attributes)
         
         #now we create a second list with default values
         for i in range(1, len(_defaults)+1):
-            _attributes[-i] = "%s = %s" % (_attributes[-i], repr(_defaults[-i]))
+            _arguments[-i] = "%s = %s" % (_arguments[-i], repr(_defaults[-i]))
 
-        attributes_defaults =  ', '.join(_attributes)
+        arguments_defaults =  ', '.join(_arguments)
 
-        code = compile ('def %(name)s (self,%(attributes_defaults)s): return self.cb["%(name)s"](%(attributes)s)' %
-                        {'name':name, 'attributes_defaults':attributes_defaults, 'attributes':attributes}, '<DBus bridge>','exec')
+        code = compile ('def %(name)s (self,%(arguments_defaults)s): return self._callback(%(arguments_callback)s)' %
+                        {'name':name, 'arguments_defaults':arguments_defaults, 'arguments_callback':arguments_callback}, '<DBus bridge>','exec')
         exec (code) #FIXME: to the same thing in a cleaner way, without compile/exec
         method = locals()[name]
         async_callbacks = ('callback', 'errback') if async else None
--- a/src/bridge/bridge_constructor/dbus_core_template.py	Fri Mar 30 09:23:23 2012 +0200
+++ b/src/bridge/bridge_constructor/dbus_core_template.py	Sun Apr 01 19:45:35 2012 +0200
@@ -147,27 +147,29 @@
         """Dynamically add a method to Dbus Bridge"""
         inspect_args = inspect.getargspec(method)
 
-        _attributes = inspect_args.args
+        _arguments = inspect_args.args
         _defaults = list(inspect_args.defaults or [])
         
         if inspect.ismethod(method):
             #if we have a method, we don't want the first argument (usually 'self')
-            del(_attributes[0])
+            del(_arguments[0])
 
+        #first arguments are for the _callback method
+        arguments_callback = ', '.join([repr(name)] + ((_arguments + ['callback=callback','errback=errback']) if async else _arguments))
+        
         if async:
-            _attributes.extend(['callback','errback'])
-            _defaults.extend(['callback', 'errback'])
+            _arguments.extend(['callback','errback'])
+            _defaults.extend([None, None])
         
-        attributes = ', '.join(_attributes)
         
         #now we create a second list with default values
         for i in range(1, len(_defaults)+1):
-            _attributes[-i] = "%s = %s" % (_attributes[-i], repr(_defaults[-i]))
+            _arguments[-i] = "%s = %s" % (_arguments[-i], repr(_defaults[-i]))
 
-        attributes_defaults =  ', '.join(_attributes)
+        arguments_defaults =  ', '.join(_arguments)
 
-        code = compile ('def %(name)s (self,%(attributes_defaults)s): return self.cb["%(name)s"](%(attributes)s)' %
-                        {'name':name, 'attributes_defaults':attributes_defaults, 'attributes':attributes}, '<DBus bridge>','exec')
+        code = compile ('def %(name)s (self,%(arguments_defaults)s): return self._callback(%(arguments_callback)s)' %
+                        {'name':name, 'arguments_defaults':arguments_defaults, 'arguments_callback':arguments_callback}, '<DBus bridge>','exec')
         exec (code) #FIXME: to the same thing in a cleaner way, without compile/exec
         method = locals()[name]
         async_callbacks = ('callback', 'errback') if async else None
--- a/src/bridge/bridge_constructor/dbus_frontend_template.py	Fri Mar 30 09:23:23 2012 +0200
+++ b/src/bridge/bridge_constructor/dbus_frontend_template.py	Sun Apr 01 19:45:35 2012 +0200
@@ -63,8 +63,8 @@
     def getRoomsJoined(self, profile_key):
         return self.db_plugin_iface.getRoomsJoined(profile_key)
 
-    def getRoomsSubjectss(self, profile_key):
-        return self.db_plugin_iface.getRoomsSubjectss(profile_key)
+    def getRoomsSubjects(self, profile_key):
+        return self.db_plugin_iface.getRoomsSubjects(profile_key)
 
     def joinMUC(self, room_jid, nick, options, profile_key):
         if options == None:
@@ -136,12 +136,12 @@
     def getLastMicroblogs(self, jid, max_items, profile_key, callback=None, errback=None):
         return self.db_plugin_iface.getLastMicroblogs(jid, max_items, profile_key, reply_handler=callback, error_handler=errback)
 
-    def getMblogNodes(self, profile_key, callback=None, errback=None):
-        return self.db_plugin_iface.getMblogNodes(profile_key, reply_handler=callback, error_handler=errback)
-    
     def sendGroupBlog(self, groups, message, profile_key):
         return self.db_plugin_iface.sendGroupBlog(groups, message, profile_key)
     
+    def getLastGroupBlogs(self, jid, max_items, profile_key, callback=None, errback=None):
+        return self.db_plugin_iface.getLastGroupBlogs(jid, max_items, profile_key, reply_handler=callback, error_handler=errback)
+    
     def sendPersonalEvent(self, event_type, data, profile_key):
         return self.db_plugin_iface.sendPersonalEvent(event_type, data, profile_key)