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
56 protected:
57 friend class VSIPluginHandle;
58 VSIPluginHandle *CreatePluginHandle(void *cbData);
59 const char *GetCallbackFilename(const char *pszFilename);
60 bool IsValidFilename(const char *pszFilename);
61
62 vsi_l_offset Tell(void *pFile);
63 int Seek(void *pFile, vsi_l_offset nOffset, int nWhence);
64 size_t Read(void *pFile, void *pBuffer, size_t nSize, size_t nCount);
65 int ReadMultiRange(void *pFile, int nRanges, void **ppData,
66 const vsi_l_offset *panOffsets, const size_t *panSizes);
67 VSIRangeStatus GetRangeStatus(void *pFile, vsi_l_offset nOffset,
68 vsi_l_offset nLength);
69 int Eof(void *pFile);
70 size_t Write(void *pFile, const void *pBuffer, size_t nSize, size_t nCount);
71 int Flush(void *pFile);
72 int Truncate(void *pFile, vsi_l_offset nNewSize);
73 int Close(void *pFile);
74
75 public:
76 VSIPluginFilesystemHandler(const char *pszPrefix,
78 ~VSIPluginFilesystemHandler() override;
79
80 VSIVirtualHandle *Open(const char *pszFilename, const char *pszAccess,
81 bool bSetError,
82 CSLConstList /* papszOptions */) override;
83
84 int Stat(const char *pszFilename, VSIStatBufL *pStatBuf,
85 int nFlags) override;
86 int Unlink(const char *pszFilename) override;
87 int Rename(const char *oldpath, const char * /*newpath*/) override;
88 int Mkdir(const char *pszDirname, long nMode) override;
89 int Rmdir(const char *pszDirname) override;
90 char **ReadDir(const char *pszDirname) override
91 {
92 return ReadDirEx(pszDirname, 0);
93 }
94 char **ReadDirEx(const char *pszDirname, int nMaxFiles) override;
95 char **SiblingFiles(const char *pszFilename) override;
96 int HasOptimizedReadMultiRange(const char *pszPath) override;
97};
98
99/************************************************************************/
100/* VSIPluginHandle */
101/************************************************************************/
102
103class VSIPluginHandle : public VSIVirtualHandle
104{
105 CPL_DISALLOW_COPY_ASSIGN(VSIPluginHandle)
106
107 protected:
108 VSIPluginFilesystemHandler *poFS;
109 void *cbData;
110
111 public:
112 VSIPluginHandle(VSIPluginFilesystemHandler *poFS, void *cbData);
113 ~VSIPluginHandle() override;
114
115 vsi_l_offset Tell() override;
116 int Seek(vsi_l_offset nOffset, int nWhence) override;
117 size_t Read(void *pBuffer, size_t nSize, size_t nCount) override;
118 int ReadMultiRange(int nRanges, void **ppData,
119 const vsi_l_offset *panOffsets,
120 const size_t *panSizes) override;
121 VSIRangeStatus GetRangeStatus(vsi_l_offset nOffset,
122 vsi_l_offset nLength) override;
123 int Eof() override;
124 size_t Write(const void *pBuffer, size_t nSize, size_t nCount) override;
125 int Flush() override;
126 int Truncate(vsi_l_offset nNewSize) override;
127 int Close() override;
128};
129
130} // namespace cpl
131
133
134#endif // CPL_VSIL_PLUGIN_H_INCLUDED
Virtual file handle.
Definition cpl_vsi_virtual.h:57
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:1049
char ** CSLConstList
Type of a constant null-terminated list of nul terminated strings.
Definition cpl_port.h:1190
Various convenience functions for working with strings and string lists.
Standard C Covers.
#define VSIStatBufL
Type for VSIStatL()
Definition cpl_vsi.h:215
VSIRangeStatus
Range status.
Definition cpl_vsi.h:194
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:635