changeset 2113:9c861d07b5b6

core: added sessionGetInfos bridge method to retrieve various data on current profile session + client.started keep start time
author Goffi <goffi@goffi.org>
date Thu, 05 Jan 2017 22:22:13 +0100
parents 877d0a2d0d86
children dc5d214f0a3b
files frontends/src/bridge/dbus_bridge.py src/bridge/bridge_constructor/bridge_template.ini src/bridge/dbus_bridge.py src/core/sat_main.py src/core/xmpp.py
diffstat 5 files changed, 40 insertions(+), 2 deletions(-) [+]
line wrap: on
line diff
--- a/frontends/src/bridge/dbus_bridge.py	Thu Jan 05 20:37:01 2017 +0100
+++ b/frontends/src/bridge/dbus_bridge.py	Thu Jan 05 22:22:13 2017 +0100
@@ -644,6 +644,15 @@
             kwargs['error_handler'] = error_handler
         return self.db_core_iface.saveParamsTemplate(filename, **kwargs)
 
+    def sessionInfosGet(self, profile_key, callback=None, errback=None):
+        if callback is None:
+            error_handler = None
+        else:
+            if errback is None:
+                errback = log.error
+            error_handler = lambda err:errback(dbus_to_bridge_exception(err))
+        return self.db_core_iface.sessionInfosGet(profile_key, timeout=const_TIMEOUT, reply_handler=callback, error_handler=error_handler)
+
     def setParam(self, name, value, category, security_limit=-1, profile_key="@DEFAULT@", callback=None, errback=None):
         if callback is None:
             error_handler = None
--- a/src/bridge/bridge_constructor/bridge_template.ini	Thu Jan 05 20:37:01 2017 +0100
+++ b/src/bridge/bridge_constructor/bridge_template.ini	Thu Jan 05 22:22:13 2017 +0100
@@ -716,3 +716,15 @@
 doc=Load parameters template from xml file
 doc_param_0=filename: input filename
 doc_return=boolean (True in case of success)
+
+[sessionInfosGet]
+async=
+type=method
+category=core
+sig_in=s
+sig_out=a{ss}
+doc=Get various informations on current profile session
+doc_param_0=%(doc_profile_key)s
+doc_return=session informations, with at least the following keys:
+    jid: current full jid
+    started: date of creation of the session (Epoch time)
--- a/src/bridge/dbus_bridge.py	Thu Jan 05 20:37:01 2017 +0100
+++ b/src/bridge/dbus_bridge.py	Thu Jan 05 22:22:13 2017 +0100
@@ -444,6 +444,12 @@
         return self._callback("saveParamsTemplate", unicode(filename))
 
     @dbus.service.method(const_INT_PREFIX+const_CORE_SUFFIX,
+                         in_signature='s', out_signature='a{ss}',
+                         async_callbacks=('callback', 'errback'))
+    def sessionInfosGet(self, profile_key, callback=None, errback=None):
+        return self._callback("sessionInfosGet", unicode(profile_key), callback=callback, errback=errback)
+
+    @dbus.service.method(const_INT_PREFIX+const_CORE_SUFFIX,
                          in_signature='sssis', out_signature='',
                          async_callbacks=None)
     def setParam(self, name, value, category, security_limit=-1, profile_key="@DEFAULT@"):
--- a/src/core/sat_main.py	Thu Jan 05 20:37:01 2017 +0100
+++ b/src/core/sat_main.py	Thu Jan 05 22:22:13 2017 +0100
@@ -118,6 +118,7 @@
         self.bridge.register_method("discoItems", self.memory.disco._discoItems)
         self.bridge.register_method("saveParamsTemplate", self.memory.save_xml)
         self.bridge.register_method("loadParamsTemplate", self.memory.load_xml)
+        self.bridge.register_method("sessionInfosGet", self.getSessionInfos)
 
         self.memory.initialized.addCallback(self._postMemoryInit)
 
@@ -1077,8 +1078,8 @@
         return ret
 
     def getMenuHelp(self, menu_id, language=''):
-        """
-        return the help string of the menu
+        """return the help string of the menu
+
         @param menu_id: id of the menu (same as callback_id)
         @param language: language used for translation, or empty string for default
         @param return: translated help
@@ -1092,3 +1093,12 @@
         help_string = _(menu_data['help_string'])
         languageSwitch()
         return help_string
+
+    def getSessionInfos(self, profile_key):
+        """compile interesting data on current profile session"""
+        client = self.getClient(profile_key)
+        data = {
+            "jid": client.jid.full(),
+            "started": unicode(int(client.started)),
+            }
+        return defer.succeed(data)
--- a/src/core/xmpp.py	Thu Jan 05 20:37:01 2017 +0100
+++ b/src/core/xmpp.py	Thu Jan 05 22:22:13 2017 +0100
@@ -44,6 +44,7 @@
     def __init__(self, host_app, profile, user_jid, password, host=None, port=C.XMPP_C2S_PORT, max_retries=C.XMPP_MAX_RETRIES):
         # XXX: DNS SRV records are checked when the host is not specified.
         # If no SRV record is found, the host is directly extracted from the JID.
+        self.started = time.time()
         if sys.platform == "android":
             # FIXME: temporary hack as SRV is not working on android
             # TODO: remove this hack and fix SRV