nx_server_plugin_sdk 1.0 Server Plugin SDK

third_party_storage.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 <stdint.h>
6
7 #include "../plugins/plugin_api.h"
8
9 #if defined(_WIN32)
10 #define STORAGE_METHOD_CALL __stdcall
11 #else
12 #define STORAGE_METHOD_CALL
13 #endif
14
16 namespace nx_spl
17 {
18 const uint64_t unknown_size = 0xffffffffffffffff;
19
21 namespace io
22 {
23 enum mode_t
24 {
25 NotOpen = 0x0001,
26 ReadOnly = 0x0002,
27 WriteOnly = 0x0004,
28 ReadWrite = ReadOnly | WriteOnly,
29 };
30 }
31
33 namespace cap
34 {
35 enum cap_t
36 {
37 ListFile = 0x0001, // capable of listing files
38 RemoveFile = 0x0002, // capable of removing files
39 ReadFile = 0x0004, // capable of reading files
40 WriteFile = 0x0008, // capable of writing files
41 DBReady = 0x0010, // capable of DB hosting
42 };
43 }
44
46 namespace error
47 {
48 enum code_t
49 {
50 NoError,
51 StorageUnavailable,
52 NotEnoughSpace,
53 SpaceInfoNotAvailable,
54 EndOfFile,
55 ReadNotSupported,
56 WriteNotSupported,
57 UrlNotExists,
58 UnknownError,
59 };
60 }
61
62 enum FileType
63 {
64 isFile,
65 isDir
66 };
67
68 // {F922BB26-D59E-4046-9B80-8466B101986B}
69 static const nxpl::NX_GUID IID_IODevice =
70 { { 0xf9, 0x22, 0xbb, 0x26, 0xd5, 0x9e, 0x40, 0x46, 0x9b, 0x80, 0x84, 0x66, 0xb1, 0x1, 0x98, 0x6b } };
71
73 class IODevice
74 :public nxpl::PluginInterface
75 {
76 public:
83 virtual uint32_t STORAGE_METHOD_CALL write(
84 const void* src,
85 const uint32_t size,
86 int* ecode
87 ) = 0;
88
97 virtual uint32_t STORAGE_METHOD_CALL read(
98 void* dst,
99 const uint32_t size,
100 int* ecode
101 ) const = 0;
102
106 virtual int STORAGE_METHOD_CALL getMode() const = 0;
107
112 virtual uint32_t STORAGE_METHOD_CALL size(int* ecode) const = 0;
113
119 virtual int STORAGE_METHOD_CALL seek(
120 uint64_t pos,
121 int* ecode
122 ) = 0;
123 };
124
126 struct FileInfo
127 {
128 const char* url;
129 uint64_t size;
130 FileType type;
131 };
132
133 // {D5DA5C59-44D5-4C14-AB17-EA7395555189}
134 static const nxpl::NX_GUID IID_FileInfoIterator =
135 { { 0xd5, 0xda, 0x5c, 0x59, 0x44, 0xd5, 0x4c, 0x14, 0xab, 0x17, 0xea, 0x73, 0x95, 0x55, 0x51, 0x89 } };
136
138 class FileInfoIterator
139 : public nxpl::PluginInterface
140 {
141 public:
147 virtual FileInfo* STORAGE_METHOD_CALL next(int* ecode) const = 0;
148 };
149
150 // {D5DA5C59-44D5-4C14-AB17-EA7395555189}
151 static const nxpl::NX_GUID IID_Storage =
152 { { 0xd5, 0xda, 0x5c, 0x59, 0x44, 0xd5, 0x4c, 0x14, 0xab, 0x17, 0xea, 0x73, 0x95, 0x55, 0x51, 0x89 } };
153
155 class Storage
156 : public nxpl::PluginInterface
157 {
158 public:
162 virtual int STORAGE_METHOD_CALL isAvailable() const = 0;
163
170 virtual IODevice* STORAGE_METHOD_CALL open(
171 const char* url,
172 int flags,
173 int* ecode
174 ) const = 0;
175
180 virtual uint64_t STORAGE_METHOD_CALL getFreeSpace(int* ecode) const = 0;
181
186 virtual uint64_t STORAGE_METHOD_CALL getTotalSpace(int* ecode) const = 0;
187
191 virtual int STORAGE_METHOD_CALL getCapabilities() const = 0;
192
197 virtual void STORAGE_METHOD_CALL removeFile(
198 const char* url,
199 int* ecode
200 ) = 0;
201
206 virtual void STORAGE_METHOD_CALL removeDir(
207 const char* url,
208 int* ecode
209 ) = 0;
210
216 virtual void STORAGE_METHOD_CALL renameFile(
217 const char* oldUrl,
218 const char* newUrl,
219 int* ecode
220 ) = 0;
221
227 virtual FileInfoIterator* STORAGE_METHOD_CALL getFileIterator(
228 const char* dirUrl,
229 int* ecode
230 ) const = 0;
231
237 virtual int STORAGE_METHOD_CALL fileExists(
238 const char* url,
239 int* ecode
240 ) const = 0;
241
247 virtual int STORAGE_METHOD_CALL dirExists(
248 const char* url,
249 int* ecode
250 ) const = 0;
251
257 virtual uint64_t STORAGE_METHOD_CALL fileSize(
258 const char* url,
259 int* ecode
260 ) const = 0;
261 };
262
263 // {2E2C7A3D-256D-4018-B40E-512D72510BEC}
264 static const nxpl::NX_GUID IID_StorageFactory =
265 { { 0x2e, 0x2c, 0x7a, 0x3d, 0x25, 0x6d, 0x40, 0x18, 0xb4, 0xe, 0x51, 0x2d, 0x72, 0x51, 0xb, 0xec } };
266
268
273 class StorageFactory
274 : public nxpl::PluginInterface
275 {
276 public:
280 virtual const char** STORAGE_METHOD_CALL findAvailable() const = 0;
281
287 virtual Storage* STORAGE_METHOD_CALL createStorage(
288 const char* url,
289 int* ecode
290 ) = 0;
291
297 virtual const char* STORAGE_METHOD_CALL storageType() const = 0;
298
303 virtual const char* lastErrorMessage(int ecode) const = 0;
304 };
305 }
nx_spl::FileInfoIterator
File information iterator abstraction.
Definition: third_party_storage.h:138
nx_spl::Storage::isAvailable
virtual int STORAGE_METHOD_CALL isAvailable() const =0
nx_spl::StorageFactory
Storage factory abstraction.
Definition: third_party_storage.h:273
nx_spl::IODevice::getMode
virtual int STORAGE_METHOD_CALL getMode() const =0
nx_spl::Storage::fileExists
virtual int STORAGE_METHOD_CALL fileExists(const char *url, int *ecode) const =0
nxpl::PluginInterface
Base class for every interface, provided by plugin.
Definition: plugin_api.h:44
nx_spl::FileInfo
Common file information.
Definition: third_party_storage.h:126
nx_spl
Storage plugin namespace.
Definition: ftp_library.cpp:29
nx_spl::Storage::getFileIterator
virtual FileInfoIterator *STORAGE_METHOD_CALL getFileIterator(const char *dirUrl, int *ecode) const =0
nxpl::NX_GUID
GUID of plugin interface.
Definition: plugin_api.h:26
nx_spl::Storage::fileSize
virtual uint64_t STORAGE_METHOD_CALL fileSize(const char *url, int *ecode) const =0
nx_spl::IODevice::read
virtual uint32_t STORAGE_METHOD_CALL read(void *dst, const uint32_t size, int *ecode) const =0
nx_spl::Storage
Storage abstraction.
Definition: third_party_storage.h:155
nx_spl::Storage::getFreeSpace
virtual uint64_t STORAGE_METHOD_CALL getFreeSpace(int *ecode) const =0
nx_spl::IODevice::seek
virtual int STORAGE_METHOD_CALL seek(uint64_t pos, int *ecode)=0
nx_spl::StorageFactory::storageType
virtual const char *STORAGE_METHOD_CALL storageType() const =0
nx_spl::Storage::removeFile
virtual void STORAGE_METHOD_CALL removeFile(const char *url, int *ecode)=0
nx_spl::Storage::getTotalSpace
virtual uint64_t STORAGE_METHOD_CALL getTotalSpace(int *ecode) const =0
nx_spl::Storage::getCapabilities
virtual int STORAGE_METHOD_CALL getCapabilities() const =0
nx_spl::Storage::open
virtual IODevice *STORAGE_METHOD_CALL open(const char *url, int flags, int *ecode) const =0
nx_spl::Storage::removeDir
virtual void STORAGE_METHOD_CALL removeDir(const char *url, int *ecode)=0
nx_spl::IODevice::size
virtual uint32_t STORAGE_METHOD_CALL size(int *ecode) const =0
nx_spl::Storage::renameFile
virtual void STORAGE_METHOD_CALL renameFile(const char *oldUrl, const char *newUrl, int *ecode)=0
nx_spl::StorageFactory::lastErrorMessage
virtual const char * lastErrorMessage(int ecode) const =0
nx_spl::Storage::dirExists
virtual int STORAGE_METHOD_CALL dirExists(const char *url, int *ecode) const =0
nx_spl::FileInfoIterator::next
virtual FileInfo *STORAGE_METHOD_CALL next(int *ecode) const =0
nx_spl::IODevice::write
virtual uint32_t STORAGE_METHOD_CALL write(const void *src, const uint32_t size, int *ecode)=0
nx_spl::StorageFactory::findAvailable
virtual const char **STORAGE_METHOD_CALL findAvailable() const =0
nx_spl::IODevice
IO device abstraction.
Definition: third_party_storage.h:73
nx_spl::StorageFactory::createStorage
virtual Storage *STORAGE_METHOD_CALL createStorage(const char *url, int *ecode)=0