1 /* JORTESubscriptionPropertiesSet.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_Subscription.h"
41 JNIEXPORT jboolean JNICALL
42 Java_org_ocera_orte_Subscription_jORTESubscriptionPropertiesSet
43 (JNIEnv *env, jobject obj, jlong j_appDomain_handle, jobject obj_sp)
48 jobject j_minSeparation = NULL;
49 jobject j_deadline = NULL;
50 jobject obj_str = NULL;
54 const char *str = NULL;
56 ORTESubsProp *subs_prop = &sp;
59 printf(":c: jORTESubscriptionPropertiesSet() called.. \n");
64 // get SubsProp instance's class
65 cls_sp = (*env)->GetObjectClass(env, obj_sp);
66 // second way how to get 'SubProp' instance's class
67 //cls_sp = (*env)->FindClass(env,"org/ocera/orte/types/SubsProp");
70 printf(":!c: class 'org.ocera.orte.types.SubsProp' not found! \n");
73 // ///////////////////////////////////////////////
74 // setting object's fields
75 /////////////////////////////////////////////////
77 fid = (*env)->GetFieldID(env,
80 "Ljava/lang/String;");
84 printf(":!c: fid = NULL \n");
88 obj_str = (*env)->GetObjectField(env, obj_sp, fid);
92 printf(":!c: obj_str = NULL \n");
96 str = (*env)->GetStringUTFChars(env,obj_str,0);
97 // Set the structure field.
98 strncpy((char *)subs_prop->topic, (const char*)str, strlen(str) + 1);
100 printf(":c: topic = %s, subs_prop->topic = %s \n",
101 str, subs_prop->topic);
104 (*env)->ReleaseStringUTFChars(env, obj_str, str);
105 /////////////////////////////////////////////////
106 // set topic - typeName
107 fid = (*env)->GetFieldID(env,
110 "Ljava/lang/String;");
114 printf(":!c: fid = NULL \n");
118 obj_str = (*env)->GetObjectField(env, obj_sp, fid);
122 printf(":!c: obj_str = NULL \n");
126 str = (*env)->GetStringUTFChars(env,obj_str,0);
127 // Set the structure field.
128 strncpy((char *)subs_prop->typeName, (const char*)str, strlen(str) + 1);
130 printf(":c: typeName = %s, subs_prop->typeName = %s \n",
131 str, subs_prop->typeName);
134 (*env)->ReleaseStringUTFChars(env, obj_str, str);
135 /////////////////////////////////////////////////
136 // set topic - typeChecksum
137 fid = (*env)->GetFieldID(env,cls_sp,"typeChecksum","I");
141 printf(":!c: fid = NULL \n");
145 subs_prop->typeChecksum = (TypeChecksum) (*env)->GetIntField(env, obj_sp, fid);
147 printf(":c: check: subs_prop->typeChecksum = %"PRId32"\n",
148 subs_prop->typeChecksum);
150 /////////////////////////////////////////////////
151 // set topic - minimumSeparation
152 fid = (*env)->GetFieldID(env,
155 "Lorg/ocera/orte/types/NtpTime;");
159 printf(":!c: fid = NULL \n");
163 j_minSeparation = (*env)->GetObjectField(env, obj_sp, fid);
164 subs_prop->minimumSeparation = getNtpTime(env, j_minSeparation);
166 printf(":c: check: subs_prop->minimumSeparation: sec = %"PRId32", fract = %"PRIu32" \n",
167 subs_prop->minimumSeparation.seconds,
168 subs_prop->minimumSeparation.fraction);
170 /////////////////////////////////////////////////
171 // set topic - recvQueueSize
172 fid = (*env)->GetFieldID(env,cls_sp,"recvQueueSize","J");
176 printf(":!c: fid = NULL \n");
180 subs_prop->recvQueueSize = (uint32_t) (*env)->GetLongField(env, obj_sp, fid);
182 printf(":c: check: subs_prop->recvQueueSize = %"PRIu32" \n",
183 subs_prop->recvQueueSize);
185 /////////////////////////////////////////////////
186 // set topic - reliabilityRequested
187 fid = (*env)->GetFieldID(env,cls_sp,"reliabilityRequested","J");
191 printf(":!c: fid = NULL \n");
195 subs_prop->reliabilityRequested = (uint32_t) (*env)->GetLongField(env, obj_sp, fid);
197 printf(":c: check: subs_prop->reliabilityRequested = %"PRIu32" \n",
198 subs_prop->reliabilityRequested);
200 /////////////////////////////////////////////////
201 // set topic - deadline
202 fid = (*env)->GetFieldID(env,
205 "Lorg/ocera/orte/types/NtpTime;");
209 printf(":!c: fid = NULL \n");
213 j_deadline = (*env)->GetObjectField(env, obj_sp, fid);
214 subs_prop->deadline = getNtpTime(env, j_deadline);
216 printf(":c: check: subs_prop->deadline: sec = %"PRId32", fract = %"PRIu32" \n",
217 subs_prop->deadline.seconds, subs_prop->deadline.fraction);
219 /////////////////////////////////////////////////
221 fid = (*env)->GetFieldID(env,cls_sp,"mode","I");
225 printf(":!c: fid = NULL \n");
229 subs_prop->mode = (uint32_t) (*env)->GetIntField(env, obj_sp, fid);
231 printf(":c: check: subs_prop->mode = %"PRIu32" \n",
235 /////////////////////////////////////////////////
236 // set topic - multicastIPAddr READ-ONLY!!
237 fid = (*env)->GetFieldID(env,cls_sp,"multicastIPAddr","J");
241 printf(":!c: fid = NULL \n");
245 subs_prop->multicast = (IPAddress) (*env)->GetLongField(env, obj_sp, fid);
247 printf(":c: check: subs_prop->multicast = %d \n",
248 subs_prop->multicast);
251 // calling original native method
252 b = ORTESubscriptionPropertiesSet((ORTESubscription *) j_appDomain_handle, subs_prop);
253 if (b == ORTE_BAD_HANDLE)
255 printf(":c!: cannot set new Subscription Properties! [bad sub handle] \n");