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
39namespace cpl
40{
41
42/************************************************************************/
43/* VSIPluginFilesystemHandler */
44/************************************************************************/
45
46class VSIPluginHandle;
47
48class 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 size_t Write(void *pFile, const void *pBuffer, size_t nSize, size_t nCount);
74 int Flush(void *pFile);
75 int Truncate(void *pFile, vsi_l_offset nNewSize);
76 int Close(void *pFile);
77
78 public:
79 VSIPluginFilesystemHandler(const char *pszPrefix,
81 ~VSIPluginFilesystemHandler() override;
82
83 VSIVirtualHandle *Open(const char *pszFilename, const char *pszAccess,
84 bool bSetError,
85 CSLConstList /* papszOptions */) override;
86
87 int Stat(const char *pszFilename, VSIStatBufL *pStatBuf,
88 int nFlags) override;
89 int Unlink(const char *pszFilename) override;
90 int Rename(const char *oldpath, const char * /*newpath*/) override;
91 int Mkdir(const char *pszDirname, long nMode) override;
92 int Rmdir(const char *pszDirname) override;
93 char **ReadDirEx(const char *pszDirname, int nMaxFiles) override;
94 char **SiblingFiles(const char *pszFilename) override;
95 int HasOptimizedReadMultiRange(const char *pszPath) override;
96};
97
98/************************************************************************/
99/* VSIPluginHandle */
100/************************************************************************/
101
102class VSIPluginHandle : public VSIVirtualHandle
103{
104 CPL_DISALLOW_COPY_ASSIGN(VSIPluginHandle)
105
106 protected:
107 VSIPluginFilesystemHandler *poFS;
108 void *cbData;
109
110 public:
111 VSIPluginHandle(VSIPluginFilesystemHandler *poFS, void *cbData);
112 ~VSIPluginHandle() override;
113
114 vsi_l_offset Tell() override;
115 int Seek(vsi_l_offset nOffset, int nWhence) override;
116 size_t Read(void *pBuffer, size_t nSize, size_t nCount) override;
117 int ReadMultiRange(int nRanges, void **ppData,
118 const vsi_l_offset *panOffsets,
119 const size_t *panSizes) override;
120 void AdviseRead(int nRanges, const vsi_l_offset *panOffsets,
121 const size_t *panSizes) override;
122 VSIRangeStatus GetRangeStatus(vsi_l_offset nOffset,
123 vsi_l_offset nLength) override;
124 int Eof() override;
125 size_t Write(const void *pBuffer, size_t nSize, size_t nCount) override;
126 int Flush() override;
127 int Truncate(vsi_l_offset nNewSize) override;
128 int Close() override;
129};
130
131} // namespace cpl
132
134
135#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:203
VSIRangeStatus
Range status.
Definition: cpl_vsi.h:182
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:656
Virtual file handle.
Definition: cpl_vsi_virtual.h:63