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.
30 // library header file's path
32 // getNtpTime function
33 #include "jorte/jorte_protos_api.h"
34 // enable TEST_STAGE run level
35 #include "jorte/4all.h"
36 // pregenerated header
37 #include "jorte/org_ocera_orte_Publication.h"
40 JNIEXPORT jboolean JNICALL
41 Java_org_ocera_orte_Publication_jORTEPublicationPropertiesSet
42 (JNIEnv *env, jobject obj, jlong j_appDomain_handle, jobject obj_pp)
47 jobject obj_ntpT = NULL;
48 jobject obj_str = NULL;
53 const char *str = NULL;
55 ORTEPublProp *publ_prop = &pp;
58 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");
70 printf(":!c: cls_pp = NULL \n");
74 // ///////////////////////////////////////////////
75 // setting object's fields
76 /////////////////////////////////////////////////
78 fid = (*env)->GetFieldID(env,
81 "Ljava/lang/String;");
85 printf(":!c: fid = NULL \n");
89 obj_str = (*env)->GetObjectField(env, obj_pp, fid);
93 printf(":!c: obj_str = NULL \n");
97 str = (*env)->GetStringUTFChars(env,obj_str,0);
98 // set structure's field
99 strncpy((char *)publ_prop->topic, (const char*)str, strlen(str) + 1);
101 printf(":c: topic = %s, publ_prop->topic = %s \n",
102 str, publ_prop->topic);
105 (*env)->ReleaseStringUTFChars(env, obj_pp, str);
106 /////////////////////////////////////////////////
108 fid = (*env)->GetFieldID(env,
111 "Ljava/lang/String;");
115 printf(":!c: fid = NULL \n");
119 obj_str = (*env)->GetObjectField(env, obj_pp, fid);
123 printf(":!c: obj_str = NULL \n");
127 str = (*env)->GetStringUTFChars(env,obj_str,0);
128 // set structure's field
129 strncpy((char *)publ_prop->typeName, (const char*)str, strlen(str) + 1);
131 printf(":c: typeName = %s, publ_prop->typeName = %s \n",
132 str, publ_prop->typeName);
135 (*env)->ReleaseStringUTFChars(env, obj_pp, str);
136 /////////////////////////////////////////////////
138 fid = (*env)->GetFieldID(env,cls_pp,"typeChecksum","I");
142 printf(":!c: fid = NULL \n");
146 publ_prop->typeChecksum = (TypeChecksum) (*env)->GetIntField(env, obj_pp, fid);
148 printf(":c: check: publ_prop->typeChecksum = %d\n",
149 publ_prop->typeChecksum);
151 /////////////////////////////////////////////////
153 fid = (*env)->GetFieldID(env,cls_pp,"expectsAck","Z");
157 printf(":!c: fid = NULL \n");
161 jbool = (*env)->GetBooleanField(env, obj_pp, fid);
162 if (jbool == 0) publ_prop->expectsAck = ORTE_FALSE;
163 else publ_prop->expectsAck = ORTE_TRUE;
165 printf(":c: check: publ_prop->expectsAck = %d\n", publ_prop->expectsAck);
167 /////////////////////////////////////////////////
169 fid = (*env)->GetFieldID(env,
172 "Lorg/ocera/orte/types/NtpTime;");
176 printf(":!c: fid = NULL \n");
180 obj_ntpT = (*env)->GetObjectField(env, obj_pp, fid);
184 printf(":!c: obj_ntpT = NULL \n");
188 publ_prop->persistence = getNtpTime(env, obj_ntpT);
190 printf(":c: check: publ_prop->persistence: sec = %d, fract = %d \n",
191 publ_prop->persistence.seconds, publ_prop->persistence.fraction);
193 /////////////////////////////////////////////////
194 // set reliabilityOffered
195 fid = (*env)->GetFieldID(env,
197 "reliabilityOffered",
202 printf(":!c: fid = NULL \n");
206 publ_prop->reliabilityOffered = (uint32_t) (*env)->GetLongField(env, obj_pp, fid);
208 printf(":c: check: publ_prop->reliabilityOffered = %d \n",
209 publ_prop->reliabilityOffered);
211 /////////////////////////////////////////////////
213 fid = (*env)->GetFieldID(env,
220 printf(":!c: fid = NULL \n");
224 publ_prop->sendQueueSize = (uint32_t) (*env)->GetLongField(env,obj_pp,fid);
226 printf(":c: check: publ_prop->sendQueueSize = %d \n",
227 publ_prop->sendQueueSize);
229 /////////////////////////////////////////////////
231 fid = (*env)->GetFieldID(env,
238 printf(":!c: fid = NULL \n");
242 publ_prop->strength = (int32_t) (*env)->GetIntField(env,obj_pp,fid);
244 printf(":c: check: publ_prop->strength = %d \n",
245 publ_prop->strength);
247 /////////////////////////////////////////////////
248 // set criticalQueueLevel
249 fid = (*env)->GetFieldID(env,
251 "criticalQueueLevel",
256 printf(":!c: fid = NULL \n");
260 publ_prop->criticalQueueLevel = (uint32_t) (*env)->GetLongField(env, obj_pp, fid);
262 printf(":c: check: publ_prop->criticalQueueLevel = %d \n",
263 publ_prop->criticalQueueLevel);
265 /////////////////////////////////////////////////
267 fid = (*env)->GetFieldID(env,
270 "Lorg/ocera/orte/types/NtpTime;");
274 printf(":!c: fid = NULL \n");
278 obj_ntpT = (*env)->GetObjectField(env, obj_pp, fid);
279 publ_prop->HBNornalRate = getNtpTime(env, obj_ntpT);
281 printf(":c: check: publ_prop->HBNornalRate: sec = %d, fract = %d \n",
282 publ_prop->HBNornalRate.seconds, publ_prop->HBNornalRate.fraction);
284 /////////////////////////////////////////////////
286 fid = (*env)->GetFieldID(env,
289 "Lorg/ocera/orte/types/NtpTime;");
293 printf(":!c: fid = NULL \n");
297 obj_ntpT = (*env)->GetObjectField(env, obj_pp, fid);
301 printf(":!c: obj_ntpT = NULL \n");
305 publ_prop->HBCQLRate = getNtpTime(env, obj_ntpT);
307 printf(":c: check: publ_prop->HBCQLRate: sec = %d, fract = %d \n",
308 publ_prop->HBCQLRate.seconds, publ_prop->HBCQLRate.fraction);
310 /////////////////////////////////////////////////
312 fid = (*env)->GetFieldID(env,
319 printf(":!c: fid = NULL \n");
323 publ_prop->HBMaxRetries = (unsigned int) (*env)->GetLongField(env, obj_pp, fid);
325 printf(":c: check: publ_prop->HBMaxRetries = %d \n",
326 publ_prop->HBMaxRetries);
328 /////////////////////////////////////////////////
330 fid = (*env)->GetFieldID(env,
333 "Lorg/ocera/orte/types/NtpTime;");
337 printf(":!c: fid = NULL \n");
341 obj_ntpT = (*env)->GetObjectField(env, obj_pp, fid);
345 printf(":!c: obj_ntpT = NULL \n");
349 publ_prop->maxBlockTime = getNtpTime(env, obj_ntpT);
351 printf(":c: check: publ_prop->maxBlockTime: sec = %d, fract = %d \n",
352 publ_prop->maxBlockTime.seconds, publ_prop->maxBlockTime.fraction);
354 /////////////////////////////////////////////////
355 // calling original native method
356 b = ORTEPublicationPropertiesSet((ORTEPublication *) j_appDomain_handle,
358 if (b == ORTE_BAD_HANDLE)
360 printf(":c!: set pub properties failed! [bad pub handle] \n");