]> rtime.felk.cvut.cz Git - orte.git/blob - orte/libjorte/JORTESubscriptionGetStatus.c
54858209ff47ce183f7c4dd55b7643346c808155
[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
37
38 JNIEXPORT jobject JNICALL
39 Java_org_ocera_orte_Subscription_jORTESubscriptionGetStatus
40 (JNIEnv *env, jobject obj, jlong j_appDomain_handle)
41 {
42   // jni types
43   jclass           cls_ss = NULL; // class of SubsStatus
44   jobject          obj_ss = NULL; // instance of SubsStatus
45   jfieldID         fid    = NULL;
46   jmethodID        mid    = NULL;
47   //
48   int              b = 0; // boolean
49   int              flag_ok = 0;
50   ORTESubsStatus   ss;
51   ORTESubsStatus  *subs_stat = &ss;
52
53   #ifdef TEST_STAGE
54     printf(":c: ORTEPublicationGetStatus() called.. \n");
55   #endif
56
57   // create new Status instance and set its fields
58   do
59   {
60     // call ORTE function
61     b = ORTESubscriptionGetStatus((ORTESubscription *)j_appDomain_handle, subs_stat);
62     if(b == ORTE_BAD_HANDLE)
63     {
64      printf(":!c: publicationGetStatus() failed! [bad pub handle] \n");
65      break;
66     }
67     // find cls
68     cls_ss = findClass(env,"org.ocera.orte.types.Status");
69     if(cls_ss == 0)
70     {
71       #ifdef TEST_STAGE
72        printf(":!c: cls_ss = NULL \n");
73       #endif
74       break;
75     }
76     // call object constructor
77     mid = (*env)->GetMethodID(env,cls_ss,"<init>","()V");
78     if(mid == 0)
79     {
80       #ifdef TEST_STAGE
81        printf(":!c: mid = NULL \n");
82       #endif
83       break;
84     }
85     // new object
86     obj_ss = (*env)->NewObject(env, cls_ss, mid);
87     if(obj_ss == 0)
88     {
89       #ifdef TEST_STAGE
90        printf(":!c: obj_ss = NULL \n");
91       #endif
92       break;
93     }
94     // ///////////////////////////////////////////////
95     // setting object's fields
96     // fieldID - strict
97     fid = (*env)->GetFieldID(env,
98                              cls_ss,
99                              "strict",
100                              "J");
101     if(fid == NULL)
102     {
103       #ifdef TEST_STAGE
104        printf(":!c: fid = NULL \n");
105       #endif
106       break;
107     }
108     (*env)->SetLongField(env,
109                          obj_ss,
110                          fid,
111                          (jlong) subs_stat->strict);
112     // fieldID - bestEffort
113     fid = (*env)->GetFieldID(env,
114                              cls_ss,
115                              "bestEffort",
116                              "J");
117     if(fid == NULL)
118     {
119       #ifdef TEST_STAGE
120        printf(":!c: fid = NULL \n");
121       #endif
122       break;
123     }
124     (*env)->SetLongField(env,
125                          obj_ss,
126                          fid,
127                          (jlong) subs_stat->bestEffort);
128     // fieldID - issues
129     fid = (*env)->GetFieldID(env,
130                              cls_ss,
131                              "issues",
132                              "J");
133     if(fid == NULL)
134     {
135       #ifdef TEST_STAGE
136         printf(":!c: fid = NULL \n");
137       #endif
138       break;
139     }
140     (*env)->SetLongField(env,
141                          obj_ss,
142                          fid,
143                          (jlong) subs_stat->issues);
144     // set flag
145     flag_ok = 1;
146
147   } while(0);
148
149   if(flag_ok == 0)
150   {
151     return NULL;
152   }
153
154   return obj_ss;
155
156 }