Logo AND Algorithmique Numérique Distribuée

Public GIT Repository
Merge branch 'master' of https://github.com/mpoquet/simgrid
[simgrid.git] / src / bindings / java / jmsg_as.cpp
index 2ebbc0e..ea41349 100644 (file)
@@ -6,15 +6,18 @@
 /* This program is free software; you can redistribute it and/or modify it
  * under the terms of the license (GNU LGPL) which comes with this package. */
 
-#include "xbt/str.h"
-#include "xbt/dict.h"
+#include <xbt/str.h>
+#include <xbt/dict.h>
+#include <xbt/dynar.h>
+
+#include <simgrid/s4u/host.hpp>
+
 #include "simgrid/msg.h"
 #include "jmsg_as.h"
 #include "jmsg_host.h"
 #include "jxbt_utilities.h"
 #include "jmsg.h"
 
-
 XBT_LOG_EXTERNAL_DEFAULT_CATEGORY(jmsg);
 
 static jmethodID jas_method_As_constructor;
@@ -41,8 +44,7 @@ msg_as_t jas_get_native(JNIEnv * env, jobject jas) {
   return (msg_as_t) (uintptr_t) env->GetLongField(jas, jas_field_As_bind);
 }
 
-JNIEXPORT void JNICALL
-Java_org_simgrid_msg_As_nativeInit(JNIEnv *env, jclass cls) {
+JNIEXPORT void JNICALL Java_org_simgrid_msg_As_nativeInit(JNIEnv *env, jclass cls) {
   jclass class_As = env->FindClass("org/simgrid/msg/As");
   jas_method_As_constructor = env->GetMethodID(class_As, "<init>", "()V");
   jas_field_As_bind = jxbt_get_jfield(env,class_As, "bind", "J");
@@ -51,14 +53,12 @@ Java_org_simgrid_msg_As_nativeInit(JNIEnv *env, jclass cls) {
   }
 }
 
-JNIEXPORT jobject JNICALL
-Java_org_simgrid_msg_As_getName(JNIEnv * env, jobject jas) {
+JNIEXPORT jobject JNICALL Java_org_simgrid_msg_As_getName(JNIEnv * env, jobject jas) {
   msg_as_t as = jas_get_native(env, jas);
   return env->NewStringUTF(MSG_environment_as_get_name(as));
 }
 
-JNIEXPORT jobjectArray JNICALL
-Java_org_simgrid_msg_As_getSons(JNIEnv * env, jobject jas) {
+JNIEXPORT jobjectArray JNICALL Java_org_simgrid_msg_As_getSons(JNIEnv * env, jobject jas) {
   int index = 0;
   jobjectArray jtable;
   jobject tmp_jas;
@@ -70,69 +70,60 @@ Java_org_simgrid_msg_As_getSons(JNIEnv * env, jobject jas) {
   jclass cls = env->FindClass("org/simgrid/msg/As");
 
   if (!cls) {
-    return NULL;
+    return nullptr;
   }
 
-  jtable = env->NewObjectArray((jsize) count, cls, NULL);
+  jtable = env->NewObjectArray(static_cast<jsize>(count), cls, nullptr);
 
   if (!jtable) {
     jxbt_throw_jni(env, "Hosts table allocation failed");
-    return NULL;
+    return nullptr;
   }
 
-  xbt_dict_cursor_t cursor=NULL;
+  xbt_dict_cursor_t cursor=nullptr;
   char *key;
 
   xbt_dict_foreach(dict,cursor,key,tmp_as) {
     tmp_jas = jas_new_instance(env);
     if (!tmp_jas) {
       jxbt_throw_jni(env, "java As instantiation failed");
-      return NULL;
+      return nullptr;
     }
     tmp_jas = jas_ref(env, tmp_jas);
     if (!tmp_jas) {
       jxbt_throw_jni(env, "new global ref allocation failed");
-      return NULL;
+      return nullptr;
     }
     jas_bind(tmp_jas, tmp_as, env);
 
     env->SetObjectArrayElement(jtable, index, tmp_jas);
     index++;
-
   }
   return jtable;
 }
 
-JNIEXPORT jobject JNICALL
-Java_org_simgrid_msg_As_getProperty(JNIEnv *env, jobject jas, jobject jname) {
+JNIEXPORT jobject JNICALL Java_org_simgrid_msg_As_getProperty(JNIEnv *env, jobject jas, jobject jname) {
   msg_as_t as = jas_get_native(env, jas);
 
   if (!as) {
     jxbt_throw_notbound(env, "as", jas);
-    return NULL;
+    return nullptr;
   }
-  const char *name = env->GetStringUTFChars((jstring) jname, 0);
+  const char *name = env->GetStringUTFChars(static_cast<jstring>(jname), 0);
 
   const char *property = MSG_environment_as_get_property_value(as, name);
   if (!property) {
-    return NULL;
+    return nullptr;
   }
 
   jobject jproperty = env->NewStringUTF(property);
 
-  env->ReleaseStringUTFChars((jstring) jname, name);
+  env->ReleaseStringUTFChars(static_cast<jstring>(jname), name);
 
   return jproperty;
 }
 
-JNIEXPORT jobject JNICALL
-Java_org_simgrid_msg_As_getModel(JNIEnv * env, jobject jas) {
-  msg_as_t as = jas_get_native(env, jas);
-  return env->NewStringUTF(MSG_environment_as_get_model(as));
-}
-
-JNIEXPORT jobjectArray JNICALL
-Java_org_simgrid_msg_As_getHosts(JNIEnv * env, jobject jas)
+JNIEXPORT jobjectArray JNICALL Java_org_simgrid_msg_As_getHosts(JNIEnv * env, jobject jas)
 {
   int index;
   jobjectArray jtable;
@@ -147,23 +138,22 @@ Java_org_simgrid_msg_As_getHosts(JNIEnv * env, jobject jas)
   jclass cls = jxbt_get_class(env, "org/simgrid/msg/Host");
 
   if (!cls) {
-    return NULL;
+    return nullptr;
   }
-  
-  jtable = env->NewObjectArray((jsize) count, cls, NULL);
+
+  jtable = env->NewObjectArray(static_cast<jsize>(count), cls, nullptr);
 
   if (!jtable) {
     jxbt_throw_jni(env, "Hosts table allocation failed");
-    return NULL;
+    return nullptr;
   }
 
   for (index = 0; index < count; index++) {
-
     host = xbt_dynar_get_as(table,index,msg_host_t);
 
-    jhost = (jobject) xbt_lib_get_level(host, JAVA_HOST_LEVEL);
+    jhost = static_cast<jobject>(host->extension(JAVA_HOST_LEVEL));
     if (!jhost) {
-      jname = env->NewStringUTF(MSG_host_get_name(host));
+      jname = env->NewStringUTF(host->cname());
 
       jhost = Java_org_simgrid_msg_Host_getByName(env, cls, jname);