changeset 963:723f28cd15c7

core (disco): added discoInfos and discoItems bridge methods
author Goffi <goffi@goffi.org>
date Tue, 01 Apr 2014 21:14:57 +0200
parents b280cf4cdf25
children e09f624d3aa9
files frontends/src/bridge/DBus.py src/bridge/DBus.py src/bridge/bridge_constructor/bridge_template.ini src/core/sat_main.py src/memory/disco.py
diffstat 5 files changed, 63 insertions(+), 2 deletions(-) [+]
line wrap: on
line diff
--- a/frontends/src/bridge/DBus.py	Mon Mar 31 20:19:34 2014 +0200
+++ b/frontends/src/bridge/DBus.py	Tue Apr 01 21:14:57 2014 +0200
@@ -119,6 +119,12 @@
     def delContact(self, entity_jid, profile_key="@DEFAULT@"):
         return self.db_core_iface.delContact(entity_jid, profile_key)
 
+    def discoInfos(self, entity_jid, profile_key, callback=None, errback=None):
+        return self.db_core_iface.discoInfos(entity_jid, profile_key, reply_handler=callback, error_handler=lambda err:errback(err._dbus_error_name[len(const_ERROR_PREFIX)+1:]))
+
+    def discoItems(self, entity_jid, profile_key, callback=None, errback=None):
+        return self.db_core_iface.discoItems(entity_jid, profile_key, reply_handler=callback, error_handler=lambda err:errback(err._dbus_error_name[len(const_ERROR_PREFIX)+1:]))
+
     def disconnect(self, profile_key="@DEFAULT@"):
         return self.db_core_iface.disconnect(profile_key)
 
--- a/src/bridge/DBus.py	Mon Mar 31 20:19:34 2014 +0200
+++ b/src/bridge/DBus.py	Tue Apr 01 21:14:57 2014 +0200
@@ -234,6 +234,18 @@
         return self._callback("delContact", unicode(entity_jid), unicode(profile_key))
 
     @dbus.service.method(const_INT_PREFIX+const_CORE_SUFFIX,
+                         in_signature='ss', out_signature='(asa(sss))',
+                         async_callbacks=('callback', 'errback'))
+    def discoInfos(self, entity_jid, profile_key, callback=None, errback=None):
+        return self._callback("discoInfos", unicode(entity_jid), unicode(profile_key), callback=callback, errback=errback)
+
+    @dbus.service.method(const_INT_PREFIX+const_CORE_SUFFIX,
+                         in_signature='ss', out_signature='a(sss)',
+                         async_callbacks=('callback', 'errback'))
+    def discoItems(self, entity_jid, profile_key, callback=None, errback=None):
+        return self._callback("discoItems", unicode(entity_jid), unicode(profile_key), callback=callback, errback=errback)
+
+    @dbus.service.method(const_INT_PREFIX+const_CORE_SUFFIX,
                          in_signature='s', out_signature='',
                          async_callbacks=None)
     def disconnect(self, profile_key="@DEFAULT@"):
--- a/src/bridge/bridge_constructor/bridge_template.ini	Mon Mar 31 20:19:34 2014 +0200
+++ b/src/bridge/bridge_constructor/bridge_template.ini	Tue Apr 01 21:14:57 2014 +0200
@@ -584,7 +584,7 @@
 [getMenus]
 type=method
 category=core
-sig_in= si
+sig_in=si
 sig_out=a(ssasas)
 doc=Get all additional menus
 doc_param_0=language: language in which the menu should be translated (empty string for default)
@@ -607,3 +607,24 @@
 doc_param_1=language: language in which the menu should be translated (empty string for default)
 doc_return=Translated help string
 
+[discoInfos]
+async=
+type=method
+category=core
+sig_in=ss
+sig_out=(asa(sss))
+doc=Discover infos on an entity
+doc_param_0=entity_jid: JID to discover
+doc_param_1=%(doc_profile_key)s
+doc_return=discovery data
+
+[discoItems]
+async=
+type=method
+category=core
+sig_in=ss
+sig_out=a(sss)
+doc=Discover items of an entity
+doc_param_0=entity_jid: JID to discover
+doc_param_1=%(doc_profile_key)s
+doc_return=array of tuple (entity, node identifier, name)
--- a/src/core/sat_main.py	Mon Mar 31 20:19:34 2014 +0200
+++ b/src/core/sat_main.py	Tue Apr 01 21:14:57 2014 +0200
@@ -135,6 +135,8 @@
         self.bridge.register("getProgress", self.getProgress)
         self.bridge.register("getMenus", self.getMenus)
         self.bridge.register("getMenuHelp", self.getMenuHelp)
+        self.bridge.register("discoInfos", self.memory.disco._discoInfos)
+        self.bridge.register("discoItems", self.memory.disco._discoItems)
 
         self.memory.initialized.addCallback(self._postMemoryInit)
 
--- a/src/memory/disco.py	Mon Mar 31 20:19:34 2014 +0200
+++ b/src/memory/disco.py	Tue Apr 01 21:14:57 2014 +0200
@@ -114,7 +114,7 @@
 
         @param jid_: jid of the target, or None for profile's server
         @param profile_key: %(doc_profile_key)s
-        @return: a Deferred which fire disco.DiscoInfo
+        @return: a Deferred which fire disco.DiscoItems
         """
         client = self.host.getClient(profile_key)
         if jid_ is None:
@@ -212,3 +212,23 @@
         cap_hash = b64encode(sha1(''.join(s)).digest())
         debug(_('Capability hash generated: [%s]') % cap_hash)
         return cap_hash
+
+    @defer.inlineCallbacks
+    def _discoInfos(self, entity_jid_s, profile_key=C.PROF_KEY_NONE):
+        """ Discovery method for the bridge
+        @param entity_jid_s: entity we want to discover
+
+        @return: list of tu"""
+        entity = jid.JID(entity_jid_s)
+        disco_infos = yield self.getInfos(entity, profile_key)
+        defer.returnValue((disco_infos.features, [(cat, type_, name or '') for (cat, type_), name in disco_infos.identities.items()]))
+
+    @defer.inlineCallbacks
+    def _discoItems(self, entity_jid_s, profile_key=C.PROF_KEY_NONE):
+        """ Discovery method for the bridge
+        @param entity_jid_s: entity we want to discover
+
+        @return: list of tu"""
+        entity = jid.JID(entity_jid_s)
+        disco_items = yield self.getItems(entity, profile_key)
+        defer.returnValue([(item.entity.full(), item.nodeIdentifier or '', item.name or '') for item in disco_items])