00001
00002
00003
00004
00005
00006
00007
00019 #ifndef OSCL_FILE_CACHE_H_INCLUDED
00020 #define OSCL_FILE_CACHE_H_INCLUDED
00021
00022 #ifndef OSCLCONFIG_IO_H_INCLUDED
00023 #include "osclconfig_io.h"
00024 #endif
00025
00026 #ifndef OSCL_BASE_H_INCLUDED
00027 #include "oscl_base.h"
00028 #endif
00029
00030 #include "oscl_file_io.h"
00031
00032 class OsclFileCache;
00033
00034 class OsclFileCacheBuffer
00035 {
00036 public:
00037 OsclFileCacheBuffer(): isFixed(false)
00038 , capacity(0)
00039 , usableSize(0)
00040 , pBuffer(NULL)
00041 , filePosition(0)
00042 , currentPos(0)
00043 , endPos(0)
00044 , updateStart(0)
00045 , updateEnd(0)
00046 {}
00047
00048 OsclFileCache* iContainer;
00049
00050
00051 bool isFixed;
00052
00053
00054 uint32 capacity;
00055
00056
00057 uint32 usableSize;
00058
00059
00060 uint8* pBuffer;
00061
00062
00063
00064 TOsclFileOffset filePosition;
00065
00066
00067
00068 uint32 currentPos;
00069
00070
00071
00072 uint32 endPos;
00073
00074
00075
00076
00077
00078 uint32 updateStart;
00079 uint32 updateEnd;
00080
00081 int32 SetPosition(TOsclFileOffset pos);
00082 int32 PrepRead();
00083 int32 PrepWrite();
00084 int32 WriteUpdatesToFile();
00085 int32 FillFromFile(uint32, uint32);
00086
00087 bool IsUpdated()
00088 {
00089 return updateEnd > updateStart;
00090 }
00091
00092
00093 bool Contains(TOsclFileOffset pos)
00094 {
00095 return (filePosition <= pos && pos < filePosition + (TOsclFileOffset)usableSize);
00096 }
00097
00098 bool Preceeds(TOsclFileOffset pos)
00099 {
00100 return (filePosition + (TOsclFileOffset)usableSize <= pos);
00101 }
00102 };
00103
00104 class Oscl_File;
00105
00106 class OsclFileCache : public HeapBase
00107 {
00108 public:
00109 OsclFileCache(Oscl_File& aContainer);
00110 ~OsclFileCache();
00111
00112 int32 Open(uint32 mode, uint32 cache_size);
00113
00114 void Close();
00115
00116 uint32 Read(void* outputBuffer, uint32 size, uint32 numelements);
00117
00118 uint32 Write(const void* inputBuffer, uint32 size, uint32 numelements);
00119
00120 TOsclFileOffset FileSize()
00121 {
00122 return _fileSize;
00123 }
00124
00125 int32 Seek(TOsclFileOffset offset, Oscl_File::seek_type origin);
00126
00127 TOsclFileOffset Tell()
00128 {
00129 return (_curCache) ? (_curCache->filePosition + _curCache->currentPos) : 0;
00130 }
00131
00132 int32 Flush();
00133
00134 int32 EndOfFile()
00135 {
00136 return (Tell() == FileSize()) ? 1 : 0;
00137 }
00138
00139 private:
00140 friend class OsclFileCacheBuffer;
00141 Oscl_File& iContainer;
00142
00143
00144 uint32 _mode;
00145
00146 public:
00147 OsclFileCacheBuffer _movableCache;
00148 Oscl_Vector<OsclFileCacheBuffer, OsclMemAllocator> _fixedCaches;
00149 OSCL_IMPORT_REF OsclFileCacheBuffer* AddFixedCache(const Oscl_File::OsclFixedCacheParam&);
00150
00151 private:
00152 OsclFileCacheBuffer* _curCache;
00153 int32 SetCachePosition(TOsclFileOffset);
00154 int32 UpdateFixedCaches();
00155
00156
00157
00158
00159 TOsclFileOffset _fileSize;
00160
00161
00162 TOsclFileOffset _nativePosition;
00163
00164 PVLogger* iLogger;
00165 };
00166
00167
00168 #endif // OSCL_FILE_CACHE_H_INCLUDED
00169