michael@0: /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- michael@0: * michael@0: * This Source Code Form is subject to the terms of the Mozilla Public michael@0: * License, v. 2.0. If a copy of the MPL was not distributed with this michael@0: * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ michael@0: michael@0: #ifndef _nsDiskCacheEntry_h_ michael@0: #define _nsDiskCacheEntry_h_ michael@0: michael@0: #include "nsDiskCacheMap.h" michael@0: michael@0: #include "nsCacheEntry.h" michael@0: michael@0: michael@0: /****************************************************************************** michael@0: * nsDiskCacheEntry michael@0: *****************************************************************************/ michael@0: struct nsDiskCacheEntry { michael@0: uint32_t mHeaderVersion; // useful for stand-alone metadata files michael@0: uint32_t mMetaLocation; // for verification michael@0: int32_t mFetchCount; michael@0: uint32_t mLastFetched; michael@0: uint32_t mLastModified; michael@0: uint32_t mExpirationTime; michael@0: uint32_t mDataSize; michael@0: uint32_t mKeySize; // includes terminating null byte michael@0: uint32_t mMetaDataSize; // includes terminating null byte michael@0: // followed by key data (mKeySize bytes) michael@0: // followed by meta data (mMetaDataSize bytes) michael@0: michael@0: uint32_t Size() { return sizeof(nsDiskCacheEntry) + michael@0: mKeySize + mMetaDataSize; michael@0: } michael@0: michael@0: char* Key() { return reinterpret_cast(this) + michael@0: sizeof(nsDiskCacheEntry); michael@0: } michael@0: michael@0: char* MetaData() michael@0: { return Key() + mKeySize; } michael@0: michael@0: nsCacheEntry * CreateCacheEntry(nsCacheDevice * device); michael@0: michael@0: void Swap() // host to network (memory to disk) michael@0: { michael@0: #if defined(IS_LITTLE_ENDIAN) michael@0: mHeaderVersion = htonl(mHeaderVersion); michael@0: mMetaLocation = htonl(mMetaLocation); michael@0: mFetchCount = htonl(mFetchCount); michael@0: mLastFetched = htonl(mLastFetched); michael@0: mLastModified = htonl(mLastModified); michael@0: mExpirationTime = htonl(mExpirationTime); michael@0: mDataSize = htonl(mDataSize); michael@0: mKeySize = htonl(mKeySize); michael@0: mMetaDataSize = htonl(mMetaDataSize); michael@0: #endif michael@0: } michael@0: michael@0: void Unswap() // network to host (disk to memory) michael@0: { michael@0: #if defined(IS_LITTLE_ENDIAN) michael@0: mHeaderVersion = ntohl(mHeaderVersion); michael@0: mMetaLocation = ntohl(mMetaLocation); michael@0: mFetchCount = ntohl(mFetchCount); michael@0: mLastFetched = ntohl(mLastFetched); michael@0: mLastModified = ntohl(mLastModified); michael@0: mExpirationTime = ntohl(mExpirationTime); michael@0: mDataSize = ntohl(mDataSize); michael@0: mKeySize = ntohl(mKeySize); michael@0: mMetaDataSize = ntohl(mMetaDataSize); michael@0: #endif michael@0: } michael@0: }; michael@0: michael@0: michael@0: /****************************************************************************** michael@0: * nsDiskCacheEntryInfo michael@0: *****************************************************************************/ michael@0: class nsDiskCacheEntryInfo : public nsICacheEntryInfo { michael@0: public: michael@0: NS_DECL_ISUPPORTS michael@0: NS_DECL_NSICACHEENTRYINFO michael@0: michael@0: nsDiskCacheEntryInfo(const char * deviceID, nsDiskCacheEntry * diskEntry) michael@0: : mDeviceID(deviceID) michael@0: , mDiskEntry(diskEntry) michael@0: { michael@0: } michael@0: michael@0: virtual ~nsDiskCacheEntryInfo() {} michael@0: michael@0: const char* Key() { return mDiskEntry->Key(); } michael@0: michael@0: private: michael@0: const char * mDeviceID; michael@0: nsDiskCacheEntry * mDiskEntry; michael@0: }; michael@0: michael@0: michael@0: #endif /* _nsDiskCacheEntry_h_ */