GDAL
cpl_vsi_virtual.h
00001 /******************************************************************************
00002  * $Id: cpl_vsi_virtual.h 36501 2016-11-25 14:09:24Z rouault $
00003  *
00004  * Project:  VSI Virtual File System
00005  * Purpose:  Declarations for classes related to the virtual filesystem.
00006  *           These would only be normally required by applications implementing
00007  *           their own virtual file system classes which should be rare.
00008  *           The class interface may be fragile through versions.
00009  * Author:   Frank Warmerdam, warmerdam@pobox.com
00010  *
00011  ******************************************************************************
00012  * Copyright (c) 2005, Frank Warmerdam <warmerdam@pobox.com>
00013  * Copyright (c) 2010-2014, Even Rouault <even dot rouault at mines-paris dot org>
00014  *
00015  * Permission is hereby granted, free of charge, to any person obtaining a
00016  * copy of this software and associated documentation files (the "Software"),
00017  * to deal in the Software without restriction, including without limitation
00018  * the rights to use, copy, modify, merge, publish, distribute, sublicense,
00019  * and/or sell copies of the Software, and to permit persons to whom the
00020  * Software is furnished to do so, subject to the following conditions:
00021  *
00022  * The above copyright notice and this permission notice shall be included
00023  * in all copies or substantial portions of the Software.
00024  *
00025  * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
00026  * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
00027  * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
00028  * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
00029  * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
00030  * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
00031  * DEALINGS IN THE SOFTWARE.
00032  ****************************************************************************/
00033 
00034 #ifndef CPL_VSI_VIRTUAL_H_INCLUDED
00035 #define CPL_VSI_VIRTUAL_H_INCLUDED
00036 
00037 #include "cpl_vsi.h"
00038 #include "cpl_vsi_error.h"
00039 #include "cpl_string.h"
00040 #include "cpl_multiproc.h"
00041 
00042 #include <map>
00043 #include <vector>
00044 #include <string>
00045 
00046 // To avoid aliasing to GetDiskFreeSpace to GetDiskFreeSpaceA on Windows
00047 #ifdef GetDiskFreeSpace
00048 #undef GetDiskFreeSpace
00049 #endif
00050 
00051 /************************************************************************/
00052 /*                           VSIVirtualHandle                           */
00053 /************************************************************************/
00054 
00056 class CPL_DLL VSIVirtualHandle {
00057   public:
00058     virtual int       Seek( vsi_l_offset nOffset, int nWhence ) = 0;
00059     virtual vsi_l_offset Tell() = 0;
00060     virtual size_t    Read( void *pBuffer, size_t nSize, size_t nCount ) = 0;
00061     virtual int       ReadMultiRange( int nRanges, void ** ppData,
00062                                       const vsi_l_offset* panOffsets,
00063                                       const size_t* panSizes );
00064     virtual size_t    Write( const void *pBuffer, size_t nSize,size_t nCount)=0;
00065     virtual int       Eof() = 0;
00066     virtual int       Flush() {return 0;}
00067     virtual int       Close() = 0;
00068     // Base implementation that only supports file extension.
00069     virtual int       Truncate( vsi_l_offset nNewSize );
00070     virtual void     *GetNativeFileDescriptor() { return NULL; }
00071     virtual VSIRangeStatus GetRangeStatus( CPL_UNUSED vsi_l_offset nOffset,
00072                                            CPL_UNUSED vsi_l_offset nLength )
00073                                           { return VSI_RANGE_STATUS_UNKNOWN; }
00074 
00075     virtual           ~VSIVirtualHandle() { }
00076 };
00077 
00078 /************************************************************************/
00079 /*                         VSIFilesystemHandler                         */
00080 /************************************************************************/
00081 
00082 #ifndef DOXYGEN_SKIP
00083 class CPL_DLL VSIFilesystemHandler {
00084 
00085 public:
00086 
00087     virtual ~VSIFilesystemHandler() {}
00088 
00089     VSIVirtualHandle *Open( const char *pszFilename,
00090                             const char *pszAccess );
00091 
00092     virtual VSIVirtualHandle *Open( const char *pszFilename,
00093                                     const char *pszAccess,
00094                                     bool bSetError ) = 0;
00095     virtual int Stat( const char *pszFilename, VSIStatBufL *pStatBuf, int nFlags) = 0;
00096     virtual int Unlink( const char *pszFilename )
00097                       { (void) pszFilename; errno=ENOENT; return -1; }
00098     virtual int Mkdir( const char *pszDirname, long nMode )
00099                       {(void)pszDirname; (void)nMode; errno=ENOENT; return -1;}
00100     virtual int Rmdir( const char *pszDirname )
00101                       { (void) pszDirname; errno=ENOENT; return -1; }
00102     virtual char **ReadDir( const char *pszDirname )
00103                       { (void) pszDirname; return NULL; }
00104     virtual char **ReadDirEx( const char *pszDirname, int /* nMaxFiles */ )
00105                       { return ReadDir(pszDirname); }
00106     virtual int Rename( const char *oldpath, const char *newpath )
00107                       { (void) oldpath; (void)newpath; errno=ENOENT; return -1; }
00108     virtual int IsCaseSensitive( const char* pszFilename )
00109                       { (void) pszFilename; return TRUE; }
00110     virtual GIntBig GetDiskFreeSpace( const char* /* pszDirname */ ) { return -1; }
00111     virtual int SupportsSparseFiles( const char* /* pszPath */ ) { return FALSE; }
00112 };
00113 #endif /* #ifndef DOXYGEN_SKIP */
00114 
00115 /************************************************************************/
00116 /*                            VSIFileManager                            */
00117 /************************************************************************/
00118 
00119 #ifndef DOXYGEN_SKIP
00120 class CPL_DLL VSIFileManager
00121 {
00122 private:
00123     VSIFilesystemHandler *poDefaultHandler;
00124     std::map<std::string, VSIFilesystemHandler *> oHandlers;
00125 
00126     VSIFileManager();
00127 
00128     static VSIFileManager *Get();
00129 
00130 public:
00131     ~VSIFileManager();
00132 
00133     static VSIFilesystemHandler *GetHandler( const char * );
00134     static void InstallHandler( const std::string& osPrefix,
00135                                 VSIFilesystemHandler * );
00136     /* RemoveHandler is never defined. */
00137     /* static void RemoveHandler( const std::string& osPrefix ); */
00138 };
00139 #endif /* #ifndef DOXYGEN_SKIP */
00140 
00141 /************************************************************************/
00142 /* ==================================================================== */
00143 /*                       VSIArchiveFilesystemHandler                   */
00144 /* ==================================================================== */
00145 /************************************************************************/
00146 
00147 #ifndef DOXYGEN_SKIP
00148 
00149 class VSIArchiveEntryFileOffset
00150 {
00151     public:
00152         virtual ~VSIArchiveEntryFileOffset();
00153 };
00154 
00155 typedef struct
00156 {
00157     char         *fileName;
00158     vsi_l_offset  uncompressed_size;
00159     VSIArchiveEntryFileOffset*      file_pos;
00160     int           bIsDir;
00161     GIntBig       nModifiedTime;
00162 } VSIArchiveEntry;
00163 
00164 class VSIArchiveContent
00165 {
00166 public:
00167     time_t       mTime;
00168     vsi_l_offset nFileSize;
00169     int nEntries;
00170     VSIArchiveEntry* entries;
00171 
00172     VSIArchiveContent() : mTime(0), nFileSize(0), nEntries(0), entries(NULL) {}
00173     ~VSIArchiveContent();
00174 };
00175 
00176 class VSIArchiveReader
00177 {
00178     public:
00179         virtual ~VSIArchiveReader();
00180 
00181         virtual int GotoFirstFile() = 0;
00182         virtual int GotoNextFile() = 0;
00183         virtual VSIArchiveEntryFileOffset* GetFileOffset() = 0;
00184         virtual GUIntBig GetFileSize() = 0;
00185         virtual CPLString GetFileName() = 0;
00186         virtual GIntBig GetModifiedTime() = 0;
00187         virtual int GotoFileOffset(VSIArchiveEntryFileOffset* pOffset) = 0;
00188 };
00189 
00190 class VSIArchiveFilesystemHandler : public VSIFilesystemHandler
00191 {
00192 protected:
00193     CPLMutex* hMutex;
00194     /* We use a cache that contains the list of files contained in a VSIArchive file as */
00195     /* unarchive.c is quite inefficient in listing them. This speeds up access to VSIArchive files */
00196     /* containing ~1000 files like a CADRG product */
00197     std::map<CPLString,VSIArchiveContent*>   oFileList;
00198 
00199     virtual const char* GetPrefix() = 0;
00200     virtual std::vector<CPLString> GetExtensions() = 0;
00201     virtual VSIArchiveReader* CreateReader(const char* pszArchiveFileName) = 0;
00202 
00203 public:
00204     VSIArchiveFilesystemHandler();
00205     virtual ~VSIArchiveFilesystemHandler();
00206 
00207     virtual int      Stat( const char *pszFilename, VSIStatBufL *pStatBuf, int nFlags ) CPL_OVERRIDE;
00208     virtual int      Unlink( const char *pszFilename ) CPL_OVERRIDE;
00209     virtual int      Rename( const char *oldpath, const char *newpath ) CPL_OVERRIDE;
00210     virtual int      Mkdir( const char *pszDirname, long nMode ) CPL_OVERRIDE;
00211     virtual int      Rmdir( const char *pszDirname ) CPL_OVERRIDE;
00212     virtual char   **ReadDirEx( const char *pszDirname, int nMaxFiles ) CPL_OVERRIDE;
00213 
00214     virtual const VSIArchiveContent* GetContentOfArchive(const char* archiveFilename, VSIArchiveReader* poReader = NULL);
00215     virtual char* SplitFilename(const char *pszFilename, CPLString &osFileInArchive, int bCheckMainFileExists);
00216     virtual VSIArchiveReader* OpenArchiveFile(const char* archiveFilename, const char* fileInArchiveName);
00217     virtual int FindFileInArchive(const char* archiveFilename, const char* fileInArchiveName, const VSIArchiveEntry** archiveEntry);
00218 };
00219 
00220 #endif /* #ifndef DOXYGEN_SKIP */
00221 
00222 VSIVirtualHandle CPL_DLL *VSICreateBufferedReaderHandle(VSIVirtualHandle* poBaseHandle);
00223 VSIVirtualHandle* VSICreateBufferedReaderHandle(VSIVirtualHandle* poBaseHandle,
00224                                                 const GByte* pabyBeginningContent,
00225                                                 vsi_l_offset nCheatFileSize);
00226 VSIVirtualHandle CPL_DLL *VSICreateCachedFile( VSIVirtualHandle* poBaseHandle, size_t nChunkSize = 32768, size_t nCacheSize = 0 );
00227 VSIVirtualHandle CPL_DLL *VSICreateGZipWritable( VSIVirtualHandle* poBaseHandle, int bRegularZLibIn, int bAutoCloseBaseHandle );
00228 
00229 #endif /* ndef CPL_VSI_VIRTUAL_H_INCLUDED */

Generated for GDAL by doxygen 1.7.6.1.