]> rtime.felk.cvut.cz Git - orte.git/blobdiff - orte/libjorte/JORTEDomainMgrDestroy.c
Merge branch 'master' of https://github.com/Vajnar/orte
[orte.git] / orte / libjorte / JORTEDomainMgrDestroy.c
index d38df5ef020da4b2ce616f4dd858337eebf224de..e5f6aebac085f203419a9d5a1bb37605a48582da 100644 (file)
   *
   */
 
-
+#include <stdlib.h>
 // origin orte headers
 #include "orte.h"
 // pregenerated header
 #include "jorte/org_ocera_orte_DomainMgr.h"
 #include "jorte/4all.h"
+#include "jorte/jorte_typedefs_defines.h"
 
 
 JNIEXPORT jboolean JNICALL
 Java_org_ocera_orte_DomainMgr_jORTEDomainMgrDestroy
-(JNIEnv *env, jclass cls, jlong dhandle)
+  (JNIEnv *env, jobject obj, jlong dhandle)
 {
-  int8_t     b;
+  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 (!ORTEDomainMgrDestroy((ORTEDomain *)dhandle)) {
+      #ifdef TEST_STAGE
+      printf(":c: mgrDomain destroy 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);
 
-  // call ORTE function
-  b = ORTEDomainMgrDestroy((ORTEDomain *) dhandle);
-  if(b == ORTE_OK)
-  {
-    #ifdef TEST_STAGE
-      printf(":c: mgrDomain destroy successfully.. \n");
-    #endif
-    return 1;
+  if (flag_ok == 0) {
+    printf(":!c: ORTEDomainMgrDestroy failed!  \n");
+    return 0;
   }
-  if (b == ORTE_BAD_HANDLE)
-    printf(":!c: mgrDomain destroy failed! [bad domain handle] \n");
-  return 0;
+
+  return 1;
 }