How To Run Some Code When Plugin Is Enabled For a Camera or Disabled For One
AnsweredI want to execute some actions (make HTTP requests) whenever my plugin is enabled for a particular camera and whenever it's disabled for a camera.
I know that the Engine acts as a factory of DeviceAgents, which are like workers assigned one to each camera.
So I'm guessing I'd have to implement some method in engine.cpp?
And in this method call some way to get the id and name of the camera being enabled or disabled.
The thing is that I'd like this method to be called just once when any camera is enabled, and just once when any camera is disabled. Not every time the server starts and the plugin is reloaded.
-
Hello Usama,
server handles enabling/disabling analytics engine on camera outside of plugin's scope. Because of that, distinguishing server restart and disable/enable from the plugin settings is tricky, and it might overcomplicate things. Could you please describe why it is important for you not to execute your HTTP request upon server restart? Perhaps, we'll be able to find a different solution for your task.
>So I'm guessing I'd have to implement some method in engine.cpp?
You can add HTTP call in the DeviceAgent constructor and destructor functions in deviceagent.cpp. However, as I mentioned, it won't be possible to ignore server restart from there.
1 -
Hey Anton Babinov
I'm basically trying to add/delete entries corresponding to the cameras on the remote server.
So, yes, sending a create request on DeviceAgent constructor is fine since I can just check on the remote server whether the camera already exists or not, and not re-add it.
But, sending a delete request in the DeviceAgent destructor could mean deleting cameras on the remote server unintentionally. The destructor will always be called when the DeviceAgent worker is about to go out of memory, like on server restart. Not just when it is disabled.0 -
>But, sending a delete request in the DeviceAgent destructor could mean deleting cameras on the remote >server unintentionally. The destructor will always be called when the DeviceAgent worker is about to go out >of memory, like on server restart. Not just when it is disabled.
I suggest marking camera as offline without deleting it from the remote system. I think it would be the most simple solution for your case.
0
Please sign in to leave a comment.
Comments
3 comments