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 VSIVirtualHandleUniquePtr Open(const char *pszFilename,
70 const char *pszAccess, 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*/, GDALProgressFunc,
77 void *) override;
78 int Mkdir(const char *pszDirname, long nMode) override;
79 int Rmdir(const char *pszDirname) override;
80 char **ReadDirEx(const char *pszDirname, int nMaxFiles) override;
81 char **SiblingFiles(const char *pszFilename) override;
82 int HasOptimizedReadMultiRange(const char *pszPath) override;
83};
84
85/************************************************************************/
86/* VSIPluginHandle */
87/************************************************************************/
88
89 class VSIPluginHandle final : public VSIVirtualHandle
90{
91 CPL_DISALLOW_COPY_ASSIGN(VSIPluginHandle)
92
93 protected:
94 VSIPluginFilesystemHandler *poFS;
95 void *cbData;
96
97 public:
98 VSIPluginHandle(VSIPluginFilesystemHandler *poFS, void *cbData);
99 ~VSIPluginHandle() override;
100
101 vsi_l_offset Tell() override;
102 int Seek(vsi_l_offset nOffset, int nWhence) override;
103 size_t Read(void *pBuffer, size_t nSize, size_t nCount) override;
104 int ReadMultiRange(int nRanges, void **ppData,
105 const vsi_l_offset *panOffsets,
106 const size_t *panSizes) override;
107 void AdviseRead(int nRanges, const vsi_l_offset *panOffsets,
108 const size_t *panSizes) override;
109 VSIRangeStatus GetRangeStatus(vsi_l_offset nOffset,
110 vsi_l_offset nLength) override;
111 void ClearErr() override;
112 int Eof() override;
113 int Error() override;
114 size_t Write(const void *pBuffer, size_t nSize, size_t nCount) override;
115 int Flush() override;
116 int Truncate(vsi_l_offset nNewSize) override;
117 int Close() override;
118};
119
120} // namespace cpl
121
123
124#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:936
CSLConstList
char ** CSLConstList
Type of a constant null-terminated list of nul terminated strings.
Definition cpl_port.h:1087
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:195
VSIRangeStatus
VSIRangeStatus
Range status.
Definition cpl_vsi.h:174
vsi_l_offset
GUIntBig vsi_l_offset
Type for a file offset.
Definition cpl_vsi.h:136
VSIFilesystemPluginCallbacksStruct
struct containing callbacks to used by the handler.
Definition cpl_vsi.h:719
VSIVirtualHandle
Virtual file handle.
Definition cpl_vsi_virtual.h:48