Main Page | Modules | Class Hierarchy | Alphabetical List | Class List | File List | Class Members | File Members | Related Pages
mmapio.h
Go to the documentation of this file.00001 /* 00002 Copyright (C) 2002 by Jorrit Tyberghein 00003 00004 This library is free software; you can redistribute it and/or 00005 modify it under the terms of the GNU Library General Public 00006 License as published by the Free Software Foundation; either 00007 version 2 of the License, or (at your option) any later version. 00008 00009 This library is distributed in the hope that it will be useful, 00010 but WITHOUT ANY WARRANTY; without even the implied warranty of 00011 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 00012 Library General Public License for more details. 00013 00014 You should have received a copy of the GNU Library General Public 00015 License along with this library; if not, write to the Free 00016 Software Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. 00017 */ 00018 00019 #ifndef __CS_MEMORY_MAPPED_IO__ 00020 #define __CS_MEMORY_MAPPED_IO__ 00021 00026 #include "csextern.h" 00027 #include "bitarray.h" 00028 00029 struct iVFS; 00030 00034 const unsigned csmmioDefaultCacheBlockSize = 256; 00035 00039 const unsigned csmmioDefaultCacheSize = 256;//2048; 00040 00044 const unsigned csmmioDefaultHashSize = 211;//1559; 00045 00046 00078 class CS_CSUTIL_EXPORT csMemoryMappedIO 00079 { 00080 private: 00082 unsigned int block_size; 00083 00085 bool valid_mmio_object; 00086 00088 unsigned cache_block_size; 00089 00094 unsigned int cache_max_size; 00095 00097 unsigned int cache_block_count; 00098 00103 csBitArray *page_map; 00104 00105 #ifdef CS_DEBUG 00106 00107 public: 00109 unsigned int hits; 00110 00112 unsigned int misses; 00113 00114 private: 00115 #endif 00116 00118 struct CacheBlock 00119 { 00121 unsigned age; 00122 00124 unsigned offset; 00125 00127 unsigned page; 00128 00130 CacheBlock *next; 00131 00133 unsigned char *data; 00134 }; 00135 00137 CacheBlock *cache[csmmioDefaultHashSize]; 00138 00139 // Software specific csMemMapInfo struct, should only be defined for 00140 // platforms w/o hardware mmio. 00141 struct emulatedMmioInfo 00142 { 00144 FILE *hMappedFile; 00145 00147 unsigned char *data; 00148 00150 unsigned int file_size; 00151 } emulatedPlatform; 00152 00153 #ifdef CS_HAS_MEMORY_MAPPED_IO 00154 00155 csMemMapInfo platform; 00156 00158 bool valid_platform; 00159 #endif 00160 public: 00168 csMemoryMappedIO(unsigned _block_size, char const *filename, iVFS* vfs = 0); 00169 00173 ~csMemoryMappedIO(); 00174 00181 void *GetPointer(unsigned int index); 00182 00186 bool IsValid(); 00187 00188 private: 00190 void CachePage(unsigned int page); 00191 00193 bool SoftMemoryMapFile(emulatedMmioInfo *platform, char const *filename); 00194 00196 void SoftUnMemoryMapFile(emulatedMmioInfo *platform); 00197 }; 00198 00199 #endif // __CS_MEMORY_MAPPED_IO__ 00200
Generated for Crystal Space by doxygen 1.3.9.1