CrystalSpace

Public API Reference

Main Page   Modules   Class Hierarchy   Alphabetical List   Compound List   File List   Compound Members   File Members  

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 "csutil/bitarray.h"
00027 
00028 struct iVFS;
00029 
00031 const unsigned csmmioDefaultCacheBlockSize = 256;
00032 
00034 const unsigned csmmioDefaultCacheSize = 256;//2048;
00035 
00037 const unsigned csmmioDefaultHashSize = 211;//1559;
00038 
00039 
00070 class csMemoryMappedIO
00071 {
00072 private:
00074   unsigned int block_size;
00075   
00077   bool valid_mmio_object;
00078 
00080   unsigned cache_block_size;
00081 
00083   unsigned int cache_max_size;
00084 
00086   unsigned int cache_block_count;
00087   
00089   csBitArray *page_map;
00090 
00091 #ifdef CS_DEBUG
00092 
00093 public:
00095   unsigned int hits;
00096 
00098   unsigned int misses;
00099 
00100 private:
00101 #endif
00102 
00104   struct CacheBlock
00105   {    
00107     unsigned age;
00108 
00110     unsigned offset;
00111 
00113     unsigned page;
00114     
00116     CacheBlock *next;
00117 
00119     unsigned char *data;
00120   };
00121 
00123   CacheBlock *cache[csmmioDefaultHashSize];
00124 
00125   // Software specific mmioInfo struct, should only be defined for platforms w/o hardware mmio.
00126   struct emulatedMmioInfo 
00127   {          
00129     FILE *hMappedFile;
00130 
00132     unsigned char *data;
00133 
00135     unsigned int file_size;
00136   } emulatedPlatform;
00137   
00138 #ifdef CS_HAS_MEMORY_MAPPED_IO
00139 
00140   mmioInfo platform;
00141   
00143   bool valid_platform;
00144 #endif
00145 public:
00152   csMemoryMappedIO(unsigned _block_size, char const *filename, iVFS* vfs = NULL);
00153 
00157   csMemoryMappedIO::~csMemoryMappedIO();
00158 
00163   void *GetPointer(unsigned int index);
00164   
00168   bool IsValid();
00169 
00170 private:
00172   void CachePage(unsigned int page);
00173 
00175   bool SoftMemoryMapFile(emulatedMmioInfo *platform, char const *filename);
00176 
00178   void SoftUnMemoryMapFile(emulatedMmioInfo *platform);
00179 };
00180 
00181 #endif // __CS_MEMORY_MAPPED_IO__
00182 

Generated for Crystal Space by doxygen 1.2.14