|
1 // Copyright (c) 1998-2009 Nokia Corporation and/or its subsidiary(-ies). |
|
2 // All rights reserved. |
|
3 // This component and the accompanying materials are made available |
|
4 // under the terms of "Eclipse Public License v1.0" |
|
5 // which accompanies this distribution, and is available |
|
6 // at the URL "http://www.eclipse.org/legal/epl-v10.html". |
|
7 // |
|
8 // Initial Contributors: |
|
9 // Nokia Corporation - initial contribution. |
|
10 // |
|
11 // Contributors: |
|
12 // |
|
13 // Description: |
|
14 // |
|
15 |
|
16 #include "UT_STD.H" |
|
17 |
|
18 EXPORT_C CEmbeddedStore* CEmbeddedStore::FromL(RReadStream& aHost) |
|
19 /** Opens the store hosted by the specified stream. |
|
20 |
|
21 Note that ownership of the stream passes to the store; the referenced RReadStream |
|
22 is cleared. |
|
23 |
|
24 @param aHost A reference to the stream hosting the embedded store. |
|
25 @return A pointer to the embedded store object. */ |
|
26 { |
|
27 CEmbeddedStore* store=FromLC(aHost); |
|
28 CleanupStack::Pop(); |
|
29 return store; |
|
30 } |
|
31 |
|
32 EXPORT_C CEmbeddedStore* CEmbeddedStore::FromLC(RReadStream& aHost) |
|
33 /** Open the store hosted by the specified stream, putting a pointer to the store |
|
34 onto the cleanup stack. |
|
35 |
|
36 Putting a pointer to the embedded store object onto the cleanup stack allows |
|
37 the object and allocated resources to be cleaned up if a subsequent leave |
|
38 occurs. |
|
39 |
|
40 Note that ownership of the stream passes to the store and the referenced RReadStream |
|
41 is cleared. |
|
42 |
|
43 @param aHost A reference to the stream hosting the embedded store. |
|
44 @return A pointer to the embedded store object. */ |
|
45 { |
|
46 CEmbeddedStore* store=CEmbeddedStore::DoNewLC(aHost.Source()); |
|
47 store->MarshalL(aHost); |
|
48 return store; |
|
49 } |
|
50 |
|
51 EXPORT_C CEmbeddedStore* CEmbeddedStore::NewL(RWriteStream& aHost) |
|
52 /** Creates an embedded store within the specified host stream. |
|
53 |
|
54 Note that ownership of the stream passes to the store and the referenced RWriteStream |
|
55 is cleared. |
|
56 |
|
57 @param aHost A reference to the stream which is to host the embedded store. |
|
58 @return A pointer to the embedded store object. */ |
|
59 { |
|
60 CEmbeddedStore* store=NewLC(aHost); |
|
61 CleanupStack::Pop(); |
|
62 return store; |
|
63 } |
|
64 |
|
65 EXPORT_C CEmbeddedStore* CEmbeddedStore::NewLC(RWriteStream& aHost) |
|
66 /** Creates an embedded store within the specified host stream, putting a pointer |
|
67 to the store onto the cleanup stack. |
|
68 |
|
69 Putting a pointer to the embedded store object onto the cleanup stack allows |
|
70 the object and allocated resources to be cleaned up if a subsequent leave |
|
71 occurs. |
|
72 |
|
73 Note that ownership of the stream passes to the store and the referenced RWriteStream |
|
74 is cleared. |
|
75 |
|
76 @param aHost A reference to the stream which is to host the embedded store. |
|
77 @return A pointer to the embedded store object. */ |
|
78 { |
|
79 CEmbeddedStore* store=CEmbeddedStore::DoNewLC(aHost.Sink()); |
|
80 store->ConstructL(aHost); |
|
81 return store; |
|
82 } |
|
83 |
|
84 EXPORT_C void CEmbeddedStore::Detach() |
|
85 /** Gives up ownership of the host stream buffer. The caller takes on the responsibility |
|
86 for discarding the buffer. */ |
|
87 { |
|
88 iHost.Host(); |
|
89 iHost.Release(); |
|
90 } |
|
91 |
|
92 EXPORT_C CEmbeddedStore::CEmbeddedStore(MStreamBuf* aHost) |
|
93 : iHost(aHost) |
|
94 { |
|
95 __ASSERT_DEBUG(aHost!=NULL,Panic(EStoreNotOpen)); |
|
96 } |
|
97 |
|
98 EXPORT_C void CEmbeddedStore::MarshalL(RReadStream& aStream) |
|
99 // |
|
100 // Second-phase construction for opening existing stores. |
|
101 // |
|
102 { |
|
103 MStreamBuf* src=aStream.Source(); |
|
104 aStream=RReadStream(); |
|
105 __ASSERT_DEBUG(src!=NULL&&src==iHost.Host(),User::Invariant()); |
|
106 iStart=src->TellL(MStreamBuf::ERead); |
|
107 RReadStream stream(src); |
|
108 stream>>iRoot; |
|
109 } |
|
110 |
|
111 EXPORT_C void CEmbeddedStore::ConstructL(RWriteStream& aStream) |
|
112 // |
|
113 // Second-phase construction for creating new stores. |
|
114 // |
|
115 { |
|
116 MStreamBuf* snk=aStream.Sink(); |
|
117 aStream=RWriteStream(); |
|
118 __ASSERT_DEBUG(snk!=NULL&&snk==iHost.Host(),User::Invariant()); |
|
119 iStart=snk->TellL(MStreamBuf::EWrite); |
|
120 RWriteStream stream(snk); |
|
121 stream<<iRoot; |
|
122 } |
|
123 |
|
124 EXPORT_C CEmbeddedStore::~CEmbeddedStore() |
|
125 /** Frees resources owned by the object, prior to its destruction. In particular, |
|
126 the destructor closes the associated file. */ |
|
127 { |
|
128 MStreamBuf* buf=iHost.Host(); |
|
129 if (buf!=NULL) |
|
130 buf->Release(); |
|
131 } |
|
132 |
|
133 EXPORT_C MStreamBuf* CEmbeddedStore::DoReadL(TStreamId anId) const |
|
134 { |
|
135 return HDirectStoreBuf::OpenL(MUTABLE_CAST(TStreamExchange&,iHost),anId,HDirectStoreBuf::ERead); |
|
136 } |
|
137 |
|
138 EXPORT_C MStreamBuf* CEmbeddedStore::DoCreateL(TStreamId& anId) |
|
139 { |
|
140 return HDirectStoreBuf::CreateL(iHost,anId,HDirectStoreBuf::ERead|HDirectStoreBuf::EWrite); |
|
141 } |
|
142 |
|
143 EXPORT_C void CEmbeddedStore::DoSetRootL(TStreamId anId) |
|
144 { |
|
145 RShareWriteStream stream(iHost,iStart); |
|
146 stream.PushL(); |
|
147 stream<<anId; |
|
148 CleanupStack::PopAndDestroy(); |
|
149 iRoot=anId; |
|
150 } |
|
151 |
|
152 EXPORT_C void CEmbeddedStore::DoCommitL() |
|
153 { |
|
154 iHost.HostL()->SynchL(); |
|
155 } |
|
156 |
|
157 CEmbeddedStore* CEmbeddedStore::DoNewLC(MStreamBuf* aHost) |
|
158 { |
|
159 aHost->PushL(); |
|
160 CEmbeddedStore* store=new(ELeave) CEmbeddedStore(aHost); |
|
161 CleanupStack::Pop(); |
|
162 CleanupStack::PushL(store); |
|
163 return store; |
|
164 } |
|
165 |