GDAL
cpl_vsi_virtual.h
00001 /******************************************************************************
00002  * $Id: cpl_vsi_virtual.h 29388 2015-06-17 18:28:29Z 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 implmenting
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_string.h"
00039 #include "cpl_multiproc.h"
00040 
00041 #if defined(WIN32CE)
00042 #  include "cpl_wince.h"
00043 #  include <wce_errno.h>
00044 #  pragma warning(disable:4786) /* Remove annoying warnings in eVC++ and VC++ 6.0 */
00045 #endif
00046 
00047 #include <map>
00048 #include <vector>
00049 #include <string>
00050 
00051 /************************************************************************/
00052 /*                           VSIVirtualHandle                           */
00053 /************************************************************************/
00054 
00055 class CPL_DLL VSIVirtualHandle { 
00056   public:
00057     virtual int       Seek( vsi_l_offset nOffset, int nWhence ) = 0;
00058     virtual vsi_l_offset Tell() = 0;
00059     virtual size_t    Read( void *pBuffer, size_t nSize, size_t nMemb ) = 0;
00060     virtual int       ReadMultiRange( int nRanges, void ** ppData, const vsi_l_offset* panOffsets, const size_t* panSizes );
00061     virtual size_t    Write( const void *pBuffer, size_t nSize,size_t nMemb)=0;
00062     virtual int       Eof() = 0;
00063     virtual int       Flush() {return 0;}
00064     virtual int       Close() = 0;
00065     virtual int       Truncate( CPL_UNUSED vsi_l_offset nNewSize ) { return -1; }
00066     virtual void     *GetNativeFileDescriptor() { return NULL; }
00067     virtual           ~VSIVirtualHandle() { }
00068 };
00069 
00070 /************************************************************************/
00071 /*                         VSIFilesystemHandler                         */
00072 /************************************************************************/
00073 
00074 class CPL_DLL VSIFilesystemHandler {
00075 
00076 public:
00077 
00078     virtual ~VSIFilesystemHandler() {}
00079 
00080     virtual VSIVirtualHandle *Open( const char *pszFilename, 
00081                                     const char *pszAccess) = 0;
00082     virtual int Stat( const char *pszFilename, VSIStatBufL *pStatBuf, int nFlags) = 0;
00083     virtual int Unlink( const char *pszFilename )
00084                       { (void) pszFilename; errno=ENOENT; return -1; }
00085     virtual int Mkdir( const char *pszDirname, long nMode ) 
00086                       {(void)pszDirname; (void)nMode; errno=ENOENT; return -1;}
00087     virtual int Rmdir( const char *pszDirname ) 
00088                       { (void) pszDirname; errno=ENOENT; return -1; }
00089     virtual char **ReadDir( const char *pszDirname ) 
00090                       { (void) pszDirname; return NULL; }
00091     virtual int Rename( const char *oldpath, const char *newpath )
00092                       { (void) oldpath; (void)newpath; errno=ENOENT; return -1; }
00093     virtual int IsCaseSensitive( const char* pszFilename )
00094                       { (void) pszFilename; return TRUE; }
00095 };
00096 
00097 /************************************************************************/
00098 /*                            VSIFileManager                            */
00099 /************************************************************************/
00100 
00101 class CPL_DLL VSIFileManager 
00102 {
00103 private:
00104     VSIFilesystemHandler *poDefaultHandler;
00105     std::map<std::string, VSIFilesystemHandler *> oHandlers;
00106 
00107     VSIFileManager();
00108 
00109     static VSIFileManager *Get();
00110 
00111 public:
00112     ~VSIFileManager();
00113 
00114     static VSIFilesystemHandler *GetHandler( const char * );
00115     static void InstallHandler( const std::string& osPrefix, 
00116                                 VSIFilesystemHandler * );
00117     /* RemoveHandler is never defined. */
00118     /* static void RemoveHandler( const std::string& osPrefix ); */
00119 };
00120 
00121 
00122 /************************************************************************/
00123 /* ==================================================================== */
00124 /*                       VSIArchiveFilesystemHandler                   */
00125 /* ==================================================================== */
00126 /************************************************************************/
00127 
00128 class VSIArchiveEntryFileOffset
00129 {
00130     public:
00131         virtual ~VSIArchiveEntryFileOffset();
00132 };
00133 
00134 typedef struct
00135 {
00136     char         *fileName;
00137     vsi_l_offset  uncompressed_size;
00138     VSIArchiveEntryFileOffset*      file_pos;
00139     int           bIsDir;
00140     GIntBig       nModifiedTime;
00141 } VSIArchiveEntry;
00142 
00143 typedef struct
00144 {
00145     time_t       mTime;
00146     vsi_l_offset nFileSize;
00147     int nEntries;
00148     VSIArchiveEntry* entries;
00149 } VSIArchiveContent;
00150 
00151 class VSIArchiveReader
00152 {
00153     public:
00154         virtual ~VSIArchiveReader();
00155 
00156         virtual int GotoFirstFile() = 0;
00157         virtual int GotoNextFile() = 0;
00158         virtual VSIArchiveEntryFileOffset* GetFileOffset() = 0;
00159         virtual GUIntBig GetFileSize() = 0;
00160         virtual CPLString GetFileName() = 0;
00161         virtual GIntBig GetModifiedTime() = 0;
00162         virtual int GotoFileOffset(VSIArchiveEntryFileOffset* pOffset) = 0;
00163 };
00164 
00165 class VSIArchiveFilesystemHandler : public VSIFilesystemHandler 
00166 {
00167 protected:
00168     CPLMutex* hMutex;
00169     /* We use a cache that contains the list of files containes in a VSIArchive file as */
00170     /* unarchive.c is quite inefficient in listing them. This speeds up access to VSIArchive files */
00171     /* containing ~1000 files like a CADRG product */
00172     std::map<CPLString,VSIArchiveContent*>   oFileList;
00173 
00174     virtual const char* GetPrefix() = 0;
00175     virtual std::vector<CPLString> GetExtensions() = 0;
00176     virtual VSIArchiveReader* CreateReader(const char* pszArchiveFileName) = 0;
00177 
00178 public:
00179     VSIArchiveFilesystemHandler();
00180     virtual ~VSIArchiveFilesystemHandler();
00181 
00182     virtual int      Stat( const char *pszFilename, VSIStatBufL *pStatBuf, int nFlags );
00183     virtual int      Unlink( const char *pszFilename );
00184     virtual int      Rename( const char *oldpath, const char *newpath );
00185     virtual int      Mkdir( const char *pszDirname, long nMode );
00186     virtual int      Rmdir( const char *pszDirname );
00187     virtual char   **ReadDir( const char *pszDirname );
00188 
00189     virtual const VSIArchiveContent* GetContentOfArchive(const char* archiveFilename, VSIArchiveReader* poReader = NULL);
00190     virtual char* SplitFilename(const char *pszFilename, CPLString &osFileInArchive, int bCheckMainFileExists);
00191     virtual VSIArchiveReader* OpenArchiveFile(const char* archiveFilename, const char* fileInArchiveName);
00192     virtual int FindFileInArchive(const char* archiveFilename, const char* fileInArchiveName, const VSIArchiveEntry** archiveEntry);
00193 };
00194 
00195 VSIVirtualHandle CPL_DLL *VSICreateBufferedReaderHandle(VSIVirtualHandle* poBaseHandle);
00196 VSIVirtualHandle* VSICreateBufferedReaderHandle(VSIVirtualHandle* poBaseHandle,
00197                                                 const GByte* pabyBeginningContent,
00198                                                 vsi_l_offset nSheatFileSize);
00199 VSIVirtualHandle* VSICreateCachedFile( VSIVirtualHandle* poBaseHandle, size_t nChunkSize = 32768, size_t nCacheSize = 0 );
00200 VSIVirtualHandle CPL_DLL *VSICreateGZipWritable( VSIVirtualHandle* poBaseHandle, int bRegularZLibIn, int bAutoCloseBaseHandle );
00201 
00202 #endif /* ndef CPL_VSI_VIRTUAL_H_INCLUDED */

Generated for GDAL by doxygen 1.7.6.1.