frappy.client.interactive: improve order of callbacks

the user would expect that updates are shown in the order
they appeared in the SECoP connection.
For this register_callback needs an additional parameter
to suppress initial callback.

Change-Id: Id1d7605d739b02ec799b3768ae2399558969c381
This commit is contained in:
zolliker 2024-09-23 14:53:55 +02:00
parent abfb8afdc5
commit ba2b5ac786
2 changed files with 11 additions and 7 deletions

View File

@ -188,7 +188,7 @@ class ProxyClient:
# caches (module, parameter) = value, timestamp, readerror (internal names!) # caches (module, parameter) = value, timestamp, readerror (internal names!)
self.cache = Cache() # dict returning Cache.undefined for missing keys self.cache = Cache() # dict returning Cache.undefined for missing keys
def register_callback(self, key, *args, **kwds): def register_callback(self, key, *args, callimmediately=None, **kwds):
"""register callback functions """register callback functions
- key might be either: - key might be either:
@ -206,7 +206,7 @@ class ProxyClient:
raise TypeError(f"unknown callback: {', '.join(kwds)}") raise TypeError(f"unknown callback: {', '.join(kwds)}")
# immediately call for some callback types # immediately call for some callback types
if cbname in ('updateItem', 'updateEvent'): if cbname in ('updateItem', 'updateEvent') and callimmediately is not False:
if key is None: # case generic callback if key is None: # case generic callback
cbargs = [(m, p, d) for (m, p), d in self.cache.items()] cbargs = [(m, p, d) for (m, p), d in self.cache.items()]
else: else:

View File

@ -216,14 +216,16 @@ class Module:
def __call__(self, target=None): def __call__(self, target=None):
if target is None: if target is None:
return self.read() return self.read()
for pname in 'value', 'status':
self._secnode.register_callback((self._name, pname),
callimmediately=False,
updateEvent=self._watch_parameter)
self.target = target # this sets self._is_driving self.target = target # this sets self._is_driving
type(self).value.prev = None # show at least one value
def loop(): def loop():
while self._is_driving: while self._is_driving:
self._driving_event.wait() self._driving_event.wait()
self._watch_parameter(self._name, 'value', mininterval=self._secnode.mininterval)
self._watch_parameter(self._name, 'status')
self._driving_event.clear() self._driving_event.clear()
try: try:
loop() loop()
@ -237,9 +239,11 @@ class Module:
pass pass
clientenv.raise_with_short_traceback(e) clientenv.raise_with_short_traceback(e)
finally: finally:
self._watch_parameter(self._name, 'status') # self._watch_parameter(self._name, 'status')
self._secnode.readParameter(self._name, 'value') self._secnode.readParameter(self._name, 'value')
self._watch_parameter(self._name, 'value', forced=True) # self._watch_parameter(self._name, 'value', forced=True)
self._secnode.unregister_callback((self._name, 'value'), updateEvent=self._watch_parameter)
self._secnode.unregister_callback((self._name, 'status'), updateEvent=self._watch_parameter)
return self.value return self.value
def __repr__(self): def __repr__(self):