nx_server_plugin_sdk 1.0 Server Plugin SDK

device_archive.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 <map>
6 #include <string>
7 #include <chrono>
8
9 #include <nx/sdk/cloud_storage/helpers/data_list.h>
10 #include <nx/sdk/cloud_storage/i_async_operation_handler.h>
11 #include <nx/sdk/helpers/list.h>
12 #include <nx/sdk/helpers/ref_countable.h>
13
14 namespace nx::sdk::cloud_storage {
15
16 enum class ChunkOperation
17 {
18 add,
19 remove,
20 };
21
22 struct MediaChunk
23 {
24 std::chrono::system_clock::time_point startPoint{};
25 std::chrono::milliseconds durationMs{-1};
26 int bucketId = -1;
27
28 bool operator<(const MediaChunk& other) const;
29
30 std::string toString() const;
31 };
32
33 std::string toString(const std::vector<MediaChunk>& chunks);
34
35 struct BucketDescription
36 {
37 std::string url;
38 int bucketId = -1;
39 };
40
41 using IndexData = std::map<ChunkOperation, std::vector<MediaChunk>>;
42 using DeviceData = std::map<int /*streamIndex*/, IndexData>;
43 using CloudChunkData = std::map<std::string, DeviceData>;
44
45 class BucketDescriptionList:
46 public nx::sdk::RefCountable<IBucketDescriptionList>,
47 public DataList<BucketDescription>
48 {
49 public:
50 BucketDescriptionList(std::vector<BucketDescription> data);
51
52 virtual void goToBeginning() const override;
53 virtual void next() const override;
54 virtual bool atEnd() const override;
55 virtual int urlLen() const override;
56 virtual bool get(char* url, int* bucketId) const override;
57
58 private:
59 using Base = DataList<BucketDescription>;
60 };
61
65 class MediaChunkList:
66 public nx::sdk::RefCountable<IMediaChunkList>,
67 public DataList<MediaChunk>
68 {
69 public:
70 MediaChunkList(std::vector<MediaChunk> chunks);
71
72 virtual void goToBeginning() const override;
73 virtual void next() const override;
74 virtual bool atEnd() const override;
75 virtual bool get(int64_t* outStartTimeMs, int64_t* durationMs, int* bucketId) const override;
76
77 private:
78 using Base = DataList<MediaChunk>;
79 };
80
81 class IndexArchive: public nx::sdk::RefCountable<IIndexArchive>
82 {
83 public:
84 IndexArchive(int streamIndex, const IndexData& indexData);
85
86 virtual const IMediaChunkList* addedChunks() const override;
87 virtual const IMediaChunkList* removedChunks() const override;
88 virtual int streamIndex() const override;
89
90 private:
91 const int m_streamIndex;
92 Ptr<IMediaChunkList> m_addedChunks;
93 Ptr<IMediaChunkList> m_removedChunks;
94 };
95
96 class DeviceArchive: public nx::sdk::RefCountable<IDeviceArchive>
97 {
98 public:
99 DeviceArchive(
100 IDeviceAgent* deviceAgent,
101 const DeviceData& deviceData);
102
103 virtual IList<IIndexArchive>* indexArchive() override;
104 virtual IDeviceAgent* deviceAgent() const override;
105
106 private:
107 IDeviceAgent* m_deviceAgent;
108 const DeviceData& m_data;
109 List<IIndexArchive> m_indexArchiveList;
110 };
111
112 } // namespace nx::sdk::cloud_storage
nx::sdk::cloud_storage::IMediaChunkList
Definition: i_async_operation_handler.h:35
nx::sdk::cloud_storage::DeviceArchive
Definition: device_archive.h:96
nx::sdk::cloud_storage::MediaChunk
Definition: device_archive.h:22
nx::sdk::cloud_storage::BucketDescription
Definition: device_archive.h:35
nx::sdk::cloud_storage::MediaChunkList
Definition: device_archive.h:65
nx::sdk::cloud_storage::IndexArchive
Definition: device_archive.h:81
nx::sdk::Ptr
Definition: ptr.h:18
nx::sdk::cloud_storage::BucketDescriptionList
Definition: device_archive.h:45
nx::sdk::cloud_storage::IDeviceAgent
Definition: i_device_agent.h:21
nx::sdk::List
Definition: list.h:15
nx::sdk::cloud_storage
Definition: algorithm.cpp:9
nx::sdk::cloud_storage::DataList
Definition: data_list.h:10
nx::sdk::IList
Definition: i_list.h:10
nx::sdk::RefCountable
Definition: ref_countable.h:83