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
61 // calling ORTE function
62 b = ORTESubscriptionPropertiesGet((ORTESubscription *)j_appDomain_handle,
64 if (b == ORTE_BAD_HANDLE) {
65 printf(":!c: subscription get properties failed! [bad sub handle] \n");
69 cls_sp = findClass(env, "org.ocera.orte.types.SubsProp");
72 printf(":!c: cls_sp = NULL \n");
76 // call object constructor
77 mid = (*env)->GetMethodID(env, cls_sp, "<init>", "()V");
80 printf(":!c: mid = NULL \n");
85 obj_sp = (*env)->NewObject(env, cls_sp, mid);
88 printf(":!c: obj_sp = NULL \n");
93 printf(":c: instance of 'org.ocera.orte.types.SubsProp' created..\n");
95 // ///////////////////////////////////////////////
96 // setting object's fields
97 /////////////////////////////////////////////////
99 if (!setTopic(env, cls_sp, obj_sp, (const char *)subs_prop->topic)) {
101 printf(":!c: setTopic() failed! \n");
105 /////////////////////////////////////////////////
107 if (!setType(env, cls_sp, obj_sp, (const char *)subs_prop->typeName)) {
109 printf(":!c: setType() failed! \n");
113 /////////////////////////////////////////////////
114 // fieldID - typeChecksum
115 fid = (*env)->GetFieldID(env,
121 printf(":!c: fid = NULL \n");
125 (*env)->SetIntField(env,
128 (jint)subs_prop->typeChecksum);
129 /////////////////////////////////////////////////
130 // fieldID - minSeparation
131 cls_ntpT = findClass(env, "org.ocera.orte.types.NtpTime");
134 printf(":!c: cls_ntpT = NULL \n");
138 // call object constructor
139 mid = (*env)->GetMethodID(env, cls_ntpT, "<init>", "(IJ)V");
142 printf(":!c: mid = NULL \n");
147 obj_ntpT = (*env)->NewObject(env,
150 (jint)subs_prop->minimumSeparation.seconds,
151 (jlong)subs_prop->minimumSeparation.fraction);
154 printf(":!c: obj_ntpT = NULL \n");
159 printf(":c: instance of 'org.ocera.orte.types.NtpTime' created..\n");
161 // set 'SubsProp' NtpTime's field
162 fid = (*env)->GetFieldID(env,
165 "Lorg/ocera/orte/types/NtpTime;");
168 printf(":!c: fid = NULL \n");
172 (*env)->SetObjectField(env,
176 /////////////////////////////////////////////////
177 // fieldID - deadline
178 // pointers cls_ntpT, obj_ntpT already set
180 obj_ntpT = (*env)->NewObject(env,
183 (jint)subs_prop->deadline.seconds,
184 (jlong)subs_prop->deadline.fraction);
187 printf(":!c: obj_ntpT = NULL \n");
192 printf(":c: instance of 'org.ocera.orte.types.NtpTime' created..\n");
194 // set 'SubsProp' NtpTime's field
195 fid = (*env)->GetFieldID(env,
198 "Lorg/ocera/orte/types/NtpTime;");
201 printf(":!c: fid = NULL \n");
205 (*env)->SetObjectField(env,
209 /////////////////////////////////////////////////
210 // fieldID - recvQueueSize
211 fid = (*env)->GetFieldID(env,
217 printf(":!c: fid = NULL \n");
221 (*env)->SetLongField(env,
224 (jlong)subs_prop->recvQueueSize);
225 /////////////////////////////////////////////////
226 // fieldID - reliabilityRequested
227 fid = (*env)->GetFieldID(env,
229 "reliabilityRequested",
233 printf(":!c: fid = NULL \n");
237 (*env)->SetLongField(env,
240 (jlong)subs_prop->reliabilityRequested);
241 /////////////////////////////////////////////////
243 fid = (*env)->GetFieldID(env,
249 printf(":!c: fid = NULL \n");
253 (*env)->SetIntField(env,
256 (jint)subs_prop->mode);
257 /////////////////////////////////////////////////
258 // fieldID - multicastIPAddr
259 fid = (*env)->GetFieldID(env,
265 printf(":!c: fid = NULL \n");
269 (*env)->SetLongField(env,
272 (jlong)subs_prop->multicast);
278 // return created object