1 /* |
|
2 * Copyright (c) 2004 - 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: Video telephony logger |
|
15 * |
|
16 */ |
|
17 |
|
18 |
|
19 #pragma CTC SKIP |
|
20 // INCLUDE FILES |
|
21 #include "cvtlogger.h" |
|
22 |
|
23 |
|
24 // LOCAL CONSTANTS |
|
25 _LIT( KVtEngLogConfig, "c:\\Logs\\VT\\VTLOGCONF.txt" ); |
|
26 _LIT( KVtEngLogFolder, "c:\\Logs\\VT" ); |
|
27 _LIT( KVtEngLogFolderLogger, "VT" ); |
|
28 _LIT( KVtEngLogPrefix, "VT: " ); |
|
29 _LIT( KVtEngLogExtension, ".txt" ); |
|
30 _LIT( KVtLoggerEnterFunc, "<" ); |
|
31 _LIT( KVtLoggerExitFunc, ">" ); |
|
32 |
|
33 |
|
34 // ============================ MEMBER FUNCTIONS =============================== |
|
35 |
|
36 // ----------------------------------------------------------------------------- |
|
37 // CVtLogger::CVtLogger |
|
38 // C++ default constructor can NOT contain any code, that |
|
39 // might leave. |
|
40 // ----------------------------------------------------------------------------- |
|
41 // |
|
42 CVtLogger::CVtLogger() : CActive( CActive::EPriorityStandard - 1 ), |
|
43 iLogLevel( ELogLogEverything ) |
|
44 { |
|
45 } |
|
46 |
|
47 // ----------------------------------------------------------------------------- |
|
48 // CVtLogger::ConstructL |
|
49 // Symbian 2nd phase constructor can leave. |
|
50 // ----------------------------------------------------------------------------- |
|
51 // |
|
52 void CVtLogger::ConstructL( ) |
|
53 { |
|
54 User::LeaveIfError( iFs.Connect() ); |
|
55 TFindFile find( iFs ); |
|
56 TUint logLevel( 0 ); |
|
57 TInt ret = iFs.Att(KVtEngLogFolder, logLevel ); |
|
58 if ( ret == KErrNone ) |
|
59 { |
|
60 if ( find.FindByPath( KVtEngLogConfig, NULL ) == KErrNone ) |
|
61 { |
|
62 CActiveScheduler::Add( this ); |
|
63 ReadCongigFile(); |
|
64 } |
|
65 if ( iLogLevel & ELogToFile ) |
|
66 { |
|
67 RThread thread; |
|
68 iFileName.Copy( thread.Name() ); |
|
69 iFileName.Append( KVtEngLogExtension ); |
|
70 } |
|
71 } |
|
72 Dll::SetTls( this ); |
|
73 } |
|
74 |
|
75 // ----------------------------------------------------------------------------- |
|
76 // CVtLogger::NewL |
|
77 // Two-phased constructor. |
|
78 // ----------------------------------------------------------------------------- |
|
79 // |
|
80 CVtLogger* CVtLogger::NewL( ) |
|
81 { |
|
82 CVtLogger* self = new( ELeave ) CVtLogger; |
|
83 |
|
84 CleanupStack::PushL( self ); |
|
85 self->ConstructL( ); |
|
86 CleanupStack::Pop(); |
|
87 |
|
88 return self; |
|
89 } |
|
90 |
|
91 // ----------------------------------------------------------------------------- |
|
92 // CVtLogger::~CVtLogger |
|
93 // Destructor |
|
94 // ----------------------------------------------------------------------------- |
|
95 // |
|
96 CVtLogger::~CVtLogger() |
|
97 { |
|
98 Cancel(); |
|
99 iFs.Close(); |
|
100 Dll::SetTls( NULL ); |
|
101 } |
|
102 |
|
103 // ----------------------------------------------------------------------------- |
|
104 // CVtLogger::Print |
|
105 // Writes to log. |
|
106 // ----------------------------------------------------------------------------- |
|
107 // |
|
108 void CVtLogger::Print( TDesC& aDes ) |
|
109 { |
|
110 if ( iLogLevel & ELogTime && !(iLogLevel & ELogToFile) ) |
|
111 { |
|
112 TTime time; |
|
113 time.HomeTime(); |
|
114 const TDateTime dt= time.DateTime(); |
|
115 |
|
116 iTempBuf.Zero(); |
|
117 iTempBuf.AppendNum( dt.Minute() ); |
|
118 iTempBuf.Append(':'); |
|
119 iTempBuf.AppendNum( dt.Second() ); |
|
120 iTempBuf.Append(':'); |
|
121 iTempBuf.AppendNum( dt.MicroSecond() ); |
|
122 iTempBuf.Append(' '); |
|
123 |
|
124 const TInt currentLength( iTempBuf.Length() ); |
|
125 |
|
126 iTempBuf.Append( aDes.Left( Min( iTempBuf.MaxLength() - currentLength, aDes.Length() ) ) ); |
|
127 RDebug::Print( iTempBuf ); |
|
128 } |
|
129 else |
|
130 { |
|
131 if ( iLogLevel & ELogToFile ) |
|
132 { |
|
133 RFileLogger::Write( |
|
134 KVtEngLogFolderLogger, |
|
135 iFileName, |
|
136 EFileLoggingModeAppend, |
|
137 aDes ); |
|
138 } |
|
139 else |
|
140 { |
|
141 RDebug::Print( aDes ); |
|
142 } |
|
143 } |
|
144 } |
|
145 |
|
146 // ----------------------------------------------------------------------------- |
|
147 // CVtLogger::Print |
|
148 // Writes to log. |
|
149 // ----------------------------------------------------------------------------- |
|
150 // |
|
151 EXPORT_C void CVtLogger::Print( |
|
152 TInt aLevel, |
|
153 TPtrC aBuffer ) |
|
154 { |
|
155 CVtLogger* logger = CVtLogger::Logger(); |
|
156 if ( logger && logger->CheckLevels( aLevel ) ) |
|
157 { |
|
158 logger->iBuffer.Copy( KVtEngLogPrefix ); |
|
159 logger->iBuffer.Append( aBuffer); |
|
160 logger->Print( logger->iBuffer ); |
|
161 } |
|
162 } |
|
163 |
|
164 // ----------------------------------------------------------------------------- |
|
165 // CVtLogger::Print |
|
166 // Writes to log. |
|
167 // ----------------------------------------------------------------------------- |
|
168 // |
|
169 EXPORT_C void CVtLogger::Print( |
|
170 TInt aLevel, |
|
171 TPtrC aBuffer, |
|
172 TInt aValue ) |
|
173 { |
|
174 CVtLogger* logger = CVtLogger::Logger(); |
|
175 if ( logger && logger->CheckLevels( aLevel ) ) |
|
176 { |
|
177 logger->iBuffer.Zero(); |
|
178 logger->iBuffer.AppendNum( aValue ); |
|
179 logger->iBuffer.Format( aBuffer, aValue ); |
|
180 logger->iBuffer.Insert( 0, KVtEngLogPrefix ); |
|
181 logger->Print( logger->iBuffer ); |
|
182 } |
|
183 } |
|
184 |
|
185 // ----------------------------------------------------------------------------- |
|
186 // CVtLogger::Print |
|
187 // Writes to log. |
|
188 // ----------------------------------------------------------------------------- |
|
189 // |
|
190 EXPORT_C void CVtLogger::Print( |
|
191 TInt aLevel, |
|
192 TPtrC aBuffer, |
|
193 TInt aValue1, |
|
194 TInt aValue2 ) |
|
195 { |
|
196 CVtLogger* logger = CVtLogger::Logger(); |
|
197 if ( logger && logger->CheckLevels( aLevel ) ) |
|
198 { |
|
199 logger->iBuffer.Format( aBuffer, aValue1, aValue2 ); |
|
200 logger->iBuffer.Insert( 0, KVtEngLogPrefix ); |
|
201 logger->Print( logger->iBuffer ); |
|
202 } |
|
203 } |
|
204 |
|
205 // ----------------------------------------------------------------------------- |
|
206 // CVtLogger::Print |
|
207 // Writes to log. |
|
208 // ----------------------------------------------------------------------------- |
|
209 // |
|
210 EXPORT_C void CVtLogger::Print( |
|
211 TInt aLevel, |
|
212 const TBool aEntry, |
|
213 TPtrC aBuffer, |
|
214 TInt aRetVal ) |
|
215 { |
|
216 CVtLogger* logger = CVtLogger::Logger(); |
|
217 if ( logger && logger->CheckLevels( aLevel ) ) |
|
218 { |
|
219 logger->iBuffer.Copy( KVtEngLogPrefix ); |
|
220 if ( aEntry ) |
|
221 { |
|
222 logger->iBuffer.Append( aBuffer ); |
|
223 logger->iBuffer.Append( KVtLoggerEnterFunc ); |
|
224 } |
|
225 else |
|
226 { |
|
227 if ( aRetVal != KVtDebugReturnValNotApplicable ) |
|
228 { |
|
229 logger->iTempBuf.Format( aBuffer, aRetVal ); |
|
230 logger->iBuffer.Append( logger->iTempBuf ); |
|
231 } |
|
232 else |
|
233 { |
|
234 logger->iBuffer.Append( aBuffer ); |
|
235 } |
|
236 logger->iBuffer.Append( KVtLoggerExitFunc ); |
|
237 } |
|
238 logger->Print( logger->iBuffer ); |
|
239 } |
|
240 } |
|
241 |
|
242 // ----------------------------------------------------------------------------- |
|
243 // CVtLogger::Logger |
|
244 // Returns logger. |
|
245 // ----------------------------------------------------------------------------- |
|
246 // |
|
247 CVtLogger* CVtLogger::Logger() |
|
248 { |
|
249 TAny* tls = Dll::Tls(); |
|
250 if ( tls ) |
|
251 { |
|
252 return reinterpret_cast<CVtLogger*>( tls ); |
|
253 } |
|
254 return NULL; |
|
255 } |
|
256 |
|
257 // ----------------------------------------------------------------------------- |
|
258 // CVtLogger::Initialize |
|
259 // Initialize logger. |
|
260 // ----------------------------------------------------------------------------- |
|
261 // |
|
262 EXPORT_C void CVtLogger::Initialize() |
|
263 { |
|
264 CVtLogger* logger = NULL; |
|
265 if ( Dll::Tls() == NULL ) |
|
266 { |
|
267 TRAPD( err, logger = CVtLogger::NewL() ); |
|
268 if ( err == KErrNone ) |
|
269 { |
|
270 Dll::SetTls( logger ); |
|
271 } |
|
272 } |
|
273 else |
|
274 { |
|
275 logger = CVtLogger::Logger(); |
|
276 } |
|
277 if ( logger ) |
|
278 { |
|
279 (logger->iAccessCount)++; |
|
280 } |
|
281 |
|
282 } |
|
283 |
|
284 // ----------------------------------------------------------------------------- |
|
285 // CVtLogger::Uninitialize |
|
286 // Uninitialize logger. |
|
287 // ----------------------------------------------------------------------------- |
|
288 // |
|
289 EXPORT_C void CVtLogger::Uninitialize() |
|
290 { |
|
291 TAny* tls = Dll::Tls(); |
|
292 if ( tls ) |
|
293 { |
|
294 CVtLogger* logger = CVtLogger::Logger(); |
|
295 if( logger ) |
|
296 { |
|
297 TInt count( --(logger->iAccessCount) ); |
|
298 if ( !count ) |
|
299 { |
|
300 delete reinterpret_cast<CVtLogger*>( tls ); |
|
301 Dll::SetTls( NULL ); |
|
302 } |
|
303 } |
|
304 } |
|
305 |
|
306 } |
|
307 |
|
308 void CVtLogger::ReadCongigFile() |
|
309 { |
|
310 #ifdef _DEBUG |
|
311 RDebug::Print(_L(" VT: ReadConfigFile" ) ); |
|
312 #endif |
|
313 RFile config; |
|
314 if ( config.Open( iFs, KVtEngLogConfig, EFileShareAny ) == KErrNone ) |
|
315 { |
|
316 TBuf8<16> buf; |
|
317 if ( config.Read( buf ) == KErrNone ) |
|
318 { |
|
319 TLex8 lex( buf ); |
|
320 TUint logLevel( 0 ); |
|
321 if ( lex.Val( logLevel, EHex ) == KErrNone ) |
|
322 { |
|
323 iLogLevel = logLevel; |
|
324 } |
|
325 } |
|
326 config.Close(); |
|
327 } |
|
328 iFs.NotifyChange( ENotifyEntry, iStatus, KVtEngLogConfig() ); |
|
329 SetActive(); |
|
330 } |
|
331 |
|
332 void CVtLogger::RunL() |
|
333 { |
|
334 if ( iStatus == KErrNone ) |
|
335 { |
|
336 ReadCongigFile(); |
|
337 } |
|
338 } |
|
339 |
|
340 void CVtLogger::DoCancel() |
|
341 { |
|
342 iFs.NotifyChangeCancel(); |
|
343 } |
|
344 |
|
345 // ----------------------------------------------------------------------------- |
|
346 // CVtLogger::Flags |
|
347 // Returns flags. |
|
348 // ----------------------------------------------------------------------------- |
|
349 // |
|
350 EXPORT_C TInt CVtLogger::Flags() |
|
351 { |
|
352 CVtLogger* logger = CVtLogger::Logger(); |
|
353 if ( logger ) |
|
354 { |
|
355 return logger->iLogLevel; |
|
356 } |
|
357 return KErrGeneral; |
|
358 } |
|
359 |
|
360 // ----------------------------------------------------------------------------- |
|
361 // CVtLogger::CheckLevels |
|
362 // Check debug level. |
|
363 // ----------------------------------------------------------------------------- |
|
364 // |
|
365 TBool CVtLogger::CheckLevels( TInt aLevels ) const |
|
366 { |
|
367 if ( aLevels & iLogLevel ) |
|
368 { |
|
369 return ETrue; |
|
370 } |
|
371 return EFalse; |
|
372 } |
|
373 #pragma CTC ENDSKIP |
|
374 // End of File |
|