From fe4a6abfae3f396622d7acf2b73e97e4e2748f89 Mon Sep 17 00:00:00 2001 From: Goffi Date: Sat, 9 Mar 2019 16:33:31 +0100 Subject: [PATCH] quick frontend (app): new synchronisation mechanism: on some frontend (notably on mobiles) frontend can be paused and lose synchronisation with backend, this can also happen if backend restart a connexion without resuming using stream management. To manage that, QuickApp now has a sync attribute which is True when the backend is in sync with frontend. When synchronisation has been lost and is possible again, all widget will have their "resync" method called, which can be used to do necessary calls to update the status. It's the responsability of each widget to then reset the "sync" attribute, once everything has been resynchronised. --- sat_frontends/quick_frontend/quick_app.py | 38 +++++++++++++++++++ sat_frontends/quick_frontend/quick_widgets.py | 2 +- 2 files changed, 39 insertions(+), 1 deletion(-) diff --git a/sat_frontends/quick_frontend/quick_app.py b/sat_frontends/quick_frontend/quick_app.py index bfbe4d54..a7be02a0 100644 --- a/sat_frontends/quick_frontend/quick_app.py +++ b/sat_frontends/quick_frontend/quick_app.py @@ -329,6 +329,7 @@ class QuickApp(object): self.features = None self.ns_map = {} # map of short name to namespaces self.encryption_plugins = [] + self._sync = True # state of synchronisation with backend def connectBridge(self): self.bridge.bridgeConnect(callback=self._bridgeCb, errback=self._bridgeEb) @@ -425,6 +426,43 @@ class QuickApp(object): if isinstance(w, quick_widgets.QuickWidget): return w + # backend state management + + @property + def sync(self): + """Get synchronization flag + + True if this frontend is synchronised with backend + """ + return self._sync + + @sync.setter + def sync(self, state): + """Called when backend is desynchronised or resynchronising + + @param state(bool): True: if the backend is resynchronising + False when we lose synchronisation, for instance if frontend is going to sleep + or if connection has been lost and a reconnection is needed + """ + if state: + # we are resynchronising + for w in self.widgets: + try: + resync = w.resync + except AttributeError: + pass + else: + resync() + self._sync = state + else: + self._sync = state + # we've lost synchronisation + for w in self.widgets: + try: + w.sync = False + except AttributeError: + pass + def registerSignal( self, function_name, handler=None, iface="core", with_profile=True ): diff --git a/sat_frontends/quick_frontend/quick_widgets.py b/sat_frontends/quick_frontend/quick_widgets.py index a3aaef41..a0c5f832 100644 --- a/sat_frontends/quick_frontend/quick_widgets.py +++ b/sat_frontends/quick_frontend/quick_widgets.py @@ -125,7 +125,7 @@ class QuickWidgetsManager(object): def getWidget(self, class_, target=None, profiles=None): """Get a widget without creating it if it doesn't exist. - @param class_(class): class of the widget to create + @param class_: subclass of QuickWidget, same parameter as used in [getOrCreateWidget] @param target: target depending of the widget, usually a JID instance @param profiles (unicode, iterable[unicode], None): profile(s) to use (may or may not be used, depending of the widget class)