code: added asyncConnect

This commit is contained in:
Goffi 2011-05-26 16:49:47 +02:00
commit 05987404cc

View file

@ -112,6 +112,7 @@ class SAT(service.Service):
self.bridge.register("deleteProfile", self.memory.deleteProfile)
self.bridge.register("registerNewAccount", self.registerNewAccount)
self.bridge.register("connect", self.connect)
self.bridge.register("asyncConnect", self.asyncConnect)
self.bridge.register("disconnect", self.disconnect)
self.bridge.register("getContacts", self.memory.getContacts)
self.bridge.register("getPresenceStatus", self.memory.getPresenceStatus)
@ -181,8 +182,16 @@ class SAT(service.Service):
self.plugins[import_name].is_handler = False
#TODO: test xmppclient presence and register handler parent
def connect(self, profile_key = '@DEFAULT@'):
"""Connect to jabber server"""
self.asyncConnect(profile_key)
def asyncConnect(self, profile_key = '@DEFAULT@', callback=None, errback=None):
"""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:
@ -191,12 +200,17 @@ class SAT(service.Service):
if (self.isConnected(profile)):
info(_("already connected !"))
if callback:
callback()
return
current = self.profiles[profile] = xmpp.SatXMPPClient(self, profile,
jid.JID(self.memory.getParamA("JabberID", "Connection", profile_key = profile), profile),
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)
@ -220,7 +234,7 @@ class SAT(service.Service):
plugin[1].getHandler(profile).setHandlerParent(current)
current.startService()
def disconnect(self, profile_key='@DEFAULT@'):
"""disconnect from jabber server"""
if (not self.isConnected(profile_key)):