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