]> rtime.felk.cvut.cz Git - orte.git/blob - orte/libjorte/JORTEPublicationPropertiesGet.c
Reformat the sources with orte/uncrustify script
[orte.git] / orte / libjorte / JORTEPublicationPropertiesGet.c
1 /* JORTEPublicationPropertiesGet.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 #include "jorte/jorte_protos_api.h"
35 // pregenerated header
36 #include "jorte/org_ocera_orte_Publication.h"
37
38
39 JNIEXPORT jobject JNICALL
40 Java_org_ocera_orte_Publication_jORTEPublicationPropertiesGet
41   (JNIEnv *env, jobject obj, jlong j_appDomain_handle)
42 {
43   // jni types
44   jclass         cls_pp   = NULL; // PublProp class
45   jclass         cls_ntpT = NULL; // NtpTime class
46   jobject        obj_pp   = NULL; // instance of PublProp
47   jobject        obj_ntpT = NULL; // instance of NtpTime
48   jfieldID       fid      = NULL;
49   jmethodID      mid;
50   jboolean       jbool = 0;
51   //
52   int            b = 0;
53   int            flag_ok = 0;
54   ORTEPublProp   pp;
55   ORTEPublProp  *publ_prop = &pp;
56
57   // calling original orte function
58   #ifdef TEST_STAGE
59   printf(":c: ORTEPublicationPropertiesGet() called.. \n");
60   #endif
61
62   // create new PublProps instance and set its fields
63   do {
64     // call ORTE function
65     b = ORTEPublicationPropertiesGet((ORTEPublication *)j_appDomain_handle,
66                                      publ_prop);
67     if (b == ORTE_BAD_HANDLE) {
68       printf(":!c: PublicationPropertiesGet() failed! [bad pub handle] \n");
69       break;
70     }
71     // find class
72     cls_pp = findClass(env, "org.ocera.orte.types.PublProp");
73     if (cls_pp == 0) {
74       #ifdef TEST_STAGE
75       printf(":!c: cls_pp = NULL \n");
76       #endif
77       break;
78     }
79     // call object constructor
80     mid = (*env)->GetMethodID(env, cls_pp, "<init>", "()V");
81     if (mid == 0) {
82       #ifdef TEST_STAGE
83       printf(":!c: mid = NULL \n");
84       #endif
85       break;
86     }
87     // new object
88     obj_pp = (*env)->NewObject(env, cls_pp, mid);
89     if (obj_pp == 0) {
90       #ifdef TEST_STAGE
91       printf(":!c: obj_pp = NULL \n");
92       #endif
93       break;
94     }
95     #ifdef TEST_STAGE
96     printf(":c: instance of 'org.ocera.orte.types.PublProp' created..\n");
97     #endif
98     // ///////////////////////////////////////////////
99     // setting object's fields
100     /////////////////////////////////////////////////
101     // set topic
102     if (!setTopic(env, cls_pp, obj_pp, (const char *)publ_prop->topic)) {
103       #ifdef TEST_STAGE
104       printf(":!c: setTopic() failed! \n");
105       #endif
106       break;
107     }
108     /////////////////////////////////////////////////
109     // set type
110     if (!setType(env, cls_pp, obj_pp, (const char *)publ_prop->typeName)) {
111       #ifdef TEST_STAGE
112       printf(":!c: setType() failed! \n");
113       #endif
114       break;
115     }
116     /////////////////////////////////////////////////
117     // fieldID - typeChecksum
118     fid = (*env)->GetFieldID(env,
119                              cls_pp,
120                              "typeChecksum",
121                              "I");
122     if (fid == 0) {
123       #ifdef TEST_STAGE
124       printf(":!c: fid = NULL \n");
125       #endif
126       break;
127     }
128     (*env)->SetIntField(env,
129                         obj_pp,
130                         fid,
131                         (jint)publ_prop->typeChecksum);
132     /////////////////////////////////////////////////
133     // fieldID - expectsAck
134     fid = (*env)->GetFieldID(env,
135                              cls_pp,
136                              "expectsAck",
137                              "Z");
138     if (fid == 0) {
139       #ifdef TEST_STAGE
140       printf(":!c: fid = NULL \n");
141       #endif
142       break;
143     }
144     if (publ_prop->expectsAck == ORTE_FALSE)
145       jbool = 0;
146     else
147       jbool = 1;
148     (*env)->SetBooleanField(env,
149                             obj_pp,
150                             fid,
151                             jbool);
152     /////////////////////////////////////////////////
153     // fieldID - persistence
154     cls_ntpT = findClass(env, "org.ocera.orte.types.NtpTime");
155     if (cls_ntpT == 0) {
156       #ifdef TEST_STAGE
157       printf(":!c: cls_ntpT = NULL \n");
158       #endif
159       break;
160     }
161     // call object constructor
162     mid = (*env)->GetMethodID(env, cls_ntpT, "<init>", "(IJ)V");
163     if (mid == 0) {
164       #ifdef TEST_STAGE
165       printf(":!c: mid = NULL \n");
166       #endif
167       break;
168     }
169     // new object
170     obj_ntpT = (*env)->NewObject(env,
171                                  cls_ntpT,
172                                  mid,
173                                  (jint)publ_prop->persistence.seconds,
174                                  (jlong)publ_prop->persistence.fraction);
175     if (obj_ntpT == 0) {
176       #ifdef TEST_STAGE
177       printf(":!c: obj_ntpT = NULL \n");
178       #endif
179       break;
180     }
181     #ifdef TEST_STAGE
182     printf(":c: instance of 'org.ocera.orte.types.NtpTime' created..\n");
183     #endif
184     // set 'PublProp' NtpTime's field
185     fid = (*env)->GetFieldID(env,
186                              cls_pp,
187                              "persistence",
188                              "Lorg/ocera/orte/types/NtpTime;");
189     if (fid == 0) {
190       #ifdef TEST_STAGE
191       printf(":!c: fid = NULL \n");
192       #endif
193       break;
194     }
195     (*env)->SetObjectField(env,
196                            obj_pp,
197                            fid,
198                            obj_ntpT);
199     /////////////////////////////////////////////////
200     // fieldID - HBNornalRate
201     // cls_ntpT and obj_ntpT already readed!!
202     // new object
203     obj_ntpT = (*env)->NewObject(env,
204                                  cls_ntpT,
205                                  mid,
206                                  (jint)publ_prop->HBNornalRate.seconds,
207                                  (jlong)publ_prop->HBNornalRate.fraction);
208     if (obj_ntpT == 0) {
209       #ifdef TEST_STAGE
210       printf(":!c: obj_ntpT = NULL \n");
211       #endif
212       break;
213     }
214     #ifdef TEST_STAGE
215     printf(":c: instance of 'org.ocera.orte.types.NtpTime' created..\n");
216     #endif
217     // set 'PublProp' NtpTime's field
218     fid = (*env)->GetFieldID(env,
219                              cls_pp,
220                              "HBNornalRate",
221                              "Lorg/ocera/orte/types/NtpTime;");
222     if (fid == 0) {
223       #ifdef TEST_STAGE
224       printf(":!c: fid = NULL \n");
225       #endif
226       break;
227     }
228     (*env)->SetObjectField(env,
229                            obj_pp,
230                            fid,
231                            obj_ntpT);
232     /////////////////////////////////////////////////
233     // fieldID - HBCQLRate
234     // cls_ntpT and obj_ntpT already readed!!
235     // new object
236     obj_ntpT = (*env)->NewObject(env,
237                                  cls_ntpT,
238                                  mid,
239                                  (jint)publ_prop->HBCQLRate.seconds,
240                                  (jlong)publ_prop->HBCQLRate.fraction);
241     if (obj_ntpT == 0) {
242       #ifdef TEST_STAGE
243       printf(":!c: obj_ntpT = NULL \n");
244       #endif
245       break;
246     }
247     #ifdef TEST_STAGE
248     printf(":c: instance of 'org.ocera.orte.types.NtpTime' created..\n");
249     #endif
250     // set 'PublProp' NtpTime's field
251     fid = (*env)->GetFieldID(env,
252                              cls_pp,
253                              "HBCQLRate",
254                              "Lorg/ocera/orte/types/NtpTime;");
255     if (fid == 0) {
256       #ifdef TEST_STAGE
257       printf(":!c: fid = NULL \n");
258       #endif
259       break;
260     }
261     (*env)->SetObjectField(env,
262                            obj_pp,
263                            fid,
264                            obj_ntpT);
265     /////////////////////////////////////////////////
266     // fieldID - HBCQLRate
267     // cls_ntpT and obj_ntpT already readed!!
268     // new object
269     obj_ntpT = (*env)->NewObject(env,
270                                  cls_ntpT,
271                                  mid,
272                                  (jint)publ_prop->maxBlockTime.seconds,
273                                  (jlong)publ_prop->maxBlockTime.fraction);
274     if (obj_ntpT == 0) {
275       #ifdef TEST_STAGE
276       printf(":!c: obj_ntpT = NULL \n");
277       #endif
278       break;
279     }
280     #ifdef TEST_STAGE
281     printf(":c: instance of 'org.ocera.orte.types.NtpTime' created..\n");
282     #endif
283     // set 'PublProp' NtpTime's field
284     fid = (*env)->GetFieldID(env,
285                              cls_pp,
286                              "maxBlockTime",
287                              "Lorg/ocera/orte/types/NtpTime;");
288     if (fid == 0) {
289       #ifdef TEST_STAGE
290       printf(":!c: fid = NULL \n");
291       #endif
292       break;
293     }
294     (*env)->SetObjectField(env,
295                            obj_pp,
296                            fid,
297                            obj_ntpT);
298     /////////////////////////////////////////////////
299     // fieldID - reliabilityOffered
300     fid = (*env)->GetFieldID(env,
301                              cls_pp,
302                              "reliabilityOffered",
303                              "J");
304     if (fid == 0) {
305       #ifdef TEST_STAGE
306       printf(":!c: fid = NULL \n");
307       #endif
308       break;
309     }
310     (*env)->SetLongField(env,
311                          obj_pp,
312                          fid,
313                          (jlong)publ_prop->reliabilityOffered);
314     /////////////////////////////////////////////////
315     // fieldID - sendQueueSize
316     fid = (*env)->GetFieldID(env,
317                              cls_pp,
318                              "sendQueueSize",
319                              "J");
320     if (fid == 0) {
321       #ifdef TEST_STAGE
322       printf(":!c: fid = NULL \n");
323       #endif
324       break;
325     }
326     (*env)->SetLongField(env,
327                          obj_pp,
328                          fid,
329                          (jlong)publ_prop->sendQueueSize);
330     /////////////////////////////////////////////////
331     // fieldID - strength
332     fid = (*env)->GetFieldID(env,
333                              cls_pp,
334                              "strength",
335                              "I");
336     if (fid == 0) {
337       #ifdef TEST_STAGE
338       printf(":!c: fid = NULL \n");
339       #endif
340       break;
341     }
342     (*env)->SetIntField(env,
343                         obj_pp,
344                         fid,
345                         (jint)publ_prop->strength);
346     /////////////////////////////////////////////////
347     // fieldID - criticalQueueLevel
348     fid = (*env)->GetFieldID(env,
349                              cls_pp,
350                              "criticalQueueLevel",
351                              "J");
352     if (fid == 0) {
353       #ifdef TEST_STAGE
354       printf(":!c: fid = NULL \n");
355       #endif
356       break;
357     }
358     (*env)->SetLongField(env,
359                          obj_pp,
360                          fid,
361                          (jlong)publ_prop->criticalQueueLevel);
362     /////////////////////////////////////////////////
363     // fieldID - HBMaxRetries
364     fid = (*env)->GetFieldID(env,
365                              cls_pp,
366                              "HBMaxRetries",
367                              "J");
368     if (fid == 0) {
369       #ifdef TEST_STAGE
370       printf(":!c: fid = NULL \n");
371       #endif
372       break;
373     }
374     (*env)->SetLongField(env,
375                          obj_pp,
376                          fid,
377                          (jlong)publ_prop->HBMaxRetries);
378     // set flag
379     flag_ok = 1;
380   } while (0);
381
382   if (flag_ok == 0) {
383     return NULL;
384   }
385
386   return obj_pp;
387
388 }