|
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: Factory for phone interface. |
|
15 * |
|
16 */ |
|
17 |
|
18 |
|
19 // INCLUDE FILES |
|
20 #include <e32std.h> |
|
21 #include <flogger.h> |
|
22 #include "WPHandlerUtil.h" |
|
23 |
|
24 |
|
25 #ifdef HANDLERDEBUG |
|
26 // CONSTANTS |
|
27 /// Folder where the log resides |
|
28 _LIT( KLogFolder, "provisioning" ); |
|
29 |
|
30 /// The name of the log file |
|
31 _LIT( KLogFileName, "handler" ); |
|
32 |
|
33 /// The format in which the time is formatted in log |
|
34 _LIT( KLogTimeFormat, "%02d.%02d:%02d:%06d "); |
|
35 |
|
36 /// The length of the string produced by KLogTimeFormat |
|
37 const TInt KLogTimeFormatLength = 16; |
|
38 |
|
39 /// How many characters a log line can contain |
|
40 const TInt KLogLineLength = 256; |
|
41 |
|
42 /// Number of bytes to represent in one line |
|
43 const TInt KBytesPerLine = 16; |
|
44 |
|
45 /// Char to prepend and append to ascii representation |
|
46 const TUint16 KQuote = '\''; |
|
47 |
|
48 /// Replaces non-displayable chars |
|
49 const TUint16 KDot = '.'; |
|
50 |
|
51 /// Number of characters printer per byte |
|
52 const TInt KCharsPerByte = 5; |
|
53 |
|
54 /// Padding size in one hex line |
|
55 const TInt KPadSize = 2; |
|
56 |
|
57 // ============================ MEMBER FUNCTIONS =============================== |
|
58 |
|
59 // ----------------------------------------------------------------------------- |
|
60 // WPHandlerUtil::Debug |
|
61 // ----------------------------------------------------------------------------- |
|
62 // |
|
63 |
|
64 void WPHandlerUtil::Debug( TRefByValue<const TDesC> aText, ... ) |
|
65 { |
|
66 VA_LIST args; |
|
67 VA_START( args, aText ); |
|
68 |
|
69 TBuf<KLogLineLength> buf; |
|
70 buf.FormatList( aText, args ); |
|
71 |
|
72 RFileLogger logger; |
|
73 TInt ret=logger.Connect(); |
|
74 if (ret==KErrNone) |
|
75 { |
|
76 logger.SetDateAndTime( EFalse,EFalse ); |
|
77 logger.CreateLog( KLogFolder, KLogFileName, EFileLoggingModeAppend ); |
|
78 TBuf<KLogTimeFormatLength> timeStamp; |
|
79 TTime now; |
|
80 now.HomeTime(); |
|
81 TDateTime dateTime; |
|
82 dateTime = now.DateTime(); |
|
83 timeStamp.Format( KLogTimeFormat, |
|
84 dateTime.Hour(), dateTime.Minute(), |
|
85 dateTime.Second(), dateTime.MicroSecond() ); |
|
86 buf.Insert( 0, timeStamp ); |
|
87 |
|
88 logger.Write(buf); |
|
89 } |
|
90 |
|
91 logger.Close(); |
|
92 |
|
93 VA_END( args ); |
|
94 } |
|
95 // --------------------------------------------------------- |
|
96 // Hex() |
|
97 // |
|
98 // --------------------------------------------------------- |
|
99 void Hex( const TDesC8& aSource, TDes& aDest ) |
|
100 { |
|
101 _LIT( KAlphabet, "0123456789ABCDEF" ); |
|
102 TBuf<17> alphabet( KAlphabet ); |
|
103 |
|
104 for( TInt i( 0 ); i < aSource.Length(); i++ ) |
|
105 { |
|
106 TBuf8<2> buf; |
|
107 TInt8 val( aSource[i] ); |
|
108 buf.Append( alphabet[ val & 0x0f ] ); |
|
109 val >>= 4; |
|
110 buf.Append( alphabet[ val & 0x0f ] ); |
|
111 |
|
112 aDest.Append( buf[1] ); |
|
113 aDest.Append( buf[0] ); |
|
114 aDest.Append( ' ' ); |
|
115 } |
|
116 } |
|
117 |
|
118 |
|
119 // --------------------------------------------------------- |
|
120 // BinDebug() |
|
121 // |
|
122 // --------------------------------------------------------- |
|
123 void WPHandlerUtil::BinDebug( const TDesC8& aText ) |
|
124 { |
|
125 TInt length( aText.Length() ); |
|
126 |
|
127 for( TInt i( 0 ); i < length; i += KBytesPerLine ) |
|
128 { |
|
129 TBuf<KBytesPerLine*KCharsPerByte + KPadSize> line; |
|
130 TPtrC8 curr( aText.Mid( i ) ); |
|
131 curr.Set( curr.Left( KBytesPerLine ) ); |
|
132 |
|
133 Hex( curr, line ); |
|
134 line.Append( KQuote ); |
|
135 for( TInt j( 0 ); j < curr.Length(); j++ ) |
|
136 { |
|
137 TChar chr( curr[j] ); |
|
138 if( chr == '%' ) |
|
139 { |
|
140 line.Append( _L("%%") ); |
|
141 } |
|
142 else if( chr.IsPrint() ) |
|
143 { |
|
144 line.Append( chr ); |
|
145 } |
|
146 else |
|
147 { |
|
148 line.Append( KDot ); |
|
149 } |
|
150 } |
|
151 line.Append( KQuote ); |
|
152 |
|
153 Debug( line ); |
|
154 } |
|
155 } |
|
156 #else |
|
157 void WPHandlerUtil::Debug( TRefByValue<const TDesC> /*aText*/, ... ) |
|
158 { |
|
159 } |
|
160 void WPHandlerUtil::BinDebug( const TDesC8& /*aText*/ ) |
|
161 { |
|
162 } |
|
163 #endif |
|
164 |
|
165 // End of File |