/* 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.hpp"
+#include "jmsg_as.hpp"
#include "jmsg_host.h"
-#include "jxbt_utilities.h"
-#include "jmsg.h"
+#include "jxbt_utilities.hpp"
XBT_LOG_EXTERNAL_DEFAULT_CATEGORY(java);
-SG_BEGIN_DECL()
+extern "C" {
static jmethodID jas_method_As_constructor;
static jfieldID jas_field_As_bind;
JNIEXPORT jobject JNICALL Java_org_simgrid_msg_As_getName(JNIEnv * env, jobject jas) {
simgrid::s4u::NetZone* as = jnetzone_get_native(env, jas);
- return env->NewStringUTF(as->name());
+ return env->NewStringUTF(as->getCname());
}
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)
+ if (not cls)
return nullptr;
- jtable = env->NewObjectArray(static_cast<jsize>(count), cls, nullptr);
+ jtable = env->NewObjectArray(static_cast<jsize>(self_as->getChildren()->size()), cls, nullptr);
- if (!jtable) {
+ if (not 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);
- if (!tmp_jas) {
+ for (auto const& tmp_as : *self_as->getChildren()) {
+ jobject tmp_jas = jnetzone_new_instance(env);
+ if (not tmp_jas) {
jxbt_throw_jni(env, "java As instantiation failed");
return nullptr;
}
tmp_jas = jnetzone_ref(env, tmp_jas);
- if (!tmp_jas) {
+ if (not tmp_jas) {
jxbt_throw_jni(env, "new global ref allocation failed");
return nullptr;
}
JNIEXPORT jobject JNICALL Java_org_simgrid_msg_As_getProperty(JNIEnv *env, jobject jas, jobject jname) {
simgrid::s4u::NetZone* as = jnetzone_get_native(env, jas);
- if (!as) {
+ if (not as) {
jxbt_throw_notbound(env, "as", jas);
return nullptr;
}
const char *name = env->GetStringUTFChars(static_cast<jstring>(jname), 0);
- const char *property = MSG_environment_as_get_property_value(as, name);
- if (!property) {
+ const char* property = MSG_zone_get_property_value(as, name);
+ if (not property) {
return nullptr;
}
simgrid::s4u::NetZone* as = jnetzone_get_native(env, jas);
jclass cls = jxbt_get_class(env, "org/simgrid/msg/Host");
- std::vector<sg_host_t>* table = as->hosts();
- if (!cls)
+ if (not cls)
return nullptr;
- jtable = env->NewObjectArray(static_cast<jsize>(table->size()), cls, nullptr);
+ std::vector<sg_host_t> table;
+ as->getHosts(&table);
+
+ jtable = env->NewObjectArray(static_cast<jsize>(table.size()), cls, nullptr);
- if (!jtable) {
+ if (not jtable) {
jxbt_throw_jni(env, "Hosts table allocation failed");
return nullptr;
}
int index = 0;
- for (auto host : *table) {
+ for (auto const& host : table) {
jhost = static_cast<jobject>(host->extension(JAVA_HOST_LEVEL));
- if (!jhost) {
- jname = env->NewStringUTF(host->cname());
+ if (not jhost) {
+ jname = env->NewStringUTF(host->getCname());
jhost = Java_org_simgrid_msg_Host_getByName(env, cls, jname);
- env->ReleaseStringUTFChars(static_cast<jstring>(jname), host->cname());
+ env->ReleaseStringUTFChars(static_cast<jstring>(jname), host->getCname());
}
env->SetObjectArrayElement(jtable, index, jhost);
}
return jtable;
}
-
-SG_END_DECL()
+}