]> rtime.felk.cvut.cz Git - orte.git/blob - orte/libjorte/setRecvInfo.c
Reformat the sources with orte/uncrustify script
[orte.git] / orte / libjorte / setRecvInfo.c
1 /* setRecvInfo.c  */
2
3 #include <jni.h>
4 #include <inttypes.h>
5 #include "orte.h"
6 #include "jorte/4all.h"
7 #include "jorte/jorte_protos_api.h"
8
9 int
10 setRecvInfo(JNIEnv *env, const ORTERecvInfo *rinfo, jobject obj)
11 {
12   jclass    cls;
13   jclass    cls_tmp;
14 //  jobject   obj;
15   jobject   obj_tmp;
16   jfieldID  fid;
17   jmethodID mid;
18   //
19   int flag_ok = 0;
20
21   #ifdef TEST_STAGE
22   int32_t sec;
23   uint32_t us;
24   #endif
25
26   do {
27     // find cls
28     cls = findClass(env, "org.ocera.orte.types.RecvInfo");
29     if (cls == 0) {
30       #ifdef TEST_STAGE
31       printf(":!c: cls = NULL \n");
32       #endif
33       break;
34     }
35     // field ID - status
36     fid = (*env)->GetFieldID(env, cls, "status", "B");
37     if (fid == 0) {
38       #ifdef TEST_STAGE
39       printf(":!c: fid = NULL \n");
40       #endif
41       break;
42     }
43     #ifdef TEST_STAGE
44     printf(":c: rinfo.status = %d \n",
45            rinfo->status);
46     #endif
47     (*env)->SetByteField(env,
48                          obj,
49                          fid,
50                          (jbyte)rinfo->status);
51 /////////////////////////////////////////////////
52     // set topic
53     if (!setTopic(env, cls, obj, rinfo->topic)) {
54       #ifdef TEST_STAGE
55       printf(":!c: seTopic() failed! \n");
56       #endif
57       break;
58     }
59     // set type
60     if (!setType(env, cls, obj, rinfo->type)) {
61       #ifdef TEST_STAGE
62       printf(":!c: seType() failed! \n");
63       #endif
64       break;
65     }
66 /////////////////////////////////////////////////
67     // find cls - GUID_RTPS
68     cls_tmp = findClass(env, "org.ocera.orte.types.GUID_RTPS");
69     if (cls_tmp == 0) {
70       #ifdef TEST_STAGE
71       printf(":!c: cls_tmp = NULL \n");
72       #endif
73       break;
74     }
75     // call object constructor
76     mid = (*env)->GetMethodID(env,
77                               cls_tmp,
78                               "<init>",
79                               "(JJJ)V");
80     if (mid == 0) {
81       #ifdef TEST_STAGE
82       printf(":!c: constructor failed! \n");
83       #endif
84       break;
85     }
86     // create new object
87     obj_tmp = (*env)->NewObject(env,
88                                 cls_tmp,
89                                 mid,
90                                 (jlong)rinfo->senderGUID.hid,
91                                 (jlong)rinfo->senderGUID.aid,
92                                 (jlong)rinfo->senderGUID.oid);
93     if (obj_tmp == 0) {
94       #ifdef TEST_STAGE
95       printf(":!c: obj = NULL \n");
96       #endif
97       break;
98     }
99     // set AppInfo's field
100     fid = (*env)->GetFieldID(env,
101                              cls,
102                              "senderGUID",
103                              "Lorg/ocera/orte/types/GUID_RTPS;");
104     if (fid == 0) {
105       #ifdef TEST_STAGE
106       printf(":!c: fid = NULL \n");
107       #endif
108       break;
109     }
110     #ifdef TEST_STAGE
111     printf(":c: rinfo.senderGUID: hid = %#" PRIx32 ", aid = %#" PRIx32 ", oid = %#" PRIx32 " \n",
112            rinfo->senderGUID.hid, rinfo->senderGUID.aid, rinfo->senderGUID.oid);
113     #endif
114     (*env)->SetObjectField(env,
115                            obj,
116                            fid,
117                            obj_tmp);
118 /////////////////////////////////////////////////
119     // find cls - NtpTime
120     cls_tmp = findClass(env, "org.ocera.orte.types.NtpTime");
121     if (cls_tmp == 0) {
122       #ifdef TEST_STAGE
123       printf(":!c: cls_tmp = NULL \n");
124       #endif
125       break;
126     }
127     // call object constructor
128     mid = (*env)->GetMethodID(env,
129                               cls_tmp,
130                               "<init>",
131                               "(IJ)V");
132     if (mid == 0) {
133       #ifdef TEST_STAGE
134       printf(":!c: constructor failed! \n");
135       #endif
136       break;
137     }
138     // create new object
139     obj_tmp = (*env)->NewObject(env,
140                                 cls_tmp,
141                                 mid,
142                                 (jint)rinfo->localTimeReceived.seconds,
143                                 (jlong)rinfo->localTimeReceived.fraction);
144     if (obj_tmp == 0) {
145       #ifdef TEST_STAGE
146       printf(":!c: obj = NULL \n");
147       #endif
148       break;
149     }
150     // set AppInfo's field
151     fid = (*env)->GetFieldID(env,
152                              cls,
153                              "localTimeRecv",
154                              "Lorg/ocera/orte/types/NtpTime;");
155     if (fid == 0) {
156       #ifdef TEST_STAGE
157       printf(":!c: fid = NULL \n");
158       #endif
159       break;
160     }
161     #ifdef TEST_STAGE
162     NtpTimeDisAssembToUs(sec, us, rinfo->localTimeReceived);
163     printf(":c: rinfo.NtpTime: %" PRId32 ".%" PRIu32 " (sec = %" PRId32 " fract = %" PRIu32 ") \n",
164            sec, us,
165            rinfo->localTimeReceived.seconds, rinfo->localTimeReceived.fraction);
166     #endif
167     (*env)->SetObjectField(env,
168                            obj,
169                            fid,
170                            obj_tmp);
171 /////////////////////////////////////////////////
172     // find cls - NtpTime
173 /*
174     cls_tmp = (*env)->FindClass(env, "org/ocera/orte/types/NtpTime");
175     if(cls_tmp == 0)
176     {
177       #ifdef TEST_STAGE
178         printf(":!c: cls_tmp = NULL \n");
179       #endif
180       break;
181     }
182     // call object constructor
183     mid = (*env)->GetMethodID(env,
184                               cls_tmp,
185                               "<init>",
186                               "(IJ)V");
187     if(mid == 0)
188     {
189       #ifdef TEST_STAGE
190         printf(":!c: constructor failed! \n");
191       #endif
192       break;
193     }
194 */
195     // create new object
196     obj_tmp = (*env)->NewObject(env,
197                                 cls_tmp,
198                                 mid,
199                                 (jint)rinfo->remoteTimePublished.seconds,
200                                 (jlong)rinfo->remoteTimePublished.fraction);
201     if (obj_tmp == 0) {
202       #ifdef TEST_STAGE
203       printf(":!c: obj = NULL \n");
204       #endif
205       break;
206     }
207     // set AppInfo's field
208     fid = (*env)->GetFieldID(env,
209                              cls,
210                              "remoteTimePub",
211                              "Lorg/ocera/orte/types/NtpTime;");
212     if (fid == 0) {
213       #ifdef TEST_STAGE
214       printf(":!c: fid = NULL \n");
215       #endif
216       break;
217     }
218     #ifdef TEST_STAGE
219     NtpTimeDisAssembToUs(sec, us, rinfo->remoteTimePublished);
220     printf(":c: rinfo.remoteTimePub: %" PRId32 ".%" PRIu32 " (sec = %" PRId32 " fract = %" PRIu32 ") \n",
221            sec, us,
222            rinfo->remoteTimePublished.seconds, rinfo->remoteTimePublished.fraction);
223     #endif
224     (*env)->SetObjectField(env,
225                            obj,
226                            fid,
227                            obj_tmp);
228 /////////////////////////////////////////////////
229     // find cls - SequenceNumber
230     cls_tmp = findClass(env, "org.ocera.orte.types.SequenceNumber");
231     if (cls_tmp == 0) {
232       #ifdef TEST_STAGE
233       printf(":!c: cls_tmp = NULL \n");
234       #endif
235       break;
236     }
237     // call object constructor
238     mid = (*env)->GetMethodID(env,
239                               cls_tmp,
240                               "<init>",
241                               "(IJ)V");
242     if (mid == 0) {
243       #ifdef TEST_STAGE
244       printf(":!c: constructor failed! # \n");
245       #endif
246       break;
247     }
248     // create new object
249     obj_tmp = (*env)->NewObject(env,
250                                 cls_tmp,
251                                 mid,
252                                 (jint)rinfo->sn.high,
253                                 (jlong)rinfo->sn.low);
254     if (obj_tmp == 0) {
255       #ifdef TEST_STAGE
256       printf(":!c: obj = NULL \n");
257       #endif
258       break;
259     }
260     // set AppInfo's field
261     fid = (*env)->GetFieldID(env,
262                              cls,
263                              "sn",
264                              "Lorg/ocera/orte/types/SequenceNumber;");
265     if (fid == 0) {
266       #ifdef TEST_STAGE
267       printf(":!c: fid = NULL \n");
268       #endif
269       break;
270     }
271     #ifdef TEST_STAGE
272     printf(":c: rinfo.sn: %" PRId64 " (high = %" PRId32 " low = %" PRId32 ") \n",
273            (((int64_t)rinfo->sn.high << 32) + rinfo->sn.low), rinfo->sn.high, rinfo->sn.low);
274     #endif
275     (*env)->SetObjectField(env,
276                            obj,
277                            fid,
278                            obj_tmp);
279 /////////////////////////////////////////////////
280
281     flag_ok = 1;
282   } while (0);
283
284   if (!flag_ok) {
285     //detach...()
286     return 0;
287   }
288
289   return 1;
290 }