00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00025
00026
00027
00028
00029
00030
00031
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)
00045 #endif
00046
00047 #include <map>
00048 #include <vector>
00049 #include <string>
00050
00051
00052
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
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
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
00118
00119 };
00120
00121
00122
00123
00124
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 int nEntries;
00146 VSIArchiveEntry* entries;
00147 } VSIArchiveContent;
00148
00149 class VSIArchiveReader
00150 {
00151 public:
00152 virtual ~VSIArchiveReader();
00153
00154 virtual int GotoFirstFile() = 0;
00155 virtual int GotoNextFile() = 0;
00156 virtual VSIArchiveEntryFileOffset* GetFileOffset() = 0;
00157 virtual GUIntBig GetFileSize() = 0;
00158 virtual CPLString GetFileName() = 0;
00159 virtual GIntBig GetModifiedTime() = 0;
00160 virtual int GotoFileOffset(VSIArchiveEntryFileOffset* pOffset) = 0;
00161 };
00162
00163 class VSIArchiveFilesystemHandler : public VSIFilesystemHandler
00164 {
00165 protected:
00166 CPLMutex* hMutex;
00167
00168
00169
00170 std::map<CPLString,VSIArchiveContent*> oFileList;
00171
00172 virtual const char* GetPrefix() = 0;
00173 virtual std::vector<CPLString> GetExtensions() = 0;
00174 virtual VSIArchiveReader* CreateReader(const char* pszArchiveFileName) = 0;
00175
00176 public:
00177 VSIArchiveFilesystemHandler();
00178 virtual ~VSIArchiveFilesystemHandler();
00179
00180 virtual int Stat( const char *pszFilename, VSIStatBufL *pStatBuf, int nFlags );
00181 virtual int Unlink( const char *pszFilename );
00182 virtual int Rename( const char *oldpath, const char *newpath );
00183 virtual int Mkdir( const char *pszDirname, long nMode );
00184 virtual int Rmdir( const char *pszDirname );
00185 virtual char **ReadDir( const char *pszDirname );
00186
00187 virtual const VSIArchiveContent* GetContentOfArchive(const char* archiveFilename, VSIArchiveReader* poReader = NULL);
00188 virtual char* SplitFilename(const char *pszFilename, CPLString &osFileInArchive, int bCheckMainFileExists);
00189 virtual VSIArchiveReader* OpenArchiveFile(const char* archiveFilename, const char* fileInArchiveName);
00190 virtual int FindFileInArchive(const char* archiveFilename, const char* fileInArchiveName, const VSIArchiveEntry** archiveEntry);
00191 };
00192
00193 VSIVirtualHandle CPL_DLL *VSICreateBufferedReaderHandle(VSIVirtualHandle* poBaseHandle);
00194 VSIVirtualHandle* VSICreateBufferedReaderHandle(VSIVirtualHandle* poBaseHandle,
00195 const GByte* pabyBeginningContent,
00196 vsi_l_offset nSheatFileSize);
00197 VSIVirtualHandle* VSICreateCachedFile( VSIVirtualHandle* poBaseHandle, size_t nChunkSize = 32768, size_t nCacheSize = 0 );
00198 VSIVirtualHandle CPL_DLL *VSICreateGZipWritable( VSIVirtualHandle* poBaseHandle, int bRegularZLibIn, int bAutoCloseBaseHandle );
00199
00200 #endif