]> rtime.felk.cvut.cz Git - orte.git/blob - orte/libjorte/JORTESubscriptionDestroy.c
JORTE: fix subscription destruction
[orte.git] / orte / libjorte / JORTESubscriptionDestroy.c
1 /* JORTESubscriptionDestroy.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
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 #include "jorte/jorte_typedefs_defines.h"
38
39 JNIEXPORT jboolean JNICALL
40 Java_org_ocera_orte_Subscription_jORTESubscriptionDestroy
41 (JNIEnv *env, jobject obj, jlong subs_handle)
42 {
43   int8_t        b;
44   jlong         h;
45   jclass        cls;
46   jfieldID      fid;
47   int           flag_ok = 0;
48
49   #ifdef TEST_STAGE
50     printf(":c: ORTESubscriptionDestroy() called.. \n");
51   #endif
52
53   do
54   {
55     // free callBack object
56     // find cls
57     cls = (*env)->GetObjectClass(env, obj);
58     if(cls == 0)
59     {
60      #ifdef TEST_STAGE
61        printf(":!c: cls = NULL! \n");
62      #endif
63      break;
64     }
65     // fieldID
66     fid = (*env)->GetFieldID(env,
67                              cls,
68                              "callbackContextHandle",
69                              "J");
70     if(fid == 0)
71     {
72      #ifdef TEST_STAGE
73        printf(":!c: fid = NULL! \n");
74      #endif
75      break;
76     }
77     if(subs_handle)
78     {
79       // call ORTE function
80       b = ORTESubscriptionDestroy((ORTESubscription *) subs_handle);
81       if (b == ORTE_BAD_HANDLE)
82       {
83         printf(":!c: subscription destroy failed! [bad sub handle] \n");
84         break;
85       }
86       #ifdef TEST_STAGE
87         printf(":c: subscription destroy succesfuly.. \n");
88       #endif
89     }
90     // get value
91     h = (*env)->GetLongField(env, obj, fid);
92     if(h)
93     {
94       //JavaVM *jvm;
95       //jint ret;
96       JORTECallbackContext_t *ctx = (JORTECallbackContext_t*)h;
97       if(ctx->obj)
98       {
99         #ifdef TEST_STAGE
100           printf(":c: deleting ctx->obj \n");
101         #endif
102         (*env)->DeleteGlobalRef(env, ctx->obj);
103       }
104       if(ctx->rinfo)
105       {
106         #ifdef TEST_STAGE
107           printf(":c: deleting ctx->rinfo\n");
108         #endif
109         (*env)->DeleteGlobalRef(env, ctx->rinfo);
110       }
111       if(ctx->msg)
112       {
113         #ifdef TEST_STAGE
114           printf(":c: deleting ctx->msg\n");
115         #endif
116         (*env)->DeleteGlobalRef(env, ctx->msg);
117       }
118       //
119       free((void*)h);
120     }
121     // set flag
122     flag_ok = 1;
123   } while(0);
124
125   #ifdef TEST_STAGE
126      printf(":c: flag_ok = %d \n",flag_ok);
127   #endif
128
129   if(flag_ok == 0)
130   {
131     return 0;
132   }
133
134   return 1;
135
136 }