• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /* ------------------------------------------------------------------
2  * Copyright (C) 1998-2009 PacketVideo
3  *
4  * Licensed under the Apache License, Version 2.0 (the "License");
5  * you may not use this file except in compliance with the License.
6  * You may obtain a copy of the License at
7  *
8  *      http://www.apache.org/licenses/LICENSE-2.0
9  *
10  * Unless required by applicable law or agreed to in writing, software
11  * distributed under the License is distributed on an "AS IS" BASIS,
12  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either
13  * express or implied.
14  * See the License for the specific language governing permissions
15  * and limitations under the License.
16  * -------------------------------------------------------------------
17  */
18 // -*- c++ -*-
19 // = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = =
20 
21 //                     O S C L _ F I L E  _ C A C H E
22 
23 // = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = =
24 
25 /*! \addtogroup osclio OSCL IO
26  *
27  * @{
28  */
29 
30 
31 /*! \file oscl_file_cache.h
32     \brief The file oscl_file_cache.h defines the  class OsclFileCache
33 
34 */
35 
36 #ifndef OSCL_FILE_CACHE_H_INCLUDED
37 #define OSCL_FILE_CACHE_H_INCLUDED
38 
39 #ifndef OSCLCONFIG_IO_H_INCLUDED
40 #include "osclconfig_io.h"
41 #endif
42 
43 #ifndef OSCL_BASE_H_INCLUDED
44 #include "oscl_base.h"
45 #endif
46 
47 #include "oscl_file_io.h"
48 
49 class Oscl_File;
50 
51 class OsclFileCache : public HeapBase
52 {
53     public:
54         OsclFileCache(Oscl_File& aContainer);
55         ~OsclFileCache();
56 
57         int32 Open(uint32 mode, uint32 cache_size);
58 
59         void Close();
60 
61         uint32 Read(void* outputBuffer, uint32 size, uint32 numelements);
62 
63         uint32 Write(const void* inputBuffer, uint32 size, uint32 numelements);
64 
FileSize()65         TOsclFileOffset  FileSize()
66         {
67             return _fileSize;
68         }
69 
70         int32 Seek(TOsclFileOffset  offset, Oscl_File::seek_type origin);
71 
Tell()72         TOsclFileOffset  Tell()
73         {
74             return (_cacheFilePosition + _currentCachePos);
75         }
76 
77         int32 Flush();
78 
EndOfFile()79         int32 EndOfFile()
80         {
81             return (Tell() == FileSize()) ? 1 : 0;
82         }
83 
84     private:
85         Oscl_File& iContainer;
86 
87         //file mode from the Open call.
88         uint32 _mode;
89 
90         //Size of the cache buffer, set by the Open call.
91         uint32 _cacheSize;
92 
93         //constant pointer to cache buffer
94         uint8*    _pCacheBufferStart;
95 
96         //the native file position corresponding to the start of the
97         //cache
98         TOsclFileOffset  _cacheFilePosition;
99 
100         //current working position (virtual file pointer) in the cache.
101         //units: 0-based byte offset from beginning of cache
102         uint32    _currentCachePos;
103 
104         //end of valid data in the cache.
105         //units: 0-based byte offset from beginning of cache
106         uint32    _endCachePos;
107 
108         //variables to track the range of data in the cache that
109         //has been updated by write operations, but has not yet
110         //been written to disk.
111         //units: 0-based byte offset from beginning of cache
112         uint32    _cacheUpdateStart;
113         uint32    _cacheUpdateEnd;
114 
115         //Current file size.  This is a virtual file size and
116         //may not match the native file size when there is
117         //cached data.
118         TOsclFileOffset     _fileSize;
119 
120         //Current true native file position.
121         TOsclFileOffset  _nativePosition;
122 
123         int32 SetCachePosition(TOsclFileOffset  pos);
124         int32 FillCacheFromFile();
125         int32 WriteCacheToFile();
126 
127         PVLogger* iLogger;
128 };
129 
130 
131 #endif // OSCL_FILE_CACHE_H_INCLUDED
132 
133 /*! @} */
134 
135