|
1 /* |
|
2 * Copyright (c) 2002 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: Client to AknIconServer. |
|
15 * |
|
16 */ |
|
17 |
|
18 |
|
19 // INCLUDE FILES |
|
20 |
|
21 #include "AknIconSrv.h" |
|
22 #include "AknIconSrvClient.h" |
|
23 #include "AknIconSrvTlsData.h" |
|
24 #include "AknBitmap.h" |
|
25 #include "AknIconSrvDef.h" |
|
26 #include "AknIconPanic.h" |
|
27 #include "AknIconManager.h" |
|
28 #include "AknIconTraces.h" |
|
29 #include <flogger.h> |
|
30 |
|
31 #ifdef PRECACHELOG |
|
32 #include <flogger.h> |
|
33 #endif |
|
34 |
|
35 // CONSTANTS |
|
36 const TInt KAsyncMessageSlots = 0; |
|
37 const TInt KConnectionTries = 2; |
|
38 |
|
39 // ================= MEMBER FUNCTIONS ========================================== |
|
40 |
|
41 RAknIconSrvClient::RAknIconSrvClient() : iConnections( 1 ) |
|
42 { |
|
43 } |
|
44 |
|
45 // ----------------------------------------------------------------------------- |
|
46 // RAknIconSrvClient::Connect() |
|
47 // ----------------------------------------------------------------------------- |
|
48 // |
|
49 EXPORT_C TInt RAknIconSrvClient::Connect() |
|
50 { |
|
51 TInt ret = KErrNone; |
|
52 |
|
53 CAknIconSrvTlsData* data = static_cast<CAknIconSrvTlsData*>( Dll::Tls() ); |
|
54 |
|
55 if ( data ) |
|
56 { |
|
57 data->iIconSession.iConnections++; |
|
58 return KErrNone; |
|
59 } |
|
60 else |
|
61 { |
|
62 TRAP( ret, CAknIconSrvTlsData::CreateSingletonL() ); |
|
63 } |
|
64 |
|
65 return ret; |
|
66 } |
|
67 |
|
68 // ----------------------------------------------------------------------------- |
|
69 // RAknIconSrvClient::Disconnect() |
|
70 // ----------------------------------------------------------------------------- |
|
71 // |
|
72 EXPORT_C void RAknIconSrvClient::Disconnect() |
|
73 { |
|
74 CAknIconSrvTlsData* data = static_cast<CAknIconSrvTlsData*>( Dll::Tls() ); |
|
75 |
|
76 if ( !data ) return; |
|
77 |
|
78 if ( data->iIconSession.iConnections > 0 ) |
|
79 { |
|
80 data->iIconSession.iConnections--; |
|
81 } |
|
82 |
|
83 if ( !data->iIconSession.iConnections ) |
|
84 { |
|
85 delete data; // also frees TLS |
|
86 } |
|
87 } |
|
88 |
|
89 // ----------------------------------------------------------------------------- |
|
90 // RAknIconSrvClient::GetSession() |
|
91 // ----------------------------------------------------------------------------- |
|
92 // |
|
93 RAknIconSrvClient* RAknIconSrvClient::GetSession() |
|
94 { |
|
95 CAknIconSrvTlsData* data = static_cast<CAknIconSrvTlsData*>( Dll::Tls() ); |
|
96 |
|
97 __ASSERT_ALWAYS( data, |
|
98 User::Panic( KAknIconPanicCategory, EClientSessionNotConnected ) ); |
|
99 |
|
100 return &data->iIconSession; |
|
101 } |
|
102 |
|
103 // ----------------------------------------------------------------------------- |
|
104 // RAknIconSrvClient::InitializeIconL() |
|
105 // ----------------------------------------------------------------------------- |
|
106 // |
|
107 void RAknIconSrvClient::InitializeIconL( |
|
108 CAknBitmap& aBitmap, |
|
109 CAknBitmap& aMask, |
|
110 TAknContentDimensions& aContentDimensions, |
|
111 const TAknIconParams& aInfo ) const |
|
112 { |
|
113 TPckgC<TAknIconParams> paramPack( aInfo ); |
|
114 TAknIconSrvReturnData retData; |
|
115 |
|
116 CAknIconManager* manager = aBitmap.Manager(); |
|
117 TBool mbmIcon = manager->IsMbmIcon(); |
|
118 |
|
119 if ( mbmIcon ) |
|
120 { |
|
121 // Existing bitmap handles are passed to the server side if they point |
|
122 // to the bitmaps already retrieved with CFbsBitmap::Load, which the |
|
123 // server it supposed to stretch into another bitmaps of given size. |
|
124 retData.iBitmapHandle = aBitmap.Handle(); |
|
125 if ( aInfo.iMaskId >= 0 ) |
|
126 { |
|
127 retData.iMaskHandle = aMask.Handle(); |
|
128 } |
|
129 #ifdef PRECACHELOG |
|
130 HBufC* buf = HBufC::New( 1024 ); |
|
131 if ( buf ) |
|
132 { |
|
133 |
|
134 TPtr ptr = buf->Des(); |
|
135 ptr.Append( _L("AKNICON load, ") ); |
|
136 |
|
137 TFileName fileName; |
|
138 manager->GetFullFileName( fileName ); |
|
139 |
|
140 ptr.Append(fileName); |
|
141 |
|
142 ptr.Append( _L(", ") ); |
|
143 ptr.AppendNum( aInfo.iBitmapId ); |
|
144 ptr.Append( _L(", ") ); |
|
145 ptr.AppendNum( aInfo.iMaskId ); |
|
146 ptr.Append( _L(", ") ); |
|
147 ptr.AppendNum( aInfo.iSize.iWidth ); |
|
148 ptr.Append( _L(", ") ); |
|
149 ptr.AppendNum( aInfo.iSize.iHeight ); |
|
150 ptr.Append( _L(", ") ); |
|
151 ptr.AppendNum( aInfo.iMode ); |
|
152 ptr.Append( _L(", ") ); |
|
153 ptr.AppendNum( aInfo.iRotationAngle ); |
|
154 ptr.Append( _L(", ") ); |
|
155 ptr.AppendNum( aInfo.iColor.Internal() ); |
|
156 ptr.Append( _L(", ") ); |
|
157 ptr.AppendNum( aInfo.IsCompressionDisabled() ); |
|
158 ptr.Append( _L(", ") ); |
|
159 |
|
160 |
|
161 _LIT( KFileLoggingDir, "AknIconPreCacher" ); |
|
162 _LIT( KFileLog, "Traces.txt" ); |
|
163 |
|
164 RFileLogger::Write(KFileLoggingDir, KFileLog, EFileLoggingModeAppend, ptr); |
|
165 |
|
166 |
|
167 |
|
168 delete buf; |
|
169 } |
|
170 |
|
171 #endif |
|
172 //PrecacheCache tool |
|
173 } |
|
174 |
|
175 TPckg<TAknIconSrvReturnData> retPack( retData ); |
|
176 TIpcArgs args( ¶mPack, &retPack, 0, 0 ); |
|
177 |
|
178 if ( aInfo.iFile.SubSessionHandle() ) |
|
179 { |
|
180 User::LeaveIfError( aInfo.iFile.TransferToServer( args, 2, 3 ) ); |
|
181 } |
|
182 |
|
183 // Scalable icon are generated and shared by server. |
|
184 // Bitmap icons are stretched and shared by server. |
|
185 User::LeaveIfError( SendReceive( ERetrieveOrCreateSharedIcon, args ) ); |
|
186 |
|
187 // Now reset the bitmaps, which frees their old contents. |
|
188 // Then duplicate them with the handles retrieved from the server. |
|
189 aBitmap.Reset(); |
|
190 if ( aInfo.iMaskId >= 0 ) |
|
191 { |
|
192 aMask.Reset(); |
|
193 } |
|
194 |
|
195 // This code enables proper cleanup in AknIconSrv side in CAknBitmap::Reset |
|
196 // and must be done before any leaving code. |
|
197 // --------------------------------------------------------------------- |
|
198 manager->SetInitializedParams( aInfo ); |
|
199 manager->SetAppIcon(aInfo.iAppIcon); |
|
200 aBitmap.SetSharedByIconSrv(); |
|
201 |
|
202 if ( aInfo.iMaskId >= 0 ) |
|
203 { |
|
204 aMask.SetSharedByIconSrv(); |
|
205 } |
|
206 // --------------------------------------------------------------------- |
|
207 |
|
208 // Duplicate the returned bitmap (and mask). |
|
209 User::LeaveIfError( aBitmap.Duplicate( retData.iBitmapHandle ) ); |
|
210 |
|
211 if ( aInfo.iMaskId >= 0 ) |
|
212 { |
|
213 User::LeaveIfError( aMask.Duplicate( retData.iMaskHandle ) ); |
|
214 } |
|
215 |
|
216 aContentDimensions = retData.iContentDimensions; |
|
217 } |
|
218 |
|
219 // ----------------------------------------------------------------------------- |
|
220 // RAknIconSrvClient::FreeBitmap() |
|
221 // ----------------------------------------------------------------------------- |
|
222 // |
|
223 void RAknIconSrvClient::FreeBitmap( CAknBitmap& aBitmap ) const |
|
224 { |
|
225 TAknIconParams info; |
|
226 |
|
227 CAknIconManager* manager = aBitmap.Manager(); |
|
228 manager->GetFileName( info.iFileName ); |
|
229 info.iBitmapId = manager->IconIdToIndex( manager->BitmapId() ); |
|
230 info.iMaskId = manager->IconIdToIndex( manager->MaskId() ); |
|
231 info.iAppIcon = manager->GetAppIcon(); |
|
232 manager->GetInitializedParams( info ); |
|
233 |
|
234 TPckgC<TAknIconParams> paramPack( info ); |
|
235 |
|
236 SendReceive( EFreeBitmap, TIpcArgs( ¶mPack ) ); |
|
237 } |
|
238 |
|
239 // ----------------------------------------------------------------------------- |
|
240 // RAknIconSrvClient::GetContentDimensions() |
|
241 // ----------------------------------------------------------------------------- |
|
242 // |
|
243 TInt RAknIconSrvClient::GetContentDimensions( |
|
244 CAknBitmap& aBitmap, TAknContentDimensions& aContentDimensions ) const |
|
245 { |
|
246 CAknIconManager* manager = aBitmap.Manager(); |
|
247 |
|
248 RFile* file = NULL; |
|
249 |
|
250 TRAPD( err, |
|
251 { |
|
252 file = manager->FileHandleL(); |
|
253 } ); |
|
254 |
|
255 if ( err != KErrNone ) |
|
256 { |
|
257 return err; |
|
258 } |
|
259 |
|
260 TAknIconParams info; |
|
261 manager->GetFileName( info.iFileName ); |
|
262 info.iBitmapId = manager->IconIdToIndex( manager->BitmapId() ); |
|
263 info.iAppIcon = manager->GetAppIcon(); |
|
264 if (manager->IsDefaultIconDirUsed()) |
|
265 { |
|
266 info.SetDefaultIconDirUsed(); |
|
267 } |
|
268 |
|
269 if ( file ) |
|
270 { |
|
271 info.iFile = *file; |
|
272 } |
|
273 |
|
274 // Other members of TAknIconParams omitted. |
|
275 |
|
276 TPckgC<TAknIconParams> paramPack( info ); |
|
277 TPckg<TAknContentDimensions> returnPack( aContentDimensions ); |
|
278 |
|
279 TIpcArgs args( ¶mPack, &returnPack, 0, 0 ); |
|
280 |
|
281 if ( info.iFile.SubSessionHandle() ) |
|
282 { |
|
283 err = info.iFile.TransferToServer( args, 2, 3 ); |
|
284 } |
|
285 |
|
286 if ( err == KErrNone ) |
|
287 { |
|
288 err = SendReceive( EGetContentDimensions, args ); |
|
289 } |
|
290 |
|
291 return err; |
|
292 } |
|
293 |
|
294 // ----------------------------------------------------------------------------- |
|
295 // RAknIconSrvClient::PreserveIconData() |
|
296 // ----------------------------------------------------------------------------- |
|
297 // |
|
298 TInt RAknIconSrvClient::PreserveIconData( CAknIconManager& aManager ) const |
|
299 { |
|
300 RFile* file = NULL; |
|
301 |
|
302 TRAPD( err, |
|
303 { |
|
304 file = aManager.FileHandleL(); |
|
305 } ); |
|
306 |
|
307 if ( err != KErrNone ) |
|
308 { |
|
309 return err; |
|
310 } |
|
311 |
|
312 TAknIconParams info; |
|
313 aManager.GetFileName( info.iFileName ); |
|
314 info.iBitmapId = aManager.IconIdToIndex( aManager.BitmapId() ); |
|
315 info.iAppIcon = aManager.GetAppIcon(); |
|
316 if (aManager.IsDefaultIconDirUsed()) |
|
317 { |
|
318 info.SetDefaultIconDirUsed(); |
|
319 } |
|
320 |
|
321 if ( file ) |
|
322 { |
|
323 info.iFile = *file; |
|
324 } |
|
325 |
|
326 // Other members of TAknIconParams omitted. |
|
327 |
|
328 TPckgC<TAknIconParams> paramPack( info ); |
|
329 TIpcArgs args( ¶mPack, 0, 0, 0 ); |
|
330 |
|
331 if ( info.iFile.SubSessionHandle() ) |
|
332 { |
|
333 err = info.iFile.TransferToServer( args, 2, 3 ); |
|
334 } |
|
335 |
|
336 if ( err == KErrNone ) |
|
337 { |
|
338 err = SendReceive( EPreserveIconData, args ); |
|
339 } |
|
340 |
|
341 return err; |
|
342 } |
|
343 |
|
344 // ----------------------------------------------------------------------------- |
|
345 // RAknIconSrvClient::DestroyIconData() |
|
346 // ----------------------------------------------------------------------------- |
|
347 // |
|
348 void RAknIconSrvClient::DestroyIconData( CAknIconManager& aManager ) const |
|
349 { |
|
350 TAknIconParams info; |
|
351 aManager.GetFileName( info.iFileName ); |
|
352 info.iBitmapId = aManager.IconIdToIndex( aManager.BitmapId() ); |
|
353 // Other members of TAknIconParams omitted. |
|
354 info.iAppIcon = aManager.GetAppIcon(); |
|
355 TPckgC<TAknIconParams> paramPack( info ); |
|
356 |
|
357 SendReceive( EDestroyIconData, TIpcArgs(¶mPack) ); |
|
358 } |
|
359 |
|
360 // ----------------------------------------------------------------------------- |
|
361 // RAknIconSrvClient::GetInitData() |
|
362 // ----------------------------------------------------------------------------- |
|
363 // |
|
364 void RAknIconSrvClient::GetInitData( |
|
365 TAknIconInitData& aData ) const |
|
366 { |
|
367 TPckg<TAknIconInitData> returnPack( aData ); |
|
368 SendReceive( EGetInitData, TIpcArgs( &returnPack ) ); |
|
369 } |
|
370 |
|
371 // ----------------------------------------------------------------------------- |
|
372 // RAknIconSrvClient::__SERVER_HEAP_MARK() |
|
373 // ----------------------------------------------------------------------------- |
|
374 // |
|
375 void RAknIconSrvClient::__SERVER_HEAP_MARK() const |
|
376 { |
|
377 #if defined(_DEBUG) && defined(__WINS__) |
|
378 SendReceive( EServerHeapMark, TIpcArgs() ); |
|
379 #endif |
|
380 } |
|
381 |
|
382 // ----------------------------------------------------------------------------- |
|
383 // RAknIconSrvClient::__SERVER_HEAP_MARKEND() |
|
384 // ----------------------------------------------------------------------------- |
|
385 // |
|
386 void RAknIconSrvClient::__SERVER_HEAP_MARKEND() const |
|
387 { |
|
388 #if defined(_DEBUG) && defined(__WINS__) |
|
389 SendReceive( EServerHeapMarkEnd, TIpcArgs() ); |
|
390 #endif |
|
391 } |
|
392 |
|
393 // ----------------------------------------------------------------------------- |
|
394 // RAknIconSrvClient::__SERVER_HEAP_FAILNEXT() |
|
395 // ----------------------------------------------------------------------------- |
|
396 // |
|
397 void RAknIconSrvClient::__SERVER_HEAP_FAILNEXT( TInt aCount ) const |
|
398 { |
|
399 #if defined(_DEBUG) && defined(__WINS__) |
|
400 SendReceive( EServerHeapFailNext, TIpcArgs(aCount) ); |
|
401 #endif |
|
402 } |
|
403 |
|
404 // ----------------------------------------------------------------------------- |
|
405 // RAknIconSrvClient::__SERVER_HEAP_FAILNEXT_INCREASING() |
|
406 // ----------------------------------------------------------------------------- |
|
407 // |
|
408 void RAknIconSrvClient::__SERVER_HEAP_FAILNEXT_INCREASING( TInt aCount ) const |
|
409 { |
|
410 #if defined(_DEBUG) && defined(__WINS__) |
|
411 SendReceive( EServerHeapFailNextIncreasing, TIpcArgs(aCount) ); |
|
412 #endif |
|
413 } |
|
414 |
|
415 // ----------------------------------------------------------------------------- |
|
416 // RAknIconSrvClient::__SERVER_HEAP_RESET() |
|
417 // ----------------------------------------------------------------------------- |
|
418 // |
|
419 void RAknIconSrvClient::__SERVER_HEAP_RESET() const |
|
420 { |
|
421 #if defined(_DEBUG) && defined(__WINS__) |
|
422 SendReceive( EServerHeapReset, TIpcArgs() ); |
|
423 #endif |
|
424 } |
|
425 |
|
426 // ----------------------------------------------------------------------------- |
|
427 // RAknIconSrvClient::__SERVER_RESET_DYNAMICALLY_CHANGING_ALLOCATIONS() |
|
428 // ----------------------------------------------------------------------------- |
|
429 // |
|
430 void RAknIconSrvClient::__SERVER_RESET_DYNAMICALLY_CHANGING_ALLOCATIONS() const |
|
431 { |
|
432 #if defined(_DEBUG) |
|
433 SendReceive( EServerResetDynamicallyChangingAllocations, TIpcArgs() ); |
|
434 #endif |
|
435 } |
|
436 |
|
437 // ----------------------------------------------------------------------------- |
|
438 // RAknIconSrvClient::__SERVER_HEAP_USED() |
|
439 // ----------------------------------------------------------------------------- |
|
440 // |
|
441 TInt RAknIconSrvClient::__SERVER_HEAP_USED() const |
|
442 { |
|
443 TInt ret = 0; |
|
444 #if defined(_DEBUG) |
|
445 ret = SendReceive( EServerHeapUsed, TIpcArgs() ); |
|
446 #endif |
|
447 return ret; |
|
448 } |
|
449 |
|
450 // ----------------------------------------------------------------------------- |
|
451 // RAknIconSrvClient::__SERVER_HEAP_USED() |
|
452 // ----------------------------------------------------------------------------- |
|
453 // |
|
454 void RAknIconSrvClient::__SERVER_SET_PREFERRED_ICON_DISPLAY_MODE( |
|
455 TDisplayMode aMode ) const |
|
456 { |
|
457 #if defined(_DEBUG) |
|
458 SendReceive( EServerSetPreferredIconDisplayMode, TIpcArgs( aMode ) ); |
|
459 #endif |
|
460 } |
|
461 |
|
462 // ----------------------------------------------------------------------------- |
|
463 // RAknIconSrvClient::ConnectToServer() |
|
464 // ----------------------------------------------------------------------------- |
|
465 // |
|
466 TInt RAknIconSrvClient::ConnectToServer() |
|
467 { |
|
468 // Connect to server and make sure this can't cause 2 servers launch |
|
469 // if 2 clients are trying to connect simultaneously. |
|
470 |
|
471 TInt err = KErrNone; |
|
472 |
|
473 for ( TInt tries = 0; tries < KConnectionTries ; tries++ ) |
|
474 { |
|
475 err = CreateSession( KAknIconSrvName, TVersion(), KAsyncMessageSlots ); |
|
476 |
|
477 // Break if connected to existing server or if the problem is |
|
478 // other than missing server. |
|
479 |
|
480 if ( err == KErrNone || |
|
481 ( err != KErrNotFound && err != KErrServerTerminated ) ) |
|
482 { |
|
483 break; |
|
484 } |
|
485 |
|
486 err = StartServer(); // try start a new server |
|
487 |
|
488 // If server launched ok or someone else got to launch it first, |
|
489 // try connect again. |
|
490 |
|
491 if ( err != KErrNone && err != KErrAlreadyExists) |
|
492 { |
|
493 break; // server not launched: don't cycle round again |
|
494 } |
|
495 } |
|
496 |
|
497 return err; |
|
498 } |
|
499 |
|
500 // ----------------------------------------------------------------------------- |
|
501 // RAknIconSrvClient::EnableCache() |
|
502 // ----------------------------------------------------------------------------- |
|
503 // |
|
504 TInt RAknIconSrvClient::EnableCache(TBool aEnable) |
|
505 { |
|
506 return SendReceive( EAknIconServRequestEnableCache, TIpcArgs(aEnable) ); |
|
507 } |
|
508 |
|
509 // End of File |