]> rtime.felk.cvut.cz Git - orte.git/blob - orte/libjorte/createAppInfo.c
Reformat the sources with orte/uncrustify script
[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
10 createAppInfo(JNIEnv *env, const ORTEAppInfo *ainfo)
11 {
12   jclass    cls;
13   jclass    cls_tmp;
14   jobject   obj;
15   jobject   obj_tmp;
16   jfieldID  fid;
17   jmethodID mid;
18   //
19   int flag_ok = 0;
20
21   do {
22     // find cls
23     cls = findClass(env, "org.ocera.orte.types.AppInfo");
24     if (cls == 0) {
25       #ifdef TEST_STAGE
26       printf(":!c: cls = NULL \n");
27       #endif
28       break;
29     }
30     // call object constructor
31     mid = (*env)->GetMethodID(env, cls, "<init>", "()V");
32     if (mid == 0) {
33       #ifdef TEST_STAGE
34       printf(":!c: constructor failed! \n");
35       #endif
36       break;
37     }
38     // create new object
39     obj = (*env)->NewObject(env, cls, mid);
40     if (obj == 0) {
41       #ifdef TEST_STAGE
42       printf(":!c: obj = NULL \n");
43       #endif
44       break;
45     }
46     // field ID - hostID
47     fid = (*env)->GetFieldID(env, cls, "hostId", "J");
48     if (fid == 0) {
49       #ifdef TEST_STAGE
50       printf(":!c: fid = NULL \n");
51       #endif
52       break;
53     }
54     #ifdef TEST_STAGE
55     printf(":c: ainfo.hostId = %#" PRIx32 " \n", ainfo->hostId);
56     #endif
57     (*env)->SetLongField(env,
58                          obj,
59                          fid,
60                          (jlong)ainfo->hostId);
61
62     // field ID - appID
63     fid = (*env)->GetFieldID(env, cls, "appId", "J");
64     if (fid == 0) {
65       #ifdef TEST_STAGE
66       printf(":!c: fid = NULL \n");
67       #endif
68       break;
69     }
70     #ifdef TEST_STAGE
71     printf(":c: ainfo.appId = %#" PRIx32 " \n", ainfo->appId);
72     #endif
73     (*env)->SetLongField(env,
74                          obj,
75                          fid,
76                          (jlong)ainfo->appId);
77     // field ID - unicastIPAddressTemp
78     fid = (*env)->GetFieldID(env, cls, "unicastIPAddressTemp", "J");
79     if (fid == 0) {
80       #ifdef TEST_STAGE
81       printf(":!c: fid uniIPAddrTemp = NULL \n");
82       #endif
83       break;
84     }
85     #ifdef TEST_STAGE
86     printf(":c: ainfo.unicastIPAddressList = %#" PRIxPTR "\n", (intptr_t)ainfo->unicastIPAddressList);
87     #endif
88     (*env)->SetLongField(env,
89                          obj,
90                          fid,
91                          (jlong) *ainfo->unicastIPAddressList);
92     // field ID - unicastIPcount
93     fid = (*env)->GetFieldID(env, cls, "unicastIPcount", "B");
94     if (fid == 0) {
95       #ifdef TEST_STAGE
96       printf(":!c: fid = NULL \n");
97       #endif
98       break;
99     }
100     #ifdef TEST_STAGE
101     printf(":c: ainfo.unicastIPcount = %hhu \n",
102            ainfo->unicastIPAddressCount);
103     #endif
104     (*env)->SetByteField(env,
105                          obj,
106                          fid,
107                          (jbyte)ainfo->unicastIPAddressCount);
108     // field ID - multicastIPAddressTemp
109     fid = (*env)->GetFieldID(env, cls, "mettaTrafficMulticastIPAddressTemp", "J");
110     if (fid == 0) {
111       #ifdef TEST_STAGE
112       printf(":!c: fid multiIPAddrTemp = NULL \n");
113       #endif
114       break;
115     }
116     #ifdef TEST_STAGE
117     printf(":c: ainfo.multicastIPAddressList = %#" PRIxPTR "\n",
118            (intptr_t)ainfo->metatrafficMulticastIPAddressList);
119     #endif
120     (*env)->SetLongField(env,
121                          obj,
122                          fid,
123                          (jlong) *ainfo->metatrafficMulticastIPAddressList);
124     // field ID - multicastIPcount
125     fid = (*env)->GetFieldID(env, cls, "multicastIPcount", "B");
126     if (fid == 0) {
127       #ifdef TEST_STAGE
128       printf(":!c: fid = NULL \n");
129       #endif
130       break;
131     }
132     #ifdef TEST_STAGE
133     printf(":c: ainfo.metatrafficMulticastIPAddressCount = %hhu \n",
134            ainfo->metatrafficMulticastIPAddressCount);
135     #endif
136     (*env)->SetByteField(env,
137                          obj,
138                          fid,
139                          (jbyte)ainfo->metatrafficMulticastIPAddressCount);
140
141     // field ID - mettatraficUnicastPort
142     fid = (*env)->GetFieldID(env, cls, "metatrafficUniPort", "J");
143     if (fid == 0) {
144       #ifdef TEST_STAGE
145       printf(":!c: fid = NULL \n");
146       #endif
147       break;
148     }
149     #ifdef TEST_STAGE
150     printf(":c: ainfo.metatrafficUnicastPort = %" PRIu32 " \n",
151            ainfo->metatrafficUnicastPort);
152     #endif
153     (*env)->SetLongField(env,
154                          obj,
155                          fid,
156                          (jlong)ainfo->metatrafficUnicastPort);
157
158     // field ID - userdataUnicastPort
159     fid = (*env)->GetFieldID(env, cls, "userdataUniPort", "J");
160     if (fid == 0) {
161       #ifdef TEST_STAGE
162       printf(":!c: fid = NULL \n");
163       #endif
164       break;
165     }
166     #ifdef TEST_STAGE
167     printf(":c: ainfo.userdataUnicastPort = %" PRIu32 " \n",
168            ainfo->userdataUnicastPort);
169     #endif
170     (*env)->SetLongField(env,
171                          obj,
172                          fid,
173                          (jlong)ainfo->userdataUnicastPort);
174
175     // find cls - VendorID
176     cls_tmp = findClass(env, "org.ocera.orte.types.VendorId");
177     if (cls_tmp == 0) {
178       #ifdef TEST_STAGE
179       printf(":!c: cls_tmp = NULL \n");
180       #endif
181       break;
182     }
183     // call object constructor
184     mid = (*env)->GetMethodID(env,
185                               cls_tmp,
186                               "<init>",
187                               "(BB)V");
188     if (mid == 0) {
189       #ifdef TEST_STAGE
190       printf(":!c: constructor failed! \n");
191       #endif
192       break;
193     }
194     // create new object
195     obj_tmp = (*env)->NewObject(env,
196                                 cls_tmp,
197                                 mid,
198                                 ainfo->vendorId.major,
199                                 ainfo->vendorId.minor);
200     if (obj_tmp == 0) {
201       #ifdef TEST_STAGE
202       printf(":!c: obj = NULL \n");
203       #endif
204       break;
205     }
206     // set AppInfo's field
207     fid = (*env)->GetFieldID(env,
208                              cls,
209                              "vendorId",
210                              "Lorg/ocera/orte/types/VendorId;");
211     if (fid == 0) {
212       #ifdef TEST_STAGE
213       printf(":!c: fid = NULL \n");
214       #endif
215       break;
216     }
217     #ifdef TEST_STAGE
218     printf(":c: ainfo.vendorId: major = %" PRId8 ", minor = %" PRId8 " \n",
219            ainfo->vendorId.major, ainfo->vendorId.minor);
220     #endif
221     (*env)->SetObjectField(env,
222                            obj,
223                            fid,
224                            obj_tmp);
225
226     // find cls - VendorID
227     cls_tmp = findClass(env, "org.ocera.orte.types.ProtocolVersion");
228     if (cls_tmp == 0) {
229       #ifdef TEST_STAGE
230       printf(":!c: cls_tmp = NULL \n");
231       #endif
232       break;
233     }
234     // call object constructor
235     mid = (*env)->GetMethodID(env,
236                               cls_tmp,
237                               "<init>",
238                               "(BB)V");
239     if (mid == 0) {
240       #ifdef TEST_STAGE
241       printf(":!c: constructor failed! \n");
242       #endif
243       break;
244     }
245     // create new object
246     obj_tmp = (*env)->NewObject(env,
247                                 cls_tmp,
248                                 mid,
249                                 ainfo->protocolVersion.major,
250                                 ainfo->protocolVersion.minor);
251     if (obj_tmp == 0) {
252       #ifdef TEST_STAGE
253       printf(":!c: obj = NULL \n");
254       #endif
255       break;
256     }
257     // set AppInfo's field
258     fid = (*env)->GetFieldID(env,
259                              cls,
260                              "protocolVersion",
261                              "Lorg/ocera/orte/types/ProtocolVersion;");
262     if (fid == 0) {
263       #ifdef TEST_STAGE
264       printf(":!c: fid = NULL \n");
265       #endif
266       break;
267     }
268     #ifdef TEST_STAGE
269     printf(":c: ainfo.protocolVersion: major = %" PRId8 ", minor = %" PRId8 " \n",
270            ainfo->protocolVersion.major, ainfo->protocolVersion.minor);
271     #endif
272     (*env)->SetObjectField(env,
273                            obj,
274                            fid,
275                            obj_tmp);
276
277     flag_ok = 1;
278   } while (0);
279
280   if (!flag_ok) {
281     //detach...()
282     return NULL;
283   }
284
285   return obj;
286 }