1 /* |
|
2 * Copyright (c) 2005-2006 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: General methods |
|
15 * |
|
16 */ |
|
17 |
|
18 // INCLUDE FILES |
|
19 #include <s32strm.h> // RWriteStream |
|
20 |
|
21 |
|
22 #ifdef M2G_INFO_POPUP |
|
23 #include <eikenv.h> // CEikonEnv::InfoWinL |
|
24 #endif |
|
25 |
|
26 #include <jni.h> |
|
27 |
|
28 #include <SvgJavaInterfaceImpl.h> |
|
29 #include "M2GGeneral.h" |
|
30 |
|
31 |
|
32 M2G_NS_START |
|
33 |
|
34 // EXTERNAL DATA STRUCTURES |
|
35 |
|
36 // EXTERNAL FUNCTION PROTOTYPES |
|
37 |
|
38 // CONSTANTS |
|
39 |
|
40 // MACROS |
|
41 |
|
42 // LOCAL CONSTANTS AND MACROS |
|
43 |
|
44 // MODULE DATA STRUCTURES |
|
45 |
|
46 // LOCAL FUNCTION PROTOTYPES |
|
47 |
|
48 // FORWARD DECLARATIONS |
|
49 |
|
50 // ----------------------------------------------------------------------------- |
|
51 // M2GGeneral::RaiseException |
|
52 // ----------------------------------------------------------------------------- |
|
53 void M2GGeneral::RaiseException( |
|
54 JNIEnv* aEnv, const TDesC8& aName, const TUint8* aMsg) |
|
55 { |
|
56 M2G_DEBUG_0("#### M2G_DEBUG: M2GGeneral::RaiseException() ####"); |
|
57 |
|
58 if (aEnv) |
|
59 { |
|
60 jclass clazz = aEnv->FindClass( |
|
61 REINTERPRET_CAST(const char*, aName.Ptr())); |
|
62 |
|
63 if (!clazz) |
|
64 { |
|
65 // if exception class not found, then use java.lang.Exception |
|
66 clazz = aEnv->FindClass( |
|
67 REINTERPRET_CAST(const char*, KJavaExceptionClass().Ptr())); |
|
68 } |
|
69 |
|
70 aEnv->ThrowNew(clazz, REINTERPRET_CAST(const char*, aMsg)); |
|
71 } |
|
72 } |
|
73 |
|
74 // ----------------------------------------------------------------------------- |
|
75 // M2GGeneral::CheckErrorCode |
|
76 // ----------------------------------------------------------------------------- |
|
77 TInt M2GGeneral::CheckErrorCode(JNIEnv* aEnv, TInt aErrorCode) |
|
78 { |
|
79 M2G_DEBUG_1("M2G_DEBUG: M2GGeneral::CheckErrorCode: %d - begin", aErrorCode); |
|
80 TInt code = aErrorCode; |
|
81 const TUint8* msg = (STATIC_CAST(const TDesC8&, KM2GEmptyString8)).Ptr(); |
|
82 jcfcommon::auto_ptr<MJavaError> error; |
|
83 |
|
84 // Check if an error object |
|
85 if (aErrorCode > 0) |
|
86 { |
|
87 M2G_DEBUG_0("M2G_DEBUG: M2GGeneral::CheckErrorCode(), is MJavaError"); |
|
88 |
|
89 // Error object need to be deleted here and the auto_ptr takes care of that!! |
|
90 error.reset(JavaUnhand< MJavaError >(aErrorCode)); |
|
91 |
|
92 // Get an error description through the MJavaError object |
|
93 msg = error->Description().Ptr(); |
|
94 |
|
95 switch (error->ErrorCode()) |
|
96 { |
|
97 case KM2GIOException: |
|
98 { |
|
99 code = error->ErrorCode(); |
|
100 } |
|
101 default: |
|
102 { |
|
103 code = error->ErrorCode(); |
|
104 } |
|
105 } |
|
106 M2G_DEBUG_1("M2G_DEBUG: M2GGeneral::CheckErrorCode(), MJavaError: error code=%d", code); |
|
107 } |
|
108 |
|
109 switch (code) |
|
110 { |
|
111 case KM2GMemoryNotOk: |
|
112 { |
|
113 M2G_DEBUG_0("#### M2G_DEBUG: M2GGeneral::CheckErrorCode() - OutOfMemoryError ####"); |
|
114 M2GGeneral::RaiseException(aEnv, KJavaOutOfMemoryErrorClass, msg); |
|
115 return code; |
|
116 } |
|
117 case KM2GIOException: |
|
118 { |
|
119 M2G_DEBUG_0("#### M2G_DEBUG: M2GGeneral::CheckErrorCode() - IOException ####"); |
|
120 M2GGeneral::RaiseException(aEnv, KJavaIOExceptionClass, msg); |
|
121 return code; |
|
122 } |
|
123 case KM2GHandleNotOk: |
|
124 { |
|
125 M2G_DEBUG_0("#### M2G_DEBUG: M2GGeneral::CheckErrorCode() - NullPointerException ####"); |
|
126 M2GGeneral::RaiseException(aEnv, KJavaNullPointerException, msg); |
|
127 return code; |
|
128 } |
|
129 default: |
|
130 { |
|
131 M2G_DEBUG_1("M2G_DEBUG: M2GGeneral::CheckErrorCode() error code=%d - end", code); |
|
132 return code; |
|
133 } |
|
134 } |
|
135 } |
|
136 |
|
137 // ----------------------------------------------------------------------------- |
|
138 // M2GGeneral::CheckHandle |
|
139 // ----------------------------------------------------------------------------- |
|
140 TInt M2GGeneral::CheckHandle(JNIEnv* aEnv, TInt aHandle) |
|
141 { |
|
142 if (aHandle == M2G_INVALID_HANDLE) |
|
143 { |
|
144 M2GGeneral::RaiseException(aEnv, KJavaNullPointerException); |
|
145 } |
|
146 if (aHandle < 0) |
|
147 { |
|
148 M2GGeneral::CheckErrorCode(aEnv, aHandle); |
|
149 } |
|
150 return aHandle; |
|
151 } |
|
152 |
|
153 // ----------------------------------------------------------------------------- |
|
154 // M2GGeneral::CheckErrorCodeAndHandle |
|
155 // ----------------------------------------------------------------------------- |
|
156 TInt M2GGeneral::CheckErrorCodeAndHandle( |
|
157 JNIEnv* aEnv, TInt aErrorCode, TInt aHandle, TInt aErrorResult) |
|
158 { |
|
159 if ((aErrorCode == KM2GOk) && (aHandle != M2G_INVALID_HANDLE)) |
|
160 { |
|
161 return aHandle; |
|
162 } |
|
163 if (aErrorCode != KM2GOk) |
|
164 { |
|
165 M2GGeneral::CheckErrorCode(aEnv, aErrorCode); |
|
166 } |
|
167 else if (aHandle == M2G_INVALID_HANDLE) |
|
168 { |
|
169 M2GGeneral::RaiseException(aEnv, KJavaOutOfMemoryErrorClass); |
|
170 } |
|
171 return aErrorResult; |
|
172 } |
|
173 |
|
174 // ----------------------------------------------------------------------------- |
|
175 // M2GGeneral::PopupInfo |
|
176 // ----------------------------------------------------------------------------- |
|
177 #ifdef M2G_INFO_POPUP |
|
178 void M2GGeneral::PopupInfo( |
|
179 const TDesC& aLine1, |
|
180 const TDesC& aLine2) |
|
181 { |
|
182 TInt err = KM2GOk; |
|
183 TRAP(err, CEikonEnv::InfoWinL(aLine1, aLine2)); |
|
184 if (err == KM2GOk) |
|
185 { |
|
186 // DUMMY |
|
187 } |
|
188 } |
|
189 #endif // M2G_INFO_POPUP |
|
190 |
|
191 |
|
192 #ifdef M2G_STATISTIC_DEBUG |
|
193 // ----------------------------------------------------------------------------- |
|
194 // M2GGeneral::TM2GStatistic::TM2GStatistic |
|
195 // ----------------------------------------------------------------------------- |
|
196 M2GGeneral::TM2GStatistic::TM2GStatistic() |
|
197 { |
|
198 Reset(); |
|
199 } |
|
200 |
|
201 // ----------------------------------------------------------------------------- |
|
202 // M2GGeneral::TM2GStatistic::Reset() |
|
203 // ----------------------------------------------------------------------------- |
|
204 void M2GGeneral::TM2GStatistic::Reset() |
|
205 { |
|
206 // Time |
|
207 iStartTime.UniversalTime(); |
|
208 iEndTime.UniversalTime(); |
|
209 // Thread |
|
210 iId = RThread().Id(); |
|
211 RThread thread; |
|
212 if (thread.Open(iId) == KM2GOk) |
|
213 { |
|
214 iThreadName = thread.Name(); |
|
215 thread.Close(); |
|
216 } |
|
217 } |
|
218 |
|
219 // ----------------------------------------------------------------------------- |
|
220 // M2GGeneral::TM2GStatistic::Print() |
|
221 // ----------------------------------------------------------------------------- |
|
222 void M2GGeneral::TM2GStatistic::Print(TBool aPrintElapsedTime) |
|
223 { |
|
224 TInt totalRom = 0; |
|
225 TInt totalRam = 0; |
|
226 TInt freeRam = 0; |
|
227 HAL::Get(HALData::EMemoryROM, totalRom); |
|
228 HAL::Get(HALData::EMemoryRAM, totalRam); |
|
229 HAL::Get(HALData::EMemoryRAMFree, freeRam); |
|
230 |
|
231 // Update time |
|
232 iEndTime.UniversalTime(); |
|
233 |
|
234 M2G_DEBUG_0("===================================================="); |
|
235 // Write memory info |
|
236 if (aPrintElapsedTime) |
|
237 { |
|
238 M2G_DEBUG_5( |
|
239 "Rom size:%d, ram size:%d, ram free:%d, ram used:%d, elapsed time:%d", |
|
240 totalRom >> 10, |
|
241 totalRam >> 10, |
|
242 freeRam >> 10, |
|
243 (totalRam - freeRam) >> 10, |
|
244 iEndTime.MicroSecondsFrom(iStartTime).Int64()); |
|
245 } |
|
246 else |
|
247 { |
|
248 M2G_DEBUG_4( |
|
249 "Rom size:%d, ram size:%d, ram free:%d, ram used:%d", |
|
250 totalRom >> 10, |
|
251 totalRam >> 10, |
|
252 freeRam >> 10, |
|
253 (totalRam - freeRam) >> 10); |
|
254 } |
|
255 // Write thread info |
|
256 RThread thread; |
|
257 if (thread.Open(iId) == KM2GOk) |
|
258 { |
|
259 TThreadStackInfo stackInfo; |
|
260 thread.StackInfo(stackInfo); |
|
261 thread.Close(); |
|
262 TUint id = iId; |
|
263 M2G_DEBUG_2("Thread id:%d, size:%d", id, (stackInfo.iBase - stackInfo.iLimit) >> 10); |
|
264 } |
|
265 M2G_DEBUG_0("===================================================="); |
|
266 } |
|
267 |
|
268 // ----------------------------------------------------------------------------- |
|
269 // M2GGeneral::TM2GStatistic::Print() |
|
270 // ----------------------------------------------------------------------------- |
|
271 void M2GGeneral::TM2GStatistic::Print(RWriteStream& /*aStream*/) |
|
272 { |
|
273 } |
|
274 |
|
275 // ----------------------------------------------------------------------------- |
|
276 // M2GGeneral::TM2GStatistic::Log() |
|
277 // ----------------------------------------------------------------------------- |
|
278 void M2GGeneral::TM2GStatistic::Log() |
|
279 { |
|
280 M2G_DEBUG_0("M2GGeneral::TM2GStatistic::Log()"); |
|
281 M2GGeneral::TM2GStatistic statistic; |
|
282 statistic.Print(); |
|
283 } |
|
284 |
|
285 #endif // M2G_STATISTIC_DEBUG |
|
286 |
|
287 M2G_NS_END |
|