1 /* JORTESubscriptionPropertiesGet.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 // pregenerated header
35 #include "jorte/org_ocera_orte_Subscription.h"
36 #include "jorte/jorte_protos_api.h"
38 JNIEXPORT jobject JNICALL
39 Java_org_ocera_orte_Subscription_jORTESubscriptionPropertiesGet
40 (JNIEnv *env, jobject obj, jlong j_appDomain_handle)
43 jclass cls_sp = NULL; // SubsProp class
44 jclass cls_ntpT = NULL; // NtpTime class
45 jobject obj_sp = NULL; // instance of SubsProp
46 jobject obj_ntpT = NULL ;// instance of NtpTime
53 ORTESubsProp *subs_prop = &sp;
56 printf(":c: ORTESubscriptionPropertiesGet() called.. \n");
59 // create new SubsProps instance and set its fields
62 // calling ORTE function
63 b = ORTESubscriptionPropertiesGet((ORTESubscription *)j_appDomain_handle,
65 if(b == ORTE_BAD_HANDLE)
67 printf(":!c: subscription get properties failed! [bad sub handle] \n");
71 cls_sp = findClass(env, "org.ocera.orte.types.SubsProp");
75 printf(":!c: cls_sp = NULL \n");
79 // call object constructor
80 mid = (*env)->GetMethodID(env, cls_sp, "<init>", "()V");
84 printf(":!c: mid = NULL \n");
89 obj_sp = (*env)->NewObject(env, cls_sp, mid);
93 printf(":!c: obj_sp = NULL \n");
98 printf(":c: instance of 'org.ocera.orte.types.SubsProp' created..\n");
100 // ///////////////////////////////////////////////
101 // setting object's fields
102 /////////////////////////////////////////////////
104 if(!setTopic(env,cls_sp,obj_sp,(const char *)subs_prop->topic))
107 printf(":!c: setTopic() failed! \n");
111 /////////////////////////////////////////////////
113 if(!setType(env,cls_sp,obj_sp,(const char *)subs_prop->typeName))
116 printf(":!c: setType() failed! \n");
120 /////////////////////////////////////////////////
121 // fieldID - typeChecksum
122 fid = (*env)->GetFieldID(env,
129 printf(":!c: fid = NULL \n");
133 (*env)->SetIntField(env,
136 (jint) subs_prop->typeChecksum);
137 /////////////////////////////////////////////////
138 // fieldID - minSeparation
139 cls_ntpT = findClass(env, "org.ocera.orte.types.NtpTime");
143 printf(":!c: cls_ntpT = NULL \n");
147 // call object constructor
148 mid = (*env)->GetMethodID(env, cls_ntpT, "<init>", "(IJ)V");
152 printf(":!c: mid = NULL \n");
157 obj_ntpT = (*env)->NewObject(env,
160 (jint) subs_prop->minimumSeparation.seconds,
161 (jlong) subs_prop->minimumSeparation.fraction);
165 printf(":!c: obj_ntpT = NULL \n");
170 printf(":c: instance of 'org.ocera.orte.types.NtpTime' created..\n");
172 // set 'SubsProp' NtpTime's field
173 fid = (*env)->GetFieldID(env,
176 "Lorg/ocera/orte/types/NtpTime;");
180 printf(":!c: fid = NULL \n");
184 (*env)->SetObjectField(env,
188 /////////////////////////////////////////////////
189 // fieldID - deadline
190 // pointers cls_ntpT, obj_ntpT already set
192 obj_ntpT = (*env)->NewObject(env,
195 (jint) subs_prop->deadline.seconds,
196 (jlong) subs_prop->deadline.fraction);
200 printf(":!c: obj_ntpT = NULL \n");
205 printf(":c: instance of 'org.ocera.orte.types.NtpTime' created..\n");
207 // set 'SubsProp' NtpTime's field
208 fid = (*env)->GetFieldID(env,
211 "Lorg/ocera/orte/types/NtpTime;");
215 printf(":!c: fid = NULL \n");
219 (*env)->SetObjectField(env,
223 /////////////////////////////////////////////////
224 // fieldID - recvQueueSize
225 fid = (*env)->GetFieldID(env,
232 printf(":!c: fid = NULL \n");
236 (*env)->SetLongField(env,
239 (jlong) subs_prop->recvQueueSize);
240 /////////////////////////////////////////////////
241 // fieldID - reliabilityRequested
242 fid = (*env)->GetFieldID(env,
244 "reliabilityRequested",
249 printf(":!c: fid = NULL \n");
253 (*env)->SetLongField(env,
256 (jlong) subs_prop->reliabilityRequested);
257 /////////////////////////////////////////////////
259 fid = (*env)->GetFieldID(env,
266 printf(":!c: fid = NULL \n");
270 (*env)->SetIntField(env,
273 (jint) subs_prop->mode);
274 /////////////////////////////////////////////////
275 // fieldID - multicastIPAddr
276 fid = (*env)->GetFieldID(env,
283 printf(":!c: fid = NULL \n");
287 (*env)->SetLongField(env,
290 (jlong) subs_prop->multicast);
296 // return created object