X-Git-Url: http://info.iut-bm.univ-fcomte.fr/pub/gitweb/simgrid.git/blobdiff_plain/5e1fa53a0d0ae78cebae28364e6802aa1db1cba3..67d66b0cf79b9fc02c0450f254584693dbf21d3b:/src/bindings/java/jmsg_host.cpp diff --git a/src/bindings/java/jmsg_host.cpp b/src/bindings/java/jmsg_host.cpp index 655f1ed813..1b276068d8 100644 --- a/src/bindings/java/jmsg_host.cpp +++ b/src/bindings/java/jmsg_host.cpp @@ -1,6 +1,6 @@ /* Functions related to the java host instances. */ -/* Copyright (c) 2007-2020. The SimGrid Team. All rights reserved. */ +/* Copyright (c) 2007-2021. The SimGrid Team. All rights reserved. */ /* 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. */ @@ -9,12 +9,10 @@ #include "simgrid/plugins/energy.h" #include "simgrid/plugins/load.h" #include "simgrid/s4u/Host.hpp" -#include "simgrid/s4u/Storage.hpp" #include "JavaContext.hpp" #include "jmsg.hpp" #include "jmsg_host.h" -#include "jmsg_storage.h" #include "jxbt_utilities.hpp" XBT_LOG_EXTERNAL_DEFAULT_CATEGORY(java); @@ -60,16 +58,14 @@ JNIEXPORT jobject JNICALL Java_org_simgrid_msg_Host_getByName(JNIEnv* env, jclas jxbt_throw_null(env, "No host can have a null name"); return nullptr; } - const char* name = env->GetStringUTFChars(jname, nullptr); + jstring_wrapper name(env, jname); /* get the host by name (the hosts are created during the grid resolution) */ sg_host_t host = sg_host_by_name(name); if (not host) { /* invalid name */ jxbt_throw_host_not_found(env, name); - env->ReleaseStringUTFChars(jname, name); return nullptr; } - env->ReleaseStringUTFChars(jname, name); if (not host->extension(JAVA_HOST_LEVEL)) { /* native host not associated yet with java host */ /* Instantiate a new java host */ @@ -93,7 +89,7 @@ JNIEXPORT jobject JNICALL Java_org_simgrid_msg_Host_getByName(JNIEnv* env, jclas jhost_bind(jhost, host, env); /* the native host data field is set with the global reference to the java host returned by this function */ - host->extension_set(JAVA_HOST_LEVEL, (void *)jhost); + host->extension_set(JAVA_HOST_LEVEL, jhost); } /* return the global reference to the java host instance */ @@ -128,7 +124,7 @@ JNIEXPORT jobject JNICALL Java_org_simgrid_msg_Host_currentHost(JNIEnv * env, jc env->SetObjectField(jhost, jhost_field_Host_name, jname); /* Bind & store it */ jhost_bind(jhost, host, env); - host->extension_set(JAVA_HOST_LEVEL, (void *) jhost); + host->extension_set(JAVA_HOST_LEVEL, jhost); } else { jhost = (jobject) host->extension(JAVA_HOST_LEVEL); } @@ -159,7 +155,7 @@ JNIEXPORT jdouble JNICALL Java_org_simgrid_msg_Host_getSpeed(JNIEnv * env, jobje return -1; } - return (jdouble)sg_host_speed(host); + return (jdouble)sg_host_get_speed(host); } JNIEXPORT jdouble JNICALL Java_org_simgrid_msg_Host_getCoreNumber(JNIEnv * env, jobject jhost) { @@ -180,7 +176,7 @@ JNIEXPORT jobject JNICALL Java_org_simgrid_msg_Host_getProperty(JNIEnv *env, job jxbt_throw_notbound(env, "host", jhost); return nullptr; } - const char* name = env->GetStringUTFChars((jstring)jname, nullptr); + jstring_wrapper name(env, (jstring)jname); const char* property = sg_host_get_property_value(host, name); if (not property) { @@ -189,8 +185,6 @@ JNIEXPORT jobject JNICALL Java_org_simgrid_msg_Host_getProperty(JNIEnv *env, job jobject jproperty = env->NewStringUTF(property); - env->ReleaseStringUTFChars((jstring) jname, name); - return jproperty; } @@ -202,14 +196,11 @@ Java_org_simgrid_msg_Host_setProperty(JNIEnv *env, jobject jhost, jobject jname, jxbt_throw_notbound(env, "host", jhost); return; } - const char* name = env->GetStringUTFChars((jstring)jname, nullptr); - const char* value_java = env->GetStringUTFChars((jstring)jvalue, nullptr); + jstring_wrapper name(env, (jstring)jname); + jstring_wrapper value_java(env, (jstring)jvalue); const char* value = xbt_strdup(value_java); sg_host_set_property_value(host, name, value); - - env->ReleaseStringUTFChars((jstring) jvalue, value_java); - env->ReleaseStringUTFChars((jstring) jname, name); } JNIEXPORT jboolean JNICALL Java_org_simgrid_msg_Host_isOn(JNIEnv * env, jobject jhost) @@ -224,74 +215,6 @@ JNIEXPORT jboolean JNICALL Java_org_simgrid_msg_Host_isOn(JNIEnv * env, jobject return (jboolean)sg_host_is_on(host); } -JNIEXPORT jobjectArray JNICALL Java_org_simgrid_msg_Host_getMountedStorage(JNIEnv * env, jobject jhost) -{ - msg_host_t host = jhost_get_native(env, jhost); - jobject jstorage; - jstring jname; - - if (not host) { - jxbt_throw_notbound(env, "host", jhost); - return nullptr; - } - - int index = 0; - jobjectArray jtable; - std::unordered_map mounted_storages = host->get_mounted_storages(); - int count = mounted_storages.size(); - jclass cls = env->FindClass("org/simgrid/msg/Storage"); - - jtable = env->NewObjectArray((jsize) count, cls, nullptr); - - if (not jtable) { - jxbt_throw_jni(env, "Storages table allocation failed"); - return nullptr; - } - - for (auto const& elm : mounted_storages) { - jname = env->NewStringUTF(elm.second->get_cname()); - jstorage = Java_org_simgrid_msg_Storage_getByName(env,cls,jname); - env->SetObjectArrayElement(jtable, index, jstorage); - index++; - } - return jtable; -} - -JNIEXPORT jobjectArray JNICALL Java_org_simgrid_msg_Host_getAttachedStorage(JNIEnv * env, jobject jhost) -{ - const_sg_host_t host = jhost_get_native(env, jhost); - - if (not host) { - jxbt_throw_notbound(env, "host", jhost); - return nullptr; - } - jobjectArray jtable; - - xbt_dynar_t dyn = sg_host_get_attached_storage_list(host); - jclass cls = jxbt_get_class(env, "java/lang/String"); - jtable = env->NewObjectArray(static_cast(xbt_dynar_length(dyn)), cls, nullptr); - unsigned int index; - const char* storage_name; - jstring jstorage_name; - xbt_dynar_foreach (dyn, index, storage_name) { - jstorage_name = env->NewStringUTF(storage_name); - env->SetObjectArrayElement(jtable, index, jstorage_name); - } - xbt_dynar_free_container(&dyn); - return jtable; -} - -JNIEXPORT jobjectArray JNICALL Java_org_simgrid_msg_Host_getStorageContent(JNIEnv * env, jobject jhost) -{ - msg_host_t host = jhost_get_native(env, jhost); - - if (not host) { - jxbt_throw_notbound(env, "host", jhost); - return nullptr; - } - return (jobjectArray)sg_host_get_storage_content(host); -} - JNIEXPORT jobjectArray JNICALL Java_org_simgrid_msg_Host_all(JNIEnv * env, jclass cls_arg) { sg_host_t* table = sg_host_list(); @@ -324,9 +247,8 @@ JNIEXPORT jobjectArray JNICALL Java_org_simgrid_msg_Host_all(JNIEnv * env, jclas JNIEXPORT void JNICALL Java_org_simgrid_msg_Host_setAsyncMailbox(JNIEnv * env, jclass cls_arg, jobject jname) { - const char* name = env->GetStringUTFChars((jstring)jname, nullptr); + jstring_wrapper name(env, (jstring)jname); sg_mailbox_set_receiver(name); - env->ReleaseStringUTFChars((jstring) jname, name); } JNIEXPORT void JNICALL Java_org_simgrid_msg_Host_updateAllEnergyConsumptions(JNIEnv* env, jclass cls) @@ -364,7 +286,7 @@ JNIEXPORT jint JNICALL Java_org_simgrid_msg_Host_getPstatesCount(JNIEnv* env, jo JNIEXPORT jdouble JNICALL Java_org_simgrid_msg_Host_getCurrentPowerPeak(JNIEnv* env, jobject jhost) { const_sg_host_t host = jhost_get_native(env, jhost); - return sg_host_speed(host); + return sg_host_get_speed(host); } JNIEXPORT jdouble JNICALL Java_org_simgrid_msg_Host_getPowerPeakAt(JNIEnv* env, jobject jhost, jint pstate) { @@ -375,7 +297,7 @@ JNIEXPORT jdouble JNICALL Java_org_simgrid_msg_Host_getPowerPeakAt(JNIEnv* env, JNIEXPORT jdouble JNICALL Java_org_simgrid_msg_Host_getLoad(JNIEnv* env, jobject jhost) { const_sg_host_t host = jhost_get_native(env, jhost); - return sg_host_load(host); + return sg_host_get_load(host); } JNIEXPORT jdouble JNICALL Java_org_simgrid_msg_Host_getCurrentLoad (JNIEnv *env, jobject jhost)