]> rtime.felk.cvut.cz Git - orte.git/blob - orte/libjorte/JORTESubscriptionPropertiesSet.c
improved JAVA interface from Lukas, update makefiles from msvc from Jan
[orte.git] / orte / libjorte / JORTESubscriptionPropertiesSet.c
1 /* JORTESubscriptionPropertiesSet.c */
2
3 /**
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')
8   *
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
13   * @version 0.1
14   *
15   *
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.
20   *
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.
25   *
26   */
27
28 #include <string.h>
29 #include <stdlib.h>
30 // library header file's path
31 #include "orte.h"
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"
38
39
40 JNIEXPORT jboolean JNICALL
41 Java_org_ocera_orte_Subscription_jORTESubscriptionPropertiesSet
42 (JNIEnv *env, jobject obj, jint j_appDomain_handle, jobject obj_sp)
43 {
44   // jni types
45   jclass         cls_sp = NULL;
46   jfieldID       fid = NULL;
47   jobject        j_minSeparation = NULL;
48   jobject        j_deadline = NULL;
49   jobject        obj_str = NULL;
50   //
51   int            b = 0;
52   int            flag_ok = 0;
53   const char    *str = NULL;
54   ORTESubsProp   sp;
55   ORTESubsProp  *subs_prop = &sp;
56
57   #ifdef TEST_STAGE
58     printf(":c: jORTESubscriptionPropertiesSet() called.. \n");
59   #endif
60
61   do
62   {
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");
67     if(cls_sp == 0)
68     {
69       printf(":!c: class 'org.ocera.orte.types.SubsProp' not found! \n");
70       break;
71     }
72     // ///////////////////////////////////////////////
73     // setting object's fields
74     /////////////////////////////////////////////////
75     // set topic
76     fid = (*env)->GetFieldID(env,
77                              cls_sp,
78                              "topic",
79                              "Ljava/lang/String;");
80     if(fid == 0)
81     {
82       #ifdef TEST_STAGE
83         printf(":!c: fid = NULL \n");
84       #endif
85       break;
86     }
87     obj_str = (*env)->GetObjectField(env, obj_sp, fid);
88     if(obj_str == 0)
89     {
90       #ifdef TEST_STAGE
91         printf(":!c: obj_str = NULL \n");
92       #endif
93       break;
94     }
95     str = (*env)->GetStringUTFChars(env,obj_str,0);
96     // Set the structure field.
97     strncpy((char *) subs_prop->topic, str, strlen(str) + 1);
98     #ifdef TEST_STAGE
99       printf(":c: topic = %s, subs_prop->topic = %s \n",
100              str, subs_prop->topic);
101     #endif
102     // free the memory
103     (*env)->ReleaseStringUTFChars(env, obj_sp, str);
104     /////////////////////////////////////////////////
105     // set topic - typeName
106     fid = (*env)->GetFieldID(env,
107                              cls_sp,
108                              "typeName",
109                              "Ljava/lang/String;");
110     if(fid == 0)
111     {
112       #ifdef TEST_STAGE
113         printf(":!c: fid = NULL \n");
114       #endif
115       break;
116     }
117     obj_str = (*env)->GetObjectField(env, obj_sp, fid);
118     if(obj_str == 0)
119     {
120       #ifdef TEST_STAGE
121         printf(":!c: obj_str = NULL \n");
122       #endif
123       break;
124     }
125     str = (*env)->GetStringUTFChars(env,obj_str,0);
126     // Set the structure field.
127     strncpy((char *) subs_prop->typeName, str, strlen(str) + 1);
128     #ifdef TEST_STAGE
129       printf(":c: typeName = %s, subs_prop->typeName = %s \n",
130              str, subs_prop->typeName);
131     #endif
132     // free the memory
133     (*env)->ReleaseStringUTFChars(env, obj_sp, str);
134     /////////////////////////////////////////////////
135     // set topic - typeChecksum
136     fid = (*env)->GetFieldID(env,cls_sp,"typeChecksum","I");
137     if(fid == 0)
138     {
139       #ifdef TEST_STAGE
140         printf(":!c: fid = NULL \n");
141       #endif
142       break;
143     }
144     subs_prop->typeChecksum = (TypeChecksum) (*env)->GetIntField(env, obj_sp, fid);
145     #ifdef TEST_STAGE
146       printf(":c: check: subs_prop->typeChecksum = %d\n",
147              subs_prop->typeChecksum);
148     #endif
149     /////////////////////////////////////////////////
150     // set topic - minimumSeparation
151     fid = (*env)->GetFieldID(env,
152                              cls_sp,
153                              "minSeparation",
154                              "Lorg/ocera/orte/types/NtpTime;");
155     if(fid == 0)
156     {
157       #ifdef TEST_STAGE
158         printf(":!c: fid = NULL \n");
159       #endif
160       break;
161     }
162     j_minSeparation = (*env)->GetObjectField(env, obj_sp, fid);
163     subs_prop->minimumSeparation = getNtpTime(env, j_minSeparation);
164     #ifdef TEST_STAGE
165       printf(":c: check: subs_prop->minimumSeparation: sec = %d, fract = %d \n",
166              subs_prop->minimumSeparation.seconds,
167              subs_prop->minimumSeparation.fraction);
168     #endif
169     /////////////////////////////////////////////////
170     // set topic - recvQueueSize
171     fid = (*env)->GetFieldID(env,cls_sp,"recvQueueSize","J");
172     if(fid == 0)
173     {
174       #ifdef TEST_STAGE
175         printf(":!c: fid = NULL \n");
176       #endif
177       break;
178     }
179     subs_prop->recvQueueSize = (uint32_t) (*env)->GetLongField(env, obj_sp, fid);
180     #ifdef TEST_STAGE
181       printf(":c: check: subs_prop->recvQueueSize = %d \n",
182              subs_prop->recvQueueSize);
183     #endif
184     /////////////////////////////////////////////////
185     // set topic - reliabilityRequested
186     fid = (*env)->GetFieldID(env,cls_sp,"reliabilityRequested","J");
187     if(fid == 0)
188     {
189       #ifdef TEST_STAGE
190         printf(":!c: fid = NULL \n");
191       #endif
192       break;
193     }
194     subs_prop->reliabilityRequested = (uint32_t) (*env)->GetLongField(env, obj_sp, fid);
195     #ifdef TEST_STAGE
196       printf(":c: check: subs_prop->reliabilityRequested = %d \n",
197              subs_prop->reliabilityRequested);
198     #endif
199     /////////////////////////////////////////////////
200     // set topic - deadline
201     fid = (*env)->GetFieldID(env,
202                              cls_sp,
203                              "deadline",
204                              "Lorg/ocera/orte/types/NtpTime;");
205     if(fid == 0)
206     {
207       #ifdef TEST_STAGE
208         printf(":!c: fid = NULL \n");
209       #endif
210       break;
211     }
212     j_deadline = (*env)->GetObjectField(env, obj_sp, fid);
213     subs_prop->deadline = getNtpTime(env, j_deadline);
214     #ifdef TEST_STAGE
215       printf(":c: check: subs_prop->deadline: sec = %d, fract = %d  \n",
216              subs_prop->deadline.seconds, subs_prop->deadline.fraction);
217     #endif
218     /////////////////////////////////////////////////
219     // set topic - mode
220     fid = (*env)->GetFieldID(env,cls_sp,"mode","I");
221     if(fid == 0)
222     {
223       #ifdef TEST_STAGE
224         printf(":!c: fid = NULL \n");
225       #endif
226       break;
227     }
228     subs_prop->mode = (uint32_t) (*env)->GetIntField(env, obj_sp, fid);
229     #ifdef TEST_STAGE
230       printf(":c: check: subs_prop->mode = %d \n",
231              subs_prop->mode);
232     #endif
233 /*
234     /////////////////////////////////////////////////
235     // set topic - multicastIPAddr READ-ONLY!!
236     fid = (*env)->GetFieldID(env,cls_sp,"multicastIPAddr","J");
237     if(fid == 0)
238     {
239       #ifdef TEST_STAGE
240         printf(":!c: fid = NULL \n");
241       #endif
242       break;
243     }
244     subs_prop->multicast = (IPAddress) (*env)->GetLongField(env, obj_sp, fid);
245     #ifdef TEST_STAGE
246       printf(":c: check: subs_prop->multicast = %d \n",
247              subs_prop->multicast);
248     #endif
249 */
250     // calling original native method
251     b = ORTESubscriptionPropertiesSet((ORTESubscription *) j_appDomain_handle, subs_prop);
252     if (b == ORTE_BAD_HANDLE)
253     {
254       printf(":c!: cannot set new Subscription Properties! [bad sub handle] \n");
255       break;
256     }
257     // set flag
258     flag_ok = 1;
259   } while(0);
260
261   if(flag_ok == 0)
262   {
263     return 0;
264   }
265
266   return 1;
267 }