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