|
1 /* |
|
2 * Copyright (c) 2007-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 the License "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 * Generates commandline report. |
|
16 * |
|
17 */ |
|
18 |
|
19 |
|
20 /** |
|
21 @file |
|
22 @internalComponent |
|
23 @released |
|
24 */ |
|
25 |
|
26 #include "cmdlinewriter.h" |
|
27 |
|
28 /** |
|
29 Constructor: CmdLineWriter class |
|
30 |
|
31 @internalComponent |
|
32 @released |
|
33 */ |
|
34 CmdLineWriter::CmdLineWriter(unsigned int aInputOptions) |
|
35 : iForDepAlign(0), iFormatSize(0), iBuffer(0), iRptType(KCmdLine), iCmdOptions(aInputOptions) |
|
36 { |
|
37 iFormatMessage.flush(); |
|
38 } |
|
39 |
|
40 |
|
41 /** |
|
42 Destructor: CmdLineWriter class |
|
43 |
|
44 Clear the Buffer. |
|
45 |
|
46 @internalComponent |
|
47 @released |
|
48 */ |
|
49 CmdLineWriter::~CmdLineWriter(void) |
|
50 { |
|
51 delete [] iBuffer; |
|
52 } |
|
53 |
|
54 |
|
55 /** |
|
56 Writes report header to the cmd line.. |
|
57 Allocates the memory for formatting purpose. |
|
58 |
|
59 @internalComponent |
|
60 @released |
|
61 */ |
|
62 void CmdLineWriter::StartReport(void) |
|
63 { |
|
64 iBuffer = new char[KCmdGenBufferSize]; |
|
65 if (iBuffer == KNull) |
|
66 { |
|
67 throw ExceptionReporter(NOMEMORY, __FILE__, __LINE__); |
|
68 } |
|
69 } |
|
70 |
|
71 |
|
72 /** |
|
73 Writes the end report info.. |
|
74 Transfer the stream data to stdout. |
|
75 |
|
76 @internalComponent |
|
77 @released |
|
78 */ |
|
79 void CmdLineWriter::EndReport(void) |
|
80 { |
|
81 String outMsg = iFormatMessage.str(); |
|
82 std::cout << outMsg.c_str(); |
|
83 } |
|
84 |
|
85 |
|
86 /** |
|
87 Writes the executable element footer. |
|
88 |
|
89 @internalComponent |
|
90 @released |
|
91 */ |
|
92 void CmdLineWriter::EndExecutable(void) |
|
93 { |
|
94 iFormatMessage << std::endl; |
|
95 iForDepAlign = false; |
|
96 |
|
97 } |
|
98 |
|
99 |
|
100 /** |
|
101 Writes the Delimiter to cmd line. |
|
102 |
|
103 @internalComponent |
|
104 @released |
|
105 */ |
|
106 void CmdLineWriter::WriteDelimiter(void) |
|
107 { |
|
108 if(iCmdOptions & KNoCheck) |
|
109 { |
|
110 iFormatMessage << KCmdLineDelimiterNoStatus.c_str() << std::endl; |
|
111 } |
|
112 else |
|
113 { |
|
114 iFormatMessage << KCmdLineDelimiter.c_str() << std::endl; |
|
115 } |
|
116 } |
|
117 |
|
118 |
|
119 /** |
|
120 Formats the given element based on set size and places to outstream. |
|
121 |
|
122 @internalComponent |
|
123 @released |
|
124 |
|
125 @param aElement - Reference element to be formated |
|
126 */ |
|
127 void CmdLineWriter::FormatAndWriteElement(const String& aElement) |
|
128 { |
|
129 if (aElement.size() < iFormatSize) |
|
130 { |
|
131 memset(iBuffer,' ',iFormatSize); |
|
132 iBuffer[iFormatSize] = '\0'; |
|
133 memcpy(iBuffer,aElement.c_str(),aElement.size()); |
|
134 } |
|
135 else if(aElement.size() >= (unsigned long)KCmdGenBufferSize) |
|
136 { |
|
137 throw ExceptionReporter(FILENAMETOOBIG, __FILE__, __LINE__); |
|
138 } |
|
139 else |
|
140 { |
|
141 strcpy(iBuffer,aElement.c_str()); |
|
142 } |
|
143 iFormatMessage << iBuffer << '\t'; |
|
144 } |
|
145 |
|
146 /** |
|
147 Writes the note about unknown dependency. |
|
148 |
|
149 @internalComponent |
|
150 @released |
|
151 */ |
|
152 void CmdLineWriter::WriteNote(void) |
|
153 { |
|
154 iFormatMessage << KNote.c_str() << ": " << KUnknownDependency << KNoteMesg.c_str() << std::endl; |
|
155 } |
|
156 |
|
157 |
|
158 /** |
|
159 Writes the image element footer. |
|
160 |
|
161 @internalComponent |
|
162 @released |
|
163 */ |
|
164 void CmdLineWriter::EndImage(void) |
|
165 { |
|
166 WriteDelimiter(); |
|
167 } |
|
168 |
|
169 |
|
170 /** |
|
171 Writes the executable name element. |
|
172 |
|
173 @internalComponent |
|
174 @released |
|
175 |
|
176 @param aExeName - Reference to executable name. |
|
177 */ |
|
178 void CmdLineWriter::StartExecutable(const unsigned int /* aSerNo */, const String& aExeName) |
|
179 { |
|
180 iFormatSize = KCmdFormatTwentyTwoWidth; |
|
181 FormatAndWriteElement(aExeName); |
|
182 iForDepAlign = true; |
|
183 } |
|
184 |
|
185 |
|
186 /** |
|
187 Writes the image name element. |
|
188 |
|
189 @internalComponent |
|
190 @released |
|
191 |
|
192 @param aImageName - Reference to image name. |
|
193 */ |
|
194 void CmdLineWriter::StartImage(const String& aImageName) |
|
195 { |
|
196 WriteDelimiter(); |
|
197 iFormatMessage << KCmdImageName.c_str() << aImageName.c_str() << std::endl; |
|
198 WriteDelimiter(); |
|
199 if(iCmdOptions & KNoCheck) |
|
200 { |
|
201 iFormatMessage << KCmdHeaderNoStatus.c_str() << std::endl; |
|
202 } |
|
203 else |
|
204 { |
|
205 iFormatMessage << KCmdHeader.c_str() << std::endl; |
|
206 } |
|
207 WriteDelimiter(); |
|
208 } |
|
209 |
|
210 |
|
211 /** |
|
212 Writes the attribute, their values and the status along with formating the output. |
|
213 |
|
214 @internalComponent |
|
215 @released |
|
216 |
|
217 @param aOneSetExeAtt - Reference to the attributes, their value and status |
|
218 */ |
|
219 void CmdLineWriter::WriteExeAttribute(ExeAttribute& aOneSetExeAtt) |
|
220 { |
|
221 if(!iForDepAlign) |
|
222 { |
|
223 iFormatSize = KCmdFormatTwentyTwoWidth; |
|
224 FormatAndWriteElement(""); |
|
225 } |
|
226 |
|
227 iFormatSize = KCmdFormatTwelveWidth; |
|
228 if(KCmdDbgName != aOneSetExeAtt.iAttName) |
|
229 { |
|
230 FormatAndWriteElement(aOneSetExeAtt.iAttName.c_str()); |
|
231 } |
|
232 else |
|
233 { |
|
234 FormatAndWriteElement(KCmdDbgDisplayName.c_str()); |
|
235 } |
|
236 |
|
237 if (KCmdDepName != aOneSetExeAtt.iAttName && KCmdDbgName != aOneSetExeAtt.iAttName) |
|
238 { |
|
239 unsigned int val; |
|
240 val = Common::StringToInt(aOneSetExeAtt.iAttValue); |
|
241 |
|
242 // to display the hex value in the format of 0x00000000 if the value is 0 |
|
243 iFormatMessage << "0x"; |
|
244 iFormatMessage.width(KCmdFormatEightWidth); |
|
245 iFormatMessage.fill('0'); |
|
246 iFormatMessage << std::hex << val << '\t'; |
|
247 iFormatMessage.fill(' '); |
|
248 iFormatMessage.width(KCmdFormatThirtyWidth); |
|
249 } |
|
250 else |
|
251 { |
|
252 iFormatSize = KCmdFormatTwentyTwoWidth; |
|
253 FormatAndWriteElement(aOneSetExeAtt.iAttValue.c_str()); |
|
254 } |
|
255 iFormatSize = KCmdFormatTwentyTwoWidth; |
|
256 FormatAndWriteElement(aOneSetExeAtt.iAttStatus.c_str()); |
|
257 iFormatMessage << std::endl; |
|
258 iForDepAlign = false; |
|
259 } |
|
260 |
|
261 |
|
262 /** |
|
263 Returns the report type. |
|
264 |
|
265 @internalComponent |
|
266 @released |
|
267 */ |
|
268 const String& CmdLineWriter::ReportType(void) |
|
269 { |
|
270 return iRptType; |
|
271 } |