Mercurial > libervia-backend
comparison 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 |
comparison
equal
deleted
inserted
replaced
422:5a18c5f08d9b | 423:6c20c76abdcc |
---|---|
203 | 203 |
204 def connect(self, profile_key = '@DEFAULT@'): | 204 def connect(self, profile_key = '@DEFAULT@'): |
205 """Connect to jabber server""" | 205 """Connect to jabber server""" |
206 self.asyncConnect(profile_key) | 206 self.asyncConnect(profile_key) |
207 | 207 |
208 def asyncConnect(self, profile_key = '@DEFAULT@', callback=None, errback=None): | 208 def asyncConnect(self, profile_key = '@DEFAULT@'): |
209 """Connect to jabber server with asynchronous reply | 209 """Connect to jabber server with asynchronous reply |
210 @param profile_key: %(doc_profile)s | 210 @param profile_key: %(doc_profile)s |
211 @param callback: called when the profile is connected | 211 """ |
212 @param errback: called is the connection fail""" | |
213 | 212 |
214 profile = self.memory.getProfileName(profile_key) | 213 profile = self.memory.getProfileName(profile_key) |
215 if not profile: | 214 if not profile: |
216 error (_('Trying to connect a non-exsitant profile')) | 215 error (_('Trying to connect a non-exsitant profile')) |
217 return | 216 return defer.fail() |
218 | 217 |
219 if (self.isConnected(profile)): | 218 if (self.isConnected(profile)): |
220 info(_("already connected !")) | 219 info(_("already connected !")) |
221 if callback: | 220 return defer.succeed("None") |
222 callback() | |
223 return | |
224 | 221 |
225 def afterMemoryInit(ignore): | 222 def afterMemoryInit(ignore): |
226 """This part must be called when we have loaded individual parameters from memory""" | 223 """This part must be called when we have loaded individual parameters from memory""" |
227 current = self.profiles[profile] = xmpp.SatXMPPClient(self, profile, | 224 current = self.profiles[profile] = xmpp.SatXMPPClient(self, profile, |
228 jid.JID(self.memory.getParamA("JabberID", "Connection", profile_key = profile), profile), | 225 jid.JID(self.memory.getParamA("JabberID", "Connection", profile_key = profile), profile), |
229 self.memory.getParamA("Password", "Connection", profile_key = profile), | 226 self.memory.getParamA("Password", "Connection", profile_key = profile), |
230 self.memory.getParamA("Server", "Connection", profile_key = profile), 5222) | 227 self.memory.getParamA("Server", "Connection", profile_key = profile), 5222) |
231 | 228 |
232 if callback and errback: | |
233 current.getConnectionDeferred().addCallbacks(lambda x:callback(), errback) | |
234 | |
235 current.messageProt = xmpp.SatMessageProtocol(self) | 229 current.messageProt = xmpp.SatMessageProtocol(self) |
236 current.messageProt.setHandlerParent(current) | 230 current.messageProt.setHandlerParent(current) |
237 | 231 |
238 current.roster = xmpp.SatRosterProtocol(self) | 232 current.roster = xmpp.SatRosterProtocol(self) |
239 current.roster.setHandlerParent(current) | 233 current.roster.setHandlerParent(current) |
254 if plugin[1].is_handler: | 248 if plugin[1].is_handler: |
255 plugin[1].getHandler(profile).setHandlerParent(current) | 249 plugin[1].getHandler(profile).setHandlerParent(current) |
256 | 250 |
257 current.startService() | 251 current.startService() |
258 | 252 |
259 params_defer = self.memory.loadIndividualParams(profile).addCallback(afterMemoryInit) | 253 return current.getConnectionDeferred() |
260 if errback: | 254 |
261 params_defer.addErrback(errback) | 255 return self.memory.loadIndividualParams(profile).addCallback(afterMemoryInit) |
262 | 256 |
263 def disconnect(self, profile_key): | 257 def disconnect(self, profile_key): |
264 """disconnect from jabber server""" | 258 """disconnect from jabber server""" |
265 if (not self.isConnected(profile_key)): | 259 if (not self.isConnected(profile_key)): |
266 info(_("not connected !")) | 260 info(_("not connected !")) |