diff --git a/frontends/src/bridge/dbus_bridge.py b/frontends/src/bridge/dbus_bridge.py index 45dc878f..52500d9a 100644 --- a/frontends/src/bridge/dbus_bridge.py +++ b/frontends/src/bridge/dbus_bridge.py @@ -644,6 +644,15 @@ class Bridge(BridgeFrontend): 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 diff --git a/src/bridge/bridge_constructor/bridge_template.ini b/src/bridge/bridge_constructor/bridge_template.ini index a624f241..18ba7b9a 100644 --- a/src/bridge/bridge_constructor/bridge_template.ini +++ b/src/bridge/bridge_constructor/bridge_template.ini @@ -716,3 +716,15 @@ sig_out=b 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) diff --git a/src/bridge/dbus_bridge.py b/src/bridge/dbus_bridge.py index 2ae50a06..68844393 100755 --- a/src/bridge/dbus_bridge.py +++ b/src/bridge/dbus_bridge.py @@ -443,6 +443,12 @@ class DbusObject(dbus.service.Object): def saveParamsTemplate(self, filename): 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) diff --git a/src/core/sat_main.py b/src/core/sat_main.py index 54a95ec9..9a0609dd 100644 --- a/src/core/sat_main.py +++ b/src/core/sat_main.py @@ -118,6 +118,7 @@ class SAT(service.Service): 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 @@ class SAT(service.Service): 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 @@ class SAT(service.Service): 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) diff --git a/src/core/xmpp.py b/src/core/xmpp.py index 91d06cea..26e585ca 100644 --- a/src/core/xmpp.py +++ b/src/core/xmpp.py @@ -44,6 +44,7 @@ class SatXMPPClient(wokkel_client.XMPPClient): 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