GDAL

cpl_vsil_plugin.h
1/******************************************************************************
2 *
3 * Project: CPL - Common Portability Library
4 * Purpose: Declarations for vsi filesystem plugin handlers
5 * Author: Thomas Bonfort <thomas.bonfort@airbus.com>
6 *
7 ******************************************************************************
8 * Copyright (c) 2019, Thomas Bonfort <thomas.bonfort@airbus.com>
9 *
10 * SPDX-License-Identifier: MIT
11 ****************************************************************************/
12
13#ifndef CPL_VSIL_PLUGIN_H_INCLUDED
14#define CPL_VSIL_PLUGIN_H_INCLUDED
15
16#include "cpl_port.h"
17#include "cpl_string.h"
18#include "cpl_vsi.h"
19#include "cpl_vsi_virtual.h"
20
22
23 namespace cpl
24{
25
26/************************************************************************/
27/* VSIPluginFilesystemHandler */
28/************************************************************************/
29
30 class VSIPluginHandle;
31
32 class VSIPluginFilesystemHandler : public VSIFilesystemHandler
33{
34 CPL_DISALLOW_COPY_ASSIGN(VSIPluginFilesystemHandler)
35
36 private:
37 const char *m_Prefix;
38 const VSIFilesystemPluginCallbacksStruct *m_cb;
39 bool m_bWarnedAdviseReadImplemented = false;
40
41 protected:
42 friend class VSIPluginHandle;
43 VSIPluginHandle *CreatePluginHandle(void *cbData);
44 const char *GetCallbackFilename(const char *pszFilename);
45 bool IsValidFilename(const char *pszFilename);
46
47 vsi_l_offset Tell(void *pFile);
48 int Seek(void *pFile, vsi_l_offset nOffset, int nWhence);
49 size_t Read(void *pFile, void *pBuffer, size_t nSize, size_t nCount);
50 int ReadMultiRange(void *pFile, int nRanges, void **ppData,
51 const vsi_l_offset *panOffsets, const size_t *panSizes);
52 void AdviseRead(void *pFile, int nRanges, const vsi_l_offset *panOffsets,
53 const size_t *panSizes);
54 VSIRangeStatus GetRangeStatus(void *pFile, vsi_l_offset nOffset,
55 vsi_l_offset nLength);
56 int Eof(void *pFile);
57 int Error(void *pFile);
58 void ClearErr(void *pFile);
59 size_t Write(void *pFile, const void *pBuffer, size_t nSize, size_t nCount);
60 int Flush(void *pFile);
61 int Truncate(void *pFile, vsi_l_offset nNewSize);
62 int Close(void *pFile);
63
64 public:
65 VSIPluginFilesystemHandler(const char *pszPrefix,
66 const VSIFilesystemPluginCallbacksStruct *cb);
67 ~VSIPluginFilesystemHandler() override;
68
69 VSIVirtualHandle *Open(const char *pszFilename, const char *pszAccess,
70 bool bSetError,
71 CSLConstList /* papszOptions */) override;
72
73 int Stat(const char *pszFilename, VSIStatBufL *pStatBuf,
74 int nFlags) override;
75 int Unlink(const char *pszFilename) override;
76 int Rename(const char *oldpath, const char * /*newpath*/) override;
77 int Mkdir(const char *pszDirname, long nMode) override;
78 int Rmdir(const char *pszDirname) override;
79 char **ReadDirEx(const char *pszDirname, int nMaxFiles) override;
80 char **SiblingFiles(const char *pszFilename) override;
81 int HasOptimizedReadMultiRange(const char *pszPath) override;
82};
83
84/************************************************************************/
85/* VSIPluginHandle */
86/************************************************************************/
87
88 class VSIPluginHandle : public VSIVirtualHandle
89{
90 CPL_DISALLOW_COPY_ASSIGN(VSIPluginHandle)
91
92 protected:
93 VSIPluginFilesystemHandler *poFS;
94 void *cbData;
95
96 public:
97 VSIPluginHandle(VSIPluginFilesystemHandler *poFS, void *cbData);
98 ~VSIPluginHandle() override;
99
100 vsi_l_offset Tell() override;
101 int Seek(vsi_l_offset nOffset, int nWhence) override;
102 size_t Read(void *pBuffer, size_t nSize, size_t nCount) override;
103 int ReadMultiRange(int nRanges, void **ppData,
104 const vsi_l_offset *panOffsets,
105 const size_t *panSizes) override;
106 void AdviseRead(int nRanges, const vsi_l_offset *panOffsets,
107 const size_t *panSizes) override;
108 VSIRangeStatus GetRangeStatus(vsi_l_offset nOffset,
109 vsi_l_offset nLength) override;
110 void ClearErr() override;
111 int Eof() override;
112 int Error() override;
113 size_t Write(const void *pBuffer, size_t nSize, size_t nCount) override;
114 int Flush() override;
115 int Truncate(vsi_l_offset nNewSize) override;
116 int Close() override;
117};
118
119} // namespace cpl
120
122
123#endif // CPL_VSIL_PLUGIN_H_INCLUDED
cpl_port.h
Core portability definitions for CPL.
CPL_DISALLOW_COPY_ASSIGN
#define CPL_DISALLOW_COPY_ASSIGN(ClassName)
Helper to remove the copy and assignment constructors so that the compiler will not generate the defa...
Definition: cpl_port.h:1030
CSLConstList
char ** CSLConstList
Type of a constant null-terminated list of nul terminated strings.
Definition: cpl_port.h:1179
cpl_string.h
Various convenience functions for working with strings and string lists.
cpl_vsi.h
Standard C Covers.
VSIStatBufL
#define VSIStatBufL
Type for VSIStatL()
Definition: cpl_vsi.h:189
VSIRangeStatus
VSIRangeStatus
Range status.
Definition: cpl_vsi.h:168
vsi_l_offset
GUIntBig vsi_l_offset
Type for a file offset.
Definition: cpl_vsi.h:130
VSIFilesystemPluginCallbacksStruct
struct containing callbacks to used by the handler.
Definition: cpl_vsi.h:701
VSIVirtualHandle
Virtual file handle.
Definition: cpl_vsi_virtual.h:47