# HG changeset patch # User Edouard Tisserant # Date 1568285732 -7200 # Node ID 6e5e752372c838501dec26ea02cc602c405c290b # Parent 3f1dd831271043fbb50a301838de4489de4973cb SVGHMI: single session for now diff -r 3f1dd8312710 -r 6e5e752372c8 svghmi/svghmi_server.py --- a/svghmi/svghmi_server.py Thu Sep 12 12:54:36 2019 +0200 +++ b/svghmi/svghmi_server.py Thu Sep 12 12:55:32 2019 +0200 @@ -15,21 +15,34 @@ from autobahn.twisted.websocket import WebSocketServerFactory, WebSocketServerProtocol from autobahn.twisted.resource import WebSocketResource -# TODO session list lock -svghmi_sessions = [] +# TODO multiclient : +# session list lock +# svghmi_sessions = [] + +svghmi_session = None class HMISession(object): def __init__(self, protocol_instance): - global svghmi_sessions - svghmi_sessions.append(self) + global svghmi_session + + # TODO: kill existing session for robustness + assert(svghmi_session is None) + + svghmi_session = self + self.protocol_instance = protocol_instance # TODO multiclient : + # svghmi_sessions.append(self) # get a unique bit index amont other svghmi_sessions, # so that we can match flags passed by C->python callback def __del__(self): - global svghmi_sessions - svghmi_sessions.remove(self) + global svghmi_session + assert(svghmi_session) + svghmi_session = None + + # TODO multiclient : + # svghmi_sessions.remove(self) def onMessage(self, msg): # TODO : pass it to the C side recieve_message()