svghmi/svghmi_server.py
branchsvghmi
changeset 2773 6e5e752372c8
parent 2772 3f1dd8312710
child 2774 9857b4b0d979
equal deleted inserted replaced
2772:3f1dd8312710 2773:6e5e752372c8
    13 from twisted.web.static import File
    13 from twisted.web.static import File
    14 
    14 
    15 from autobahn.twisted.websocket import WebSocketServerFactory, WebSocketServerProtocol
    15 from autobahn.twisted.websocket import WebSocketServerFactory, WebSocketServerProtocol
    16 from autobahn.twisted.resource import  WebSocketResource
    16 from autobahn.twisted.resource import  WebSocketResource
    17 
    17 
    18 # TODO session list lock
    18 # TODO multiclient :
    19 svghmi_sessions = []
    19 # session list lock
       
    20 # svghmi_sessions = []
       
    21 
       
    22 svghmi_session = None
    20 
    23 
    21 class HMISession(object):
    24 class HMISession(object):
    22     def __init__(self, protocol_instance):
    25     def __init__(self, protocol_instance):
    23         global svghmi_sessions
    26         global svghmi_session
    24         svghmi_sessions.append(self)
    27         
       
    28         # TODO: kill existing session for robustness
       
    29         assert(svghmi_session is None)
       
    30 
       
    31         svghmi_session = self
       
    32         self.protocol_instance = protocol_instance
    25 
    33 
    26         # TODO multiclient :
    34         # TODO multiclient :
       
    35         # svghmi_sessions.append(self)
    27         # get a unique bit index amont other svghmi_sessions,
    36         # get a unique bit index amont other svghmi_sessions,
    28         # so that we can match flags passed by C->python callback
    37         # so that we can match flags passed by C->python callback
    29     
    38     
    30     def __del__(self):
    39     def __del__(self):
    31         global svghmi_sessions
    40         global svghmi_session
    32         svghmi_sessions.remove(self)
    41         assert(svghmi_session)
       
    42         svghmi_session = None
       
    43 
       
    44         # TODO multiclient :
       
    45         # svghmi_sessions.remove(self)
    33 
    46 
    34     def onMessage(self, msg):
    47     def onMessage(self, msg):
    35         # TODO :  pass it to the C side recieve_message()
    48         # TODO :  pass it to the C side recieve_message()
    36         #    update HMITree
    49         #    update HMITree
    37         #        - values
    50         #        - values