diff -r e4ab768170f9 -r db68cb0e6bdc runtime/PLCObject.py --- a/runtime/PLCObject.py Thu May 28 11:01:42 2020 +0100 +++ b/runtime/PLCObject.py Thu May 28 11:15:22 2020 +0100 @@ -99,6 +99,9 @@ self.TraceLock = Lock() self.Traces = [] self.DebugToken = 0 + # Callbacks used by web settings extensions (e.g.: BACnet_config.py, Modbus_config.py) + self.LoadCallbacks = {} # list of functions to call when PLC is loaded + self.UnLoadCallbacks = {} # list of functions to call when PLC is unloaded self._init_blobs() @@ -167,6 +170,22 @@ return self._loading_error, 0, 0, 0 return None + def RegisterCallbackLoad(self, ExtensionName, ExtensionCallback): + """ + Register function to be called when PLC is loaded + ExtensionName: a string with the name of the extension asking to register the callback + ExtensionCallback: the function to be called... + """ + self.LoadCallbacks[ExtensionName] = ExtensionCallback + + def RegisterCallbackUnLoad(self, ExtensionName, ExtensionCallback): + """ + Register function to be called when PLC is unloaded + ExtensionName: a string with the name of the extension asking to register the callback + ExtensionCallback: the function to be called... + """ + self.UnLoadCallbacks[ExtensionName] = ExtensionCallback + def _GetMD5FileName(self): return os.path.join(self.workingdir, "lasttransferedPLC.md5") @@ -270,6 +289,8 @@ res = self._LoadPLC() if res: self.PythonRuntimeInit() + for name, callbackFunc in self.LoadCallbacks.items(): + callbackFunc() else: self._FreePLC() @@ -278,6 +299,8 @@ @RunInMain def UnLoadPLC(self): self.PythonRuntimeCleanup() + for name, callbackFunc in self.UnLoadCallbacks.items(): + callbackFunc() self._FreePLC() def _InitPLCStubCalls(self):