changeset 541:8b116fa42a31

core, bridge: waiting confirmation management (new getWaitingConf method)
author Goffi <goffi@goffi.org>
date Wed, 14 Nov 2012 20:24:28 +0100
parents 47e45a577ab7
children 3eeb6c865e4d
files src/bridge/DBus.py src/bridge/bridge_constructor/bridge_template.ini src/core/sat_main.py
diffstat 3 files changed, 37 insertions(+), 9 deletions(-) [+]
line wrap: on
line diff
--- a/src/bridge/DBus.py	Mon Nov 12 10:55:44 2012 +0100
+++ b/src/bridge/DBus.py	Wed Nov 14 20:24:28 2012 +0100
@@ -116,7 +116,7 @@
 
     @dbus.service.signal(const_INT_PREFIX+const_CORE_SUFFIX,
                          signature='ssa{ss}s')
-    def askConfirmation(self, conf_type, id, data, profile):
+    def askConfirmation(self, id, conf_type, data, profile):
         pass
 
     @dbus.service.signal(const_INT_PREFIX+const_CORE_SUFFIX,
@@ -352,6 +352,12 @@
         return self._callback("getVersion", )
 
     @dbus.service.method(const_INT_PREFIX+const_CORE_SUFFIX,
+                         in_signature='s', out_signature='a(ssa{ss})',
+                         async_callbacks=None)
+    def getWaitingConf(self, profile_key):
+        return self._callback("getWaitingConf", unicode(profile_key))
+
+    @dbus.service.method(const_INT_PREFIX+const_CORE_SUFFIX,
                          in_signature='s', out_signature='a{ss}',
                          async_callbacks=None)
     def getWaitingSub(self, profile_key="@DEFAULT@"):
@@ -509,8 +515,8 @@
     def actionResultExt(self, answer_type, id, data, profile):
         self.dbus_bridge.actionResultExt(answer_type, id, data, profile)
 
-    def askConfirmation(self, conf_type, id, data, profile):
-        self.dbus_bridge.askConfirmation(conf_type, id, data, profile)
+    def askConfirmation(self, id, conf_type, data, profile):
+        self.dbus_bridge.askConfirmation(id, conf_type, data, profile)
 
     def connected(self, profile):
         self.dbus_bridge.connected(profile)
--- a/src/bridge/bridge_constructor/bridge_template.ini	Mon Nov 12 10:55:44 2012 +0100
+++ b/src/bridge/bridge_constructor/bridge_template.ini	Wed Nov 14 20:24:28 2012 +0100
@@ -108,10 +108,10 @@
 category=core
 sig_in=ssa{ss}s
 doc=A confirmation is needed for an action
-doc_param_0=conf_type: Type of the confirmation, can be:
+doc_param_0=id: Id of the confirmation query
+doc_param_1=conf_type: Type of the confirmation, can be:
  - YES/NO: A question which need a yes or no answer
  - FILE_TRANSFER: A confirmation is needed before transfering a file
-doc_param_1=id: Id of the confirmation query
 doc_param_2=data: conf_type dependent data
 doc_param_3=%(doc_profile)s
 
@@ -331,6 +331,16 @@
 doc_param_0=%(doc_profile_key)s
 doc_return=Dict where contact JID is the key, and value is the subscription type
 
+[getWaitingConf]
+type=method
+category=core
+sig_in=s
+sig_out=a(ssa{ss})
+doc=Get confirmations requests in queue
+doc_param_0=%(doc_profile_key)s
+doc_return=List of confirmation request data, same as for [askConfirmation]
+
+
 [sendMessage]
 type=method
 category=core
--- a/src/core/sat_main.py	Mon Nov 12 10:55:44 2012 +0100
+++ b/src/core/sat_main.py	Wed Nov 14 20:24:28 2012 +0100
@@ -129,6 +129,7 @@
         self.bridge.register("getLastResource", self.memory.getLastResource)
         self.bridge.register("getPresenceStatus", self.memory.getPresenceStatus)
         self.bridge.register("getWaitingSub", self.memory.getWaitingSub)
+        self.bridge.register("getWaitingConf", self.getWaitingConf)
         self.bridge.register("sendMessage", self.sendMessage)
         self.bridge.register("getConfig", self.memory.getConfig)
         self.bridge.register("setParam", self.setParam)
@@ -452,6 +453,17 @@
 
 
     ## jabber methods ##
+   
+    def getWaitingConf(self, profile_key=None):
+        assert(profile_key)
+        client = self.getClient(profile_key)
+        if not client:
+            raise ProfileNotInCacheError
+        ret = []
+        for conf_id in client._waiting_conf:
+            conf_type, data = client._waiting_conf[conf_id][:2]
+            ret.append((conf_id, conf_type, data))
+        return ret
     
     def sendMessage(self, to, msg, subject=None, mess_type='auto', profile_key='@DEFAULT@'):
         #FIXME: check validity of recipient
@@ -635,8 +647,8 @@
         if client._waiting_conf.has_key(conf_id):
             error (_("Attempt to register two callbacks for the same confirmation"))
         else:
-            client._waiting_conf[conf_id] = cb
-            self.bridge.askConfirmation(conf_type, conf_id, data, profile)
+            client._waiting_conf[conf_id] = (conf_type, data, cb)
+            self.bridge.askConfirmation(conf_id, conf_type, data, profile)
 
 
     def confirmationAnswer(self, conf_id, accepted, data, profile):
@@ -646,9 +658,9 @@
             raise ProfileUnknownError(_("Confirmation answer from a non-existant profile"))
         debug (_("Received confirmation answer for conf_id [%(conf_id)s]: %(success)s") % {'conf_id': conf_id, 'success':_("accepted") if accepted else _("refused")})
         if not client._waiting_conf.has_key(conf_id):
-            error (_("Received an unknown confirmation"))
+            error (_("Received an unknown confirmation (%(id)s for %(profile)s)") % {'id': conf_id, 'profile': profile})
         else:
-            cb = client._waiting_conf[conf_id]
+            cb = client._waiting_conf[conf_id][-1]
             del client._waiting_conf[conf_id]
             cb(conf_id, accepted, data, profile)