|
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 * This class is used to receive the enum index of the original |
|
16 * message with some more variable arguments. These variable |
|
17 * arguments are split and put into the original message. |
|
18 * |
|
19 */ |
|
20 |
|
21 |
|
22 /** |
|
23 @file |
|
24 @internalComponent |
|
25 @released |
|
26 */ |
|
27 |
|
28 #include "exceptionreporter.h" |
|
29 #include "utils.h" |
|
30 |
|
31 /** |
|
32 Constructor receives the variable arguements and gets the instance |
|
33 of MessageImplementation class. Invokes GetMessage to get the |
|
34 original message. Find %d and %s inside the original message and |
|
35 replace these specifiers with the received variable argument value. |
|
36 |
|
37 @internalComponent |
|
38 @released |
|
39 |
|
40 @param aMsgIndex - an enum index to get original message from |
|
41 MessageImplementation class |
|
42 @param ... - variable arguments. |
|
43 */ |
|
44 ExceptionReporter::ExceptionReporter(int aMsgIndex, ...) |
|
45 { |
|
46 iExcepImplPtr = ExceptionImplementation::Instance(0); |
|
47 iMessage = iExcepImplPtr->Message(aMsgIndex); |
|
48 int fileNameIndex = 0; |
|
49 if(iMessage.length() > 0) |
|
50 { |
|
51 va_list argList; |
|
52 va_start(argList,aMsgIndex); |
|
53 |
|
54 int intVal; |
|
55 String strVal; |
|
56 |
|
57 unsigned int index = iMessage.find("%"); |
|
58 String subStr = iMessage.substr(index + 1);//skip '%' |
|
59 while( index != String::npos ) |
|
60 { |
|
61 switch(iMessage.at(index + 1)) |
|
62 { |
|
63 case 'd': |
|
64 intVal = va_arg(argList, int); |
|
65 iMessage.erase(index, 2);//delete two characters "%d" |
|
66 iMessage.insert(index, ReaderUtil::IntToAscii(intVal, EBase10)); |
|
67 break; |
|
68 case 's': |
|
69 strVal.assign(va_arg(argList, char*)); |
|
70 #ifdef __TOOLS2__ |
|
71 fileNameIndex = strVal.find_last_of('\\'); |
|
72 ++fileNameIndex; |
|
73 #endif |
|
74 #ifdef __LINUX__ |
|
75 fileNameIndex = strVal.find_last_of('/'); //Remove the |
|
76 ++fileNameIndex; |
|
77 #endif |
|
78 strVal = (index != String::npos)? strVal.substr(fileNameIndex) : strVal; |
|
79 iMessage.erase(index, 2); //delete two characters "%s" |
|
80 iMessage.insert(index, strVal); |
|
81 break; |
|
82 } |
|
83 index = iMessage.find("%"); |
|
84 } |
|
85 } |
|
86 } |
|
87 |
|
88 |
|
89 /** |
|
90 Destructor. |
|
91 |
|
92 @internalComponent |
|
93 @released |
|
94 */ |
|
95 ExceptionReporter::~ExceptionReporter() |
|
96 { |
|
97 } |
|
98 |
|
99 |
|
100 /** |
|
101 Invokes the Log function of ExceptionImplementation, which puts the |
|
102 data into logfile directly and takes decision whether to put the same |
|
103 on standard output or not. |
|
104 |
|
105 @internalComponent |
|
106 @released |
|
107 */ |
|
108 void ExceptionReporter::Log(void) const |
|
109 { |
|
110 iExcepImplPtr->Log(iMessage); |
|
111 } |
|
112 |
|
113 /** |
|
114 Invokes the Report function of ExceptionImplementation to report error or warning. |
|
115 |
|
116 @internalComponent |
|
117 @released |
|
118 */ |
|
119 void ExceptionReporter::Report(void) const |
|
120 { |
|
121 iExcepImplPtr->Report(iMessage); |
|
122 } |