1 /* |
|
2 * Copyright (c) 2004-2006 Nokia Corporation and/or its subsidiary(-ies). |
|
3 * All rights reserved. |
|
4 * This component and the accompanying materials are made available |
|
5 * under the terms of "Eclipse Public License v1.0" |
|
6 * which accompanies this distribution, and is available |
|
7 * at the URL "http://www.eclipse.org/legal/epl-v10.html". |
|
8 * |
|
9 * Initial Contributors: |
|
10 * Nokia Corporation - initial contribution. |
|
11 * |
|
12 * Contributors: |
|
13 * |
|
14 * Description: Keeps metadata persistent |
|
15 * |
|
16 */ |
|
17 |
|
18 |
|
19 // INCLUDE FILES |
|
20 #include <s32mem.h> |
|
21 |
|
22 #include "rsfwmetadatastore.h" |
|
23 #include "mdebug.h" |
|
24 |
|
25 // CONSTANTS |
|
26 const TUint32 KMetaDataStoreVersion = 0x010101; // current version |
|
27 const TInt KMaxExternalizedMountConfigSize = 512; |
|
28 const TInt KDefaultMetaDataBlockSize = 128; |
|
29 |
|
30 // ============================ MEMBER FUNCTIONS ============================== |
|
31 |
|
32 // ---------------------------------------------------------------------------- |
|
33 // CRsfwMetaDataStore::NewL |
|
34 // ---------------------------------------------------------------------------- |
|
35 // |
|
36 CRsfwMetaDataStore* CRsfwMetaDataStore::NewL(const TDesC& aPath) |
|
37 { |
|
38 DEBUGSTRING(("CRsfwMetaDataStore::NewL")); |
|
39 CRsfwMetaDataStore* self = CRsfwMetaDataStore::NewLC(aPath); |
|
40 CleanupStack::Pop(self); |
|
41 return self; |
|
42 } |
|
43 |
|
44 // ---------------------------------------------------------------------------- |
|
45 // CRsfwMetaDataStore::NewLC |
|
46 // ---------------------------------------------------------------------------- |
|
47 // |
|
48 CRsfwMetaDataStore* CRsfwMetaDataStore::NewLC(const TDesC& aPath) |
|
49 { |
|
50 DEBUGSTRING(("CRsfwMetaDataStore::NewLC")); |
|
51 CRsfwMetaDataStore* self = new (ELeave) CRsfwMetaDataStore(); |
|
52 CleanupStack::PushL(self); |
|
53 self->ConstructL(aPath); |
|
54 return self; |
|
55 } |
|
56 |
|
57 // ---------------------------------------------------------------------------- |
|
58 // CRsfwMetaDataStore::ConstructL |
|
59 // ---------------------------------------------------------------------------- |
|
60 // |
|
61 void CRsfwMetaDataStore::ConstructL(const TDesC& aPath) |
|
62 { |
|
63 DEBUGSTRING(("CRsfwMetaDataStore::ConstructL")); |
|
64 CRsfwPermanentStore::ConstructL(aPath, |
|
65 KMaxExternalizedMountConfigSize, |
|
66 KDefaultMetaDataBlockSize); |
|
67 } |
|
68 |
|
69 // ---------------------------------------------------------------------------- |
|
70 // CRsfwMetaDataStore::GetMountConfigL |
|
71 // ---------------------------------------------------------------------------- |
|
72 // |
|
73 void CRsfwMetaDataStore::GetMountConfigL(TRsfwMountConfig& aMountConfig) |
|
74 { |
|
75 // Load the configuration information |
|
76 DEBUGSTRING(("CRsfwMetaDataStore::GetMountConfigL")); |
|
77 const HBufC8* header = Header(); |
|
78 if (header) |
|
79 { |
|
80 RMemReadStream stream(header->Ptr(), header->Length()); |
|
81 CleanupClosePushL(stream); |
|
82 TUint32 version = stream.ReadUint32L(); |
|
83 if (version != KMetaDataStoreVersion) |
|
84 { |
|
85 DEBUGSTRING(("metadata store version 0x%x differs from 0x%x", |
|
86 version, |
|
87 KMetaDataStoreVersion)); |
|
88 User::Leave(KErrCorrupt); |
|
89 } |
|
90 aMountConfig.InternalizeL(stream); |
|
91 CleanupStack::PopAndDestroy(&stream); // stream |
|
92 } |
|
93 else |
|
94 { |
|
95 User::Leave(KErrNotFound); |
|
96 } |
|
97 } |
|
98 |
|
99 // ---------------------------------------------------------------------------- |
|
100 // CRsfwMetaDataStore::SetMountConfigL |
|
101 // ---------------------------------------------------------------------------- |
|
102 // |
|
103 void CRsfwMetaDataStore::SetMountConfigL(const TRsfwMountConfig& aMountConfig) |
|
104 { |
|
105 // Store the configuration information |
|
106 HBufC8* buf = HBufC8::NewLC(KMaxExternalizedMountConfigSize); |
|
107 TPtr8 ptr = buf->Des(); |
|
108 TUint8* data = const_cast<TUint8 *>(ptr.Ptr()); |
|
109 RMemWriteStream stream(data, KMaxExternalizedMountConfigSize); |
|
110 CleanupClosePushL(stream); |
|
111 |
|
112 // Dump the externalized data in the memory buffer |
|
113 stream.WriteUint32L(KMetaDataStoreVersion); |
|
114 aMountConfig.ExternalizeL(stream); |
|
115 MStreamBuf* streamBuf = stream.Sink(); |
|
116 TInt dataLen = streamBuf->TellL(MStreamBuf::EWrite).Offset(); |
|
117 DEBUGSTRING(("mount config data len = %d,", dataLen)); |
|
118 stream.CommitL(); |
|
119 TPtrC8 header(data, dataLen); |
|
120 SetHeaderL(header); |
|
121 |
|
122 CleanupStack::PopAndDestroy(2, buf); // stream, buf |
|
123 } |
|
124 |
|
125 // End of File |
|