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