runtime/WampClient.py
changeset 1445 e25479e3fe11
parent 1443 ff8a22d45c44
child 1446 4963e3816641
equal deleted inserted replaced
1444:c162f1b0fbac 1445:e25479e3fe11
    25                 "RemoteExec",
    25                 "RemoteExec",
    26                 "GetLogMessage",
    26                 "GetLogMessage",
    27                 "ResetLogCount",
    27                 "ResetLogCount",
    28                 ]
    28                 ]
    29 
    29 
    30 def MakeCallee(name):
    30 def GetCallee(name):
    31     global _PySrv
    31     global _PySrv
    32     def Callee(*args,**kwargs):
    32     names = name.split('.')
    33         return getattr(_PySrv.plcobj, name)(*args,**kwargs)
    33     obj = _PySrv.plcobj
    34     return Callee
    34     while names: obj = getattr(obj, names.pop(0))
    35 
    35     return obj
    36 
    36 
    37 class WampSession(wamp.ApplicationSession):
    37 class WampSession(wamp.ApplicationSession):
    38 
    38 
    39     @inlineCallbacks
    39     @inlineCallbacks
    40     def onJoin(self, details):
    40     def onJoin(self, details):
    41         global _WampSession
    41         global _WampSession
    42         _WampSession = self
    42         _WampSession = self
    43         ID = self.config.extra["ID"]
    43         ID = self.config.extra["ID"]
    44         print 'WAMP session joined by :', ID
    44         print 'WAMP session joined by :', ID
    45         for name in ExposedCalls:
    45         for name in ExposedCalls:
    46             reg = yield self.register(MakeCallee(name), '.'.join((ID,name)))
    46             reg = yield self.register(GetCallee(name), '.'.join((ID,name)))
    47 
    47 
    48     def onLeave(self, details):
    48     def onLeave(self, details):
    49         global _WampSession
    49         global _WampSession
    50         _WampSession = None
    50         _WampSession = None
    51         print 'WAMP session left'
    51         print 'WAMP session left'