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