diff --git a/base.py b/base.py index c0eb505..fb31d77 100644 --- a/base.py +++ b/base.py @@ -41,6 +41,8 @@ class HandlerBase: class Client(HandlerBase): + dictionary = {} # dict (kind, uri) of node + def __init__(self, server, streams, instrument_name, device_name): super().__init__() self.id = uuid.uuid4().hex[0:15] @@ -50,7 +52,18 @@ class Client(HandlerBase): for uri in streams: urisplit = uri.rsplit('://') kind = urisplit[0] if len(urisplit) == 2 else 'secop' - node = server.interactor_classes[kind](uri, self.node_map) + + node = self.dictionary.get((kind, uri)) + + if node is None: + + def change_callback(dictionary=self.dictionary, kind_uri=(kind, uri)): + dictionary.pop(kind_uri, None) + + node = server.interactor_classes[kind](uri, self.node_map, change_callback) + + self.dictionary[kind, uri] = node + self.nodes[uri] = node self.server = server self.instrument_name = instrument_name diff --git a/client/jsFiles/SEAWebClientCommunication.js b/client/jsFiles/SEAWebClientCommunication.js index b807388..9cd9280 100644 --- a/client/jsFiles/SEAWebClientCommunication.js +++ b/client/jsFiles/SEAWebClientCommunication.js @@ -313,7 +313,7 @@ function reqJSON(s, url, successHandler, errorHandler) { : new ActiveXObject('Microsoft.XMLHTTP'); if (debugCommunication) { console.log("%cto server (reqJSON): %s", - "color:white;background:darkgreen", url); + "background:yellow", url); } xhr.open('get', url, true); xhr.onreadystatechange = function() { diff --git a/secop-webserver b/secop-webserver index 35748e2..75d6476 100755 --- a/secop-webserver +++ b/secop-webserver @@ -1,9 +1,9 @@ #!/usr/bin/env python import sys -from os.path import expanduser -# look for sehistory and frappy at usual locations in home directory -sys.path.extend([expanduser('~'), expanduser('~/frappy')]) +# look for sehistory and frappy +sys.path.extend(['/sq_sw/linse', '/sq_sw/linse/frappy']) + import argparse from webserver import server from base import Client diff --git a/secop.py b/secop.py index c14ac09..0614aaf 100644 --- a/secop.py +++ b/secop.py @@ -49,18 +49,23 @@ class SecopInteractor(SecopClient): hide_par = ["baseclass", "class", "pollinterval"] skip_par = ["status2"] - def __init__(self, uri, node_map): + def __init__(self, uri, node_map, change_callback=None): super().__init__(uri) self.module_updates = set() self.param_updates = set() self.updates = {} + self.change_callback = change_callback try: self.connect() node_map.update({k: self for k in self.modules}) - self.register_callback(None, updateItem=self.updateItem) + self.register_callback(None, updateItem=self.updateItem, descriptiveDataChange=self.descChanged) except Exception as e: print(repr(e)) + def descChanged(self, module, desc): + if module is None and self.change_callback: + self.change_callback() + def add_main_components(self, components): for name, desc in self.modules.items(): parameters = desc['parameters']