1 /* |
|
2 * Copyright (c) 2003 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: This module contains the implementation of CbsUtils class |
|
15 * member functions. |
|
16 * |
|
17 */ |
|
18 |
|
19 |
|
20 |
|
21 // INCLUDE FILES |
|
22 #include <f32file.h> |
|
23 #include <barsc.h> |
|
24 #include <bautils.h> |
|
25 #include <sysutil.h> // FFS critical level check |
|
26 #include "CbsUtils.h" |
|
27 #include <hal.h> |
|
28 #include <centralrepository.h> |
|
29 #include <UiklafInternalCRKeys.h> |
|
30 #include <data_caging_path_literals.hrh> |
|
31 #include "CbsLogger.h" |
|
32 |
|
33 |
|
34 // ================= CONSTANTS ======================= |
|
35 |
|
36 const TInt KRamMemoryCriticalLevel = 1500000; // KRAMLOWTHRESHOLD = 1500000 |
|
37 |
|
38 |
|
39 // ================= MEMBER FUNCTIONS ======================= |
|
40 |
|
41 |
|
42 // ----------------------------------------------------------------------------- |
|
43 // CbsUtils::FindAndOpenDefaultResourceFileLC |
|
44 // Searches and opens the DLL default resource file. |
|
45 // (other items were commented in a header). |
|
46 // ----------------------------------------------------------------------------- |
|
47 // |
|
48 void CbsUtils::FindAndOpenDefaultResourceFileLC( |
|
49 RFs& aFs, |
|
50 RResourceFile& aResFile ) |
|
51 { |
|
52 // default resource file path |
|
53 |
|
54 _LIT(KDirAndFile,"z:CbsServer.rsc"); |
|
55 |
|
56 TParse* fp = new(ELeave) TParse(); |
|
57 fp->Set(KDirAndFile, &KDC_RESOURCE_FILES_DIR, NULL); |
|
58 |
|
59 static const TInt KDefResFileSignature = 4; |
|
60 |
|
61 // Find the resource file |
|
62 TFileName fileName( fp->FullName() ); |
|
63 BaflUtils::NearestLanguageFile( aFs, fileName ); |
|
64 |
|
65 // Open the resource file |
|
66 aResFile.OpenL( aFs, fileName ); |
|
67 // Push close operation in tbe cleanup stack |
|
68 CleanupClosePushL( aResFile ); |
|
69 |
|
70 aResFile.ConfirmSignatureL( KDefResFileSignature ); |
|
71 |
|
72 delete fp; |
|
73 } |
|
74 |
|
75 // ----------------------------------------------------------------------------- |
|
76 // CbsUtils::FFSCriticalLevelCheckL |
|
77 // Checks that there is space for writing data on FFS. |
|
78 // (other items were commented in a header). |
|
79 // ----------------------------------------------------------------------------- |
|
80 // |
|
81 void CbsUtils::FFSCriticalLevelCheckL( |
|
82 const TInt aBytesToWrite, |
|
83 RFs& aFs ) |
|
84 { |
|
85 CBSLOGSTRING("CBSSERVER: >>> CbsUtils::FFSCriticalLevelCheckL()"); |
|
86 |
|
87 // Checks RAM memory critical level. |
|
88 if (RamMemCriticalLevelCheckL( aBytesToWrite )) |
|
89 { |
|
90 User::Leave( KErrDiskFull ); // returns KErrDiskFull -> no changes to clients |
|
91 } |
|
92 |
|
93 // Checks RAM disk critical level |
|
94 if ( SysUtil::FFSSpaceBelowCriticalLevelL( &aFs, aBytesToWrite ) ) |
|
95 { |
|
96 User::Leave( KErrDiskFull ); |
|
97 } |
|
98 |
|
99 CBSLOGSTRING("CBSSERVER: <<< CbsUtils::FFSCriticalLevelCheckL()"); |
|
100 } |
|
101 |
|
102 // ----------------------------------------------------------------------------- |
|
103 // CbsUtils::RamMemCriticalLevelCheckL |
|
104 // Checks that there is space for allocating data in memory. |
|
105 // (other items were commented in a header). |
|
106 // ----------------------------------------------------------------------------- |
|
107 // |
|
108 TBool CbsUtils::RamMemCriticalLevelCheckL( |
|
109 const TInt aBytesToWrite) |
|
110 { |
|
111 |
|
112 // Read the critical threahold RAM memory level from the repository. |
|
113 TInt thresholdVal; |
|
114 CRepository* repository = CRepository::NewLC( KCRUidUiklaf ); |
|
115 if (repository->Get( KUikOOMRamLowThreshold, thresholdVal ) != KErrNone) |
|
116 { |
|
117 thresholdVal = KRamMemoryCriticalLevel; |
|
118 } |
|
119 CleanupStack::PopAndDestroy( repository ); |
|
120 |
|
121 TInt freeMem = 0; |
|
122 HAL::Get(HAL::EMemoryRAMFree, freeMem); |
|
123 if ( freeMem > (thresholdVal + aBytesToWrite) ) |
|
124 { |
|
125 return EFalse; |
|
126 } |
|
127 |
|
128 return ETrue; |
|
129 } |
|
130 // ----------------------------------------------------------------------------- |
|
131 // CbsUtils::VolumeCriticalLevelCheckL |
|
132 // Leaves with KErrDiskFull if writing aBytesToWrite bytes |
|
133 // to the RAM File System would reduce the free space on RAM |
|
134 // under the critical level. |
|
135 // (other items were commented in a header). |
|
136 // ----------------------------------------------------------------------------- |
|
137 // |
|
138 void CbsUtils::VolumeCriticalLevelCheckL( |
|
139 const TDesC& aFileName, |
|
140 TInt aBytesToWrite, |
|
141 const RFs& aFs ) |
|
142 { |
|
143 // Convert file name to a volume number |
|
144 TInt volumeNumber; |
|
145 aFs.CharToDrive( aFileName[0], volumeNumber ); |
|
146 |
|
147 // Find out if the volume has enough free space |
|
148 TVolumeInfo volume; |
|
149 User::LeaveIfError( aFs.Volume( volume, volumeNumber ) ); |
|
150 if ( volume.iFree < aBytesToWrite ) |
|
151 { |
|
152 User::Leave( KErrDiskFull ); |
|
153 } |
|
154 } |
|
155 |
|
156 // ----------------------------------------------------------------------------- |
|
157 // CbsUtils::ExistsL |
|
158 // Returns ETrue, if the file aFile exists. |
|
159 // (other items were commented in a header). |
|
160 // ----------------------------------------------------------------------------- |
|
161 // |
|
162 TBool CbsUtils::ExistsL( |
|
163 const RFs& aFs, |
|
164 const TDesC& aFile ) |
|
165 { |
|
166 TParse filename; |
|
167 aFs.Parse( aFile, filename ); |
|
168 |
|
169 TBool returnCode( EFalse ); |
|
170 TUint attributes; |
|
171 |
|
172 TInt result( aFs.Att( filename.FullName(), attributes ) ); |
|
173 if ( result == KErrNone ) |
|
174 { |
|
175 returnCode = ETrue; |
|
176 } |
|
177 else if ( result == KErrNotFound ) |
|
178 { |
|
179 returnCode = EFalse; |
|
180 } |
|
181 else |
|
182 { |
|
183 User::Leave( result ); |
|
184 } |
|
185 return returnCode; |
|
186 } |
|
187 |
|
188 // ----------------------------------------------------------------------------- |
|
189 // CbsUtils::DeleteFileL |
|
190 // Deletes the given file. |
|
191 // (other items were commented in a header). |
|
192 // ----------------------------------------------------------------------------- |
|
193 // |
|
194 void CbsUtils::DeleteFileL( |
|
195 RFs& aFs, |
|
196 const TDesC& aFile ) |
|
197 { |
|
198 TInt result( aFs.Delete( aFile ) ); |
|
199 if ( result != KErrNone && |
|
200 result != KErrNotFound && |
|
201 result != KErrPathNotFound ) |
|
202 { |
|
203 User::Leave( result ); |
|
204 } |
|
205 } |
|
206 |
|
207 // ========================== OTHER EXPORTED FUNCTIONS ========================= |
|
208 |
|
209 // End of File |
|
210 |
|
211 |
|