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");
64 // get 'SubProp' instance's class
65 cls_pp = (*env)->GetObjectClass(env, obj_pp);
66 // second way how to get 'PublProp' instance's class
67 //cls_pp = (*env)->FindClass(env,"org/ocera/orte/types/PublProp");
71 printf(":!c: cls_pp = NULL \n");
75 // ///////////////////////////////////////////////
76 // setting object's fields
77 /////////////////////////////////////////////////
79 fid = (*env)->GetFieldID(env,
82 "Ljava/lang/String;");
86 printf(":!c: fid = NULL \n");
90 obj_str = (*env)->GetObjectField(env, obj_pp, fid);
94 printf(":!c: obj_str = NULL \n");
98 str = (*env)->GetStringUTFChars(env,obj_str,0);
99 // set structure's field
100 strncpy((char *)publ_prop->topic, (const char*)str, strlen(str) + 1);
102 printf(":c: topic = %s, publ_prop->topic = %s \n",
103 str, publ_prop->topic);
106 (*env)->ReleaseStringUTFChars(env, obj_pp, str);
107 /////////////////////////////////////////////////
109 fid = (*env)->GetFieldID(env,
112 "Ljava/lang/String;");
116 printf(":!c: fid = NULL \n");
120 obj_str = (*env)->GetObjectField(env, obj_pp, fid);
124 printf(":!c: obj_str = NULL \n");
128 str = (*env)->GetStringUTFChars(env,obj_str,0);
129 // set structure's field
130 strncpy((char *)publ_prop->typeName, (const char*)str, strlen(str) + 1);
132 printf(":c: typeName = %s, publ_prop->typeName = %s \n",
133 str, publ_prop->typeName);
136 (*env)->ReleaseStringUTFChars(env, obj_pp, str);
137 /////////////////////////////////////////////////
139 fid = (*env)->GetFieldID(env,cls_pp,"typeChecksum","I");
143 printf(":!c: fid = NULL \n");
147 publ_prop->typeChecksum = (TypeChecksum) (*env)->GetIntField(env, obj_pp, fid);
149 printf(":c: check: publ_prop->typeChecksum = %"PRId32"\n",
150 publ_prop->typeChecksum);
152 /////////////////////////////////////////////////
154 fid = (*env)->GetFieldID(env,cls_pp,"expectsAck","Z");
158 printf(":!c: fid = NULL \n");
162 jbool = (*env)->GetBooleanField(env, obj_pp, fid);
163 if (jbool == 0) publ_prop->expectsAck = ORTE_FALSE;
164 else publ_prop->expectsAck = ORTE_TRUE;
166 printf(":c: check: publ_prop->expectsAck = %"PRId8"\n", publ_prop->expectsAck);
168 /////////////////////////////////////////////////
170 fid = (*env)->GetFieldID(env,
173 "Lorg/ocera/orte/types/NtpTime;");
177 printf(":!c: fid = NULL \n");
181 obj_ntpT = (*env)->GetObjectField(env, obj_pp, fid);
185 printf(":!c: obj_ntpT = NULL \n");
189 publ_prop->persistence = getNtpTime(env, obj_ntpT);
191 printf(":c: check: publ_prop->persistence: sec = %"PRId32", fract = %"PRIu32" \n",
192 publ_prop->persistence.seconds, publ_prop->persistence.fraction);
194 /////////////////////////////////////////////////
195 // set reliabilityOffered
196 fid = (*env)->GetFieldID(env,
198 "reliabilityOffered",
203 printf(":!c: fid = NULL \n");
207 publ_prop->reliabilityOffered = (uint32_t) (*env)->GetLongField(env, obj_pp, fid);
209 printf(":c: check: publ_prop->reliabilityOffered = %"PRIu32" \n",
210 publ_prop->reliabilityOffered);
212 /////////////////////////////////////////////////
214 fid = (*env)->GetFieldID(env,
221 printf(":!c: fid = NULL \n");
225 publ_prop->sendQueueSize = (uint32_t) (*env)->GetLongField(env,obj_pp,fid);
227 printf(":c: check: publ_prop->sendQueueSize = %"PRIu32" \n",
228 publ_prop->sendQueueSize);
230 /////////////////////////////////////////////////
232 fid = (*env)->GetFieldID(env,
239 printf(":!c: fid = NULL \n");
243 publ_prop->strength = (int32_t) (*env)->GetIntField(env,obj_pp,fid);
245 printf(":c: check: publ_prop->strength = %"PRId32" \n",
246 publ_prop->strength);
248 /////////////////////////////////////////////////
249 // set criticalQueueLevel
250 fid = (*env)->GetFieldID(env,
252 "criticalQueueLevel",
257 printf(":!c: fid = NULL \n");
261 publ_prop->criticalQueueLevel = (uint32_t) (*env)->GetLongField(env, obj_pp, fid);
263 printf(":c: check: publ_prop->criticalQueueLevel = %"PRIu32" \n",
264 publ_prop->criticalQueueLevel);
266 /////////////////////////////////////////////////
268 fid = (*env)->GetFieldID(env,
271 "Lorg/ocera/orte/types/NtpTime;");
275 printf(":!c: fid = NULL \n");
279 obj_ntpT = (*env)->GetObjectField(env, obj_pp, fid);
280 publ_prop->HBNornalRate = getNtpTime(env, obj_ntpT);
282 printf(":c: check: publ_prop->HBNornalRate: sec = %"PRId32", fract = %"PRIu32" \n",
283 publ_prop->HBNornalRate.seconds, publ_prop->HBNornalRate.fraction);
285 /////////////////////////////////////////////////
287 fid = (*env)->GetFieldID(env,
290 "Lorg/ocera/orte/types/NtpTime;");
294 printf(":!c: fid = NULL \n");
298 obj_ntpT = (*env)->GetObjectField(env, obj_pp, fid);
302 printf(":!c: obj_ntpT = NULL \n");
306 publ_prop->HBCQLRate = getNtpTime(env, obj_ntpT);
308 printf(":c: check: publ_prop->HBCQLRate: sec = %"PRId32", fract = %"PRIu32" \n",
309 publ_prop->HBCQLRate.seconds, publ_prop->HBCQLRate.fraction);
311 /////////////////////////////////////////////////
313 fid = (*env)->GetFieldID(env,
320 printf(":!c: fid = NULL \n");
324 publ_prop->HBMaxRetries = (unsigned int) (*env)->GetLongField(env, obj_pp, fid);
326 printf(":c: check: publ_prop->HBMaxRetries = %u \n",
327 publ_prop->HBMaxRetries);
329 /////////////////////////////////////////////////
331 fid = (*env)->GetFieldID(env,
334 "Lorg/ocera/orte/types/NtpTime;");
338 printf(":!c: fid = NULL \n");
342 obj_ntpT = (*env)->GetObjectField(env, obj_pp, fid);
346 printf(":!c: obj_ntpT = NULL \n");
350 publ_prop->maxBlockTime = getNtpTime(env, obj_ntpT);
352 printf(":c: check: publ_prop->maxBlockTime: sec = %"PRId32", fract = %"PRIu32" \n",
353 publ_prop->maxBlockTime.seconds, publ_prop->maxBlockTime.fraction);
355 /////////////////////////////////////////////////
356 // calling original native method
357 b = ORTEPublicationPropertiesSet((ORTEPublication *) j_appDomain_handle,
359 if (b == ORTE_BAD_HANDLE)
361 printf(":c!: set pub properties failed! [bad pub handle] \n");