]> rtime.felk.cvut.cz Git - orte.git/blob - orte/libjorte/createAppInfo.c
Merge branch 'android' of ssh://git@rtime.felk.cvut.cz/orte into robot
[orte.git] / orte / libjorte / createAppInfo.c
1 /* createAppInfo.c  */
2
3 #include <jni.h>
4 #include "orte.h"
5 #include "jorte/4all.h"
6 #include "jorte/jorte_protos_api.h"
7 #include <inttypes.h>
8
9 jobject createAppInfo(JNIEnv *env, const ORTEAppInfo *ainfo)
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
20   do
21   {
22     // find cls
23     cls = findClass(env, "org.ocera.orte.types.AppInfo");
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     // field ID - hostID
50     fid = (*env)->GetFieldID(env,cls,"hostId","J");
51     if(fid == 0)
52     {
53       #ifdef TEST_STAGE
54         printf(":!c: fid = NULL \n");
55       #endif
56       break;
57     }
58     #ifdef TEST_STAGE
59        printf(":c: ainfo.hostId = %d \n",ainfo->hostId);
60     #endif
61     (*env)->SetLongField(env,
62                          obj,
63                          fid,
64                          (jlong) ainfo->hostId);
65
66     // field ID - appID
67     fid = (*env)->GetFieldID(env,cls,"appId","J");
68     if(fid == 0)
69     {
70       #ifdef TEST_STAGE
71         printf(":!c: fid = NULL \n");
72       #endif
73       break;
74     }
75     #ifdef TEST_STAGE
76        printf(":c: ainfo.appId = %d \n",ainfo->appId);
77     #endif
78     (*env)->SetLongField(env,
79                          obj,
80                          fid,
81                          (jlong) ainfo->appId);
82     // field ID - unicastIPAddressTemp
83     fid = (*env)->GetFieldID(env,cls,"unicastIPAddressTemp","J");
84     if(fid == 0)
85     {
86       #ifdef TEST_STAGE
87         printf(":!c: fid uniIPAddrTemp = NULL \n");
88       #endif
89       break;
90     }
91     #ifdef TEST_STAGE
92        printf(":c: ainfo.unicastIPAddressList = %"PRIoPTR"\n",(intptr_t)ainfo->unicastIPAddressList);
93     #endif
94     (*env)->SetLongField(env,
95                          obj,
96                          fid,
97                          (jlong) *ainfo->unicastIPAddressList);
98     // field ID - unicastIPcount
99     fid = (*env)->GetFieldID(env,cls,"unicastIPcount","B");
100     if(fid == 0)
101     {
102       #ifdef TEST_STAGE
103         printf(":!c: fid = NULL \n");
104       #endif
105       break;
106     }
107     #ifdef TEST_STAGE
108        printf(":c: ainfo.unicastIPcount = %d \n",
109               ainfo->unicastIPAddressCount);
110     #endif
111     (*env)->SetByteField(env,
112                          obj,
113                          fid,
114                          (jbyte) ainfo->unicastIPAddressCount);
115     // field ID - multicastIPAddressTemp
116     fid = (*env)->GetFieldID(env,cls,"mettaTrafficMulticastIPAddressTemp","J");
117     if(fid == 0)
118     {
119       #ifdef TEST_STAGE
120         printf(":!c: fid multiIPAddrTemp = NULL \n");
121       #endif
122       break;
123     }
124     #ifdef TEST_STAGE
125        printf(":c: ainfo.multicastIPAddressList = %"PRIoPTR"\n",
126               (intptr_t)ainfo->metatrafficMulticastIPAddressList);
127     #endif
128     (*env)->SetLongField(env,
129                          obj,
130                          fid,
131                          (jlong) *ainfo->metatrafficMulticastIPAddressList);
132     // field ID - multicastIPcount
133     fid = (*env)->GetFieldID(env,cls,"multicastIPcount","B");
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: ainfo.metatrafficMulticastIPAddressCount = %d \n",
143               ainfo->metatrafficMulticastIPAddressCount);
144     #endif
145     (*env)->SetByteField(env,
146                          obj,
147                          fid,
148                          (jbyte) ainfo->metatrafficMulticastIPAddressCount);
149
150     // field ID - mettatraficUnicastPort
151     fid = (*env)->GetFieldID(env,cls,"metatrafficUniPort","J");
152     if(fid == 0)
153     {
154       #ifdef TEST_STAGE
155         printf(":!c: fid = NULL \n");
156       #endif
157       break;
158     }
159     #ifdef TEST_STAGE
160        printf(":c: ainfo.metatrafficUnicastPort = %d \n",
161               ainfo->metatrafficUnicastPort);
162     #endif
163     (*env)->SetLongField(env,
164                          obj,
165                          fid,
166                          (jlong) ainfo->metatrafficUnicastPort);
167
168     // field ID - userdataUnicastPort
169     fid = (*env)->GetFieldID(env,cls,"userdataUniPort","J");
170     if(fid == 0)
171     {
172       #ifdef TEST_STAGE
173         printf(":!c: fid = NULL \n");
174       #endif
175       break;
176     }
177     #ifdef TEST_STAGE
178        printf(":c: ainfo.userdataUnicastPort = %d \n",
179               ainfo->userdataUnicastPort);
180     #endif
181     (*env)->SetLongField(env,
182                          obj,
183                          fid,
184                          (jlong) ainfo->userdataUnicastPort);
185
186     // find cls - VendorID
187     cls_tmp = findClass(env, "org.ocera.orte.types.VendorId");
188     if(cls_tmp == 0)
189     {
190       #ifdef TEST_STAGE
191         printf(":!c: cls_tmp = NULL \n");
192       #endif
193       break;
194     }
195     // call object constructor
196     mid = (*env)->GetMethodID(env,
197                               cls_tmp,
198                               "<init>",
199                               "(BB)V");
200     if(mid == 0)
201     {
202       #ifdef TEST_STAGE
203         printf(":!c: constructor failed! \n");
204       #endif
205       break;
206     }
207     // create new object
208     obj_tmp = (*env)->NewObject(env,
209                                 cls_tmp,
210                                 mid,
211                                 ainfo->vendorId.major,
212                                 ainfo->vendorId.minor);
213     if(obj_tmp == 0)
214     {
215       #ifdef TEST_STAGE
216         printf(":!c: obj = NULL \n");
217       #endif
218       break;
219     }
220     // set AppInfo's field
221     fid = (*env)->GetFieldID(env,
222                              cls,
223                              "vendorId",
224                              "Lorg/ocera/orte/types/VendorId;");
225     if(fid == 0)
226     {
227       #ifdef TEST_STAGE
228         printf(":!c: fid = NULL \n");
229       #endif
230       break;
231     }
232     #ifdef TEST_STAGE
233        printf(":c: ainfo.vendorId: major = %d, minor = %d \n",
234               ainfo->vendorId.major, ainfo->vendorId.minor);
235     #endif
236     (*env)->SetObjectField(env,
237                            obj,
238                            fid,
239                            obj_tmp);
240
241     // find cls - VendorID
242     cls_tmp = findClass(env, "org.ocera.orte.types.ProtocolVersion");
243     if(cls_tmp == 0)
244     {
245       #ifdef TEST_STAGE
246         printf(":!c: cls_tmp = NULL \n");
247       #endif
248       break;
249     }
250     // call object constructor
251     mid = (*env)->GetMethodID(env,
252                               cls_tmp,
253                               "<init>",
254                               "(BB)V");
255     if(mid == 0)
256     {
257       #ifdef TEST_STAGE
258         printf(":!c: constructor failed! \n");
259       #endif
260       break;
261     }
262     // create new object
263     obj_tmp = (*env)->NewObject(env,
264                                 cls_tmp,
265                                 mid,
266                                 ainfo->protocolVersion.major,
267                                 ainfo->protocolVersion.minor);
268     if(obj_tmp == 0)
269     {
270       #ifdef TEST_STAGE
271         printf(":!c: obj = NULL \n");
272       #endif
273       break;
274     }
275     // set AppInfo's field
276     fid = (*env)->GetFieldID(env,
277                              cls,
278                              "protocolVersion",
279                              "Lorg/ocera/orte/types/ProtocolVersion;");
280     if(fid == 0)
281     {
282       #ifdef TEST_STAGE
283         printf(":!c: fid = NULL \n");
284       #endif
285       break;
286     }
287     #ifdef TEST_STAGE
288        printf(":c: ainfo.protocolVersion: major = %d, minor = %d \n",
289               ainfo->protocolVersion.major, ainfo->protocolVersion.minor);
290     #endif
291     (*env)->SetObjectField(env,
292                            obj,
293                            fid,
294                            obj_tmp);
295
296     flag_ok = 1;
297   } while(0);
298
299   if(!flag_ok)
300   {
301     //detach...()
302     return NULL;
303   }
304
305 return obj;
306 }