2001-03-21 01:42:03 +03:00
|
|
|
/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*-
|
|
|
|
*
|
2012-05-21 15:12:37 +04:00
|
|
|
* This Source Code Form is subject to the terms of the Mozilla Public
|
|
|
|
* License, v. 2.0. If a copy of the MPL was not distributed with this
|
|
|
|
* file, You can obtain one at http://mozilla.org/MPL/2.0/. */
|
2001-03-21 01:42:03 +03:00
|
|
|
|
|
|
|
#ifndef _nsDiskCacheEntry_h_
|
|
|
|
#define _nsDiskCacheEntry_h_
|
|
|
|
|
2001-05-19 03:24:09 +04:00
|
|
|
#include "nsDiskCacheMap.h"
|
2001-03-21 01:42:03 +03:00
|
|
|
|
|
|
|
#include "nsCacheEntry.h"
|
|
|
|
|
2001-05-19 03:24:09 +04:00
|
|
|
|
|
|
|
/******************************************************************************
|
|
|
|
* nsDiskCacheEntry
|
|
|
|
*****************************************************************************/
|
|
|
|
struct nsDiskCacheEntry {
|
2012-08-22 19:56:38 +04:00
|
|
|
uint32_t mHeaderVersion; // useful for stand-alone metadata files
|
|
|
|
uint32_t mMetaLocation; // for verification
|
|
|
|
int32_t mFetchCount;
|
|
|
|
uint32_t mLastFetched;
|
|
|
|
uint32_t mLastModified;
|
|
|
|
uint32_t mExpirationTime;
|
|
|
|
uint32_t mDataSize;
|
|
|
|
uint32_t mKeySize; // includes terminating null byte
|
|
|
|
uint32_t mMetaDataSize; // includes terminating null byte
|
2007-01-26 02:09:01 +03:00
|
|
|
// followed by key data (mKeySize bytes)
|
|
|
|
// followed by meta data (mMetaDataSize bytes)
|
2001-05-19 03:24:09 +04:00
|
|
|
|
2012-08-22 19:56:38 +04:00
|
|
|
uint32_t Size() { return sizeof(nsDiskCacheEntry) +
|
2002-10-09 07:01:11 +04:00
|
|
|
mKeySize + mMetaDataSize;
|
2001-05-19 03:24:09 +04:00
|
|
|
}
|
|
|
|
|
2007-07-08 11:08:04 +04:00
|
|
|
char* Key() { return reinterpret_cast<char*const>(this) +
|
2007-01-26 02:09:01 +03:00
|
|
|
sizeof(nsDiskCacheEntry);
|
|
|
|
}
|
|
|
|
|
|
|
|
char* MetaData()
|
|
|
|
{ return Key() + mKeySize; }
|
|
|
|
|
2001-05-19 03:24:09 +04:00
|
|
|
nsCacheEntry * CreateCacheEntry(nsCacheDevice * device);
|
2001-03-21 01:42:03 +03:00
|
|
|
|
2001-05-19 03:24:09 +04:00
|
|
|
void Swap() // host to network (memory to disk)
|
2001-03-21 01:42:03 +03:00
|
|
|
{
|
2001-05-19 03:24:09 +04:00
|
|
|
#if defined(IS_LITTLE_ENDIAN)
|
2005-10-08 05:20:36 +04:00
|
|
|
mHeaderVersion = htonl(mHeaderVersion);
|
|
|
|
mMetaLocation = htonl(mMetaLocation);
|
|
|
|
mFetchCount = htonl(mFetchCount);
|
|
|
|
mLastFetched = htonl(mLastFetched);
|
|
|
|
mLastModified = htonl(mLastModified);
|
|
|
|
mExpirationTime = htonl(mExpirationTime);
|
|
|
|
mDataSize = htonl(mDataSize);
|
|
|
|
mKeySize = htonl(mKeySize);
|
|
|
|
mMetaDataSize = htonl(mMetaDataSize);
|
2001-03-21 01:42:03 +03:00
|
|
|
#endif
|
|
|
|
}
|
|
|
|
|
2001-05-19 03:24:09 +04:00
|
|
|
void Unswap() // network to host (disk to memory)
|
2001-04-04 07:30:45 +04:00
|
|
|
{
|
2001-05-19 03:24:09 +04:00
|
|
|
#if defined(IS_LITTLE_ENDIAN)
|
2005-10-08 05:20:36 +04:00
|
|
|
mHeaderVersion = ntohl(mHeaderVersion);
|
|
|
|
mMetaLocation = ntohl(mMetaLocation);
|
|
|
|
mFetchCount = ntohl(mFetchCount);
|
|
|
|
mLastFetched = ntohl(mLastFetched);
|
|
|
|
mLastModified = ntohl(mLastModified);
|
|
|
|
mExpirationTime = ntohl(mExpirationTime);
|
|
|
|
mDataSize = ntohl(mDataSize);
|
|
|
|
mKeySize = ntohl(mKeySize);
|
|
|
|
mMetaDataSize = ntohl(mMetaDataSize);
|
2001-03-21 01:42:03 +03:00
|
|
|
#endif
|
2001-05-19 03:24:09 +04:00
|
|
|
}
|
2001-03-21 01:42:03 +03:00
|
|
|
};
|
|
|
|
|
2001-05-19 03:24:09 +04:00
|
|
|
|
|
|
|
/******************************************************************************
|
|
|
|
* nsDiskCacheEntryInfo
|
|
|
|
*****************************************************************************/
|
|
|
|
class nsDiskCacheEntryInfo : public nsICacheEntryInfo {
|
2001-03-21 01:42:03 +03:00
|
|
|
public:
|
2001-05-19 03:24:09 +04:00
|
|
|
NS_DECL_ISUPPORTS
|
|
|
|
NS_DECL_NSICACHEENTRYINFO
|
2001-03-21 01:42:03 +03:00
|
|
|
|
2001-05-19 03:24:09 +04:00
|
|
|
nsDiskCacheEntryInfo(const char * deviceID, nsDiskCacheEntry * diskEntry)
|
|
|
|
: mDeviceID(deviceID)
|
|
|
|
, mDiskEntry(diskEntry)
|
|
|
|
{
|
|
|
|
}
|
2001-03-21 01:42:03 +03:00
|
|
|
|
2007-01-26 02:09:01 +03:00
|
|
|
const char* Key() { return mDiskEntry->Key(); }
|
2001-03-21 01:42:03 +03:00
|
|
|
|
|
|
|
private:
|
2014-06-24 20:36:44 +04:00
|
|
|
virtual ~nsDiskCacheEntryInfo() {}
|
|
|
|
|
2001-05-19 03:24:09 +04:00
|
|
|
const char * mDeviceID;
|
|
|
|
nsDiskCacheEntry * mDiskEntry;
|
2001-03-21 01:42:03 +03:00
|
|
|
};
|
|
|
|
|
2001-05-19 03:24:09 +04:00
|
|
|
|
2001-03-21 01:42:03 +03:00
|
|
|
#endif /* _nsDiskCacheEntry_h_ */
|