PageRenderTime 63ms CodeModel.GetById 31ms app.highlight 11ms RepoModel.GetById 19ms app.codeStats 0ms

/indra/newview/llvocache.h

https://bitbucket.org/lindenlab/viewer-beta/
C++ Header | 156 lines | 103 code | 22 blank | 31 comment | 2 complexity | 38ec140237e525d4bcbedbb5ea32ef92 MD5 | raw file
  1/** 
  2 * @file llvocache.h
  3 * @brief Cache of objects on the viewer.
  4 *
  5 * $LicenseInfo:firstyear=2003&license=viewerlgpl$
  6 * Second Life Viewer Source Code
  7 * Copyright (C) 2010, Linden Research, Inc.
  8 * 
  9 * This library is free software; you can redistribute it and/or
 10 * modify it under the terms of the GNU Lesser General Public
 11 * License as published by the Free Software Foundation;
 12 * version 2.1 of the License only.
 13 * 
 14 * This library is distributed in the hope that it will be useful,
 15 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 16 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
 17 * Lesser General Public License for more details.
 18 * 
 19 * You should have received a copy of the GNU Lesser General Public
 20 * License along with this library; if not, write to the Free Software
 21 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301  USA
 22 * 
 23 * Linden Research, Inc., 945 Battery Street, San Francisco, CA  94111  USA
 24 * $/LicenseInfo$
 25 */
 26
 27#ifndef LL_LLVOCACHE_H
 28#define LL_LLVOCACHE_H
 29
 30#include "lluuid.h"
 31#include "lldatapacker.h"
 32#include "lldlinked.h"
 33#include "lldir.h"
 34
 35
 36//---------------------------------------------------------------------------
 37// Cache entries
 38class LLVOCacheEntry;
 39
 40class LLVOCacheEntry
 41{
 42public:
 43	LLVOCacheEntry(U32 local_id, U32 crc, LLDataPackerBinaryBuffer &dp);
 44	LLVOCacheEntry(LLAPRFile* apr_file);
 45	LLVOCacheEntry();
 46	~LLVOCacheEntry();
 47
 48	U32 getLocalID() const			{ return mLocalID; }
 49	U32 getCRC() const				{ return mCRC; }
 50	S32 getHitCount() const			{ return mHitCount; }
 51	S32 getCRCChangeCount() const	{ return mCRCChangeCount; }
 52
 53	void dump() const;
 54	BOOL writeToFile(LLAPRFile* apr_file) const;
 55	void assignCRC(U32 crc, LLDataPackerBinaryBuffer &dp);
 56	LLDataPackerBinaryBuffer *getDP(U32 crc);
 57	void recordHit();
 58	void recordDupe() { mDupeCount++; }
 59
 60public:
 61	typedef std::map<U32, LLVOCacheEntry*>	vocache_entry_map_t;
 62
 63protected:
 64	U32							mLocalID;
 65	U32							mCRC;
 66	S32							mHitCount;
 67	S32							mDupeCount;
 68	S32							mCRCChangeCount;
 69	LLDataPackerBinaryBuffer	mDP;
 70	U8							*mBuffer;
 71};
 72
 73//
 74//Note: LLVOCache is not thread-safe
 75//
 76class LLVOCache
 77{
 78private:
 79	struct HeaderEntryInfo
 80	{
 81		HeaderEntryInfo() : mIndex(0), mHandle(0), mTime(0) {}
 82		S32 mIndex;
 83		U64 mHandle ;
 84		U32 mTime ;
 85	};
 86
 87	struct HeaderMetaInfo
 88	{
 89		HeaderMetaInfo() : mVersion(0){}
 90
 91		U32 mVersion;
 92	};
 93
 94	struct header_entry_less
 95	{
 96		bool operator()(const HeaderEntryInfo* lhs, const HeaderEntryInfo* rhs) const
 97		{
 98			if(lhs->mTime == rhs->mTime) 
 99			{
100				return lhs < rhs ;
101			}
102			
103			return lhs->mTime < rhs->mTime ; // older entry in front of queue (set)
104		}
105	};
106	typedef std::set<HeaderEntryInfo*, header_entry_less> header_entry_queue_t;
107	typedef std::map<U64, HeaderEntryInfo*> handle_entry_map_t;
108private:
109	LLVOCache() ;
110
111public:
112	~LLVOCache() ;
113
114	void initCache(ELLPath location, U32 size, U32 cache_version) ;
115	void removeCache(ELLPath location) ;
116
117	void readFromCache(U64 handle, const LLUUID& id, LLVOCacheEntry::vocache_entry_map_t& cache_entry_map) ;
118	void writeToCache(U64 handle, const LLUUID& id, const LLVOCacheEntry::vocache_entry_map_t& cache_entry_map, BOOL dirty_cache) ;
119	void removeEntry(U64 handle) ;
120
121	void setReadOnly(BOOL read_only) {mReadOnly = read_only;} 
122
123private:
124	void setDirNames(ELLPath location);	
125	// determine the cache filename for the region from the region handle	
126	void getObjectCacheFilename(U64 handle, std::string& filename);
127	void removeFromCache(HeaderEntryInfo* entry);
128	void readCacheHeader();
129	void writeCacheHeader();
130	void clearCacheInMemory();
131	void removeCache() ;
132	void removeEntry(HeaderEntryInfo* entry) ;
133	void purgeEntries(U32 size);
134	BOOL updateEntry(const HeaderEntryInfo* entry);
135	
136private:
137	BOOL                 mEnabled;
138	BOOL                 mInitialized ;
139	BOOL                 mReadOnly ;
140	HeaderMetaInfo       mMetaInfo;
141	U32                  mCacheSize;
142	U32                  mNumEntries;
143	std::string          mHeaderFileName ;
144	std::string          mObjectCacheDirName;
145	LLVolatileAPRPool*   mLocalAPRFilePoolp ; 	
146	header_entry_queue_t mHeaderEntryQueue;
147	handle_entry_map_t   mHandleEntryMap;	
148
149	static LLVOCache* sInstance ;
150public:
151	static LLVOCache* getInstance() ;
152	static BOOL       hasInstance() ;	
153	static void       destroyClass() ;
154};
155
156#endif