1 /* JORTEPublicationPropertiesSet.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.
31 // library header file's path
33 // getNtpTime function
34 #include "jorte/jorte_protos_api.h"
35 // enable TEST_STAGE run level
36 #include "jorte/4all.h"
37 // pregenerated header
38 #include "jorte/org_ocera_orte_Publication.h"
41 JNIEXPORT jboolean JNICALL
42 Java_org_ocera_orte_Publication_jORTEPublicationPropertiesSet
43 (JNIEnv *env, jobject obj, jlong j_appDomain_handle, jobject obj_pp)
48 jobject obj_ntpT = NULL;
49 jobject obj_str = NULL;
54 const char *str = NULL;
56 ORTEPublProp *publ_prop = &pp;
59 printf(":c: jORTEPublicationPropertiesSet() called.. \n");
63 // get 'SubProp' instance's class
64 cls_pp = (*env)->GetObjectClass(env, obj_pp);
65 // second way how to get 'PublProp' instance's class
66 //cls_pp = (*env)->FindClass(env,"org/ocera/orte/types/PublProp");
69 printf(":!c: cls_pp = NULL \n");
73 // ///////////////////////////////////////////////
74 // setting object's fields
75 /////////////////////////////////////////////////
77 fid = (*env)->GetFieldID(env,
80 "Ljava/lang/String;");
83 printf(":!c: fid = NULL \n");
87 obj_str = (*env)->GetObjectField(env, obj_pp, fid);
90 printf(":!c: obj_str = NULL \n");
94 str = (*env)->GetStringUTFChars(env, obj_str, 0);
95 // set structure's field
96 strncpy((char *)publ_prop->topic, (const char *)str, strlen(str) + 1);
98 printf(":c: topic = %s, publ_prop->topic = %s \n",
99 str, publ_prop->topic);
102 (*env)->ReleaseStringUTFChars(env, obj_str, str);
103 /////////////////////////////////////////////////
105 fid = (*env)->GetFieldID(env,
108 "Ljava/lang/String;");
111 printf(":!c: fid = NULL \n");
115 obj_str = (*env)->GetObjectField(env, obj_pp, fid);
118 printf(":!c: obj_str = NULL \n");
122 str = (*env)->GetStringUTFChars(env, obj_str, 0);
123 // set structure's field
124 strncpy((char *)publ_prop->typeName, (const char *)str, strlen(str) + 1);
126 printf(":c: typeName = %s, publ_prop->typeName = %s \n",
127 str, publ_prop->typeName);
130 (*env)->ReleaseStringUTFChars(env, obj_str, str);
131 /////////////////////////////////////////////////
133 fid = (*env)->GetFieldID(env, cls_pp, "typeChecksum", "I");
136 printf(":!c: fid = NULL \n");
140 publ_prop->typeChecksum = (TypeChecksum)(*env)->GetIntField(env, obj_pp, fid);
142 printf(":c: check: publ_prop->typeChecksum = %" PRId32 "\n",
143 publ_prop->typeChecksum);
145 /////////////////////////////////////////////////
147 fid = (*env)->GetFieldID(env, cls_pp, "expectsAck", "Z");
150 printf(":!c: fid = NULL \n");
154 jbool = (*env)->GetBooleanField(env, obj_pp, fid);
156 publ_prop->expectsAck = ORTE_FALSE;
158 publ_prop->expectsAck = ORTE_TRUE;
160 printf(":c: check: publ_prop->expectsAck = %" PRId8 "\n", publ_prop->expectsAck);
162 /////////////////////////////////////////////////
164 fid = (*env)->GetFieldID(env,
167 "Lorg/ocera/orte/types/NtpTime;");
170 printf(":!c: fid = NULL \n");
174 obj_ntpT = (*env)->GetObjectField(env, obj_pp, fid);
177 printf(":!c: obj_ntpT = NULL \n");
181 publ_prop->persistence = getNtpTime(env, obj_ntpT);
183 printf(":c: check: publ_prop->persistence: sec = %" PRId32 ", fract = %" PRIu32 " \n",
184 publ_prop->persistence.seconds, publ_prop->persistence.fraction);
186 /////////////////////////////////////////////////
187 // set reliabilityOffered
188 fid = (*env)->GetFieldID(env,
190 "reliabilityOffered",
194 printf(":!c: fid = NULL \n");
198 publ_prop->reliabilityOffered = (uint32_t)(*env)->GetLongField(env, obj_pp, fid);
200 printf(":c: check: publ_prop->reliabilityOffered = %" PRIu32 " \n",
201 publ_prop->reliabilityOffered);
203 /////////////////////////////////////////////////
205 fid = (*env)->GetFieldID(env,
211 printf(":!c: fid = NULL \n");
215 publ_prop->sendQueueSize = (uint32_t)(*env)->GetLongField(env, obj_pp, fid);
217 printf(":c: check: publ_prop->sendQueueSize = %" PRIu32 " \n",
218 publ_prop->sendQueueSize);
220 /////////////////////////////////////////////////
222 fid = (*env)->GetFieldID(env,
228 printf(":!c: fid = NULL \n");
232 publ_prop->strength = (int32_t)(*env)->GetIntField(env, obj_pp, fid);
234 printf(":c: check: publ_prop->strength = %" PRId32 " \n",
235 publ_prop->strength);
237 /////////////////////////////////////////////////
238 // set criticalQueueLevel
239 fid = (*env)->GetFieldID(env,
241 "criticalQueueLevel",
245 printf(":!c: fid = NULL \n");
249 publ_prop->criticalQueueLevel = (uint32_t)(*env)->GetLongField(env, obj_pp, fid);
251 printf(":c: check: publ_prop->criticalQueueLevel = %" PRIu32 " \n",
252 publ_prop->criticalQueueLevel);
254 /////////////////////////////////////////////////
256 fid = (*env)->GetFieldID(env,
259 "Lorg/ocera/orte/types/NtpTime;");
262 printf(":!c: fid = NULL \n");
266 obj_ntpT = (*env)->GetObjectField(env, obj_pp, fid);
267 publ_prop->HBNornalRate = getNtpTime(env, obj_ntpT);
269 printf(":c: check: publ_prop->HBNornalRate: sec = %" PRId32 ", fract = %" PRIu32 " \n",
270 publ_prop->HBNornalRate.seconds, publ_prop->HBNornalRate.fraction);
272 /////////////////////////////////////////////////
274 fid = (*env)->GetFieldID(env,
277 "Lorg/ocera/orte/types/NtpTime;");
280 printf(":!c: fid = NULL \n");
284 obj_ntpT = (*env)->GetObjectField(env, obj_pp, fid);
287 printf(":!c: obj_ntpT = NULL \n");
291 publ_prop->HBCQLRate = getNtpTime(env, obj_ntpT);
293 printf(":c: check: publ_prop->HBCQLRate: sec = %" PRId32 ", fract = %" PRIu32 " \n",
294 publ_prop->HBCQLRate.seconds, publ_prop->HBCQLRate.fraction);
296 /////////////////////////////////////////////////
298 fid = (*env)->GetFieldID(env,
304 printf(":!c: fid = NULL \n");
308 publ_prop->HBMaxRetries = (unsigned int)(*env)->GetLongField(env, obj_pp, fid);
310 printf(":c: check: publ_prop->HBMaxRetries = %u \n",
311 publ_prop->HBMaxRetries);
313 /////////////////////////////////////////////////
315 fid = (*env)->GetFieldID(env,
318 "Lorg/ocera/orte/types/NtpTime;");
321 printf(":!c: fid = NULL \n");
325 obj_ntpT = (*env)->GetObjectField(env, obj_pp, fid);
328 printf(":!c: obj_ntpT = NULL \n");
332 publ_prop->maxBlockTime = getNtpTime(env, obj_ntpT);
334 printf(":c: check: publ_prop->maxBlockTime: sec = %" PRId32 ", fract = %" PRIu32 " \n",
335 publ_prop->maxBlockTime.seconds, publ_prop->maxBlockTime.fraction);
337 /////////////////////////////////////////////////
338 // calling original native method
339 b = ORTEPublicationPropertiesSet((ORTEPublication *)j_appDomain_handle,
341 if (b == ORTE_BAD_HANDLE) {
342 printf(":c!: set pub properties failed! [bad pub handle] \n");