|
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 "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: InstallOperation provides a way to launch and communicate |
|
15 * with Java Installer process |
|
16 |
|
17 * |
|
18 */ |
|
19 |
|
20 |
|
21 #include "installoperation.h" |
|
22 |
|
23 #include "logger.h" |
|
24 #include "comms.h" |
|
25 #include "commsmessage.h" |
|
26 #include "javaprocessconstants.h" |
|
27 #include "javasymbianoslayer.h" |
|
28 |
|
29 using namespace java::debug; |
|
30 using namespace java::util; |
|
31 using namespace java::comms; |
|
32 |
|
33 InstallOperation::InstallOperation() |
|
34 { |
|
35 mInstaller.registerDefaultListener(this); |
|
36 } |
|
37 |
|
38 InstallOperation::~InstallOperation() |
|
39 { |
|
40 } |
|
41 |
|
42 int InstallOperation::runJavaInstaller() |
|
43 { |
|
44 JELOG2(EDebugApi); |
|
45 |
|
46 int rc = mInstaller.start(IPC_ADDRESS_JAVA_DEBUGAPI_C); |
|
47 if (!rc) |
|
48 { |
|
49 int waitCount = 5; |
|
50 do |
|
51 { |
|
52 // If install operation is done immediately after previous one then |
|
53 // it's possible that previous Java Installer process instance has not |
|
54 // exited yet. |
|
55 rc = startJavaInstaller(); |
|
56 if (rc == KErrAlreadyExists) |
|
57 { |
|
58 LOG(EDebugApi, EInfo, "waiting java installer to exit"); |
|
59 User::After(500000); // 0.5s |
|
60 } |
|
61 else |
|
62 { |
|
63 waitCount = 0; |
|
64 } |
|
65 } |
|
66 while (--waitCount > 0); |
|
67 } |
|
68 mInstaller.stop(); |
|
69 |
|
70 if (rc) |
|
71 { |
|
72 ELOG1(EDebugApi, "runJavaInstaller() failed: rc=%d", rc); |
|
73 } |
|
74 return rc; |
|
75 } |
|
76 |
|
77 int InstallOperation::startJavaInstaller() |
|
78 { |
|
79 JELOG2(EDebugApi); |
|
80 |
|
81 std::string args = java::runtime::JAVA_INSTALLER_STARTER_DLL; |
|
82 args += " poll -address=debugapi"; |
|
83 |
|
84 std::auto_ptr<HBufC> cmdLine(stringToDes(args.c_str())); |
|
85 std::auto_ptr<HBufC> exe(stringToDes(java::runtime::JAVA_PROCESS)); |
|
86 |
|
87 RProcess process; |
|
88 int rc = process.Create(exe->Des(), cmdLine->Des()); |
|
89 |
|
90 if (KErrNone == rc) |
|
91 { |
|
92 // wait for JavaInstaller exit |
|
93 TRequestStatus status; |
|
94 process.Logon(status); |
|
95 process.Resume(); |
|
96 User::WaitForRequest(status); |
|
97 rc = status.Int(); |
|
98 process.Close(); |
|
99 } |
|
100 |
|
101 LOG1(EDebugApi, EInfo,"javainstaller exit code: %d", rc); |
|
102 return rc; |
|
103 } |
|
104 |
|
105 /** |
|
106 * Communication with Java Installer is done asynchronously. |
|
107 * 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 * String suiteUid (present if operation = install) |
|
122 */ |
|
123 void InstallOperation::processMessage(CommsMessage& aMessage) |
|
124 { |
|
125 JELOG2(EDebugApi); |
|
126 |
|
127 switch (aMessage.getMessageId()) |
|
128 { |
|
129 case GET_NEXT_OPERATION_MESSAGE_ID: |
|
130 { |
|
131 LOG(EDebugApi, EInfo, "GET_NEXT_OPERATION received"); |
|
132 CommsMessage reply = getNextOperation(); |
|
133 reply.replyTo(aMessage); |
|
134 reply.setMessageId(OPERATION_MESSAGE_ID); |
|
135 sendToJavaInstaller(reply); |
|
136 } |
|
137 break; |
|
138 |
|
139 case OPERATION_RESULT_MESSAGE_ID: |
|
140 LOG(EDebugApi, EInfo,"OPERATION_RESULT received"); |
|
141 handleOperationResult(aMessage); |
|
142 break; |
|
143 |
|
144 default: |
|
145 WLOG1(EDebugApi, "Unknown message received: msgId = %d", aMessage.getMessageId()); |
|
146 break; |
|
147 } |
|
148 } |
|
149 |
|
150 CommsMessage InstallOperation::getNextOperation() |
|
151 { |
|
152 CommsMessage msg; |
|
153 msg << EXIT_OPERATION; |
|
154 LOG(EDebugApi, EInfo, "next operation is EXIT"); |
|
155 return msg; |
|
156 } |
|
157 |
|
158 void InstallOperation::sendToJavaInstaller(CommsMessage& aMessage) |
|
159 { |
|
160 int rc = mInstaller.send(aMessage); |
|
161 if (rc) |
|
162 { |
|
163 WLOG1(EDebugApi, "sendToJavaInstaller() failed: rc = %d", rc); |
|
164 } |
|
165 } |
|
166 |
|
167 void InstallOperation::handleOperationResult(CommsMessage& /*aMessage*/) |
|
168 { |
|
169 } |