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
This commit is contained in:
parent
0d5b8b5a84
commit
b27f385511
1 changed files with 14 additions and 9 deletions
|
|
@ -55,6 +55,8 @@ class SatXMPPEntity(object):
|
|||
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 @@ class SatXMPPEntity(object):
|
|||
# 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 @@ class SatXMPPEntity(object):
|
|||
|
||||
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 SatXMPPEntity(object):
|
|||
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 @@ class SatXMPPClient(SatXMPPEntity, wokkel_client.XMPPClient):
|
|||
|
||||
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 @@ class SatXMPPComponent(SatXMPPEntity, component.Component):
|
|||
"""
|
||||
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 @@ class SatXMPPComponent(SatXMPPEntity, component.Component):
|
|||
# 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 @@ class SatXMPPComponent(SatXMPPEntity, component.Component):
|
|||
|
||||
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:
|
||||
|
|
|
|||
Loading…
Reference in a new issue