|
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: Main |
|
15 * |
|
16 */ |
|
17 |
|
18 |
|
19 #include <stdio.h> |
|
20 #include <string> |
|
21 #include <unistd.h> |
|
22 |
|
23 #include "javacommonutils.h" |
|
24 #include "comms.h" |
|
25 #include "commsclientendpoint.h" |
|
26 #include "commslistener.h" |
|
27 #include "monitor.h" |
|
28 |
|
29 #include "rtcmessages.h" |
|
30 |
|
31 #include "testuids.h" |
|
32 |
|
33 using namespace java::util; |
|
34 using namespace java::comms; |
|
35 using namespace java::captain; |
|
36 |
|
37 CommsClientEndpoint comms; |
|
38 Monitor* monitor; |
|
39 Uid uid; |
|
40 |
|
41 class rtCommsListener : public CommsListener |
|
42 { |
|
43 public: |
|
44 void processMessage(CommsMessage& message) |
|
45 { |
|
46 switch (message.getMessageId()) |
|
47 { |
|
48 case RTC_MSG_ID_TERMINATE_APPLICATION_REQ: |
|
49 printf("TERMINATE_REQ received, triggering monitor\n"); |
|
50 monitor->notify(); |
|
51 break; |
|
52 } |
|
53 } |
|
54 }; |
|
55 |
|
56 static void sendRunningInd(); |
|
57 static void sendTerminatedInd(); |
|
58 static void sendGetRuntimeAttributes(); |
|
59 |
|
60 void runtime(const int& uSecDelayBeforeRunningInd, |
|
61 const int& numOfRunningInds, |
|
62 const bool& getRuntimeAttributes, |
|
63 const bool& immediateExit, |
|
64 const bool& obeyTerminateReqs, |
|
65 const int& numOfTerminateInds, |
|
66 const bool& stayRunning) |
|
67 { |
|
68 if (uSecDelayBeforeRunningInd > 0) |
|
69 { |
|
70 usleep(uSecDelayBeforeRunningInd); |
|
71 } |
|
72 |
|
73 for (int runInds = 0 ; runInds < numOfRunningInds ; runInds++) |
|
74 { |
|
75 sendRunningInd(); |
|
76 } |
|
77 |
|
78 if (getRuntimeAttributes) |
|
79 { |
|
80 sendGetRuntimeAttributes(); |
|
81 } |
|
82 |
|
83 if (!immediateExit) |
|
84 { |
|
85 do |
|
86 { |
|
87 monitor->wait(); |
|
88 } |
|
89 while (!obeyTerminateReqs); |
|
90 } |
|
91 |
|
92 for (int termInds = 0; termInds < numOfTerminateInds ; termInds++) |
|
93 { |
|
94 sendTerminatedInd(); |
|
95 } |
|
96 |
|
97 if (stayRunning) |
|
98 { |
|
99 while (true) |
|
100 { |
|
101 monitor->wait(); |
|
102 } |
|
103 } |
|
104 } |
|
105 |
|
106 int main(int ac, char** av) |
|
107 { |
|
108 monitor = Monitor::createMonitor(); |
|
109 |
|
110 rtCommsListener listener; |
|
111 comms.registerDefaultListener(&listener); |
|
112 comms.connect(IPC_ADDRESS_JAVA_CAPTAIN_C); |
|
113 |
|
114 printf("we have liftoff\n"); |
|
115 |
|
116 for (int i = 0 ; i<ac ; ++i) |
|
117 { |
|
118 printf("%d:%s ", i, av[i]); |
|
119 } |
|
120 printf("\n"); |
|
121 |
|
122 uid = Uid(java::util::JavaCommonUtils::utf8ToWstring(av[3])); |
|
123 printf("%s used for launching\n", av[3]); |
|
124 |
|
125 bool getRuntimeAttributes = false; |
|
126 if (ac > 4 && (std::string(av[4]) == "-debug")) |
|
127 { |
|
128 printf("getRuntimeAttributes -> true\n"); |
|
129 getRuntimeAttributes = true; |
|
130 } |
|
131 |
|
132 // startup sequence : running_ind 1x |
|
133 // runtime behaviour: stays running |
|
134 // exit sequence : sends terminate_ind 1x -> exits |
|
135 //const Uid uid_normal1(L"normal1"); |
|
136 if (uid == uid_normal1 || |
|
137 uid == uid_push1) |
|
138 { |
|
139 runtime(500000, // uSecDelayBeforeRunningInd |
|
140 1, // numOfRunningInds |
|
141 getRuntimeAttributes, |
|
142 false, // immediateExit |
|
143 true, // obeyTerminateReqs |
|
144 1, // numOfTerminateInds |
|
145 false); // stayRunning |
|
146 } |
|
147 |
|
148 // startup sequence : running_ind 2x (no delay in between) |
|
149 // runtime behaviour: stays running |
|
150 // exit sequence : sends terminate_ind 1x -> exits |
|
151 //const Uid uid_normal2(L"normal2"); |
|
152 else if (uid == uid_normal2) |
|
153 { |
|
154 runtime(500000, // uSecDelayBeforeRunningInd |
|
155 2, // numOfRunningInds |
|
156 getRuntimeAttributes, |
|
157 false, // immediateExit |
|
158 true, // obeyTerminateReqs |
|
159 1, // numOfTerminateInds |
|
160 false); // stayRunning |
|
161 } |
|
162 |
|
163 // startup sequence : running_ind 2x (no delay) |
|
164 // runtime behaviour: stays running |
|
165 // exit sequence : sends terminate_ind 2x (no delay) -> exits |
|
166 //const Uid uid_normal3(L"normal3"); |
|
167 else if (uid == uid_normal3) |
|
168 { |
|
169 runtime(500000, //uSecDelayBeforeRunningInd |
|
170 2, // numOfRunningInds |
|
171 getRuntimeAttributes, |
|
172 false, // immediateExit |
|
173 true, // obeyTerminateReqs |
|
174 2, // numOfTerminateInds |
|
175 false); // stayRunning |
|
176 } |
|
177 // startup sequence : running_ind 1x no delay |
|
178 // runtime behaviour: stays running |
|
179 // exit sequence : sends terminate_ind 1x -> exits |
|
180 //const Uid uid_normal1(L"normal4"); |
|
181 else if (uid == uid_normal4) |
|
182 { |
|
183 runtime(0, // uSecDelayBeforeRunningInd |
|
184 1, // numOfRunningInds |
|
185 getRuntimeAttributes, |
|
186 false, // immediateExit |
|
187 true, // obeyTerminateReqs |
|
188 1, // numOfTerminateInds |
|
189 false); // stayRunning |
|
190 } |
|
191 |
|
192 // startup sequence : running_ind 1x |
|
193 // runtime behaviour: stays running |
|
194 // exit sequence : sends nothing -> stays running |
|
195 else if (uid == uid_wont_terminate1) |
|
196 { |
|
197 runtime(500000, // uSecDelayBeforeRunningInd |
|
198 1, // numOfRunningInds |
|
199 getRuntimeAttributes, |
|
200 false, // immediateExit |
|
201 false, // obeyTerminateReqs |
|
202 0, // numOfTerminateInds |
|
203 true); // stayRunning |
|
204 } |
|
205 |
|
206 // startup sequence : running_ind 1x |
|
207 // runtime behaviour: stays running |
|
208 // exit sequence : sends terminate_ind but stays running |
|
209 else if (uid == uid_wont_terminate2) |
|
210 { |
|
211 runtime(500000, // uSecDelayBeforeRunningInd |
|
212 1, // numOfRunningInds |
|
213 getRuntimeAttributes, |
|
214 false, // immediateExit |
|
215 false, // obeyTerminateReqs |
|
216 1, // numOfTerminateInds |
|
217 true); // stayRunning |
|
218 } |
|
219 |
|
220 // startup sequence : running_ind 0x |
|
221 // runtime behaviour: exit immediately |
|
222 // exit sequence : sends terminate_ind 1x -> exits |
|
223 //const Uid uid_premature_exit1(L"premature_exit1"); |
|
224 else if (uid == uid_premature_exit1) |
|
225 { |
|
226 runtime(500000, //uSecDelayBeforeRunningInd |
|
227 0, // numOfRunningInds |
|
228 getRuntimeAttributes, |
|
229 true, // immediateExit |
|
230 true, // obeyTerminateReqs |
|
231 1, // numOfTerminateInds |
|
232 false); // stayRunning |
|
233 } |
|
234 |
|
235 // startup sequence : running_ind 1x |
|
236 // runtime behaviour: exit immediately |
|
237 // exit sequence : sends terminate_ind 1x -> exits |
|
238 //const Uid uid_premature_exit2(L"premature_exit2"); |
|
239 else if (uid == uid_premature_exit2) |
|
240 { |
|
241 runtime(500000, //uSecDelayBeforeRunningInd |
|
242 1, // numOfRunningInds |
|
243 getRuntimeAttributes, |
|
244 true, // immediateExit |
|
245 true, // obeyTerminateReqs |
|
246 1, // numOfTerminateInds |
|
247 false); // stayRunning |
|
248 } |
|
249 |
|
250 // startup sequence : running_ind 1x |
|
251 // runtime behaviour: exit immediately |
|
252 // exit sequence : sends nothing -> exits |
|
253 //const Uid uid_premature_exit3(L"premature_exit3"); |
|
254 else if (uid == uid_premature_exit3) |
|
255 { |
|
256 runtime(500000, //uSecDelayBeforeRunningInd |
|
257 1, // numOfRunningInds |
|
258 getRuntimeAttributes, |
|
259 true, // immediateExit |
|
260 true, // obeyTerminateReqs |
|
261 0, // numOfTerminateInds |
|
262 false); // stayRunning |
|
263 } |
|
264 |
|
265 comms.disconnect(); |
|
266 |
|
267 delete monitor; |
|
268 |
|
269 puts("Exiting"); |
|
270 |
|
271 return 0; |
|
272 } |
|
273 |
|
274 void sendRunningInd() |
|
275 { |
|
276 CommsMessage msg; |
|
277 setApplicationRunningIndParams(msg, uid, 0); |
|
278 comms.send(msg); |
|
279 } |
|
280 |
|
281 void sendTerminatedInd() |
|
282 { |
|
283 CommsMessage msg; |
|
284 setApplicationTerminatedIndParams(msg, uid, 0); |
|
285 comms.send(msg); |
|
286 } |
|
287 |
|
288 void sendGetRuntimeAttributes() |
|
289 { |
|
290 CommsMessage msg; |
|
291 setGetExtraArguments(msg); |
|
292 comms.send(msg); |
|
293 } |