1 /* |
|
2 * Copyright (c) 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: Comms server, |
|
15 * part of Java platform 2.0 javarestoreconverter process |
|
16 * |
|
17 */ |
|
18 |
|
19 |
|
20 #include <iostream> |
|
21 #include <unistd.h> |
|
22 |
|
23 #include "comms.h" |
|
24 #include "javasymbianoslayer.h" |
|
25 #include "logger.h" |
|
26 #include "restoreserver.h" |
|
27 |
|
28 using namespace java::comms; |
|
29 using namespace std; |
|
30 |
|
31 RestoreServer::RestoreServer() |
|
32 { |
|
33 } |
|
34 |
|
35 RestoreServer::~RestoreServer() |
|
36 { |
|
37 iInstallFiles.clear(); |
|
38 iUninstallUids.clear(); |
|
39 } |
|
40 |
|
41 void RestoreServer::setOperations( |
|
42 RPointerArray<HBufC> &aInstallFiles, |
|
43 std::vector<std::wstring> &aUninstallUids) |
|
44 { |
|
45 // file index will contain the number of valid install file urls |
|
46 iFileIndex = 0; |
|
47 // clear the old install file paths if any |
|
48 iInstallFiles.clear(); |
|
49 |
|
50 int nPointers = aInstallFiles.Count(); |
|
51 iInstallFiles.reserve(nPointers); |
|
52 |
|
53 for (int i = 0; i < nPointers; i++) |
|
54 { |
|
55 HBufC* pBuf = aInstallFiles[i]; |
|
56 if (NULL == pBuf) |
|
57 { |
|
58 // skip this NULL pointer |
|
59 continue; |
|
60 } |
|
61 |
|
62 TPtr16 ptrName(pBuf->Des()); |
|
63 // Convert each HBufC to std:wstring before adding to iInstallFiles |
|
64 iInstallFiles.push_back(std::wstring(desToWstring(ptrName))); |
|
65 iFileIndex++; |
|
66 } |
|
67 |
|
68 LOG1(EJavaConverters, EInfo, "RestoreServer: number of install files = %d", iFileIndex); |
|
69 iFilesTotal = iFileIndex; |
|
70 iFileIndex = 0; |
|
71 |
|
72 iUidIndex = 0; |
|
73 iUninstallUids = aUninstallUids; |
|
74 iUidsTotal = iUninstallUids.size(); |
|
75 LOG1(EJavaConverters, EInfo, "RestoreServer: uninstall %d suites", iUidsTotal); |
|
76 } |
|
77 |
|
78 int RestoreServer::start() |
|
79 { |
|
80 LOG(EJavaConverters, EInfo, "RestoreServer:start called"); |
|
81 |
|
82 iRunning = 1; |
|
83 iComms.registerDefaultListener(this); |
|
84 // Using the same Comms endpoint as javaappconverter on purpose |
|
85 return iComms.start(IPC_ADDRESS_JAVA_APPCONVERTER_C); |
|
86 } |
|
87 |
|
88 int RestoreServer::stop() |
|
89 { |
|
90 if (iRunning > 0) |
|
91 { |
|
92 iRunning = 0; |
|
93 iComms.unregisterDefaultListener(this); |
|
94 return iComms.stop(); |
|
95 } |
|
96 else |
|
97 { |
|
98 return 0; |
|
99 } |
|
100 } |
|
101 |
|
102 /** |
|
103 * Communicates with Java Installer. The following messages are used. |
|
104 * |
|
105 * Message Name Id Contents |
|
106 * |
|
107 * Get Next Operation 500 None |
|
108 * |
|
109 * Operation 501 int operation (install = 0, uninstall = 1, exit = 2) |
|
110 * String url (present if operation = install) |
|
111 * String uid (present if operation = uninstall) |
|
112 * int current (1..total, present if operation = install |
|
113 * and caller is appconverter) |
|
114 * int total (total number of apps to convert, present |
|
115 * if operation = install and caller is appconverter) |
|
116 * |
|
117 * Operation Result 502 int operation (install = 0, uninstall = 1, exit = 2) |
|
118 * int result (ok = 0, error codes are negative) |
|
119 * int uidCount (present if operation = install, value = uids.length) |
|
120 * String[] uids (present if operation = install) |
|
121 */ |
|
122 void RestoreServer::processMessage(CommsMessage& aMessage) |
|
123 { |
|
124 LOG1(EJavaConverters, EInfo, "RestoreServer::processMessage, sender = %d", aMessage.getSender()); |
|
125 LOG1(EJavaConverters, EInfo, "RestoreServer::processMessage, messageId = %d", aMessage.getMessageId()); |
|
126 |
|
127 switch (aMessage.getMessageId()) |
|
128 { |
|
129 case GET_NEXT_OPERATION_MESSAGE_ID: |
|
130 { |
|
131 // Java Installer asks for the next install operation. |
|
132 // Reply with 'Operation' message. |
|
133 |
|
134 CommsMessage reply; |
|
135 reply.replyTo(aMessage); |
|
136 |
|
137 reply.setMessageId(OPERATION_MESSAGE_ID); |
|
138 |
|
139 if (iUidIndex < iUidsTotal) |
|
140 { |
|
141 // ask Java Installer to uninstall next |
|
142 reply << UNINSTALL_OPERATION << iUninstallUids[iUidIndex]; |
|
143 iUidIndex++; |
|
144 } |
|
145 else if (iFileIndex >= iFilesTotal) |
|
146 { |
|
147 // all install files have been handled, ask Java Installer to exit |
|
148 reply << EXIT_OPERATION; |
|
149 |
|
150 // Java Installer sends reply to 'exit' message and then |
|
151 // it exits which wakes up javaappconverter main thread |
|
152 } |
|
153 else |
|
154 { |
|
155 // ask Java Installer to install next |
|
156 reply << INSTALL_OPERATION << iInstallFiles[iFileIndex] << iFileIndex << iFilesTotal; |
|
157 iFileIndex++; |
|
158 } |
|
159 |
|
160 int err = iComms.send(reply); |
|
161 if (err != 0) |
|
162 { |
|
163 ELOG1(EJavaConverters, |
|
164 "RestoreServer: Sending reply to Java Installer failed, err %d", err); |
|
165 // Propably Java Installer has crashed and the execution of |
|
166 // CRestoreConvertMIDlet is already proceeding. This server will |
|
167 // be stopped when the execution reaches EExit state. |
|
168 } |
|
169 } |
|
170 break; |
|
171 |
|
172 case OPERATION_RESULT_MESSAGE_ID: |
|
173 { |
|
174 // Log the result of the operation. Javarestoreconverter does not need |
|
175 // the Uids of the installed Java Applications so they are not parsed. |
|
176 int operation; |
|
177 int result; |
|
178 |
|
179 aMessage >> operation >> result; |
|
180 |
|
181 LOG2(EJavaConverters, EInfo, |
|
182 "RestoreServer: operation = %d, result = %d", operation, result); |
|
183 |
|
184 if (result < 0) |
|
185 { |
|
186 // Conversion failed. |
|
187 ELOG2(EJavaConverters, "RestoreServer: Converting (installing) " |
|
188 "application number %d failed with code %d", |
|
189 iFileIndex, result); |
|
190 } |
|
191 } |
|
192 break; |
|
193 |
|
194 default: |
|
195 { |
|
196 // Unknown message. Ignore it. |
|
197 WLOG1(EJavaConverters, |
|
198 "RestoreServer: Unknown message received. Msg Id = %d", |
|
199 aMessage.getMessageId()); |
|
200 } |
|
201 break; |
|
202 } |
|
203 } |
|