#include <PageInfo.h>
Public Member Functions | |
PageList () | |
~PageList () | |
void | reset (const int size) |
void | clear () |
void | addPage (CPageInfo *info) |
void | removeOldestOne (const int center) |
CPageInfo * | getPage (const int number) |
CPageInfo * | checkPage (const CPageInfo &info) |
CPageInfo * | checkPage (const TodoItem *pItem) |
void | dump () |
Private Member Functions | |
void | initialize () |
Private Attributes | |
pthread_mutex_t | mutex |
PageInfoPtr * | list |
int | length |
Definition at line 80 of file PageInfo.h.
PageList::PageList | ( | ) |
Definition at line 74 of file PageInfo.cpp.
00075 { 00076 length = 0; list = NULL; 00077 initialize(); 00078 }
PageList::~PageList | ( | ) |
void PageList::initialize | ( | ) | [private] |
void PageList::reset | ( | const int | size | ) |
Definition at line 106 of file PageInfo.cpp.
00107 { 00108 pthread_mutex_lock(&mutex); 00109 for(int i = 0; i < length ; ++i) 00110 { 00111 if (list[i]) 00112 { 00113 delete list[i]; 00114 list[i] = NULL; 00115 } 00116 } 00117 length = size; 00118 if (list) 00119 { 00120 delete [] list; list = NULL; 00121 } 00122 list = new PageInfoPtr[size]; 00123 memset(list, 0, length * sizeof(PageInfoPtr)); 00124 pthread_mutex_unlock(&mutex); 00125 }
void PageList::clear | ( | ) |
void PageList::addPage | ( | CPageInfo * | info | ) |
Definition at line 127 of file PageInfo.cpp.
00128 { 00129 if (NULL == info) return; 00130 int index = info->pageNumber; 00131 if (index < 1 || index > length) return; 00132 pthread_mutex_lock(&mutex); 00133 --index; 00134 if (list[index] == NULL) 00135 { 00136 list[index] = info; 00137 } 00138 else 00139 { 00140 /* 00141 PV_DUMP("Page already exist, parameters:\n"); 00142 PV_DUMP("Original page %d\t\t", list[index]->pageNumber); 00143 PV_DUMP("zoom %lf\t", list[index]->pageZoom); 00144 PV_DUMP("rotate %d\t", list[index]->rotate); 00145 PV_DUMP("time %d\n", list[index]->timestamp); 00146 00147 PV_DUMP("New page %d\t\t", info->pageNumber); 00148 PV_DUMP("zoom %lf\t", info->pageZoom); 00149 PV_DUMP("rotate %d\t", info->rotate); 00150 PV_DUMP("time %d\n", info->timestamp); 00151 */ 00152 delete list[index]; list[index] = info; 00153 } 00154 pthread_mutex_unlock(&mutex); 00155 }
void PageList::removeOldestOne | ( | const int | center | ) |
Definition at line 161 of file PageInfo.cpp.
00162 { 00163 int index = -1, i; 00164 int min = 0x7fffffff; 00165 CPageInfo * pItem = NULL; 00166 pthread_mutex_lock(&mutex); 00167 00168 // find oldest page in unprotected area 00169 for(i = 0; i < center - ProtectWidth && i < length; ++i) 00170 { 00171 pItem = list[i]; 00172 if (pItem && min > pItem->timestamp) 00173 { 00174 index = i; min = pItem->timestamp; 00175 } 00176 } 00177 for(i = center + ProtectWidth; i < length; ++i) 00178 { 00179 pItem = list[i]; 00180 if (pItem && min > pItem->timestamp) 00181 { 00182 index = i; min = pItem->timestamp; 00183 } 00184 } 00185 if (index >= 0 && index < length) 00186 { 00187 PV_LOGPRINTF("delete page %d", list[index]->pageNumber); 00188 delete list[index]; list[index] = NULL; 00189 pthread_mutex_unlock(&mutex); 00190 return; 00191 } 00192 00193 // remove page most far from current page 00194 index = -1; 00195 int dist = 0, pos = -1; 00196 for(i = -ProtectWidth; i <= ProtectWidth; ++i) 00197 { 00198 index = center + i - 1; 00199 if (index < 0) index = 0; 00200 else if (index >= length) index = length - 1; 00201 if (list[index] && abs(index + 1 - center) > dist) 00202 { 00203 pos = index; 00204 dist = abs(index + 1 - center); 00205 } 00206 } 00207 if (pos >= 0 && pos != center - 1) 00208 { 00209 PV_LOGPRINTF("delete page %d\n", list[pos]->pageNumber); 00210 delete list[pos]; list[pos] = NULL; 00211 } 00212 pthread_mutex_unlock(&mutex); 00213 }
CPageInfo * PageList::getPage | ( | const int | number | ) |
Definition at line 226 of file PageInfo.cpp.
00227 { 00228 CPageInfo * pItem = getPage(info.pageNumber); 00229 if (NULL == pItem) return NULL; 00230 if (pItem->isSame(info.pageNumber, info.pageZoom, info.rotate)) 00231 { 00232 return pItem; 00233 } 00234 return NULL; 00235 }
Definition at line 237 of file PageInfo.cpp.
00238 { 00239 if (NULL == todo) return NULL; 00240 CPageInfo * pItem = getPage(todo->pageNumber); 00241 if (NULL == pItem) return NULL; 00242 if (pItem->isSame(todo->pageNumber, todo->zoom, todo->rotate)) 00243 { 00244 return pItem; 00245 } 00246 return NULL; 00247 }
void PageList::dump | ( | ) |
Definition at line 249 of file PageInfo.cpp.
00250 { 00251 PV_DUMP("\n\nPageList:\n"); 00252 CPageInfo * pItem = NULL; 00253 pthread_mutex_lock(&mutex); 00254 for(int i = 0; i < length; ++i) 00255 { 00256 pItem = list[i]; 00257 if (pItem) 00258 { 00259 PV_DUMP("page %d\t", pItem->pageNumber); 00260 PV_DUMP("zoom %lf\t", pItem->pageZoom); 00261 PV_DUMP("rotate %d\t", pItem->rotate); 00262 PV_DUMP("time %d\n", pItem->timestamp); 00263 } 00264 } 00265 PV_DUMP("\n\n"); 00266 pthread_mutex_unlock(&mutex); 00267 }
pthread_mutex_t PageList::mutex [private] |
Definition at line 83 of file PageInfo.h.
PageInfoPtr* PageList::list [private] |
Definition at line 84 of file PageInfo.h.
int PageList::length [private] |
Definition at line 85 of file PageInfo.h.