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");
63 // get SubsProp instance's class
64 cls_sp = (*env)->GetObjectClass(env, obj_sp);
65 // second way how to get 'SubProp' instance's class
66 //cls_sp = (*env)->FindClass(env,"org/ocera/orte/types/SubsProp");
68 printf(":!c: class 'org.ocera.orte.types.SubsProp' not found! \n");
71 // ///////////////////////////////////////////////
72 // setting object's fields
73 /////////////////////////////////////////////////
75 fid = (*env)->GetFieldID(env,
78 "Ljava/lang/String;");
81 printf(":!c: fid = NULL \n");
85 obj_str = (*env)->GetObjectField(env, obj_sp, fid);
88 printf(":!c: obj_str = NULL \n");
92 str = (*env)->GetStringUTFChars(env, obj_str, 0);
93 // Set the structure field.
94 strncpy((char *)subs_prop->topic, (const char *)str, strlen(str) + 1);
96 printf(":c: topic = %s, subs_prop->topic = %s \n",
97 str, subs_prop->topic);
100 (*env)->ReleaseStringUTFChars(env, obj_str, str);
101 /////////////////////////////////////////////////
102 // set topic - typeName
103 fid = (*env)->GetFieldID(env,
106 "Ljava/lang/String;");
109 printf(":!c: fid = NULL \n");
113 obj_str = (*env)->GetObjectField(env, obj_sp, fid);
116 printf(":!c: obj_str = NULL \n");
120 str = (*env)->GetStringUTFChars(env, obj_str, 0);
121 // Set the structure field.
122 strncpy((char *)subs_prop->typeName, (const char *)str, strlen(str) + 1);
124 printf(":c: typeName = %s, subs_prop->typeName = %s \n",
125 str, subs_prop->typeName);
128 (*env)->ReleaseStringUTFChars(env, obj_str, str);
129 /////////////////////////////////////////////////
130 // set topic - typeChecksum
131 fid = (*env)->GetFieldID(env, cls_sp, "typeChecksum", "I");
134 printf(":!c: fid = NULL \n");
138 subs_prop->typeChecksum = (TypeChecksum)(*env)->GetIntField(env, obj_sp, fid);
140 printf(":c: check: subs_prop->typeChecksum = %" PRId32 "\n",
141 subs_prop->typeChecksum);
143 /////////////////////////////////////////////////
144 // set topic - minimumSeparation
145 fid = (*env)->GetFieldID(env,
148 "Lorg/ocera/orte/types/NtpTime;");
151 printf(":!c: fid = NULL \n");
155 j_minSeparation = (*env)->GetObjectField(env, obj_sp, fid);
156 subs_prop->minimumSeparation = getNtpTime(env, j_minSeparation);
158 printf(":c: check: subs_prop->minimumSeparation: sec = %" PRId32 ", fract = %" PRIu32 " \n",
159 subs_prop->minimumSeparation.seconds,
160 subs_prop->minimumSeparation.fraction);
162 /////////////////////////////////////////////////
163 // set topic - recvQueueSize
164 fid = (*env)->GetFieldID(env, cls_sp, "recvQueueSize", "J");
167 printf(":!c: fid = NULL \n");
171 subs_prop->recvQueueSize = (uint32_t)(*env)->GetLongField(env, obj_sp, fid);
173 printf(":c: check: subs_prop->recvQueueSize = %" PRIu32 " \n",
174 subs_prop->recvQueueSize);
176 /////////////////////////////////////////////////
177 // set topic - reliabilityRequested
178 fid = (*env)->GetFieldID(env, cls_sp, "reliabilityRequested", "J");
181 printf(":!c: fid = NULL \n");
185 subs_prop->reliabilityRequested = (uint32_t)(*env)->GetLongField(env, obj_sp, fid);
187 printf(":c: check: subs_prop->reliabilityRequested = %" PRIu32 " \n",
188 subs_prop->reliabilityRequested);
190 /////////////////////////////////////////////////
191 // set topic - deadline
192 fid = (*env)->GetFieldID(env,
195 "Lorg/ocera/orte/types/NtpTime;");
198 printf(":!c: fid = NULL \n");
202 j_deadline = (*env)->GetObjectField(env, obj_sp, fid);
203 subs_prop->deadline = getNtpTime(env, j_deadline);
205 printf(":c: check: subs_prop->deadline: sec = %" PRId32 ", fract = %" PRIu32 " \n",
206 subs_prop->deadline.seconds, subs_prop->deadline.fraction);
208 /////////////////////////////////////////////////
210 fid = (*env)->GetFieldID(env, cls_sp, "mode", "I");
213 printf(":!c: fid = NULL \n");
217 subs_prop->mode = (uint32_t)(*env)->GetIntField(env, obj_sp, fid);
219 printf(":c: check: subs_prop->mode = %" PRIu32 " \n",
223 /////////////////////////////////////////////////
224 // set topic - multicastIPAddr READ-ONLY!!
225 fid = (*env)->GetFieldID(env,cls_sp,"multicastIPAddr","J");
229 printf(":!c: fid = NULL \n");
233 subs_prop->multicast = (IPAddress) (*env)->GetLongField(env, obj_sp, fid);
235 printf(":c: check: subs_prop->multicast = %d \n",
236 subs_prop->multicast);
239 // calling original native method
240 b = ORTESubscriptionPropertiesSet((ORTESubscription *)j_appDomain_handle, subs_prop);
241 if (b == ORTE_BAD_HANDLE) {
242 printf(":c!: cannot set new Subscription Properties! [bad sub handle] \n");