|
1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- |
|
2 * |
|
3 * This Source Code Form is subject to the terms of the Mozilla Public |
|
4 * License, v. 2.0. If a copy of the MPL was not distributed with this |
|
5 * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ |
|
6 |
|
7 #ifndef _nsDiskCacheEntry_h_ |
|
8 #define _nsDiskCacheEntry_h_ |
|
9 |
|
10 #include "nsDiskCacheMap.h" |
|
11 |
|
12 #include "nsCacheEntry.h" |
|
13 |
|
14 |
|
15 /****************************************************************************** |
|
16 * nsDiskCacheEntry |
|
17 *****************************************************************************/ |
|
18 struct nsDiskCacheEntry { |
|
19 uint32_t mHeaderVersion; // useful for stand-alone metadata files |
|
20 uint32_t mMetaLocation; // for verification |
|
21 int32_t mFetchCount; |
|
22 uint32_t mLastFetched; |
|
23 uint32_t mLastModified; |
|
24 uint32_t mExpirationTime; |
|
25 uint32_t mDataSize; |
|
26 uint32_t mKeySize; // includes terminating null byte |
|
27 uint32_t mMetaDataSize; // includes terminating null byte |
|
28 // followed by key data (mKeySize bytes) |
|
29 // followed by meta data (mMetaDataSize bytes) |
|
30 |
|
31 uint32_t Size() { return sizeof(nsDiskCacheEntry) + |
|
32 mKeySize + mMetaDataSize; |
|
33 } |
|
34 |
|
35 char* Key() { return reinterpret_cast<char*const>(this) + |
|
36 sizeof(nsDiskCacheEntry); |
|
37 } |
|
38 |
|
39 char* MetaData() |
|
40 { return Key() + mKeySize; } |
|
41 |
|
42 nsCacheEntry * CreateCacheEntry(nsCacheDevice * device); |
|
43 |
|
44 void Swap() // host to network (memory to disk) |
|
45 { |
|
46 #if defined(IS_LITTLE_ENDIAN) |
|
47 mHeaderVersion = htonl(mHeaderVersion); |
|
48 mMetaLocation = htonl(mMetaLocation); |
|
49 mFetchCount = htonl(mFetchCount); |
|
50 mLastFetched = htonl(mLastFetched); |
|
51 mLastModified = htonl(mLastModified); |
|
52 mExpirationTime = htonl(mExpirationTime); |
|
53 mDataSize = htonl(mDataSize); |
|
54 mKeySize = htonl(mKeySize); |
|
55 mMetaDataSize = htonl(mMetaDataSize); |
|
56 #endif |
|
57 } |
|
58 |
|
59 void Unswap() // network to host (disk to memory) |
|
60 { |
|
61 #if defined(IS_LITTLE_ENDIAN) |
|
62 mHeaderVersion = ntohl(mHeaderVersion); |
|
63 mMetaLocation = ntohl(mMetaLocation); |
|
64 mFetchCount = ntohl(mFetchCount); |
|
65 mLastFetched = ntohl(mLastFetched); |
|
66 mLastModified = ntohl(mLastModified); |
|
67 mExpirationTime = ntohl(mExpirationTime); |
|
68 mDataSize = ntohl(mDataSize); |
|
69 mKeySize = ntohl(mKeySize); |
|
70 mMetaDataSize = ntohl(mMetaDataSize); |
|
71 #endif |
|
72 } |
|
73 }; |
|
74 |
|
75 |
|
76 /****************************************************************************** |
|
77 * nsDiskCacheEntryInfo |
|
78 *****************************************************************************/ |
|
79 class nsDiskCacheEntryInfo : public nsICacheEntryInfo { |
|
80 public: |
|
81 NS_DECL_ISUPPORTS |
|
82 NS_DECL_NSICACHEENTRYINFO |
|
83 |
|
84 nsDiskCacheEntryInfo(const char * deviceID, nsDiskCacheEntry * diskEntry) |
|
85 : mDeviceID(deviceID) |
|
86 , mDiskEntry(diskEntry) |
|
87 { |
|
88 } |
|
89 |
|
90 virtual ~nsDiskCacheEntryInfo() {} |
|
91 |
|
92 const char* Key() { return mDiskEntry->Key(); } |
|
93 |
|
94 private: |
|
95 const char * mDeviceID; |
|
96 nsDiskCacheEntry * mDiskEntry; |
|
97 }; |
|
98 |
|
99 |
|
100 #endif /* _nsDiskCacheEntry_h_ */ |