Commit | Line | Data |
---|---|---|
d44e3c4f | 1 | /****************************************************************************** |
2 | * Copyright (c) 2000-2016 Ericsson Telecom AB | |
3 | * All rights reserved. This program and the accompanying materials | |
4 | * are made available under the terms of the Eclipse Public License v1.0 | |
5 | * which accompanies this distribution, and is available at | |
6 | * http://www.eclipse.org/legal/epl-v10.html | |
7 | * | |
8 | * Contributors: | |
9 | * Baji, Laszlo | |
10 | * Balasko, Jeno | |
11 | * Lovassy, Arpad | |
12 | * | |
13 | ******************************************************************************/ | |
970ed795 EL |
14 | #include "jnimw.h" |
15 | #include "org_eclipse_titan_executor_jni_JNIMiddleWare.h" | |
16 | #include <sys/socket.h> | |
17 | #include <netinet/in.h> | |
18 | #include <arpa/inet.h> | |
19 | #include "../core/Textbuf.hh" | |
20 | #include "../common/memory.h" | |
21 | #include "../common/license.h" | |
22 | #include "../common/version.h" | |
23 | #include <string.h> | |
24 | #include <stdlib.h> | |
25 | ||
26 | ||
27 | using mctr::MainController; | |
28 | using namespace jnimw; | |
29 | ||
30 | JNIEXPORT jlong JNICALL Java_org_eclipse_titan_executor_jni_JNIMiddleWare_init(JNIEnv *, jobject, jint max_ptcs) | |
31 | { | |
32 | Jnimw *userInterface; | |
33 | userInterface = new Jnimw(); | |
34 | Jnimw::userInterface = userInterface; | |
35 | MainController::initialize(*userInterface, (int)max_ptcs); | |
36 | return (jlong)userInterface; | |
37 | } | |
38 | ||
39 | JNIEXPORT void JNICALL Java_org_eclipse_titan_executor_jni_JNIMiddleWare_terminate(JNIEnv *, jobject) | |
40 | { | |
41 | MainController::terminate(); | |
42 | delete Jnimw::userInterface; | |
43 | Jnimw::userInterface = NULL; | |
44 | } | |
45 | ||
46 | JNIEXPORT void JNICALL Java_org_eclipse_titan_executor_jni_JNIMiddleWare_add_1host(JNIEnv *env, jobject, jstring group_name, jstring host_name) | |
47 | { | |
48 | // Fix for TR HO56282. | |
49 | if (!Jnimw::userInterface) | |
50 | return; | |
51 | jboolean iscopy_grp; | |
52 | jboolean iscopy_hst; | |
53 | const char *grp_name = env->GetStringUTFChars(group_name, &iscopy_grp); | |
54 | const char *hst_name = env->GetStringUTFChars(host_name, &iscopy_hst); | |
55 | MainController::add_host(grp_name, hst_name); | |
56 | env->ReleaseStringUTFChars(group_name, grp_name); | |
57 | env->ReleaseStringUTFChars(host_name, hst_name); | |
58 | } | |
59 | ||
60 | JNIEXPORT void JNICALL Java_org_eclipse_titan_executor_jni_JNIMiddleWare_assign_1component(JNIEnv *env, jobject, jstring host_or_group, jstring component_id) | |
61 | { | |
62 | // Fix for TR HO56282. | |
63 | if (!Jnimw::userInterface) | |
64 | return; | |
65 | jboolean iscopy_hog; | |
66 | jboolean iscopy_cid; | |
67 | const char *hog = env->GetStringUTFChars(host_or_group, &iscopy_hog); | |
68 | const char *cid = env->GetStringUTFChars(component_id, &iscopy_cid); | |
69 | MainController::assign_component(hog, cid); | |
70 | env->ReleaseStringUTFChars(host_or_group, hog); | |
71 | env->ReleaseStringUTFChars(component_id, cid); | |
72 | } | |
73 | ||
74 | JNIEXPORT void JNICALL Java_org_eclipse_titan_executor_jni_JNIMiddleWare_destroy_1host_1groups(JNIEnv *, jobject) | |
75 | { | |
76 | // Fix for TR HO56282. | |
77 | if (!Jnimw::userInterface) | |
78 | return; | |
79 | MainController::destroy_host_groups(); | |
80 | } | |
81 | ||
82 | JNIEXPORT void JNICALL Java_org_eclipse_titan_executor_jni_JNIMiddleWare_set_1kill_1timer(JNIEnv *, jobject, jdouble timer_val) | |
83 | { | |
84 | // Fix for TR HO56282. | |
85 | if (!Jnimw::userInterface) | |
86 | return; | |
87 | MainController::set_kill_timer((double)timer_val); | |
88 | } | |
89 | ||
90 | JNIEXPORT jint JNICALL Java_org_eclipse_titan_executor_jni_JNIMiddleWare_start_1session(JNIEnv *env, jobject, jstring local_address, jint tcp_port, jboolean unixdomainsocketenabled) | |
91 | { | |
92 | // Fix for TR HO56282. | |
93 | if (!Jnimw::userInterface) | |
94 | return (jint)-1; | |
95 | jboolean iscopy; | |
96 | const char *local_addr = env->GetStringUTFChars(local_address, &iscopy); | |
97 | if (strcmp(local_addr, "NULL") == 0) { | |
98 | env->ReleaseStringUTFChars(local_address, local_addr); | |
99 | local_addr = NULL; | |
100 | } | |
101 | unsigned short tcp_listen_port = (unsigned short)tcp_port; | |
102 | int ret = MainController::start_session(local_addr, tcp_listen_port, unixdomainsocketenabled); | |
103 | if (local_addr != NULL) env->ReleaseStringUTFChars(local_address, local_addr); | |
104 | return (jint)ret; | |
105 | } | |
106 | ||
107 | JNIEXPORT void JNICALL Java_org_eclipse_titan_executor_jni_JNIMiddleWare_shutdown_1session(JNIEnv *, jobject) | |
108 | { | |
109 | // Fix for TR HO56282. | |
110 | if (!Jnimw::userInterface) | |
111 | return; | |
112 | MainController::shutdown_session(); | |
113 | } | |
114 | ||
115 | /** | |
116 | * ASYNCHRONOUS | |
117 | * Configure MainController and HCs. | |
118 | * It is also known as "Set parameter" operation. | |
119 | * | |
120 | * It can be called in the following states: | |
121 | * MC_LISTENING -> MC_LISTENING_CONFIGURED will be the next state, when configuring operation is finished | |
122 | * MC_LISTENING_CONFIGURED -> MC_LISTENING_CONFIGURED will be the next state, when configuring operation is finished | |
123 | * MC_HC_CONNECTED -> MC_CONFIGURING immediately and MC_ACTIVE when configuring operation is finished | |
124 | * | |
125 | * @param env Pointer to the caller java environment (mandatory parameter of every JNI function) | |
126 | * @param jobject The caller java object (mandatory parameter of every JNI function) | |
127 | * @param config_file config string, generated from the config file by removing unnecessary parts. It can be empty string, and also null. | |
128 | * Generating config string can be done in 2 ways: | |
129 | * by "hand" (if the parameter is not empty string and not null): | |
130 | * on the java side, and pass it as a parameter, for an example see JniExecutor.DEFAULT_CONFIG_STRING or BaseExecutor.generateCfgString() | |
131 | * by MainController (if the parameter is empty string or null): | |
132 | * call set_cfg_file() after init() with the cfg file, and let MainController process it and create the config string, | |
133 | * and then config() can be called with empty string or null as a parameter, which means that config string from MainController config data will be used. | |
134 | * | |
135 | * NOTE: Function comment is here, because function declaration is in org_eclipse_titan_executor_jni_JNIMiddleWare.h, which is generated. | |
136 | */ | |
137 | JNIEXPORT void JNICALL Java_org_eclipse_titan_executor_jni_JNIMiddleWare_configure(JNIEnv *env, jobject, jstring config_file) | |
138 | { | |
139 | // Fix for TR HO56282. | |
140 | if (!Jnimw::userInterface) | |
141 | return; | |
142 | jboolean iscopy; | |
143 | if (config_file == NULL || env->GetStringLength( config_file ) == 0 ) { | |
144 | // use config string, which was generated by MainController | |
145 | MainController::configure(Jnimw::mycfg.config_read_buffer); | |
146 | } | |
147 | else { | |
148 | const char *conf_file = env->GetStringUTFChars(config_file, &iscopy); | |
149 | MainController::configure(conf_file); | |
150 | env->ReleaseStringUTFChars(config_file, conf_file); | |
151 | } | |
152 | } | |
153 | ||
154 | /** | |
155 | * The name of the config file is sent here for syntactic and semantic analysis. | |
156 | * The result config string is needed by start_session() and configure(). | |
157 | * Result is stored in Jnimw::mycfg. | |
158 | * We need the following info from it: | |
159 | * config_read_buffer: passed to configure() if parameter is an empty string | |
160 | * local_address: needed by the java side for start_session() and starting the HC, it is read by calling get_mc_host() | |
161 | * tcp_listen_port: needed by the java side for start_session(), it is read by calling get_port() | |
162 | * kill_timer: processed in this function | |
163 | * group_list: processed in this function | |
164 | * component_list: processed in this function | |
165 | * This code is based on the following code: Cli.cc: Cli::enterloop() | |
166 | * | |
167 | * @param env Pointer to the caller java environment (mandatory parameter of every JNI function) | |
168 | * @param jobject The caller java object (mandatory parameter of every JNI function) | |
169 | * @param conf_file_name The configuration file name of the TTCN-3 test project | |
170 | * | |
171 | * NOTE: Function comment is here, because function declaration is in org_eclipse_titan_executor_jni_JNIMiddleWare.h, which is generated. | |
172 | */ | |
173 | JNIEXPORT void JNICALL Java_org_eclipse_titan_executor_jni_JNIMiddleWare_set_1cfg_1file(JNIEnv *env, jobject, jstring config_file_name) | |
174 | { | |
175 | if (!Jnimw::userInterface) | |
176 | return; | |
177 | jboolean iscopy; | |
178 | if (config_file_name == NULL) | |
179 | return; | |
180 | const char *conf_file_name = env->GetStringUTFChars(config_file_name, &iscopy); | |
181 | ||
182 | if (process_config_read_file(conf_file_name, &Jnimw::mycfg)) { | |
183 | MainController::error("Error was found in the configuration file. Exiting."); | |
184 | } | |
185 | else { | |
186 | MainController::set_kill_timer(Jnimw::mycfg.kill_timer); | |
187 | ||
188 | for (int i = 0; i < Jnimw::mycfg.group_list_len; ++i) { | |
189 | const group_item& item = Jnimw::mycfg.group_list[i]; | |
190 | MainController::add_host( item.group_name, item.host_name ); | |
191 | } | |
192 | ||
193 | for (int i = 0; i < Jnimw::mycfg.component_list_len; ++i) { | |
194 | const component_item& item = Jnimw::mycfg.component_list[i]; | |
195 | MainController::assign_component( item.host_or_group, item.component ); | |
196 | } | |
197 | } | |
198 | ||
199 | env->ReleaseStringUTFChars(config_file_name, conf_file_name); | |
200 | } | |
201 | ||
202 | /** | |
203 | * Local host address for start_session() and starting the HC | |
204 | * This will contain valid information after successful run of Java_org_eclipse_titan_executor_jni_JNIMiddleWare_set_1cfg_1file() | |
205 | * | |
206 | * @param env Pointer to the caller java environment (mandatory parameter of every JNI function) | |
207 | * @param jobject The caller java object (mandatory parameter of every JNI function) | |
208 | * @return Local host address | |
209 | * | |
210 | * NOTE: Function comment is here, because function declaration is in org_eclipse_titan_executor_jni_JNIMiddleWare.h, which is generated. | |
211 | */ | |
212 | JNIEXPORT jstring JNICALL Java_org_eclipse_titan_executor_jni_JNIMiddleWare_get_1mc_1host(JNIEnv *env, jobject) | |
213 | { | |
214 | return env->NewStringUTF( Jnimw::mycfg.local_addr != NULL ? Jnimw::mycfg.local_addr : "NULL" ); | |
215 | } | |
216 | ||
217 | /** | |
218 | * TCP listen port for start_session() | |
219 | * This will contain valid information after successful run of Java_org_eclipse_titan_executor_jni_JNIMiddleWare_set_1cfg_1file() | |
220 | * | |
221 | * @param env Pointer to the caller java environment (mandatory parameter of every JNI function) | |
222 | * @param jobject The caller java object (mandatory parameter of every JNI function) | |
223 | * @return TCP listen port | |
224 | * | |
225 | * NOTE: Function comment is here, because function declaration is in org_eclipse_titan_executor_jni_JNIMiddleWare.h, which is generated. | |
226 | */ | |
227 | JNIEXPORT jint JNICALL Java_org_eclipse_titan_executor_jni_JNIMiddleWare_get_1port(JNIEnv *, jobject) | |
228 | { | |
229 | return (jint)Jnimw::mycfg.tcp_listen_port; | |
230 | } | |
231 | ||
232 | JNIEXPORT void JNICALL Java_org_eclipse_titan_executor_jni_JNIMiddleWare_create_1mtc(JNIEnv *, jobject, jint host_index) | |
233 | { | |
234 | // Fix for TR HO56282. | |
235 | if (!Jnimw::userInterface) | |
236 | return; | |
237 | MainController::create_mtc((int)host_index); | |
238 | } | |
239 | ||
240 | JNIEXPORT void JNICALL Java_org_eclipse_titan_executor_jni_JNIMiddleWare_exit_1mtc(JNIEnv *, jobject) | |
241 | { | |
242 | // Fix for TR HO56282. | |
243 | if (!Jnimw::userInterface) | |
244 | return; | |
245 | MainController::exit_mtc(); | |
246 | } | |
247 | ||
248 | JNIEXPORT void JNICALL Java_org_eclipse_titan_executor_jni_JNIMiddleWare_execute_1control(JNIEnv *env, jobject, jstring module_name) | |
249 | { | |
250 | // Fix for TR HO56282. | |
251 | if (!Jnimw::userInterface) | |
252 | return; | |
253 | jboolean iscopy; | |
254 | const char *mod_name = env->GetStringUTFChars(module_name, &iscopy); | |
255 | MainController::execute_control(mod_name); | |
256 | env->ReleaseStringUTFChars(module_name, mod_name); | |
257 | } | |
258 | ||
259 | JNIEXPORT void JNICALL Java_org_eclipse_titan_executor_jni_JNIMiddleWare_execute_1testcase(JNIEnv *env, jobject, jstring module_name, jstring testcase_name) | |
260 | { | |
261 | // Fix for TR HO56282. | |
262 | if (!Jnimw::userInterface) | |
263 | return; | |
264 | jboolean iscopy_mod; | |
265 | jboolean iscopy_tes; | |
266 | const char *mod_name = env->GetStringUTFChars(module_name, &iscopy_mod); | |
267 | const char *testc_name = env->GetStringUTFChars(testcase_name, &iscopy_tes); | |
268 | MainController::execute_testcase(mod_name, testc_name); | |
269 | env->ReleaseStringUTFChars(module_name, mod_name); | |
270 | env->ReleaseStringUTFChars(testcase_name, testc_name); | |
271 | } | |
272 | ||
273 | /** | |
274 | * Gets the length of the execute list. | |
275 | * @param env Pointer to the caller java environment (mandatory parameter of every JNI function) | |
276 | * @param jobject The caller java object (mandatory parameter of every JNI function) | |
277 | * @return The length of the execute list, | |
278 | * which is defined in the [EXECUTE] section in the configuration file. | |
279 | * 0, if there is no [EXECUTE] section in the configuration file. | |
280 | * | |
281 | * NOTE: Function comment is here, because function declaration is in org_eclipse_titan_executor_jni_JNIMiddleWare.h, which is generated. | |
282 | */ | |
283 | JNIEXPORT jint JNICALL Java_org_eclipse_titan_executor_jni_JNIMiddleWare_get_1execute_1cfg_1len(JNIEnv *env, jobject) | |
284 | { | |
285 | return (jint)Jnimw::mycfg.execute_list_len; | |
286 | } | |
287 | ||
288 | /** | |
289 | * Executes the index-th element form the execute list, | |
290 | * which is defined in the [EXECUTE] section in the configuration file. | |
291 | * Based on Cli::executeFromList() | |
292 | * @param env Pointer to the caller java environment (mandatory parameter of every JNI function) | |
293 | * @param jobject The caller java object (mandatory parameter of every JNI function) | |
294 | * @param index The test index from the execute list | |
295 | * | |
296 | * NOTE: Function comment is here, because function declaration is in org_eclipse_titan_executor_jni_JNIMiddleWare.h, which is generated. | |
297 | */ | |
298 | JNIEXPORT void JNICALL Java_org_eclipse_titan_executor_jni_JNIMiddleWare_execute_1cfg(JNIEnv *env, jobject, jint index) | |
299 | { | |
300 | if (!Jnimw::userInterface) | |
301 | return; | |
302 | if ( index < 0 || index >= Jnimw::mycfg.execute_list_len ) { | |
303 | MainController::error("Java_org_eclipse_titan_executor_jni_JNIMiddleWare_execute_1cfg(): invalid argument: index"); | |
304 | return; | |
305 | } | |
306 | const execute_list_item& item = Jnimw::mycfg.execute_list[ index ]; | |
307 | if ( item.testcase_name == NULL ) { | |
308 | MainController::execute_control( item.module_name ); | |
309 | } else if ( !strcmp( item.testcase_name, "*" ) ) { | |
310 | MainController::execute_testcase( item.module_name, NULL ); | |
311 | } else { | |
312 | MainController::execute_testcase( item.module_name, item.testcase_name ); | |
313 | } | |
314 | } | |
315 | ||
316 | JNIEXPORT void JNICALL Java_org_eclipse_titan_executor_jni_JNIMiddleWare_stop_1after_1testcase(JNIEnv *, jobject, jboolean new_state) | |
317 | { | |
318 | // Fix for TR HO56282. | |
319 | if (!Jnimw::userInterface) | |
320 | return; | |
321 | MainController::stop_after_testcase((bool)new_state); | |
322 | } | |
323 | ||
324 | JNIEXPORT void JNICALL Java_org_eclipse_titan_executor_jni_JNIMiddleWare_continue_1testcase(JNIEnv *, jobject) | |
325 | { | |
326 | // Fix for TR HO56282. | |
327 | if (!Jnimw::userInterface) | |
328 | return; | |
329 | MainController::continue_testcase(); | |
330 | } | |
331 | ||
332 | JNIEXPORT void JNICALL Java_org_eclipse_titan_executor_jni_JNIMiddleWare_stop_1execution(JNIEnv *, jobject) | |
333 | { | |
334 | // Fix for TR HO56282. | |
335 | if (!Jnimw::userInterface) | |
336 | return; | |
337 | MainController::stop_execution(); | |
338 | } | |
339 | ||
340 | JNIEXPORT jobject JNICALL Java_org_eclipse_titan_executor_jni_JNIMiddleWare_get_1state(JNIEnv *env, jobject) | |
341 | { | |
342 | jclass cls = env->FindClass("org/eclipse/titan/executor/jni/McStateEnum"); | |
343 | if (cls == NULL) { | |
344 | printf("Can't find class org.eclipse.titan.executor.jni.McStateEnum\n"); | |
345 | } | |
346 | jfieldID fid = 0; | |
347 | jobject ret; | |
348 | // Fix for TR HO56282. | |
349 | // MC's get_state() calls lock(), but the mutex is destroyed already at this | |
350 | // point from JNI code... | |
351 | if (!Jnimw::userInterface) { | |
352 | fid = env->GetStaticFieldID(cls, "MC_INACTIVE", | |
353 | "Lorg/eclipse/titan/executor/jni/McStateEnum;"); | |
354 | if (fid == 0) { | |
355 | printf("Can't find field MC_INACTIVE\n"); | |
356 | } | |
357 | } else { | |
358 | switch (MainController::get_state()) { | |
359 | case mctr::MC_INACTIVE: | |
360 | fid = env->GetStaticFieldID(cls, "MC_INACTIVE", | |
361 | "Lorg/eclipse/titan/executor/jni/McStateEnum;"); | |
362 | if (fid == 0) { | |
363 | printf("Can't find field MC_INACTIVE\n"); | |
364 | } | |
365 | break; | |
366 | case mctr::MC_LISTENING: | |
367 | fid = env->GetStaticFieldID(cls, "MC_LISTENING", | |
368 | "Lorg/eclipse/titan/executor/jni/McStateEnum;"); | |
369 | if (fid == 0) { | |
370 | printf("Can't find field MC_LISTENING\n"); | |
371 | } | |
372 | break; | |
373 | case mctr::MC_LISTENING_CONFIGURED: | |
374 | fid = env->GetStaticFieldID(cls, "MC_LISTENING_CONFIGURED", | |
375 | "Lorg/eclipse/titan/executor/jni/McStateEnum;"); | |
376 | if (fid == 0) { | |
377 | printf("Can't find field MC_LISTENING_CONFIGURED\n"); | |
378 | } | |
379 | break; | |
380 | case mctr::MC_HC_CONNECTED: | |
381 | fid = env->GetStaticFieldID(cls, "MC_HC_CONNECTED", | |
382 | "Lorg/eclipse/titan/executor/jni/McStateEnum;"); | |
383 | if (fid == 0) { | |
384 | printf("Can't find field MC_HC_CONNECTED\n"); | |
385 | } | |
386 | break; | |
387 | case mctr::MC_CONFIGURING: | |
388 | fid = env->GetStaticFieldID(cls, "MC_CONFIGURING", | |
389 | "Lorg/eclipse/titan/executor/jni/McStateEnum;"); | |
390 | if (fid == 0) { | |
391 | printf("Can't find field MC_CONFIGURING\n"); | |
392 | } | |
393 | break; | |
394 | case mctr::MC_ACTIVE: | |
395 | fid = env->GetStaticFieldID(cls, "MC_ACTIVE", | |
396 | "Lorg/eclipse/titan/executor/jni/McStateEnum;"); | |
397 | if (fid == 0) { | |
398 | printf("Can't find field MC_ACTIVE\n"); | |
399 | } | |
400 | break; | |
401 | case mctr::MC_SHUTDOWN: | |
402 | fid = env->GetStaticFieldID(cls, "MC_SHUTDOWN", | |
403 | "Lorg/eclipse/titan/executor/jni/McStateEnum;"); | |
404 | if (fid == 0) { | |
405 | printf("Can't find field MC_SHUTDOWN\n"); | |
406 | } | |
407 | break; | |
408 | case mctr::MC_CREATING_MTC: | |
409 | fid = env->GetStaticFieldID(cls, "MC_CREATING_MTC", | |
410 | "Lorg/eclipse/titan/executor/jni/McStateEnum;"); | |
411 | if (fid == 0) { | |
412 | printf("Can't find field MC_CREATING_MTC\n"); | |
413 | } | |
414 | break; | |
415 | case mctr::MC_READY: | |
416 | fid = env->GetStaticFieldID(cls, "MC_READY", | |
417 | "Lorg/eclipse/titan/executor/jni/McStateEnum;"); | |
418 | if (fid == 0) { | |
419 | printf("Can't find field MC_READY\n"); | |
420 | } | |
421 | break; | |
422 | case mctr::MC_TERMINATING_MTC: | |
423 | fid = env->GetStaticFieldID(cls, "MC_TERMINATING_MTC", | |
424 | "Lorg/eclipse/titan/executor/jni/McStateEnum;"); | |
425 | if (fid == 0) { | |
426 | printf("Can't find field MC_TERMINATING_MTC\n"); | |
427 | } | |
428 | break; | |
429 | case mctr::MC_EXECUTING_CONTROL: | |
430 | fid = env->GetStaticFieldID(cls, "MC_EXECUTING_CONTROL", | |
431 | "Lorg/eclipse/titan/executor/jni/McStateEnum;"); | |
432 | if (fid == 0) { | |
433 | printf("Can't find field MC_EXECUTING_CONTROL\n"); | |
434 | } | |
435 | break; | |
436 | case mctr::MC_EXECUTING_TESTCASE: | |
437 | fid = env->GetStaticFieldID(cls, "MC_EXECUTING_TESTCASE", | |
438 | "Lorg/eclipse/titan/executor/jni/McStateEnum;"); | |
439 | if (fid == 0) { | |
440 | printf("Can't find field MC_EXECUTING_TESTCASE\n"); | |
441 | } | |
442 | break; | |
443 | case mctr::MC_TERMINATING_TESTCASE: | |
444 | fid = env->GetStaticFieldID(cls, "MC_TERMINATING_TESTCASE", | |
445 | "Lorg/eclipse/titan/executor/jni/McStateEnum;"); | |
446 | if (fid == 0) { | |
447 | printf("Can't find field MC_TERMINATING_TESTCASE\n"); | |
448 | } | |
449 | break; | |
450 | case mctr::MC_PAUSED: | |
451 | fid = env->GetStaticFieldID(cls, "MC_PAUSED", | |
452 | "Lorg/eclipse/titan/executor/jni/McStateEnum;"); | |
453 | if (fid == 0) { | |
454 | printf("Can't find field MC_PAUSED\n"); | |
455 | } | |
456 | break; | |
457 | default: | |
458 | printf("Unknown mc_state_enum state\n"); | |
459 | } | |
460 | } | |
461 | ret = env->GetStaticObjectField(cls, fid); | |
462 | env->ExceptionClear(); | |
463 | return ret; | |
464 | } | |
465 | ||
466 | JNIEXPORT jboolean JNICALL Java_org_eclipse_titan_executor_jni_JNIMiddleWare_get_1stop_1after_1testcase(JNIEnv *, jobject) | |
467 | { | |
468 | // Fix for TR HO56282. | |
469 | if (!Jnimw::userInterface) | |
470 | return (jboolean)true; | |
471 | return (jboolean)MainController::get_stop_after_testcase(); | |
472 | } | |
473 | ||
474 | JNIEXPORT jint JNICALL Java_org_eclipse_titan_executor_jni_JNIMiddleWare_get_1nof_1hosts(JNIEnv *, jobject) | |
475 | { | |
476 | // Fix for TR HO56282. | |
477 | if (!Jnimw::userInterface) | |
478 | return (jint)-1; | |
479 | return (jint)MainController::get_nof_hosts(); | |
480 | } | |
481 | ||
482 | JNIEXPORT jobject JNICALL Java_org_eclipse_titan_executor_jni_JNIMiddleWare_get_1host_1data(JNIEnv *env, jobject, jint host_index) | |
483 | { | |
484 | // Fix for TR HO56282. | |
485 | if (!Jnimw::userInterface) | |
486 | return NULL; | |
487 | mctr::host_struct *hs = MainController::get_host_data((int)host_index); | |
488 | if (hs == NULL) return NULL; | |
489 | IPAddress *ip_addr = hs->ip_addr; | |
490 | const char *hostname = hs->hostname; | |
491 | const char *hostname_local = hs->hostname_local; | |
492 | const char *machine_type = hs->machine_type; | |
493 | const char *system_name = hs->system_name; | |
494 | const char *system_release = hs->system_release; | |
495 | const char *system_version = hs->system_version; | |
496 | boolean *transport_supported = hs->transport_supported; | |
497 | const char *log_source = hs->log_source; | |
498 | mctr::hc_state_enum hc_state = hs->hc_state; | |
499 | int hc_fd = hs->hc_fd; | |
500 | Text_Buf *text_buf = hs->text_buf; | |
501 | int n_components = hs->n_components; | |
502 | component *components = hs->components; | |
503 | mctr::string_set allowed_components = hs->allowed_components; | |
504 | bool all_components_allowed = hs->all_components_allowed; | |
505 | int n_active_components = hs->n_active_components; | |
506 | ||
507 | /*// --- DEBUG --- filling test data | |
508 | in_addr t_i; | |
509 | t_i.s_addr = 121345; | |
510 | in_addr ip_addr = t_i; | |
511 | const char *hostname = "test hostname"; | |
512 | const char *hostname_local = "test hostname_local"; | |
513 | const char *machine_type = "test machine_type"; | |
514 | const char *system_name = "test system_name"; | |
515 | const char *system_release = "test system_release"; | |
516 | const char *system_version = "test system_version"; | |
517 | boolean test[3] = {true, true, false}; | |
518 | boolean *transport_supported = test; | |
519 | const char *log_source = "test log_source"; | |
520 | mctr::hc_state_enum hc_state = mctr::HC_CONFIGURING; | |
521 | int hc_fd = 8; | |
522 | Text_Buf *text_buf = new Text_Buf(); | |
523 | text_buf->push_string("test Text_Buf"); | |
524 | int n_components = 3; | |
525 | int test_i[3] = {2,4,5}; | |
526 | component *components = (component*) test_i; | |
527 | mctr::string_set s_set; | |
528 | s_set.n_elements = 3; | |
529 | char *t_stringarray[3] = {"test 1", "test 2", "test 3"}; | |
530 | s_set.elements = t_stringarray; | |
531 | mctr::string_set allowed_components = s_set; | |
532 | bool all_components_allowed = true; | |
533 | int n_active_components = 5; | |
534 | // --- END OF DEBUG ---*/ | |
535 | ||
536 | // creating HostStruct | |
537 | jclass cls = env->FindClass("org/eclipse/titan/executor/jni/HostStruct"); | |
538 | if( cls == NULL ) { | |
539 | printf("Can't find class org.eclipse.titan.executor.jni.HostStruct\n"); | |
540 | } | |
541 | jfieldID fid; | |
542 | jmethodID mid; | |
543 | jobject HostStruct; | |
544 | mid = env->GetMethodID(cls, "<init>", "(IIII)V"); | |
545 | HostStruct = env->NewObject(cls, mid, 3, text_buf->get_len(), n_components, allowed_components.n_elements); | |
546 | ||
547 | // processing struct fields | |
548 | // ip_addr | |
549 | const char *ipaddr = ip_addr->get_addr_str(); | |
550 | fid = env->GetFieldID(cls, "ip_addr", "Ljava/lang/String;"); | |
551 | if (fid == 0) { | |
552 | printf("Can't find field hostname\n"); | |
553 | } | |
554 | env->SetObjectField(HostStruct, fid, env->NewStringUTF(ipaddr)); | |
555 | ||
556 | // hostname | |
557 | fid = env->GetFieldID(cls, "hostname", "Ljava/lang/String;"); | |
558 | if (fid == 0) { | |
559 | printf("Can't find field hostname\n"); | |
560 | } | |
561 | env->SetObjectField(HostStruct, fid, env->NewStringUTF(hostname)); | |
562 | ||
563 | // hostname_local | |
564 | fid = env->GetFieldID(cls, "hostname_local", "Ljava/lang/String;"); | |
565 | if (fid == 0) { | |
566 | printf("Can't find field hostname_local\n"); | |
567 | } | |
568 | env->SetObjectField(HostStruct, fid, env->NewStringUTF(hostname_local)); | |
569 | ||
570 | // machine_type | |
571 | fid = env->GetFieldID(cls, "machine_type", "Ljava/lang/String;"); | |
572 | if (fid == 0) { | |
573 | printf("Can't find field machine_type\n"); | |
574 | } | |
575 | env->SetObjectField(HostStruct, fid, env->NewStringUTF(machine_type)); | |
576 | ||
577 | // system_name | |
578 | fid = env->GetFieldID(cls, "system_name", "Ljava/lang/String;"); | |
579 | if (fid == 0) { | |
580 | printf("Can't find field system_name\n"); | |
581 | } | |
582 | env->SetObjectField(HostStruct, fid, env->NewStringUTF(system_name)); | |
583 | ||
584 | // system_release | |
585 | fid = env->GetFieldID(cls, "system_release", "Ljava/lang/String;"); | |
586 | if (fid == 0) { | |
587 | printf("Can't find field system_release\n"); | |
588 | } | |
589 | env->SetObjectField(HostStruct, fid, env->NewStringUTF(system_release)); | |
590 | ||
591 | // system_version | |
592 | fid = env->GetFieldID(cls, "system_version", "Ljava/lang/String;"); | |
593 | if (fid == 0) { | |
594 | printf("Can't find field system_version\n"); | |
595 | } | |
596 | env->SetObjectField(HostStruct, fid, env->NewStringUTF(system_version)); | |
597 | ||
598 | // transport_supported | |
599 | fid = env->GetFieldID(cls, "transport_supported", "[Z"); | |
600 | if (fid == 0) { | |
601 | printf("Can't find field transport_supported\n"); | |
602 | } | |
603 | jbooleanArray TransportSupported = (jbooleanArray)env->GetObjectField(HostStruct, fid); | |
604 | env->SetBooleanArrayRegion(TransportSupported, (jsize)0, 3,(jboolean *)transport_supported); | |
605 | ||
606 | // log_source | |
607 | fid = env->GetFieldID(cls, "log_source", "Ljava/lang/String;"); | |
608 | if (fid == 0) { | |
609 | printf("Can't find field log_source\n"); | |
610 | } | |
611 | env->SetObjectField(HostStruct, fid, env->NewStringUTF(log_source)); | |
612 | ||
613 | // hc_state | |
614 | fid = env->GetFieldID(cls, "hc_state", "Lorg/eclipse/titan/executor/jni/HcStateEnum;"); | |
615 | if (fid == 0) { | |
616 | printf("Can't find field hc_state\n"); | |
617 | } | |
618 | ||
619 | jclass cls_hc = env->FindClass("org/eclipse/titan/executor/jni/HcStateEnum"); | |
620 | if( cls_hc == NULL ) { | |
621 | printf("Can't find class org.eclipse.titan.executor.jni.HcStateEnum\n"); | |
622 | } | |
623 | jfieldID fid_hc = 0; | |
624 | jobject ret; | |
625 | switch(hc_state) { | |
626 | case mctr::HC_IDLE: | |
627 | fid_hc = env->GetStaticFieldID(cls_hc, "HC_IDLE", "Lorg/eclipse/titan/executor/jni/HcStateEnum;"); | |
628 | if (fid_hc == 0) { | |
629 | printf("Can't find field HC_IDLE\n"); | |
630 | } | |
631 | break; | |
632 | case mctr::HC_CONFIGURING: | |
633 | fid_hc = env->GetStaticFieldID(cls_hc, "HC_CONFIGURING", "Lorg/eclipse/titan/executor/jni/HcStateEnum;"); | |
634 | if (fid_hc == 0) { | |
635 | printf("Can't find field HC_CONFIGURING\n"); | |
636 | } | |
637 | break; | |
638 | case mctr::HC_ACTIVE: | |
639 | fid_hc = env->GetStaticFieldID(cls_hc, "HC_ACTIVE", "Lorg/eclipse/titan/executor/jni/HcStateEnum;"); | |
640 | if (fid_hc == 0) { | |
641 | printf("Can't find field HC_ACTIVE\n"); | |
642 | } | |
643 | break; | |
644 | case mctr::HC_OVERLOADED: | |
645 | fid_hc = env->GetStaticFieldID(cls_hc, "HC_OVERLOADED", "Lorg/eclipse/titan/executor/jni/HcStateEnum;"); | |
646 | if (fid_hc == 0) { | |
647 | printf("Can't find field HC_OVERLOADED\n"); | |
648 | } | |
649 | break; | |
650 | case mctr::HC_CONFIGURING_OVERLOADED: | |
651 | fid_hc = env->GetStaticFieldID(cls_hc, "HC_CONFIGURING_OVERLOADED", "Lorg/eclipse/titan/executor/jni/HcStateEnum;"); | |
652 | if (fid_hc == 0) { | |
653 | printf("Can't find field HC_CONFIGURING_OVERLOADED\n"); | |
654 | } | |
655 | break; | |
656 | // ----------------------------------------------- 6-7 | |
657 | case mctr::HC_EXITING: | |
658 | fid_hc = env->GetStaticFieldID(cls_hc, "HC_EXITING", "Lorg/eclipse/titan/executor/jni/HcStateEnum;"); | |
659 | if (fid_hc == 0) { | |
660 | printf("Can't find field HC_EXITING\n"); | |
661 | } | |
662 | break; | |
663 | case mctr::HC_DOWN: | |
664 | fid_hc = env->GetStaticFieldID(cls_hc, "HC_DOWN", "Lorg/eclipse/titan/executor/jni/HcStateEnum;"); | |
665 | if (fid_hc == 0) { | |
666 | printf("Can't find field HC_DOWN\n"); | |
667 | } | |
668 | break; | |
669 | default: | |
670 | printf("Unknown hc_state_enum state\n"); | |
671 | } | |
672 | ret = env->GetStaticObjectField(cls_hc, fid_hc); | |
673 | env->ExceptionClear(); | |
674 | env->SetObjectField(HostStruct, fid, ret); | |
675 | ||
676 | // hc_fd | |
677 | fid = env->GetFieldID(cls, "hc_fd", "I"); | |
678 | if (fid == 0) { | |
679 | printf("Can't find field hc_fd\n"); | |
680 | } | |
681 | env->SetIntField(HostStruct, fid, (jint)hc_fd); | |
682 | ||
683 | // text_buf | |
684 | fid = env->GetFieldID(cls, "text_buf", "[B"); | |
685 | if (fid == 0) { | |
686 | printf("Can't find field text_buf\n"); | |
687 | } | |
688 | jbyteArray TextBuf = (jbyteArray)env->GetObjectField(HostStruct, fid); | |
689 | env->SetByteArrayRegion(TextBuf, (jsize)0, text_buf->get_len(), | |
690 | const_cast<jbyte *>((const jbyte *)text_buf->get_data())); | |
691 | ||
692 | // components | |
693 | fid = env->GetFieldID(cls, "components", "[I"); | |
694 | if (fid == 0) { | |
695 | printf("Can't find field components\n"); | |
696 | } | |
697 | ||
698 | jintArray Components = (jintArray)env->GetObjectField(HostStruct, fid); | |
699 | env->SetIntArrayRegion(Components, (jsize)0,n_components,(jint *)components); | |
700 | ||
701 | // allowed_components | |
702 | fid = env->GetFieldID(cls, "allowed_components", "[Ljava/lang/String;"); | |
703 | if (fid == 0) { | |
704 | printf("Can't find field allowed_components\n"); | |
705 | } | |
706 | jobjectArray allowedComponents = (jobjectArray) env->GetObjectField(HostStruct, fid); | |
707 | for(int i = 0; i < allowed_components.n_elements; i++) { | |
708 | env->SetObjectArrayElement(allowedComponents, i, env->NewStringUTF(allowed_components.elements[i])); | |
709 | } | |
710 | ||
711 | // all_components_allowed | |
712 | fid = env->GetFieldID(cls, "all_components_allowed", "Z"); | |
713 | if (fid == 0) { | |
714 | printf("Can't find field all_components_allowed\n"); | |
715 | } | |
716 | env->SetBooleanField(HostStruct, fid, (jboolean)all_components_allowed); | |
717 | ||
718 | // n_active_components | |
719 | fid = env->GetFieldID(cls, "n_active_components", "I"); | |
720 | if (fid == 0) { | |
721 | printf("Can't find field n_active_components\n"); | |
722 | } | |
723 | env->SetIntField(HostStruct, fid, (jint)n_active_components); | |
724 | ||
725 | return HostStruct; | |
726 | } | |
727 | ||
728 | JNIEXPORT jobject JNICALL Java_org_eclipse_titan_executor_jni_JNIMiddleWare_get_1component_1data(JNIEnv *env, jobject, jint component_reference) | |
729 | { | |
730 | // Fix for TR HO56282. | |
731 | if (!Jnimw::userInterface) | |
732 | return NULL; | |
733 | mctr::component_struct *cs = MainController::get_component_data((int)component_reference); | |
734 | if (cs == NULL) return NULL; | |
735 | ||
736 | // getting data from struct | |
737 | ||
738 | // If any of the pointers are NULL, we return null. | |
739 | // Some of the pointers may be NULL if its value is not initialized, | |
740 | // or temporarily set to NULL, like text_buf is NULL during the create MTC operation: it is set to NULL when create_mtc() is called, | |
741 | // and it will have valid data when asynchronous request of MTC creation is finished. | |
742 | // Reading component data makes sense only in the following states: | |
743 | // MC_READY, MC_EXECUTING_CONTROL, MC_EXECUTING_TESTCASE, MC_TERMINATING_TESTCASE, MC_PAUSED | |
744 | component comp_ref = cs->comp_ref; | |
745 | qualified_name comp_type = cs->comp_type; | |
746 | const char *comp_name = cs->comp_name; | |
747 | if ( NULL == comp_name ) { | |
748 | return NULL; | |
749 | } | |
750 | const char *log_source = cs->log_source; | |
751 | if ( NULL == log_source ) { | |
752 | return NULL; | |
753 | } | |
754 | mctr::host_struct *comp_location = cs->comp_location; | |
755 | if ( NULL == comp_location ) { | |
756 | return NULL; | |
757 | } | |
758 | mctr::tc_state_enum tc_state = cs->tc_state; | |
759 | verdicttype local_verdict = cs->local_verdict; | |
760 | int tc_fd = cs->tc_fd; | |
761 | Text_Buf *text_buf = cs->text_buf; | |
762 | if ( NULL == text_buf ) { | |
763 | return NULL; | |
764 | } | |
765 | qualified_name tc_fn_name = cs->tc_fn_name; | |
766 | const char *return_type = cs->return_type; | |
767 | if ( NULL == return_type ) { | |
768 | return NULL; | |
769 | } | |
770 | int return_value_len = cs->return_value_len; | |
771 | bool is_alive = cs->is_alive; | |
772 | bool stop_requested = cs->stop_requested; | |
773 | bool process_killed = cs->process_killed; | |
774 | ||
775 | /*// --- DEBUG --- filling test data | |
776 | component comp_ref = (component) 5; | |
777 | qualified_name comp_type; | |
778 | comp_type.module_name = "test module"; | |
779 | comp_type.definition_name = "test definition"; | |
780 | const char *comp_name = "test comp_name"; | |
781 | const char *log_source = "test log_source"; | |
782 | // --- DEBUG --- filling inner host_struct | |
783 | mctr::host_struct debug_comp_location; | |
784 | in_addr t_i; | |
785 | t_i.s_addr = 121345; | |
786 | debug_comp_location.ip_addr = t_i; | |
787 | debug_comp_location.hostname = "inner test hostname"; | |
788 | debug_comp_location.hostname_local = "inner test hostname_local"; | |
789 | debug_comp_location.machine_type = "inner test machine_type"; | |
790 | debug_comp_location.system_name = "inner test system_name"; | |
791 | debug_comp_location.system_release = "inner test system_release"; | |
792 | debug_comp_location.system_version = "inner test system_version"; | |
793 | boolean test[3] = {true, true, false}; | |
794 | debug_comp_location.transport_supported = test; | |
795 | debug_comp_location.log_source = "inner test log_source"; | |
796 | debug_comp_location.hc_state = mctr::HC_CONFIGURING; | |
797 | debug_comp_location.hc_fd = 8; | |
798 | debug_comp_location.text_buf = new Text_Buf(); | |
799 | debug_comp_location.text_buf->push_string("inner test Text_Buf"); | |
800 | debug_comp_location.n_components = 3; | |
801 | int test_i[3] = {2,4,5}; | |
802 | debug_comp_location.components = (component*) test_i; | |
803 | mctr::string_set s_set; | |
804 | s_set.n_elements = 3; | |
805 | char *t_stringarray[3] = {"inner test 1", "inner test 2", "inner test 3"}; | |
806 | s_set.elements = t_stringarray; | |
807 | debug_comp_location.allowed_components = s_set; | |
808 | debug_comp_location.all_components_allowed = true; | |
809 | debug_comp_location.n_active_components = 5; | |
810 | // --- END OF DEBUG host_struct --- | |
811 | mctr::host_struct *comp_location = &debug_comp_location; | |
812 | mctr::tc_state_enum tc_state = mctr::TC_INITIAL; | |
813 | verdicttype local_verdict = FAIL; | |
814 | int tc_fd = 7; | |
815 | Text_Buf *text_buf = new Text_Buf(); | |
816 | text_buf->push_string("test Text_Buf component"); | |
817 | qualified_name tc_fn_name; | |
818 | tc_fn_name.module_name = "test tc_fn_name module_name"; | |
819 | tc_fn_name.definition_name = "test tc_fn_name definition_name"; | |
820 | const char *return_type = "test return_type"; | |
821 | int return_value_len = 10; | |
822 | bool is_alive = true; | |
823 | bool stop_requested = false; | |
824 | bool process_killed = false; | |
825 | // --- END OF DEBUG ---*/ | |
826 | ||
827 | // creating ComponentStruct | |
828 | jclass cls = env->FindClass("org/eclipse/titan/executor/jni/ComponentStruct"); | |
829 | if( cls == NULL ) { | |
830 | printf("Can't find class org.eclipse.titan.executor.jni.ComponentStruct\n"); | |
831 | } | |
832 | jfieldID fid; | |
833 | jmethodID mid; | |
834 | jobject ComponentStruct; | |
835 | mid = env->GetMethodID(cls, "<init>", "(I)V"); | |
836 | ComponentStruct = env->NewObject(cls, mid, text_buf->get_len()); | |
837 | ||
838 | // processing struct fields | |
839 | // comp_ref | |
840 | fid = env->GetFieldID(cls, "comp_ref", "I"); | |
841 | if (fid == 0) { | |
842 | printf("Can't find field comp_ref\n"); | |
843 | } | |
844 | env->SetIntField(ComponentStruct, fid, (jint) comp_ref); | |
845 | ||
846 | // comp_type | |
847 | fid = env->GetFieldID(cls, "comp_type", "Lorg/eclipse/titan/executor/jni/QualifiedName;"); | |
848 | if (fid == 0) { | |
849 | printf("Can't find field comp_type\n"); | |
850 | } | |
851 | jclass cls_q = env->FindClass("org/eclipse/titan/executor/jni/QualifiedName"); | |
852 | if( cls_q == NULL ) { | |
853 | printf("Can't find class QualifiedName\n"); | |
854 | } | |
855 | // creating new QualifiedName object | |
856 | jmethodID mid_q = env->GetMethodID(cls_q, "<init>", "(Ljava/lang/String;Ljava/lang/String;)V"); | |
857 | jobject qname = env->NewObject(cls_q, mid_q, env->NewStringUTF(comp_type.module_name), | |
858 | env->NewStringUTF(comp_type.definition_name)); | |
859 | env->ExceptionClear(); | |
860 | env->SetObjectField(ComponentStruct, fid, qname); | |
861 | ||
862 | // comp_name | |
863 | fid = env->GetFieldID(cls, "comp_name", "Ljava/lang/String;"); | |
864 | if (fid == 0) { | |
865 | printf("Can't find field comp_name\n"); | |
866 | } | |
867 | env->SetObjectField(ComponentStruct, fid, env->NewStringUTF(comp_name)); | |
868 | ||
869 | // log_source | |
870 | fid = env->GetFieldID(cls, "log_source", "Ljava/lang/String;"); | |
871 | if (fid == 0) { | |
872 | printf("Can't find field log_source\n"); | |
873 | } | |
874 | env->SetObjectField(ComponentStruct, fid, env->NewStringUTF(log_source)); | |
875 | ||
876 | // comp_location --------------------------------------- | |
877 | fid = env->GetFieldID(cls, "comp_location", "Lorg/eclipse/titan/executor/jni/HostStruct;"); | |
878 | jclass cls_hs = env->FindClass("org/eclipse/titan/executor/jni/HostStruct"); | |
879 | if( cls_hs == NULL ) { | |
880 | printf("Can't find class org.eclipse.titan.executor.jni.HostStruct\n"); | |
881 | } | |
882 | jfieldID fid_hs; | |
883 | jmethodID mid_hs; | |
884 | jobject HostStruct; | |
885 | mid_hs = env->GetMethodID(cls_hs, "<init>", "(IIII)V"); | |
886 | HostStruct = env->NewObject(cls_hs, mid_hs, 3, comp_location->text_buf->get_len(), comp_location->n_components, comp_location->allowed_components.n_elements); | |
887 | ||
888 | if(env->ExceptionOccurred()) { | |
889 | printf("error at creating HostStruct\n"); | |
890 | env->ExceptionDescribe(); | |
891 | env->ExceptionClear(); | |
892 | } | |
893 | // processing struct fields | |
894 | // ip_addr | |
895 | const char *ipaddr = comp_location->ip_addr->get_addr_str(); | |
896 | fid_hs = env->GetFieldID(cls_hs, "ip_addr", "Ljava/lang/String;"); | |
897 | if (fid_hs == 0) { | |
898 | printf("Can't find field hostname\n"); | |
899 | } | |
900 | env->SetObjectField(HostStruct, fid_hs, env->NewStringUTF(ipaddr)); | |
901 | ||
902 | // hostname | |
903 | fid_hs = env->GetFieldID(cls_hs, "hostname", "Ljava/lang/String;"); | |
904 | if (fid_hs == 0) { | |
905 | printf("Can't find field hostname\n"); | |
906 | } | |
907 | env->SetObjectField(HostStruct, fid_hs, env->NewStringUTF(comp_location->hostname)); | |
908 | ||
909 | // hostname_local | |
910 | fid_hs = env->GetFieldID(cls_hs, "hostname_local", "Ljava/lang/String;"); | |
911 | if (fid_hs == 0) { | |
912 | printf("Can't find field hostname_local\n"); | |
913 | } | |
914 | env->SetObjectField(HostStruct, fid_hs, env->NewStringUTF(comp_location->hostname_local)); | |
915 | ||
916 | // machine_type | |
917 | fid_hs = env->GetFieldID(cls_hs, "machine_type", "Ljava/lang/String;"); | |
918 | if (fid_hs == 0) { | |
919 | printf("Can't find field machine_type\n"); | |
920 | } | |
921 | env->SetObjectField(HostStruct, fid_hs, env->NewStringUTF(comp_location->machine_type)); | |
922 | ||
923 | // system_name | |
924 | fid_hs = env->GetFieldID(cls_hs, "system_name", "Ljava/lang/String;"); | |
925 | if (fid_hs == 0) { | |
926 | printf("Can't find field system_name\n"); | |
927 | } | |
928 | env->SetObjectField(HostStruct, fid_hs, env->NewStringUTF(comp_location->system_name)); | |
929 | ||
930 | // system_release | |
931 | fid_hs = env->GetFieldID(cls_hs, "system_release", "Ljava/lang/String;"); | |
932 | if (fid_hs == 0) { | |
933 | printf("Can't find field system_release\n"); | |
934 | } | |
935 | env->SetObjectField(HostStruct, fid_hs, env->NewStringUTF(comp_location->system_release)); | |
936 | ||
937 | // system_version | |
938 | fid_hs = env->GetFieldID(cls_hs, "system_version", "Ljava/lang/String;"); | |
939 | if (fid_hs == 0) { | |
940 | printf("Can't find field system_version\n"); | |
941 | } | |
942 | env->SetObjectField(HostStruct, fid_hs, env->NewStringUTF(comp_location->system_version)); | |
943 | ||
944 | // transport_supported | |
945 | fid_hs = env->GetFieldID(cls_hs, "transport_supported", "[Z"); | |
946 | if (fid_hs == 0) { | |
947 | printf("Can't find field transport_supported\n"); | |
948 | } | |
949 | jbooleanArray TransportSupported = (jbooleanArray)env->GetObjectField(HostStruct, fid_hs); | |
950 | env->SetBooleanArrayRegion(TransportSupported, (jsize)0, 3,(jboolean *)comp_location->transport_supported); | |
951 | ||
952 | // log_source | |
953 | fid_hs = env->GetFieldID(cls_hs, "log_source", "Ljava/lang/String;"); | |
954 | if (fid_hs == 0) { | |
955 | printf("Can't find field log_source\n"); | |
956 | } | |
957 | env->SetObjectField(HostStruct, fid_hs, env->NewStringUTF(comp_location->log_source)); | |
958 | ||
959 | // hc_state | |
960 | fid_hs = env->GetFieldID(cls_hs, "hc_state", "Lorg/eclipse/titan/executor/jni/HcStateEnum;"); | |
961 | if (fid_hs == 0) { | |
962 | printf("Can't find field hc_state\n"); | |
963 | } | |
964 | ||
965 | jclass cls_hs_hc = env->FindClass("org/eclipse/titan/executor/jni/HcStateEnum"); | |
966 | if( cls_hs_hc == NULL ) { | |
967 | printf("Can't find class org.eclipse.titan.executor.jni.HcStateEnum\n"); | |
968 | } | |
969 | jfieldID fid_hs_hc = 0; | |
970 | jobject ret; | |
971 | switch(comp_location->hc_state) { | |
972 | case mctr::HC_IDLE: | |
973 | fid_hs_hc = env->GetStaticFieldID(cls_hs_hc, "HC_IDLE", "Lorg/eclipse/titan/executor/jni/HcStateEnum;"); | |
974 | if (fid_hs_hc == 0) { | |
975 | printf("Can't find field HC_IDLE\n"); | |
976 | } | |
977 | break; | |
978 | case mctr::HC_CONFIGURING: | |
979 | fid_hs_hc = env->GetStaticFieldID(cls_hs_hc, "HC_CONFIGURING", "Lorg/eclipse/titan/executor/jni/HcStateEnum;"); | |
980 | if (fid_hs_hc == 0) { | |
981 | printf("Can't find field HC_CONFIGURING\n"); | |
982 | } | |
983 | break; | |
984 | case mctr::HC_ACTIVE: | |
985 | fid_hs_hc = env->GetStaticFieldID(cls_hs_hc, "HC_ACTIVE", "Lorg/eclipse/titan/executor/jni/HcStateEnum;"); | |
986 | if (fid_hs_hc == 0) { | |
987 | printf("Can't find field HC_ACTIVE\n"); | |
988 | } | |
989 | break; | |
990 | case mctr::HC_OVERLOADED: | |
991 | fid_hs_hc = env->GetStaticFieldID(cls_hs_hc, "HC_OVERLOADED", "Lorg/eclipse/titan/executor/jni/HcStateEnum;"); | |
992 | if (fid_hs_hc == 0) { | |
993 | printf("Can't find field HC_OVERLOADED\n"); | |
994 | } | |
995 | break; | |
996 | case mctr::HC_CONFIGURING_OVERLOADED: | |
997 | fid_hs_hc = env->GetStaticFieldID(cls_hs_hc, "HC_CONFIGURING_OVERLOADED", "Lorg/eclipse/titan/executor/jni/HcStateEnum;"); | |
998 | if (fid_hs_hc == 0) { | |
999 | printf("Can't find field HC_CONFIGURING_OVERLOADED\n"); | |
1000 | } | |
1001 | break; | |
1002 | // ----------------------------------------------- 6-7 | |
1003 | case mctr::HC_EXITING: | |
1004 | fid_hs_hc = env->GetStaticFieldID(cls_hs_hc, "HC_EXITING", "Lorg/eclipse/titan/executor/jni/HcStateEnum;"); | |
1005 | if (fid_hs_hc == 0) { | |
1006 | printf("Can't find field HC_EXITING\n"); | |
1007 | } | |
1008 | break; | |
1009 | case mctr::HC_DOWN: | |
1010 | fid_hs_hc = env->GetStaticFieldID(cls_hs_hc, "HC_DOWN", "Lorg/eclipse/titan/executor/jni/HcStateEnum;"); | |
1011 | if (fid_hs_hc == 0) { | |
1012 | printf("Can't find field HC_DOWN\n"); | |
1013 | } | |
1014 | break; | |
1015 | default: | |
1016 | printf("Unknown hc_state_enum state\n"); | |
1017 | } | |
1018 | ret = env->GetStaticObjectField(cls_hs_hc, fid_hs_hc); | |
1019 | env->ExceptionClear(); | |
1020 | env->SetObjectField(HostStruct, fid_hs, ret); | |
1021 | ||
1022 | // hc_fd | |
1023 | fid_hs = env->GetFieldID(cls_hs, "hc_fd", "I"); | |
1024 | if (fid_hs == 0) { | |
1025 | printf("Can't find field hc_fd\n"); | |
1026 | } | |
1027 | env->SetIntField(HostStruct, fid_hs, (jint)comp_location->hc_fd); | |
1028 | ||
1029 | // text_buf | |
1030 | fid_hs = env->GetFieldID(cls_hs, "text_buf", "[B"); | |
1031 | if (fid_hs == 0) { | |
1032 | printf("Can't find field text_buf\n"); | |
1033 | } | |
1034 | jbyteArray TextBuf = (jbyteArray)env->GetObjectField(HostStruct, fid_hs); | |
1035 | env->SetByteArrayRegion(TextBuf, (jsize)0, comp_location->text_buf->get_len(), | |
1036 | const_cast<jbyte *>((const jbyte *)text_buf->get_data())); | |
1037 | ||
1038 | // components | |
1039 | fid_hs = env->GetFieldID(cls_hs, "components", "[I"); | |
1040 | if (fid_hs == 0) { | |
1041 | printf("Can't find field components\n"); | |
1042 | } | |
1043 | ||
1044 | jintArray Components = (jintArray)env->GetObjectField(HostStruct, fid_hs); | |
1045 | env->SetIntArrayRegion(Components, (jsize)0, comp_location->n_components, (jint *)comp_location->components); | |
1046 | ||
1047 | // allowed_components | |
1048 | fid_hs = env->GetFieldID(cls_hs, "allowed_components", "[Ljava/lang/String;"); | |
1049 | if (fid_hs == 0) { | |
1050 | printf("Can't find field allowed_components\n"); | |
1051 | } | |
1052 | jobjectArray allowedComponents = (jobjectArray) env->GetObjectField(HostStruct, fid_hs); | |
1053 | for(int i = 0; i < comp_location->allowed_components.n_elements; i++) { | |
1054 | env->SetObjectArrayElement(allowedComponents, i, env->NewStringUTF(comp_location->allowed_components.elements[i])); | |
1055 | } | |
1056 | ||
1057 | // all_components_allowed | |
1058 | fid_hs = env->GetFieldID(cls_hs, "all_components_allowed", "Z"); | |
1059 | if (fid_hs == 0) { | |
1060 | printf("Can't find field all_components_allowed\n"); | |
1061 | } | |
1062 | env->SetBooleanField(HostStruct, fid_hs, (jboolean)comp_location->all_components_allowed); | |
1063 | ||
1064 | // n_active_components | |
1065 | fid_hs = env->GetFieldID(cls_hs, "n_active_components", "I"); | |
1066 | if (fid_hs == 0) { | |
1067 | printf("Can't find field n_active_components\n"); | |
1068 | } | |
1069 | env->SetIntField(HostStruct, fid_hs, (jint)comp_location->n_active_components); | |
1070 | ||
1071 | ||
1072 | env->SetObjectField(ComponentStruct, fid, HostStruct); // finally setting inner host_struct | |
1073 | // end of comp_location -------------------------------- | |
1074 | ||
1075 | // tc_state | |
1076 | fid = env->GetFieldID(cls, "tc_state", "Lorg/eclipse/titan/executor/jni/TcStateEnum;"); | |
1077 | if (fid == 0) { | |
1078 | printf("Can't find field tc_state\n"); | |
1079 | } | |
1080 | ||
1081 | jclass cls_tc = env->FindClass("org/eclipse/titan/executor/jni/TcStateEnum"); | |
1082 | if( cls_tc == NULL ) { | |
1083 | printf("Can't find class org.eclipse.titan.executor.jni.TcStateEnum\n"); | |
1084 | } | |
1085 | jfieldID fid_tc = 0; | |
1086 | jobject ret_tc; | |
1087 | switch(tc_state) { | |
1088 | case mctr::TC_INITIAL: | |
1089 | fid_tc = env->GetStaticFieldID(cls_tc, "TC_INITIAL", "Lorg/eclipse/titan/executor/jni/TcStateEnum;"); | |
1090 | if (fid_tc == 0) { | |
1091 | printf("Can't find field TC_INITIAL\n"); | |
1092 | } | |
1093 | break; | |
1094 | case mctr::TC_IDLE: | |
1095 | fid_tc = env->GetStaticFieldID(cls_tc, "TC_IDLE", "Lorg/eclipse/titan/executor/jni/TcStateEnum;"); | |
1096 | if (fid_tc == 0) { | |
1097 | printf("Can't find field TC_IDLE\n"); | |
1098 | } | |
1099 | break; | |
1100 | case mctr::TC_CREATE: | |
1101 | fid_tc = env->GetStaticFieldID(cls_tc, "TC_CREATE", "Lorg/eclipse/titan/executor/jni/TcStateEnum;"); | |
1102 | if (fid_tc == 0) { | |
1103 | printf("Can't find field TC_CREATE\n"); | |
1104 | } | |
1105 | break; | |
1106 | case mctr::TC_START: | |
1107 | fid_tc = env->GetStaticFieldID(cls_tc, "TC_START", "Lorg/eclipse/titan/executor/jni/TcStateEnum;"); | |
1108 | if (fid_tc == 0) { | |
1109 | printf("Can't find field TC_START\n"); | |
1110 | } | |
1111 | break; | |
1112 | case mctr::TC_STOP: | |
1113 | fid_tc = env->GetStaticFieldID(cls_tc, "TC_STOP", "Lorg/eclipse/titan/executor/jni/TcStateEnum;"); | |
1114 | if (fid_tc == 0) { | |
1115 | printf("Can't find field TC_STOP\n"); | |
1116 | } | |
1117 | break; | |
1118 | // ----------------------------------------------- 6-10 | |
1119 | case mctr::TC_KILL: | |
1120 | fid_tc = env->GetStaticFieldID(cls_tc, "TC_KILL", "Lorg/eclipse/titan/executor/jni/TcStateEnum;"); | |
1121 | if (fid_tc == 0) { | |
1122 | printf("Can't find field TC_KILL\n"); | |
1123 | } | |
1124 | break; | |
1125 | case mctr::TC_CONNECT: | |
1126 | fid_tc = env->GetStaticFieldID(cls_tc, "TC_CONNECT", "Lorg/eclipse/titan/executor/jni/TcStateEnum;"); | |
1127 | if (fid_tc == 0) { | |
1128 | printf("Can't find field TC_CONNECT\n"); | |
1129 | } | |
1130 | break; | |
1131 | case mctr::TC_DISCONNECT: | |
1132 | fid_tc = env->GetStaticFieldID(cls_tc, "TC_DISCONNECT", "Lorg/eclipse/titan/executor/jni/TcStateEnum;"); | |
1133 | if (fid_tc == 0) { | |
1134 | printf("Can't find field TC_DISCONNECT\n"); | |
1135 | } | |
1136 | break; | |
1137 | case mctr::TC_MAP: | |
1138 | fid_tc = env->GetStaticFieldID(cls_tc, "TC_MAP", "Lorg/eclipse/titan/executor/jni/TcStateEnum;"); | |
1139 | if (fid_tc == 0) { | |
1140 | printf("Can't find field TC_MAP\n"); | |
1141 | } | |
1142 | break; | |
1143 | case mctr::TC_UNMAP: | |
1144 | fid_tc = env->GetStaticFieldID(cls_tc, "TC_UNMAP", "Lorg/eclipse/titan/executor/jni/TcStateEnum;"); | |
1145 | if (fid_tc == 0) { | |
1146 | printf("Can't find field TC_UNMAP\n"); | |
1147 | } | |
1148 | break; | |
1149 | // ----------------------------------------------- 11-15 | |
1150 | case mctr::TC_STOPPING: | |
1151 | fid_tc = env->GetStaticFieldID(cls_tc, "TC_STOPPING", "Lorg/eclipse/titan/executor/jni/TcStateEnum;"); | |
1152 | if (fid_tc == 0) { | |
1153 | printf("Can't find field TC_STOPPING\n"); | |
1154 | } | |
1155 | break; | |
1156 | case mctr::TC_EXITING: | |
1157 | fid_tc = env->GetStaticFieldID(cls_tc, "TC_EXITING", "Lorg/eclipse/titan/executor/jni/TcStateEnum;"); | |
1158 | if (fid_tc == 0) { | |
1159 | printf("Can't find field TC_EXITING\n"); | |
1160 | } | |
1161 | break; | |
1162 | case mctr::TC_EXITED: | |
1163 | fid_tc = env->GetStaticFieldID(cls_tc, "TC_EXITED", "Lorg/eclipse/titan/executor/jni/TcStateEnum;"); | |
1164 | if (fid_tc == 0) { | |
1165 | printf("Can't find field TC_EXITED\n"); | |
1166 | } | |
1167 | break; | |
1168 | case mctr::MTC_CONTROLPART: | |
1169 | fid_tc = env->GetStaticFieldID(cls_tc, "MTC_CONTROLPART", "Lorg/eclipse/titan/executor/jni/TcStateEnum;"); | |
1170 | if (fid_tc == 0) { | |
1171 | printf("Can't find field MTC_CONTROLPART\n"); | |
1172 | } | |
1173 | break; | |
1174 | case mctr::MTC_TESTCASE: | |
1175 | fid_tc = env->GetStaticFieldID(cls_tc, "MTC_TESTCASE", "Lorg/eclipse/titan/executor/jni/TcStateEnum;"); | |
1176 | if (fid_tc == 0) { | |
1177 | printf("Can't find field MTC_TESTCASE\n"); | |
1178 | } | |
1179 | break; | |
1180 | // ----------------------------------------------- 16-20 | |
1181 | case mctr::MTC_ALL_COMPONENT_STOP: | |
1182 | fid_tc = env->GetStaticFieldID(cls_tc, "MTC_ALL_COMPONENT_STOP", "Lorg/eclipse/titan/executor/jni/TcStateEnum;"); | |
1183 | if (fid_tc == 0) { | |
1184 | printf("Can't find field MTC_ALL_COMPONENT_STOP\n"); | |
1185 | } | |
1186 | break; | |
1187 | case mctr::MTC_ALL_COMPONENT_KILL: | |
1188 | fid_tc = env->GetStaticFieldID(cls_tc, "MTC_ALL_COMPONENT_KILL", "Lorg/eclipse/titan/executor/jni/TcStateEnum;"); | |
1189 | if (fid_tc == 0) { | |
1190 | printf("Can't find field MTC_ALL_COMPONENT_KILL\n"); | |
1191 | } | |
1192 | ret_tc = env->GetStaticObjectField(cls_tc, fid_tc); | |
1193 | env->ExceptionClear(); | |
1194 | break; | |
1195 | case mctr::MTC_TERMINATING_TESTCASE: | |
1196 | fid_tc = env->GetStaticFieldID(cls_tc, "MTC_TERMINATING_TESTCASE", "Lorg/eclipse/titan/executor/jni/TcStateEnum;"); | |
1197 | if (fid_tc == 0) { | |
1198 | printf("Can't find field MTC_TERMINATING_TESTCASE\n"); | |
1199 | } | |
1200 | break; | |
1201 | case mctr::MTC_PAUSED: | |
1202 | fid_tc = env->GetStaticFieldID(cls_tc, "MTC_PAUSED", "Lorg/eclipse/titan/executor/jni/TcStateEnum;"); | |
1203 | if (fid_tc == 0) { | |
1204 | printf("Can't find field MTC_PAUSED\n"); | |
1205 | } | |
1206 | break; | |
1207 | case mctr::PTC_FUNCTION: | |
1208 | fid_tc = env->GetStaticFieldID(cls_tc, "PTC_FUNCTION", "Lorg/eclipse/titan/executor/jni/TcStateEnum;"); | |
1209 | if (fid_tc == 0) { | |
1210 | printf("Can't find field PTC_FUNCTION\n"); | |
1211 | } | |
1212 | break; | |
1213 | // ----------------------------------------------- 21-25 | |
1214 | case mctr::PTC_STARTING: | |
1215 | fid_tc = env->GetStaticFieldID(cls_tc, "PTC_STARTING", "Lorg/eclipse/titan/executor/jni/TcStateEnum;"); | |
1216 | if (fid_tc == 0) { | |
1217 | printf("Can't find field PTC_STARTING\n"); | |
1218 | } | |
1219 | break; | |
1220 | case mctr::PTC_STOPPED: | |
1221 | fid_tc = env->GetStaticFieldID(cls_tc, "PTC_STOPPED", "Lorg/eclipse/titan/executor/jni/TcStateEnum;"); | |
1222 | if (fid_tc == 0) { | |
1223 | printf("Can't find field PTC_STOPPED\n"); | |
1224 | } | |
1225 | break; | |
1226 | case mctr::PTC_KILLING: | |
1227 | fid_tc = env->GetStaticFieldID(cls_tc, "PTC_KILLING", "Lorg/eclipse/titan/executor/jni/TcStateEnum;"); | |
1228 | if (fid_tc == 0) { | |
1229 | printf("Can't find field PTC_KILLING\n"); | |
1230 | } | |
1231 | break; | |
1232 | case mctr::PTC_STOPPING_KILLING: | |
1233 | fid_tc = env->GetStaticFieldID(cls_tc, "PTC_STOPPING_KILLING", "Lorg/eclipse/titan/executor/jni/TcStateEnum;"); | |
1234 | if (fid_tc == 0) { | |
1235 | printf("Can't find field PTC_STOPPING_KILLING\n"); | |
1236 | } | |
1237 | break; | |
1238 | case mctr::PTC_STALE: | |
1239 | fid_tc = env->GetStaticFieldID(cls_tc, "PTC_STALE", "Lorg/eclipse/titan/executor/jni/TcStateEnum;"); | |
1240 | if (fid_tc == 0) { | |
1241 | printf("Can't find field PTC_STALE\n"); | |
1242 | } | |
1243 | break; | |
1244 | // ----------------------------------------------- 26 | |
1245 | case mctr::TC_SYSTEM: | |
1246 | fid_tc = env->GetStaticFieldID(cls_tc, "TC_SYSTEM", "Lorg/eclipse/titan/executor/jni/TcStateEnum;"); | |
1247 | if (fid_tc == 0) { | |
1248 | printf("Can't find field TC_SYSTEM\n"); | |
1249 | } | |
1250 | break; | |
1251 | default: | |
1252 | printf("Unknown tc_state_enum state\n"); | |
1253 | } | |
1254 | ret_tc = env->GetStaticObjectField(cls_tc, fid_tc); | |
1255 | env->ExceptionClear(); | |
1256 | env->SetObjectField(ComponentStruct, fid, ret_tc); | |
1257 | ||
1258 | // local_verdict | |
1259 | fid = env->GetFieldID(cls, "local_verdict", "Lorg/eclipse/titan/executor/jni/VerdictTypeEnum;"); | |
1260 | if (fid == 0) { | |
1261 | printf("Can't find field local_verdict\n"); | |
1262 | } | |
1263 | jclass cls_v = env->FindClass("org/eclipse/titan/executor/jni/VerdictTypeEnum"); | |
1264 | if( cls_v == NULL ) { | |
1265 | printf("Can't find class org.eclipse.titan.executor.jni.VerdictTypeEnum\n"); | |
1266 | } | |
1267 | jfieldID fid_v = 0; | |
1268 | jobject ret_v; | |
1269 | switch(local_verdict) { | |
1270 | case NONE: | |
1271 | fid_v = env->GetStaticFieldID(cls_v, "NONE", "Lorg/eclipse/titan/executor/jni/VerdictTypeEnum;"); | |
1272 | if (fid_v == 0) { | |
1273 | printf("Can't find field NONE\n"); | |
1274 | } | |
1275 | break; | |
1276 | case PASS: | |
1277 | fid_v = env->GetStaticFieldID(cls_v, "PASS", "Lorg/eclipse/titan/executor/jni/VerdictTypeEnum;"); | |
1278 | if (fid_v == 0) { | |
1279 | printf("Can't find field PASS\n"); | |
1280 | } | |
1281 | break; | |
1282 | case INCONC: | |
1283 | fid_v = env->GetStaticFieldID(cls_v, "INCONC", "Lorg/eclipse/titan/executor/jni/VerdictTypeEnum;"); | |
1284 | if (fid_v == 0) { | |
1285 | printf("Can't find field INCONC\n"); | |
1286 | } | |
1287 | break; | |
1288 | case FAIL: | |
1289 | fid_v = env->GetStaticFieldID(cls_v, "FAIL", "Lorg/eclipse/titan/executor/jni/VerdictTypeEnum;"); | |
1290 | if (fid_v == 0) { | |
1291 | printf("Can't find field FAIL\n"); | |
1292 | } | |
1293 | break; | |
1294 | case ERROR: | |
1295 | fid_v = env->GetStaticFieldID(cls_v, "ERROR", "Lorg/eclipse/titan/executor/jni/VerdictTypeEnum;"); | |
1296 | if (fid_v == 0) { | |
1297 | printf("Can't find field ERROR\n"); | |
1298 | } | |
1299 | break; | |
1300 | default: | |
1301 | printf("Unknown tc_state_enum state\n"); | |
1302 | } | |
1303 | ret_v = env->GetStaticObjectField(cls_v, fid_v); | |
1304 | env->ExceptionClear(); | |
1305 | env->SetObjectField(ComponentStruct, fid, ret_v); | |
1306 | ||
1307 | // tc_fd | |
1308 | fid = env->GetFieldID(cls, "tc_fd", "I"); | |
1309 | if (fid == 0) { | |
1310 | printf("Can't find field tc_fd\n"); | |
1311 | } | |
1312 | env->SetIntField(ComponentStruct, fid, (jint)tc_fd); | |
1313 | ||
1314 | // text_buf | |
1315 | fid = env->GetFieldID(cls, "text_buf", "[B"); | |
1316 | if (fid == 0) { | |
1317 | printf("Can't find field text_buf\n"); | |
1318 | } | |
1319 | jbyteArray TextBuf_c = (jbyteArray)env->GetObjectField(ComponentStruct, fid); | |
1320 | env->SetByteArrayRegion(TextBuf_c, (jsize)0, text_buf->get_len(), | |
1321 | const_cast<jbyte *>((const jbyte *)text_buf->get_data())); | |
1322 | ||
1323 | // tc_fn_name | |
1324 | fid = env->GetFieldID(cls, "tc_fn_name", "Lorg/eclipse/titan/executor/jni/QualifiedName;"); | |
1325 | if (fid == 0) { | |
1326 | printf("Can't find field tc_fn_name\n"); | |
1327 | } | |
1328 | jclass cls_qualified = env->FindClass("org/eclipse/titan/executor/jni/QualifiedName"); | |
1329 | if( cls_qualified == NULL ) { | |
1330 | printf("Can't find class org.eclipse.titan.executor.jni.QualifiedName\n"); | |
1331 | } | |
1332 | jmethodID mid_qualified; | |
1333 | jobject QualifiedName; | |
1334 | mid_qualified = env->GetMethodID(cls_qualified, "<init>", "(Ljava/lang/String;Ljava/lang/String;)V"); | |
1335 | QualifiedName = env->NewObject(cls_qualified, mid_qualified, env->NewStringUTF(tc_fn_name.module_name), | |
1336 | env->NewStringUTF(tc_fn_name.definition_name)); | |
1337 | env->SetObjectField(ComponentStruct, fid, QualifiedName); | |
1338 | ||
1339 | // return_type | |
1340 | fid = env->GetFieldID(cls, "return_type", "Ljava/lang/String;"); | |
1341 | if (fid == 0) { | |
1342 | printf("Can't find field return_type\n"); | |
1343 | } | |
1344 | env->SetObjectField(ComponentStruct, fid, env->NewStringUTF(return_type)); | |
1345 | ||
1346 | // return_value_len | |
1347 | fid = env->GetFieldID(cls, "return_value_len", "I"); | |
1348 | if (fid == 0) { | |
1349 | printf("Can't find field return_value_len\n"); | |
1350 | } | |
1351 | env->SetIntField(ComponentStruct, fid, (jint)return_value_len); | |
1352 | ||
1353 | // is_alive | |
1354 | fid = env->GetFieldID(cls, "is_alive", "Z"); | |
1355 | if (fid == 0) { | |
1356 | printf("Can't find field is_alive\n"); | |
1357 | } | |
1358 | env->SetBooleanField(ComponentStruct, fid, (jboolean)is_alive); | |
1359 | ||
1360 | // stop_requested | |
1361 | fid = env->GetFieldID(cls, "stop_requested", "Z"); | |
1362 | if (fid == 0) { | |
1363 | printf("Can't find field stop_requested\n"); | |
1364 | } | |
1365 | env->SetBooleanField(ComponentStruct, fid, (jboolean)stop_requested); | |
1366 | ||
1367 | // process_killed | |
1368 | fid = env->GetFieldID(cls, "process_killed", "Z"); | |
1369 | if (fid == 0) { | |
1370 | printf("Can't find field process_killed\n"); | |
1371 | } | |
1372 | env->SetBooleanField(ComponentStruct, fid, (jboolean)process_killed); | |
1373 | ||
1374 | return ComponentStruct; | |
1375 | } | |
1376 | ||
1377 | JNIEXPORT void JNICALL Java_org_eclipse_titan_executor_jni_JNIMiddleWare_release_1data | |
1378 | (JNIEnv *, jobject) { | |
1379 | MainController::release_data(); | |
1380 | } | |
1381 | ||
1382 | JNIEXPORT jstring JNICALL Java_org_eclipse_titan_executor_jni_JNIMiddleWare_get_1mc_1state_1name | |
1383 | (JNIEnv *env, jobject, jobject state) { | |
1384 | jclass cls = env->GetObjectClass(state); | |
1385 | if( cls == NULL ) { | |
1386 | printf("Can't find class org.eclipse.titan.executor.jni.McStateEnum\n"); | |
1387 | } | |
1388 | jmethodID mid = env->GetMethodID(cls, "getValue", "()I"); | |
1389 | if( mid == NULL ) { | |
1390 | printf("Can't find method getValue\n"); | |
1391 | } | |
1392 | int value = env->CallIntMethod(state, mid); | |
1393 | const char *state_name = MainController::get_mc_state_name((mctr::mc_state_enum)value); | |
1394 | return (env->NewStringUTF(state_name)); | |
1395 | } | |
1396 | ||
1397 | JNIEXPORT jstring JNICALL Java_org_eclipse_titan_executor_jni_JNIMiddleWare_get_1hc_1state_1name | |
1398 | (JNIEnv *env, jobject, jobject state) { | |
1399 | jclass cls = env->GetObjectClass(state); | |
1400 | if( cls == NULL ) { | |
1401 | printf("Can't find class org.eclipse.titan.executor.jni.HcStateEnum\n"); | |
1402 | } | |
1403 | jmethodID mid = env->GetMethodID(cls, "getValue", "()I"); | |
1404 | if( mid == NULL ) { | |
1405 | printf("Can't find method getValue\n"); | |
1406 | } | |
1407 | int value = env->CallIntMethod(state, mid); | |
1408 | const char *state_name = MainController::get_hc_state_name((mctr::hc_state_enum)value); | |
1409 | return (env->NewStringUTF(state_name)); | |
1410 | } | |
1411 | ||
1412 | JNIEXPORT jstring JNICALL Java_org_eclipse_titan_executor_jni_JNIMiddleWare_get_1tc_1state_1name | |
1413 | (JNIEnv *env, jobject, jobject state) { | |
1414 | jclass cls = env->GetObjectClass(state); | |
1415 | if( cls == NULL ) { | |
1416 | printf("Can't find class org.eclipse.titan.executor.jni.TcStateEnum\n"); | |
1417 | } | |
1418 | jmethodID mid = env->GetMethodID(cls, "getValue", "()I"); | |
1419 | if( mid == NULL ) { | |
1420 | printf("Can't find method getValue\n"); | |
1421 | } | |
1422 | int value = env->CallIntMethod(state, mid); | |
1423 | const char *state_name = MainController::get_tc_state_name((mctr::tc_state_enum)value); | |
1424 | return (env->NewStringUTF(state_name)); | |
1425 | } | |
1426 | ||
1427 | JNIEXPORT jstring JNICALL Java_org_eclipse_titan_executor_jni_JNIMiddleWare_get_1transport_1name | |
1428 | (JNIEnv *env, jobject, jobject transport) { | |
1429 | jclass cls = env->GetObjectClass(transport); | |
1430 | if( cls == NULL ) { | |
1431 | printf("Can't find class org.eclipse.titan.executor.jni.TransportTypeEnum\n"); | |
1432 | } | |
1433 | jmethodID mid = env->GetMethodID(cls, "getValue", "()I"); | |
1434 | if( mid == NULL ) { | |
1435 | printf("Can't find method getValue\n"); | |
1436 | } | |
1437 | int value = env->CallIntMethod(transport, mid); | |
1438 | const char *transport_name = MainController::get_transport_name((transport_type_enum)value); | |
1439 | return (env->NewStringUTF(transport_name)); | |
1440 | } | |
1441 | ||
1442 | // ******************************************************* | |
1443 | // Other native functions | |
1444 | // ******************************************************* | |
1445 | ||
1446 | JNIEXPORT void JNICALL Java_org_eclipse_titan_executor_jni_JNIMiddleWare_check_1mem_1leak | |
1447 | (JNIEnv *env, jobject, jstring program_name) { | |
1448 | jboolean iscopy; | |
1449 | const char *p_name = env->GetStringUTFChars(program_name, &iscopy); | |
1450 | check_mem_leak(p_name); | |
1451 | env->ReleaseStringUTFChars(program_name, p_name); | |
1452 | } | |
1453 | ||
1454 | JNIEXPORT void JNICALL Java_org_eclipse_titan_executor_jni_JNIMiddleWare_print_1license_1info | |
1455 | (JNIEnv *, jobject) { | |
1456 | #ifdef LICENSE | |
1457 | print_license_info(); | |
1458 | #endif | |
1459 | } | |
1460 | ||
1461 | JNIEXPORT jint JNICALL Java_org_eclipse_titan_executor_jni_JNIMiddleWare_check_1license | |
1462 | (JNIEnv *, jobject) { | |
1463 | int max_ptcs; | |
1464 | #ifdef LICENSE | |
1465 | license_struct lstr; | |
1466 | init_openssl(); | |
1467 | load_license(&lstr); | |
1468 | if (!verify_license(&lstr)) { | |
1469 | free_license(&lstr); | |
1470 | free_openssl(); | |
1471 | exit(EXIT_FAILURE); | |
1472 | } | |
1473 | if (!check_feature(&lstr, FEATURE_MCTR)) { | |
1474 | fputs("The license key does not allow the starting of TTCN-3 " | |
1475 | "Main Controller.\n", stderr); | |
1476 | return 2; | |
1477 | } | |
1478 | max_ptcs = lstr.max_ptcs; | |
1479 | free_license(&lstr); | |
1480 | free_openssl(); | |
1481 | #else | |
1482 | max_ptcs = -1; | |
1483 | #endif | |
1484 | return (jint)max_ptcs; | |
1485 | } | |
1486 | ||
1487 | JNIEXPORT jstring JNICALL Java_org_eclipse_titan_executor_jni_JNIMiddleWare_readPipe | |
1488 | (JNIEnv *env, jobject) { | |
1489 | char *buf = Jnimw::userInterface->read_pipe(); | |
1490 | return (env->NewStringUTF(buf)); | |
1491 | } | |
1492 | ||
1493 | JNIEXPORT jboolean JNICALL Java_org_eclipse_titan_executor_jni_JNIMiddleWare_isPipeReadable | |
1494 | (JNIEnv *, jobject) { | |
1495 | return ((jboolean)Jnimw::userInterface->is_pipe_readable()); | |
1496 | } | |
1497 | ||
1498 | JNIEXPORT jlong JNICALL Java_org_eclipse_titan_executor_jni_JNIMiddleWare_getSharedLibraryVersion | |
1499 | (JNIEnv *, jclass) { | |
1500 | return (jlong) TTCN3_VERSION; | |
1501 | } |