|
1 /* |
|
2 * Copyright (c) 2009 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: |
|
15 * |
|
16 * |
|
17 */ |
|
18 |
|
19 // Include Files |
|
20 |
|
21 #include "STFLogger.h" // RSTFLogger |
|
22 #include "STFLoggerCSCommon.h" |
|
23 #include "STFLoggerOverFlow.h" |
|
24 #include <hal.h> |
|
25 #include "SettingServerClient.h" |
|
26 |
|
27 // Runs client-side and starts the separate server process |
|
28 static TInt StartTheServer() |
|
29 { |
|
30 |
|
31 //Ccheck server not already started |
|
32 TFindServer findServer(KSTFLoggerServerBinaryName); |
|
33 TFullName name; |
|
34 if (findServer.Next(name) == KErrNone) |
|
35 { |
|
36 return KErrAlreadyExists; |
|
37 } |
|
38 RProcess server; |
|
39 TInt r = server.Create(KSTFLoggerServerBinaryName, KNullDesC); |
|
40 if (r != KErrNone) |
|
41 return r; |
|
42 |
|
43 TRequestStatus stat; |
|
44 server.Rendezvous(stat); |
|
45 if (stat != KRequestPending) |
|
46 server.Kill(0); // abort startup |
|
47 else |
|
48 server.Resume(); // logon OK - start the server |
|
49 |
|
50 User::WaitForRequest(stat); // wait for start or death |
|
51 |
|
52 // Check the exit type. |
|
53 // We can't use the 'exit reason' because if the server panicked this |
|
54 // is set to the panic 'reason' (which may be '0' and cannot thus be distinguished |
|
55 // from KErrNone) |
|
56 r = server.ExitType(); |
|
57 if (EExitPanic == r) |
|
58 r = KErrGeneral; |
|
59 else |
|
60 r = stat.Int(); |
|
61 |
|
62 server.Close(); // This is no longer needed |
|
63 return r; |
|
64 } |
|
65 |
|
66 // Member Functions |
|
67 EXPORT_C TInt RSTFLogger::Connect() |
|
68 { |
|
69 TInt retry = 2; |
|
70 for (;;) |
|
71 {// Uses system-pool message slots |
|
72 TInt r = CreateSession(KSTFLoggerServerName, TVersion(1, 0, 0)); |
|
73 if ((KErrNotFound != r) && (KErrServerTerminated != r)) |
|
74 return (r); |
|
75 if (--retry == 0) |
|
76 return (r); |
|
77 r = StartTheServer(); |
|
78 if ((KErrNone != r) && (KErrAlreadyExists != r)) |
|
79 return (r); |
|
80 } |
|
81 } |
|
82 |
|
83 EXPORT_C TInt RSTFLogger::CreateL(const TDesC& aTestPath, |
|
84 const TDesC& aTestFile, CStifLogger::TLoggerType aLoggerType, |
|
85 CStifLogger::TOutput aOutput, TBool aOverWrite, TBool aWithTimeStamp, |
|
86 TBool aWithLineBreak, TBool aWithEventRanking, |
|
87 TBool aThreadIdToLogFile, TBool aCreateLogDir, |
|
88 TInt aStaticBufferSize, TBool aUnicode) |
|
89 { |
|
90 if( KMaxName < aTestPath.Length() || KMaxName < aTestFile.Length() ) |
|
91 { |
|
92 User::Leave( KErrArgument ); |
|
93 } |
|
94 |
|
95 // Handle to Setting server. |
|
96 RSettingServer settingServer; |
|
97 // Connect to the Setting server and create session |
|
98 TInt ret = settingServer.Connect(); |
|
99 if (ret != KErrNone) |
|
100 { |
|
101 settingServer.Close(); |
|
102 return ret; |
|
103 } |
|
104 // Struct to StifLoggerBase settigs. |
|
105 TLoggerSettings loggerSettings; |
|
106 // Parse StifLoggerBase defaults from STIF initialization file. |
|
107 ret = settingServer.GetLoggerSettings(loggerSettings); |
|
108 settingServer.Close(); |
|
109 if (ret != KErrNone) |
|
110 { |
|
111 return ret; |
|
112 } |
|
113 |
|
114 TName testPath = aTestPath; |
|
115 TName testFile = aTestFile; |
|
116 |
|
117 // Take in use the overwrite parameters |
|
118 OverwriteLoggerSettings(loggerSettings, testPath, testFile, aLoggerType, |
|
119 aOutput, aOverWrite, aWithTimeStamp, aWithLineBreak, |
|
120 aWithEventRanking, aThreadIdToLogFile, aCreateLogDir, aUnicode); |
|
121 |
|
122 RThread threadHandle; // A handle to a thread |
|
123 TThreadId id = threadHandle.Id(); // Encapsulates the Id of a thread |
|
124 |
|
125 TSTFLoggerCreateData loggerData(testPath, testFile, aLoggerType, aOutput, |
|
126 aOverWrite, aWithTimeStamp, aWithLineBreak, aWithEventRanking, |
|
127 aThreadIdToLogFile, aCreateLogDir, aStaticBufferSize, aUnicode, (TInt)id); |
|
128 TPckg<TSTFLoggerCreateData> data(loggerData); |
|
129 TIpcArgs args(&data); |
|
130 return (SendReceive(ESTFLogger_CreateLogger, args)); |
|
131 } |
|
132 |
|
133 |
|
134 |
|
135 EXPORT_C TInt RSTFLogger::CreateL(const TDesC& aTestPath, |
|
136 const TDesC& aTestFile, TLoggerSettings& aLoggerSettings) |
|
137 { |
|
138 TSTFLoggerCreateData loggerData; |
|
139 loggerData.iTestPath = aTestPath; |
|
140 loggerData.iTestFile = aTestFile; |
|
141 loggerData.iOverWrite = aLoggerSettings.iOverwrite; |
|
142 loggerData.iWithTimeStamp = aLoggerSettings.iTimeStamp; |
|
143 loggerData.iWithLineBreak = aLoggerSettings.iLineBreak; |
|
144 loggerData.iWithEventRanking = aLoggerSettings.iEventRanking; |
|
145 loggerData.iThreadIdToLogFile = aLoggerSettings.iThreadId; |
|
146 loggerData.iCreateLogDir = aLoggerSettings.iCreateLogDirectories; |
|
147 loggerData.iStaticBufferSize = 0; |
|
148 loggerData.iUnicode = aLoggerSettings.iUnicode; |
|
149 TInt cpu(0); |
|
150 HAL::Get(HALData::ECPU, cpu); |
|
151 |
|
152 // HW environment |
|
153 if (cpu == HALData::ECPU_ARM) |
|
154 { |
|
155 loggerData.iOutput = aLoggerSettings.iHardwareOutput; |
|
156 loggerData.iLoggerType = aLoggerSettings.iHardwareFormat; |
|
157 } // End of HW environment branch |
|
158 |
|
159 // Wins environment ( cpu == HALData::ECPU_X86 ) |
|
160 else |
|
161 { |
|
162 loggerData.iOutput = aLoggerSettings.iEmulatorOutput; |
|
163 loggerData.iLoggerType = aLoggerSettings.iEmulatorFormat; |
|
164 } // End of WINS environment branch |
|
165 |
|
166 RThread threadHandle; // A handle to a thread |
|
167 TThreadId id = threadHandle.Id(); // Encapsulates the Id of a thread |
|
168 |
|
169 loggerData.iThreadId = (TInt)id; |
|
170 |
|
171 TPckg<TSTFLoggerCreateData> data(loggerData); |
|
172 TIpcArgs args(&data); |
|
173 return (SendReceive(ESTFLogger_CreateLogger, args)); |
|
174 } |
|
175 |
|
176 EXPORT_C TInt RSTFLogger::Log(const TDesC& aLogInfo) |
|
177 { |
|
178 return (Log(CStifLogger::ENoStyle, aLogInfo)); |
|
179 } |
|
180 |
|
181 EXPORT_C TInt RSTFLogger::Log(const TDesC8& aLogInfo) |
|
182 { |
|
183 return (Log(CStifLogger::ENoStyle, aLogInfo)); |
|
184 } |
|
185 |
|
186 EXPORT_C TInt RSTFLogger::Log(TInt aStyle, const TDesC& aLogInfo) |
|
187 { |
|
188 TIpcArgs args(aLogInfo.Length(), aStyle, &aLogInfo); |
|
189 return (SendReceive(ESTFLogger_Log_TInt_TDesC, args)); |
|
190 } |
|
191 |
|
192 EXPORT_C TInt RSTFLogger::Log(TInt aStyle, const TDesC8& aLogInfo) |
|
193 { |
|
194 TIpcArgs args(aLogInfo.Length(), aStyle, &aLogInfo); |
|
195 return (SendReceive(ESTFLogger_Log_TInt_TDesC8, args)); |
|
196 } |
|
197 |
|
198 EXPORT_C TInt RSTFLogger::Log(TRefByValue<const TDesC> aLogInfo, ...) |
|
199 { |
|
200 VA_LIST list; |
|
201 VA_START( list, aLogInfo ); |
|
202 TLogInfo logInfo; |
|
203 |
|
204 // Create overflow handler. If the log information size is over the |
|
205 // KMaxLogData rest of the information will cut. |
|
206 TDesSTFLoggerOverflowHandler overFlowHandler(this, 1); |
|
207 |
|
208 // Parse parameters |
|
209 logInfo.AppendFormatList(aLogInfo, list, &overFlowHandler); |
|
210 |
|
211 // No text style info |
|
212 |
|
213 return Log(CStifLogger::ENoStyle, logInfo); |
|
214 } |
|
215 |
|
216 EXPORT_C TInt RSTFLogger::Log(TRefByValue<const TDesC8> aLogInfo, ...) |
|
217 { |
|
218 VA_LIST list; |
|
219 VA_START( list, aLogInfo ); |
|
220 TLogInfo8 logInfo; |
|
221 |
|
222 // Create overflow handler. If the log information size is over the |
|
223 // KMaxLogData rest of the information will cut. |
|
224 TDes8STFLoggerOverflowHandler overFlowHandler(this, 1); |
|
225 |
|
226 // Parse parameters |
|
227 logInfo.AppendFormatList(aLogInfo, list, &overFlowHandler); |
|
228 |
|
229 // No text style info |
|
230 return Log(CStifLogger::ENoStyle, logInfo); |
|
231 } |
|
232 |
|
233 EXPORT_C TInt RSTFLogger::Log(TInt aStyle, TRefByValue<const TDesC> aLogInfo, |
|
234 ...) |
|
235 { |
|
236 VA_LIST list; |
|
237 VA_START( list, aLogInfo ); |
|
238 TLogInfo logInfo; |
|
239 |
|
240 // Create overflow handler. If the log information size is over the |
|
241 // KMaxLogData rest of the information will cut. |
|
242 TDesSTFLoggerOverflowHandler overFlowHandler(this, 2); |
|
243 |
|
244 // Parse parameters |
|
245 logInfo.AppendFormatList(aLogInfo, list, &overFlowHandler); |
|
246 |
|
247 return Log(aStyle, logInfo); |
|
248 } |
|
249 |
|
250 EXPORT_C TInt RSTFLogger::Log(TInt aStyle, |
|
251 TRefByValue<const TDesC8> aLogInfo, ...) |
|
252 { |
|
253 VA_LIST list; |
|
254 VA_START( list, aLogInfo ); |
|
255 TLogInfo8 logInfo; |
|
256 |
|
257 // Create overflow handler. If the log information size is over the |
|
258 // KMaxLogData rest of the information will cut. |
|
259 TDes8STFLoggerOverflowHandler overFlowHandler(this, 2); |
|
260 |
|
261 // Parse parameters |
|
262 logInfo.AppendFormatList(aLogInfo, list, &overFlowHandler); |
|
263 |
|
264 return Log(aStyle, logInfo); |
|
265 } |
|
266 |
|
267 EXPORT_C TInt RSTFLogger::WriteDelimiter(const TDesC& aDelimiter, TInt aCount) |
|
268 { |
|
269 TLogInfo delimiter; |
|
270 |
|
271 // Create overflow handler. If the delimiter size expands over the |
|
272 // KMaxLogData the TDesLoggerOverflowHandler will call. |
|
273 TDesSTFLoggerOverflowHandler overFlowHandler(this, 3); |
|
274 |
|
275 // Create a delimiter |
|
276 for (TInt a = 0; a < aCount; a++) |
|
277 { |
|
278 // If delimiter creation keeps under the KMaxLogData. |
|
279 // If not we use TDesLoggerOverflowHandler. |
|
280 if ((a * aDelimiter.Length()) < KMaxLogData) |
|
281 { |
|
282 delimiter.Append(aDelimiter); |
|
283 } |
|
284 // KMaxLogData is exceeded |
|
285 else |
|
286 { |
|
287 // If the title size is over the KMaxLogData default delimiter will |
|
288 // use. Use normal overflowhandler to print overflow information. |
|
289 TBuf<4> empty; // Not really used. |
|
290 overFlowHandler.Overflow(empty); |
|
291 delimiter.Copy( |
|
292 _L( "##################################################" )); |
|
293 break; |
|
294 } |
|
295 } |
|
296 |
|
297 // No text style info |
|
298 return Log(CStifLogger::ENoStyle, delimiter); |
|
299 } |
|
300 |
|
301 EXPORT_C TInt RSTFLogger::WriteDelimiter(const TDesC8& aDelimiter, |
|
302 TInt aCount) |
|
303 { |
|
304 TLogInfo8 delimiter; |
|
305 |
|
306 // Create overflow handler. If the delimiter size expands over the |
|
307 // KMaxLogData the TDesLoggerOverflowHandler will call. |
|
308 TDes8STFLoggerOverflowHandler overFlowHandler(this, 3); |
|
309 |
|
310 // Create a delimiter |
|
311 for (TInt a = 0; a < aCount; a++) |
|
312 { |
|
313 // If delimiter creation keeps under the KMaxLogData. |
|
314 // If not we use TDesLoggerOverflowHandler. |
|
315 if ((a * aDelimiter.Length()) < KMaxLogData) |
|
316 { |
|
317 delimiter.Append(aDelimiter); |
|
318 } |
|
319 // KMaxLogData is exceeded |
|
320 else |
|
321 { |
|
322 // If the title size is over the KMaxLogData default delimiter will |
|
323 // use. Use normal overflowhandler to print overflow information. |
|
324 TBuf8<4> empty; // Not really used. |
|
325 overFlowHandler.Overflow(empty); |
|
326 delimiter.Copy( |
|
327 _L8( "##################################################" )); |
|
328 break; |
|
329 } |
|
330 } |
|
331 |
|
332 // No text style info |
|
333 return Log(CStifLogger::ENoStyle, delimiter); |
|
334 } |
|
335 |
|
336 EXPORT_C TInt RSTFLogger::SaveData(const TDesC& aData) |
|
337 { |
|
338 return Log(CStifLogger::ENoStyle, aData); |
|
339 } |
|
340 |
|
341 EXPORT_C TInt RSTFLogger::SaveData(const TDesC8& aData) |
|
342 { |
|
343 return Log(CStifLogger::ENoStyle, aData); |
|
344 } |
|
345 |
|
346 EXPORT_C TInt RSTFLogger::CreationResult(TInt& aResult) |
|
347 { |
|
348 TPckg<TInt> data(aResult); |
|
349 TIpcArgs args(&data); |
|
350 return (SendReceive(ESTFLogger_CreationResult, args)); |
|
351 } |
|
352 |
|
353 EXPORT_C TInt RSTFLogger::OutputType(CStifLogger::TOutput& aOutputType) |
|
354 { |
|
355 TPckg<CStifLogger::TOutput> data(aOutputType); |
|
356 TIpcArgs args(&data); |
|
357 return (SendReceive(ESTFLogger_OutputType, args)); |
|
358 } |
|
359 |
|
360 void RSTFLogger::OverwriteLoggerSettings(TLoggerSettings& aLoggerSettings, |
|
361 TName& aTestPath, TName& aTestFile, |
|
362 CStifLogger::TLoggerType& aLoggerType, CStifLogger::TOutput& aOutput, |
|
363 TBool& aOverWrite, TBool& aWithTimeStamp, TBool& aWithLineBreak, |
|
364 TBool& aWithEventRanking, TBool& aThreadIdToLogFile, |
|
365 TBool& aCreateLogDir, TBool& aUnicode) |
|
366 { |
|
367 // Which environment is in use |
|
368 TInt cpu(0); |
|
369 |
|
370 // Indicator is file type remove acceptable operation |
|
371 TBool removeFileType(EFalse); |
|
372 |
|
373 // Get environment |
|
374 HAL::Get(HALData::ECPU, cpu); |
|
375 |
|
376 // HW environment |
|
377 if (cpu == HALData::ECPU_ARM) |
|
378 { |
|
379 TInt pathLen = aTestPath.Length() |
|
380 + aLoggerSettings.iHardwarePath.Length(); |
|
381 |
|
382 // Check that path overwrite setting is defined and length is legal |
|
383 if (aLoggerSettings.iIsDefined.iHwPath && pathLen < KMaxName) |
|
384 { |
|
385 TName newPath; |
|
386 newPath = aLoggerSettings.iHardwarePath; |
|
387 // Check is '\' the last character |
|
388 TInt ret(0); |
|
389 ret = newPath.LocateReverse(92); |
|
390 // Is '\' character founded |
|
391 if (ret != KErrNotFound) |
|
392 { |
|
393 // Is '\' last character |
|
394 if (ret == (newPath.Length() - 1)) |
|
395 { |
|
396 // delete last '\' |
|
397 newPath.Delete((aLoggerSettings.iHardwarePath.Length() |
|
398 - 1), 1); |
|
399 } |
|
400 } |
|
401 // Removes drive letter if given and appends implemented path |
|
402 TParse parse; |
|
403 parse.Set(aTestPath, NULL, NULL); |
|
404 // Path() return value starts with '\' |
|
405 newPath.Append(parse.Path()); |
|
406 aTestPath = newPath; |
|
407 } |
|
408 if (aLoggerSettings.iIsDefined.iHwFormat) |
|
409 { |
|
410 aLoggerType = aLoggerSettings.iHardwareFormat; |
|
411 // Remove file type if it is set |
|
412 removeFileType = ETrue; |
|
413 } |
|
414 if (aLoggerSettings.iIsDefined.iHwOutput) |
|
415 { |
|
416 aOutput = aLoggerSettings.iHardwareOutput; |
|
417 } |
|
418 } |
|
419 |
|
420 // Wins environment ( cpu == HALData::ECPU_X86 ) |
|
421 else |
|
422 { |
|
423 TInt pathLen = aTestPath.Length() |
|
424 + aLoggerSettings.iEmulatorPath.Length(); |
|
425 |
|
426 // Check that path overwrite setting is defined and length is legal |
|
427 if (aLoggerSettings.iIsDefined.iPath && pathLen < KMaxName) |
|
428 { |
|
429 TName newPath; |
|
430 newPath = aLoggerSettings.iEmulatorPath; |
|
431 // Check is '\' the last character |
|
432 TInt ret(0); |
|
433 ret = newPath.LocateReverse(92); |
|
434 // Is '\' character founded |
|
435 if (ret != KErrNotFound) |
|
436 { |
|
437 // Is '\' last character |
|
438 if (ret == (newPath.Length() - 1)) |
|
439 { |
|
440 // delete last '\' |
|
441 newPath.Delete((aLoggerSettings.iEmulatorPath.Length() |
|
442 - 1), 1); |
|
443 } |
|
444 } |
|
445 // Removes drive letter if given and appends implemented path |
|
446 TParse parse; |
|
447 parse.Set(aTestPath, NULL, NULL); |
|
448 // Path() return value starts with '\' |
|
449 newPath.Append(parse.Path()); |
|
450 aTestPath = newPath; |
|
451 } |
|
452 if (aLoggerSettings.iIsDefined.iFormat) |
|
453 { |
|
454 aLoggerType = aLoggerSettings.iEmulatorFormat; |
|
455 // Remove file type if it is set |
|
456 removeFileType = ETrue; |
|
457 } |
|
458 if (aLoggerSettings.iIsDefined.iOutput) |
|
459 { |
|
460 aOutput = aLoggerSettings.iEmulatorOutput; |
|
461 } |
|
462 } |
|
463 |
|
464 // Rest of the overwrite values |
|
465 if (aLoggerSettings.iIsDefined.iOverwrite) |
|
466 { |
|
467 aOverWrite = aLoggerSettings.iOverwrite; |
|
468 } |
|
469 if (aLoggerSettings.iIsDefined.iTimeStamp) |
|
470 { |
|
471 aWithTimeStamp = aLoggerSettings.iTimeStamp; |
|
472 } |
|
473 if (aLoggerSettings.iIsDefined.iLineBreak) |
|
474 { |
|
475 aWithLineBreak = aLoggerSettings.iLineBreak; |
|
476 } |
|
477 if (aLoggerSettings.iIsDefined.iEventRanking) |
|
478 { |
|
479 aWithEventRanking = aLoggerSettings.iEventRanking; |
|
480 } |
|
481 if (aLoggerSettings.iIsDefined.iThreadId) |
|
482 { |
|
483 aThreadIdToLogFile = aLoggerSettings.iThreadId; |
|
484 } |
|
485 if (aLoggerSettings.iIsDefined.iCreateLogDir) |
|
486 { |
|
487 aCreateLogDir = aLoggerSettings.iCreateLogDirectories; |
|
488 } |
|
489 if (aLoggerSettings.iIsDefined.iUnicode) |
|
490 { |
|
491 aUnicode = aLoggerSettings.iUnicode; |
|
492 } |
|
493 |
|
494 // Remove file type if allowed and if file type is set to filename |
|
495 if (removeFileType) |
|
496 { |
|
497 // Remove file type '.XXX' from file name if exist |
|
498 if (aTestFile.Find(_L( "." ))) |
|
499 { |
|
500 TParse parse; |
|
501 parse.Set(aTestFile, NULL, NULL); |
|
502 // Type length |
|
503 TInt length(0); |
|
504 // '.XXX' |
|
505 length = parse.Ext().Length(); |
|
506 // Delete type |
|
507 aTestFile.Delete(aTestFile.Length() - length, length); |
|
508 } |
|
509 } |
|
510 |
|
511 } |