OGR
cpl_vsi_virtual.h
1 /******************************************************************************
2  * $Id: cpl_vsi_virtual.h 29388 2015-06-17 18:28:29Z rouault $
3  *
4  * Project: VSI Virtual File System
5  * Purpose: Declarations for classes related to the virtual filesystem.
6  * These would only be normally required by applications implmenting
7  * their own virtual file system classes which should be rare.
8  * The class interface may be fragile through versions.
9  * Author: Frank Warmerdam, warmerdam@pobox.com
10  *
11  ******************************************************************************
12  * Copyright (c) 2005, Frank Warmerdam <warmerdam@pobox.com>
13  * Copyright (c) 2010-2014, Even Rouault <even dot rouault at mines-paris dot org>
14  *
15  * Permission is hereby granted, free of charge, to any person obtaining a
16  * copy of this software and associated documentation files (the "Software"),
17  * to deal in the Software without restriction, including without limitation
18  * the rights to use, copy, modify, merge, publish, distribute, sublicense,
19  * and/or sell copies of the Software, and to permit persons to whom the
20  * Software is furnished to do so, subject to the following conditions:
21  *
22  * The above copyright notice and this permission notice shall be included
23  * in all copies or substantial portions of the Software.
24  *
25  * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
26  * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
27  * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
28  * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
29  * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
30  * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
31  * DEALINGS IN THE SOFTWARE.
32  ****************************************************************************/
33 
34 #ifndef CPL_VSI_VIRTUAL_H_INCLUDED
35 #define CPL_VSI_VIRTUAL_H_INCLUDED
36 
37 #include "cpl_vsi.h"
38 #include "cpl_string.h"
39 #include "cpl_multiproc.h"
40 
41 #if defined(WIN32CE)
42 # include "cpl_wince.h"
43 # include <wce_errno.h>
44 # pragma warning(disable:4786) /* Remove annoying warnings in eVC++ and VC++ 6.0 */
45 #endif
46 
47 #include <map>
48 #include <vector>
49 #include <string>
50 
51 /************************************************************************/
52 /* VSIVirtualHandle */
53 /************************************************************************/
54 
55 class CPL_DLL VSIVirtualHandle {
56  public:
57  virtual int Seek( vsi_l_offset nOffset, int nWhence ) = 0;
58  virtual vsi_l_offset Tell() = 0;
59  virtual size_t Read( void *pBuffer, size_t nSize, size_t nMemb ) = 0;
60  virtual int ReadMultiRange( int nRanges, void ** ppData, const vsi_l_offset* panOffsets, const size_t* panSizes );
61  virtual size_t Write( const void *pBuffer, size_t nSize,size_t nMemb)=0;
62  virtual int Eof() = 0;
63  virtual int Flush() {return 0;}
64  virtual int Close() = 0;
65  virtual int Truncate( CPL_UNUSED vsi_l_offset nNewSize ) { return -1; }
66  virtual void *GetNativeFileDescriptor() { return NULL; }
67  virtual ~VSIVirtualHandle() { }
68 };
69 
70 /************************************************************************/
71 /* VSIFilesystemHandler */
72 /************************************************************************/
73 
74 class CPL_DLL VSIFilesystemHandler {
75 
76 public:
77 
78  virtual ~VSIFilesystemHandler() {}
79 
80  virtual VSIVirtualHandle *Open( const char *pszFilename,
81  const char *pszAccess) = 0;
82  virtual int Stat( const char *pszFilename, VSIStatBufL *pStatBuf, int nFlags) = 0;
83  virtual int Unlink( const char *pszFilename )
84  { (void) pszFilename; errno=ENOENT; return -1; }
85  virtual int Mkdir( const char *pszDirname, long nMode )
86  {(void)pszDirname; (void)nMode; errno=ENOENT; return -1;}
87  virtual int Rmdir( const char *pszDirname )
88  { (void) pszDirname; errno=ENOENT; return -1; }
89  virtual char **ReadDir( const char *pszDirname )
90  { (void) pszDirname; return NULL; }
91  virtual int Rename( const char *oldpath, const char *newpath )
92  { (void) oldpath; (void)newpath; errno=ENOENT; return -1; }
93  virtual int IsCaseSensitive( const char* pszFilename )
94  { (void) pszFilename; return TRUE; }
95 };
96 
97 /************************************************************************/
98 /* VSIFileManager */
99 /************************************************************************/
100 
101 class CPL_DLL VSIFileManager
102 {
103 private:
104  VSIFilesystemHandler *poDefaultHandler;
105  std::map<std::string, VSIFilesystemHandler *> oHandlers;
106 
107  VSIFileManager();
108 
109  static VSIFileManager *Get();
110 
111 public:
112  ~VSIFileManager();
113 
114  static VSIFilesystemHandler *GetHandler( const char * );
115  static void InstallHandler( const std::string& osPrefix,
117  /* RemoveHandler is never defined. */
118  /* static void RemoveHandler( const std::string& osPrefix ); */
119 };
120 
121 
122 /************************************************************************/
123 /* ==================================================================== */
124 /* VSIArchiveFilesystemHandler */
125 /* ==================================================================== */
126 /************************************************************************/
127 
129 {
130  public:
131  virtual ~VSIArchiveEntryFileOffset();
132 };
133 
134 typedef struct
135 {
136  char *fileName;
137  vsi_l_offset uncompressed_size;
138  VSIArchiveEntryFileOffset* file_pos;
139  int bIsDir;
140  GIntBig nModifiedTime;
142 
143 typedef struct
144 {
145  time_t mTime;
146  vsi_l_offset nFileSize;
147  int nEntries;
148  VSIArchiveEntry* entries;
150 
152 {
153  public:
154  virtual ~VSIArchiveReader();
155 
156  virtual int GotoFirstFile() = 0;
157  virtual int GotoNextFile() = 0;
158  virtual VSIArchiveEntryFileOffset* GetFileOffset() = 0;
159  virtual GUIntBig GetFileSize() = 0;
160  virtual CPLString GetFileName() = 0;
161  virtual GIntBig GetModifiedTime() = 0;
162  virtual int GotoFileOffset(VSIArchiveEntryFileOffset* pOffset) = 0;
163 };
164 
166 {
167 protected:
168  CPLMutex* hMutex;
169  /* We use a cache that contains the list of files containes in a VSIArchive file as */
170  /* unarchive.c is quite inefficient in listing them. This speeds up access to VSIArchive files */
171  /* containing ~1000 files like a CADRG product */
172  std::map<CPLString,VSIArchiveContent*> oFileList;
173 
174  virtual const char* GetPrefix() = 0;
175  virtual std::vector<CPLString> GetExtensions() = 0;
176  virtual VSIArchiveReader* CreateReader(const char* pszArchiveFileName) = 0;
177 
178 public:
180  virtual ~VSIArchiveFilesystemHandler();
181 
182  virtual int Stat( const char *pszFilename, VSIStatBufL *pStatBuf, int nFlags );
183  virtual int Unlink( const char *pszFilename );
184  virtual int Rename( const char *oldpath, const char *newpath );
185  virtual int Mkdir( const char *pszDirname, long nMode );
186  virtual int Rmdir( const char *pszDirname );
187  virtual char **ReadDir( const char *pszDirname );
188 
189  virtual const VSIArchiveContent* GetContentOfArchive(const char* archiveFilename, VSIArchiveReader* poReader = NULL);
190  virtual char* SplitFilename(const char *pszFilename, CPLString &osFileInArchive, int bCheckMainFileExists);
191  virtual VSIArchiveReader* OpenArchiveFile(const char* archiveFilename, const char* fileInArchiveName);
192  virtual int FindFileInArchive(const char* archiveFilename, const char* fileInArchiveName, const VSIArchiveEntry** archiveEntry);
193 };
194 
195 VSIVirtualHandle CPL_DLL *VSICreateBufferedReaderHandle(VSIVirtualHandle* poBaseHandle);
196 VSIVirtualHandle* VSICreateBufferedReaderHandle(VSIVirtualHandle* poBaseHandle,
197  const GByte* pabyBeginningContent,
198  vsi_l_offset nSheatFileSize);
199 VSIVirtualHandle* VSICreateCachedFile( VSIVirtualHandle* poBaseHandle, size_t nChunkSize = 32768, size_t nCacheSize = 0 );
200 VSIVirtualHandle CPL_DLL *VSICreateGZipWritable( VSIVirtualHandle* poBaseHandle, int bRegularZLibIn, int bAutoCloseBaseHandle );
201 
202 #endif /* ndef CPL_VSI_VIRTUAL_H_INCLUDED */
Definition: cpl_vsi_virtual.h:74
Definition: cpl_vsi_virtual.h:165
Definition: cpl_vsi_virtual.h:55
Convenient string class based on std::string.
Definition: cpl_string.h:236
Definition: cpl_vsi_virtual.h:143
Definition: cpl_vsi_virtual.h:134
Definition: cpl_vsi_virtual.h:151
Definition: cpl_vsi_virtual.h:101
Definition: cpl_vsi_virtual.h:128

Generated for GDAL by doxygen 1.8.11.