]> rtime.felk.cvut.cz Git - orte.git/blob - orte/libjorte/JORTESubscriptionPropertiesGet.c
Revert "JORTE: update license headers and clean-up includes"
[orte.git] / orte / libjorte / JORTESubscriptionPropertiesGet.c
1 /* JORTESubscriptionPropertiesGet.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 // 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"
37
38 JNIEXPORT jobject JNICALL
39 Java_org_ocera_orte_Subscription_jORTESubscriptionPropertiesGet
40 (JNIEnv *env, jobject obj, jlong j_appDomain_handle)
41 {
42   // jni types
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
47   jfieldID       fid      = NULL;
48   jmethodID      mid;
49   //
50   int            b = 0;
51   int            flag_ok = 0;
52   ORTESubsProp   sp;
53   ORTESubsProp  *subs_prop = &sp;
54
55   #ifdef TEST_STAGE
56     printf(":c: ORTESubscriptionPropertiesGet() called.. \n");
57   #endif
58
59   // create new SubsProps instance and set its fields
60   do
61   {
62     // calling ORTE function
63     b = ORTESubscriptionPropertiesGet((ORTESubscription *)j_appDomain_handle,
64                                       subs_prop);
65     if(b == ORTE_BAD_HANDLE)
66     {
67      printf(":!c: subscription get properties failed!  [bad sub handle] \n");
68      break;
69     }
70     // get cls
71     cls_sp = findClass(env, "org.ocera.orte.types.SubsProp");
72     if(cls_sp == 0)
73     {
74       #ifdef TEST_STAGE
75        printf(":!c: cls_sp = NULL \n");
76       #endif
77       break;
78     }
79     // call object constructor
80     mid = (*env)->GetMethodID(env, cls_sp, "<init>", "()V");
81     if(mid == 0)
82     {
83     #ifdef TEST_STAGE
84        printf(":!c: mid = NULL \n");
85       #endif
86       break;
87     }
88     // new object
89     obj_sp = (*env)->NewObject(env, cls_sp, mid);
90     if(obj_sp == 0)
91     {
92     #ifdef TEST_STAGE
93        printf(":!c: obj_sp = NULL \n");
94       #endif
95       break;
96     }
97     #ifdef TEST_STAGE
98       printf(":c: instance of 'org.ocera.orte.types.SubsProp' created..\n");
99     #endif
100     // ///////////////////////////////////////////////
101     // setting object's fields
102     /////////////////////////////////////////////////
103     // set topic
104     if(!setTopic(env,cls_sp,obj_sp,(const char *)subs_prop->topic))
105     {
106       #ifdef TEST_STAGE
107         printf(":!c: setTopic() failed! \n");
108       #endif
109       break;
110     }
111     /////////////////////////////////////////////////
112     // set type
113     if(!setType(env,cls_sp,obj_sp,(const char *)subs_prop->typeName))
114     {
115       #ifdef TEST_STAGE
116         printf(":!c: setType() failed! \n");
117       #endif
118       break;
119     }
120     /////////////////////////////////////////////////
121     // fieldID - typeChecksum
122     fid = (*env)->GetFieldID(env,
123                              cls_sp,
124                              "typeChecksum",
125                              "I");
126     if(fid == 0)
127     {
128       #ifdef TEST_STAGE
129        printf(":!c: fid = NULL \n");
130       #endif
131       break;
132     }
133     (*env)->SetIntField(env,
134                         obj_sp,
135                         fid,
136                         (jint) subs_prop->typeChecksum);
137     /////////////////////////////////////////////////
138     // fieldID - minSeparation
139     cls_ntpT = findClass(env, "org.ocera.orte.types.NtpTime");
140     if(cls_ntpT == 0)
141     {
142       #ifdef TEST_STAGE
143        printf(":!c: cls_ntpT = NULL \n");
144       #endif
145       break;
146     }
147     // call object constructor
148     mid = (*env)->GetMethodID(env, cls_ntpT, "<init>", "(IJ)V");
149     if(mid == 0)
150     {
151       #ifdef TEST_STAGE
152        printf(":!c: mid = NULL \n");
153       #endif
154       break;
155     }
156     // new object
157     obj_ntpT = (*env)->NewObject(env,
158                                  cls_ntpT,
159                                  mid,
160                                  (jint)  subs_prop->minimumSeparation.seconds,
161                                  (jlong) subs_prop->minimumSeparation.fraction);
162     if(obj_ntpT == 0)
163     {
164       #ifdef TEST_STAGE
165        printf(":!c: obj_ntpT = NULL \n");
166       #endif
167       break;
168     }
169     #ifdef TEST_STAGE
170       printf(":c: instance of 'org.ocera.orte.types.NtpTime' created..\n");
171     #endif
172     // set 'SubsProp' NtpTime's field
173     fid = (*env)->GetFieldID(env,
174                              cls_sp,
175                              "minSeparation",
176                              "Lorg/ocera/orte/types/NtpTime;");
177     if(fid == 0)
178     {
179       #ifdef TEST_STAGE
180        printf(":!c: fid = NULL \n");
181       #endif
182       break;
183     }
184     (*env)->SetObjectField(env,
185                            obj_sp,
186                            fid,
187                            obj_ntpT);
188     /////////////////////////////////////////////////
189     // fieldID - deadline
190     // pointers cls_ntpT, obj_ntpT already set
191     // new object
192     obj_ntpT = (*env)->NewObject(env,
193                                  cls_ntpT,
194                                  mid,
195                                  (jint)  subs_prop->deadline.seconds,
196                                  (jlong) subs_prop->deadline.fraction);
197     if(obj_ntpT == 0)
198     {
199       #ifdef TEST_STAGE
200        printf(":!c: obj_ntpT = NULL \n");
201       #endif
202       break;
203     }
204     #ifdef TEST_STAGE
205       printf(":c: instance of 'org.ocera.orte.types.NtpTime' created..\n");
206     #endif
207     // set 'SubsProp' NtpTime's field
208     fid = (*env)->GetFieldID(env,
209                              cls_sp,
210                              "deadline",
211                              "Lorg/ocera/orte/types/NtpTime;");
212     if(fid == 0)
213     {
214       #ifdef TEST_STAGE
215        printf(":!c: fid = NULL \n");
216       #endif
217       break;
218     }
219     (*env)->SetObjectField(env,
220                            obj_sp,
221                            fid,
222                            obj_ntpT);
223     /////////////////////////////////////////////////
224     // fieldID - recvQueueSize
225     fid = (*env)->GetFieldID(env,
226                              cls_sp,
227                              "recvQueueSize",
228                              "J");
229     if(fid == 0)
230     {
231       #ifdef TEST_STAGE
232         printf(":!c: fid = NULL \n");
233       #endif
234       break;
235     }
236     (*env)->SetLongField(env,
237                          obj_sp,
238                          fid,
239                          (jlong) subs_prop->recvQueueSize);
240     /////////////////////////////////////////////////
241     // fieldID - reliabilityRequested
242     fid = (*env)->GetFieldID(env,
243                              cls_sp,
244                              "reliabilityRequested",
245                              "J");
246     if(fid == 0)
247     {
248       #ifdef TEST_STAGE
249         printf(":!c: fid = NULL \n");
250       #endif
251       break;
252     }
253     (*env)->SetLongField(env,
254                          obj_sp,
255                          fid,
256                          (jlong) subs_prop->reliabilityRequested);
257     /////////////////////////////////////////////////
258     // fieldID - mode
259     fid = (*env)->GetFieldID(env,
260                              cls_sp,
261                              "mode",
262                              "I");
263     if(fid == 0)
264     {
265       #ifdef TEST_STAGE
266         printf(":!c: fid = NULL \n");
267       #endif
268       break;
269     }
270     (*env)->SetIntField(env,
271                         obj_sp,
272                         fid,
273                         (jint) subs_prop->mode);
274     /////////////////////////////////////////////////
275     // fieldID - multicastIPAddr
276     fid = (*env)->GetFieldID(env,
277                              cls_sp,
278                              "multicastIPAddr",
279                              "J");
280     if(fid == 0)
281     {
282       #ifdef TEST_STAGE
283         printf(":!c: fid = NULL \n");
284       #endif
285       break;
286     }
287     (*env)->SetLongField(env,
288                          obj_sp,
289                          fid,
290                          (jlong) subs_prop->multicast);
291     // set flag
292     flag_ok = 1;
293
294   } while(0);
295
296   // return created object
297   if(flag_ok == 0)
298   {
299     return NULL;
300   }
301
302   return obj_sp;
303
304 }