nx_metadata_sdk 1.0 Metadata 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/helpers/consuming_device_agent.h>
13
14 #include "engine.h"
15 #include "stub_analytics_plugin_events_ini.h"
16
17 namespace nx {
18 namespace vms_server_plugins {
19 namespace analytics {
20 namespace stub {
21 namespace events {
22
23 const std::string kDeclareAdditionalEventTypesSetting = "declareAdditionalEventTypesSetting";
24 const std::string kGenerateEventsSetting = "generateEvents";
25
26 class DeviceAgent: public nx::sdk::analytics::ConsumingDeviceAgent
27 {
28 public:
29 DeviceAgent(Engine* engine, const nx::sdk::IDeviceInfo* deviceInfo);
30 virtual ~DeviceAgent() override;
31
32 protected:
33 virtual void doSetNeededMetadataTypes(
34 nx::sdk::Result<void>* outValue,
35 const nx::sdk::analytics::IMetadataTypes* neededMetadataTypes) override;
36
37 virtual std::string manifestString() const override;
38
39 virtual nx::sdk::Result<const nx::sdk::ISettingsResponse*> settingsReceived() override;
40
41 private:
42 nx::sdk::analytics::IMetadataPacket* cookSomeEvents();
43 int64_t usSinceEpoch() const;
44 void startFetchingMetadata(const nx::sdk::analytics::IMetadataTypes* metadataTypes);
45 void stopFetchingMetadata();
46 void parseSettings();
47 void eventThreadLoop();
48 void startEventThread();
49 void stopEventThread();
50
51 private:
52 Engine* const m_engine;
53
54 std::unique_ptr<std::thread> m_eventThread;
55 std::mutex m_eventThreadMutex;
56 std::condition_variable m_eventThreadCondition;
57 std::atomic<bool> m_terminated{false};
58 std::atomic<bool> m_needToGenerateEvents{false};
59 std::string m_eventTypeId;
60
61 struct DeviceAgentSettings
62 {
63 std::atomic<bool> declareAdditionalEventTypes{false};
64 std::atomic<bool> generateEvents{true};
65 };
66
67 DeviceAgentSettings m_deviceAgentSettings;
68
69 struct EventContext
70 {
71 int currentEventTypeIndex = 0;
72 };
73
74 EventContext m_eventContext;
75 };
76
77 const std::string kLineCrossingEventType = "nx.stub.lineCrossing";
78 const std::string kObjectInTheAreaEventType = "nx.stub.objectInTheArea";
79 const std::string kLoiteringEventType = "nx.stub.loitering";
80 const std::string kIntrusionEventType = "nx.stub.intrusion";
81 const std::string kGunshotEventType = "nx.stub.gunshot";
82 const std::string kSuspiciousNoiseEventType = "nx.stub.suspiciousNoise";
83 const std::string kSoundRelatedEventGroup = "nx.stub.soundRelated";
84 const std::string kAdditionalEventType = "nx.stub.additionalEvent1";
85 const std::string kAdditionalEventType2 = "nx.stub.additionalEvent2";
86
87 } // namespace events
88 } // namespace stub
89 } // namespace analytics
90 } // namespace vms_server_plugins
91 } // namespace nx
nx::sdk::analytics::IMetadataPacket
Definition: i_metadata_packet.h:13
nx::vms_server_plugins::analytics::stub::events::DeviceAgent::settingsReceived
virtual nx::sdk::Result< const nx::sdk::ISettingsResponse * > settingsReceived() override
Definition: device_agent.cpp:220
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:82
nx::sdk::IDeviceInfo
Definition: i_device_info.h:13
nx::vms_server_plugins::analytics::stub::events::DeviceAgent
Definition: device_agent.h:26
nx::sdk::Result
Definition: result.h:48
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