|
1 // Copyright (c) 2004-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 // Reserving/Accessing/Releasing drive space - CSqlDriveSpace and RSqlDriveSpaceCol classes implementations |
|
15 // |
|
16 // |
|
17 |
|
18 #include "SqlSrvDriveSpace.h" |
|
19 #include "SqlPanic.h" |
|
20 |
|
21 /** |
|
22 The amount of the disk space, which will be reserved at the moment of creation of |
|
23 each CDriveSpace object. |
|
24 It should be enough for the most of "delete" transactions, if they do not require a rollback transaction |
|
25 file, bigger than KReservedDiskSpace bytes. |
|
26 |
|
27 Note: this is the max possible amount, which can be reserved per file session. |
|
28 Look for KMaxSessionDriveReserved constant value. |
|
29 |
|
30 @internalComponent |
|
31 */ |
|
32 const TInt KReservedDiskSpace = 64 * 1024; |
|
33 |
|
34 ////////////////////////////////////////////////////////////////////////////////////////////////////////////////// |
|
35 //////////////////////////////// CSqlDriveSpace class ////////////////////////////////////////////////////// |
|
36 ////////////////////////////////////////////////////////////////////////////////////////////////////////////////// |
|
37 |
|
38 /** |
|
39 Standard phase-one factory method for creation of CSqlDriveSpace objects. |
|
40 |
|
41 @param aFs File session instance |
|
42 @param aDrive Drive number |
|
43 |
|
44 @return A pointer to the created CSqlDriveSpace object. |
|
45 |
|
46 @leave KErrNoMemory, Out of memory condition has occured; |
|
47 RFs::ReserveDriveSpace() return values. |
|
48 |
|
49 @panic SqlDb 4 In _DEBUG mode if aDrive is invalid |
|
50 |
|
51 @see RFs::ReserveDriveSpace() |
|
52 */ |
|
53 CSqlDriveSpace* CSqlDriveSpace::NewLC(RFs& aFs, TDriveNumber aDrive) |
|
54 { |
|
55 __SQLASSERT(aDrive >= EDriveA && aDrive <= EDriveZ, ESqlPanicBadArgument); |
|
56 CSqlDriveSpace* self = new (ELeave) CSqlDriveSpace(aFs, aDrive); |
|
57 CleanupStack::PushL(self); |
|
58 self->ConstructL(); |
|
59 return self; |
|
60 } |
|
61 |
|
62 /** |
|
63 Frees the reserved disk space. |
|
64 */ |
|
65 CSqlDriveSpace::~CSqlDriveSpace() |
|
66 { |
|
67 SQLDRIVESPACE_INVARIANT(); |
|
68 (void)iFs.ReleaseReserveAccess(static_cast <TInt> (iDrive)); |
|
69 (void)iFs.ReserveDriveSpace(static_cast <TInt> (iDrive), 0); |
|
70 } |
|
71 |
|
72 /** |
|
73 Gives an access to the already reserved drive space. The method uses RFs::GetReserveAccess() |
|
74 for that. RFs::GetReserveAccess() will be called only once, when iGetAccessRefCnt is 0 - |
|
75 this is a shared file session instance. |
|
76 |
|
77 @leave RFs::GetReserveAccess() return values |
|
78 |
|
79 @see RFs::GetReserveAccess() |
|
80 |
|
81 @panic SqlDb 12 In _DEBUG mode if iGetAccessRefCnt < 0 |
|
82 */ |
|
83 void CSqlDriveSpace::GetAccessL() |
|
84 { |
|
85 SQLDRIVESPACE_INVARIANT(); |
|
86 //Gets an access only once, there is only one RFs session instance. |
|
87 if(iGetAccessRefCnt == 0) |
|
88 { |
|
89 __SQLLEAVE_IF_ERROR(iFs.GetReserveAccess(static_cast <TInt> (iDrive))); |
|
90 } |
|
91 ++iGetAccessRefCnt; |
|
92 SQLDRIVESPACE_INVARIANT(); |
|
93 } |
|
94 |
|
95 /** |
|
96 Revokes access to the reserved drive space. |
|
97 |
|
98 The method calls RFs::ReleaseReserveAccess() only when iGetAccessRefCnt value reaches 0. |
|
99 |
|
100 @see RFs::ReleaseReserveAccess() |
|
101 |
|
102 @panic SqlDb 12 In _DEBUG mode if iGetAccessRefCnt < 0 |
|
103 */ |
|
104 void CSqlDriveSpace::ReleaseAccess() |
|
105 { |
|
106 SQLDRIVESPACE_INVARIANT(); |
|
107 if(iGetAccessRefCnt == 0) |
|
108 { |
|
109 return; |
|
110 } |
|
111 if(--iGetAccessRefCnt == 0) |
|
112 { |
|
113 //I can't see any reason to bother the caller with errors, when the access to the |
|
114 //reserved space is revoked. |
|
115 (void)iFs.ReleaseReserveAccess(static_cast <TInt> (iDrive)); |
|
116 } |
|
117 SQLDRIVESPACE_INVARIANT(); |
|
118 } |
|
119 |
|
120 /** |
|
121 @param aFs File session instance |
|
122 @param aDrive Drive number |
|
123 |
|
124 @panic SqlDb 4 In _DEBUG mode if aDrive is invalid |
|
125 */ |
|
126 CSqlDriveSpace::CSqlDriveSpace(RFs& aFs, TDriveNumber aDrive) : |
|
127 iFs(aFs), |
|
128 iDrive(aDrive) |
|
129 { |
|
130 __SQLASSERT(aDrive >= EDriveA && aDrive <= EDriveZ, ESqlPanicBadArgument); |
|
131 } |
|
132 |
|
133 /** |
|
134 Standard phase-two construction method for creation of CSqlDriveSpace objects. |
|
135 |
|
136 It will reserve a predefined amount of a disk space, enough for the most of the |
|
137 "delete" transactions, used by the applications. |
|
138 |
|
139 @leave RFs::ReserveDriveSpace() return values |
|
140 |
|
141 @see RFs::ReserveDriveSpace() |
|
142 */ |
|
143 void CSqlDriveSpace::ConstructL() |
|
144 { |
|
145 __SQLLEAVE_IF_ERROR(iFs.ReserveDriveSpace(static_cast <TInt> (iDrive), KReservedDiskSpace)); |
|
146 SQLDRIVESPACE_INVARIANT(); |
|
147 } |
|
148 |
|
149 #ifdef _DEBUG |
|
150 /** |
|
151 CSqlDriveSpace invariant. |
|
152 */ |
|
153 void CSqlDriveSpace::Invariant() const |
|
154 { |
|
155 __SQLASSERT(iDrive >= EDriveA && iDrive <= EDriveZ, ESqlPanicInternalError); |
|
156 __SQLASSERT(iGetAccessRefCnt >= 0, ESqlPanicMisuse); |
|
157 } |
|
158 #endif//_DEBUG |
|
159 |
|
160 ////////////////////////////////////////////////////////////////////////////////////////////////////////////////// |
|
161 //////////////////////////////// RSqlDriveSpaceCol class /////////////////////////////////////////////////// |
|
162 ////////////////////////////////////////////////////////////////////////////////////////////////////////////////// |
|
163 |
|
164 RSqlDriveSpaceCol::RSqlDriveSpaceCol() : |
|
165 iFs(NULL) |
|
166 { |
|
167 } |
|
168 |
|
169 /** |
|
170 @param aFs A reference to file session instance |
|
171 */ |
|
172 void RSqlDriveSpaceCol::Create(RFs& aFs) |
|
173 { |
|
174 iFs = &aFs; |
|
175 SQLDRIVESPACECOL_INVARIANT(); |
|
176 } |
|
177 |
|
178 /** |
|
179 The method releases all the resources used by RSqlDriveSpaceCol object, including and |
|
180 reserved drive spaces on all drives in the collection. |
|
181 */ |
|
182 void RSqlDriveSpaceCol::ResetAndDestroy() |
|
183 { |
|
184 //Forced release of the reserved space |
|
185 for(TInt i=iDriveSpaceCol.Count()-1;i>=0;--i) |
|
186 { |
|
187 delete iDriveSpaceCol[i]; |
|
188 } |
|
189 iDriveSpaceCol.Close(); |
|
190 iFs = NULL; |
|
191 } |
|
192 |
|
193 /** |
|
194 Searches the collection for a CSqlDriveSpace object holding information about the reserved space on aDrive drive. |
|
195 |
|
196 @param aDrive Drive number. |
|
197 |
|
198 @return A pointer to the CSqlDriveSpace object, which handles drive space reservation requests |
|
199 for aDriveNo drive. If there is no such object, the method returns NULL. |
|
200 |
|
201 @panic SqlDb 4 In _DEBUG mode if aDrive is invalid |
|
202 */ |
|
203 CSqlDriveSpace* RSqlDriveSpaceCol::Find(TDriveNumber aDrive) |
|
204 { |
|
205 __SQLASSERT(aDrive >= EDriveA && aDrive <= EDriveZ, ESqlPanicBadArgument); |
|
206 SQLDRIVESPACECOL_INVARIANT(); |
|
207 for(TInt index=iDriveSpaceCol.Count()-1;index>=0;--index) |
|
208 { |
|
209 if(iDriveSpaceCol[index]->Drive() == aDrive) |
|
210 { |
|
211 return iDriveSpaceCol[index]; |
|
212 } |
|
213 } |
|
214 SQLDRIVESPACECOL_INVARIANT(); |
|
215 return NULL; |
|
216 } |
|
217 |
|
218 /** |
|
219 The method creates a new CSqlDriveSpace object, adds it to the collection and returns a pointer to it. |
|
220 |
|
221 @param aDrive Drive number. |
|
222 |
|
223 @return A pointer to the created CDriveSpace object, which handles drive space |
|
224 reservation requests for aDriveNo drive. |
|
225 |
|
226 @leave System-wide error codes, including KErrNoMemory. |
|
227 |
|
228 @panic SqlDb 4, In _DEBUG mode if aDrive is invalid. |
|
229 @panic SqlDb 12, In _DEBUG mode if a CDriveSpace object already exists for aDrive. |
|
230 */ |
|
231 CSqlDriveSpace* RSqlDriveSpaceCol::AddL(TDriveNumber aDrive) |
|
232 { |
|
233 __SQLASSERT(aDrive >= EDriveA && aDrive <= EDriveZ, ESqlPanicBadArgument); |
|
234 __SQLASSERT(!Find(aDrive), ESqlPanicMisuse); |
|
235 SQLDRIVESPACECOL_INVARIANT(); |
|
236 CSqlDriveSpace* drvSpace = CSqlDriveSpace::NewLC(*iFs, aDrive); |
|
237 __SQLLEAVE_IF_ERROR(iDriveSpaceCol.Append(drvSpace)); |
|
238 CleanupStack::Pop(drvSpace); |
|
239 SQLDRIVESPACECOL_INVARIANT(); |
|
240 return drvSpace; |
|
241 } |
|
242 |
|
243 #ifdef _DEBUG |
|
244 /** |
|
245 RSqlDriveSpaceCol invariant. |
|
246 */ |
|
247 void RSqlDriveSpaceCol::Invariant() const |
|
248 { |
|
249 __SQLASSERT(iFs != NULL, ESqlPanicInternalError); |
|
250 for(TInt index=iDriveSpaceCol.Count()-1;index>=0;--index) |
|
251 { |
|
252 iDriveSpaceCol[index]->Invariant(); |
|
253 } |
|
254 } |
|
255 #endif//_DEBUG |
|
256 |