Mercurial > libervia-backend
comparison src/core/sat_main.py @ 2142:be96beb7ca14
core, bridge, frontends: renamed asyncConnect to connect, and added options parameters (not used yet)
author | Goffi <goffi@goffi.org> |
---|---|
date | Mon, 06 Feb 2017 22:54:43 +0100 |
parents | 6e509ee853a8 |
children | 1d3f73e065e1 |
comparison
equal
deleted
inserted
replaced
2141:35762e9ce8b9 | 2142:be96beb7ca14 |
---|---|
84 self.bridge.register_method("asyncCreateProfile", self.memory.asyncCreateProfile) | 84 self.bridge.register_method("asyncCreateProfile", self.memory.asyncCreateProfile) |
85 self.bridge.register_method("asyncDeleteProfile", self.memory.asyncDeleteProfile) | 85 self.bridge.register_method("asyncDeleteProfile", self.memory.asyncDeleteProfile) |
86 self.bridge.register_method("profileStartSession", self.memory.startSession) | 86 self.bridge.register_method("profileStartSession", self.memory.startSession) |
87 self.bridge.register_method("profileIsSessionStarted", self.memory._isSessionStarted) | 87 self.bridge.register_method("profileIsSessionStarted", self.memory._isSessionStarted) |
88 self.bridge.register_method("profileSetDefault", self.memory.profileSetDefault) | 88 self.bridge.register_method("profileSetDefault", self.memory.profileSetDefault) |
89 self.bridge.register_method("asyncConnect", self._asyncConnect) | 89 self.bridge.register_method("connect", self._connect) |
90 self.bridge.register_method("disconnect", self.disconnect) | 90 self.bridge.register_method("disconnect", self.disconnect) |
91 self.bridge.register_method("getContacts", self.getContacts) | 91 self.bridge.register_method("getContacts", self.getContacts) |
92 self.bridge.register_method("getContactsFromGroup", self.getContactsFromGroup) | 92 self.bridge.register_method("getContactsFromGroup", self.getContactsFromGroup) |
93 self.bridge.register_method("getMainResource", self.memory._getMainResource) | 93 self.bridge.register_method("getMainResource", self.memory._getMainResource) |
94 self.bridge.register_method("getPresenceStatuses", self.memory._getPresenceStatuses) | 94 self.bridge.register_method("getPresenceStatuses", self.memory._getPresenceStatuses) |
261 continue | 261 continue |
262 else: | 262 else: |
263 defers_list.append(defer.maybeDeferred(unload)) | 263 defers_list.append(defer.maybeDeferred(unload)) |
264 return defers_list | 264 return defers_list |
265 | 265 |
266 def _asyncConnect(self, profile_key, password=''): | 266 def _connect(self, profile_key, password='', options=None): |
267 profile = self.memory.getProfileName(profile_key) | 267 profile = self.memory.getProfileName(profile_key) |
268 return self.asyncConnect(profile, password) | 268 return self.connect(profile, password, options) |
269 | 269 |
270 def asyncConnect(self, profile, password='', max_retries=C.XMPP_MAX_RETRIES): | 270 def connect(self, profile, password='', options=None, max_retries=C.XMPP_MAX_RETRIES): |
271 """Retrieve the individual parameters, authenticate the profile | 271 """Retrieve the individual parameters, authenticate the profile |
272 and initiate the connection to the associated XMPP server. | 272 and initiate the connection to the associated XMPP server. |
273 | 273 |
274 @param profile: %(doc_profile)s | 274 @param profile: %(doc_profile)s |
275 @param password (string): the SàT profile password | 275 @param password (string): the SàT profile password |
276 @param options (dict): connection options | |
276 @param max_retries (int): max number of connection retries | 277 @param max_retries (int): max number of connection retries |
277 @return (D(bool)): | 278 @return (D(bool)): |
278 - True if the XMPP connection was already established | 279 - True if the XMPP connection was already established |
279 - False if the XMPP connection has been initiated (it may still fail) | 280 - False if the XMPP connection has been initiated (it may still fail) |
280 @raise exceptions.PasswordError: Profile password is wrong | 281 @raise exceptions.PasswordError: Profile password is wrong |
281 """ | 282 """ |
283 if options is None: | |
284 options={} | |
282 def connectXMPPClient(dummy=None): | 285 def connectXMPPClient(dummy=None): |
283 if self.isConnected(profile): | 286 if self.isConnected(profile): |
284 log.info(_("already connected !")) | 287 log.info(_("already connected !")) |
285 return True | 288 return True |
286 d = self._connectXMPPClient(profile, max_retries) | 289 d = self._connectXMPPClient(profile, max_retries) |
290 d.addCallback(connectXMPPClient) | 293 d.addCallback(connectXMPPClient) |
291 return d | 294 return d |
292 | 295 |
293 @defer.inlineCallbacks | 296 @defer.inlineCallbacks |
294 def _connectXMPPClient(self, profile, max_retries): | 297 def _connectXMPPClient(self, profile, max_retries): |
295 """This part is called from asyncConnect when we have loaded individual parameters from memory""" | 298 """This part is called from connect when we have loaded individual parameters from memory""" |
296 try: | 299 try: |
297 port = int(self.memory.getParamA(C.FORCE_PORT_PARAM, "Connection", profile_key=profile)) | 300 port = int(self.memory.getParamA(C.FORCE_PORT_PARAM, "Connection", profile_key=profile)) |
298 except ValueError: | 301 except ValueError: |
299 log.debug(_("Can't parse port value, using default value")) | 302 log.debug(_("Can't parse port value, using default value")) |
300 port = None # will use default value 5222 or be retrieved from a DNS SRV record | 303 port = None # will use default value 5222 or be retrieved from a DNS SRV record |