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 /* VSIPluginFilesystemHandler */
43 /************************************************************************/
44
45 class VSIPluginHandle;
46
47 class VSIPluginFilesystemHandler : public VSIFilesystemHandler
48 {
49 CPL_DISALLOW_COPY_ASSIGN(VSIPluginFilesystemHandler)
50
51 private:
52 const char* m_Prefix;
53 const VSIFilesystemPluginCallbacksStruct* m_cb;
54
55 protected:
56 friend class VSIPluginHandle;
57 VSIPluginHandle* CreatePluginHandle(void *cbData);
58 const char* GetCallbackFilename(const char* pszFilename);
59 bool IsValidFilename(const char *pszFilename);
60
61 vsi_l_offset Tell( void *pFile );
62 int Seek( void *pFile, vsi_l_offset nOffset, int nWhence );
63 size_t Read( void *pFile, void *pBuffer, size_t nSize, size_t nCount );
64 int ReadMultiRange( void *pFile, int nRanges, void ** ppData, const vsi_l_offset* panOffsets, const size_t* panSizes );
65 VSIRangeStatus GetRangeStatus( void *pFile, vsi_l_offset nOffset, vsi_l_offset nLength );
66 int Eof( void *pFile );
67 size_t Write( void *pFile, const void *pBuffer, size_t nSize,size_t nCount);
68 int Flush( void *pFile );
69 int Truncate( void *pFile, vsi_l_offset nNewSize );
70 int Close( void *pFile );
71
72 public:
73 VSIPluginFilesystemHandler( const char *pszPrefix,
74 const VSIFilesystemPluginCallbacksStruct *cb);
75 ~VSIPluginFilesystemHandler() override;
76
77 VSIVirtualHandle *Open( const char *pszFilename,
78 const char *pszAccess,
79 bool bSetError,
80 CSLConstList /* papszOptions */ ) override;
81
82 int Stat ( const char *pszFilename, VSIStatBufL *pStatBuf, int nFlags ) override;
83 int Unlink ( const char * pszFilename ) override;
84 int Rename ( const char * oldpath, const char * /*newpath*/ ) override;
85 int Mkdir ( const char * pszDirname, long nMode ) override;
86 int Rmdir ( const char * pszDirname ) override;
87 char **ReadDir ( const char *pszDirname ) override
88 { return ReadDirEx(pszDirname, 0); }
89 char **ReadDirEx( const char * pszDirname, int nMaxFiles ) override;
90 char **SiblingFiles( const char * pszFilename ) override;
91 int HasOptimizedReadMultiRange(const char* pszPath ) override;
92
93 };
94
95 /************************************************************************/
96 /* VSIPluginHandle */
97 /************************************************************************/
98
99 class VSIPluginHandle : public VSIVirtualHandle
100 {
101 CPL_DISALLOW_COPY_ASSIGN(VSIPluginHandle)
102
103 protected:
104 VSIPluginFilesystemHandler* poFS;
105 void *cbData;
106
107 public:
108
109 VSIPluginHandle( VSIPluginFilesystemHandler* poFS, void *cbData);
110 ~VSIPluginHandle() override;
111
112 vsi_l_offset Tell() override;
113 int Seek( vsi_l_offset nOffset, int nWhence ) override;
114 size_t Read( void *pBuffer, size_t nSize, size_t nCount ) override;
115 int ReadMultiRange( int nRanges, void ** ppData, const vsi_l_offset* panOffsets, const size_t* panSizes ) override;
116 VSIRangeStatus GetRangeStatus( vsi_l_offset nOffset, vsi_l_offset nLength ) override;
117 int Eof() override;
118 size_t Write( const void *pBuffer, size_t nSize,size_t nCount) override;
119 int Flush() override;
120 int Truncate( vsi_l_offset nNewSize ) override;
121 int Close() override;
122 };
123
124 } // namespace cpl
125
127
128 #endif // CPL_VSIL_PLUGIN_H_INCLUDED
cpl_vsi.h
VSIRangeStatus
VSIRangeStatus
Range status.
Definition: cpl_vsi.h:176
VSIFilesystemPluginCallbacksStruct
struct containing callbacks to used by the handler.
Definition: cpl_vsi.h:539
CSLConstList
char ** CSLConstList
Type of a constant null-terminated list of nul terminated strings.
Definition: cpl_port.h:1169
cpl_string.h
vsi_l_offset
GUIntBig vsi_l_offset
Type for a file offset.
Definition: cpl_vsi.h:140
VSIStatBufL
struct VSI_STAT64_T VSIStatBufL
Type for VSIStatL()
Definition: cpl_vsi.h:195
cpl_port.h
VSIVirtualHandle
Virtual file handle.
Definition: cpl_vsi_virtual.h:56
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:955