changeset 2498:d6de69da3dd4

core (client): component improvments: - renamed component boolean to is_component for more clarity - profileConnected/profileDisconnected don't use a suffix anymore, it's called for both client and component. To check for there, the is_component boolean is enough - fixed dependencies handling - componentStart is not mandatory anymore, as a component can just be used with its handler
author Goffi <goffi@goffi.org>
date Wed, 28 Feb 2018 18:28:39 +0100
parents 38f472dbfcf0
children af4a38ebf52a
files src/core/xmpp.py
diffstat 1 files changed, 14 insertions(+), 9 deletions(-) [+]
line wrap: on
line diff
--- a/src/core/xmpp.py	Wed Feb 28 18:28:39 2018 +0100
+++ b/src/core/xmpp.py	Wed Feb 28 18:28:39 2018 +0100
@@ -55,6 +55,8 @@
         self.cache = cache.Cache(host_app, profile)
         self._mess_id_uid = {} # map from message id to uid used in history. Key: (full_jid,message_id) Value: uid
         self.conn_deferred = defer.Deferred()
+        self._progress_cb = {}  # callback called when a progress is requested (key = progress id)
+        self.actions = {} # used to keep track of actions for retrieval (key = action_id)
 
     ## initialisation ##
 
@@ -76,12 +78,12 @@
             # profileConnecting/profileConnected methods handling
 
             # profile connecting is called right now (before actually starting client)
-            connecting_cb = getattr(plugin, "profileConnecting" + self.trigger_suffix, None)
+            connecting_cb = getattr(plugin, "profileConnecting", None)
             if connecting_cb is not None:
                 yield connecting_cb(self)
 
             # profile connected is called after client is ready and roster is got
-            connected_cb = getattr(plugin, "profileConnected" + self.trigger_suffix, None)
+            connected_cb = getattr(plugin, "profileConnected", None)
             if connected_cb is not None:
                 plugin_conn_cb.append((plugin, connected_cb))
 
@@ -244,7 +246,7 @@
 
         used to call profileDisconnected* triggers
         """
-        trigger_name = "profileDisconnected" + self.trigger_suffix
+        trigger_name = "profileDisconnected"
         for plugin in self._getPluginsList():
             disconnected_cb = getattr(plugin, trigger_name, None)
             if disconnected_cb is not None:
@@ -454,7 +456,7 @@
 class SatXMPPClient(SatXMPPEntity, wokkel_client.XMPPClient):
     implements(iwokkel.IDisco)
     trigger_suffix = ""
-    component = False
+    is_component = False
 
     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.
@@ -492,8 +494,6 @@
 
         wokkel_client.XMPPClient.__init__(self, user_jid, password, host or None, port or C.XMPP_C2S_PORT)
         SatXMPPEntity.__init__(self, host_app, profile, max_retries)
-        self._progress_cb = {}  # callback called when a progress is requested (key = progress id)
-        self.actions = {} # used to keep track of actions for retrieval (key = action_id)
 
     def _getPluginsList(self):
         for p in self.host_app.plugins.itervalues():
@@ -582,7 +582,7 @@
     """
     implements(iwokkel.IDisco)
     trigger_suffix = "Component"  # used for to distinguish some trigger points set in SatXMPPEntity
-    component = True
+    is_component = True
     sendHistory = False  # XXX: set to True from entry plugin to keep messages in history for received messages
 
     def __init__(self, host_app, profile, component_jid, password, host=None, port=None, max_retries=C.XMPP_MAX_RETRIES):
@@ -639,7 +639,7 @@
             # plugins are already loaded as dependencies
             # so we know they are in self.host_app.plugins
             dep = self.host_app.plugins[import_name]
-            self._checkDependencies(dep, plugins)
+            self._buildDependencies(dep, plugins)
 
         for import_name in current._info.get(C.PI_RECOMMENDATIONS, []):
             # here plugins are only recommendations,
@@ -664,7 +664,12 @@
 
     def entityConnected(self):
         # we can now launch entry point
-        return self.entry_plugin.componentStart(self)
+        try:
+            start_cb = self.entry_plugin.componentStart
+        except AttributeError:
+            return
+        else:
+            return start_cb(self)
 
     def addPostXmlCallbacks(self, post_xml_treatments):
         if self.sendHistory: