9 * Initial Contributors: |
9 * Initial Contributors: |
10 * Nokia Corporation - initial contribution. |
10 * Nokia Corporation - initial contribution. |
11 * |
11 * |
12 * Contributors: |
12 * Contributors: |
13 * |
13 * |
14 * Description: Comms server, |
14 * Description: Comms server, part of Java Sif plugin. |
15 * part of Java platform 2.0 javarestoreconverter process |
15 * When started in 'commsresult' mode from Java Sif plugin |
|
16 * Java Installer sends the results of the operation |
|
17 * it executes (install, uninstall or component info) |
|
18 * to this server. |
16 * |
19 * |
17 */ |
20 */ |
18 |
21 |
19 |
22 |
20 #include <iostream> |
23 #include <iostream> |
21 #include <unistd.h> |
24 #include <unistd.h> |
|
25 #include <usif/usiferror.h> |
22 |
26 |
23 #include "comms.h" |
27 #include "comms.h" |
24 #include "javasymbianoslayer.h" |
28 #include "javasymbianoslayer.h" |
25 #include "logger.h" |
29 #include "logger.h" |
26 #include "resultsserver.h" |
30 #include "resultsserver.h" |
27 |
31 |
28 using namespace java::comms; |
32 using namespace java::comms; |
29 using namespace std; |
33 using namespace std; |
30 |
34 |
31 ResultsServer::ResultsServer(COpaqueNamedParams& aResults, CComponentInfo& aInfo) : |
35 ResultsServer::ResultsServer(COpaqueNamedParams& aResults, CComponentInfo& aInfo) : |
32 iResults(aResults), iInfo(aInfo) |
36 mResults(aResults), mInfo(aInfo) |
33 { |
37 { |
34 } |
38 } |
35 |
39 |
36 ResultsServer::~ResultsServer() |
40 ResultsServer::~ResultsServer() |
37 { |
41 { |
42 iStringPairs.clear(); |
46 iStringPairs.clear(); |
43 } |
47 } |
44 |
48 |
45 int ResultsServer::start() |
49 int ResultsServer::start() |
46 { |
50 { |
47 iRunning = 1; |
51 // Write reasonable error codes to mResults that can be used if |
48 iComms.registerDefaultListener(this); |
52 // Java Installer never returns InstallerResultMessage. |
49 return iComms.start(IPC_ADDRESS_JAVA_SIF_PLUGIN_C); |
53 // If InstallerResultMessage is received the values will be overwritten. |
|
54 TRAPD(err, mResults.AddIntL(KSifOutParam_ErrCategory, EUnexpectedError)); |
|
55 if (KErrNone != err) |
|
56 { |
|
57 ELOG1(EJavaInstaller, |
|
58 "ResultsServer::start mResults.AddIntL ErrCategory err %d", err); |
|
59 } |
|
60 |
|
61 TRAP(err, mResults.AddIntL(KSifOutParam_ErrCode, KErrUnknown)); |
|
62 if (KErrNone != err) |
|
63 { |
|
64 ELOG1(EJavaInstaller, |
|
65 "ResultsServer::start mResults.AddIntL ErrCode err %d", err); |
|
66 } |
|
67 |
|
68 TRAP(err, mResults.AddIntL(KSifOutParam_ExtendedErrCode, 0)); |
|
69 if (KErrNone != err) |
|
70 { |
|
71 ELOG1(EJavaInstaller, |
|
72 "ResultsServer::start mResults.AddIntL ExtendedErrCode err %d", err); |
|
73 } |
|
74 |
|
75 // TODO: return also localized error message (KSifOutParam_ErrMessage and |
|
76 // perhaps also KSifOutParam_ErrMessageDetails) from usif |
|
77 // common localization file after the localized strings are available |
|
78 |
|
79 |
|
80 mComms.registerDefaultListener(this); |
|
81 return mComms.start(IPC_ADDRESS_JAVA_SIF_PLUGIN_C); |
50 } |
82 } |
51 |
83 |
52 int ResultsServer::stop() |
84 int ResultsServer::stop() |
53 { |
85 { |
54 if (iRunning > 0) |
86 mComms.unregisterDefaultListener(this); |
55 { |
87 return mComms.stop(); |
56 iRunning = 0; |
|
57 iComms.unregisterDefaultListener(this); |
|
58 return iComms.stop(); |
|
59 } |
|
60 else |
|
61 { |
|
62 return 0; |
|
63 } |
|
64 } |
88 } |
65 |
89 |
66 /** |
90 /** |
67 * Communicates with Java Installer. The following messages are used. |
91 * Communicates with Java Installer. The following messages are used. |
68 * |
92 * |
115 // result is KErrNone if the operation succeeded |
139 // result is KErrNone if the operation succeeded |
116 int result = iIntPairs[L"result"]; |
140 int result = iIntPairs[L"result"]; |
117 |
141 |
118 if (KErrNone != result) |
142 if (KErrNone != result) |
119 { |
143 { |
120 // return common error information |
144 // return common error information; |
121 TRAP(err, iResults.AddIntL(KSifOutParam_ExtendedErrCode, result)); |
145 setCommonErrorInfo(); |
122 if (KErrNone != err) |
146 |
|
147 if (INSTALL_OPERATION == operation) |
123 { |
148 { |
124 ELOG1(EJavaInstaller, |
149 ELOG1(EJavaInstaller, |
125 "ResultsServer::processMessage iResults.AddIntL ExtendedErrCode err %d", |
150 "ResultsServer::processMessage, Install failed with error %d", result); |
126 err); |
151 } |
127 } |
152 else if (UNINSTALL_OPERATION == operation) |
128 |
|
129 TRAP(err, iResults.AddIntL(KSifOutParam_ErrCode, result)); |
|
130 if (KErrNone != err) |
|
131 { |
153 { |
132 ELOG1(EJavaInstaller, |
154 ELOG1(EJavaInstaller, |
133 "ResultsServer::processMessage iResults.AddIntL ErrCode err %d", err); |
155 "ResultsServer::processMessage, Uninstall failed with error %d", result); |
134 } |
156 } |
135 |
157 else if (COMPONENT_INFO_OPERATION == operation) |
136 TRAP(err, iResults.AddIntL( |
|
137 KSifOutParam_ErrCategory, iIntPairs[L"error-category"])); |
|
138 if (KErrNone != err) |
|
139 { |
158 { |
140 ELOG1(EJavaInstaller, |
159 ELOG1(EJavaInstaller, |
141 "ResultsServer::processMessage iResults.AddIntL ErrCategory err %d", |
160 "ResultsServer::processMessage, Component info failed with error %d", |
142 err); |
161 result); |
143 } |
162 } |
144 |
163 } |
145 HBufC *message = wstringToBuf(iStringPairs[L"error-message"]); |
164 else |
146 if (message == NULL) |
165 { |
147 { |
166 // Operation succeeded |
148 ELOG(EJavaInstaller, |
167 |
149 "ResultsServer::processMessage iResults.wstringToBuf returned NULL "); |
168 // Overwrite (reset) the default error values set for the case where no |
150 } |
169 // InstallerResultMessage is never received |
151 else |
170 resetDefaultErrorValues(); |
152 { |
171 |
153 TRAP(err, iResults.AddStringL(KSifOutParam_ErrMessage, *message)); |
172 if (INSTALL_OPERATION == operation) |
|
173 { |
|
174 // Return the component ids of the installed Java application. |
|
175 TComponentId resultComponentId = iIntPairs[L"suite-cid"]; |
|
176 TRAP(err, mResults.AddIntL(KSifOutParam_ComponentId, resultComponentId)); |
154 if (KErrNone != err) |
177 if (KErrNone != err) |
155 { |
178 { |
156 ELOG1(EJavaInstaller, |
179 ELOG1(EJavaInstaller, |
157 "ResultsServer::processMessage iResults.AddStringL ErrMessage err %d", |
180 "ResultsServer::processMessage mResults.AddIntL cid error %d", err); |
158 err); |
|
159 } |
|
160 delete message; |
|
161 } |
|
162 |
|
163 message = wstringToBuf(iStringPairs[L"error-details"]); |
|
164 if (message == NULL) |
|
165 { |
|
166 ELOG(EJavaInstaller, |
|
167 "ResultsServer::processMessage iResults.wstringToBuf 2 returned NULL "); |
|
168 } |
|
169 else |
|
170 { |
|
171 TRAP(err, iResults.AddStringL(KSifOutParam_ErrMessageDetails, *message)); |
|
172 if (KErrNone != err) |
|
173 { |
|
174 ELOG1(EJavaInstaller, |
|
175 "ResultsServer::processMessage iResults.AddStringL ErrMessageDetails " |
|
176 "err %d", err); |
|
177 } |
|
178 delete message; |
|
179 } |
|
180 |
|
181 if (INSTALL_OPERATION == operation) |
|
182 { |
|
183 ELOG1(EJavaInstaller, |
|
184 "ResultsServer::processMessage, Install failed with error %d", result); |
|
185 } |
|
186 else if (UNINSTALL_OPERATION == operation) |
|
187 { |
|
188 ELOG1(EJavaInstaller, |
|
189 "ResultsServer::processMessage, Uninstall failed with error %d", result); |
|
190 } |
|
191 else if (COMPONENT_INFO_OPERATION == operation) |
|
192 { |
|
193 ELOG1(EJavaInstaller, |
|
194 "ResultsServer::processMessage, Component info failed with error %d", |
|
195 result); |
|
196 } |
|
197 } |
|
198 else |
|
199 { |
|
200 // operation succeeded |
|
201 |
|
202 if (INSTALL_OPERATION == operation) |
|
203 { |
|
204 // Return the component ids of the installed Java application. |
|
205 TComponentId resultComponentId = iIntPairs[L"suite-cid"]; |
|
206 TRAP(err, iResults.AddIntL(KSifOutParam_ComponentId, resultComponentId)); |
|
207 if (KErrNone != err) |
|
208 { |
|
209 ELOG1(EJavaInstaller, |
|
210 "ResultsServer::processMessage iResults.AddIntL cid error %d", err); |
|
211 } |
181 } |
212 } |
182 } |
213 else if (UNINSTALL_OPERATION == operation) |
183 else if (UNINSTALL_OPERATION == operation) |
214 { |
184 { |
215 // Return nothing if uninstall succeeds |
185 // Return nothing if uninstall succeeds |
260 |
230 |
261 clearData(); |
231 clearData(); |
262 } |
232 } |
263 |
233 |
264 |
234 |
|
235 /** |
|
236 * Set common error information. |
|
237 * Note that the information is in member variables |
|
238 * iIntPairs and iStringPairs |
|
239 */ |
|
240 void ResultsServer::setCommonErrorInfo() |
|
241 { |
|
242 // return common error information |
|
243 TRAPD(err, mResults.AddIntL(KSifOutParam_ErrCode, iIntPairs[L"error-code"])); |
|
244 if (KErrNone != err) |
|
245 { |
|
246 ELOG1(EJavaInstaller, |
|
247 "ResultsServer::setCommonErrorInfo mResults.AddIntL ErrCode err %d", err); |
|
248 } |
|
249 |
|
250 TRAP(err, mResults.AddIntL( |
|
251 KSifOutParam_ErrCategory, iIntPairs[L"error-category"])); |
|
252 if (KErrNone != err) |
|
253 { |
|
254 ELOG1(EJavaInstaller, |
|
255 "ResultsServer::setCommonErrorInfo mResults.AddIntL ErrCategory err %d", |
|
256 err); |
|
257 } |
|
258 |
|
259 HBufC *message = wstringToBuf(iStringPairs[L"error-message"]); |
|
260 if (!message) |
|
261 { |
|
262 ELOG(EJavaInstaller, |
|
263 "ResultsServer::setCommonErrorInfo mResults.wstringToBuf returned NULL "); |
|
264 } |
|
265 else |
|
266 { |
|
267 TRAP(err, mResults.AddStringL(KSifOutParam_ErrMessage, *message)); |
|
268 if (KErrNone != err) |
|
269 { |
|
270 ELOG1(EJavaInstaller, |
|
271 "ResultsServer::setCommonErrorInfo mResults.AddStringL ErrMessage err %d", |
|
272 err); |
|
273 } |
|
274 delete message; |
|
275 } |
|
276 |
|
277 message = wstringToBuf(iStringPairs[L"error-details"]); |
|
278 if (!message) |
|
279 { |
|
280 ELOG(EJavaInstaller, |
|
281 "ResultsServer::setCommonErrorInfo mResults.wstringToBuf 2 returned NULL "); |
|
282 } |
|
283 else |
|
284 { |
|
285 TRAP(err, mResults.AddStringL(KSifOutParam_ErrMessageDetails, *message)); |
|
286 if (KErrNone != err) |
|
287 { |
|
288 ELOG1(EJavaInstaller, |
|
289 "ResultsServer::setCommonErrorInfo mResults.AddStringL ErrMessageDetails " |
|
290 "err %d", err); |
|
291 } |
|
292 delete message; |
|
293 } |
|
294 } |
|
295 |
|
296 |
|
297 /** |
|
298 * Overwrite (reset) the default error values to 'no error'. |
|
299 * The default error values were originally set for the case |
|
300 * where no InstallerResultMessage is never received and we must |
|
301 * return sensible error information. |
|
302 */ |
|
303 void ResultsServer::resetDefaultErrorValues() |
|
304 { |
|
305 TRAPD(err, mResults.AddIntL(KSifOutParam_ErrCategory, 0)); |
|
306 if (KErrNone != err) |
|
307 { |
|
308 ELOG1(EJavaInstaller, |
|
309 "ResultsServer::resetDefaultErrorValues mResults.AddIntL ErrCategory err %d", err); |
|
310 } |
|
311 |
|
312 TRAP(err, mResults.AddIntL(KSifOutParam_ErrCode, 0)); |
|
313 if (KErrNone != err) |
|
314 { |
|
315 ELOG1(EJavaInstaller, |
|
316 "ResultsServer::resetDefaultErrorValues mResults.AddIntL ErrCode err %d", err); |
|
317 } |
|
318 |
|
319 // TODO: reset also localized error message KSifOutParam_ErrMessage and |
|
320 // perhaps also KSifOutParam_ErrMessageDetails if they have been set in start() |
|
321 } |
|
322 |
|
323 |
265 void ResultsServer::clearData() |
324 void ResultsServer::clearData() |
266 { |
325 { |
267 iIntPairs.clear(); |
326 iIntPairs.clear(); |
268 iStringPairs.clear(); |
327 iStringPairs.clear(); |
269 } |
328 } |