How To Access Configurable Values In DeviceAgent?
AnsweredHi,
In plugin.cpp we define a manifestString that contains an
engineSettingsModel with different configurable value that the user can change in System Administration -> Plugins.
I was wondering how we can access these value in deviceagent?
-
Hi Usama,
device agent can have individual setting model accessible in Camera Settings -> Plugin. If you want to access engine's setting from inside device agent, you can store pointer to the engine in your device agent and implement function inside your engine to receive required values.
Check my example below. For your device agent class:
DeviceAgent(Engine* engine, const nx::sdk::IDeviceInfo* deviceInfo);
Engine* const m_engine;
DeviceAgent::DeviceAgent(Engine* engine, const nx::sdk::IDeviceInfo* deviceInfo):
ConsumingDeviceAgent(deviceInfo, NX_DEBUG_ENABLE_OUTPUT),
m_engine(engine)
{
m_pluginDiagnosticEventThread =
std::make_unique<std::thread>([this]() { processPluginDiagnosticEvents(); });
m_eventThread = std::make_unique<std::thread>([this]() { processEvents(); });
}For your engine class:
void Engine::doObtainDeviceAgent(Result<IDeviceAgent*>* outResult, const IDeviceInfo* deviceInfo)
{
*outResult = new DeviceAgent(this, deviceInfo);
}bool getSettingCheckbox() const { return m_SomeCheckBox};Then you can use checkbox state from System Administration -> Plugins somewhere in your device agent code:
if (m_engine->getSettingCheckbox)
do_something()0 -
Hey Anton Babinov
Thanks very much for your answer. I'm trying it out right now and it seems promising.
Of course m_SomeCheckBox is undefined. I have some text fields and some number SpinBoxes in my engine settings models.
How can I access them in Engine?0 -
Could you please give more details on your parameters and how you plan to use them? How do you store those text fields and numbers in your engine?
In general, you can implement getEngineSettings() function in your engine.cpp and then use it from DeviceAgent instance to read settings. As another approach you can implement different method for each setting value, for example getNumber1(), getString1()...
0 -
Hey Anton Babinov
My engineSettings are like this:"engineSettingsModel": {
"type": "Settings",
"items": [
{
"type": "GroupBox",
"caption": "Calipsa configuration",
"items": [
{
"type": "TextField",
"name": "calipsa_host",
"caption": "Calipsa host",
"description": "Calipsa's external host",
"defaultValue": "https://dw.calipsa.info"
},
{
"type": "SpinBox",
"name": "calipsa_port",
"caption": "Calipsa's external port number",
"description": "Calipsa port",
"defaultValue": 443,
"minValue": 0,
"maxValue": 66000
},
{
"type": "TextField",
"name": "calipsa_auth_token",
"caption": "Calipsa authentication token",
"description": "Please obtain this from Calipsa to enable plugin functionality.",
"defaultValue": ""
},
{
"type": "Separator"
},
{
"type": "SpinBox",
"name": "calipsa_number_of_frames",
"caption": "Number of frames",
"description": "The number of frames to send to Calipsa for analysis per event.",
"defaultValue": 3,
"minValue": 1,
"maxValue": 6
},
{
"type": "SpinBox",
"name": "calipsa_number_of_tries",
"caption": "Number of tries",
"description": "The number of times the plugin will try to connect to Calipsa per event. If all tries fail, the event will by default be considered a true alarm.",
"defaultValue": 2,
"minValue": 0,
"maxValue": 3
},
{
"type": "SpinBox",
"name": "calipsa_timeout_seconds",
"caption": "Timeout per try (seconds)",
"description": "Timeout per try (seconds).",
"defaultValue": 25,
"minValue": 2,
"maxValue": 60
}
]
}
]
}
And for now that's it. I don't have any class variables yet in my Engine that point to the values of these textboxes, spinboxes etc. I guess what I want to know is how to do exactly this; how to link variables in my Engine class to the values of the items in the Engine Settings.
Thank you!0 -
You need to define variables in your engine to handle these settings. In your settings_model.h
const std::string kCalipsaHost{"calipsa_host"};Your engineSettingsModel for calipsa_host should looks like this:
{
"type": "TextField",
"name": ")json" + kCalipsaHost R"json(",
"caption": "Calipsa host",
"description": "Calipsa's external host",
"defaultValue": "https://dw.calipsa.info"
},Define private variable to store host value in your engine.h:
std::string m_CalipsaHost;
Read value of your parameter in settingsReceived() of your engine.cpp:
Result<const ISettingsResponse*> Engine::settingsReceived()
{
m_CalipsaHost = settingValue(kCalipsaHost);
.........
}Now you can use m_CalipsaHost as any other variable in your engine.cpp.
As next step, implement simple getSettings function for your engine:
std:string getCalipsaHost() const { return m_CalipsaHost};
Assuming you have pointer to your engine class in your device agent, you can use m_engine->getCalipsaHost() to get the value of Calipsa Host text field from plugin settings in your device agent class.
0
Please sign in to leave a comment.
Comments
5 comments