core, bridge, frontends: renamed asyncConnect to connect, and added options parameters (not used yet)

This commit is contained in:
Goffi 2017-02-06 22:54:43 +01:00
commit b5f1e45d4e
5 changed files with 34 additions and 29 deletions

View file

@ -264,17 +264,19 @@ errback is called with error constant as parameter:
- ProfileUnknownError: the profile name is unknown
- ConnectedProfileError: a connected profile would not be deleted
[asyncConnect]
[connect]
async=
type=method
category=core
sig_in=ss
sig_in=ssa{ss}
sig_out=b
param_0_default="@DEFAULT@"
param_1_default=''
param_2_default={}
doc=Connect a profile
doc_param_0=%(doc_profile_key)s
doc_param_1=password: the SàT profile password
doc_param_2=options: connection options
doc_return=a deferred boolean or failure:
- boolean if the profile authentication succeed:
- True if the XMPP connection was already established

View file

@ -203,12 +203,6 @@ class DbusObject(dbus.service.Object):
def addContact(self, entity_jid, profile_key="@DEFAULT@"):
return self._callback("addContact", unicode(entity_jid), unicode(profile_key))
@dbus.service.method(const_INT_PREFIX+const_CORE_SUFFIX,
in_signature='ss', out_signature='b',
async_callbacks=('callback', 'errback'))
def asyncConnect(self, profile_key="@DEFAULT@", password='', callback=None, errback=None):
return self._callback("asyncConnect", unicode(profile_key), unicode(password), callback=callback, errback=errback)
@dbus.service.method(const_INT_PREFIX+const_CORE_SUFFIX,
in_signature='ss', out_signature='',
async_callbacks=('callback', 'errback'))
@ -233,6 +227,12 @@ class DbusObject(dbus.service.Object):
def asyncGetParamsValuesFromCategory(self, category, security_limit=-1, profile_key="@DEFAULT@", callback=None, errback=None):
return self._callback("asyncGetParamsValuesFromCategory", unicode(category), security_limit, unicode(profile_key), callback=callback, errback=errback)
@dbus.service.method(const_INT_PREFIX+const_CORE_SUFFIX,
in_signature='ssa{ss}', out_signature='b',
async_callbacks=('callback', 'errback'))
def connect(self, profile_key="@DEFAULT@", password='', options={}, callback=None, errback=None):
return self._callback("connect", unicode(profile_key), unicode(password), options, callback=callback, errback=errback)
@dbus.service.method(const_INT_PREFIX+const_CORE_SUFFIX,
in_signature='ss', out_signature='',
async_callbacks=('callback', 'errback'))

View file

@ -86,7 +86,7 @@ class SAT(service.Service):
self.bridge.register_method("profileStartSession", self.memory.startSession)
self.bridge.register_method("profileIsSessionStarted", self.memory._isSessionStarted)
self.bridge.register_method("profileSetDefault", self.memory.profileSetDefault)
self.bridge.register_method("asyncConnect", self._asyncConnect)
self.bridge.register_method("connect", self._connect)
self.bridge.register_method("disconnect", self.disconnect)
self.bridge.register_method("getContacts", self.getContacts)
self.bridge.register_method("getContactsFromGroup", self.getContactsFromGroup)
@ -263,22 +263,25 @@ class SAT(service.Service):
defers_list.append(defer.maybeDeferred(unload))
return defers_list
def _asyncConnect(self, profile_key, password=''):
def _connect(self, profile_key, password='', options=None):
profile = self.memory.getProfileName(profile_key)
return self.asyncConnect(profile, password)
return self.connect(profile, password, options)
def asyncConnect(self, profile, password='', max_retries=C.XMPP_MAX_RETRIES):
def connect(self, profile, password='', options=None, max_retries=C.XMPP_MAX_RETRIES):
"""Retrieve the individual parameters, authenticate the profile
and initiate the connection to the associated XMPP server.
@param profile: %(doc_profile)s
@param password (string): the SàT profile password
@param options (dict): connection options
@param max_retries (int): max number of connection retries
@return (D(bool)):
- True if the XMPP connection was already established
- False if the XMPP connection has been initiated (it may still fail)
@raise exceptions.PasswordError: Profile password is wrong
"""
if options is None:
options={}
def connectXMPPClient(dummy=None):
if self.isConnected(profile):
log.info(_("already connected !"))
@ -292,7 +295,7 @@ class SAT(service.Service):
@defer.inlineCallbacks
def _connectXMPPClient(self, profile, max_retries):
"""This part is called from asyncConnect when we have loaded individual parameters from memory"""
"""This part is called from connect when we have loaded individual parameters from memory"""
try:
port = int(self.memory.getParamA(C.FORCE_PORT_PARAM, "Connection", profile_key=profile))
except ValueError:

View file

@ -617,7 +617,7 @@ http://www.salut-a-toi.org
d = self.createProfile(password, jid_s, jid_s)
d.addCallback(lambda dummy: self.host.memory.getProfileName(jid_s)) # checks if the profile has been successfuly created
d.addCallback(self.host.asyncConnect, password, 0)
d.addCallback(self.host.connect, password, {}, 0)
def connected(result):

View file

@ -109,7 +109,7 @@ class ProfileManager(object):
def _changeXMPPPasswordCb(self, data, profile):
xmpp_password = data[xml_tools.formEscape('xmpp_password')]
d = self.host.memory.setParam("Password", xmpp_password, "Connection", profile_key=profile)
d.addCallback(lambda dummy: self.host.asyncConnect(profile))
d.addCallback(lambda dummy: self.host.connect(profile))
d.addCallback(lambda dummy: {})
d.addErrback(lambda dummy: self._changeXMPPPassword({}, profile))
return d