]> rtime.felk.cvut.cz Git - orte.git/blob - orte/libjorte/JORTESubscriptionPropertiesSet.c
Reformat the sources with orte/uncrustify script
[orte.git] / orte / libjorte / JORTESubscriptionPropertiesSet.c
1 /* JORTESubscriptionPropertiesSet.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_Subscription.h"
39
40
41 JNIEXPORT jboolean JNICALL
42 Java_org_ocera_orte_Subscription_jORTESubscriptionPropertiesSet
43   (JNIEnv *env, jobject obj, jlong j_appDomain_handle, jobject obj_sp)
44 {
45   // jni types
46   jclass         cls_sp = NULL;
47   jfieldID       fid = NULL;
48   jobject        j_minSeparation = NULL;
49   jobject        j_deadline = NULL;
50   jobject        obj_str = NULL;
51   //
52   int            b = 0;
53   int            flag_ok = 0;
54   const char    *str = NULL;
55   ORTESubsProp   sp;
56   ORTESubsProp  *subs_prop = &sp;
57
58   #ifdef TEST_STAGE
59   printf(":c: jORTESubscriptionPropertiesSet() called.. \n");
60   #endif
61
62   do {
63     // get SubsProp instance's class
64     cls_sp = (*env)->GetObjectClass(env, obj_sp);
65     // second way how to get 'SubProp' instance's class
66     //cls_sp = (*env)->FindClass(env,"org/ocera/orte/types/SubsProp");
67     if (cls_sp == 0) {
68       printf(":!c: class 'org.ocera.orte.types.SubsProp' not found! \n");
69       break;
70     }
71     // ///////////////////////////////////////////////
72     // setting object's fields
73     /////////////////////////////////////////////////
74     // set topic
75     fid = (*env)->GetFieldID(env,
76                              cls_sp,
77                              "topic",
78                              "Ljava/lang/String;");
79     if (fid == 0) {
80       #ifdef TEST_STAGE
81       printf(":!c: fid = NULL \n");
82       #endif
83       break;
84     }
85     obj_str = (*env)->GetObjectField(env, obj_sp, fid);
86     if (obj_str == 0) {
87       #ifdef TEST_STAGE
88       printf(":!c: obj_str = NULL \n");
89       #endif
90       break;
91     }
92     str = (*env)->GetStringUTFChars(env, obj_str, 0);
93     // Set the structure field.
94     strncpy((char *)subs_prop->topic, (const char *)str, strlen(str) + 1);
95     #ifdef TEST_STAGE
96     printf(":c: topic = %s, subs_prop->topic = %s \n",
97            str, subs_prop->topic);
98     #endif
99     // free the memory
100     (*env)->ReleaseStringUTFChars(env, obj_str, str);
101     /////////////////////////////////////////////////
102     // set topic - typeName
103     fid = (*env)->GetFieldID(env,
104                              cls_sp,
105                              "typeName",
106                              "Ljava/lang/String;");
107     if (fid == 0) {
108       #ifdef TEST_STAGE
109       printf(":!c: fid = NULL \n");
110       #endif
111       break;
112     }
113     obj_str = (*env)->GetObjectField(env, obj_sp, fid);
114     if (obj_str == 0) {
115       #ifdef TEST_STAGE
116       printf(":!c: obj_str = NULL \n");
117       #endif
118       break;
119     }
120     str = (*env)->GetStringUTFChars(env, obj_str, 0);
121     // Set the structure field.
122     strncpy((char *)subs_prop->typeName, (const char *)str, strlen(str) + 1);
123     #ifdef TEST_STAGE
124     printf(":c: typeName = %s, subs_prop->typeName = %s \n",
125            str, subs_prop->typeName);
126     #endif
127     // free the memory
128     (*env)->ReleaseStringUTFChars(env, obj_str, str);
129     /////////////////////////////////////////////////
130     // set topic - typeChecksum
131     fid = (*env)->GetFieldID(env, cls_sp, "typeChecksum", "I");
132     if (fid == 0) {
133       #ifdef TEST_STAGE
134       printf(":!c: fid = NULL \n");
135       #endif
136       break;
137     }
138     subs_prop->typeChecksum = (TypeChecksum)(*env)->GetIntField(env, obj_sp, fid);
139     #ifdef TEST_STAGE
140     printf(":c: check: subs_prop->typeChecksum = %" PRId32 "\n",
141            subs_prop->typeChecksum);
142     #endif
143     /////////////////////////////////////////////////
144     // set topic - minimumSeparation
145     fid = (*env)->GetFieldID(env,
146                              cls_sp,
147                              "minSeparation",
148                              "Lorg/ocera/orte/types/NtpTime;");
149     if (fid == 0) {
150       #ifdef TEST_STAGE
151       printf(":!c: fid = NULL \n");
152       #endif
153       break;
154     }
155     j_minSeparation = (*env)->GetObjectField(env, obj_sp, fid);
156     subs_prop->minimumSeparation = getNtpTime(env, j_minSeparation);
157     #ifdef TEST_STAGE
158     printf(":c: check: subs_prop->minimumSeparation: sec = %" PRId32 ", fract = %" PRIu32 " \n",
159            subs_prop->minimumSeparation.seconds,
160            subs_prop->minimumSeparation.fraction);
161     #endif
162     /////////////////////////////////////////////////
163     // set topic - recvQueueSize
164     fid = (*env)->GetFieldID(env, cls_sp, "recvQueueSize", "J");
165     if (fid == 0) {
166       #ifdef TEST_STAGE
167       printf(":!c: fid = NULL \n");
168       #endif
169       break;
170     }
171     subs_prop->recvQueueSize = (uint32_t)(*env)->GetLongField(env, obj_sp, fid);
172     #ifdef TEST_STAGE
173     printf(":c: check: subs_prop->recvQueueSize = %" PRIu32 " \n",
174            subs_prop->recvQueueSize);
175     #endif
176     /////////////////////////////////////////////////
177     // set topic - reliabilityRequested
178     fid = (*env)->GetFieldID(env, cls_sp, "reliabilityRequested", "J");
179     if (fid == 0) {
180       #ifdef TEST_STAGE
181       printf(":!c: fid = NULL \n");
182       #endif
183       break;
184     }
185     subs_prop->reliabilityRequested = (uint32_t)(*env)->GetLongField(env, obj_sp, fid);
186     #ifdef TEST_STAGE
187     printf(":c: check: subs_prop->reliabilityRequested = %" PRIu32 " \n",
188            subs_prop->reliabilityRequested);
189     #endif
190     /////////////////////////////////////////////////
191     // set topic - deadline
192     fid = (*env)->GetFieldID(env,
193                              cls_sp,
194                              "deadline",
195                              "Lorg/ocera/orte/types/NtpTime;");
196     if (fid == 0) {
197       #ifdef TEST_STAGE
198       printf(":!c: fid = NULL \n");
199       #endif
200       break;
201     }
202     j_deadline = (*env)->GetObjectField(env, obj_sp, fid);
203     subs_prop->deadline = getNtpTime(env, j_deadline);
204     #ifdef TEST_STAGE
205     printf(":c: check: subs_prop->deadline: sec = %" PRId32 ", fract = %" PRIu32 "  \n",
206            subs_prop->deadline.seconds, subs_prop->deadline.fraction);
207     #endif
208     /////////////////////////////////////////////////
209     // set topic - mode
210     fid = (*env)->GetFieldID(env, cls_sp, "mode", "I");
211     if (fid == 0) {
212       #ifdef TEST_STAGE
213       printf(":!c: fid = NULL \n");
214       #endif
215       break;
216     }
217     subs_prop->mode = (uint32_t)(*env)->GetIntField(env, obj_sp, fid);
218     #ifdef TEST_STAGE
219     printf(":c: check: subs_prop->mode = %" PRIu32 " \n",
220            subs_prop->mode);
221     #endif
222 /*
223     /////////////////////////////////////////////////
224     // set topic - multicastIPAddr READ-ONLY!!
225     fid = (*env)->GetFieldID(env,cls_sp,"multicastIPAddr","J");
226     if(fid == 0)
227     {
228       #ifdef TEST_STAGE
229         printf(":!c: fid = NULL \n");
230       #endif
231       break;
232     }
233     subs_prop->multicast = (IPAddress) (*env)->GetLongField(env, obj_sp, fid);
234     #ifdef TEST_STAGE
235       printf(":c: check: subs_prop->multicast = %d \n",
236              subs_prop->multicast);
237     #endif
238 */
239     // calling original native method
240     b = ORTESubscriptionPropertiesSet((ORTESubscription *)j_appDomain_handle, subs_prop);
241     if (b == ORTE_BAD_HANDLE) {
242       printf(":c!: cannot set new Subscription Properties! [bad sub handle] \n");
243       break;
244     }
245     // set flag
246     flag_ok = 1;
247   } while (0);
248
249   if (flag_ok == 0) {
250     return 0;
251   }
252
253   return 1;
254 }