]> rtime.felk.cvut.cz Git - orte.git/blob - orte/libjorte/JORTESubscriptionGetStatus.c
Reformat the sources with orte/uncrustify script
[orte.git] / orte / libjorte / JORTESubscriptionGetStatus.c
1 /* JORTESubscriptionGetStatus.c */
2
3 /**
4   * This code provides conversion between JAVA a C environments.
5   * The C functions are calling here and results are send to JAVA
6   * native functions. It uses the header pregenerated by JAVA
7   * (by command 'javah -jni class_with_native_function')
8   *
9   * @author Lukas Pokorny (lukas_pokorny@centrum.cz)
10   * @author CTU FEE Prague - Department of Control Engineering (dce.felk.cvut.cz)
11   * @author Project ORTE - OCERA Real Time Ethernet (www.ocera.org)
12   * @author dedication to Kj
13   * @version 0.1
14   *
15   *
16   * This program is free software; you can redistribute it and/or modify
17   * it under the terms of the GNU General Public License as published by
18   * the Free Software Foundation; either version 2 of the License, or
19   * (at your option) any later version.
20   *
21   * This program is distributed in the hope that it will be useful,
22   * but WITHOUT ANY WARRANTY; without even the implied warranty of
23   * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
24   * GNU General Public License for more details.
25   *
26   */
27
28 #include <string.h>
29 #include <stdlib.h>
30 // library header file's path
31 #include "orte.h"
32 // enable TEST_STAGE run level
33 #include "jorte/4all.h"
34 // pregenerated header
35 #include "jorte/org_ocera_orte_Subscription.h"
36 #include "jorte/jorte_protos_api.h"
37
38
39 JNIEXPORT jobject JNICALL
40 Java_org_ocera_orte_Subscription_jORTESubscriptionGetStatus
41   (JNIEnv *env, jobject obj, jlong j_appDomain_handle)
42 {
43   // jni types
44   jclass           cls_ss = NULL; // class of SubsStatus
45   jobject          obj_ss = NULL; // instance of SubsStatus
46   jfieldID         fid    = NULL;
47   jmethodID        mid    = NULL;
48   //
49   int              b = 0; // boolean
50   int              flag_ok = 0;
51   ORTESubsStatus   ss;
52   ORTESubsStatus  *subs_stat = &ss;
53
54   #ifdef TEST_STAGE
55   printf(":c: ORTEPublicationGetStatus() called.. \n");
56   #endif
57
58   // create new Status instance and set its fields
59   do {
60     // call ORTE function
61     b = ORTESubscriptionGetStatus((ORTESubscription *)j_appDomain_handle, subs_stat);
62     if (b == ORTE_BAD_HANDLE) {
63       printf(":!c: publicationGetStatus() failed! [bad pub handle] \n");
64       break;
65     }
66     // find cls
67     cls_ss = findClass(env, "org.ocera.orte.types.Status");
68     if (cls_ss == 0) {
69       #ifdef TEST_STAGE
70       printf(":!c: cls_ss = NULL \n");
71       #endif
72       break;
73     }
74     // call object constructor
75     mid = (*env)->GetMethodID(env, cls_ss, "<init>", "()V");
76     if (mid == 0) {
77       #ifdef TEST_STAGE
78       printf(":!c: mid = NULL \n");
79       #endif
80       break;
81     }
82     // new object
83     obj_ss = (*env)->NewObject(env, cls_ss, mid);
84     if (obj_ss == 0) {
85       #ifdef TEST_STAGE
86       printf(":!c: obj_ss = NULL \n");
87       #endif
88       break;
89     }
90     // ///////////////////////////////////////////////
91     // setting object's fields
92     // fieldID - strict
93     fid = (*env)->GetFieldID(env,
94                              cls_ss,
95                              "strict",
96                              "J");
97     if (fid == NULL) {
98       #ifdef TEST_STAGE
99       printf(":!c: fid = NULL \n");
100       #endif
101       break;
102     }
103     (*env)->SetLongField(env,
104                          obj_ss,
105                          fid,
106                          (jlong)subs_stat->strict);
107     // fieldID - bestEffort
108     fid = (*env)->GetFieldID(env,
109                              cls_ss,
110                              "bestEffort",
111                              "J");
112     if (fid == NULL) {
113       #ifdef TEST_STAGE
114       printf(":!c: fid = NULL \n");
115       #endif
116       break;
117     }
118     (*env)->SetLongField(env,
119                          obj_ss,
120                          fid,
121                          (jlong)subs_stat->bestEffort);
122     // fieldID - issues
123     fid = (*env)->GetFieldID(env,
124                              cls_ss,
125                              "issues",
126                              "J");
127     if (fid == NULL) {
128       #ifdef TEST_STAGE
129       printf(":!c: fid = NULL \n");
130       #endif
131       break;
132     }
133     (*env)->SetLongField(env,
134                          obj_ss,
135                          fid,
136                          (jlong)subs_stat->issues);
137     // set flag
138     flag_ok = 1;
139
140   } while (0);
141
142   if (flag_ok == 0) {
143     return NULL;
144   }
145
146   return obj_ss;
147
148 }