nx_server_plugin_sdk 1.0 Server Plugin SDK

engine.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 <mutex>
6 #include <string>
7 #include <thread>
8 #include <vector>
9
10 #include <nx/sdk/cloud_storage/i_async_operation_handler.h>
11 #include <nx/sdk/cloud_storage/i_engine.h>
12 #include <nx/sdk/helpers/ref_countable.h>
13 #include <nx/sdk/i_utility_provider.h>
14
15 #include "data_manager.h"
16
17 namespace nx::vms_server_plugins::cloud_storage::stub {
18
19 class Integration;
20
21 class Engine: public nx::sdk::RefCountable<nx::sdk::cloud_storage::IEngine>
22 {
23 public:
24 Engine(
25 const nx::sdk::cloud_storage::IAsyncOperationHandler* asyncOperationHandler,
26 const std::shared_ptr<DataManager>& dataManager,
27 const std::string& integrationId);
28
29 virtual ~Engine() override;
30 virtual void startAsyncTasks(const char* lastSequenceId) override;
31 virtual void stopAsyncTasks() override;
32 virtual nx::sdk::ErrorCode saveMetadata(
33 const char* deviceId,
34 nx::sdk::cloud_storage::MetadataType type,
35 const char* data) override;
36
37 virtual bool isOnline() const override;
38 virtual nx::sdk::ErrorCode storageSpace(
39 nx::sdk::cloud_storage::StorageSpace* storageSpace) const override;
40
41 virtual void flushMetadata(nx::sdk::cloud_storage::MetadataType type) override;
42
43 protected:
44 virtual void doObtainDeviceAgent(
45 nx::sdk::Result<nx::sdk::cloud_storage::IDeviceAgent*>* outResult,
46 const nx::sdk::IDeviceInfo* deviceInfo) override;
47
48 virtual void doQueryMotionTimePeriods(
49 const char* filter,
50 nx::sdk::Result<nx::sdk::IString*>* outResult) override;
51
52 virtual void doQueryAnalytics(
53 const char* filter,
54 nx::sdk::Result<nx::sdk::IString*>* outResult) override;
55
56 virtual void doQueryAnalyticsTimePeriods(
57 const char* filter,
58 nx::sdk::Result<nx::sdk::IString*>* outResult) override;
59
60 virtual void doQueryBookmarks(
61 const char* filter,
62 nx::sdk::Result<nx::sdk::IString*>* outResult) override;
63
64 virtual nx::sdk::ErrorCode deleteBookmark(const char* bookmarkId) override;
65 virtual void doFetchTrackImage(
66 const char* objectTrackId,
67 nx::sdk::cloud_storage::TrackImageType type,
68 nx::sdk::Result<nx::sdk::IString*>* outResult) const override;
69
70 private:
71 nx::sdk::Ptr<const nx::sdk::cloud_storage::IAsyncOperationHandler> m_handler;
72 std::shared_ptr<DataManager> m_dataManager;
73 std::vector<nx::sdk::Ptr<nx::sdk::cloud_storage::IDeviceAgent>> m_deviceAgents;
74 std::string m_integrationId;
75 std::thread m_worker;
76 mutable std::mutex m_mutex;
77 bool m_needToStop = false;
78 std::optional<std::chrono::system_clock::time_point> m_lastReportTimePoint;
79 std::optional<std::chrono::system_clock::time_point> m_lastScanTimePoint;
80
81 nx::sdk::cloud_storage::IDeviceAgent* findDeviceAgentById(
82 const std::string& id,
83 const std::vector<nx::sdk::Ptr<nx::sdk::cloud_storage::IDeviceAgent>>& deviceAgents);
84 };
85
86 } // nx::vms_server_plugins::cloud_storage::stub
nx::vms_server_plugins::cloud_storage::stub::Engine::isOnline
virtual bool isOnline() const override
Definition: engine.cpp:396
nx::vms_server_plugins::cloud_storage::stub::Engine::flushMetadata
virtual void flushMetadata(nx::sdk::cloud_storage::MetadataType type) override
Definition: engine.cpp:352
nx::sdk::cloud_storage::StorageSpace
Definition: i_engine.h:24
nx::vms_server_plugins::cloud_storage::stub
Definition: data_manager.cpp:36
nx::sdk::Ptr< const nx::sdk::cloud_storage::IAsyncOperationHandler >
nx::vms_server_plugins::cloud_storage::stub::Engine::saveMetadata
virtual nx::sdk::ErrorCode saveMetadata(const char *deviceId, nx::sdk::cloud_storage::MetadataType type, const char *data) override
Definition: engine.cpp:357
nx::sdk::cloud_storage::IAsyncOperationHandler
Definition: i_async_operation_handler.h:69
nx::vms_server_plugins::cloud_storage::stub::Engine::startAsyncTasks
virtual void startAsyncTasks(const char *lastSequenceId) override
Definition: engine.cpp:79
nx::sdk::IDeviceInfo
Definition: i_device_info.h:13
nx::vms_server_plugins::cloud_storage::stub::Engine::storageSpace
virtual nx::sdk::ErrorCode storageSpace(nx::sdk::cloud_storage::StorageSpace *storageSpace) const override
Definition: engine.cpp:401
nx::sdk::cloud_storage::IDeviceAgent
Definition: i_device_agent.h:21
nx::sdk::Result
Definition: result.h:52
nx::vms_server_plugins::cloud_storage::stub::Engine::stopAsyncTasks
virtual void stopAsyncTasks() override
Definition: engine.cpp:65
nx::vms_server_plugins::cloud_storage::stub::Engine
Definition: engine.h:21
nx::sdk::RefCountable
Definition: ref_countable.h:83