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  * Permission is hereby granted, free of charge, to any person obtaining a
11  * copy of this software and associated documentation files (the "Software"),
12  * to deal in the Software without restriction, including without limitation
13  * the rights to use, copy, modify, merge, publish, distribute, sublicense,
14  * and/or sell copies of the Software, and to permit persons to whom the
15  * Software is furnished to do so, subject to the following conditions:
16  *
17  * The above copyright notice and this permission notice shall be included
18  * in all copies or substantial portions of the Software.
19  *
20  * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
21  * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
22  * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
23  * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
24  * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
25  * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
26  * DEALINGS IN THE SOFTWARE.
27  ****************************************************************************/
28 
29 #ifndef CPL_VSIL_PLUGIN_H_INCLUDED
30 #define CPL_VSIL_PLUGIN_H_INCLUDED
31 
32 #include "cpl_port.h"
33 #include "cpl_string.h"
34 #include "cpl_vsi.h"
35 #include "cpl_vsi_virtual.h"
36 
38 
39 namespace cpl
40 {
41 
42 /************************************************************************/
43 /* VSIPluginFilesystemHandler */
44 /************************************************************************/
45 
46 class VSIPluginHandle;
47 
48 class VSIPluginFilesystemHandler : public VSIFilesystemHandler
49 {
50  CPL_DISALLOW_COPY_ASSIGN(VSIPluginFilesystemHandler)
51 
52  private:
53  const char *m_Prefix;
55  bool m_bWarnedAdviseReadImplemented = false;
56 
57  protected:
58  friend class VSIPluginHandle;
59  VSIPluginHandle *CreatePluginHandle(void *cbData);
60  const char *GetCallbackFilename(const char *pszFilename);
61  bool IsValidFilename(const char *pszFilename);
62 
63  vsi_l_offset Tell(void *pFile);
64  int Seek(void *pFile, vsi_l_offset nOffset, int nWhence);
65  size_t Read(void *pFile, void *pBuffer, size_t nSize, size_t nCount);
66  int ReadMultiRange(void *pFile, int nRanges, void **ppData,
67  const vsi_l_offset *panOffsets, const size_t *panSizes);
68  void AdviseRead(void *pFile, int nRanges, const vsi_l_offset *panOffsets,
69  const size_t *panSizes);
70  VSIRangeStatus GetRangeStatus(void *pFile, vsi_l_offset nOffset,
71  vsi_l_offset nLength);
72  int Eof(void *pFile);
73  int Error(void *pFile);
74  void ClearErr(void *pFile);
75  size_t Write(void *pFile, const void *pBuffer, size_t nSize, size_t nCount);
76  int Flush(void *pFile);
77  int Truncate(void *pFile, vsi_l_offset nNewSize);
78  int Close(void *pFile);
79 
80  public:
81  VSIPluginFilesystemHandler(const char *pszPrefix,
83  ~VSIPluginFilesystemHandler() override;
84 
85  VSIVirtualHandle *Open(const char *pszFilename, const char *pszAccess,
86  bool bSetError,
87  CSLConstList /* papszOptions */) override;
88 
89  int Stat(const char *pszFilename, VSIStatBufL *pStatBuf,
90  int nFlags) override;
91  int Unlink(const char *pszFilename) override;
92  int Rename(const char *oldpath, const char * /*newpath*/) override;
93  int Mkdir(const char *pszDirname, long nMode) override;
94  int Rmdir(const char *pszDirname) override;
95  char **ReadDirEx(const char *pszDirname, int nMaxFiles) override;
96  char **SiblingFiles(const char *pszFilename) override;
97  int HasOptimizedReadMultiRange(const char *pszPath) override;
98 };
99 
100 /************************************************************************/
101 /* VSIPluginHandle */
102 /************************************************************************/
103 
104 class VSIPluginHandle : public VSIVirtualHandle
105 {
106  CPL_DISALLOW_COPY_ASSIGN(VSIPluginHandle)
107 
108  protected:
109  VSIPluginFilesystemHandler *poFS;
110  void *cbData;
111 
112  public:
113  VSIPluginHandle(VSIPluginFilesystemHandler *poFS, void *cbData);
114  ~VSIPluginHandle() override;
115 
116  vsi_l_offset Tell() override;
117  int Seek(vsi_l_offset nOffset, int nWhence) override;
118  size_t Read(void *pBuffer, size_t nSize, size_t nCount) override;
119  int ReadMultiRange(int nRanges, void **ppData,
120  const vsi_l_offset *panOffsets,
121  const size_t *panSizes) override;
122  void AdviseRead(int nRanges, const vsi_l_offset *panOffsets,
123  const size_t *panSizes) override;
124  VSIRangeStatus GetRangeStatus(vsi_l_offset nOffset,
125  vsi_l_offset nLength) override;
126  void ClearErr() override;
127  int Eof() override;
128  int Error() override;
129  size_t Write(const void *pBuffer, size_t nSize, size_t nCount) override;
130  int Flush() override;
131  int Truncate(vsi_l_offset nNewSize) override;
132  int Close() override;
133 };
134 
135 } // namespace cpl
136 
138 
139 #endif // CPL_VSIL_PLUGIN_H_INCLUDED
Core portability definitions for CPL.
#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:1042
char ** CSLConstList
Type of a constant null-terminated list of nul terminated strings.
Definition: cpl_port.h:1183
Various convenience functions for working with strings and string lists.
Standard C Covers.
#define VSIStatBufL
Type for VSIStatL()
Definition: cpl_vsi.h:205
VSIRangeStatus
Range status.
Definition: cpl_vsi.h:184
GUIntBig vsi_l_offset
Type for a file offset.
Definition: cpl_vsi.h:146
struct containing callbacks to used by the handler.
Definition: cpl_vsi.h:715
Virtual file handle.
Definition: cpl_vsi_virtual.h:63