equal
deleted
inserted
replaced
42 _WampSessionEvent = Event() |
42 _WampSessionEvent = Event() |
43 |
43 |
44 |
44 |
45 class WampSession(wamp.ApplicationSession): |
45 class WampSession(wamp.ApplicationSession): |
46 def onJoin(self, details): |
46 def onJoin(self, details): |
47 global _WampSession, _WampSessionEvent |
47 global _WampSession |
48 _WampSession = self |
48 _WampSession = self |
49 _WampSessionEvent.set() |
49 _WampSessionEvent.set() |
50 print('WAMP session joined for :', self.config.extra["ID"]) |
50 print('WAMP session joined for :', self.config.extra["ID"]) |
51 |
51 |
52 def onLeave(self, details): |
52 def onLeave(self, details): |
53 global _WampSession, _WampSessionEvent |
53 global _WampSession |
54 _WampSessionEvent.clear() |
54 _WampSessionEvent.clear() |
55 _WampSession = None |
55 _WampSession = None |
56 print('WAMP session left') |
56 print('WAMP session left') |
57 |
57 |
58 |
58 |
111 |
111 |
112 def WampSessionProcMapper(funcname): |
112 def WampSessionProcMapper(funcname): |
113 wampfuncname = '.'.join((ID, funcname)) |
113 wampfuncname = '.'.join((ID, funcname)) |
114 |
114 |
115 def catcher_func(*args, **kwargs): |
115 def catcher_func(*args, **kwargs): |
116 global _WampSession |
|
117 if _WampSession is not None: |
116 if _WampSession is not None: |
118 try: |
117 try: |
119 return threads.blockingCallFromThread( |
118 return threads.blockingCallFromThread( |
120 reactor, _WampSession.call, wampfuncname, |
119 reactor, _WampSession.call, wampfuncname, |
121 *args, **kwargs) |
120 *args, **kwargs) |
130 return PLCObjDefaults.get(funcname) |
129 return PLCObjDefaults.get(funcname) |
131 return catcher_func |
130 return catcher_func |
132 |
131 |
133 class WampPLCObjectProxy(object): |
132 class WampPLCObjectProxy(object): |
134 def __init__(self): |
133 def __init__(self): |
135 global _WampSessionEvent, _WampConnection |
134 global _WampConnection |
136 if not reactor.running: |
135 if not reactor.running: |
137 Thread(target=ThreadProc).start() |
136 Thread(target=ThreadProc).start() |
138 else: |
137 else: |
139 _WampConnection = threads.blockingCallFromThread( |
138 _WampConnection = threads.blockingCallFromThread( |
140 reactor, RegisterWampClient) |
139 reactor, RegisterWampClient) |
141 if not _WampSessionEvent.wait(5): |
140 if not _WampSessionEvent.wait(5): |
142 _WampConnection = stopConnecting() |
141 _WampConnection = stopConnecting() |
143 raise Exception(_("WAMP connection timeout")) |
142 raise Exception(_("WAMP connection timeout")) |
144 |
143 |
145 def __del__(self): |
144 def __del__(self): |
146 global _WampConnection |
|
147 _WampConnection.disconnect() |
145 _WampConnection.disconnect() |
148 # |
146 # |
149 # reactor.stop() |
147 # reactor.stop() |
150 |
148 |
151 def __getattr__(self, attrName): |
149 def __getattr__(self, attrName): |