CacheManager.hpp

00001 /*********************************************************************** 00002 * * 00003 * ViTooKi * 00004 * * 00005 * title: CacheManager.hpp * 00006 * * 00007 * * 00008 * * 00009 * ITEC institute of the University of Klagenfurt (Austria) * 00010 * http://www.itec.uni-klu.ac.at * 00011 * * 00012 * * 00013 * For more information visit the ViTooKi homepage: * 00014 * http://ViTooKi.sourceforge.net * 00015 * vitooki-user@lists.sourceforge.net * 00016 * vitooki-devel@lists.sourceforge.net * 00017 * * 00018 * This file is part of ViTooKi, a free video toolkit. * 00019 * ViTooKi is free software; you can redistribute it and/or * 00020 * modify it under the terms of the GNU General Public License * 00021 * as published by the Free Software Foundation; either version 2 * 00022 * of the License, or (at your option) any later version. * 00023 * * 00024 * This program is distributed in the hope that it will be useful, * 00025 * but WITHOUT ANY WARRANTY; without even the implied warranty of * 00026 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * 00027 * GNU General Public License for more details. * 00028 * * 00029 * You should have received a copy of the GNU General Public License * 00030 * along with this program; if not, write to the Free Software * 00031 * Foundation, Inc., 59 Temple Place - Suite 330, Boston, * 00032 * MA 02111-1307, USA. * 00033 * * 00034 ***********************************************************************/ 00035 00036 /*********************************************************************** 00037 * * 00038 * REVISION HISTORY: * 00039 * * 00040 * * 00041 * * 00042 ***********************************************************************/ 00043 00044 // Definition: Abstract Cache Manager Class // 00045 00046 #ifndef _CACHEMANAGER_HPP_ 00047 #define _CACHEMANAGER_HPP_ 00048 00049 #include "global.hpp" 00050 #ifdef ISOMP4 00051 #include "ISOMovies.h" 00052 #endif 00053 #include "VMutex.hpp" 00054 #include "net/ProxySession.hpp" 00055 class ContainerInfo; 00056 class Url; 00057 class MetaObject; 00058 00070 class CacheManager { 00071 protected: 00072 u32 cacheSize; 00073 u32 actSize; 00074 u32 requests; 00075 u32 hits; 00076 u64 byteRequested; 00077 u64 byteHits; 00078 double qualityHits; 00079 VMutex lock; 00084 bool serverMode; 00088 virtual bool replace(bool testPriorDelete) = 0; 00089 public: 00090 virtual ~ CacheManager() {}; 00091 virtual void putVideo(ContainerInfo * video,u32 dskSpaceReserved=0) = 0; 00092 virtual ContainerInfo *getVideo(const Url *URL) = 0; 00093 virtual MetaObject* findMetaObject(const Url* url)=0; 00094 virtual void deleteMetaObject(const Url* url)=0 ; 00095 virtual u32 getCacheSize() { 00096 return cacheSize; 00097 }; 00098 virtual u32 getMaxObjectSize() { 00099 return cacheSize; 00100 } 00101 void lockCache() {lock.lock();}; 00102 void unlockCache() {lock.release();}; 00106 bool reserveDiskSpace(u32 dskSpace) { 00107 prxStat.insertsIntoCM++; 00108 if(dskSpace<getMaxObjectSize()) { 00109 actSize+=dskSpace; 00110 if(replace(true)) { 00111 return true; 00112 } 00113 prxStat.rejectedDueToLocking++; 00114 actSize-=dskSpace; 00115 } 00116 else { 00117 prxStat.rejectedDueToSize++; 00118 } 00119 return false; 00120 }; 00122 void freeDiskSpace(u32 dskSpace) { 00123 assert(actSize>=dskSpace); 00124 actSize-=dskSpace; 00125 // no need to update prxStats, this happens in ProxySession 00126 } 00127 virtual u32 getActSize() { 00128 return actSize; 00129 }; 00130 virtual u32 getRequests() { 00131 return requests; 00132 }; 00133 virtual u32 getHits() { 00134 return hits; 00135 }; 00136 virtual u64 getByteRequested() { 00137 return byteRequested; 00138 }; 00139 virtual u64 getByteHits() { 00140 return byteHits; 00141 }; 00142 virtual double getQualityHits() { 00143 return qualityHits; 00144 } 00145 00146 virtual void getContent() = 0; 00147 00148 virtual void saveCacheIndexToDir(const char* dir) = 0; 00149 00150 void saveStatisticTo(FILE* fp) { 00151 dprintf_full("CacheManager::saveStatisticTo\n"); 00152 if(fp) { 00153 fprintf(fp,"Size: %u\nRequests: %u\nHits: %u\nBytesReq(KB): %u\n BytesHit(KB); %u\n", 00154 cacheSize, requests, hits, (u32)(byteRequested/1024), (u32)(byteHits/1024)); 00155 } 00156 } 00157 }; 00158 00159 #endif /* _CACHEMANAGER_HPP_ */