|
1 // Copyright (c) 2001-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 "blogger.h" |
|
18 |
|
19 #ifndef BLOGGING__ |
|
20 EXPORT_C TAny* CBlogger::GetFloggerInfo() |
|
21 { |
|
22 return 0; |
|
23 } |
|
24 #endif |
|
25 |
|
26 #ifdef BLOGGING__ |
|
27 #include "rfcommmuxer.h" |
|
28 #include "rfcommframe.h" |
|
29 |
|
30 |
|
31 CBlogger::~CBlogger() |
|
32 { |
|
33 delete ifilename; |
|
34 ifile.Close (); |
|
35 ifileserv.Close (); |
|
36 } |
|
37 |
|
38 CBlogger::CBlogger() : |
|
39 iOutputWindowSize(KBlogOutputWindowDefault), |
|
40 iVerbosityLevel(KBlogVerbosityAllLevels), |
|
41 iLayersToLogMask(KBlogAllLayers), |
|
42 iLoggingMask(KBlogTypeLogAllMask) |
|
43 { |
|
44 } |
|
45 |
|
46 CBlogger* CBlogger::NewL() |
|
47 { |
|
48 CBlogger* self = new (ELeave)CBlogger(); |
|
49 self->ConstructL(); |
|
50 return self; |
|
51 } |
|
52 |
|
53 void CBlogger::ConstructL() |
|
54 { |
|
55 User::LeaveIfError(ifileserv.Connect()); |
|
56 MakefilenameL(_L("Blog.txt")); |
|
57 iFileExists = EFalse; |
|
58 } |
|
59 |
|
60 TInt CBlogger::LoggingMask(TInt aLayer, TInt aVerbosity) const |
|
61 { |
|
62 if(aLayer&iLayersToLogMask) |
|
63 { |
|
64 if(aVerbosity<=iVerbosityLevel) |
|
65 { |
|
66 return iLoggingMask; |
|
67 } |
|
68 } |
|
69 //else |
|
70 return 0; |
|
71 } |
|
72 |
|
73 CBloggette* CBlogger::GetLayerBloggette(TInt aLayer) |
|
74 { |
|
75 switch(aLayer) |
|
76 { |
|
77 case KBlogLayerLinkLayer : |
|
78 { |
|
79 return iLLBloggette; |
|
80 } |
|
81 case KBlogLayerL2CAP : |
|
82 { |
|
83 return iL2Bloggette; |
|
84 } |
|
85 case KBlogLayerRFComm : |
|
86 { |
|
87 return iRFBloggette; |
|
88 } |
|
89 default: |
|
90 { |
|
91 Panic(EBloggerLayerRequestedOutOfRange); |
|
92 return NULL; //for compiler to shut up |
|
93 } |
|
94 }; |
|
95 } |
|
96 |
|
97 void CBlogger::Register(CBloggette* aLayerBloggette) |
|
98 /** |
|
99 only one per layer please |
|
100 */ |
|
101 { |
|
102 TUint layer = aLayerBloggette->Layer(); |
|
103 switch(layer) |
|
104 { |
|
105 case KBlogLayerLinkLayer: |
|
106 { |
|
107 __ASSERT_DEBUG(iLLBloggette==NULL,Panic(EBloggerLayerBloggetteAlreadyRegistered)); |
|
108 iLLBloggette=aLayerBloggette; |
|
109 break; |
|
110 } |
|
111 case KBlogLayerL2CAP : |
|
112 { |
|
113 __ASSERT_DEBUG(iL2Bloggette==NULL,Panic(EBloggerLayerBloggetteAlreadyRegistered)); |
|
114 iL2Bloggette=aLayerBloggette; |
|
115 break; |
|
116 } |
|
117 case KBlogLayerRFComm : |
|
118 { |
|
119 __ASSERT_DEBUG(iRFBloggette==NULL,Panic(EBloggerLayerBloggetteAlreadyRegistered)); |
|
120 iRFBloggette=aLayerBloggette; |
|
121 break; |
|
122 } |
|
123 default: |
|
124 { |
|
125 Panic(EBloggerLayerRegistrationOutOfRange); |
|
126 } |
|
127 }; |
|
128 } |
|
129 |
|
130 |
|
131 TInt CBlogger::UpdateLoggingSettings(TUint aOptionType,const TDesC8& aOption) |
|
132 { |
|
133 #define CHECK_OPT_IS_(type) {if (aOption.Size() != sizeof(type)) \ |
|
134 return KErrArgument;} |
|
135 switch(aOptionType) |
|
136 { |
|
137 case KBloggerSetLayers: |
|
138 { |
|
139 CHECK_OPT_IS_(TInt); |
|
140 iLayersToLogMask= *(TUint*)aOption.Ptr(); |
|
141 break; |
|
142 } |
|
143 case KBloggerSetVerbosity: |
|
144 { |
|
145 CHECK_OPT_IS_(TInt); |
|
146 TInt verbosity=*(TUint*)aOption.Ptr(); |
|
147 if((verbosity<KBlogVerbosityOff)||(verbosity>KBlogVerbosityAllLevels)) |
|
148 { |
|
149 return KErrArgument; |
|
150 } |
|
151 iVerbosityLevel= verbosity; |
|
152 break; |
|
153 } |
|
154 case KBloggerSetLoggingMask: |
|
155 { |
|
156 CHECK_OPT_IS_(TInt); |
|
157 iLoggingMask= *(TInt*)aOption.Ptr(); |
|
158 break; |
|
159 } |
|
160 case KBloggerSetMedium: |
|
161 { |
|
162 CHECK_OPT_IS_(TInt); |
|
163 TInt mediumType=*(TUint*)aOption.Ptr(); |
|
164 if((mediumType!=KBlogOutputTypeIsFlogger)||(mediumType!=KBlogOutputTypeIsRDebug)) |
|
165 {//otherwise we will panic when we try to output |
|
166 return KErrArgument; |
|
167 } |
|
168 iMediumType= mediumType; |
|
169 break; |
|
170 } |
|
171 case KBloggerSetTestCaseName: |
|
172 { |
|
173 TInt length=Min(KRDBMaxLit,aOption.Length()); |
|
174 iTestCaseLit.Copy(((TDesC16*)aOption.Ptr())->Left(length)); |
|
175 BlogTestCase(iTestCaseLit); |
|
176 break; |
|
177 } |
|
178 case KBloggerSetOutputWindow: |
|
179 { |
|
180 CHECK_OPT_IS_(TInt); |
|
181 TInt windowSize=*(TUint*)aOption.Ptr(); |
|
182 if((windowSize<1)||(windowSize>KRDBMaxLit)) |
|
183 { |
|
184 return KErrArgument; |
|
185 } |
|
186 iOutputWindowSize=windowSize; |
|
187 break; |
|
188 } |
|
189 case KBloggerSetTestCaseResult: |
|
190 { |
|
191 CHECK_OPT_IS_(TInt); |
|
192 TInt tcResult=*(TUint*)aOption.Ptr(); |
|
193 if(tcResult>KBlogTestCaseResultUpperNo) |
|
194 { |
|
195 return KErrArgument; |
|
196 } |
|
197 BlogTestCaseResult(tcResult); |
|
198 break; |
|
199 } |
|
200 case KBloggerSetTesterMessage: |
|
201 { |
|
202 BlogTesterMessage(*(TDesC16*)aOption.Ptr()); |
|
203 break; |
|
204 } |
|
205 case KBloggerSetAllOptions: |
|
206 { |
|
207 CHECK_OPT_IS_(TBlogSettings); // we care about the data pckgd not he pckg itself |
|
208 TBlogSettingsPckg theSettings; |
|
209 theSettings.Copy(aOption); |
|
210 |
|
211 TInt verbosity=(theSettings()).iVerbosity; |
|
212 if((verbosity<KBlogVerbosityOff)||(verbosity>KBlogVerbosityAllLevels)) |
|
213 { |
|
214 return KErrArgument; |
|
215 } |
|
216 |
|
217 TInt mediumType=(theSettings()).iMediumToLog; |
|
218 if((mediumType!=KBlogOutputTypeIsFlogger)&&(mediumType!=KBlogOutputTypeIsRDebug)) |
|
219 {//otherwise we will panic when we try to output |
|
220 return KErrArgument; |
|
221 } |
|
222 |
|
223 TInt windowSize=(theSettings()).iOutputWindowSize; |
|
224 if((windowSize<1)||(windowSize>KRDBMaxLit)) |
|
225 { |
|
226 return KErrArgument; |
|
227 } |
|
228 |
|
229 iLayersToLogMask =(theSettings()).iLayersToLog; |
|
230 iVerbosityLevel =verbosity; |
|
231 iLoggingMask =(theSettings()).iLoggingMask; |
|
232 iMediumType =mediumType; |
|
233 iOutputWindowSize =windowSize; |
|
234 iTestCaseLit =(theSettings()).iTestCaseLit; |
|
235 |
|
236 if (iTestCaseLit!=KNullDesC) |
|
237 BlogTestCase(iTestCaseLit); |
|
238 |
|
239 break; |
|
240 } |
|
241 default: |
|
242 { |
|
243 return KErrArgument; |
|
244 } |
|
245 }; |
|
246 return KErrNone; |
|
247 } |
|
248 |
|
249 |
|
250 void CBlogger::Panic(TBloggerPanic aPanic) |
|
251 { |
|
252 User::Panic(_L("BLogger Panic"),aPanic); |
|
253 } |
|
254 |
|
255 void CBlogger::Blog(const TDesC& aMessage,TInt aFrameWindow) |
|
256 /** |
|
257 Formats the message with a date and time preamble and blogs it. |
|
258 But a limitation is that although it breaks the message in parts of |
|
259 aFrameWindow size characters, it cannot accept amessage which is longer |
|
260 than KBlogMessageMaxLitLength |
|
261 */ |
|
262 { |
|
263 __ASSERT_DEBUG((KBlogMessageMaxLitLength-KBlogDateTimeLitLength)>=aMessage.Length(),Panic(EBloggerMessageLengthTooLong)); |
|
264 TBuf<KBlogMessageMaxLitLength> logMessage; |
|
265 DoDateTimeFormat(logMessage); |
|
266 logMessage.Append(aMessage); |
|
267 DoBlog(logMessage,aFrameWindow); |
|
268 } |
|
269 |
|
270 void CBlogger::Blog(const TDesC& aMessage) |
|
271 /** |
|
272 Formats the message with a date and time preamble and blogs it. |
|
273 But a limitation is that it cannot accept a message which is longer |
|
274 than KBlogMessageMaxLitLength. |
|
275 */ |
|
276 { |
|
277 Blog(aMessage,iOutputWindowSize); |
|
278 } |
|
279 |
|
280 |
|
281 void CBlogger::BlogTestCase(TDesC& aTestCaseName) |
|
282 { |
|
283 // output a preamble indicating new test case (or a repeat of the previous one:-) |
|
284 // include time date and a Lit for the preamble |
|
285 __ASSERT_DEBUG(KBlogTestCaseMaxLitLength>=KBlogDateTimeLitLength,Panic(EBloggerDescriptorLengthWasShorter)); |
|
286 TBuf<KBlogTestCaseMaxLitLength> testCaseString; |
|
287 DoDateTimeFormat(testCaseString); // no need for ret val check here |
|
288 testCaseString.Append(KBlogTestCaseLit); |
|
289 testCaseString.Append(aTestCaseName); |
|
290 DoBlog(testCaseString,iOutputWindowSize); |
|
291 } |
|
292 |
|
293 void CBlogger::BlogTesterMessage(TDesC& aTesterMessage) |
|
294 /** |
|
295 A Test App can output a string in the Blogger logs through this method. |
|
296 To do this the test app should issue a SetOpt of type KBloggerSetTesterMessage |
|
297 and pass a packaged TDesC16. |
|
298 */ |
|
299 { |
|
300 TBuf<KBlogTesterMessageInfoMaxLitLength> tstInfoString; |
|
301 DoDateTimeFormat(tstInfoString); |
|
302 tstInfoString.Append(KBlogTesterMessageInfoLit); |
|
303 tstInfoString.Append(aTesterMessage); |
|
304 DoBlog(tstInfoString,iOutputWindowSize); |
|
305 // DoBlog(aTesterMessage,iOutputWindowSize); |
|
306 } |
|
307 |
|
308 void CBlogger::BlogTestCaseResult(TInt aTestCaseResult) |
|
309 { |
|
310 if(!(iTestCaseLit.Length())) //in the case the TC Lit was not setup |
|
311 { |
|
312 return; |
|
313 } |
|
314 |
|
315 TBuf<KBlogTestCaseResultMaxLitLength> tcMessage; |
|
316 __ASSERT_DEBUG(KBlogTestCaseResultMaxLitLength>KBlogDateTimeLitLength,Panic(EBloggerDescriptorLengthWasShorter)); |
|
317 DoDateTimeFormat(tcMessage); |
|
318 |
|
319 switch(aTestCaseResult) |
|
320 { |
|
321 case KBlogTestCaseResultPassed: |
|
322 { |
|
323 tcMessage.Append(KBlogTestCaseResultLitPass); |
|
324 break; |
|
325 } |
|
326 case KBlogTestCaseResultFailed: |
|
327 { |
|
328 tcMessage.Append(KBlogTestCaseResultLitFailed); |
|
329 break; |
|
330 } |
|
331 case KBlogTestCaseResultInconclusive: |
|
332 { |
|
333 tcMessage.Append(KBlogTestCaseResultLitInconclusive); |
|
334 break; |
|
335 } |
|
336 case KBlogTestCaseResultSkipped: |
|
337 { |
|
338 tcMessage.Append(KBlogTestCaseResultLitSkipped); |
|
339 break; |
|
340 } |
|
341 default: |
|
342 { |
|
343 // check your bounds checking in the handler |
|
344 Panic(EBloggerTestCaseResultIsBogus); |
|
345 } |
|
346 }; |
|
347 |
|
348 tcMessage.Append(iTestCaseLit); |
|
349 DoBlog(tcMessage,iOutputWindowSize); |
|
350 } |
|
351 |
|
352 void CBlogger::DoBlog(const TDesC& aMessage,TInt aFrameWindow) |
|
353 { |
|
354 TInt msgLength=aMessage.Length(); |
|
355 if(!msgLength) |
|
356 {return;} |
|
357 |
|
358 TInt min=Min(KRDBMaxLit,aMessage.Length()); |
|
359 TInt len=Min(min,aFrameWindow); |
|
360 |
|
361 TInt frames=msgLength/len; |
|
362 TInt lastFrameSize=msgLength%len;// i.e the remainder |
|
363 |
|
364 TInt position=0; |
|
365 for(TInt f=0;f<frames;f++,position=f*len) |
|
366 { |
|
367 DoOutputToResourceL(aMessage.Mid(position,len)); //Qualified |
|
368 } |
|
369 // log last frame |
|
370 if(lastFrameSize) |
|
371 { |
|
372 DoOutputToResourceL(aMessage.Mid(position)); //Qualified |
|
373 } |
|
374 } |
|
375 |
|
376 TInt CBlogger::DoDateTimeFormat(TDes& aDesToPrepend) |
|
377 { |
|
378 |
|
379 //FIXME:if the options are for time critical logging then spare the date and time |
|
380 |
|
381 if(aDesToPrepend.MaxLength()<KBlogDateTimeLitLength) |
|
382 { |
|
383 return KErrArgument; |
|
384 } |
|
385 TBuf<KBlogDateTimeLitLength> timeLit; // abit more bytes than needed |
|
386 TTime time; |
|
387 time.HomeTime(); |
|
388 TRAPD(errD,time.FormatL(aDesToPrepend,KBlogDateFormat)); |
|
389 if(errD) |
|
390 { |
|
391 //since we OOMed |
|
392 aDesToPrepend.Append(KBlogBlankDate); |
|
393 } |
|
394 TRAPD(errT,time.FormatL(timeLit,KBlogTimeFormat)); |
|
395 if (errT) |
|
396 { |
|
397 timeLit.Copy(KBlogBlankTime); |
|
398 } |
|
399 |
|
400 aDesToPrepend.Append(timeLit); |
|
401 |
|
402 // although OOM may have happened, but the point is to get the log out quickly |
|
403 return KErrNone; |
|
404 } |
|
405 |
|
406 |
|
407 void CBlogger::HexDump(const TDesC& aDescription,const TDesC8& aHexFrame, TInt aFrameWindow) |
|
408 /** |
|
409 It will trim the sDescription to fit in the aFrameWindow size. |
|
410 It also log the HexFrame in chunks of size=aFrameWindow. |
|
411 */ |
|
412 { |
|
413 //255 is the max RDebug::Print size |
|
414 |
|
415 DoBlog(aDescription,aFrameWindow); |
|
416 |
|
417 TInt bufferSize=aHexFrame.Length(); |
|
418 if(!bufferSize) |
|
419 {return;} |
|
420 |
|
421 TInt frames=bufferSize/(aFrameWindow/5); // 5 is the size of the formating lit |
|
422 TInt lastFrameSize=(bufferSize*5)%aFrameWindow;// i.e the remainder |
|
423 |
|
424 TInt i=0; |
|
425 TBuf<KRDBMaxLit> outBuf; |
|
426 |
|
427 for ( TInt f=0;f<frames;f++) |
|
428 { |
|
429 outBuf.Zero(); |
|
430 for ( i = 0; i < aFrameWindow/5; ++i) |
|
431 {// 5 is the size of the formating lit :-) |
|
432 outBuf.AppendFormat(_L("0x%02x "),aHexFrame[(f*aFrameWindow/5)+i]); |
|
433 } |
|
434 DoOutputToResourceL(outBuf); //Qualified |
|
435 } |
|
436 |
|
437 // log last frame |
|
438 if(lastFrameSize) |
|
439 { |
|
440 outBuf.Zero(); |
|
441 for(i=(frames*aFrameWindow/5);i<bufferSize;i++) |
|
442 { |
|
443 outBuf.AppendFormat(_L("0x%02x "),aHexFrame[i]); |
|
444 } |
|
445 DoOutputToResourceL(outBuf); //Qualified |
|
446 } |
|
447 } |
|
448 void CBlogger::CreateBlogFileL() |
|
449 { |
|
450 //User::LeaveIfError(ifileserv.Connect()); |
|
451 User::LeaveIfError(ifile.Replace(ifileserv, *ifilename, EFileStream|EFileWrite)); |
|
452 } |
|
453 |
|
454 void CBlogger::DoFileL() |
|
455 { |
|
456 /* |
|
457 if the file exists and is open then write to it |
|
458 otherwise create and open it |
|
459 */ |
|
460 TInt ret; |
|
461 ret=ifile.Open(ifileserv,*ifilename,EFileStream|EFileWrite); |
|
462 if (ret==KErrNotFound) // file does not exist - create it |
|
463 { |
|
464 CreateBlogFileL(); |
|
465 } |
|
466 iFileExists = ETrue; |
|
467 } |
|
468 |
|
469 void CBlogger::MakefilenameL(const TDesC &aFileName) |
|
470 { |
|
471 //Connect to Fileserver |
|
472 User::LeaveIfNull(ifilename=aFileName.AllocL()); |
|
473 TInt err = ifileserv.MkDirAll(*ifilename); |
|
474 if ( (err != KErrAlreadyExists) && (err != KErrNone)) |
|
475 User::Leave(err); |
|
476 } |
|
477 |
|
478 void CBlogger::DoOutputToResourceL(const TDesC& aMessage) |
|
479 { |
|
480 // It is reasonable to assume we only gonna have 2 types of output resource |
|
481 // either COM:0 or File Flogging thus do the sipmlest thing here |
|
482 |
|
483 //iMediumType=1; //need this to be 1 for output to a file. |
|
484 |
|
485 switch(iMediumType) //yes I like dynamic binding myself but we only gonna have 2 isn't it ? |
|
486 { |
|
487 case KBlogOutputTypeIsRDebug: |
|
488 { |
|
489 RDebug::Print(_L("%S"),&aMessage); |
|
490 break; |
|
491 } |
|
492 case KBlogOutputTypeIsFlogger: |
|
493 { |
|
494 //User::LeaveIfError(ifileserv.Connect()); |
|
495 //Makefilename(_L("Blog.txt")); |
|
496 if(!iFileExists) |
|
497 { |
|
498 DoFileL(); |
|
499 } |
|
500 TBuf8<256> buf8; |
|
501 buf8.Copy(aMessage); |
|
502 User::LeaveIfError(ifile.Write(buf8)); |
|
503 User::LeaveIfError(ifile.Write(_L8("\r\n"))); |
|
504 User::LeaveIfError(ifile.Flush()); |
|
505 break; |
|
506 } |
|
507 default: |
|
508 { |
|
509 Panic(EBloggerResourceTypeIsBogus); |
|
510 } |
|
511 }; |
|
512 |
|
513 } |
|
514 |
|
515 void CBlogger::StoreFloggerInfo(TAny* aLogInfo) |
|
516 /** |
|
517 Store the pointer from the HCI's TLS that indicates to which file the floffer should log. |
|
518 This is necessary in order to be able (at will) to accomodate both Flogger |
|
519 and Blogger functionality in the stack. |
|
520 |
|
521 This method will only be used from the LinkMgr when Flogging is enabled. |
|
522 */ |
|
523 { |
|
524 iFloggerInfo=aLogInfo; |
|
525 } |
|
526 |
|
527 |
|
528 EXPORT_C TAny* CBlogger::GetFloggerInfo() |
|
529 { |
|
530 return iFloggerInfo; |
|
531 } |
|
532 |
|
533 void CBlogger::DoBloggerTests() |
|
534 { |
|
535 #ifdef BLOGGING__SELF_TESTS__ |
|
536 LLQBLOG(1,Log(_L(" >>>>>>>>>>>>>>>>>> This is %d <<<<<<<<<<<<<<<<"),1)); |
|
537 LLQBLOG(1,Log(_L("123456789a123456789b123456789c123456789d123456789e123456789f123456789g123456789h123456789i"))); |
|
538 LLQBLOG(1,Log(_L(" a string %S and a number %d"),&_L("Andy"), 1)); |
|
539 LLQBLOG(1,HexDump(_L("A hex dump"),_L8(" read hex mate?"),10)); |
|
540 LLQBLOG(1,HexDump(_L("A long hex dump"),_L8("123456789a123456789b123456789c123456789d123456789e123456789f123456789g"),80)); |
|
541 |
|
542 // Testing test case Lit setup |
|
543 TBuf<KRDBMaxLit> tcName(_L("My First Test Case ,NO1")); |
|
544 TPckgBuf<TBlogTestCaseLit> tcNamePckg(tcName); |
|
545 UpdateLoggingSettings(KBloggerSetTestCaseName,tcNamePckg); |
|
546 |
|
547 // Testing Test Case Results |
|
548 TPckgBuf<TInt> tcResult(KBlogTestCaseResultPassed); |
|
549 UpdateLoggingSettings(KBloggerSetTestCaseResult,tcResult); |
|
550 |
|
551 //Testing Test app messages |
|
552 TBuf<KRDBMaxLit> tstMsg(_L("This is message from the tester saying it is doing a test")); |
|
553 TPckgBuf<TBlogTestCaseLit> tstMsgPckg(tstMsg); |
|
554 UpdateLoggingSettings(KBloggerSetTesterMessage,tstMsgPckg); |
|
555 #endif |
|
556 } |
|
557 |
|
558 // Blogettes |
|
559 |
|
560 CBloggette::~CBloggette() |
|
561 { |
|
562 } |
|
563 |
|
564 CBloggette::CBloggette(CBlogger* aProvider, TInt aLayer) : |
|
565 iLayer(aLayer), |
|
566 iBlogger(aProvider) |
|
567 { |
|
568 } |
|
569 |
|
570 void CBloggette::Log(TRefByValue<const TDesC> aFormatingLit, ...) |
|
571 /** |
|
572 The maximum length of the allowed string is 255. |
|
573 */ |
|
574 { |
|
575 VA_LIST tmpArgList; |
|
576 VA_START(tmpArgList,aFormatingLit); |
|
577 TBuf<KRDBMaxLit> blogBuf; |
|
578 blogBuf.Zero(); |
|
579 blogBuf.AppendFormatList(aFormatingLit, tmpArgList); //FIXME overflow handler possibly ? |
|
580 iBlogger->Blog(blogBuf); |
|
581 VA_END(tmpArgList); |
|
582 } |
|
583 |
|
584 |
|
585 void CBloggette::HexDump(TRefByValue<const TDesC> aDescription,const TDesC8& aHexFrame, TInt aFrameWindow) |
|
586 { |
|
587 iBlogger->HexDump(aDescription,aHexFrame,aFrameWindow); |
|
588 } |
|
589 |
|
590 TInt CBloggette::Layer() const |
|
591 { |
|
592 return iLayer; |
|
593 } |
|
594 |
|
595 |
|
596 // Link Layer Bloggette |
|
597 |
|
598 CLLBloggette* CLLBloggette::NewL(CBlogger* aProvider, TInt aLayer) |
|
599 { |
|
600 CLLBloggette* self = new (ELeave)CLLBloggette(aProvider,aLayer); |
|
601 self->iBlogger->Register(self); |
|
602 return self; |
|
603 } |
|
604 |
|
605 CLLBloggette::CLLBloggette(CBlogger* aProvider, TInt aLayer) |
|
606 : CBloggette(aProvider,aLayer) |
|
607 { |
|
608 } |
|
609 |
|
610 CLLBloggette::~CLLBloggette() |
|
611 { |
|
612 } |
|
613 |
|
614 TDesC CLLBloggette::NameDes() |
|
615 { |
|
616 return _L("LL Dummy Bloggette"); |
|
617 } |
|
618 |
|
619 // L2CAP Bloggette |
|
620 |
|
621 CL2Bloggette* CL2Bloggette::NewL(CBlogger* aProvider, TInt aLayer) |
|
622 { |
|
623 CL2Bloggette* self = new (ELeave)CL2Bloggette(aProvider,aLayer); |
|
624 self->iBlogger->Register(self); |
|
625 return self; |
|
626 } |
|
627 |
|
628 CL2Bloggette::CL2Bloggette(CBlogger* aProvider, TInt aLayer) |
|
629 : CBloggette(aProvider,aLayer) |
|
630 { |
|
631 } |
|
632 |
|
633 CL2Bloggette::~CL2Bloggette() |
|
634 { |
|
635 } |
|
636 |
|
637 TDesC CL2Bloggette::NameDes() |
|
638 { |
|
639 return _L("L2CAP Dummy Bloggette"); |
|
640 } |
|
641 |
|
642 // RFCOMM Bloggette |
|
643 |
|
644 CRFBloggette* CRFBloggette::NewL(CBlogger* aProvider, TInt aLayer) |
|
645 { |
|
646 CRFBloggette* self = new (ELeave)CRFBloggette(aProvider,aLayer); |
|
647 self->iBlogger->Register(self); |
|
648 return self; |
|
649 } |
|
650 |
|
651 CRFBloggette::CRFBloggette(CBlogger* aProvider, TInt aLayer) |
|
652 : CBloggette(aProvider,aLayer) |
|
653 { |
|
654 } |
|
655 |
|
656 CRFBloggette::~CRFBloggette() |
|
657 { |
|
658 } |
|
659 |
|
660 TDesC CRFBloggette::NameDes() |
|
661 { |
|
662 return _L("RFComm Dummy Bloggette"); |
|
663 } |
|
664 |
|
665 void CRFBloggette::Timeout(/*CRfcommSAP* aSAP, CRfcommMuxer* aMux,*/ CRfcommFrame* aFrm ) |
|
666 { |
|
667 TUint8 ctrlfield = aFrm->Ctrl(); |
|
668 |
|
669 switch((ctrlfield&~KPollFinalBitmask)) |
|
670 { |
|
671 case KSABMCtrlField: |
|
672 Log(KBlogTimeout); |
|
673 Log(KBlogSABM); |
|
674 break; |
|
675 case KDISCCtrlField: |
|
676 Log(KBlogTimeout); |
|
677 Log(KBlogDISC); |
|
678 break; |
|
679 default: |
|
680 break; |
|
681 }; |
|
682 } |
|
683 |
|
684 void CRFBloggette::LogMuxCommand(CRfcommSAP* aSAP, CRfcommMuxer* aMux, TUint8 aCommand) |
|
685 { |
|
686 TUint8 signals; |
|
687 |
|
688 switch(aCommand) |
|
689 { |
|
690 case KTestType: |
|
691 Log(KBlogTestCommand); |
|
692 break; |
|
693 case KPNType: |
|
694 Log(KBlogPN);// |
|
695 break; |
|
696 case KRPNType: |
|
697 Log(KBlogRPN);// |
|
698 break; |
|
699 case KFConType: |
|
700 //may need length byte value |
|
701 Log(KBlogFcOn);// |
|
702 break; |
|
703 case KFCoffType: |
|
704 Log(KBlogFcOff);// |
|
705 break; |
|
706 case KMSCType: |
|
707 signals = aSAP->Signals();//V.24 signals in MSC |
|
708 Log(KBlogMSC);// |
|
709 break; |
|
710 case KNSCType: |
|
711 Log(KBlogNSC);// |
|
712 break; |
|
713 case KRLSType: |
|
714 Log(KBlogRLS);// |
|
715 }; |
|
716 |
|
717 } |
|
718 void CRFBloggette::ExplainOutgoingFrame(CRfcommFrame* aFrm, CRfcommMuxer* aMux ) |
|
719 { |
|
720 #ifndef TCI |
|
721 //Show what type of frame we have sent and the various parts of the frame which are important. |
|
722 |
|
723 TInt frametype = aFrm->Type(); //Is it a Ctrl Frame, Data Frame, CreditDataFrame or Mux Ctrl Frame ? |
|
724 TUint8 ctrlfield = aFrm->Ctrl(); |
|
725 TUint8 ctrl = ctrlfield&~KPollFinalBitmask; //tells whether SABM, DISC, UA, DM |
|
726 TUint8 addressfield = aFrm->Address(); //Contains EA, CR, DLCI |
|
727 // TUint8 dlci = aMux->DecodeDLCI(addressfield); //extracts dlci |
|
728 TBool EA = addressfield & KEABitmask; //Is the EA bit set? |
|
729 TBool CR = addressfield & KCRBitmask; //Is the CR bit set? |
|
730 TBool poll = ctrlfield & KPollFinalBitmask; //Is the p/f bit set? |
|
731 |
|
732 switch(frametype) |
|
733 { |
|
734 case KCtrlFrameType: |
|
735 { |
|
736 //CRfcommCtrlFrame* ctrlfrm=static_cast<CRfcommCtrlFrame*>(aFrm); |
|
737 //TUint16 ctrlframelength = ctrlfrm->DataLength(); |
|
738 Log(_L("Tx:")); |
|
739 |
|
740 if(ctrl==KSABMCtrlField) |
|
741 { |
|
742 Log(_L("Tx: SABM")); |
|
743 } |
|
744 if(ctrl==KUACtrlField) |
|
745 { |
|
746 Log(_L("Tx: UA")); |
|
747 } |
|
748 if(ctrl==KDMCtrlField) |
|
749 { |
|
750 Log(_L("Tx: DM")); |
|
751 } |
|
752 if(ctrl==KDISCCtrlField) |
|
753 { |
|
754 Log(_L("Tx: DISC")); |
|
755 } |
|
756 } |
|
757 break; |
|
758 case KDataFrameType: //CRfCommUIHFrame |
|
759 { |
|
760 CRfcommUIHFrame* uihfrm=static_cast<CRfcommUIHFrame*>(aFrm); |
|
761 TUint16 uihframelength = uihfrm->DataLength(); |
|
762 |
|
763 if(poll) |
|
764 Log(_L("Tx: UIH credit data frame")); |
|
765 |
|
766 if (uihframelength<=127) |
|
767 { |
|
768 Log(_L("Tx: UIH simple data frame")); |
|
769 } |
|
770 else |
|
771 { |
|
772 Log(_L("Tx: UIH simple data frame")); |
|
773 } |
|
774 } |
|
775 break; |
|
776 case KCreditDataFrameType: //CRfcommCreditDataFrame |
|
777 { |
|
778 CRfcommCreditDataFrame* creditfrm=static_cast<CRfcommCreditDataFrame*>(aFrm); |
|
779 TUint8 credits = creditfrm->Credit(); |
|
780 //BLOG Credits |
|
781 TUint16 length = creditfrm->DataLength(); |
|
782 |
|
783 if (length<=127) |
|
784 { |
|
785 Log(KBlogShortCreditUIH, credits); |
|
786 } |
|
787 else |
|
788 { |
|
789 Log(KBlogLongCreditUIH, credits); |
|
790 } |
|
791 } |
|
792 break; |
|
793 case KMuxCtrlFrameType: //CRfcommMuxCtrlFrame containing muxer messages/commands |
|
794 { |
|
795 //#ifndef TCI |
|
796 CRfcommMuxCtrlFrame* muxfrm=static_cast<CRfcommMuxCtrlFrame*>(aFrm); |
|
797 TUint8 muxdlci = muxfrm->iDLCI; |
|
798 CRfcommSAP* sap = aMux->FindSAP(muxdlci); //Find the SAP that is on this dlci for aMux |
|
799 TUint8 command = muxfrm->CommandType(); |
|
800 LogMuxCommand(sap, aMux, command); |
|
801 //#endif |
|
802 } |
|
803 break; |
|
804 default: //CRfcommDataFrame |
|
805 break; |
|
806 }; |
|
807 Log(KBlogPFSet, poll); |
|
808 Log(KBlogEASet, EA); |
|
809 Log(KBlogCRSet, CR); |
|
810 |
|
811 Log(KBlogFrameType, frametype); |
|
812 #endif |
|
813 } |
|
814 |
|
815 void CRFBloggette::ExplainIncomingFrame(TUint8 aDlci, TUint8 aCtrl, TBool aPoll) |
|
816 { |
|
817 Log(_L("Rx: ")); |
|
818 switch (aCtrl) |
|
819 { |
|
820 case KSABMCtrlField: |
|
821 Log(_L("Rx: SABM")); |
|
822 break; |
|
823 case KUACtrlField: |
|
824 Log(_L("Rx: UA")); |
|
825 break; |
|
826 case KDMCtrlField: |
|
827 Log(KBlogDM); |
|
828 break; |
|
829 case KDISCCtrlField: |
|
830 Log(KBlogDISC); |
|
831 break; |
|
832 case KUIHCtrlField: |
|
833 { |
|
834 if(aDlci== KMuxDLCI) |
|
835 { |
|
836 Log(KBlogUIHCtrlFrame); |
|
837 } |
|
838 else |
|
839 { |
|
840 Log(KBlogSimpleUIH); |
|
841 } |
|
842 } |
|
843 break; |
|
844 default: |
|
845 //FLOG(_L("Error: RFCOMM: Unexpected frame ctrl field")); |
|
846 break; |
|
847 }; |
|
848 Log(KBlogDLCI, aDlci); |
|
849 Log(KBlogPFSet, aPoll); |
|
850 } |
|
851 |
|
852 void CRFBloggette::IncomingCtrlMessage(TUint8 aCommand, TInt aLength) |
|
853 { |
|
854 switch(aCommand) |
|
855 { |
|
856 case KTestType: |
|
857 Log(KBlogTestCommand); |
|
858 break; |
|
859 case KPNType: |
|
860 Log(KBlogPN); |
|
861 break; |
|
862 case KRPNType: |
|
863 Log(KBlogRPN); |
|
864 break; |
|
865 case KFConType: |
|
866 { |
|
867 Log(KBlogFcOn); |
|
868 if(aLength!=0) |
|
869 { |
|
870 Log(KBlogNonZeroLength); |
|
871 } |
|
872 } |
|
873 break; |
|
874 case KFCoffType: |
|
875 { |
|
876 Log(KBlogFcOff); |
|
877 if(aLength!=0) |
|
878 { |
|
879 Log(KBlogNonZeroLength); |
|
880 } |
|
881 } |
|
882 break; |
|
883 case KMSCType: |
|
884 Log(KBlogMSC); |
|
885 break; |
|
886 case KNSCType: |
|
887 Log(KBlogNSC); |
|
888 break; |
|
889 case KRLSType: |
|
890 Log(KBlogRLS); |
|
891 }; |
|
892 } |
|
893 |
|
894 #endif |