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