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