diff src/core/sat_main.py @ 423:6c20c76abdcc

backend: - bridge async D-Bus method now automatically manage callback and errback, we just have to return a deferred - getParams, getParamsForCategory and getParamsUI are now asynchronous primitivus: management of asynchronous getParamsUI
author Goffi <goffi@goffi.org>
date Mon, 07 Nov 2011 00:09:22 +0100
parents acd908528ef7
children e4e9187e3b5b
line wrap: on
line diff
--- a/src/core/sat_main.py	Sun Nov 06 15:19:51 2011 +0100
+++ b/src/core/sat_main.py	Mon Nov 07 00:09:22 2011 +0100
@@ -205,22 +205,19 @@
         """Connect to jabber server"""
         self.asyncConnect(profile_key)
     
-    def asyncConnect(self, profile_key = '@DEFAULT@', callback=None, errback=None):
+    def asyncConnect(self, profile_key = '@DEFAULT@'):
         """Connect to jabber server with asynchronous reply
         @param profile_key: %(doc_profile)s
-        @param callback: called when the profile is connected
-        @param errback: called is the connection fail"""
+        """
 
         profile = self.memory.getProfileName(profile_key)
         if not profile:
             error (_('Trying to connect a non-exsitant profile'))
-            return
+            return defer.fail()
         
         if (self.isConnected(profile)):
             info(_("already connected !"))
-            if callback:
-                callback()
-            return
+            return defer.succeed("None")
 
         def afterMemoryInit(ignore):
             """This part must be called when we have loaded individual parameters from memory"""
@@ -229,9 +226,6 @@
                 self.memory.getParamA("Password", "Connection", profile_key = profile),
                 self.memory.getParamA("Server", "Connection", profile_key = profile), 5222)
 
-            if callback and errback:
-                current.getConnectionDeferred().addCallbacks(lambda x:callback(), errback)
-
             current.messageProt = xmpp.SatMessageProtocol(self)
             current.messageProt.setHandlerParent(current)
             
@@ -256,9 +250,9 @@
 
             current.startService()
 
-        params_defer = self.memory.loadIndividualParams(profile).addCallback(afterMemoryInit)
-        if errback:
-            params_defer.addErrback(errback)
+            return current.getConnectionDeferred()
+
+        return self.memory.loadIndividualParams(profile).addCallback(afterMemoryInit)
 
     def disconnect(self, profile_key):
         """disconnect from jabber server"""