|
1 /* |
|
2 * Copyright (c) 2008 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: Comms server, part of OMJ S60 preinstaller process |
|
15 * |
|
16 */ |
|
17 |
|
18 |
|
19 #include <iostream> |
|
20 #include <unistd.h> |
|
21 |
|
22 #include "comms.h" |
|
23 #include "logger.h" |
|
24 #include "javasymbianoslayer.h" |
|
25 #include "preinstallcommsserver.h" |
|
26 |
|
27 using namespace java::comms; |
|
28 using namespace std; |
|
29 |
|
30 PreinstallCommsServer::PreinstallCommsServer() : mRunning(0) |
|
31 { |
|
32 } |
|
33 |
|
34 PreinstallCommsServer::~PreinstallCommsServer() |
|
35 { |
|
36 mJadFiles.clear(); |
|
37 } |
|
38 |
|
39 void PreinstallCommsServer::setJadFiles(RPointerArray<HBufC> &aJadFiles) |
|
40 { |
|
41 JELOG2(EJavaPreinstaller); |
|
42 |
|
43 // jad index will contain the number of valid jad file urls |
|
44 mJadIndex = 0; |
|
45 // clear the old jad file paths if any |
|
46 mJadFiles.clear(); |
|
47 |
|
48 int nPointers = aJadFiles.Count(); |
|
49 mJadFiles.reserve(nPointers); |
|
50 |
|
51 // index is decremented because mJadIndex will also be decremented when |
|
52 // installing -> total effect is that jad files will be given to |
|
53 // Java Installer in the original order |
|
54 for (int i = nPointers - 1; i > -1; i--) |
|
55 { |
|
56 HBufC* pBuf = aJadFiles[i]; |
|
57 |
|
58 if (NULL == pBuf) |
|
59 { |
|
60 // skip this NULL pointer |
|
61 continue; |
|
62 } |
|
63 |
|
64 TPtr16 ptrName(pBuf->Des()); |
|
65 // Convert each HBufC to std:wstring before adding to mJadFiles |
|
66 mJadFiles.push_back(std::wstring(desToWstring(ptrName))); |
|
67 mJadIndex++; |
|
68 } |
|
69 |
|
70 LOG1(EJavaPreinstaller, EInfo, "PreinstallCommsServer: number of Jad files = %d", mJadIndex); |
|
71 } |
|
72 |
|
73 int PreinstallCommsServer::start() |
|
74 { |
|
75 LOG(EJavaPreinstaller, EInfo, |
|
76 "PreinstallCommsServer:start called"); |
|
77 |
|
78 if (mRunning == 0) |
|
79 { |
|
80 mRunning = 1; |
|
81 mComms.registerDefaultListener(this); |
|
82 return mComms.start(IPC_ADDRESS_JAVA_PREINSTALLER_C); |
|
83 } |
|
84 else |
|
85 { |
|
86 WLOG(EJavaPreinstaller, |
|
87 "PreinstallCommsServer:start called but server is already running"); |
|
88 return 0; |
|
89 } |
|
90 } |
|
91 |
|
92 int PreinstallCommsServer::stop() |
|
93 { |
|
94 if (mRunning > 0) |
|
95 { |
|
96 mRunning = 0; |
|
97 mComms.unregisterDefaultListener(this); |
|
98 return mComms.stop(); |
|
99 } |
|
100 else |
|
101 { |
|
102 return 0; |
|
103 } |
|
104 } |
|
105 |
|
106 /** |
|
107 * Communicates with Java Installer. The following messages are used. |
|
108 * |
|
109 * Message Name Id Contents |
|
110 * |
|
111 * Get Next Operation 500 None |
|
112 * |
|
113 * Operation 501 int operation (install = 0, uninstall = 1, exit = 2) |
|
114 * String url (present if operation = install) |
|
115 * String uid (present if operation = uninstall) |
|
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 PreinstallCommsServer::processMessage(CommsMessage& aMessage) |
|
123 { |
|
124 LOG1(EJavaPreinstaller, EInfo, "processMessage, sender = %d", aMessage.getSender()); |
|
125 LOG1(EJavaPreinstaller, EInfo, "processMessage, messageId = %d", aMessage.getMessageId()); |
|
126 LOG1(EJavaPreinstaller, EInfo, "processMessage, messageRef= %d", aMessage.getMessageRef()); |
|
127 |
|
128 switch (aMessage.getMessageId()) |
|
129 { |
|
130 case GET_NEXT_OPERATION_MESSAGE_ID: |
|
131 { |
|
132 // Java Installer asks for the next install operation. |
|
133 // Reply with 'Operation' message. |
|
134 |
|
135 CommsMessage reply; |
|
136 reply.replyTo(aMessage); |
|
137 |
|
138 reply.setMessageId(OPERATION_MESSAGE_ID); |
|
139 |
|
140 mJadIndex--; |
|
141 if (mJadIndex <= -1) |
|
142 { |
|
143 // all Jad files have been handled, ask Java Installer to exit |
|
144 reply << EXIT_OPERATION; |
|
145 |
|
146 // Java Installer sends reply to 'exit' message and then |
|
147 // it exits which causes the completion of the CSilentMIDletInstall active object |
|
148 } |
|
149 else |
|
150 { |
|
151 // ask Java Installer to install next |
|
152 reply << INSTALL_OPERATION << mJadFiles[mJadIndex]; |
|
153 } |
|
154 |
|
155 // Ignore possible error code returned by send() because Comms |
|
156 // logs the error situations |
|
157 mComms.send(reply); |
|
158 } |
|
159 break; |
|
160 |
|
161 case OPERATION_RESULT_MESSAGE_ID: |
|
162 { |
|
163 // Log the result of the operation. Preinstaller does not need |
|
164 // the Uids of the installed Java Applications so they are not |
|
165 // parsed. |
|
166 int operation; |
|
167 int result; |
|
168 |
|
169 aMessage >> operation >> result; |
|
170 |
|
171 LOG2(EJavaPreinstaller, EInfo, |
|
172 "PreinstallCommsServer: operation = %d, result = %d", operation, result); |
|
173 } |
|
174 break; |
|
175 |
|
176 default: |
|
177 { |
|
178 // Unknown message. Ignore it. |
|
179 WLOG1(EJavaPreinstaller, |
|
180 "PreinstallCommsServer: Unknown message received. Msg Id = %d", |
|
181 aMessage.getMessageId()); |
|
182 } |
|
183 break; |
|
184 } |
|
185 } |