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:
parent
abfb8afdc5
commit
ba2b5ac786
@ -188,7 +188,7 @@ class ProxyClient:
|
||||
# caches (module, parameter) = value, timestamp, readerror (internal names!)
|
||||
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
|
||||
|
||||
- key might be either:
|
||||
@ -206,7 +206,7 @@ class ProxyClient:
|
||||
raise TypeError(f"unknown callback: {', '.join(kwds)}")
|
||||
|
||||
# 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
|
||||
cbargs = [(m, p, d) for (m, p), d in self.cache.items()]
|
||||
else:
|
||||
|
@ -216,14 +216,16 @@ class Module:
|
||||
def __call__(self, target=None):
|
||||
if target is None:
|
||||
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
|
||||
type(self).value.prev = None # show at least one value
|
||||
|
||||
def loop():
|
||||
while self._is_driving:
|
||||
self._driving_event.wait()
|
||||
self._watch_parameter(self._name, 'value', mininterval=self._secnode.mininterval)
|
||||
self._watch_parameter(self._name, 'status')
|
||||
self._driving_event.clear()
|
||||
try:
|
||||
loop()
|
||||
@ -237,9 +239,11 @@ class Module:
|
||||
pass
|
||||
clientenv.raise_with_short_traceback(e)
|
||||
finally:
|
||||
self._watch_parameter(self._name, 'status')
|
||||
# self._watch_parameter(self._name, 'status')
|
||||
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
|
||||
|
||||
def __repr__(self):
|
||||
|
Loading…
x
Reference in New Issue
Block a user