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 ///////////////////////////////////////////////////////////////////////////////
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"
21 using mctr::MainController
;
22 using namespace jnimw
;
24 JNIEXPORT jlong JNICALL
Java_org_eclipse_titan_executor_jni_JNIMiddleWare_init(JNIEnv
*, jobject
, jint max_ptcs
)
27 userInterface
= new Jnimw();
28 Jnimw::userInterface
= userInterface
;
29 MainController::initialize(*userInterface
, (int)max_ptcs
);
30 return (jlong
)userInterface
;
33 JNIEXPORT
void JNICALL
Java_org_eclipse_titan_executor_jni_JNIMiddleWare_terminate(JNIEnv
*, jobject
)
35 MainController::terminate();
36 delete Jnimw::userInterface
;
37 Jnimw::userInterface
= NULL
;
40 JNIEXPORT
void JNICALL
Java_org_eclipse_titan_executor_jni_JNIMiddleWare_add_1host(JNIEnv
*env
, jobject
, jstring group_name
, jstring host_name
)
42 // Fix for TR HO56282.
43 if (!Jnimw::userInterface
)
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
);
54 JNIEXPORT
void JNICALL
Java_org_eclipse_titan_executor_jni_JNIMiddleWare_assign_1component(JNIEnv
*env
, jobject
, jstring host_or_group
, jstring component_id
)
56 // Fix for TR HO56282.
57 if (!Jnimw::userInterface
)
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
);
68 JNIEXPORT
void JNICALL
Java_org_eclipse_titan_executor_jni_JNIMiddleWare_destroy_1host_1groups(JNIEnv
*, jobject
)
70 // Fix for TR HO56282.
71 if (!Jnimw::userInterface
)
73 MainController::destroy_host_groups();
76 JNIEXPORT
void JNICALL
Java_org_eclipse_titan_executor_jni_JNIMiddleWare_set_1kill_1timer(JNIEnv
*, jobject
, jdouble timer_val
)
78 // Fix for TR HO56282.
79 if (!Jnimw::userInterface
)
81 MainController::set_kill_timer((double)timer_val
);
84 JNIEXPORT jint JNICALL
Java_org_eclipse_titan_executor_jni_JNIMiddleWare_start_1session(JNIEnv
*env
, jobject
, jstring local_address
, jint tcp_port
, jboolean unixdomainsocketenabled
)
86 // Fix for TR HO56282.
87 if (!Jnimw::userInterface
)
90 const char *local_addr
= env
->GetStringUTFChars(local_address
, &iscopy
);
91 if (strcmp(local_addr
, "NULL") == 0) {
92 env
->ReleaseStringUTFChars(local_address
, local_addr
);
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
);
101 JNIEXPORT
void JNICALL
Java_org_eclipse_titan_executor_jni_JNIMiddleWare_shutdown_1session(JNIEnv
*, jobject
)
103 // Fix for TR HO56282.
104 if (!Jnimw::userInterface
)
106 MainController::shutdown_session();
111 * Configure MainController and HCs.
112 * It is also known as "Set parameter" operation.
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
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.
129 * NOTE: Function comment is here, because function declaration is in org_eclipse_titan_executor_jni_JNIMiddleWare.h, which is generated.
131 JNIEXPORT
void JNICALL
Java_org_eclipse_titan_executor_jni_JNIMiddleWare_configure(JNIEnv
*env
, jobject
, jstring config_file
)
133 // Fix for TR HO56282.
134 if (!Jnimw::userInterface
)
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
);
142 const char *conf_file
= env
->GetStringUTFChars(config_file
, &iscopy
);
143 MainController::configure(conf_file
);
144 env
->ReleaseStringUTFChars(config_file
, conf_file
);
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()
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
165 * NOTE: Function comment is here, because function declaration is in org_eclipse_titan_executor_jni_JNIMiddleWare.h, which is generated.
167 JNIEXPORT
void JNICALL
Java_org_eclipse_titan_executor_jni_JNIMiddleWare_set_1cfg_1file(JNIEnv
*env
, jobject
, jstring config_file_name
)
169 if (!Jnimw::userInterface
)
172 if (config_file_name
== NULL
)
174 const char *conf_file_name
= env
->GetStringUTFChars(config_file_name
, &iscopy
);
176 if (process_config_read_file(conf_file_name
, &Jnimw::mycfg
)) {
177 MainController::error("Error was found in the configuration file. Exiting.");
180 MainController::set_kill_timer(Jnimw::mycfg
.kill_timer
);
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
);
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
);
193 env
->ReleaseStringUTFChars(config_file_name
, conf_file_name
);
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()
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
204 * NOTE: Function comment is here, because function declaration is in org_eclipse_titan_executor_jni_JNIMiddleWare.h, which is generated.
206 JNIEXPORT jstring JNICALL
Java_org_eclipse_titan_executor_jni_JNIMiddleWare_get_1mc_1host(JNIEnv
*env
, jobject
)
208 return env
->NewStringUTF( Jnimw::mycfg
.local_addr
!= NULL
? Jnimw::mycfg
.local_addr
: "NULL" );
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()
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
219 * NOTE: Function comment is here, because function declaration is in org_eclipse_titan_executor_jni_JNIMiddleWare.h, which is generated.
221 JNIEXPORT jint JNICALL
Java_org_eclipse_titan_executor_jni_JNIMiddleWare_get_1port(JNIEnv
*, jobject
)
223 return (jint
)Jnimw::mycfg
.tcp_listen_port
;
226 JNIEXPORT
void JNICALL
Java_org_eclipse_titan_executor_jni_JNIMiddleWare_create_1mtc(JNIEnv
*, jobject
, jint host_index
)
228 // Fix for TR HO56282.
229 if (!Jnimw::userInterface
)
231 MainController::create_mtc((int)host_index
);
234 JNIEXPORT
void JNICALL
Java_org_eclipse_titan_executor_jni_JNIMiddleWare_exit_1mtc(JNIEnv
*, jobject
)
236 // Fix for TR HO56282.
237 if (!Jnimw::userInterface
)
239 MainController::exit_mtc();
242 JNIEXPORT
void JNICALL
Java_org_eclipse_titan_executor_jni_JNIMiddleWare_execute_1control(JNIEnv
*env
, jobject
, jstring module_name
)
244 // Fix for TR HO56282.
245 if (!Jnimw::userInterface
)
248 const char *mod_name
= env
->GetStringUTFChars(module_name
, &iscopy
);
249 MainController::execute_control(mod_name
);
250 env
->ReleaseStringUTFChars(module_name
, mod_name
);
253 JNIEXPORT
void JNICALL
Java_org_eclipse_titan_executor_jni_JNIMiddleWare_execute_1testcase(JNIEnv
*env
, jobject
, jstring module_name
, jstring testcase_name
)
255 // Fix for TR HO56282.
256 if (!Jnimw::userInterface
)
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
);
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.
275 * NOTE: Function comment is here, because function declaration is in org_eclipse_titan_executor_jni_JNIMiddleWare.h, which is generated.
277 JNIEXPORT jint JNICALL
Java_org_eclipse_titan_executor_jni_JNIMiddleWare_get_1execute_1cfg_1len(JNIEnv
*env
, jobject
)
279 return (jint
)Jnimw::mycfg
.execute_list_len
;
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
290 * NOTE: Function comment is here, because function declaration is in org_eclipse_titan_executor_jni_JNIMiddleWare.h, which is generated.
292 JNIEXPORT
void JNICALL
Java_org_eclipse_titan_executor_jni_JNIMiddleWare_execute_1cfg(JNIEnv
*env
, jobject
, jint index
)
294 if (!Jnimw::userInterface
)
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");
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
);
306 MainController::execute_testcase( item
.module_name
, item
.testcase_name
);
310 JNIEXPORT
void JNICALL
Java_org_eclipse_titan_executor_jni_JNIMiddleWare_stop_1after_1testcase(JNIEnv
*, jobject
, jboolean new_state
)
312 // Fix for TR HO56282.
313 if (!Jnimw::userInterface
)
315 MainController::stop_after_testcase((bool)new_state
);
318 JNIEXPORT
void JNICALL
Java_org_eclipse_titan_executor_jni_JNIMiddleWare_continue_1testcase(JNIEnv
*, jobject
)
320 // Fix for TR HO56282.
321 if (!Jnimw::userInterface
)
323 MainController::continue_testcase();
326 JNIEXPORT
void JNICALL
Java_org_eclipse_titan_executor_jni_JNIMiddleWare_stop_1execution(JNIEnv
*, jobject
)
328 // Fix for TR HO56282.
329 if (!Jnimw::userInterface
)
331 MainController::stop_execution();
334 JNIEXPORT jobject JNICALL
Java_org_eclipse_titan_executor_jni_JNIMiddleWare_get_1state(JNIEnv
*env
, jobject
)
336 jclass cls
= env
->FindClass("org/eclipse/titan/executor/jni/McStateEnum");
338 printf("Can't find class org.eclipse.titan.executor.jni.McStateEnum\n");
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;");
349 printf("Can't find field MC_INACTIVE\n");
352 switch (MainController::get_state()) {
353 case mctr::MC_INACTIVE
:
354 fid
= env
->GetStaticFieldID(cls
, "MC_INACTIVE",
355 "Lorg/eclipse/titan/executor/jni/McStateEnum;");
357 printf("Can't find field MC_INACTIVE\n");
360 case mctr::MC_LISTENING
:
361 fid
= env
->GetStaticFieldID(cls
, "MC_LISTENING",
362 "Lorg/eclipse/titan/executor/jni/McStateEnum;");
364 printf("Can't find field MC_LISTENING\n");
367 case mctr::MC_LISTENING_CONFIGURED
:
368 fid
= env
->GetStaticFieldID(cls
, "MC_LISTENING_CONFIGURED",
369 "Lorg/eclipse/titan/executor/jni/McStateEnum;");
371 printf("Can't find field MC_LISTENING_CONFIGURED\n");
374 case mctr::MC_HC_CONNECTED
:
375 fid
= env
->GetStaticFieldID(cls
, "MC_HC_CONNECTED",
376 "Lorg/eclipse/titan/executor/jni/McStateEnum;");
378 printf("Can't find field MC_HC_CONNECTED\n");
381 case mctr::MC_CONFIGURING
:
382 fid
= env
->GetStaticFieldID(cls
, "MC_CONFIGURING",
383 "Lorg/eclipse/titan/executor/jni/McStateEnum;");
385 printf("Can't find field MC_CONFIGURING\n");
388 case mctr::MC_ACTIVE
:
389 fid
= env
->GetStaticFieldID(cls
, "MC_ACTIVE",
390 "Lorg/eclipse/titan/executor/jni/McStateEnum;");
392 printf("Can't find field MC_ACTIVE\n");
395 case mctr::MC_SHUTDOWN
:
396 fid
= env
->GetStaticFieldID(cls
, "MC_SHUTDOWN",
397 "Lorg/eclipse/titan/executor/jni/McStateEnum;");
399 printf("Can't find field MC_SHUTDOWN\n");
402 case mctr::MC_CREATING_MTC
:
403 fid
= env
->GetStaticFieldID(cls
, "MC_CREATING_MTC",
404 "Lorg/eclipse/titan/executor/jni/McStateEnum;");
406 printf("Can't find field MC_CREATING_MTC\n");
410 fid
= env
->GetStaticFieldID(cls
, "MC_READY",
411 "Lorg/eclipse/titan/executor/jni/McStateEnum;");
413 printf("Can't find field MC_READY\n");
416 case mctr::MC_TERMINATING_MTC
:
417 fid
= env
->GetStaticFieldID(cls
, "MC_TERMINATING_MTC",
418 "Lorg/eclipse/titan/executor/jni/McStateEnum;");
420 printf("Can't find field MC_TERMINATING_MTC\n");
423 case mctr::MC_EXECUTING_CONTROL
:
424 fid
= env
->GetStaticFieldID(cls
, "MC_EXECUTING_CONTROL",
425 "Lorg/eclipse/titan/executor/jni/McStateEnum;");
427 printf("Can't find field MC_EXECUTING_CONTROL\n");
430 case mctr::MC_EXECUTING_TESTCASE
:
431 fid
= env
->GetStaticFieldID(cls
, "MC_EXECUTING_TESTCASE",
432 "Lorg/eclipse/titan/executor/jni/McStateEnum;");
434 printf("Can't find field MC_EXECUTING_TESTCASE\n");
437 case mctr::MC_TERMINATING_TESTCASE
:
438 fid
= env
->GetStaticFieldID(cls
, "MC_TERMINATING_TESTCASE",
439 "Lorg/eclipse/titan/executor/jni/McStateEnum;");
441 printf("Can't find field MC_TERMINATING_TESTCASE\n");
444 case mctr::MC_PAUSED
:
445 fid
= env
->GetStaticFieldID(cls
, "MC_PAUSED",
446 "Lorg/eclipse/titan/executor/jni/McStateEnum;");
448 printf("Can't find field MC_PAUSED\n");
452 printf("Unknown mc_state_enum state\n");
455 ret
= env
->GetStaticObjectField(cls
, fid
);
456 env
->ExceptionClear();
460 JNIEXPORT jboolean JNICALL
Java_org_eclipse_titan_executor_jni_JNIMiddleWare_get_1stop_1after_1testcase(JNIEnv
*, jobject
)
462 // Fix for TR HO56282.
463 if (!Jnimw::userInterface
)
464 return (jboolean
)true;
465 return (jboolean
)MainController::get_stop_after_testcase();
468 JNIEXPORT jint JNICALL
Java_org_eclipse_titan_executor_jni_JNIMiddleWare_get_1nof_1hosts(JNIEnv
*, jobject
)
470 // Fix for TR HO56282.
471 if (!Jnimw::userInterface
)
473 return (jint
)MainController::get_nof_hosts();
476 JNIEXPORT jobject JNICALL
Java_org_eclipse_titan_executor_jni_JNIMiddleWare_get_1host_1data(JNIEnv
*env
, jobject
, jint host_index
)
478 // Fix for TR HO56282.
479 if (!Jnimw::userInterface
)
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
;
501 /*// --- DEBUG --- filling test data
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;
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 ---*/
530 // creating HostStruct
531 jclass cls
= env
->FindClass("org/eclipse/titan/executor/jni/HostStruct");
533 printf("Can't find class org.eclipse.titan.executor.jni.HostStruct\n");
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
);
541 // processing struct fields
543 const char *ipaddr
= ip_addr
->get_addr_str();
544 fid
= env
->GetFieldID(cls
, "ip_addr", "Ljava/lang/String;");
546 printf("Can't find field hostname\n");
548 env
->SetObjectField(HostStruct
, fid
, env
->NewStringUTF(ipaddr
));
551 fid
= env
->GetFieldID(cls
, "hostname", "Ljava/lang/String;");
553 printf("Can't find field hostname\n");
555 env
->SetObjectField(HostStruct
, fid
, env
->NewStringUTF(hostname
));
558 fid
= env
->GetFieldID(cls
, "hostname_local", "Ljava/lang/String;");
560 printf("Can't find field hostname_local\n");
562 env
->SetObjectField(HostStruct
, fid
, env
->NewStringUTF(hostname_local
));
565 fid
= env
->GetFieldID(cls
, "machine_type", "Ljava/lang/String;");
567 printf("Can't find field machine_type\n");
569 env
->SetObjectField(HostStruct
, fid
, env
->NewStringUTF(machine_type
));
572 fid
= env
->GetFieldID(cls
, "system_name", "Ljava/lang/String;");
574 printf("Can't find field system_name\n");
576 env
->SetObjectField(HostStruct
, fid
, env
->NewStringUTF(system_name
));
579 fid
= env
->GetFieldID(cls
, "system_release", "Ljava/lang/String;");
581 printf("Can't find field system_release\n");
583 env
->SetObjectField(HostStruct
, fid
, env
->NewStringUTF(system_release
));
586 fid
= env
->GetFieldID(cls
, "system_version", "Ljava/lang/String;");
588 printf("Can't find field system_version\n");
590 env
->SetObjectField(HostStruct
, fid
, env
->NewStringUTF(system_version
));
592 // transport_supported
593 fid
= env
->GetFieldID(cls
, "transport_supported", "[Z");
595 printf("Can't find field transport_supported\n");
597 jbooleanArray TransportSupported
= (jbooleanArray
)env
->GetObjectField(HostStruct
, fid
);
598 env
->SetBooleanArrayRegion(TransportSupported
, (jsize
)0, 3,(jboolean
*)transport_supported
);
601 fid
= env
->GetFieldID(cls
, "log_source", "Ljava/lang/String;");
603 printf("Can't find field log_source\n");
605 env
->SetObjectField(HostStruct
, fid
, env
->NewStringUTF(log_source
));
608 fid
= env
->GetFieldID(cls
, "hc_state", "Lorg/eclipse/titan/executor/jni/HcStateEnum;");
610 printf("Can't find field hc_state\n");
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");
621 fid_hc
= env
->GetStaticFieldID(cls_hc
, "HC_IDLE", "Lorg/eclipse/titan/executor/jni/HcStateEnum;");
623 printf("Can't find field HC_IDLE\n");
626 case mctr::HC_CONFIGURING
:
627 fid_hc
= env
->GetStaticFieldID(cls_hc
, "HC_CONFIGURING", "Lorg/eclipse/titan/executor/jni/HcStateEnum;");
629 printf("Can't find field HC_CONFIGURING\n");
632 case mctr::HC_ACTIVE
:
633 fid_hc
= env
->GetStaticFieldID(cls_hc
, "HC_ACTIVE", "Lorg/eclipse/titan/executor/jni/HcStateEnum;");
635 printf("Can't find field HC_ACTIVE\n");
638 case mctr::HC_OVERLOADED
:
639 fid_hc
= env
->GetStaticFieldID(cls_hc
, "HC_OVERLOADED", "Lorg/eclipse/titan/executor/jni/HcStateEnum;");
641 printf("Can't find field HC_OVERLOADED\n");
644 case mctr::HC_CONFIGURING_OVERLOADED
:
645 fid_hc
= env
->GetStaticFieldID(cls_hc
, "HC_CONFIGURING_OVERLOADED", "Lorg/eclipse/titan/executor/jni/HcStateEnum;");
647 printf("Can't find field HC_CONFIGURING_OVERLOADED\n");
650 // ----------------------------------------------- 6-7
651 case mctr::HC_EXITING
:
652 fid_hc
= env
->GetStaticFieldID(cls_hc
, "HC_EXITING", "Lorg/eclipse/titan/executor/jni/HcStateEnum;");
654 printf("Can't find field HC_EXITING\n");
658 fid_hc
= env
->GetStaticFieldID(cls_hc
, "HC_DOWN", "Lorg/eclipse/titan/executor/jni/HcStateEnum;");
660 printf("Can't find field HC_DOWN\n");
664 printf("Unknown hc_state_enum state\n");
666 ret
= env
->GetStaticObjectField(cls_hc
, fid_hc
);
667 env
->ExceptionClear();
668 env
->SetObjectField(HostStruct
, fid
, ret
);
671 fid
= env
->GetFieldID(cls
, "hc_fd", "I");
673 printf("Can't find field hc_fd\n");
675 env
->SetIntField(HostStruct
, fid
, (jint
)hc_fd
);
678 fid
= env
->GetFieldID(cls
, "text_buf", "[B");
680 printf("Can't find field text_buf\n");
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()));
687 fid
= env
->GetFieldID(cls
, "components", "[I");
689 printf("Can't find field components\n");
692 jintArray Components
= (jintArray
)env
->GetObjectField(HostStruct
, fid
);
693 env
->SetIntArrayRegion(Components
, (jsize
)0,n_components
,(jint
*)components
);
695 // allowed_components
696 fid
= env
->GetFieldID(cls
, "allowed_components", "[Ljava/lang/String;");
698 printf("Can't find field allowed_components\n");
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
]));
705 // all_components_allowed
706 fid
= env
->GetFieldID(cls
, "all_components_allowed", "Z");
708 printf("Can't find field all_components_allowed\n");
710 env
->SetBooleanField(HostStruct
, fid
, (jboolean
)all_components_allowed
);
712 // n_active_components
713 fid
= env
->GetFieldID(cls
, "n_active_components", "I");
715 printf("Can't find field n_active_components\n");
717 env
->SetIntField(HostStruct
, fid
, (jint
)n_active_components
);
722 JNIEXPORT jobject JNICALL
Java_org_eclipse_titan_executor_jni_JNIMiddleWare_get_1component_1data(JNIEnv
*env
, jobject
, jint component_reference
)
724 // Fix for TR HO56282.
725 if (!Jnimw::userInterface
)
727 mctr::component_struct
*cs
= MainController::get_component_data((int)component_reference
);
728 if (cs
== NULL
) return NULL
;
730 // getting data from struct
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
) {
744 const char *log_source
= cs
->log_source
;
745 if ( NULL
== log_source
) {
748 mctr::host_struct
*comp_location
= cs
->comp_location
;
749 if ( NULL
== comp_location
) {
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
) {
759 qualified_name tc_fn_name
= cs
->tc_fn_name
;
760 const char *return_type
= cs
->return_type
;
761 if ( NULL
== return_type
) {
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
;
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;
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;
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 ---*/
821 // creating ComponentStruct
822 jclass cls
= env
->FindClass("org/eclipse/titan/executor/jni/ComponentStruct");
824 printf("Can't find class org.eclipse.titan.executor.jni.ComponentStruct\n");
828 jobject ComponentStruct
;
829 mid
= env
->GetMethodID(cls
, "<init>", "(I)V");
830 ComponentStruct
= env
->NewObject(cls
, mid
, text_buf
->get_len());
832 // processing struct fields
834 fid
= env
->GetFieldID(cls
, "comp_ref", "I");
836 printf("Can't find field comp_ref\n");
838 env
->SetIntField(ComponentStruct
, fid
, (jint
) comp_ref
);
841 fid
= env
->GetFieldID(cls
, "comp_type", "Lorg/eclipse/titan/executor/jni/QualifiedName;");
843 printf("Can't find field comp_type\n");
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");
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
);
857 fid
= env
->GetFieldID(cls
, "comp_name", "Ljava/lang/String;");
859 printf("Can't find field comp_name\n");
861 env
->SetObjectField(ComponentStruct
, fid
, env
->NewStringUTF(comp_name
));
864 fid
= env
->GetFieldID(cls
, "log_source", "Ljava/lang/String;");
866 printf("Can't find field log_source\n");
868 env
->SetObjectField(ComponentStruct
, fid
, env
->NewStringUTF(log_source
));
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");
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
);
882 if(env
->ExceptionOccurred()) {
883 printf("error at creating HostStruct\n");
884 env
->ExceptionDescribe();
885 env
->ExceptionClear();
887 // processing struct fields
889 const char *ipaddr
= comp_location
->ip_addr
->get_addr_str();
890 fid_hs
= env
->GetFieldID(cls_hs
, "ip_addr", "Ljava/lang/String;");
892 printf("Can't find field hostname\n");
894 env
->SetObjectField(HostStruct
, fid_hs
, env
->NewStringUTF(ipaddr
));
897 fid_hs
= env
->GetFieldID(cls_hs
, "hostname", "Ljava/lang/String;");
899 printf("Can't find field hostname\n");
901 env
->SetObjectField(HostStruct
, fid_hs
, env
->NewStringUTF(comp_location
->hostname
));
904 fid_hs
= env
->GetFieldID(cls_hs
, "hostname_local", "Ljava/lang/String;");
906 printf("Can't find field hostname_local\n");
908 env
->SetObjectField(HostStruct
, fid_hs
, env
->NewStringUTF(comp_location
->hostname_local
));
911 fid_hs
= env
->GetFieldID(cls_hs
, "machine_type", "Ljava/lang/String;");
913 printf("Can't find field machine_type\n");
915 env
->SetObjectField(HostStruct
, fid_hs
, env
->NewStringUTF(comp_location
->machine_type
));
918 fid_hs
= env
->GetFieldID(cls_hs
, "system_name", "Ljava/lang/String;");
920 printf("Can't find field system_name\n");
922 env
->SetObjectField(HostStruct
, fid_hs
, env
->NewStringUTF(comp_location
->system_name
));
925 fid_hs
= env
->GetFieldID(cls_hs
, "system_release", "Ljava/lang/String;");
927 printf("Can't find field system_release\n");
929 env
->SetObjectField(HostStruct
, fid_hs
, env
->NewStringUTF(comp_location
->system_release
));
932 fid_hs
= env
->GetFieldID(cls_hs
, "system_version", "Ljava/lang/String;");
934 printf("Can't find field system_version\n");
936 env
->SetObjectField(HostStruct
, fid_hs
, env
->NewStringUTF(comp_location
->system_version
));
938 // transport_supported
939 fid_hs
= env
->GetFieldID(cls_hs
, "transport_supported", "[Z");
941 printf("Can't find field transport_supported\n");
943 jbooleanArray TransportSupported
= (jbooleanArray
)env
->GetObjectField(HostStruct
, fid_hs
);
944 env
->SetBooleanArrayRegion(TransportSupported
, (jsize
)0, 3,(jboolean
*)comp_location
->transport_supported
);
947 fid_hs
= env
->GetFieldID(cls_hs
, "log_source", "Ljava/lang/String;");
949 printf("Can't find field log_source\n");
951 env
->SetObjectField(HostStruct
, fid_hs
, env
->NewStringUTF(comp_location
->log_source
));
954 fid_hs
= env
->GetFieldID(cls_hs
, "hc_state", "Lorg/eclipse/titan/executor/jni/HcStateEnum;");
956 printf("Can't find field hc_state\n");
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");
963 jfieldID fid_hs_hc
= 0;
965 switch(comp_location
->hc_state
) {
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");
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");
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");
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");
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");
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");
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");
1010 printf("Unknown hc_state_enum state\n");
1012 ret
= env
->GetStaticObjectField(cls_hs_hc
, fid_hs_hc
);
1013 env
->ExceptionClear();
1014 env
->SetObjectField(HostStruct
, fid_hs
, ret
);
1017 fid_hs
= env
->GetFieldID(cls_hs
, "hc_fd", "I");
1019 printf("Can't find field hc_fd\n");
1021 env
->SetIntField(HostStruct
, fid_hs
, (jint
)comp_location
->hc_fd
);
1024 fid_hs
= env
->GetFieldID(cls_hs
, "text_buf", "[B");
1026 printf("Can't find field text_buf\n");
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()));
1033 fid_hs
= env
->GetFieldID(cls_hs
, "components", "[I");
1035 printf("Can't find field components\n");
1038 jintArray Components
= (jintArray
)env
->GetObjectField(HostStruct
, fid_hs
);
1039 env
->SetIntArrayRegion(Components
, (jsize
)0, comp_location
->n_components
, (jint
*)comp_location
->components
);
1041 // allowed_components
1042 fid_hs
= env
->GetFieldID(cls_hs
, "allowed_components", "[Ljava/lang/String;");
1044 printf("Can't find field allowed_components\n");
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
]));
1051 // all_components_allowed
1052 fid_hs
= env
->GetFieldID(cls_hs
, "all_components_allowed", "Z");
1054 printf("Can't find field all_components_allowed\n");
1056 env
->SetBooleanField(HostStruct
, fid_hs
, (jboolean
)comp_location
->all_components_allowed
);
1058 // n_active_components
1059 fid_hs
= env
->GetFieldID(cls_hs
, "n_active_components", "I");
1061 printf("Can't find field n_active_components\n");
1063 env
->SetIntField(HostStruct
, fid_hs
, (jint
)comp_location
->n_active_components
);
1066 env
->SetObjectField(ComponentStruct
, fid
, HostStruct
); // finally setting inner host_struct
1067 // end of comp_location --------------------------------
1070 fid
= env
->GetFieldID(cls
, "tc_state", "Lorg/eclipse/titan/executor/jni/TcStateEnum;");
1072 printf("Can't find field tc_state\n");
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");
1079 jfieldID fid_tc
= 0;
1082 case mctr::TC_INITIAL
:
1083 fid_tc
= env
->GetStaticFieldID(cls_tc
, "TC_INITIAL", "Lorg/eclipse/titan/executor/jni/TcStateEnum;");
1085 printf("Can't find field TC_INITIAL\n");
1089 fid_tc
= env
->GetStaticFieldID(cls_tc
, "TC_IDLE", "Lorg/eclipse/titan/executor/jni/TcStateEnum;");
1091 printf("Can't find field TC_IDLE\n");
1094 case mctr::TC_CREATE
:
1095 fid_tc
= env
->GetStaticFieldID(cls_tc
, "TC_CREATE", "Lorg/eclipse/titan/executor/jni/TcStateEnum;");
1097 printf("Can't find field TC_CREATE\n");
1100 case mctr::TC_START
:
1101 fid_tc
= env
->GetStaticFieldID(cls_tc
, "TC_START", "Lorg/eclipse/titan/executor/jni/TcStateEnum;");
1103 printf("Can't find field TC_START\n");
1107 fid_tc
= env
->GetStaticFieldID(cls_tc
, "TC_STOP", "Lorg/eclipse/titan/executor/jni/TcStateEnum;");
1109 printf("Can't find field TC_STOP\n");
1112 // ----------------------------------------------- 6-10
1114 fid_tc
= env
->GetStaticFieldID(cls_tc
, "TC_KILL", "Lorg/eclipse/titan/executor/jni/TcStateEnum;");
1116 printf("Can't find field TC_KILL\n");
1119 case mctr::TC_CONNECT
:
1120 fid_tc
= env
->GetStaticFieldID(cls_tc
, "TC_CONNECT", "Lorg/eclipse/titan/executor/jni/TcStateEnum;");
1122 printf("Can't find field TC_CONNECT\n");
1125 case mctr::TC_DISCONNECT
:
1126 fid_tc
= env
->GetStaticFieldID(cls_tc
, "TC_DISCONNECT", "Lorg/eclipse/titan/executor/jni/TcStateEnum;");
1128 printf("Can't find field TC_DISCONNECT\n");
1132 fid_tc
= env
->GetStaticFieldID(cls_tc
, "TC_MAP", "Lorg/eclipse/titan/executor/jni/TcStateEnum;");
1134 printf("Can't find field TC_MAP\n");
1137 case mctr::TC_UNMAP
:
1138 fid_tc
= env
->GetStaticFieldID(cls_tc
, "TC_UNMAP", "Lorg/eclipse/titan/executor/jni/TcStateEnum;");
1140 printf("Can't find field TC_UNMAP\n");
1143 // ----------------------------------------------- 11-15
1144 case mctr::TC_STOPPING
:
1145 fid_tc
= env
->GetStaticFieldID(cls_tc
, "TC_STOPPING", "Lorg/eclipse/titan/executor/jni/TcStateEnum;");
1147 printf("Can't find field TC_STOPPING\n");
1150 case mctr::TC_EXITING
:
1151 fid_tc
= env
->GetStaticFieldID(cls_tc
, "TC_EXITING", "Lorg/eclipse/titan/executor/jni/TcStateEnum;");
1153 printf("Can't find field TC_EXITING\n");
1156 case mctr::TC_EXITED
:
1157 fid_tc
= env
->GetStaticFieldID(cls_tc
, "TC_EXITED", "Lorg/eclipse/titan/executor/jni/TcStateEnum;");
1159 printf("Can't find field TC_EXITED\n");
1162 case mctr::MTC_CONTROLPART
:
1163 fid_tc
= env
->GetStaticFieldID(cls_tc
, "MTC_CONTROLPART", "Lorg/eclipse/titan/executor/jni/TcStateEnum;");
1165 printf("Can't find field MTC_CONTROLPART\n");
1168 case mctr::MTC_TESTCASE
:
1169 fid_tc
= env
->GetStaticFieldID(cls_tc
, "MTC_TESTCASE", "Lorg/eclipse/titan/executor/jni/TcStateEnum;");
1171 printf("Can't find field MTC_TESTCASE\n");
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;");
1178 printf("Can't find field MTC_ALL_COMPONENT_STOP\n");
1181 case mctr::MTC_ALL_COMPONENT_KILL
:
1182 fid_tc
= env
->GetStaticFieldID(cls_tc
, "MTC_ALL_COMPONENT_KILL", "Lorg/eclipse/titan/executor/jni/TcStateEnum;");
1184 printf("Can't find field MTC_ALL_COMPONENT_KILL\n");
1186 ret_tc
= env
->GetStaticObjectField(cls_tc
, fid_tc
);
1187 env
->ExceptionClear();
1189 case mctr::MTC_TERMINATING_TESTCASE
:
1190 fid_tc
= env
->GetStaticFieldID(cls_tc
, "MTC_TERMINATING_TESTCASE", "Lorg/eclipse/titan/executor/jni/TcStateEnum;");
1192 printf("Can't find field MTC_TERMINATING_TESTCASE\n");
1195 case mctr::MTC_PAUSED
:
1196 fid_tc
= env
->GetStaticFieldID(cls_tc
, "MTC_PAUSED", "Lorg/eclipse/titan/executor/jni/TcStateEnum;");
1198 printf("Can't find field MTC_PAUSED\n");
1201 case mctr::PTC_FUNCTION
:
1202 fid_tc
= env
->GetStaticFieldID(cls_tc
, "PTC_FUNCTION", "Lorg/eclipse/titan/executor/jni/TcStateEnum;");
1204 printf("Can't find field PTC_FUNCTION\n");
1207 // ----------------------------------------------- 21-25
1208 case mctr::PTC_STARTING
:
1209 fid_tc
= env
->GetStaticFieldID(cls_tc
, "PTC_STARTING", "Lorg/eclipse/titan/executor/jni/TcStateEnum;");
1211 printf("Can't find field PTC_STARTING\n");
1214 case mctr::PTC_STOPPED
:
1215 fid_tc
= env
->GetStaticFieldID(cls_tc
, "PTC_STOPPED", "Lorg/eclipse/titan/executor/jni/TcStateEnum;");
1217 printf("Can't find field PTC_STOPPED\n");
1220 case mctr::PTC_KILLING
:
1221 fid_tc
= env
->GetStaticFieldID(cls_tc
, "PTC_KILLING", "Lorg/eclipse/titan/executor/jni/TcStateEnum;");
1223 printf("Can't find field PTC_KILLING\n");
1226 case mctr::PTC_STOPPING_KILLING
:
1227 fid_tc
= env
->GetStaticFieldID(cls_tc
, "PTC_STOPPING_KILLING", "Lorg/eclipse/titan/executor/jni/TcStateEnum;");
1229 printf("Can't find field PTC_STOPPING_KILLING\n");
1232 case mctr::PTC_STALE
:
1233 fid_tc
= env
->GetStaticFieldID(cls_tc
, "PTC_STALE", "Lorg/eclipse/titan/executor/jni/TcStateEnum;");
1235 printf("Can't find field PTC_STALE\n");
1238 // ----------------------------------------------- 26
1239 case mctr::TC_SYSTEM
:
1240 fid_tc
= env
->GetStaticFieldID(cls_tc
, "TC_SYSTEM", "Lorg/eclipse/titan/executor/jni/TcStateEnum;");
1242 printf("Can't find field TC_SYSTEM\n");
1246 printf("Unknown tc_state_enum state\n");
1248 ret_tc
= env
->GetStaticObjectField(cls_tc
, fid_tc
);
1249 env
->ExceptionClear();
1250 env
->SetObjectField(ComponentStruct
, fid
, ret_tc
);
1253 fid
= env
->GetFieldID(cls
, "local_verdict", "Lorg/eclipse/titan/executor/jni/VerdictTypeEnum;");
1255 printf("Can't find field local_verdict\n");
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");
1263 switch(local_verdict
) {
1265 fid_v
= env
->GetStaticFieldID(cls_v
, "NONE", "Lorg/eclipse/titan/executor/jni/VerdictTypeEnum;");
1267 printf("Can't find field NONE\n");
1271 fid_v
= env
->GetStaticFieldID(cls_v
, "PASS", "Lorg/eclipse/titan/executor/jni/VerdictTypeEnum;");
1273 printf("Can't find field PASS\n");
1277 fid_v
= env
->GetStaticFieldID(cls_v
, "INCONC", "Lorg/eclipse/titan/executor/jni/VerdictTypeEnum;");
1279 printf("Can't find field INCONC\n");
1283 fid_v
= env
->GetStaticFieldID(cls_v
, "FAIL", "Lorg/eclipse/titan/executor/jni/VerdictTypeEnum;");
1285 printf("Can't find field FAIL\n");
1289 fid_v
= env
->GetStaticFieldID(cls_v
, "ERROR", "Lorg/eclipse/titan/executor/jni/VerdictTypeEnum;");
1291 printf("Can't find field ERROR\n");
1295 printf("Unknown tc_state_enum state\n");
1297 ret_v
= env
->GetStaticObjectField(cls_v
, fid_v
);
1298 env
->ExceptionClear();
1299 env
->SetObjectField(ComponentStruct
, fid
, ret_v
);
1302 fid
= env
->GetFieldID(cls
, "tc_fd", "I");
1304 printf("Can't find field tc_fd\n");
1306 env
->SetIntField(ComponentStruct
, fid
, (jint
)tc_fd
);
1309 fid
= env
->GetFieldID(cls
, "text_buf", "[B");
1311 printf("Can't find field text_buf\n");
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()));
1318 fid
= env
->GetFieldID(cls
, "tc_fn_name", "Lorg/eclipse/titan/executor/jni/QualifiedName;");
1320 printf("Can't find field tc_fn_name\n");
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");
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
);
1334 fid
= env
->GetFieldID(cls
, "return_type", "Ljava/lang/String;");
1336 printf("Can't find field return_type\n");
1338 env
->SetObjectField(ComponentStruct
, fid
, env
->NewStringUTF(return_type
));
1341 fid
= env
->GetFieldID(cls
, "return_value_len", "I");
1343 printf("Can't find field return_value_len\n");
1345 env
->SetIntField(ComponentStruct
, fid
, (jint
)return_value_len
);
1348 fid
= env
->GetFieldID(cls
, "is_alive", "Z");
1350 printf("Can't find field is_alive\n");
1352 env
->SetBooleanField(ComponentStruct
, fid
, (jboolean
)is_alive
);
1355 fid
= env
->GetFieldID(cls
, "stop_requested", "Z");
1357 printf("Can't find field stop_requested\n");
1359 env
->SetBooleanField(ComponentStruct
, fid
, (jboolean
)stop_requested
);
1362 fid
= env
->GetFieldID(cls
, "process_killed", "Z");
1364 printf("Can't find field process_killed\n");
1366 env
->SetBooleanField(ComponentStruct
, fid
, (jboolean
)process_killed
);
1368 return ComponentStruct
;
1371 JNIEXPORT
void JNICALL Java_org_eclipse_titan_executor_jni_JNIMiddleWare_release_1data
1372 (JNIEnv
*, jobject
) {
1373 MainController::release_data();
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
);
1380 printf("Can't find class org.eclipse.titan.executor.jni.McStateEnum\n");
1382 jmethodID mid
= env
->GetMethodID(cls
, "getValue", "()I");
1384 printf("Can't find method getValue\n");
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
));
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
);
1395 printf("Can't find class org.eclipse.titan.executor.jni.HcStateEnum\n");
1397 jmethodID mid
= env
->GetMethodID(cls
, "getValue", "()I");
1399 printf("Can't find method getValue\n");
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
));
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
);
1410 printf("Can't find class org.eclipse.titan.executor.jni.TcStateEnum\n");
1412 jmethodID mid
= env
->GetMethodID(cls
, "getValue", "()I");
1414 printf("Can't find method getValue\n");
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
));
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
);
1425 printf("Can't find class org.eclipse.titan.executor.jni.TransportTypeEnum\n");
1427 jmethodID mid
= env
->GetMethodID(cls
, "getValue", "()I");
1429 printf("Can't find method getValue\n");
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
));
1436 // *******************************************************
1437 // Other native functions
1438 // *******************************************************
1440 JNIEXPORT
void JNICALL Java_org_eclipse_titan_executor_jni_JNIMiddleWare_check_1mem_1leak
1441 (JNIEnv
*env
, jobject
, jstring program_name
) {
1443 const char *p_name
= env
->GetStringUTFChars(program_name
, &iscopy
);
1444 check_mem_leak(p_name
);
1445 env
->ReleaseStringUTFChars(program_name
, p_name
);
1448 JNIEXPORT
void JNICALL Java_org_eclipse_titan_executor_jni_JNIMiddleWare_print_1license_1info
1449 (JNIEnv
*, jobject
) {
1451 print_license_info();
1455 JNIEXPORT jint JNICALL Java_org_eclipse_titan_executor_jni_JNIMiddleWare_check_1license
1456 (JNIEnv
*, jobject
) {
1459 license_struct lstr
;
1461 load_license(&lstr
);
1462 if (!verify_license(&lstr
)) {
1463 free_license(&lstr
);
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
);
1472 max_ptcs
= lstr
.max_ptcs
;
1473 free_license(&lstr
);
1478 return (jint
)max_ptcs
;
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
));
1487 JNIEXPORT jboolean JNICALL Java_org_eclipse_titan_executor_jni_JNIMiddleWare_isPipeReadable
1488 (JNIEnv
*, jobject
) {
1489 return ((jboolean
)Jnimw::userInterface
->is_pipe_readable());
1492 JNIEXPORT jlong JNICALL Java_org_eclipse_titan_executor_jni_JNIMiddleWare_getSharedLibraryVersion
1493 (JNIEnv
*, jclass
) {
1494 return (jlong
) TTCN3_VERSION
;