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.
30 // library header file's path
32 // getNtpTime function
33 #include "jorte/jorte_protos_api.h"
34 // enable TEST_STAGE run level
35 #include "jorte/4all.h"
36 // pregenerated header
37 #include "jorte/org_ocera_orte_Subscription.h"
40 JNIEXPORT jboolean JNICALL
41 Java_org_ocera_orte_Subscription_jORTESubscriptionPropertiesSet
42 (JNIEnv *env, jobject obj, jint j_appDomain_handle, jobject obj_sp)
47 jobject j_minSeparation = NULL;
48 jobject j_deadline = NULL;
49 jobject obj_str = NULL;
53 const char *str = NULL;
55 ORTESubsProp *subs_prop = &sp;
58 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");
69 printf(":!c: class 'org.ocera.orte.types.SubsProp' not found! \n");
72 // ///////////////////////////////////////////////
73 // setting object's fields
74 /////////////////////////////////////////////////
76 fid = (*env)->GetFieldID(env,
79 "Ljava/lang/String;");
83 printf(":!c: fid = NULL \n");
87 obj_str = (*env)->GetObjectField(env, obj_sp, fid);
91 printf(":!c: obj_str = NULL \n");
95 str = (*env)->GetStringUTFChars(env,obj_str,0);
96 // Set the structure field.
97 strncpy((char *) subs_prop->topic, str, strlen(str) + 1);
99 printf(":c: topic = %s, subs_prop->topic = %s \n",
100 str, subs_prop->topic);
103 (*env)->ReleaseStringUTFChars(env, obj_sp, str);
104 /////////////////////////////////////////////////
105 // set topic - typeName
106 fid = (*env)->GetFieldID(env,
109 "Ljava/lang/String;");
113 printf(":!c: fid = NULL \n");
117 obj_str = (*env)->GetObjectField(env, obj_sp, fid);
121 printf(":!c: obj_str = NULL \n");
125 str = (*env)->GetStringUTFChars(env,obj_str,0);
126 // Set the structure field.
127 strncpy((char *) subs_prop->typeName, str, strlen(str) + 1);
129 printf(":c: typeName = %s, subs_prop->typeName = %s \n",
130 str, subs_prop->typeName);
133 (*env)->ReleaseStringUTFChars(env, obj_sp, str);
134 /////////////////////////////////////////////////
135 // set topic - typeChecksum
136 fid = (*env)->GetFieldID(env,cls_sp,"typeChecksum","I");
140 printf(":!c: fid = NULL \n");
144 subs_prop->typeChecksum = (TypeChecksum) (*env)->GetIntField(env, obj_sp, fid);
146 printf(":c: check: subs_prop->typeChecksum = %d\n",
147 subs_prop->typeChecksum);
149 /////////////////////////////////////////////////
150 // set topic - minimumSeparation
151 fid = (*env)->GetFieldID(env,
154 "Lorg/ocera/orte/types/NtpTime;");
158 printf(":!c: fid = NULL \n");
162 j_minSeparation = (*env)->GetObjectField(env, obj_sp, fid);
163 subs_prop->minimumSeparation = getNtpTime(env, j_minSeparation);
165 printf(":c: check: subs_prop->minimumSeparation: sec = %d, fract = %d \n",
166 subs_prop->minimumSeparation.seconds,
167 subs_prop->minimumSeparation.fraction);
169 /////////////////////////////////////////////////
170 // set topic - recvQueueSize
171 fid = (*env)->GetFieldID(env,cls_sp,"recvQueueSize","J");
175 printf(":!c: fid = NULL \n");
179 subs_prop->recvQueueSize = (uint32_t) (*env)->GetLongField(env, obj_sp, fid);
181 printf(":c: check: subs_prop->recvQueueSize = %d \n",
182 subs_prop->recvQueueSize);
184 /////////////////////////////////////////////////
185 // set topic - reliabilityRequested
186 fid = (*env)->GetFieldID(env,cls_sp,"reliabilityRequested","J");
190 printf(":!c: fid = NULL \n");
194 subs_prop->reliabilityRequested = (uint32_t) (*env)->GetLongField(env, obj_sp, fid);
196 printf(":c: check: subs_prop->reliabilityRequested = %d \n",
197 subs_prop->reliabilityRequested);
199 /////////////////////////////////////////////////
200 // set topic - deadline
201 fid = (*env)->GetFieldID(env,
204 "Lorg/ocera/orte/types/NtpTime;");
208 printf(":!c: fid = NULL \n");
212 j_deadline = (*env)->GetObjectField(env, obj_sp, fid);
213 subs_prop->deadline = getNtpTime(env, j_deadline);
215 printf(":c: check: subs_prop->deadline: sec = %d, fract = %d \n",
216 subs_prop->deadline.seconds, subs_prop->deadline.fraction);
218 /////////////////////////////////////////////////
220 fid = (*env)->GetFieldID(env,cls_sp,"mode","I");
224 printf(":!c: fid = NULL \n");
228 subs_prop->mode = (uint32_t) (*env)->GetIntField(env, obj_sp, fid);
230 printf(":c: check: subs_prop->mode = %d \n",
234 /////////////////////////////////////////////////
235 // set topic - multicastIPAddr READ-ONLY!!
236 fid = (*env)->GetFieldID(env,cls_sp,"multicastIPAddr","J");
240 printf(":!c: fid = NULL \n");
244 subs_prop->multicast = (IPAddress) (*env)->GetLongField(env, obj_sp, fid);
246 printf(":c: check: subs_prop->multicast = %d \n",
247 subs_prop->multicast);
250 // calling original native method
251 b = ORTESubscriptionPropertiesSet((ORTESubscription *) j_appDomain_handle, subs_prop);
252 if (b == ORTE_BAD_HANDLE)
254 printf(":c!: cannot set new Subscription Properties! [bad sub handle] \n");