nx_server_plugin_sdk 1.0 Server Plugin SDK

device_agent.h
1 // Copyright 2018-present Network Optix, Inc. Licensed under MPL 2.0: www.mozilla.org/MPL/2.0/
2
3 #pragma once
4
5 #include <atomic>
6 #include <condition_variable>
7 #include <memory>
8 #include <string>
9 #include <thread>
10 #include <vector>
11
12 #include <nx/sdk/analytics/i_event_metadata.h>
13 #include <nx/sdk/analytics/helpers/consuming_device_agent.h>
14
15 #include "engine.h"
16 #include "stub_analytics_plugin_events_ini.h"
17
18 namespace nx {
19 namespace vms_server_plugins {
20 namespace analytics {
21 namespace stub {
22 namespace events {
23
24 const std::string kDeclareAdditionalEventTypesSetting = "declareAdditionalEventTypesSetting";
25 const std::string kGenerateEventsSetting = "generateEvents";
26
27 class DeviceAgent: public nx::sdk::analytics::ConsumingDeviceAgent
28 {
29 public:
30 DeviceAgent(Engine* engine, const nx::sdk::IDeviceInfo* deviceInfo);
31 virtual ~DeviceAgent() override;
32
33 protected:
34 virtual void doSetNeededMetadataTypes(
35 nx::sdk::Result<void>* outValue,
36 const nx::sdk::analytics::IMetadataTypes* neededMetadataTypes) override;
37
38 virtual std::string manifestString() const override;
39
40 virtual nx::sdk::Result<const nx::sdk::ISettingsResponse*> settingsReceived() override;
41
42 private:
43 nx::sdk::Ptr<nx::sdk::analytics::IMetadataPacket> cookSomeEvents();
44 nx::sdk::Ptr<nx::sdk::analytics::IEventMetadata> createEventWithImage();
45 int64_t usSinceEpoch() const;
46 void startFetchingMetadata(const nx::sdk::analytics::IMetadataTypes* metadataTypes);
47 void stopFetchingMetadata();
48 void parseSettings();
49 void eventThreadLoop();
50 void startEventThread();
51 void stopEventThread();
52
53 private:
54 Engine* const m_engine;
55
56 std::unique_ptr<std::thread> m_eventThread;
57 std::mutex m_eventThreadMutex;
58 std::condition_variable m_eventThreadCondition;
59 std::atomic<bool> m_terminated{false};
60 std::atomic<bool> m_needToGenerateEvents{false};
61 std::string m_eventTypeId;
62
63 struct DeviceAgentSettings
64 {
65 std::atomic<bool> declareAdditionalEventTypes{false};
66 std::atomic<bool> generateEvents{true};
67 };
68
69 DeviceAgentSettings m_deviceAgentSettings;
70
71 struct EventContext
72 {
73 int currentEventTypeIndex = 0;
74 float imageX = 0;
75 float imageY = 0;
76 };
77
78 EventContext m_eventContext;
79 };
80
81 const std::string kLineCrossingEventType = "nx.stub.lineCrossing";
82 const std::string kObjectInTheAreaEventType = "nx.stub.objectInTheArea";
83 const std::string kLoiteringEventType = "nx.stub.loitering";
84 const std::string kIntrusionEventType = "nx.stub.intrusion";
85 const std::string kGunshotEventType = "nx.stub.gunshot";
86 const std::string kSuspiciousNoiseEventType = "nx.stub.suspiciousNoise";
87 const std::string kSoundRelatedEventGroup = "nx.stub.soundRelated";
88 const std::string kAdditionalEventType = "nx.stub.additionalEvent1";
89 const std::string kAdditionalEventType2 = "nx.stub.additionalEvent2";
90 const std::string kEventWithImageEventType = "nx.stub.eventWithImage";
91
92 } // namespace events
93 } // namespace stub
94 } // namespace analytics
95 } // namespace vms_server_plugins
96 } // namespace nx
nx::vms_server_plugins::analytics::stub::events::DeviceAgent::settingsReceived
virtual nx::sdk::Result< const nx::sdk::ISettingsResponse * > settingsReceived() override
Definition: device_agent.cpp:221
nx::sdk::Ptr
Definition: ptr.h:18
nx::sdk::analytics::ConsumingDeviceAgent
Definition: consuming_device_agent.h:36
nx::sdk::analytics::IMetadataTypes
Definition: i_metadata_types.h:10
nx::sdk::Result< void >
Definition: result.h:86
nx::sdk::IDeviceInfo
Definition: i_device_info.h:13
nx::vms_server_plugins::analytics::stub::events::DeviceAgent
Definition: device_agent.h:27
nx::sdk::Result
Definition: result.h:52
nx
Definition: apple_utils.h:6
nx::vms_server_plugins::analytics::stub::events::DeviceAgent::manifestString
virtual std::string manifestString() const override
Definition: device_agent.cpp:162
nx::vms_server_plugins::analytics::stub::events::Engine
Definition: engine.h:22