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