|
1 /* |
|
2 * Copyright (c) 2007-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: |
|
15 * |
|
16 */ |
|
17 |
|
18 #include <string> |
|
19 #include <unistd.h> |
|
20 #include <errno.h> |
|
21 |
|
22 #ifdef __SYMBIAN32__ |
|
23 #include <spawn.h> |
|
24 #else |
|
25 #include <stdio.h> |
|
26 #endif //__SYMBIAN32__ |
|
27 |
|
28 |
|
29 #include "logger.h" |
|
30 #include "comms.h" |
|
31 #include "rtcmessages.h" |
|
32 #include "coremessages.h" |
|
33 |
|
34 #include "testserver.h" |
|
35 |
|
36 using namespace java::comms; |
|
37 using namespace java::captain; |
|
38 |
|
39 |
|
40 TestServer::TestServer() |
|
41 { |
|
42 } |
|
43 |
|
44 TestServer::~TestServer() |
|
45 { |
|
46 } |
|
47 |
|
48 int TestServer::start() |
|
49 { |
|
50 mJavaCaptain.registerDefaultListener(this); |
|
51 mJavaInstaller.registerDefaultListener(this); |
|
52 stopJavaCaptain(); |
|
53 int rc = mJavaCaptain.start(IPC_ADDRESS_JAVA_CAPTAIN_C); |
|
54 |
|
55 if (!rc) |
|
56 { |
|
57 startTckRunner(); |
|
58 rc = mJavaInstaller.connect(IPC_ADDRESS_JAVA_TCK_RUNNER_C); |
|
59 |
|
60 while (rc != 0) |
|
61 { |
|
62 // tck runner is not up yet |
|
63 sleep(1); |
|
64 WLOG(ETckRunner, "waiting for tckrunner..."); |
|
65 rc = mJavaInstaller.connect(IPC_ADDRESS_JAVA_TCK_RUNNER_C); |
|
66 } |
|
67 } |
|
68 else |
|
69 { |
|
70 ELOG1(ETckRunner, "Unable to create Java Captain endpoint %d. Is Java Captain running?", rc); |
|
71 } |
|
72 return rc; |
|
73 } |
|
74 |
|
75 int TestServer::stop() |
|
76 { |
|
77 stopTckRunner(); |
|
78 mJavaCaptain.unregisterDefaultListener(this); |
|
79 mJavaInstaller.unregisterDefaultListener(this); |
|
80 int rc1 = mJavaCaptain.stop(); |
|
81 int rc2 = mJavaInstaller.disconnect(); |
|
82 return rc1 + rc2; |
|
83 } |
|
84 |
|
85 |
|
86 void TestServer::processMessage(CommsMessage& aMessage) |
|
87 { |
|
88 switch (aMessage.getMessageId()) |
|
89 { |
|
90 case MSG_ID_OPERATION: |
|
91 { |
|
92 int oper; |
|
93 string urlOrUid; |
|
94 aMessage >> oper >> urlOrUid; |
|
95 |
|
96 CommsMessage msg; |
|
97 msg.replyTo(aMessage); |
|
98 msg.setMessageId(MSG_ID_OPERATION_RESULT); |
|
99 int status = 0; |
|
100 msg << oper << status << 1 << urlOrUid; |
|
101 mJavaInstaller.send(msg); |
|
102 } |
|
103 break; |
|
104 |
|
105 case RTC_MSG_ID_LAUNCH_APPLICATION_REQ: |
|
106 { |
|
107 string rtc, uid; |
|
108 int option, type; |
|
109 aMessage >> uid >> type >> option >> rtc; |
|
110 |
|
111 CommsMessage msg; |
|
112 msg.replyTo(aMessage); |
|
113 msg.setMessageId(RTC_MSG_ID_APPLICATION_TERMINATED_IND); |
|
114 int status = 0; |
|
115 if (uid.compare("fail") == 0) |
|
116 { |
|
117 status = -1; |
|
118 } |
|
119 msg << uid << status; |
|
120 mJavaCaptain.send(msg); |
|
121 |
|
122 mLaunchReqs.push(uid); |
|
123 } |
|
124 break; |
|
125 |
|
126 default: |
|
127 LOG1(ETckRunner, EInfo, "Unknown message= %d", aMessage.getMessageId()); |
|
128 break; |
|
129 } |
|
130 } |
|
131 |
|
132 int TestServer::startTckRunner() |
|
133 { |
|
134 int rc = 0; |
|
135 int pid = 0; |
|
136 |
|
137 char* av[4]; |
|
138 int index = 0; |
|
139 av[index++] = "tckrunner"; |
|
140 av[index++] = "unittest"; |
|
141 av[index++] = "unittest:\\\\tckrunner_tester"; |
|
142 av[index] = NULL; |
|
143 |
|
144 #ifdef __SYMBIAN32__ |
|
145 rc = posix_spawn(&pid, "tckrunner", NULL, NULL, av, NULL); |
|
146 #else |
|
147 if (!(pid = fork())) |
|
148 { |
|
149 rc = execvp("tckrunner", av); |
|
150 if (rc == -1) |
|
151 { |
|
152 rc = errno; |
|
153 } |
|
154 } |
|
155 #endif // __SYMBIAN32__ |
|
156 |
|
157 if (rc) |
|
158 { |
|
159 ELOG3(ETckRunner, "%s failed, %s - errno=%d", __PRETTY_FUNCTION__, strerror(rc), rc); |
|
160 } |
|
161 return rc; |
|
162 } |
|
163 |
|
164 |
|
165 int TestServer::stopTckRunner() |
|
166 { |
|
167 CommsMessage msg; |
|
168 msg.setMessageId(MSG_ID_OPERATION_RESULT); |
|
169 int status = 0; |
|
170 msg << OPERATION_EXIT << status; |
|
171 int rc = mJavaInstaller.send(msg); |
|
172 while (rc == 0) |
|
173 { |
|
174 sleep(1); |
|
175 WLOG(ETckRunner, "waiting tckrunner to exit..."); |
|
176 rc = mJavaInstaller.send(msg); |
|
177 } |
|
178 return rc; |
|
179 } |
|
180 |
|
181 void TestServer::stopJavaCaptain() |
|
182 { |
|
183 CommsMessage message; |
|
184 message.setModuleId(PLUGIN_ID_JAVACAPTAIN_CORE_C); |
|
185 message.setMessageId(CORE_MSG_ID_STOP_JAVACAPTAIN); |
|
186 CommsClientEndpoint comms; |
|
187 comms.connect(IPC_ADDRESS_JAVA_CAPTAIN_C); |
|
188 int rc = comms.send(message); |
|
189 while (rc == 0) |
|
190 { |
|
191 sleep(1); |
|
192 WLOG(ETckRunner, "waiting JavaCaptain to exit..."); |
|
193 rc = comms.send(message); |
|
194 } |
|
195 comms.disconnect(); |
|
196 } |
|
197 |
|
198 |