X-Git-Url: http://info.iut-bm.univ-fcomte.fr/pub/gitweb/simgrid.git/blobdiff_plain/ce9cbf0e2aea0198cb08a735a3ad36c6471f5468..39423c5e63cbaa7fc3c41a4af6037948c4033225:/src/bindings/java/jmsg_as.cpp diff --git a/src/bindings/java/jmsg_as.cpp b/src/bindings/java/jmsg_as.cpp index 8124ac4a15..9b4f7bf3ae 100644 --- a/src/bindings/java/jmsg_as.cpp +++ b/src/bindings/java/jmsg_as.cpp @@ -5,15 +5,16 @@ /* 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 "simgrid/s4u/Host.hpp" #include "simgrid/s4u/NetZone.hpp" -#include "simgrid/s4u/host.hpp" +#include "src/kernel/routing/NetZoneImpl.hpp" #include "jmsg_as.h" #include "jmsg_host.h" #include "jxbt_utilities.h" #include "jmsg.h" -XBT_LOG_EXTERNAL_DEFAULT_CATEGORY(jmsg); +XBT_LOG_EXTERNAL_DEFAULT_CATEGORY(java); SG_BEGIN_DECL() @@ -63,29 +64,22 @@ JNIEXPORT jobject JNICALL Java_org_simgrid_msg_As_getName(JNIEnv * env, jobject JNIEXPORT jobjectArray JNICALL Java_org_simgrid_msg_As_getSons(JNIEnv * env, jobject jas) { int index = 0; jobjectArray jtable; - jobject tmp_jas; - simgrid::s4u::NetZone* tmp_as; - simgrid::s4u::NetZone* self_as = jnetzone_get_native(env, jas); + sg_netzone_t self_as = jnetzone_get_native(env, jas); - xbt_dict_t dict = self_as->children(); - int count = xbt_dict_length(dict); jclass cls = env->FindClass("org/simgrid/msg/As"); if (!cls) return nullptr; - jtable = env->NewObjectArray(static_cast(count), cls, nullptr); + jtable = env->NewObjectArray(static_cast(self_as->children()->size()), cls, nullptr); if (!jtable) { jxbt_throw_jni(env, "Hosts table allocation failed"); return nullptr; } - xbt_dict_cursor_t cursor=nullptr; - char *key; - - xbt_dict_foreach(dict,cursor,key,tmp_as) { - tmp_jas = jnetzone_new_instance(env); + for (auto tmp_as : *self_as->children()) { + jobject tmp_jas = jnetzone_new_instance(env); if (!tmp_jas) { jxbt_throw_jni(env, "java As instantiation failed"); return nullptr; @@ -129,27 +123,22 @@ JNIEXPORT jobjectArray JNICALL Java_org_simgrid_msg_As_getHosts(JNIEnv * env, jo jobjectArray jtable; jobject jhost; jstring jname; - msg_host_t host; simgrid::s4u::NetZone* as = jnetzone_get_native(env, jas); - xbt_dynar_t table = as->hosts(); - int count = xbt_dynar_length(table); - jclass cls = jxbt_get_class(env, "org/simgrid/msg/Host"); - + std::vector* table = as->hosts(); if (!cls) return nullptr; - jtable = env->NewObjectArray(static_cast(count), cls, nullptr); + jtable = env->NewObjectArray(static_cast(table->size()), cls, nullptr); if (!jtable) { jxbt_throw_jni(env, "Hosts table allocation failed"); return nullptr; } - for (int index = 0; index < count; index++) { - host = xbt_dynar_get_as(table,index,msg_host_t); - + int index = 0; + for (auto host : *table) { jhost = static_cast(host->extension(JAVA_HOST_LEVEL)); if (!jhost) { jname = env->NewStringUTF(host->cname()); @@ -160,8 +149,8 @@ JNIEXPORT jobjectArray JNICALL Java_org_simgrid_msg_As_getHosts(JNIEnv * env, jo } env->SetObjectArrayElement(jtable, index, jhost); + index++; } - xbt_dynar_free(&table); return jtable; }