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
This commit is contained in:
parent
8ac5759a5f
commit
19232e8a6b
1 changed files with 250 additions and 166 deletions
|
|
@ -205,22 +205,19 @@ class SAT(service.Service):
|
|||
"""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 @@ class SAT(service.Service):
|
|||
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 @@ class SAT(service.Service):
|
|||
|
||||
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"""
|
||||
|
|
|
|||
Loading…
Reference in a new issue