]> rtime.felk.cvut.cz Git - orte.git/blobdiff - orte/libjorte/JORTEDomainAppDestroy.c
Revert "JORTE: update license headers and clean-up includes"
[orte.git] / orte / libjorte / JORTEDomainAppDestroy.c
index 031b24f8da092976e8e2dd63e66838d1b3aa11ba..460682b34863f9d2400df29c9283dba3c6328f1e 100644 (file)
   *
   */
 
-
+#include <stdlib.h>
 // origin orte headers
 #include "orte.h"
 // pregenerated header
-#include "jorte/org_ocera_orte_Domain.h"
-
-
+#include "jorte/org_ocera_orte_DomainApp.h"
+#include "jorte/4all.h"
+#include "jorte/jorte_typedefs_defines.h"
 
 JNIEXPORT jboolean JNICALL
-Java_org_ocera_orte_Domain_jORTEDomainADestroy
-(JNIEnv *env, jclass cls, jint dhandle)
+Java_org_ocera_orte_DomainApp_jORTEDomainAppDestroy
+(JNIEnv *env, jobject obj, jlong dhandle)
 {
-  if (!dhandle) return 0;
-  /* call the liborte function */
-  if (ORTEDomainAppDestroy((ORTEDomain *) dhandle))  {
-    /*  printf(":c: ORTEDomainAppDestroy() succesfuly \n"); */
-    return 1;
+  jlong       h;
+  jclass      cls;
+  jfieldID    fid;
+  int         flag_ok = 0;
+
+  do {
+    // check domain handle
+    if (dhandle == 0)
+    {
+      printf(":!c: ORTEDomainAppDestroy failed! [bad handle] \n");
+      break;
+    }
+    // call ORTE function
+    if (!ORTEDomainAppDestroy((ORTEDomain *) dhandle))
+    {
+      #ifdef TEST_STAGE
+         printf(":c: ORTEDomainAppDestroy failed.. \n");
+      #endif
+      break;
+    }
+
+    // free domainEvents object
+    // find cls
+    cls = (*env)->GetObjectClass(env, obj);
+    if(cls == 0)
+    {
+      #ifdef TEST_STAGE
+        printf(":!c: cls = NULL! \n");
+      #endif
+      break;
+    }
+    // fieldID
+    fid = (*env)->GetFieldID(env,
+                             cls,
+                             "domainEventsContextHandle",
+                             "J");
+    if(fid == 0)
+    {
+     #ifdef TEST_STAGE
+       printf(":!c: fid = NULL! \n");
+     #endif
+     break;
+    }
+    // get value
+    h = (*env)->GetLongField(env, obj, fid);
+    if(h)
+    {
+      JORTEDomainEventsContext_t *ctx = (JORTEDomainEventsContext_t*)h;
+      if(ctx->obj_de)
+      {
+        #ifdef TEST_STAGE
+          printf(":c: deleting ctx->obj_de \n");
+        #endif
+        (*env)->DeleteGlobalRef(env, ctx->obj_de);
+      }
+      //
+      free((void*)h);
+    }
+    flag_ok = 1;
+  } while(0);
+
+  if(flag_ok == 0)
+  {
+    printf(":!c: ORTEDomainAppDestroy failed!  \n");
+    return 0;
   }
-  printf(":!c: ORTEDomainAppDestroy failed!  \n");
-  return 0;
+
+  return 1;
 }