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