runtime/WampClient.py
changeset 1446 4963e3816641
parent 1445 e25479e3fe11
child 1511 91538d0c242c
equal deleted inserted replaced
1445:e25479e3fe11 1446:4963e3816641
    25                 "RemoteExec",
    25                 "RemoteExec",
    26                 "GetLogMessage",
    26                 "GetLogMessage",
    27                 "ResetLogCount",
    27                 "ResetLogCount",
    28                 ]
    28                 ]
    29 
    29 
       
    30 SubscribedEvents = []
       
    31 
       
    32 DoOnJoin = []
       
    33 
    30 def GetCallee(name):
    34 def GetCallee(name):
       
    35     """ Get Callee or Subscriber corresponding to '.' spearated object path """
    31     global _PySrv
    36     global _PySrv
    32     names = name.split('.')
    37     names = name.split('.')
    33     obj = _PySrv.plcobj
    38     obj = _PySrv.plcobj
    34     while names: obj = getattr(obj, names.pop(0))
    39     while names: obj = getattr(obj, names.pop(0))
    35     return obj
    40     return obj
    43         ID = self.config.extra["ID"]
    48         ID = self.config.extra["ID"]
    44         print 'WAMP session joined by :', ID
    49         print 'WAMP session joined by :', ID
    45         for name in ExposedCalls:
    50         for name in ExposedCalls:
    46             reg = yield self.register(GetCallee(name), '.'.join((ID,name)))
    51             reg = yield self.register(GetCallee(name), '.'.join((ID,name)))
    47 
    52 
       
    53         for name in SubscribedEvents:
       
    54             reg = yield self.subscribe(GetCallee(name), name)
       
    55 
       
    56         for func in DoOnJoin:
       
    57             yield func(self)
       
    58 
    48     def onLeave(self, details):
    59     def onLeave(self, details):
    49         global _WampSession
    60         global _WampSession
    50         _WampSession = None
    61         _WampSession = None
    51         print 'WAMP session left'
    62         print 'WAMP session left'
    52 
    63 
    56         self.retry(connector)
    67         self.retry(connector)
    57     def clientConnectionLost(self, connector, reason):
    68     def clientConnectionLost(self, connector, reason):
    58         print("WAMP Client connection lost .. retrying ..")
    69         print("WAMP Client connection lost .. retrying ..")
    59         self.retry(connector)
    70         self.retry(connector)
    60 
    71 
       
    72 def LoadWampClientConf(wampconf):
       
    73 
       
    74     WSClientConf = json.load(open(wampconf))
       
    75     return WSClientConf
       
    76 
    61 def RegisterWampClient(wampconf):
    77 def RegisterWampClient(wampconf):
    62 
    78 
    63     WSClientConf = json.load(open(wampconf))
    79     WSClientConf = LoadWampClientConf(wampconf)
    64 
    80 
    65     ## start logging to console
    81     ## start logging to console
    66     # log.startLogging(sys.stdout)
    82     # log.startLogging(sys.stdout)
    67 
    83 
    68     # create a WAMP application session factory
    84     # create a WAMP application session factory