1 /* |
|
2 * Copyright (c) 2005-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 * Source file for the client api |
|
16 * |
|
17 */ |
|
18 |
|
19 |
|
20 |
|
21 /** |
|
22 @file Client.cpp |
|
23 */ |
|
24 #include <test/testexecutepipslog.h> |
|
25 |
|
26 const TInt KMaxFilename = 50; |
|
27 // EKA1 requires DLL entry point |
|
28 EXPORT_C TInt RTestExecutePIPSLogServ::Connect() |
|
29 /** |
|
30 * @return int - Standard error codes |
|
31 * EKA2 all variants and EKA1 target. |
|
32 * Server is an exe |
|
33 */ |
|
34 { |
|
35 TVersion version(KTestExecuteLoggerMajorVersion,KTestExecuteLoggerMinorVersion,KTestExecuteLoggerBuildVersion); |
|
36 // Assume the server is already running and attempt to create a session |
|
37 TInt err = CreateSession(KTestExecutePIPSLogServerName,version,8); |
|
38 if(err == KErrNotFound) |
|
39 { |
|
40 // Server not running |
|
41 // Construct the server binary name |
|
42 _LIT(KEmpty,""); |
|
43 // EKA2 is simple |
|
44 // No path required |
|
45 TBuf<32> serverFile; |
|
46 serverFile.Copy(KTestExecutePIPSLogServerName); |
|
47 _LIT(KExe,".exe"); |
|
48 serverFile.Append(KExe); |
|
49 RProcess server; |
|
50 err = server.Create(serverFile,KEmpty); |
|
51 if(err != KErrNone) |
|
52 return err; |
|
53 // Synchronise with the server |
|
54 TRequestStatus reqStatus; |
|
55 server.Rendezvous(reqStatus); |
|
56 server.Resume(); |
|
57 // Server will call the reciprocal static synchronise call |
|
58 User::WaitForRequest(reqStatus); |
|
59 server.Close(); |
|
60 if(reqStatus.Int() != KErrNone) |
|
61 return reqStatus.Int(); |
|
62 // Create the root server session |
|
63 err = CreateSession(KTestExecutePIPSLogServerName,version,8); |
|
64 } |
|
65 |
|
66 #ifdef TEF_SHARE_AUTO |
|
67 // Makes the session shared among all threads in the process |
|
68 if( err == KErrNone ) |
|
69 { |
|
70 err = ShareAuto(); |
|
71 } |
|
72 #endif |
|
73 |
|
74 return err; |
|
75 } |
|
76 |
|
77 EXPORT_C TInt RTestExecutePIPSLogServ::CreateLog(const TDesC& aLogFilePath) |
|
78 /** |
|
79 * @param aLogFilePath - Full path and filename of the log file |
|
80 * @param aMode - Overwrite or Append |
|
81 * Makes synchronous call to the log server to create a log session |
|
82 */ |
|
83 { |
|
84 iLogFilename = aLogFilePath; |
|
85 return KErrNone; |
|
86 |
|
87 } |
|
88 |
|
89 EXPORT_C void RTestExecutePIPSLogServ::LogExtra(const TText8* aFile, TInt aLine, TInt aSeverity,TRefByValue<const TDesC> aFmt,...) |
|
90 /** |
|
91 * @param aFile - Source file name |
|
92 * @param aLine - Source file line number |
|
93 * @param aSeverity - ERR, WARN, INFO |
|
94 * @param aFmt - UNICODE format string |
|
95 */ |
|
96 { |
|
97 if (aSeverity>iLogLevel) |
|
98 { |
|
99 return; |
|
100 } |
|
101 // Set up a Variable argument list and call private method |
|
102 VA_LIST aList; |
|
103 VA_START(aList, aFmt); |
|
104 LogExtra(aFile, aLine, aSeverity, aFmt, aList); |
|
105 VA_END(aList); |
|
106 } |
|
107 |
|
108 EXPORT_C void RTestExecutePIPSLogServ::WriteFormat(TRefByValue<const TDesC> aFmt,...) |
|
109 /** |
|
110 * @param aFmt - UNICODE format string |
|
111 */ |
|
112 { |
|
113 // Set up a Variable argument list and call private method |
|
114 VA_LIST aList; |
|
115 VA_START(aList, aFmt); |
|
116 WriteFormat(aFmt, aList); |
|
117 VA_END(aList); |
|
118 } |
|
119 |
|
120 |
|
121 EXPORT_C void RTestExecutePIPSLogServ::Write(const TDesC& aLogBuffer) |
|
122 /** |
|
123 * @param aLogBuffer - Pre-formatted UNICODE buffer |
|
124 */ |
|
125 { |
|
126 // Just call private method |
|
127 // Ignore errors. Could put in ASSERT |
|
128 TRAP_IGNORE(WriteL(aLogBuffer)); |
|
129 } |
|
130 |
|
131 |
|
132 EXPORT_C void RTestExecutePIPSLogServ::WriteFormat(TRefByValue<const TDesC8> aFmt,...) |
|
133 /** |
|
134 * @param aFmt - Narrow format string |
|
135 */ |
|
136 { |
|
137 // Set up a Variable argument list and call private method |
|
138 VA_LIST aList; |
|
139 VA_START(aList, aFmt); |
|
140 WriteFormat(aFmt, aList); |
|
141 VA_END(aList); |
|
142 } |
|
143 |
|
144 |
|
145 EXPORT_C void RTestExecutePIPSLogServ::Write(const TDesC8& aLogBuffer) |
|
146 /** |
|
147 * @param aLogBuffer - Pre-formatted Narrow buffer |
|
148 */ |
|
149 { |
|
150 // Create a larger buffer for adding terminators |
|
151 // Could do more formatting but just allow for CRLF plus time stamp for the time being |
|
152 HBufC8* buffer = HBufC8::New(aLogBuffer.Length()+20); |
|
153 if(buffer) |
|
154 { |
|
155 TPtr8 ptr(buffer->Des()); |
|
156 AddTime(ptr); |
|
157 ptr.Append(aLogBuffer); |
|
158 // Ignore error for the time being. Could do an ASSERT |
|
159 TRAP_IGNORE(WriteL(ptr)); |
|
160 delete buffer; |
|
161 } |
|
162 } |
|
163 |
|
164 void RTestExecutePIPSLogServ::AddTime(TDes8& aLogBuffer) |
|
165 /** |
|
166 * @param aLogBuffer - the line to be decorated |
|
167 * decorate the output with current time |
|
168 */ |
|
169 |
|
170 { |
|
171 TTime now; |
|
172 now.UniversalTime(); |
|
173 TDateTime dateTime = now.DateTime(); |
|
174 _LIT8(KFormat,"%02d:%02d:%02d:%03d "); |
|
175 // add the current time |
|
176 aLogBuffer.AppendFormat(KFormat,dateTime.Hour(),dateTime.Minute(),dateTime.Second(),(dateTime.MicroSecond()/1000)); |
|
177 } |
|
178 |
|
179 EXPORT_C void RTestExecutePIPSLogServ::LogExtra(const TText8* aFile, TInt aLine, TInt aSeverity,TRefByValue<const TDesC> aFmt, VA_LIST aList) |
|
180 /** |
|
181 * @param aFile - Source file name |
|
182 * @param aLine - Source file line number |
|
183 * @param aSeverity - ERR, WARN, INFO |
|
184 * @param aFmt - UNICODE format string |
|
185 * @param aList - Variable argument list |
|
186 * |
|
187 * Format a log output line |
|
188 */ |
|
189 { |
|
190 if (aSeverity>iLogLevel) |
|
191 { |
|
192 return; |
|
193 } |
|
194 // Create a filename string |
|
195 TBuf16<KMaxFilename> fileName; |
|
196 GetCPPModuleName(fileName, aFile); |
|
197 // Create a buffer for formatting |
|
198 HBufC* buffer = HBufC::New(KMaxTestExecuteLogLineLength*2); |
|
199 if (buffer) |
|
200 { |
|
201 TPtr ptr(buffer->Des()); |
|
202 _LIT(KErr,"ERROR - "); |
|
203 _LIT(KHigh,"HIGH - "); |
|
204 _LIT(KWarn,"WARN - "); |
|
205 _LIT(KMedium,"MEDIUM - "); |
|
206 _LIT(KInfo,"INFO - "); |
|
207 _LIT(KLow,"LOW - "); |
|
208 _LIT(KFormat," %d %S %d "); |
|
209 if(aSeverity == ESevrErr) |
|
210 ptr.Append(KErr); |
|
211 else if(aSeverity == ESevrHigh) |
|
212 ptr.Append(KHigh); |
|
213 else if(aSeverity == ESevrWarn) |
|
214 ptr.Append(KWarn); |
|
215 else if(aSeverity == ESevrMedium) |
|
216 ptr.Append(KMedium); |
|
217 else if (aSeverity == ESevrInfo) |
|
218 ptr.Append(KInfo); |
|
219 else if(aSeverity == ESevrLow) |
|
220 ptr.Append(KLow); |
|
221 else //if(aSeverity == ESevrAll) |
|
222 ptr.Append(KInfo); |
|
223 // Add the thread id |
|
224 ptr.AppendFormat(KFormat,(TInt)RThread().Id(),&fileName, aLine); |
|
225 TTEFDes16OverflowPIPS des16OverflowObject; |
|
226 ptr.AppendFormatList(aFmt, aList, &des16OverflowObject); |
|
227 |
|
228 |
|
229 TRAP_IGNORE(WriteL(ptr)); |
|
230 delete buffer; |
|
231 } |
|
232 } |
|
233 |
|
234 EXPORT_C void RTestExecutePIPSLogServ::WriteFormat(TRefByValue<const TDesC> aFmt, VA_LIST aList) |
|
235 /** |
|
236 * @param aFmt - UNICODE format string |
|
237 * @param aList - Variable argument list |
|
238 */ |
|
239 { |
|
240 HBufC* buffer = HBufC::New(KMaxTestExecuteLogLineLength*2); |
|
241 if (buffer) |
|
242 { |
|
243 TPtr ptr(buffer->Des()); |
|
244 TTEFDes16OverflowPIPS des16OverflowObject; |
|
245 ptr.AppendFormatList(aFmt, aList, &des16OverflowObject); |
|
246 |
|
247 TRAP_IGNORE(WriteL(ptr)); |
|
248 delete buffer; |
|
249 } |
|
250 } |
|
251 |
|
252 EXPORT_C void RTestExecutePIPSLogServ::WriteFormat(TRefByValue<const TDesC8> aFmt, VA_LIST aList) |
|
253 /** |
|
254 * @param aFmt - UNICODE format string |
|
255 * @param aList - Variable argument list |
|
256 */ |
|
257 { |
|
258 HBufC8* buffer = HBufC8::New(KMaxTestExecuteLogLineLength*2); |
|
259 if (buffer) |
|
260 { |
|
261 TPtr8 ptr(buffer->Des()); |
|
262 AddTime(ptr); |
|
263 TTEFDes8OverflowPIPS des8OverflowObject; |
|
264 ptr.AppendFormatList(aFmt, aList, &des8OverflowObject); |
|
265 |
|
266 TRAP_IGNORE(WriteL(ptr)); |
|
267 delete buffer; |
|
268 } |
|
269 } |
|
270 |
|
271 void RTestExecutePIPSLogServ::WriteL(const TDesC& aLogBuffer) |
|
272 /** |
|
273 * @param aLogBuffer - UNICODE buffer |
|
274 */ |
|
275 { |
|
276 HBufC8* buffer = HBufC8::NewLC(aLogBuffer.Length()+20); |
|
277 TPtr8 ptr(buffer->Des()); |
|
278 AddTime(ptr); |
|
279 ptr.Append(aLogBuffer); |
|
280 WriteL(ptr); |
|
281 |
|
282 CleanupStack::PopAndDestroy(buffer); |
|
283 } |
|
284 |
|
285 void RTestExecutePIPSLogServ::WriteL(TDes8& aLogBuffer) |
|
286 /** |
|
287 * @param aLogBuffer - pre-formatted narrow buffer |
|
288 * |
|
289 * Synchronous write to the server |
|
290 */ |
|
291 { |
|
292 //try to make a buf out of pipeName... |
|
293 |
|
294 HBufC8* bufferFile = HBufC8::NewL(iLogFilename.Length()); |
|
295 TPtr8 ptrFile(bufferFile->Des()); |
|
296 ptrFile.Append(iLogFilename); |
|
297 |
|
298 _LIT8(KEnd,"\r\n"); |
|
299 |
|
300 TInt retValue = 0 ; |
|
301 // Check to see if there's room to add CRLF |
|
302 if(aLogBuffer.Length()+2 > aLogBuffer.MaxLength()) |
|
303 { |
|
304 HBufC8* buffer = HBufC8::NewLC(aLogBuffer.Length()+2); |
|
305 TPtr8 ptr(buffer->Des()); |
|
306 ptr.Copy(aLogBuffer); |
|
307 ptr.Append(KEnd); |
|
308 TIpcArgs args; |
|
309 args.Set(0,&ptr); |
|
310 args.Set(1,ptr.Length()); |
|
311 args.Set(2,&ptrFile); |
|
312 args.Set(3,iLogFilename.Length()); |
|
313 |
|
314 //User::LeaveIfError(SendReceive(EWriteLog,args)); |
|
315 retValue = SendReceive(EWriteLog,args) ; |
|
316 CleanupStack::PopAndDestroy(buffer); |
|
317 } |
|
318 else |
|
319 { |
|
320 aLogBuffer.Append(KEnd); |
|
321 TIpcArgs args; |
|
322 args.Set(0,&aLogBuffer); |
|
323 args.Set(1,aLogBuffer.Length()); |
|
324 args.Set(2,&ptrFile); |
|
325 args.Set(3,iLogFilename.Length()); |
|
326 //User::LeaveIfError(SendReceive(EWriteLog,args)); |
|
327 retValue = SendReceive(EWriteLog,args) ; |
|
328 } |
|
329 delete bufferFile; |
|
330 User::LeaveIfError(retValue) ; |
|
331 } |
|
332 |
|
333 void RTestExecutePIPSLogServ::GetCPPModuleName(TDes& aModuleName, const TText8* aCPPFileName) |
|
334 /** |
|
335 * @return aModuleName - Filename in descriptor |
|
336 * @param aCppFileName - Filename |
|
337 * Borrowed from scheduletest |
|
338 */ |
|
339 { |
|
340 TPtrC8 fileNamePtrC8(aCPPFileName); |
|
341 // We do our own filename munging here; TParse can't help us since that's |
|
342 // expressly for EPOC filepaths and here we've got whatever the build system is |
|
343 // At present Win32 and Unix directory delimiters are supported |
|
344 TInt lastDelimiter = Max(fileNamePtrC8.LocateReverse('\\'), fileNamePtrC8.LocateReverse('/')); |
|
345 if(lastDelimiter >= 0 && lastDelimiter < fileNamePtrC8.Length() - 1) |
|
346 { |
|
347 // Found a delimiter which isn't trailing; update the ptr to start at the next char |
|
348 TInt fileNameLen = Min(KMaxFilename, fileNamePtrC8.Length() - (lastDelimiter + 1)); |
|
349 fileNamePtrC8.Set(aCPPFileName + lastDelimiter + 1, fileNameLen); |
|
350 } |
|
351 else |
|
352 { |
|
353 // Didn't find a delimiter; take as much of the right-end of the name as fits |
|
354 fileNamePtrC8.Set(aCPPFileName + Max(0, fileNamePtrC8.Length() - KMaxFilename), Min(fileNamePtrC8.Length(), KMaxFilename)); |
|
355 } |
|
356 aModuleName.Copy(fileNamePtrC8); |
|
357 } |
|
358 |
|
359 EXPORT_C void RTestExecutePIPSLogServ::SetLogLevel(TLogSeverity aSeverity) |
|
360 /** |
|
361 * @return void |
|
362 * @param aSeverity - severity of the logs |
|
363 */ |
|
364 { |
|
365 iLogLevel = aSeverity; |
|
366 } |
|