connectors/PYRO/__init__.py
changeset 361 331d698e1118
parent 354 ff721067a75c
child 399 77e23bf04c33
equal deleted inserted replaced
360:32339ad7d9ae 361:331d698e1118
    26 
    26 
    27 def PYRO_connector_factory(uri, pluginsroot):
    27 def PYRO_connector_factory(uri, pluginsroot):
    28     """
    28     """
    29     This returns the connector to Pyro style PLCobject
    29     This returns the connector to Pyro style PLCobject
    30     """
    30     """
    31     pluginsroot.logger.write("Connecting to URI : %s\n"%uri)
    31     pluginsroot.logger.write(_("Connecting to URI : %s\n")%uri)
    32 
    32 
    33     servicetype, location = uri.split("://")
    33     servicetype, location = uri.split("://")
    34     
    34     
    35     # Try to get the proxy object
    35     # Try to get the proxy object
    36     try :
    36     try :
    37         RemotePLCObjectProxy = pyro.getAttrProxyForURI("PYROLOC://"+location+"/PLCObject")
    37         RemotePLCObjectProxy = pyro.getAttrProxyForURI("PYROLOC://"+location+"/PLCObject")
    38     except Exception, msg:
    38     except Exception, msg:
    39         pluginsroot.logger.write_error("Wrong URI, please check it !\n")
    39         pluginsroot.logger.write_error(_("Wrong URI, please check it !\n"))
    40         pluginsroot.logger.write_error(traceback.format_exc())
    40         pluginsroot.logger.write_error(traceback.format_exc())
    41         return None
    41         return None
    42 
    42 
    43     def PyroCatcher(func, default=None):
    43     def PyroCatcher(func, default=None):
    44         """
    44         """
    56         return catcher_func
    56         return catcher_func
    57 
    57 
    58     # Check connection is effective. 
    58     # Check connection is effective. 
    59     # lambda is for getattr of GetPLCstatus to happen inside catcher
    59     # lambda is for getattr of GetPLCstatus to happen inside catcher
    60     if PyroCatcher(lambda:RemotePLCObjectProxy.GetPLCstatus())() == None:
    60     if PyroCatcher(lambda:RemotePLCObjectProxy.GetPLCstatus())() == None:
    61         pluginsroot.logger.write_error("Cannot get PLC status - connection failed.\n")
    61         pluginsroot.logger.write_error(_("Cannot get PLC status - connection failed.\n"))
    62         return None
    62         return None
    63 
    63 
    64 
    64 
    65     class PyroProxyProxy:
    65     class PyroProxyProxy:
    66         """
    66         """
    88             if pluginsroot._connector.GetPyroProxy().GetPLCstatus() == "Dirty":
    88             if pluginsroot._connector.GetPyroProxy().GetPLCstatus() == "Dirty":
    89                 """
    89                 """
    90                 Some bad libs with static symbols may polute PLC
    90                 Some bad libs with static symbols may polute PLC
    91                 ask runtime to suicide and come back again
    91                 ask runtime to suicide and come back again
    92                 """
    92                 """
    93                 pluginsroot.logger.write("Force runtime reload\n")
    93                 pluginsroot.logger.write(_("Force runtime reload\n"))
    94                 pluginsroot._connector.GetPyroProxy().ForceReload()
    94                 pluginsroot._connector.GetPyroProxy().ForceReload()
    95                 pluginsroot._Disconnect()
    95                 pluginsroot._Disconnect()
    96                 # let remote PLC time to resurect.(freeze app)
    96                 # let remote PLC time to resurect.(freeze app)
    97                 sleep(0.5)
    97                 sleep(0.5)
    98                 pluginsroot._Connect()
    98                 pluginsroot._Connect()