Mercurial > libervia-web
comparison libervia.tac @ 156:46835a4e2551
server side: disconnection
author | Goffi <goffi@goffi.org> |
---|---|
date | Sat, 05 Jan 2013 16:06:33 +0100 |
parents | 9c4550b1df3c |
children | 6f913f5adca8 |
comparison
equal
deleted
inserted
replaced
155:9c4550b1df3c | 156:46835a4e2551 |
---|---|
146 sat_session = ISATSession(self.session) | 146 sat_session = ISATSession(self.session) |
147 profile = sat_session.profile | 147 profile = sat_session.profile |
148 sat_session.jid = JID(self.sat_host.bridge.getParamA("JabberID", "Connection", profile_key=profile)) | 148 sat_session.jid = JID(self.sat_host.bridge.getParamA("JabberID", "Connection", profile_key=profile)) |
149 return sat_session.jid.full() | 149 return sat_session.jid.full() |
150 | 150 |
151 def jsonrpc_disconnect(self): | |
152 """Disconnect the profile""" | |
153 sat_session = ISATSession(self.session) | |
154 profile = sat_session.profile | |
155 self.sat_host.bridge.disconnect(profile) | |
156 | |
151 def jsonrpc_getContacts(self): | 157 def jsonrpc_getContacts(self): |
152 """Return all passed args.""" | 158 """Return all passed args.""" |
153 profile = ISATSession(self.session).profile | 159 profile = ISATSession(self.session).profile |
154 return self.sat_host.bridge.getContacts(profile) | 160 return self.sat_host.bridge.getContacts(profile) |
155 | 161 |
547 return result('SESSION_ACTIVE') | 553 return result('SESSION_ACTIVE') |
548 sat_session.profile = profile | 554 sat_session.profile = profile |
549 self.sat_host.prof_connected.add(profile) | 555 self.sat_host.prof_connected.add(profile) |
550 | 556 |
551 def onExpire(): | 557 def onExpire(): |
558 info ("Session expired (profile=%s)" % (profile,)) | |
552 try: | 559 try: |
553 #We purge the queue | 560 #We purge the queue |
554 del self.sat_host.signal_handler.queue[profile] | 561 del self.sat_host.signal_handler.queue[profile] |
555 except KeyError: | 562 except KeyError: |
556 pass | 563 pass |
609 return self.queue[profile].pop(0) | 616 return self.queue[profile].pop(0) |
610 else: | 617 else: |
611 #the queue is empty, we delete the profile from queue | 618 #the queue is empty, we delete the profile from queue |
612 del self.queue[profile] | 619 del self.queue[profile] |
613 _session.lock() #we don't want the session to expire as long as this connection is active | 620 _session.lock() #we don't want the session to expire as long as this connection is active |
614 def unlock(ignore): | 621 def unlock(signal, profile): |
615 _session.unlock() | 622 _session.unlock() |
623 try: | |
624 source_defer = self.signalDeferred[profile] | |
625 if source_defer.called and source_defer.result[0] == "disconnected": | |
626 info(u"[%s] disconnected" % (profile,)) | |
627 _session.expire() | |
628 except IndexError: | |
629 error("Deferred result should be a tuple with fonction name first") | |
630 | |
616 self.signalDeferred[profile] = defer.Deferred() | 631 self.signalDeferred[profile] = defer.Deferred() |
617 self.request.notifyFinish().addBoth(unlock) | 632 self.request.notifyFinish().addBoth(unlock, profile) |
618 return self.signalDeferred[profile] | 633 return self.signalDeferred[profile] |
619 | 634 |
620 def getGenericCb(self, function_name): | 635 def getGenericCb(self, function_name): |
621 """Return a generic function which send all params to signalDeferred.callback | 636 """Return a generic function which send all params to signalDeferred.callback |
622 function must have profile as last argument""" | 637 function must have profile as last argument""" |
636 def connected(self, profile): | 651 def connected(self, profile): |
637 assert(self.register) #register must be plugged | 652 assert(self.register) #register must be plugged |
638 request = self.register.getWaitingRequest(profile) | 653 request = self.register.getWaitingRequest(profile) |
639 if request: | 654 if request: |
640 self.register._logged(profile, request) | 655 self.register._logged(profile, request) |
656 | |
657 def disconnected(self, profile): | |
658 if not profile in self.sat_host.prof_connected: | |
659 error("'disconnected' signal received for a not connected profile") | |
660 return | |
661 self.sat_host.prof_connected.remove(profile) | |
662 if profile in self.signalDeferred: | |
663 self.signalDeferred[profile].callback(("disconnected",)) | |
664 del self.signalDeferred[profile] | |
665 else: | |
666 if not self.queue.has_key(profile): | |
667 self.queue[profile] = [] | |
668 self.queue[profile].append(("disconnected",)) | |
669 | |
641 | 670 |
642 def connectionError(self, error_type, profile): | 671 def connectionError(self, error_type, profile): |
643 assert(self.register) #register must be plugged | 672 assert(self.register) #register must be plugged |
644 request = self.register.getWaitingRequest(profile) | 673 request = self.register.getWaitingRequest(profile) |
645 if request: #The user is trying to log in | 674 if request: #The user is trying to log in |
748 self.bridge=DBusBridgeFrontend() | 777 self.bridge=DBusBridgeFrontend() |
749 except BridgeExceptionNoService: | 778 except BridgeExceptionNoService: |
750 print(u"Can't connect to SàT backend, are you sure it's launched ?") | 779 print(u"Can't connect to SàT backend, are you sure it's launched ?") |
751 sys.exit(1) | 780 sys.exit(1) |
752 self.bridge.register("connected", self.signal_handler.connected) | 781 self.bridge.register("connected", self.signal_handler.connected) |
782 self.bridge.register("disconnected", self.signal_handler.disconnected) | |
753 self.bridge.register("connectionError", self.signal_handler.connectionError) | 783 self.bridge.register("connectionError", self.signal_handler.connectionError) |
754 self.bridge.register("actionResult", self.action_handler.actionResultCb) | 784 self.bridge.register("actionResult", self.action_handler.actionResultCb) |
755 #core | 785 #core |
756 for signal_name in ['presenceUpdate', 'newMessage', 'subscribe', 'contactDeleted', 'newContact', 'entityDataUpdated']: | 786 for signal_name in ['presenceUpdate', 'newMessage', 'subscribe', 'contactDeleted', 'newContact', 'entityDataUpdated']: |
757 self.bridge.register(signal_name, self.signal_handler.getGenericCb(signal_name)) | 787 self.bridge.register(signal_name, self.signal_handler.getGenericCb(signal_name)) |