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