sl@0
|
1 |
// Copyright (c) 2001-2009 Nokia Corporation and/or its subsidiary(-ies).
|
sl@0
|
2 |
// All rights reserved.
|
sl@0
|
3 |
// This component and the accompanying materials are made available
|
sl@0
|
4 |
// under the terms of "Eclipse Public License v1.0"
|
sl@0
|
5 |
// which accompanies this distribution, and is available
|
sl@0
|
6 |
// at the URL "http://www.eclipse.org/legal/epl-v10.html".
|
sl@0
|
7 |
//
|
sl@0
|
8 |
// Initial Contributors:
|
sl@0
|
9 |
// Nokia Corporation - initial contribution.
|
sl@0
|
10 |
//
|
sl@0
|
11 |
// Contributors:
|
sl@0
|
12 |
//
|
sl@0
|
13 |
// Description:
|
sl@0
|
14 |
// inulogger.cpp
|
sl@0
|
15 |
//
|
sl@0
|
16 |
//
|
sl@0
|
17 |
|
sl@0
|
18 |
#include <f32file.h> // for TParse, in Flogger stuff
|
sl@0
|
19 |
|
sl@0
|
20 |
|
sl@0
|
21 |
#include "InuLogger.h"
|
sl@0
|
22 |
|
sl@0
|
23 |
#define KLogsDir _L("c:\\logs\\")
|
sl@0
|
24 |
#define KInuLogsDirName _L("InetUtils")
|
sl@0
|
25 |
#define KTestHeader _L("Inet Utils Log")
|
sl@0
|
26 |
#define KTestCommentPrepend _L("\t")
|
sl@0
|
27 |
|
sl@0
|
28 |
const TInt KMaxLogLineLength = 128;
|
sl@0
|
29 |
|
sl@0
|
30 |
EXPORT_C
|
sl@0
|
31 |
TInuLogger::~TInuLogger()
|
sl@0
|
32 |
{
|
sl@0
|
33 |
#if defined (_DEBUG)
|
sl@0
|
34 |
iLogger.Close();
|
sl@0
|
35 |
#endif
|
sl@0
|
36 |
}
|
sl@0
|
37 |
|
sl@0
|
38 |
EXPORT_C
|
sl@0
|
39 |
#if defined (_DEBUG)
|
sl@0
|
40 |
void TInuLogger::CreateFlogger(const TDesC& aFileName, TInt aShowDate, TInt aShowTime)
|
sl@0
|
41 |
//
|
sl@0
|
42 |
// Create log file in directory KLogsdir\KWapLogsDirName - Note: ingore Drive and Path of aFilename
|
sl@0
|
43 |
{
|
sl@0
|
44 |
iLogger.Connect();
|
sl@0
|
45 |
TParse p;
|
sl@0
|
46 |
p.Set(aFileName, NULL, NULL);
|
sl@0
|
47 |
iLogger.CreateLog(KInuLogsDirName, p.NameAndExt(), EFileLoggingModeOverwrite);
|
sl@0
|
48 |
iLogger.SetDateAndTime(aShowDate, aShowTime);
|
sl@0
|
49 |
iLogger.Write(KTestHeader);
|
sl@0
|
50 |
}
|
sl@0
|
51 |
#else if !defined (_DEBUG)
|
sl@0
|
52 |
void TInuLogger::CreateFlogger(const TDesC& , TInt , TInt ) {}
|
sl@0
|
53 |
#endif
|
sl@0
|
54 |
|
sl@0
|
55 |
EXPORT_C
|
sl@0
|
56 |
#if defined (_DEBUG)
|
sl@0
|
57 |
void TInuLogger::LogIt(TRefByValue<const TDesC> aFmt, ...)
|
sl@0
|
58 |
//
|
sl@0
|
59 |
// Messages to the front end emulator and to the log file
|
sl@0
|
60 |
{
|
sl@0
|
61 |
VA_LIST list;
|
sl@0
|
62 |
VA_START(list,aFmt);
|
sl@0
|
63 |
|
sl@0
|
64 |
TBuf<KMaxFileName> buf;
|
sl@0
|
65 |
buf.Append(KTestCommentPrepend);
|
sl@0
|
66 |
buf.AppendFormatList(aFmt,list);
|
sl@0
|
67 |
VA_END(list);
|
sl@0
|
68 |
|
sl@0
|
69 |
WriteComment(buf);
|
sl@0
|
70 |
}
|
sl@0
|
71 |
#else if !defined (_DEBUG)
|
sl@0
|
72 |
void TInuLogger::LogIt(TRefByValue<const TDesC> , ...) {}
|
sl@0
|
73 |
#endif
|
sl@0
|
74 |
|
sl@0
|
75 |
|
sl@0
|
76 |
|
sl@0
|
77 |
#if defined (_DEBUG)
|
sl@0
|
78 |
EXPORT_C void TInuLogger::WriteComment(const TDesC& aComment)
|
sl@0
|
79 |
//
|
sl@0
|
80 |
// Writes aComment to test log file, logging file and test harness
|
sl@0
|
81 |
{
|
sl@0
|
82 |
TPtrC line;
|
sl@0
|
83 |
line.Set(aComment);
|
sl@0
|
84 |
|
sl@0
|
85 |
while (line.Length() > KMaxLogLineLength)
|
sl@0
|
86 |
{
|
sl@0
|
87 |
iLogger.Write(line.Left(KMaxLogLineLength));
|
sl@0
|
88 |
line.Set(line.Right(line.Length() - KMaxLogLineLength));
|
sl@0
|
89 |
}
|
sl@0
|
90 |
|
sl@0
|
91 |
iLogger.Write(line.Left(line.Length()));
|
sl@0
|
92 |
|
sl@0
|
93 |
}
|
sl@0
|
94 |
|
sl@0
|
95 |
#else if !defined (_DEBUG)
|
sl@0
|
96 |
EXPORT_C void TInuLogger::WriteComment(const TDesC& ) {}
|
sl@0
|
97 |
#endif
|
sl@0
|
98 |
|
sl@0
|
99 |
|
sl@0
|
100 |
|
sl@0
|
101 |
EXPORT_C
|
sl@0
|
102 |
#if defined (_DEBUG)
|
sl@0
|
103 |
void TInuLogger::DumpIt(const TDesC8& aData)
|
sl@0
|
104 |
//Do a formatted dump of binary data
|
sl@0
|
105 |
{
|
sl@0
|
106 |
// Iterate the supplied block of data in blocks of cols=80 bytes
|
sl@0
|
107 |
const TInt cols=16;
|
sl@0
|
108 |
TInt pos = 0;
|
sl@0
|
109 |
TBuf<KMaxLogLineLength> logLine;
|
sl@0
|
110 |
TBuf<KMaxLogLineLength> anEntry;
|
sl@0
|
111 |
while (pos < aData.Length())
|
sl@0
|
112 |
{
|
sl@0
|
113 |
//start-line exadecimal( a 4 digit number)
|
sl@0
|
114 |
anEntry.Format(TRefByValue<const TDesC>_L("%04x : "), pos);
|
sl@0
|
115 |
logLine.Append(anEntry.Left(KMaxLogLineLength));
|
sl@0
|
116 |
|
sl@0
|
117 |
// Hex output
|
sl@0
|
118 |
TInt offset;
|
sl@0
|
119 |
for (offset = 0; offset < cols; offset++)
|
sl@0
|
120 |
{
|
sl@0
|
121 |
if (pos + offset < aData.Length())
|
sl@0
|
122 |
{
|
sl@0
|
123 |
TInt nextByte = aData[pos + offset];
|
sl@0
|
124 |
anEntry.Format(TRefByValue<const TDesC>_L("%02x "), nextByte);
|
sl@0
|
125 |
logLine.Append(anEntry);
|
sl@0
|
126 |
}
|
sl@0
|
127 |
else
|
sl@0
|
128 |
{
|
sl@0
|
129 |
//fill the remaining spaces with blanks untill the cols-th Hex number
|
sl@0
|
130 |
anEntry.Format(TRefByValue<const TDesC>_L(" "));
|
sl@0
|
131 |
logLine.Append(anEntry);
|
sl@0
|
132 |
}
|
sl@0
|
133 |
}
|
sl@0
|
134 |
anEntry.Format(TRefByValue<const TDesC>_L(": "));
|
sl@0
|
135 |
logLine.Append(anEntry);
|
sl@0
|
136 |
|
sl@0
|
137 |
// Char output
|
sl@0
|
138 |
for (offset = 0; offset < cols; offset++)
|
sl@0
|
139 |
{
|
sl@0
|
140 |
if (pos + offset < aData.Length())
|
sl@0
|
141 |
{
|
sl@0
|
142 |
TInt nextByte = aData[pos + offset];
|
sl@0
|
143 |
if ((nextByte >= 32) && (nextByte <= 127))
|
sl@0
|
144 |
{
|
sl@0
|
145 |
anEntry.Format(TRefByValue<const TDesC>_L("%c"), nextByte);
|
sl@0
|
146 |
logLine.Append(anEntry);
|
sl@0
|
147 |
}
|
sl@0
|
148 |
else
|
sl@0
|
149 |
{
|
sl@0
|
150 |
anEntry.Format(TRefByValue<const TDesC>_L("."));
|
sl@0
|
151 |
logLine.Append(anEntry);
|
sl@0
|
152 |
}
|
sl@0
|
153 |
}
|
sl@0
|
154 |
else
|
sl@0
|
155 |
{
|
sl@0
|
156 |
anEntry.Format(TRefByValue<const TDesC>_L(" "));
|
sl@0
|
157 |
logLine.Append(anEntry);
|
sl@0
|
158 |
}
|
sl@0
|
159 |
}
|
sl@0
|
160 |
LogIt(TRefByValue<const TDesC>_L("%S\n"), &logLine);
|
sl@0
|
161 |
logLine.Zero();
|
sl@0
|
162 |
|
sl@0
|
163 |
// Advance to next byte segment (1 seg= cols)
|
sl@0
|
164 |
pos += cols;
|
sl@0
|
165 |
}
|
sl@0
|
166 |
}
|
sl@0
|
167 |
#else if !defined (_DEBUG)
|
sl@0
|
168 |
void TInuLogger::DumpIt(const TDesC8& ) {}
|
sl@0
|
169 |
#endif
|
sl@0
|
170 |
|
sl@0
|
171 |
EXPORT_C
|
sl@0
|
172 |
#if defined (_DEBUG)
|
sl@0
|
173 |
void TInuLogger::WriteComment(const TDesC8& aData)
|
sl@0
|
174 |
//Do a write of the supplied data, literally where possible
|
sl@0
|
175 |
{
|
sl@0
|
176 |
TPtrC8 line;
|
sl@0
|
177 |
line.Set(aData);
|
sl@0
|
178 |
while (line.Length() > KMaxLogLineLength)
|
sl@0
|
179 |
{
|
sl@0
|
180 |
iLogger.Write(line.Left(KMaxLogLineLength));
|
sl@0
|
181 |
line.Set(line.Right(line.Length() - KMaxLogLineLength));
|
sl@0
|
182 |
}
|
sl@0
|
183 |
|
sl@0
|
184 |
iLogger.Write(line.Left(line.Length()));
|
sl@0
|
185 |
}
|
sl@0
|
186 |
#else if !defined (_DEBUG)
|
sl@0
|
187 |
void TInuLogger::WriteComment(const TDesC8& ) {}
|
sl@0
|
188 |
#endif
|
sl@0
|
189 |
|