1 /* |
|
2 * Copyright (c) 2005 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: CXcapCacheServer |
|
15 * |
|
16 */ |
|
17 |
|
18 |
|
19 |
|
20 |
|
21 // INCLUDE FILES |
|
22 #include <e32std.h> |
|
23 #include <e32math.h> |
|
24 #include <flogger.h> |
|
25 #include <centralrepository.h> |
|
26 #include <XdmEngineDomainCRKeys.h> |
|
27 #include "XcapCacheIndex.h" |
|
28 #include "XcapCacheServer.h" |
|
29 #include "XcapCacheSession.h" |
|
30 #include "XcapCacheIndexAdmin.h" |
|
31 #include "XcapCacheServerMain.h" |
|
32 |
|
33 GLDEF_C void PanicServer( TXcapCacheServerPanic aPanic ) |
|
34 { |
|
35 _LIT( KCacheServerPanic, "XcapCacheServer"); |
|
36 User::Panic( KCacheServerPanic, aPanic ); |
|
37 } |
|
38 |
|
39 // ---------------------------------------------------------- |
|
40 // CXcapCacheServer::New |
|
41 // |
|
42 // ---------------------------------------------------------- |
|
43 // |
|
44 CServer2* CXcapCacheServer::NewLC() |
|
45 { |
|
46 CXcapCacheServer* self = new CXcapCacheServer( EPriorityHigh ); |
|
47 CleanupStack::PushL( self ); |
|
48 self->ConstructL(); |
|
49 return self; |
|
50 } |
|
51 |
|
52 // ---------------------------------------------------------- |
|
53 // CXcapCacheServer::New |
|
54 // |
|
55 // ---------------------------------------------------------- |
|
56 // |
|
57 void CXcapCacheServer::ConstructL() |
|
58 { |
|
59 ReadMaxCacheSizeL(); |
|
60 User::LeaveIfError( iFileSession.Connect() ); |
|
61 StartL( KXcapCacheServerLib ); |
|
62 iShutdownTimer.ConstructL(); |
|
63 iShutdownTimer.Start(); |
|
64 } |
|
65 |
|
66 // ---------------------------------------------------------- |
|
67 // CXcapCacheServer::NewSessionL |
|
68 // |
|
69 // ---------------------------------------------------------- |
|
70 // |
|
71 CSession2* CXcapCacheServer::NewSessionL( const TVersion& aVersion, |
|
72 const RMessage2& /*aMessage*/ ) const |
|
73 { |
|
74 // Check version number of API against our known version number. |
|
75 TVersion thisVersion( KCacheServerMajorVersionNumber, |
|
76 KCacheServerMinorVersionNumber, |
|
77 KCacheServerBuildVersionNumber ); |
|
78 if( !User::QueryVersionSupported( thisVersion, aVersion ) ) |
|
79 User::Leave( KErrNotSupported ); |
|
80 return CXcapCacheSession::NewL( ( CXcapCacheServer* )this ); |
|
81 } |
|
82 |
|
83 // ---------------------------------------------------------- |
|
84 // CXcapCacheServer::CXcapCacheServer |
|
85 // |
|
86 // ---------------------------------------------------------- |
|
87 // |
|
88 CXcapCacheServer::~CXcapCacheServer() |
|
89 { |
|
90 iFileSession.Close(); |
|
91 } |
|
92 |
|
93 // ---------------------------------------------------------- |
|
94 // CXcapCacheServer::ReadMaxCacheSizeL |
|
95 // |
|
96 // ---------------------------------------------------------- |
|
97 // |
|
98 void CXcapCacheServer::ReadMaxCacheSizeL() |
|
99 { |
|
100 #ifdef _DEBUG |
|
101 CXcapCacheServer::WriteToLog( _L8( "CXcapCacheServer::ReadMaxCacheSizeL()" ) ); |
|
102 #endif |
|
103 CRepository* repository = CRepository::NewL( KCRUIDXDMEngineXcapLocal ); |
|
104 CleanupStack::PushL( repository ); |
|
105 TInt error = repository->Get( KXDMXcapCacheSize, iMaxCacheSize ); |
|
106 //If something went wrong, just use 30 KB as a default value |
|
107 if( error != KErrNone ) |
|
108 { |
|
109 #ifdef _DEBUG |
|
110 CXcapCacheServer::WriteToLog( _L8( "Reading from CenRep failed: %d => Default to 30 KB" ), error ); |
|
111 #endif |
|
112 iMaxCacheSize = 30000; |
|
113 } |
|
114 else |
|
115 { |
|
116 #ifdef _DEBUG |
|
117 CXcapCacheServer::WriteToLog( _L8( " Max cache size is %d KB" ), iMaxCacheSize ); |
|
118 #endif |
|
119 iMaxCacheSize = iMaxCacheSize * 1000; |
|
120 } |
|
121 CleanupStack::PopAndDestroy(); //repository |
|
122 } |
|
123 |
|
124 // ---------------------------------------------------------- |
|
125 // CXcapCacheServer::CXcapCacheServer |
|
126 // |
|
127 // ---------------------------------------------------------- |
|
128 // |
|
129 CXcapCacheServer::CXcapCacheServer( TInt aPriority ) : CServer2( aPriority ) |
|
130 { |
|
131 } |
|
132 |
|
133 // ---------------------------------------------------------- |
|
134 // CXcapCacheServer::AddSession |
|
135 // |
|
136 // ---------------------------------------------------------- |
|
137 // |
|
138 void CXcapCacheServer::AddSession() |
|
139 { |
|
140 #ifdef _DEBUG |
|
141 CXcapCacheServer::WriteToLog( _L8( "CXcapCacheServer::AddSession()" ) ); |
|
142 #endif |
|
143 ++iSessionCount; |
|
144 iShutdownTimer.Cancel(); |
|
145 } |
|
146 |
|
147 // ---------------------------------------------------------- |
|
148 // CXcapCacheServer::DropSession |
|
149 // |
|
150 // ---------------------------------------------------------- |
|
151 // |
|
152 void CXcapCacheServer::DropSession() |
|
153 { |
|
154 #ifdef _DEBUG |
|
155 CXcapCacheServer::WriteToLog( _L8( "CXcapCacheServer::DropSession()" ) ); |
|
156 #endif |
|
157 if( --iSessionCount == 0 ) |
|
158 CActiveScheduler::Stop(); |
|
159 } |
|
160 |
|
161 // ---------------------------------------------------------- |
|
162 // CXcapCacheServer::ConvertDesc |
|
163 // |
|
164 // ---------------------------------------------------------- |
|
165 // |
|
166 TInt CXcapCacheServer::ConvertDesc( const TDesC8& aNumberDesc ) |
|
167 { |
|
168 TInt ret = 0; |
|
169 TLex8 lex( aNumberDesc ); |
|
170 TInt error = lex.Val( ret ); |
|
171 return error == KErrNone ? ret : error; |
|
172 } |
|
173 |
|
174 // --------------------------------------------------------- |
|
175 // CXcapCacheServer::Date |
|
176 // |
|
177 // --------------------------------------------------------- |
|
178 // |
|
179 TBuf<KDateMaxSize> CXcapCacheServer::Date() |
|
180 { |
|
181 TTime time; |
|
182 TBuf<KDateMaxSize> dateBuffer; |
|
183 dateBuffer.SetLength( 0 ); |
|
184 time.HomeTime(); |
|
185 time.FormatL( dateBuffer, KCacheDateFormat ); |
|
186 return dateBuffer; |
|
187 } |
|
188 |
|
189 // --------------------------------------------------------- |
|
190 // CXcapCacheServer::DateTime |
|
191 // |
|
192 // --------------------------------------------------------- |
|
193 // |
|
194 TBuf<KDateTimeMaxSize> CXcapCacheServer::DateTime() |
|
195 { |
|
196 TTime time; |
|
197 TBuf<KDateMaxSize> dateBuffer; |
|
198 time.HomeTime(); |
|
199 time.FormatL( dateBuffer, KDateFormatFileName ); |
|
200 TBuf<KDateMaxSize> timeBuffer; |
|
201 time.HomeTime(); |
|
202 time.FormatL( timeBuffer, KTimeFormatFileName ); |
|
203 TBuf<KDateTimeMaxSize> buffer; |
|
204 buffer.SetLength( 0 ); |
|
205 buffer.Copy( dateBuffer ); |
|
206 buffer.Append( timeBuffer ); |
|
207 return buffer; |
|
208 } |
|
209 |
|
210 // --------------------------------------------------------- |
|
211 // CXcapCacheServer::DateTime |
|
212 // |
|
213 // --------------------------------------------------------- |
|
214 // |
|
215 TBuf<KDateTimeMaxSize> CXcapCacheServer::DateTime( const TTime& aTime ) |
|
216 { |
|
217 TBuf<KDateTimeMaxSize> dateTimeBuffer; |
|
218 aTime.FormatL( dateTimeBuffer, KDateTimeFormat ); |
|
219 return dateTimeBuffer; |
|
220 } |
|
221 |
|
222 // ---------------------------------------------------------- |
|
223 // CXcapCacheServer::MaxCacheSize |
|
224 // |
|
225 // ---------------------------------------------------------- |
|
226 // |
|
227 TInt CXcapCacheServer::MaxCacheSize() const |
|
228 { |
|
229 return iMaxCacheSize; |
|
230 } |
|
231 |
|
232 // --------------------------------------------------------- |
|
233 // CXcapCacheServer::CacheSize |
|
234 // |
|
235 // --------------------------------------------------------- |
|
236 // |
|
237 TInt CXcapCacheServer::CacheSize( TInt& aEntryCount ) |
|
238 { |
|
239 #ifdef _DEBUG |
|
240 CXcapCacheServer::WriteToLog( _L8( "CXcapCacheServer::CacheSize()" ) ); |
|
241 #endif |
|
242 TInt total = 0; |
|
243 TInt entryCount = 0; |
|
244 CDir* directory = NULL; |
|
245 User::LeaveIfError( iFileSession.GetDir( KCacheServerRoot, KEntryAttNormal, |
|
246 ESortNone, directory ) ); |
|
247 CleanupStack::PushL( directory ); |
|
248 entryCount = directory->Count(); |
|
249 for( TInt i = 0;i < entryCount;i++ ) |
|
250 total = total + ( *directory )[i].iSize; |
|
251 #ifdef _DEBUG |
|
252 CXcapCacheServer::WriteToLog( _L8( " Entries: %d " ), entryCount ); |
|
253 CXcapCacheServer::WriteToLog( _L8( " Total size: %d bytes" ), total ); |
|
254 #endif |
|
255 CleanupStack::PopAndDestroy(); |
|
256 aEntryCount = entryCount; |
|
257 return total; |
|
258 } |
|
259 |
|
260 // --------------------------------------------------------- |
|
261 // CXcapCacheServer::RandomString |
|
262 // |
|
263 // --------------------------------------------------------- |
|
264 // |
|
265 TBuf<KRandStringLength> CXcapCacheServer::RandomString() |
|
266 { |
|
267 const TInt charCount( sizeof( KRandomStringCharArray ) / sizeof( TInt ) ); |
|
268 TBuf<KRandStringLength> buffer; |
|
269 buffer.Zero(); |
|
270 for( TInt i = 0; i < KRandStringLength;i++ ) |
|
271 { |
|
272 TInt index = Math::Random() % charCount; |
|
273 buffer.Append( ( TChar )KRandomStringCharArray[index] ); |
|
274 } |
|
275 return buffer; |
|
276 } |
|
277 |
|
278 // --------------------------------------------------------- |
|
279 // CXcapCacheServer::Time |
|
280 // |
|
281 // --------------------------------------------------------- |
|
282 // |
|
283 TBuf<KDateMaxSize> CXcapCacheServer::Time() |
|
284 { |
|
285 TTime time; |
|
286 TBuf<KDateMaxSize> timeBuffer; |
|
287 timeBuffer.SetLength( 0 ); |
|
288 time.HomeTime(); |
|
289 time.FormatL( timeBuffer, KCacheTimeFormat ); |
|
290 return timeBuffer; |
|
291 } |
|
292 |
|
293 // --------------------------------------------------------- |
|
294 // CXcapCacheServer::DescriptorCast |
|
295 // |
|
296 // --------------------------------------------------------- |
|
297 // |
|
298 TPtr8 CXcapCacheServer::DescriptorCast( const TDesC8& aConstData ) |
|
299 { |
|
300 TInt length = aConstData.Length(); |
|
301 TPtr8 constCast( CONST_CAST( TUint8*, aConstData.Ptr() ), length, length ); |
|
302 constCast.TrimAll(); |
|
303 return constCast; |
|
304 } |
|
305 |
|
306 // ---------------------------------------------------- |
|
307 // CXcapCacheServer::FileSession |
|
308 // |
|
309 // ---------------------------------------------------- |
|
310 // |
|
311 RFs& CXcapCacheServer::FileSession() |
|
312 { |
|
313 return FsSession; |
|
314 } |
|
315 |
|
316 // ---------------------------------------------------- |
|
317 // CXcapCacheServer::FileSession |
|
318 // |
|
319 // ---------------------------------------------------- |
|
320 // |
|
321 CXcapCacheIndex* CXcapCacheServer::Index() |
|
322 { |
|
323 return CacheIndex; |
|
324 } |
|
325 |
|
326 // ---------------------------------------------------- |
|
327 // CXcapCacheServer::FileSession |
|
328 // |
|
329 // ---------------------------------------------------- |
|
330 // |
|
331 CXcapCacheIndexAdmin* CXcapCacheServer::IndexAdmin() |
|
332 { |
|
333 return CacheIndexAdmin; |
|
334 } |
|
335 |
|
336 // ---------------------------------------------------- |
|
337 // CXcapCacheServer::StartThread |
|
338 // |
|
339 // ---------------------------------------------------- |
|
340 // |
|
341 EXPORT_C TInt CXcapCacheServer::StartThread() |
|
342 { |
|
343 User::LeaveIfError( User::RenameThread( KXcapCacheServerName ) ); |
|
344 CActiveScheduler* scheduler = new ( ELeave ) CActiveScheduler; |
|
345 CleanupStack::PushL( scheduler ); |
|
346 CActiveScheduler::Install( scheduler ); |
|
347 User::LeaveIfError( FsSession.Connect() ); |
|
348 CleanupClosePushL( FsSession ); |
|
349 CXcapCacheServer::NewLC(); |
|
350 CacheIndex = CXcapCacheIndex::NewL(); |
|
351 CleanupStack::PushL( CacheIndex ); |
|
352 CacheIndexAdmin = CXcapCacheIndexAdmin::NewL(); |
|
353 CleanupStack::PushL( CacheIndexAdmin ); |
|
354 RProcess::Rendezvous( KErrNone ); |
|
355 #ifdef _DEBUG |
|
356 CXcapCacheServer::WriteToLog( _L8( "XcapCacheServer fully running" ) ); |
|
357 #endif |
|
358 CActiveScheduler::Start(); |
|
359 #ifdef _DEBUG |
|
360 CXcapCacheServer::WriteToLog( _L8( "XcapCacheServer closing..." ) ); |
|
361 #endif |
|
362 CleanupStack::PopAndDestroy( 5 ); //CacheIndexAdmin, CacheIndex, server, FsSession, scheduler |
|
363 return KErrNone; |
|
364 } |
|
365 |
|
366 // ---------------------------------------------------- |
|
367 // CXcapCacheServer::WriteToLog |
|
368 // |
|
369 // ---------------------------------------------------- |
|
370 // |
|
371 EXPORT_C void CXcapCacheServer::WriteToLog( TRefByValue<const TDesC8> aFmt,... ) |
|
372 { |
|
373 VA_LIST list; |
|
374 VA_START( list, aFmt ); |
|
375 TBuf8<KServerLogBufferMaxSize> buf; |
|
376 buf.FormatList( aFmt, list ); |
|
377 RFileLogger::Write( KCacheServerLogDir, KCacheServerLogFile, EFileLoggingModeAppend, buf ); |
|
378 RDebug::RawPrint( buf ); |
|
379 } |
|
380 |
|
381 |
|