1 /* JORTEPublicationPropertiesGet.c */
4 * This code provides conversion between JAVA a C environments.
5 * The C functions are calling here and results are send to JAVA
6 * native functions. It uses the header pregenerated by JAVA
7 * (by command 'javah -jni class_with_native_function')
9 * @author Lukas Pokorny (lukas_pokorny@centrum.cz)
10 * @author CTU FEE Prague - Department of Control Engineering (dce.felk.cvut.cz)
11 * @author Project ORTE - OCERA Real Time Ethernet (www.ocera.org)
12 * @author dedication to Kj
16 * This program is free software; you can redistribute it and/or modify
17 * it under the terms of the GNU General Public License as published by
18 * the Free Software Foundation; either version 2 of the License, or
19 * (at your option) any later version.
21 * This program is distributed in the hope that it will be useful,
22 * but WITHOUT ANY WARRANTY; without even the implied warranty of
23 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
24 * GNU General Public License for more details.
30 // library header file's path
32 // enable TEST_STAGE run level
33 #include "jorte/4all.h"
34 #include "jorte/jorte_protos_api.h"
35 // pregenerated header
36 #include "jorte/org_ocera_orte_Publication.h"
39 JNIEXPORT jobject JNICALL
40 Java_org_ocera_orte_Publication_jORTEPublicationPropertiesGet
41 (JNIEnv *env, jobject obj, jlong j_appDomain_handle)
44 jclass cls_pp = NULL; // PublProp class
45 jclass cls_ntpT = NULL; // NtpTime class
46 jobject obj_pp = NULL; // instance of PublProp
47 jobject obj_ntpT = NULL; // instance of NtpTime
55 ORTEPublProp *publ_prop = &pp;
57 // calling original orte function
59 printf(":c: ORTEPublicationPropertiesGet() called.. \n");
62 // create new PublProps instance and set its fields
65 b = ORTEPublicationPropertiesGet((ORTEPublication *)j_appDomain_handle,
67 if (b == ORTE_BAD_HANDLE) {
68 printf(":!c: PublicationPropertiesGet() failed! [bad pub handle] \n");
72 cls_pp = findClass(env, "org.ocera.orte.types.PublProp");
75 printf(":!c: cls_pp = NULL \n");
79 // call object constructor
80 mid = (*env)->GetMethodID(env, cls_pp, "<init>", "()V");
83 printf(":!c: mid = NULL \n");
88 obj_pp = (*env)->NewObject(env, cls_pp, mid);
91 printf(":!c: obj_pp = NULL \n");
96 printf(":c: instance of 'org.ocera.orte.types.PublProp' created..\n");
98 // ///////////////////////////////////////////////
99 // setting object's fields
100 /////////////////////////////////////////////////
102 if (!setTopic(env, cls_pp, obj_pp, (const char *)publ_prop->topic)) {
104 printf(":!c: setTopic() failed! \n");
108 /////////////////////////////////////////////////
110 if (!setType(env, cls_pp, obj_pp, (const char *)publ_prop->typeName)) {
112 printf(":!c: setType() failed! \n");
116 /////////////////////////////////////////////////
117 // fieldID - typeChecksum
118 fid = (*env)->GetFieldID(env,
124 printf(":!c: fid = NULL \n");
128 (*env)->SetIntField(env,
131 (jint)publ_prop->typeChecksum);
132 /////////////////////////////////////////////////
133 // fieldID - expectsAck
134 fid = (*env)->GetFieldID(env,
140 printf(":!c: fid = NULL \n");
144 if (publ_prop->expectsAck == ORTE_FALSE)
148 (*env)->SetBooleanField(env,
152 /////////////////////////////////////////////////
153 // fieldID - persistence
154 cls_ntpT = findClass(env, "org.ocera.orte.types.NtpTime");
157 printf(":!c: cls_ntpT = NULL \n");
161 // call object constructor
162 mid = (*env)->GetMethodID(env, cls_ntpT, "<init>", "(IJ)V");
165 printf(":!c: mid = NULL \n");
170 obj_ntpT = (*env)->NewObject(env,
173 (jint)publ_prop->persistence.seconds,
174 (jlong)publ_prop->persistence.fraction);
177 printf(":!c: obj_ntpT = NULL \n");
182 printf(":c: instance of 'org.ocera.orte.types.NtpTime' created..\n");
184 // set 'PublProp' NtpTime's field
185 fid = (*env)->GetFieldID(env,
188 "Lorg/ocera/orte/types/NtpTime;");
191 printf(":!c: fid = NULL \n");
195 (*env)->SetObjectField(env,
199 /////////////////////////////////////////////////
200 // fieldID - HBNornalRate
201 // cls_ntpT and obj_ntpT already readed!!
203 obj_ntpT = (*env)->NewObject(env,
206 (jint)publ_prop->HBNornalRate.seconds,
207 (jlong)publ_prop->HBNornalRate.fraction);
210 printf(":!c: obj_ntpT = NULL \n");
215 printf(":c: instance of 'org.ocera.orte.types.NtpTime' created..\n");
217 // set 'PublProp' NtpTime's field
218 fid = (*env)->GetFieldID(env,
221 "Lorg/ocera/orte/types/NtpTime;");
224 printf(":!c: fid = NULL \n");
228 (*env)->SetObjectField(env,
232 /////////////////////////////////////////////////
233 // fieldID - HBCQLRate
234 // cls_ntpT and obj_ntpT already readed!!
236 obj_ntpT = (*env)->NewObject(env,
239 (jint)publ_prop->HBCQLRate.seconds,
240 (jlong)publ_prop->HBCQLRate.fraction);
243 printf(":!c: obj_ntpT = NULL \n");
248 printf(":c: instance of 'org.ocera.orte.types.NtpTime' created..\n");
250 // set 'PublProp' NtpTime's field
251 fid = (*env)->GetFieldID(env,
254 "Lorg/ocera/orte/types/NtpTime;");
257 printf(":!c: fid = NULL \n");
261 (*env)->SetObjectField(env,
265 /////////////////////////////////////////////////
266 // fieldID - HBCQLRate
267 // cls_ntpT and obj_ntpT already readed!!
269 obj_ntpT = (*env)->NewObject(env,
272 (jint)publ_prop->maxBlockTime.seconds,
273 (jlong)publ_prop->maxBlockTime.fraction);
276 printf(":!c: obj_ntpT = NULL \n");
281 printf(":c: instance of 'org.ocera.orte.types.NtpTime' created..\n");
283 // set 'PublProp' NtpTime's field
284 fid = (*env)->GetFieldID(env,
287 "Lorg/ocera/orte/types/NtpTime;");
290 printf(":!c: fid = NULL \n");
294 (*env)->SetObjectField(env,
298 /////////////////////////////////////////////////
299 // fieldID - reliabilityOffered
300 fid = (*env)->GetFieldID(env,
302 "reliabilityOffered",
306 printf(":!c: fid = NULL \n");
310 (*env)->SetLongField(env,
313 (jlong)publ_prop->reliabilityOffered);
314 /////////////////////////////////////////////////
315 // fieldID - sendQueueSize
316 fid = (*env)->GetFieldID(env,
322 printf(":!c: fid = NULL \n");
326 (*env)->SetLongField(env,
329 (jlong)publ_prop->sendQueueSize);
330 /////////////////////////////////////////////////
331 // fieldID - strength
332 fid = (*env)->GetFieldID(env,
338 printf(":!c: fid = NULL \n");
342 (*env)->SetIntField(env,
345 (jint)publ_prop->strength);
346 /////////////////////////////////////////////////
347 // fieldID - criticalQueueLevel
348 fid = (*env)->GetFieldID(env,
350 "criticalQueueLevel",
354 printf(":!c: fid = NULL \n");
358 (*env)->SetLongField(env,
361 (jlong)publ_prop->criticalQueueLevel);
362 /////////////////////////////////////////////////
363 // fieldID - HBMaxRetries
364 fid = (*env)->GetFieldID(env,
370 printf(":!c: fid = NULL \n");
374 (*env)->SetLongField(env,
377 (jlong)publ_prop->HBMaxRetries);