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