]> rtime.felk.cvut.cz Git - orte.git/blob - orte/libjorte/JORTEPublicationPropertiesSet.c
Reformat the sources with orte/uncrustify script
[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     // 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       #ifdef TEST_STAGE
69       printf(":!c: cls_pp = NULL \n");
70       #endif
71       break;
72     }
73     // ///////////////////////////////////////////////
74     // setting object's fields
75     /////////////////////////////////////////////////
76     // set topic
77     fid = (*env)->GetFieldID(env,
78                              cls_pp,
79                              "topic",
80                              "Ljava/lang/String;");
81     if (fid == 0) {
82       #ifdef TEST_STAGE
83       printf(":!c: fid = NULL \n");
84       #endif
85       break;
86     }
87     obj_str = (*env)->GetObjectField(env, obj_pp, fid);
88     if (obj_str == 0) {
89       #ifdef TEST_STAGE
90       printf(":!c: obj_str = NULL \n");
91       #endif
92       break;
93     }
94     str = (*env)->GetStringUTFChars(env, obj_str, 0);
95     // set structure's field
96     strncpy((char *)publ_prop->topic, (const char *)str, strlen(str) + 1);
97     #ifdef TEST_STAGE
98     printf(":c: topic = %s, publ_prop->topic = %s \n",
99            str, publ_prop->topic);
100     #endif
101     // free the memory
102     (*env)->ReleaseStringUTFChars(env, obj_str, str);
103     /////////////////////////////////////////////////
104     // set typeName
105     fid = (*env)->GetFieldID(env,
106                              cls_pp,
107                              "typeName",
108                              "Ljava/lang/String;");
109     if (fid == 0) {
110       #ifdef TEST_STAGE
111       printf(":!c: fid = NULL \n");
112       #endif
113       break;
114     }
115     obj_str = (*env)->GetObjectField(env, obj_pp, fid);
116     if (obj_str == 0) {
117       #ifdef TEST_STAGE
118       printf(":!c: obj_str = NULL \n");
119       #endif
120       break;
121     }
122     str = (*env)->GetStringUTFChars(env, obj_str, 0);
123     // set structure's field
124     strncpy((char *)publ_prop->typeName, (const char *)str, strlen(str) + 1);
125     #ifdef TEST_STAGE
126     printf(":c: typeName = %s, publ_prop->typeName = %s \n",
127            str, publ_prop->typeName);
128     #endif
129     // free the memory
130     (*env)->ReleaseStringUTFChars(env, obj_str, str);
131     /////////////////////////////////////////////////
132     // set typeChecksum
133     fid = (*env)->GetFieldID(env, cls_pp, "typeChecksum", "I");
134     if (fid == 0) {
135       #ifdef TEST_STAGE
136       printf(":!c: fid = NULL \n");
137       #endif
138       break;
139     }
140     publ_prop->typeChecksum = (TypeChecksum)(*env)->GetIntField(env, obj_pp, fid);
141     #ifdef TEST_STAGE
142     printf(":c: check: publ_prop->typeChecksum = %" PRId32 "\n",
143            publ_prop->typeChecksum);
144     #endif
145     /////////////////////////////////////////////////
146     // set expectsAck
147     fid = (*env)->GetFieldID(env, cls_pp, "expectsAck", "Z");
148     if (fid == 0) {
149       #ifdef TEST_STAGE
150       printf(":!c: fid = NULL \n");
151       #endif
152       break;
153     }
154     jbool = (*env)->GetBooleanField(env, obj_pp, fid);
155     if (jbool == 0)
156       publ_prop->expectsAck = ORTE_FALSE;
157     else
158       publ_prop->expectsAck = ORTE_TRUE;
159     #ifdef TEST_STAGE
160     printf(":c: check: publ_prop->expectsAck = %" PRId8 "\n", publ_prop->expectsAck);
161     #endif
162     /////////////////////////////////////////////////
163     // set persistence
164     fid = (*env)->GetFieldID(env,
165                              cls_pp,
166                              "persistence",
167                              "Lorg/ocera/orte/types/NtpTime;");
168     if (fid == 0) {
169       #ifdef TEST_STAGE
170       printf(":!c: fid = NULL \n");
171       #endif
172       break;
173     }
174     obj_ntpT = (*env)->GetObjectField(env, obj_pp, fid);
175     if (obj_ntpT == 0) {
176       #ifdef TEST_STAGE
177       printf(":!c: obj_ntpT = NULL \n");
178       #endif
179       break;
180     }
181     publ_prop->persistence = getNtpTime(env, obj_ntpT);
182     #ifdef TEST_STAGE
183     printf(":c: check: publ_prop->persistence: sec = %" PRId32 ", fract = %" PRIu32 "  \n",
184            publ_prop->persistence.seconds, publ_prop->persistence.fraction);
185     #endif
186     /////////////////////////////////////////////////
187     // set reliabilityOffered
188     fid = (*env)->GetFieldID(env,
189                              cls_pp,
190                              "reliabilityOffered",
191                              "J");
192     if (fid == 0) {
193       #ifdef TEST_STAGE
194       printf(":!c: fid = NULL \n");
195       #endif
196       break;
197     }
198     publ_prop->reliabilityOffered = (uint32_t)(*env)->GetLongField(env, obj_pp, fid);
199     #ifdef TEST_STAGE
200     printf(":c: check: publ_prop->reliabilityOffered = %" PRIu32 " \n",
201            publ_prop->reliabilityOffered);
202     #endif
203     /////////////////////////////////////////////////
204     // set sendQueueSize
205     fid = (*env)->GetFieldID(env,
206                              cls_pp,
207                              "sendQueueSize",
208                              "J");
209     if (fid == 0) {
210       #ifdef TEST_STAGE
211       printf(":!c: fid = NULL \n");
212       #endif
213       break;
214     }
215     publ_prop->sendQueueSize = (uint32_t)(*env)->GetLongField(env, obj_pp, fid);
216     #ifdef TEST_STAGE
217     printf(":c: check: publ_prop->sendQueueSize = %" PRIu32 " \n",
218            publ_prop->sendQueueSize);
219     #endif
220     /////////////////////////////////////////////////
221     // set strength
222     fid = (*env)->GetFieldID(env,
223                              cls_pp,
224                              "strength",
225                              "I");
226     if (fid == 0) {
227       #ifdef TEST_STAGE
228       printf(":!c: fid = NULL \n");
229       #endif
230       break;
231     }
232     publ_prop->strength = (int32_t)(*env)->GetIntField(env, obj_pp, fid);
233     #ifdef TEST_STAGE
234     printf(":c: check: publ_prop->strength = %" PRId32 " \n",
235            publ_prop->strength);
236     #endif
237     /////////////////////////////////////////////////
238     // set criticalQueueLevel
239     fid = (*env)->GetFieldID(env,
240                              cls_pp,
241                              "criticalQueueLevel",
242                              "J");
243     if (fid == 0) {
244       #ifdef TEST_STAGE
245       printf(":!c: fid = NULL \n");
246       #endif
247       break;
248     }
249     publ_prop->criticalQueueLevel = (uint32_t)(*env)->GetLongField(env, obj_pp, fid);
250     #ifdef TEST_STAGE
251     printf(":c: check: publ_prop->criticalQueueLevel = %" PRIu32 " \n",
252            publ_prop->criticalQueueLevel);
253     #endif
254     /////////////////////////////////////////////////
255     // set HBNornalRate
256     fid = (*env)->GetFieldID(env,
257                              cls_pp,
258                              "HBNornalRate",
259                              "Lorg/ocera/orte/types/NtpTime;");
260     if (fid == 0) {
261       #ifdef TEST_STAGE
262       printf(":!c: fid = NULL \n");
263       #endif
264       break;
265     }
266     obj_ntpT = (*env)->GetObjectField(env, obj_pp, fid);
267     publ_prop->HBNornalRate = getNtpTime(env, obj_ntpT);
268     #ifdef TEST_STAGE
269     printf(":c: check: publ_prop->HBNornalRate: sec = %" PRId32 ", fract = %" PRIu32 "  \n",
270            publ_prop->HBNornalRate.seconds, publ_prop->HBNornalRate.fraction);
271     #endif
272     /////////////////////////////////////////////////
273     // set HBCQLRate
274     fid = (*env)->GetFieldID(env,
275                              cls_pp,
276                              "HBCQLRate",
277                              "Lorg/ocera/orte/types/NtpTime;");
278     if (fid == 0) {
279       #ifdef TEST_STAGE
280       printf(":!c: fid = NULL \n");
281       #endif
282       break;
283     }
284     obj_ntpT = (*env)->GetObjectField(env, obj_pp, fid);
285     if (obj_ntpT == 0) {
286       #ifdef TEST_STAGE
287       printf(":!c: obj_ntpT = NULL \n");
288       #endif
289       break;
290     }
291     publ_prop->HBCQLRate = getNtpTime(env, obj_ntpT);
292     #ifdef TEST_STAGE
293     printf(":c: check: publ_prop->HBCQLRate: sec = %" PRId32 ", fract = %" PRIu32 "  \n",
294            publ_prop->HBCQLRate.seconds, publ_prop->HBCQLRate.fraction);
295     #endif
296     /////////////////////////////////////////////////
297     // set HBMaxRetries
298     fid = (*env)->GetFieldID(env,
299                              cls_pp,
300                              "HBMaxRetries",
301                              "J");
302     if (fid == 0) {
303       #ifdef TEST_STAGE
304       printf(":!c: fid = NULL \n");
305       #endif
306       break;
307     }
308     publ_prop->HBMaxRetries = (unsigned int)(*env)->GetLongField(env, obj_pp, fid);
309     #ifdef TEST_STAGE
310     printf(":c: check: publ_prop->HBMaxRetries = %u \n",
311            publ_prop->HBMaxRetries);
312     #endif
313     /////////////////////////////////////////////////
314     // set maxBlockTime
315     fid = (*env)->GetFieldID(env,
316                              cls_pp,
317                              "maxBlockTime",
318                              "Lorg/ocera/orte/types/NtpTime;");
319     if (fid == 0) {
320       #ifdef TEST_STAGE
321       printf(":!c: fid = NULL \n");
322       #endif
323       break;
324     }
325     obj_ntpT = (*env)->GetObjectField(env, obj_pp, fid);
326     if (obj_ntpT == 0) {
327       #ifdef TEST_STAGE
328       printf(":!c: obj_ntpT = NULL \n");
329       #endif
330       break;
331     }
332     publ_prop->maxBlockTime = getNtpTime(env, obj_ntpT);
333     #ifdef TEST_STAGE
334     printf(":c: check: publ_prop->maxBlockTime: sec = %" PRId32 ", fract = %" PRIu32 "  \n",
335            publ_prop->maxBlockTime.seconds, publ_prop->maxBlockTime.fraction);
336     #endif
337     /////////////////////////////////////////////////
338     // calling original native method
339     b = ORTEPublicationPropertiesSet((ORTEPublication *)j_appDomain_handle,
340                                      publ_prop);
341     if (b == ORTE_BAD_HANDLE) {
342       printf(":c!: set pub properties failed! [bad pub handle] \n");
343       break;
344     }
345     // set flag
346     flag_ok = 1;
347   } while (0);
348
349   if (flag_ok == 0) {
350     return 0;
351   }
352
353   return 1;
354
355 }