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