connectors/WAMP/__init__.py
changeset 1739 ec153828ded2
parent 1736 7e61baa047f0
child 1740 b789b695b5c6
equal deleted inserted replaced
1738:d2e979738700 1739:ec153828ded2
    50         global _WampSession, _WampSessionEvent
    50         global _WampSession, _WampSessionEvent
    51         _WampSessionEvent.clear()
    51         _WampSessionEvent.clear()
    52         _WampSession = None
    52         _WampSession = None
    53         print 'WAMP session left'
    53         print 'WAMP session left'
    54 
    54 
    55 PLCObjDefaults = { "StartPLC": False,
    55 PLCObjDefaults = { "StartPLC":          False,
    56                    "GetTraceVariables" : ("Broken",None),
    56                    "GetTraceVariables": ("Broken", None),
    57                    "GetPLCstatus" : ("Broken",None),
    57                    "GetPLCstatus":      ("Broken", None),
    58                    "RemoteExec" : (-1, "RemoteExec script failed!")}
    58                    "RemoteExec":        (-1, "RemoteExec script failed!")}
    59 
    59 
    60 
    60 
    61 def WAMP_connector_factory(uri, confnodesroot):
    61 def WAMP_connector_factory(uri, confnodesroot):
    62     """
    62     """
    63     WAMP://127.0.0.1:12345/path#realm#ID
    63     WAMP://127.0.0.1:12345/path#realm#ID
   104 
   104 
   105     def WampSessionProcMapper(funcname):
   105     def WampSessionProcMapper(funcname):
   106         wampfuncname = '.'.join((ID,funcname))
   106         wampfuncname = '.'.join((ID,funcname))
   107         def catcher_func(*args,**kwargs):
   107         def catcher_func(*args,**kwargs):
   108             global _WampSession
   108             global _WampSession
   109             if _WampSession is not None :
   109             if _WampSession is not None:
   110                 try:
   110                 try:
   111                     return threads.blockingCallFromThread(
   111                     return threads.blockingCallFromThread(
   112                         reactor, _WampSession.call, wampfuncname,
   112                         reactor, _WampSession.call, wampfuncname,
   113                         *args,**kwargs)
   113                         *args,**kwargs)
   114                 except TransportLost, e:
   114                 except TransportLost, e:
   146                 member = WampSessionProcMapper(attrName)
   146                 member = WampSessionProcMapper(attrName)
   147                 self.__dict__[attrName] = member
   147                 self.__dict__[attrName] = member
   148             return member
   148             return member
   149 
   149 
   150     # Try to get the proxy object
   150     # Try to get the proxy object
   151     try :
   151     try:
   152         return WampPLCObjectProxy()
   152         return WampPLCObjectProxy()
   153     except Exception, msg:
   153     except Exception, msg:
   154         confnodesroot.logger.write_error(_("WAMP connection to '%s' failed.\n") % location)
   154         confnodesroot.logger.write_error(_("WAMP connection to '%s' failed.\n") % location)
   155         confnodesroot.logger.write_error(traceback.format_exc())
   155         confnodesroot.logger.write_error(traceback.format_exc())
   156         return None
   156         return None