|
1 // Copyright (c) 2007-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 |
|
17 #include <s32mem.h> |
|
18 #include "uloggersession.h" |
|
19 #include "uloggershared.h" |
|
20 #include "uloggerclient.h" |
|
21 #include "uloggershared.h" |
|
22 #include "uloggertools.h" |
|
23 |
|
24 namespace Ulogger { |
|
25 |
|
26 |
|
27 CULoggerSession* CULoggerSession::NewL(RThread& aClient, CULoggerServer& aServer) |
|
28 { |
|
29 CULoggerSession* self = CULoggerSession::NewLC(aClient, aServer); |
|
30 CleanupStack::Pop(); //self |
|
31 return self; |
|
32 }//</NewL> |
|
33 |
|
34 |
|
35 |
|
36 |
|
37 CULoggerSession* CULoggerSession::NewLC(RThread& aClient, CULoggerServer& aServer) |
|
38 { |
|
39 CULoggerSession* self = new(ELeave) CULoggerSession( aClient, aServer ); |
|
40 CleanupStack::PushL( self ); |
|
41 self->ConstructL(); |
|
42 return self; |
|
43 }//</NewLC> |
|
44 |
|
45 |
|
46 |
|
47 |
|
48 void CULoggerSession::ConstructL() |
|
49 { |
|
50 iServer.IncrementSessions(); |
|
51 }//</ConstructL> |
|
52 |
|
53 |
|
54 |
|
55 CULoggerSession::CULoggerSession(RThread& aClient, CULoggerServer& aServer) |
|
56 : CSession2(), |
|
57 iServer( aServer ), |
|
58 iClient( aClient ) |
|
59 { |
|
60 |
|
61 }//</constructor> |
|
62 |
|
63 |
|
64 |
|
65 CULoggerSession::~CULoggerSession() |
|
66 { |
|
67 iServer.DecrementSessions(); |
|
68 }//</destructor> |
|
69 |
|
70 |
|
71 |
|
72 |
|
73 |
|
74 |
|
75 /** Process message from 'client' (actually another instance of ourselves) |
|
76 */ |
|
77 void CULoggerSession::ServiceL(const RMessage2& aMessage) |
|
78 { |
|
79 TInt error = KErrNone; |
|
80 switch(aMessage.Function()) |
|
81 { |
|
82 case ERunAsService: |
|
83 { |
|
84 iServer.RunAsService(ETrue); |
|
85 error = KErrNone; |
|
86 } |
|
87 break; |
|
88 |
|
89 case EDontRunAsService: |
|
90 { |
|
91 iServer.RunAsService(EFalse); |
|
92 error = KErrNone; |
|
93 } |
|
94 break; |
|
95 |
|
96 case EStart: |
|
97 { |
|
98 //Starts the BTrace |
|
99 //r= iServer.Start(); |
|
100 if(!iServer.ServerState()) |
|
101 error = iServer.RestartOutputting(); |
|
102 else |
|
103 error = KErrInUse; |
|
104 } |
|
105 break; |
|
106 |
|
107 case EStop: |
|
108 { |
|
109 //Stops the BTrace |
|
110 error = iServer.Stop(); |
|
111 //iServer.UnconfigureCurrentChannel(); |
|
112 } |
|
113 break; |
|
114 |
|
115 case ERestart: |
|
116 { |
|
117 error = iServer.RestartOutputting(); |
|
118 } |
|
119 break; |
|
120 |
|
121 case ESetPrimaryFilter: |
|
122 { |
|
123 //Set filter 1 |
|
124 RArray<TUint32> filterArray; |
|
125 |
|
126 TInt elementsCount = aMessage.Int1(); |
|
127 if(elementsCount > 0) |
|
128 { |
|
129 HBufC8* desData = HBufC8::NewLC(elementsCount*sizeof(TUint8)); |
|
130 TPtr8 readPtr(desData->Des()); |
|
131 aMessage.ReadL(0, readPtr); |
|
132 |
|
133 CArrayFixFlat<TUint8> *array = new (ELeave) CArrayFixFlat<TUint8>(1); |
|
134 CleanupStack::PushL(array); |
|
135 |
|
136 TUint8 tmp=1; |
|
137 InternalizeFromBufL(readPtr, *array, tmp); |
|
138 |
|
139 for(TInt i=0;i<array->Count();++i) |
|
140 { |
|
141 filterArray.Append((TUint32)array->At(i)); |
|
142 } |
|
143 |
|
144 error = iServer.SetActiveFilter(filterArray, EPrimaryFilter); |
|
145 |
|
146 CleanupStack::PopAndDestroy(2,desData); //array, desData |
|
147 filterArray.Close(); |
|
148 } |
|
149 else |
|
150 error = KErrArgument; |
|
151 } |
|
152 break; |
|
153 case ERemovePrimaryFilter: |
|
154 { |
|
155 //remove primaryfilters |
|
156 TInt elementsCount = aMessage.Int1(); |
|
157 if(elementsCount > 0) |
|
158 { |
|
159 RArray<TUint32> filterArray; |
|
160 HBufC8* desData = HBufC8::NewLC(elementsCount*sizeof(TUint8)); |
|
161 TPtr8 readPtr(desData->Des()); |
|
162 aMessage.ReadL(0, readPtr); |
|
163 |
|
164 CArrayFixFlat<TUint8> *array = new (ELeave) CArrayFixFlat<TUint8>(1); |
|
165 CleanupStack::PushL(array); |
|
166 |
|
167 TUint8 tmp=1; |
|
168 InternalizeFromBufL(readPtr, *array, tmp); |
|
169 |
|
170 for(TInt i=0;i<array->Count();++i) |
|
171 { |
|
172 filterArray.Append((TUint32)array->At(i)); |
|
173 } |
|
174 |
|
175 error = iServer.RemoveActiveFilter(filterArray,EPrimaryFilter); |
|
176 |
|
177 CleanupStack::PopAndDestroy(2,desData); //array, desData |
|
178 filterArray.Close(); |
|
179 } |
|
180 else |
|
181 error = KErrArgument; |
|
182 |
|
183 } |
|
184 break; |
|
185 |
|
186 case EGetPrimaryFilters: |
|
187 { |
|
188 //Get primaryfilters |
|
189 RArray<TUint32> listBuffer; |
|
190 error = iServer.GetActiveFilters(listBuffer,EPrimaryFilter); |
|
191 |
|
192 CArrayFixFlat<TUint8> *fixArray = new (ELeave)CArrayFixFlat<TUint8>(1); |
|
193 CleanupStack::PushL(fixArray); |
|
194 |
|
195 for(TInt i=0; i<listBuffer.Count(); ++i) |
|
196 fixArray->AppendL((TUint8)listBuffer[i]); |
|
197 HBufC8* desData = ExternalizeToBufL((const CArrayFix<TUint8>&) *fixArray, sizeof(TUint8)); |
|
198 CleanupStack::PopAndDestroy(); //fixArray |
|
199 |
|
200 aMessage.Write(0,*desData); |
|
201 |
|
202 delete desData; |
|
203 desData = NULL; |
|
204 listBuffer.Close(); |
|
205 } |
|
206 break; |
|
207 case ESetSecondaryFilter: |
|
208 { |
|
209 //Set filter 2 |
|
210 TInt elementsCount = aMessage.Int1(); |
|
211 if(elementsCount > 0) |
|
212 { |
|
213 HBufC8* desData = HBufC8::NewLC(elementsCount*sizeof(TUint32)); |
|
214 TPtr8 readPtr(desData->Des()); |
|
215 aMessage.ReadL(0, readPtr); |
|
216 |
|
217 RArray<TUint32> filterArray; |
|
218 TUint32 tmp=1; |
|
219 InternalizeFromBufL(readPtr, filterArray, tmp); |
|
220 |
|
221 error = iServer.SetActiveFilter(filterArray,ESecondaryFilter); |
|
222 |
|
223 CleanupStack::PopAndDestroy(); //desData |
|
224 filterArray.Close(); |
|
225 } |
|
226 else |
|
227 error = KErrArgument; |
|
228 } |
|
229 break; |
|
230 |
|
231 case ERemoveSecondaryFilter: |
|
232 { |
|
233 //remove secondaryfilters |
|
234 TInt elementsCount = aMessage.Int1(); |
|
235 if(elementsCount > 0) |
|
236 { |
|
237 HBufC8* desData = HBufC8::NewLC(elementsCount*sizeof(TUint32)); |
|
238 TPtr8 readPtr(desData->Des()); |
|
239 aMessage.ReadL(0, readPtr); |
|
240 |
|
241 RArray<TUint32> filterArray; |
|
242 |
|
243 TUint32 tmp=1; |
|
244 InternalizeFromBufL(readPtr, filterArray, tmp); |
|
245 |
|
246 error = iServer.RemoveActiveFilter(filterArray,ESecondaryFilter); |
|
247 |
|
248 CleanupStack::PopAndDestroy(); //desData |
|
249 filterArray.Close(); |
|
250 } |
|
251 else |
|
252 error = KErrArgument; |
|
253 } |
|
254 break; |
|
255 |
|
256 case EGetSecondaryFilters: |
|
257 { |
|
258 //Get secondary filters |
|
259 RArray<TUint32> listBuffer; |
|
260 error=iServer.GetActiveFilters(listBuffer,ESecondaryFilter); |
|
261 |
|
262 HBufC8* desData = ExternalizeToBufL(listBuffer, sizeof(TUint32)); |
|
263 TPtr8 readPtr2(desData->Des()); |
|
264 aMessage.Write(0,readPtr2); |
|
265 |
|
266 delete desData; |
|
267 desData = NULL; |
|
268 listBuffer.Close(); |
|
269 } |
|
270 break; |
|
271 |
|
272 case EEnableSecondaryFiltering: |
|
273 { |
|
274 error = iServer.SetSecondaryFiltering(KEnable); |
|
275 } |
|
276 break; |
|
277 |
|
278 case EDisableSecondaryFiltering: |
|
279 { |
|
280 error = iServer.SetSecondaryFiltering(KDisable); |
|
281 } |
|
282 break; |
|
283 |
|
284 case EGetSecondaryFiltering: |
|
285 { |
|
286 TBool enabled = EFalse; |
|
287 iServer.GetSecondaryFiltering(enabled); |
|
288 SendInteger(aMessage, (TInt)enabled); |
|
289 } |
|
290 break; |
|
291 |
|
292 case ESetActivePlugin: |
|
293 { |
|
294 //Set the active plugin |
|
295 HBufC8* pluginName = NULL; |
|
296 TInt dataSize1 = aMessage.GetDesLength(0); |
|
297 if(dataSize1 > 0) |
|
298 { |
|
299 pluginName = HBufC8::NewLC( dataSize1 ); |
|
300 TPtr8 namePtr(pluginName->Des()); |
|
301 aMessage.ReadL(0,namePtr); |
|
302 error = iServer.SetActiveOutputPlugin(pluginName->Des()); |
|
303 CleanupStack::PopAndDestroy(1); |
|
304 } |
|
305 else |
|
306 error = KErrArgument; |
|
307 } |
|
308 break; |
|
309 |
|
310 case ESetActiveInputPlugin: |
|
311 { |
|
312 //Set the active control plugin |
|
313 HBufC8* pluginName = NULL; |
|
314 TInt dataSize1 = aMessage.GetDesLength(0); |
|
315 if(dataSize1 > 0) |
|
316 { |
|
317 pluginName = HBufC8::NewLC( dataSize1 ); |
|
318 TPtr8 namePtr(pluginName->Des()); |
|
319 aMessage.ReadL(0,namePtr); |
|
320 error = iServer.SetActiveInputPlugin(pluginName->Des()); |
|
321 CleanupStack::PopAndDestroy(1); //pluginName |
|
322 } |
|
323 else |
|
324 error = KErrArgument; |
|
325 } |
|
326 break; |
|
327 |
|
328 case ESetPluginSettings: |
|
329 { |
|
330 //Set the channel settings |
|
331 HBufC8* pluginName = NULL; |
|
332 HBufC8* setting = NULL; |
|
333 |
|
334 RArray<TPtrC8> value; |
|
335 TInt dataSize1 = aMessage.GetDesLength(0); |
|
336 TInt dataSize2 = aMessage.GetDesLength(1); |
|
337 CArrayPtrFlat<HBufC8> *ptrArray = new (ELeave) CArrayPtrFlat<HBufC8>(1); |
|
338 CleanupStack::PushL(ptrArray); |
|
339 |
|
340 if(dataSize1>0 && dataSize2>0) |
|
341 { |
|
342 pluginName = HBufC8::NewLC( dataSize1 ); |
|
343 setting = HBufC8::NewLC( dataSize2 ); |
|
344 TPtr8 data1Ptr(pluginName->Des()); |
|
345 TPtr8 data2Ptr(setting->Des()); |
|
346 |
|
347 aMessage.ReadL(0,data1Ptr); |
|
348 aMessage.ReadL(1,data2Ptr); |
|
349 |
|
350 _LIT8(KSeparator,";"); |
|
351 TInt pos = KErrNone; |
|
352 |
|
353 while(pos != KErrNotFound) |
|
354 { |
|
355 pos = setting->Des().Find(KSeparator); |
|
356 if(pos > 0) |
|
357 { |
|
358 TPtrC8 ptrVal(setting->Des().Left(pos)); |
|
359 HBufC8 *bufDes = HBufC8::NewLC(ptrVal.Length()+8); |
|
360 bufDes->Des().Copy(ptrVal); |
|
361 CleanupStack::Pop(bufDes); |
|
362 ptrArray->AppendL(bufDes); |
|
363 setting->Des().Delete(0,pos+1); |
|
364 } |
|
365 } |
|
366 |
|
367 for(TInt i=0; i<ptrArray->Count(); ++i) |
|
368 value.AppendL(*(ptrArray->At(i))); |
|
369 error = iServer.SetPluginSettings(pluginName->Des(), value); |
|
370 CleanupStack::PopAndDestroy(2); |
|
371 } |
|
372 else |
|
373 error = KErrArgument; |
|
374 |
|
375 CleanupStack::PopAndDestroy(ptrArray); |
|
376 } |
|
377 break; |
|
378 |
|
379 case ERemovePluginSettings: |
|
380 { |
|
381 TInt dataSize = aMessage.GetDesLength(0); |
|
382 TBuf8<KMaxPluginName> pluginName; |
|
383 if (dataSize > 0) |
|
384 { |
|
385 aMessage.ReadL(0, pluginName); |
|
386 error = iServer.RemovePluginSettingsL(pluginName); |
|
387 } |
|
388 else |
|
389 error = KErrArgument; |
|
390 } |
|
391 break; |
|
392 |
|
393 case EGetPluginSettings: |
|
394 { |
|
395 TInt dataSize1 = aMessage.GetDesLength(0); |
|
396 TBuf8<128> mediaName; |
|
397 |
|
398 if(dataSize1 > 0) |
|
399 { |
|
400 aMessage.ReadL(0, mediaName); |
|
401 RArray<TPtrC8> tmpArray; |
|
402 error = iServer.GetOptionsSettingsL(mediaName,tmpArray); |
|
403 |
|
404 //<rewrite array and add separator to each record> |
|
405 _LIT8(KFormatString,"%S;");//';' is a separator |
|
406 RArray<TPtrC8> tmpArray2; |
|
407 //count total_length + separators |
|
408 TInt length = 1; |
|
409 TInt i=0; |
|
410 for(i=0; i<tmpArray.Count(); ++i) |
|
411 length+=tmpArray[i].Length()+1; |
|
412 |
|
413 HBufC8* b = HBufC8::NewLC(length); |
|
414 for(i=0; i<tmpArray.Count(); ++i) |
|
415 b->Des().AppendFormat(KFormatString, &tmpArray[i]); |
|
416 //</rewrite array and add separator to each record> |
|
417 |
|
418 aMessage.Write(1,*b); |
|
419 CleanupStack::PopAndDestroy(); // b |
|
420 } |
|
421 else |
|
422 error = KErrArgument; |
|
423 } |
|
424 break; |
|
425 |
|
426 case EGetInstalledPlugins: |
|
427 { |
|
428 //Get the installed plugins |
|
429 RArray<TPtrC8> tmpArray; |
|
430 iServer.GetInstalledOutputPlugins(tmpArray); |
|
431 |
|
432 //<rewrite array and add separator to each record> |
|
433 _LIT8(KFormatString,"%S;");//';' is a separator |
|
434 RArray<TPtrC8> tmpArray2; |
|
435 //count total_length + separators |
|
436 TInt length = 1; |
|
437 TInt i=0; |
|
438 for(i=0; i<tmpArray.Count(); ++i) |
|
439 length+=tmpArray[i].Length()+1; |
|
440 |
|
441 HBufC8* b = HBufC8::NewLC(length); |
|
442 for(i=0; i<tmpArray.Count(); ++i) |
|
443 b->Des().AppendFormat(KFormatString, &tmpArray[i]); |
|
444 //</rewrite array and add separator to each record> |
|
445 |
|
446 aMessage.Write(0,*b); |
|
447 CleanupStack::PopAndDestroy(); // b |
|
448 } |
|
449 break; |
|
450 |
|
451 case EGetInputPlugins: |
|
452 { |
|
453 //Get the installed plugins |
|
454 RArray<TPtrC8> tmpArray; |
|
455 error = iServer.GetInstalledInputPlugins(tmpArray); |
|
456 if(!error) |
|
457 { |
|
458 //<rewrite array and add separator to each record> |
|
459 _LIT8(KFormatString,"%S;");//';' is a separator |
|
460 //count total_length + separators |
|
461 TInt length = 1; |
|
462 TInt i=0; |
|
463 for(i=0; i<tmpArray.Count(); ++i) |
|
464 length+=tmpArray[i].Length()+1; |
|
465 |
|
466 HBufC8* b = HBufC8::NewLC(length); |
|
467 for(i=0; i<tmpArray.Count(); ++i) |
|
468 b->Des().AppendFormat(KFormatString, &tmpArray[i]); |
|
469 //</rewrite array and add separator to each record> |
|
470 |
|
471 aMessage.Write(0,*b); |
|
472 CleanupStack::PopAndDestroy(); // b |
|
473 } |
|
474 } |
|
475 break; |
|
476 |
|
477 case EGetActivePlugin: |
|
478 { |
|
479 //Reads the active plugin |
|
480 RArray<TPtrC8> tmpArray; |
|
481 error = iServer.GetActiveOutputPlugin(tmpArray); |
|
482 if(!error) |
|
483 { |
|
484 //<rewrite array and add separator to each record> |
|
485 _LIT8(KFormatString,"%S;");//';' is a separator |
|
486 RArray<TPtrC8> tmpArray2; |
|
487 //count total_length + separators |
|
488 TInt length = 1; |
|
489 TInt i=0; |
|
490 for(i=0; i<tmpArray.Count(); ++i) |
|
491 length+=tmpArray[i].Length()+1; |
|
492 |
|
493 HBufC8* b = HBufC8::NewLC(length); |
|
494 for(i=0; i<tmpArray.Count(); ++i) |
|
495 b->Des().AppendFormat(KFormatString, &tmpArray[i]); |
|
496 //</rewrite array and add separator to each record> |
|
497 |
|
498 aMessage.Write(0,*b); |
|
499 CleanupStack::PopAndDestroy(); // b |
|
500 } |
|
501 } |
|
502 break; |
|
503 |
|
504 case EGetActiveInputPlugin: |
|
505 { |
|
506 RArray<TPtrC8> tmpArray; |
|
507 error = iServer.GetActiveInputPlugin(tmpArray); |
|
508 if(!error) |
|
509 { |
|
510 if(tmpArray.Count() == 0) |
|
511 error = KErrNotFound; |
|
512 //<rewrite array and add separator to each record> |
|
513 _LIT8(KFormatString,"%S;");//';' is a separator |
|
514 RArray<TPtrC8> tmpArray2; |
|
515 //count total_length + separators |
|
516 TInt length = 1; |
|
517 TInt i=0; |
|
518 for(i=0; i<tmpArray.Count(); ++i) |
|
519 length+=tmpArray[i].Length()+1; |
|
520 |
|
521 HBufC8* b = HBufC8::NewLC(length); |
|
522 for(i=0; i<tmpArray.Count(); ++i) |
|
523 b->Des().AppendFormat(KFormatString, &tmpArray[i]); |
|
524 //</rewrite array and add separator to each record> |
|
525 |
|
526 aMessage.Write(0,*b); |
|
527 CleanupStack::PopAndDestroy(); // b |
|
528 } |
|
529 } |
|
530 break; |
|
531 |
|
532 case EDeactivateInputPlugin: |
|
533 { |
|
534 HBufC8* pluginName = NULL; |
|
535 TInt dataSize1 = aMessage.GetDesLength(0); |
|
536 if(dataSize1 > 0) |
|
537 { |
|
538 pluginName = HBufC8::NewLC( dataSize1 ); |
|
539 TPtr8 namePtr(pluginName->Des()); |
|
540 aMessage.ReadL(0,namePtr); |
|
541 error = iServer.DeActivateInputPlugin(pluginName->Des()); |
|
542 CleanupStack::PopAndDestroy(); //pluginName |
|
543 } |
|
544 } |
|
545 break; |
|
546 case EResizeTraceBuffer: |
|
547 { |
|
548 //Resize buffer size |
|
549 TInt bufferSize = aMessage.Int0(); |
|
550 error = iServer.SetBufferSize(bufferSize); |
|
551 } |
|
552 break; |
|
553 |
|
554 case EGetTraceBufferSize: |
|
555 { |
|
556 //Get buffer size |
|
557 TInt bufferSize = 0; |
|
558 error = iServer.GetBufandDataNotifyValuesL(KBuffer,bufferSize); |
|
559 SendInteger(aMessage, bufferSize); |
|
560 } |
|
561 break; |
|
562 |
|
563 case ESetBufferMode: |
|
564 { |
|
565 TInt bufferMode = aMessage.Int0(); |
|
566 if(bufferMode == ECircularBuffer) |
|
567 error = iServer.SetBufferMode(KCircular); |
|
568 else if(bufferMode == EStraightBuffer) |
|
569 error = iServer.SetBufferMode(KStraight); |
|
570 else |
|
571 error = KErrArgument; |
|
572 } |
|
573 break; |
|
574 |
|
575 case EGetBufferMode: |
|
576 { |
|
577 //Get buffer size |
|
578 TInt bufferMode = 3; |
|
579 error = iServer.GetBufandDataNotifyValuesL(KBufferMode,bufferMode); |
|
580 SendInteger(aMessage, bufferMode); |
|
581 } |
|
582 break; |
|
583 |
|
584 case ESetDataNotificationSize: |
|
585 { |
|
586 //Set data notification size |
|
587 TInt dataNotification = aMessage.Int0(); |
|
588 error = iServer.SetDataNotificationSize(dataNotification); |
|
589 } |
|
590 break; |
|
591 |
|
592 case EGetDataNotificationSize: |
|
593 { |
|
594 //Get Data Notification size |
|
595 TInt dataNotification = 0; |
|
596 error = iServer.GetBufandDataNotifyValuesL(KDataNotification,dataNotification); |
|
597 SendInteger(aMessage, dataNotification); |
|
598 } |
|
599 break; |
|
600 |
|
601 default: |
|
602 { |
|
603 error = KErrArgument; |
|
604 } |
|
605 break; |
|
606 } |
|
607 aMessage.Complete(error); |
|
608 } |
|
609 |
|
610 void CULoggerSession::SendInteger(const RMessage2& aMessage, TUint32 aInt) |
|
611 { |
|
612 HBufC8* size = HBufC8::NewLC(32); |
|
613 size->Des().Num(aInt); |
|
614 TPtr8 ptr(size->Des()); |
|
615 aMessage.Write(0,ptr); |
|
616 CleanupStack::PopAndDestroy(); |
|
617 } |
|
618 }//namespace |