137 # lambda is for getattr of GetPLCstatus to happen inside catcher |
137 # lambda is for getattr of GetPLCstatus to happen inside catcher |
138 if PyroCatcher(RemotePLCObjectProxy.GetPLCstatus)() is None: |
138 if PyroCatcher(RemotePLCObjectProxy.GetPLCstatus)() is None: |
139 confnodesroot.logger.write_error(_("Cannot get PLC status - connection failed.\n")) |
139 confnodesroot.logger.write_error(_("Cannot get PLC status - connection failed.\n")) |
140 return None |
140 return None |
141 |
141 |
|
142 _special_return_funcs = { |
|
143 "StartPLC": False, |
|
144 "GetTraceVariables": ("Broken", None), |
|
145 "GetPLCstatus": ("Broken", None), |
|
146 "RemoteExec": (-1, "RemoteExec script failed!") |
|
147 } |
142 class PyroProxyProxy(object): |
148 class PyroProxyProxy(object): |
143 """ |
149 """ |
144 A proxy proxy class to handle Beremiz Pyro interface specific behavior. |
150 A proxy proxy class to handle Beremiz Pyro interface specific behavior. |
145 And to put Pyro exception catcher in between caller and Pyro proxy |
151 And to put Pyro exception catcher in between caller and Pyro proxy |
146 """ |
152 """ |
147 def __init__(self): |
|
148 # for safe use in from debug thread, must create a copy |
|
149 self.RemotePLCObjectProxyCopy = None |
|
150 |
|
151 def _PyroStartPLC(self, *args, **kwargs): |
|
152 return RemotePLCObjectProxy.StartPLC(*args, **kwargs) |
|
153 StartPLC = PyroCatcher(_PyroStartPLC, False) |
|
154 |
|
155 def _PyroGetTraceVariables(self): |
|
156 """ |
|
157 for use from debug thread, use a copy |
|
158 pyro creates a new thread on server end proxy object is copied |
|
159 """ |
|
160 if self.RemotePLCObjectProxyCopy is None: |
|
161 self.RemotePLCObjectProxyCopy = copy.copy(RemotePLCObjectProxy) |
|
162 return self.RemotePLCObjectProxyCopy.GetTraceVariables() |
|
163 GetTraceVariables = PyroCatcher(_PyroGetTraceVariables, ("Broken", None)) |
|
164 |
|
165 def _PyroGetPLCstatus(self): |
|
166 return RemotePLCObjectProxy.GetPLCstatus() |
|
167 GetPLCstatus = PyroCatcher(_PyroGetPLCstatus, ("Broken", None)) |
|
168 |
|
169 def _PyroRemoteExec(self, script, **kwargs): |
|
170 return RemotePLCObjectProxy.RemoteExec(script, **kwargs) |
|
171 RemoteExec = PyroCatcher(_PyroRemoteExec, (-1, "RemoteExec script failed!")) |
|
172 |
|
173 def __getattr__(self, attrName): |
153 def __getattr__(self, attrName): |
174 member = self.__dict__.get(attrName, None) |
154 member = self.__dict__.get(attrName, None) |
175 if member is None: |
155 if member is None: |
176 def my_local_func(*args, **kwargs): |
156 def my_local_func(*args, **kwargs): |
177 return RemotePLCObjectProxy.__getattr__(attrName)(*args, **kwargs) |
157 return RemotePLCObjectProxy.__getattr__(attrName)(*args, **kwargs) |
178 member = PyroCatcher(my_local_func, None) |
158 member = PyroCatcher(my_local_func, _special_return_funcs.get(attrName, None)) |
179 self.__dict__[attrName] = member |
159 self.__dict__[attrName] = member |
180 return member |
160 return member |
181 |
161 |
182 return PyroProxyProxy() |
162 return PyroProxyProxy() |