Main Page Modules Class Hierarchy Data Structures File List Data Fields Globals Related Pages

# oscl_file_io.h

Go to the documentation of this file.

    00001 // -*- c++ -*-
    00002 // = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = =
    00003
    00004 //                     O S C L _ F I L E  _ I O
    00005
    00006 // = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = =
    00007
    00021 #ifndef OSCL_FILE_IO_H_INCLUDED
    00022 #define OSCL_FILE_IO_H_INCLUDED
    00023
    00024 #ifndef OSCLCONFIG_IO_H_INCLUDED
    00025 #include "osclconfig_io.h"
    00026 #endif
    00027
    00028 #ifndef OSCL_BASE_H_INCLUDED
    00029 #include "oscl_base.h"
    00030 #endif
    00031
    00032 #ifndef OSCL_MEM_H_INCLUDED
    00033 #include "oscl_mem.h"
    00034 #endif
    00035
    00036 #ifndef OSCL_VECTOR_H_INCLUDED
    00037 #include "oscl_vector.h"
    00038 #endif
    00039
    00047 class PVLogger;
    00048 class OsclFileCache;
    00049 class OsclFileCacheBuffer;
    00050 class Oscl_FileServer;
    00051 class OsclFileHandle;
    00052 class OsclNativeFile;
    00053 class OsclFileStats;
    00054 class OsclNativeFileParams;
    00055 class OsclAsyncFile;
    00056 #define TOsclFileOffsetInt32 int32
    00057
    00058 class Oscl_File : public HeapBase
    00059 {
    00060     public:
    00061
    00062         typedef enum
    00063         {
    00067             SEEKSET,
    00071             SEEKCUR,
    00075             SEEKEND
    00076         } seek_type;
    00077
    00078         typedef enum
    00079         {
    00083             MODE_READ =      0x0001,
    00089             MODE_READWRITE = 0x0002,
    00096             MODE_APPEND =    0x0004,
    00100             MODE_BINARY =    0x0008,
    00104             MODE_TEXT =      0x0010,
    00109             MODE_READ_PLUS =  0x0020
    00110
    00111         } mode_type;
    00112
    00116         OSCL_IMPORT_REF Oscl_File();
    00117
    00123         OSCL_IMPORT_REF Oscl_File(uint32 aCacheSize);
    00130         OSCL_IMPORT_REF Oscl_File(uint32 aCacheSize, OsclFileHandle* aFileHandle);
    00131
    00135         OSCL_IMPORT_REF ~Oscl_File();
    00136
    00146         OSCL_IMPORT_REF void SetPVCacheSize(uint32 aSize);
    00147
    00151         class OsclFixedCacheParam
    00152         {
    00153             public:
    00154                 /*
    00155                 ** File position where the fixed cache is located.
    00156                 */
    00157                 TOsclFileOffset iFilePosition;
    00158                 /*
    00159                 ** Fixed cache size in bytes.
    00160                 */
    00161                 uint32 iSize;
    00162
    00163                 bool Contains(TOsclFileOffset pos) const
    00164                 {
    00165                     return (iFilePosition <= pos && pos < iFilePosition + (TOsclFileOffset)iSize);
    00166                 }
    00167         };
    00168
    00176         void AddFixedCache(const OsclFixedCacheParam& aParam)
    00177         {
    00178             iAddFixedCache.push_back(aParam);
    00179         }
    00180
    00186         void RemoveFixedCache(const TOsclFileOffset &aPos)
    00187         {
    00188             iRemoveFixedCache.push_back(aPos);
    00189         }
    00190
    00196         class OsclCacheObserver
    00197         {
    00198             public:
    00199                 virtual ~OsclCacheObserver() {};
    00200                 virtual OsclFileCacheBuffer* ChooseCurCache(OsclFileCache& aContext, TOsclFileOffset aPos) = 0;
    00201         };
    00202         void SetCacheObserver(OsclCacheObserver* aObs)
    00203         {
    00204             iCacheObserver = aObs;
    00205         }
    00206
    00217         OSCL_IMPORT_REF void SetNativeAccessMode(uint32 aMode);
    00218
    00222         enum TSymbianAccessMode
    00223         {
    00224             ESymbianAccessMode_Rfile = 0
    00225             , ESymbianAccessMode_RfileBuf = 1
    00226         };
    00227
    00242         OSCL_IMPORT_REF void SetNativeBufferSize(int32 aSize);
    00243
    00257         OSCL_IMPORT_REF void SetAsyncReadBufferSize(uint32 aSize);
    00258
    00281         OSCL_IMPORT_REF int32 SetFileHandle(OsclFileHandle* aHandle);
    00282
    00296         OSCL_IMPORT_REF int32 Open(const char *filename, uint32 mode, Oscl_FileServer& fileserv);
    00297
    00310         OSCL_IMPORT_REF int32 Open(const oscl_wchar *filename, uint32 mode, Oscl_FileServer& fileserv);
    00311
    00328         OSCL_IMPORT_REF uint32 Read(OsclAny *buffer,
    00329                                     uint32 size,
    00330                                     uint32 numelements);
    00331
    00343         OSCL_IMPORT_REF uint32 Write(const OsclAny *buffer,
    00344                                      uint32 size,
    00345                                      uint32 numelements);
    00346
    00347
    00357         OSCL_IMPORT_REF int32 Seek(TOsclFileOffset offset,
    00358                                    seek_type origin);
    00359
    00364         OSCL_IMPORT_REF TOsclFileOffset Tell();
    00365
    00366
    00377         OSCL_IMPORT_REF int32 Close();
    00378
    00379
    00388         OSCL_IMPORT_REF int32 Flush();
    00389
    00397         OSCL_IMPORT_REF int32 SetSize(uint32 size);
    00398
    00406         OSCL_IMPORT_REF int32 EndOfFile();
    00407
    00408
    00416         OSCL_IMPORT_REF int32 GetError();
    00417
    00423         OsclFileHandle* Handle()
    00424         {
    00425             return iOpenFileHandle;
    00426         }
    00427
    00433         OSCL_IMPORT_REF TOsclFileOffset Size();
    00434
    00443         OSCL_IMPORT_REF void SetLoggingEnable(bool aEnable);
    00444
    00452         OSCL_IMPORT_REF void SetSummaryStatsLoggingEnable(bool aEnable);
    00453
    00454
    00455     private:
    00456         friend class OsclFileCache;
    00457         friend class OsclFileCacheBuffer;
    00458         friend class asyncfilereadwrite_test;
    00459         friend class largeasyncfilereadwrite_test;
    00460         friend class asyncfilereadcancel_test;
    00461
    00462         void Construct();
    00463         void OldCacheDefaults();
    00464         void OldCacheSelect(uint32);
    00465
    00466         //state info
    00467         bool iIsOpen;
    00468
    00469         //For Logging
    00470         PVLogger* iLogger;
    00471         PVLogger* iStatsLogger;
    00472         PVLogger* iNativeLogger;
    00473         PVLogger* iAsyncLogger;
    00474         OsclFileStats* iFileStats;
    00475         void CreateFileStats();
    00476
    00477         //External file handle.
    00478         OsclFileHandle* iOpenFileHandle;
    00479
    00480         //For PV File Cache
    00481         uint32 iPVCacheSize;
    00482         OsclFileCache* iFileCache;
    00483         Oscl_Vector<OsclFixedCacheParam, OsclMemAllocator> iAddFixedCache;
    00484         Oscl_Vector<TOsclFileOffset, OsclMemAllocator> iRemoveFixedCache;
    00485         OsclCacheObserver* iCacheObserver;
    00486
    00487         int32 OpenFileCacheOrAsyncBuffer(const char *filename
    00488                                          , const oscl_wchar* wfilename
    00489                                          , uint32 mode
    00490                                          , const OsclNativeFileParams& params
    00491                                          , Oscl_FileServer& fileserv) ;
    00492
    00493         //For native file I/O.
    00494         OsclNativeFile* iNativeFile;
    00495         int32 iNativeBufferSize;
    00496         uint32 iNativeAccessMode;
    00497
    00498         //For async read feature
    00499         uint32 iAsyncReadBufferSize;
    00500         OsclAsyncFile* iAsyncFile;
    00501
    00502         // These are wrappers to call the Native OS File IO calls with
    00503         // stats and logging.
    00504
    00505         int32  CallNativeOpen(const OsclFileHandle&, uint32 mode
    00506                               , const OsclNativeFileParams& params
    00507                               , Oscl_FileServer& fileserv);
    00508         int32  CallNativeOpen(const oscl_wchar *filename, uint32 mode
    00509                               , const OsclNativeFileParams& params
    00510                               , Oscl_FileServer& fileserv);
    00511         int32  CallNativeOpen(const char *filename, uint32 mode
    00512                               , const OsclNativeFileParams& params
    00513                               , Oscl_FileServer& fileserv);
    00514         uint32 CallNativeRead(OsclAny *buffer, uint32 size, uint32 numelements);
    00515         uint32 CallNativeWrite(const OsclAny *buffer, uint32 size, uint32 numelements);
    00516         int32  CallNativeSeek(TOsclFileOffset offset, Oscl_File::seek_type origin);
    00517         int32  CallNativeSetSize(uint32 size);
    00518         TOsclFileOffset  CallNativeTell();
    00519         int32  CallNativeFlush();
    00520         int32  CallNativeEndOfFile();
    00521         TOsclFileOffset CallNativeSize();
    00522         int32 CallNativeClose();
    00523         uint32 CallNativeMode();
    00524         int32 CallNativeGetError();
    00525         OSCL_IMPORT_REF uint32 GetAsyncFileNumOfRun();
    00526         OSCL_IMPORT_REF uint32 GetAsyncFileNumOfRunError();
    00527
    00528 };
    00529
    00530
    00531 //Include all public file apis for convenience here.
    00532 #include "oscl_file_server.h"
    00533 #include "oscl_file_find.h"
    00534 #include "oscl_file_dir_utils.h"
    00535 #include "oscl_file_handle.h"
    00536
    00537 #endif // OSCL_FILE_IO_H_INCLUDED
    00538