00001 /* 00002 * PageFileHandle.h 00003 * 00004 * Created on: Mar 15, 2010 00005 * Author: green 00006 */ 00007 00008 #ifndef HEAPFILEHANDLE_H_ 00009 #define HEAPFILEHANDLE_H_ 00010 00011 #include "AllocationPage.h" 00012 #include "BufferPool.h" 00013 #include "Common.h" 00014 #include <limits.h> 00015 #include <stdio.h> 00016 00017 static const char STAT_PAGE_READS[] = "STAT_PAGE_READS"; 00018 static const char STAT_PAGE_WRITES[] = "STAT_PAGE_WRITES"; 00019 00020 00024 typedef struct { 00028 int pageNo; 00032 char* data; 00033 } PageHandle; 00034 00035 00041 class PageFileHandle { 00042 public: 00043 PageFileHandle(); 00044 ~PageFileHandle(); 00045 00057 ReturnCode initialize(const char* fileName, FILE* file); 00058 00070 ReturnCode getFirstPage(PageHandle *pageHandle); 00071 00079 ReturnCode getLastPage(PageHandle *pageHandle); 00080 00094 ReturnCode getNextPage(int pageNo, PageHandle *pageHandle); 00095 00104 ReturnCode getPrevPage(int pageNo, PageHandle *pageHandle); 00105 00120 ReturnCode getThisPage(int pageNo, PageHandle *pageHandle); 00121 00134 ReturnCode allocatePage(PageHandle *pageHandle); 00135 00145 ReturnCode disposePage(int pageNo); 00146 00156 ReturnCode markDirty(int pageNo); 00157 00168 ReturnCode unpinPage(int pageNo); 00169 00180 ReturnCode forcePage(int pageNo); 00181 00188 ReturnCode forceAllPages(); 00189 00193 const char* getFileName(); 00194 00201 FILE* getFile(); 00202 00203 static ReturnCode onCreate(const char* fileName, FILE* file); 00204 00208 int countPages(); 00209 00210 private: 00211 uint getOffset(int pageNo); 00212 ReturnCode readPage(uint offset, char* buffer); 00213 ReturnCode writePage(uint offset, const char* buffer); 00214 ReturnCode pinPage(int pageNo); 00215 ReturnCode getBuffer(char* buffer); 00216 ReturnCode mgrForcePage(int pageNo); 00217 ReturnCode forceDirtyPage(int pageNo); 00218 ReturnCode forceAllocationPage(); 00219 ReturnCode updateFileLength(); 00220 00221 static const uint HEADER_SIZE; 00222 00223 AllocationPage alloc_; 00224 char fileName_[MAX_FILE_NAME]; 00225 FILE* file_; 00226 BufferPool* pool_; 00227 }; 00228 00229 #endif /* HEAPFILEHANDLE_H_ */