diff src/bridge/DBus.py @ 337:4402ac630712

bridge: async callback managed in bridge_constructor + misc - the new flag async make the method asynchronous - new method asyncConnect (connect which return when the user is connected) - setMicroblogAccess added to DBus frontend
author Goffi <goffi@goffi.org>
date Thu, 26 May 2011 16:47:09 +0200
parents 953536246d9d
children e6047415868d
line wrap: on
line diff
--- a/src/bridge/DBus.py	Wed May 25 17:18:05 2011 +0200
+++ b/src/bridge/DBus.py	Thu May 26 16:47:09 2011 +0200
@@ -116,152 +116,188 @@
     ### methods ###    
     
     @dbus.service.method(const_INT_PREFIX+const_COMM_SUFFIX,
-                         in_signature='ss', out_signature='')
+                         in_signature='ss', out_signature='',
+                         async_callbacks=None)
     def addContact(self, entity, profile_key="@DEFAULT@"):
         return self.cb["addContact"](unicode(entity), unicode(profile_key))
 
+    @dbus.service.method(const_INT_PREFIX+const_COMM_SUFFIX,
+                         in_signature='s', out_signature='',
+                         async_callbacks=('callback', 'errback'))
+    def asyncConnect(self, profile_key="@DEFAULT@", callback=None, errback=None):
+        return self.cb["asyncConnect"](unicode(profile_key), callback, errback)
+
     @dbus.service.method(const_INT_PREFIX+const_REQ_SUFFIX,
-                         in_signature='ssss', out_signature='s')
+                         in_signature='ssss', out_signature='s',
+                         async_callbacks=None)
     def callMenu(self, category, name, menu_type, profile_key):
         return self.cb["callMenu"](unicode(category), unicode(name), unicode(menu_type), unicode(profile_key))
 
     @dbus.service.method(const_INT_PREFIX+const_REQ_SUFFIX,
-                         in_signature='sba{ss}', out_signature='')
+                         in_signature='sba{ss}', out_signature='',
+                         async_callbacks=None)
     def confirmationAnswer(self, id, accepted, data):
         return self.cb["confirmationAnswer"](unicode(id), accepted, data)
 
     @dbus.service.method(const_INT_PREFIX+const_COMM_SUFFIX,
-                         in_signature='s', out_signature='')
+                         in_signature='s', out_signature='',
+                         async_callbacks=None)
     def connect(self, profile_key="@DEFAULT@"):
         return self.cb["connect"](unicode(profile_key))
 
     @dbus.service.method(const_INT_PREFIX+const_REQ_SUFFIX,
-                         in_signature='s', out_signature='i')
+                         in_signature='s', out_signature='i',
+                         async_callbacks=None)
     def createProfile(self, profile):
         return self.cb["createProfile"](unicode(profile))
 
     @dbus.service.method(const_INT_PREFIX+const_COMM_SUFFIX,
-                         in_signature='ss', out_signature='')
+                         in_signature='ss', out_signature='',
+                         async_callbacks=None)
     def delContact(self, entity, profile_key="@DEFAULT@"):
         return self.cb["delContact"](unicode(entity), unicode(profile_key))
 
     @dbus.service.method(const_INT_PREFIX+const_REQ_SUFFIX,
-                         in_signature='s', out_signature='i')
+                         in_signature='s', out_signature='i',
+                         async_callbacks=None)
     def deleteProfile(self, profile):
         return self.cb["deleteProfile"](unicode(profile))
 
     @dbus.service.method(const_INT_PREFIX+const_COMM_SUFFIX,
-                         in_signature='s', out_signature='')
+                         in_signature='s', out_signature='',
+                         async_callbacks=None)
     def disconnect(self, profile_key="@DEFAULT@"):
         return self.cb["disconnect"](unicode(profile_key))
 
     @dbus.service.method(const_INT_PREFIX+const_COMM_SUFFIX,
-                         in_signature='s', out_signature='a(sa{ss}as)')
+                         in_signature='s', out_signature='a(sa{ss}as)',
+                         async_callbacks=None)
     def getContacts(self, profile_key="@DEFAULT@"):
         return self.cb["getContacts"](unicode(profile_key))
 
     @dbus.service.method(const_INT_PREFIX+const_COMM_SUFFIX,
-                         in_signature='ssi', out_signature='a{i(ss)}')
+                         in_signature='ssi', out_signature='a{i(ss)}',
+                         async_callbacks=None)
     def getHistory(self, from_jid, to_jid, size):
         return self.cb["getHistory"](unicode(from_jid), unicode(to_jid), size)
 
     @dbus.service.method(const_INT_PREFIX+const_REQ_SUFFIX,
-                         in_signature='sss', out_signature='s')
+                         in_signature='sss', out_signature='s',
+                         async_callbacks=None)
     def getMenuHelp(self, category, name, menu_type):
         return self.cb["getMenuHelp"](unicode(category), unicode(name), unicode(menu_type))
 
     @dbus.service.method(const_INT_PREFIX+const_REQ_SUFFIX,
-                         in_signature='', out_signature='a(sss)')
+                         in_signature='', out_signature='a(sss)',
+                         async_callbacks=None)
     def getMenus(self, ):
         return self.cb["getMenus"]()
 
     @dbus.service.method(const_INT_PREFIX+const_COMM_SUFFIX,
-                         in_signature='ssss', out_signature='s')
+                         in_signature='ssss', out_signature='s',
+                         async_callbacks=None)
     def getParamA(self, name, category, attribute="value", profile_key="@DEFAULT@"):
         return self.cb["getParamA"](unicode(name), unicode(category), unicode(attribute), unicode(profile_key))
 
     @dbus.service.method(const_INT_PREFIX+const_COMM_SUFFIX,
-                         in_signature='s', out_signature='s')
+                         in_signature='s', out_signature='s',
+                         async_callbacks=None)
     def getParams(self, profile_key="@DEFAULT@"):
         return self.cb["getParams"](unicode(profile_key))
 
     @dbus.service.method(const_INT_PREFIX+const_COMM_SUFFIX,
-                         in_signature='', out_signature='as')
+                         in_signature='', out_signature='as',
+                         async_callbacks=None)
     def getParamsCategories(self, ):
         return self.cb["getParamsCategories"]()
 
     @dbus.service.method(const_INT_PREFIX+const_COMM_SUFFIX,
-                         in_signature='ss', out_signature='s')
+                         in_signature='ss', out_signature='s',
+                         async_callbacks=None)
     def getParamsForCategory(self, category, profile_key="@DEFAULT@"):
         return self.cb["getParamsForCategory"](unicode(category), unicode(profile_key))
 
     @dbus.service.method(const_INT_PREFIX+const_COMM_SUFFIX,
-                         in_signature='s', out_signature='s')
+                         in_signature='s', out_signature='s',
+                         async_callbacks=None)
     def getParamsUI(self, profile_key="@DEFAULT@"):
         return self.cb["getParamsUI"](unicode(profile_key))
 
     @dbus.service.method(const_INT_PREFIX+const_COMM_SUFFIX,
-                         in_signature='s', out_signature='a{sa{s(sia{ss})}}')
+                         in_signature='s', out_signature='a{sa{s(sia{ss})}}',
+                         async_callbacks=None)
     def getPresenceStatus(self, profile_key="@DEFAULT@"):
         return self.cb["getPresenceStatus"](unicode(profile_key))
 
     @dbus.service.method(const_INT_PREFIX+const_REQ_SUFFIX,
-                         in_signature='s', out_signature='s')
+                         in_signature='s', out_signature='s',
+                         async_callbacks=None)
     def getProfileName(self, profile_key="@DEFAULT@"):
         return self.cb["getProfileName"](unicode(profile_key))
 
     @dbus.service.method(const_INT_PREFIX+const_REQ_SUFFIX,
-                         in_signature='', out_signature='as')
+                         in_signature='', out_signature='as',
+                         async_callbacks=None)
     def getProfilesList(self, ):
         return self.cb["getProfilesList"]()
 
     @dbus.service.method(const_INT_PREFIX+const_REQ_SUFFIX,
-                         in_signature='s', out_signature='a{ss}')
+                         in_signature='s', out_signature='a{ss}',
+                         async_callbacks=None)
     def getProgress(self, id):
         return self.cb["getProgress"](unicode(id))
 
     @dbus.service.method(const_INT_PREFIX+const_REQ_SUFFIX,
-                         in_signature='', out_signature='s')
+                         in_signature='', out_signature='s',
+                         async_callbacks=None)
     def getVersion(self, ):
         return self.cb["getVersion"]()
 
     @dbus.service.method(const_INT_PREFIX+const_COMM_SUFFIX,
-                         in_signature='s', out_signature='a{ss}')
+                         in_signature='s', out_signature='a{ss}',
+                         async_callbacks=None)
     def getWaitingSub(self, profile_key="@DEFAULT@"):
         return self.cb["getWaitingSub"](unicode(profile_key))
 
     @dbus.service.method(const_INT_PREFIX+const_COMM_SUFFIX,
-                         in_signature='s', out_signature='b')
+                         in_signature='s', out_signature='b',
+                         async_callbacks=None)
     def isConnected(self, profile_key="@DEFAULT@"):
         return self.cb["isConnected"](unicode(profile_key))
 
     @dbus.service.method(const_INT_PREFIX+const_REQ_SUFFIX,
-                         in_signature='sa{ss}s', out_signature='s')
+                         in_signature='sa{ss}s', out_signature='s',
+                         async_callbacks=None)
     def launchAction(self, action_type, data, profile_key="@DEFAULT@"):
         return self.cb["launchAction"](unicode(action_type), data, unicode(profile_key))
 
     @dbus.service.method(const_INT_PREFIX+const_COMM_SUFFIX,
-                         in_signature='ssssi', out_signature='s')
+                         in_signature='ssssi', out_signature='s',
+                         async_callbacks=None)
     def registerNewAccount(self, login, password, email, host, port=5222):
         return self.cb["registerNewAccount"](unicode(login), unicode(password), unicode(email), unicode(host), port)
 
     @dbus.service.method(const_INT_PREFIX+const_COMM_SUFFIX,
-                         in_signature='sssss', out_signature='')
+                         in_signature='sssss', out_signature='',
+                         async_callbacks=None)
     def sendMessage(self, to_jid, message, subject='', mess_type="chat", profile_key="@DEFAULT@"):
         return self.cb["sendMessage"](unicode(to_jid), unicode(message), unicode(subject), unicode(mess_type), unicode(profile_key))
 
     @dbus.service.method(const_INT_PREFIX+const_COMM_SUFFIX,
-                         in_signature='ssss', out_signature='')
+                         in_signature='ssss', out_signature='',
+                         async_callbacks=None)
     def setParam(self, name, value, category, profile_key="@DEFAULT@"):
         return self.cb["setParam"](unicode(name), unicode(value), unicode(category), unicode(profile_key))
 
     @dbus.service.method(const_INT_PREFIX+const_COMM_SUFFIX,
-                         in_signature='ssia{ss}s', out_signature='')
+                         in_signature='ssia{ss}s', out_signature='',
+                         async_callbacks=None)
     def setPresence(self, to_jid='', show='', priority=0, statuses={}, profile_key="@DEFAULT@"):
         return self.cb["setPresence"](unicode(to_jid), unicode(show), priority, statuses, unicode(profile_key))
 
     @dbus.service.method(const_INT_PREFIX+const_COMM_SUFFIX,
-                         in_signature='sss', out_signature='')
+                         in_signature='sss', out_signature='',
+                         async_callbacks=None)
     def subscription(self, sub_type, entity, profile_key="@DEFAULT@"):
         return self.cb["subscription"](unicode(sub_type), unicode(entity), unicode(profile_key))
 
@@ -326,7 +362,8 @@
         """Dynamically add a signal to Dbus Bridge"""
         attributes = ', '.join(self.__attributes(signature))
 
-        code = compile ('def '+name+' (self,'+attributes+'): debug ("'+name+' signal")', '<DBus bridge>','exec')
+        #code = compile ('def '+name+' (self,'+attributes+'): debug ("'+name+' signal")', '<DBus bridge>','exec') #XXX: the debug is too annoying with xmllog
+        code = compile ('def '+name+' (self,'+attributes+'): pass', '<DBus bridge>','exec')
         exec (code)
         signal = locals()[name]
         setattr(DbusObject, name, dbus.service.signal(