changeset 3:154d4caa57f4

server side: proper profile management in signals generic callback
author Goffi <goffi@goffi.org>
date Sun, 13 Feb 2011 16:16:40 +0100
parents 669c531a857e
children 7325e787c22b
files libervia.tac
diffstat 1 files changed, 11 insertions(+), 12 deletions(-) [+]
line wrap: on
line diff
--- a/libervia.tac	Tue Feb 08 21:18:31 2011 +0100
+++ b/libervia.tac	Sun Feb 13 16:16:40 2011 +0100
@@ -182,7 +182,7 @@
         Resource.__init__(self)
         self.register=None
         self.sat_host=sat_host
-        self.signalDeferred = None
+        self.signalDeferred = {}
 
     def plugRegister(self, register):
         self.register = register
@@ -190,23 +190,22 @@
     def jsonrpc_getSignals(self):
         """Keep the connection alive until a signal is received, then send it
         @return: (signal, *signal_args)"""
-        self.signalDeferred = defer.Deferred()
-        return self.signalDeferred
+        _session = self.request.getSession()
+        profile = _session.sat_profile
+        self.signalDeferred[profile] = defer.Deferred()
+        return self.signalDeferred[profile]
     
     def getGenericCb(self, function_name):
-        """Return a generic function which send all params to signalDeferred.callback"""
+        """Return a generic function which send all params to signalDeferred.callback
+        function must have profile as last argument"""
         def genericCb(*args):
-            if self.signalDeferred:
-                self.signalDeferred.callback((function_name,args))
+            profile = args[-1]
+            if profile in self.signalDeferred:
+                self.signalDeferred[profile].callback((function_name,args[:-1]))
             else:
                 print("Warning: signal [%s] can't be sent" % function_name)
         return genericCb
     
-    def genericCallback(self, *args):
-        """"This method send all params to signalDeferred"""
-        if self.signalDeferred:
-            print ("Sending signals %s")
-        
     def connected(self, profile):
         assert(self.register) #register must be plugged
         request = self.register.getWaitingRequest(profile)
@@ -259,7 +258,7 @@
             sys.exit(1)
         self.bridge.register("connected", self.signal_handler.connected)
         self.bridge.register("connectionError", self.signal_handler.connectionError)
-        for signal_name in ['presenceUpdate']:
+        for signal_name in ['presenceUpdate', 'personalEvent']:
             self.bridge.register(signal_name, self.signal_handler.getGenericCb(signal_name))
 
     def startService(self):