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