X-Git-Url: http://info.iut-bm.univ-fcomte.fr/pub/gitweb/simgrid.git/blobdiff_plain/ef33b9c0c2c0e9c15c27fce82515a23e8aadc0ed..d442cebf6863fc131f3fcf453039a70e6b014d11:/src/bindings/java/jmsg_host.cpp diff --git a/src/bindings/java/jmsg_host.cpp b/src/bindings/java/jmsg_host.cpp index aa84bd2837..8211551449 100644 --- a/src/bindings/java/jmsg_host.cpp +++ b/src/bindings/java/jmsg_host.cpp @@ -6,16 +6,25 @@ /* 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 +#include +#include +#include + +#include + +#include + #include "simgrid/msg.h" #include "jmsg.h" #include "jmsg_host.h" #include "jxbt_utilities.h" #include "jmsg_storage.h" -#include XBT_LOG_EXTERNAL_DEFAULT_CATEGORY(jmsg); +SG_BEGIN_DECL() + static jmethodID jhost_method_Host_constructor; static jfieldID jhost_field_Host_bind; static jfieldID jhost_field_Host_name; @@ -43,7 +52,7 @@ msg_host_t jhost_get_native(JNIEnv * env, jobject jhost) { const char *jhost_get_name(jobject jhost, JNIEnv * env) { msg_host_t host = jhost_get_native(env, jhost); - return MSG_host_get_name(host); + return host->cname(); } jboolean jhost_is_valid(jobject jhost, JNIEnv * env) { @@ -59,38 +68,35 @@ JNIEXPORT void JNICALL Java_org_simgrid_msg_Host_nativeInit(JNIEnv *env, jclass jhost_method_Host_constructor = env->GetMethodID(class_Host, "", "()V"); jhost_field_Host_bind = jxbt_get_jfield(env,class_Host, "bind", "J"); jhost_field_Host_name = jxbt_get_jfield(env, class_Host, "name", "Ljava/lang/String;"); - if (!class_Host || !jhost_field_Host_name || !jhost_method_Host_constructor || !jhost_field_Host_bind) { - jxbt_throw_native(env,bprintf("Can't find some fields in Java class. You should report this bug.")); - } + xbt_assert(class_Host && jhost_field_Host_name && jhost_method_Host_constructor && jhost_field_Host_bind, + "Native initialization of msg/Host failed. Please report that bug"); } JNIEXPORT jobject JNICALL Java_org_simgrid_msg_Host_getByName(JNIEnv * env, jclass cls, jstring jname) { - msg_host_t host; /* native host */ - jobject jhost; /* global reference to the java host instance returned */ /* get the C string from the java string */ - if (jname == NULL) { + if (jname == nullptr) { jxbt_throw_null(env,bprintf("No host can have a null name")); - return NULL; + return nullptr; } const char *name = env->GetStringUTFChars(jname, 0); /* get the host by name (the hosts are created during the grid resolution) */ - host = MSG_host_by_name(name); + msg_host_t host = MSG_host_by_name(name); if (!host) { /* invalid name */ jxbt_throw_host_not_found(env, name); env->ReleaseStringUTFChars(jname, name); - return NULL; + return nullptr; } env->ReleaseStringUTFChars(jname, name); if (!host->extension(JAVA_HOST_LEVEL)) { /* native host not associated yet with java host */ /* Instantiate a new java host */ - jhost = jhost_new_instance(env); + jobject jhost = jhost_new_instance(env); if (!jhost) { jxbt_throw_jni(env, "java host instantiation failed"); - return NULL; + return nullptr; } /* get a global reference to the newly created host */ @@ -98,7 +104,7 @@ JNIEXPORT jobject JNICALL Java_org_simgrid_msg_Host_getByName(JNIEnv * env, jcla if (!jhost) { jxbt_throw_jni(env, "new global ref allocation failed"); - return NULL; + return nullptr; } /* Sets the java host name */ env->SetObjectField(jhost, jhost_field_Host_name, jname); @@ -126,7 +132,7 @@ JNIEXPORT jobject JNICALL Java_org_simgrid_msg_Host_currentHost(JNIEnv * env, jc if (!jhost) { jxbt_throw_jni(env, "java host instantiation failed"); - return NULL; + return nullptr; } /* get a global reference to the newly created host */ @@ -134,11 +140,10 @@ JNIEXPORT jobject JNICALL Java_org_simgrid_msg_Host_currentHost(JNIEnv * env, jc if (!jhost) { jxbt_throw_jni(env, "global ref allocation failed"); - return NULL; + return nullptr; } /* Sets the host name */ - const char *name = MSG_host_get_name(host); - jobject jname = env->NewStringUTF(name); + jobject jname = env->NewStringUTF(host->cname()); env->SetObjectField(jhost, jhost_field_Host_name, jname); /* Bind & store it */ jhost_bind(jhost, host, env); @@ -194,13 +199,13 @@ JNIEXPORT jobject JNICALL Java_org_simgrid_msg_Host_getProperty(JNIEnv *env, job if (!host) { jxbt_throw_notbound(env, "host", jhost); - return NULL; + return nullptr; } const char *name = env->GetStringUTFChars((jstring) jname, 0); const char *property = MSG_host_get_property_value(host, name); if (!property) { - return NULL; + return nullptr; } jobject jproperty = env->NewStringUTF(property); @@ -222,7 +227,7 @@ Java_org_simgrid_msg_Host_setProperty(JNIEnv *env, jobject jhost, jobject jname, const char *value_java = env->GetStringUTFChars((jstring) jvalue, 0); char *value = xbt_strdup(value_java); - MSG_host_set_property_value(host, name, value, xbt_free_f); + MSG_host_set_property_value(host, name, value); env->ReleaseStringUTFChars((jstring) jvalue, value_java); env->ReleaseStringUTFChars((jstring) jname, name); @@ -257,15 +262,16 @@ JNIEXPORT jobjectArray JNICALL Java_org_simgrid_msg_Host_getMountedStorage(JNIEn int count = xbt_dict_length(dict); jclass cls = env->FindClass("org/simgrid/msg/Storage"); - jtable = env->NewObjectArray((jsize) count, cls, NULL); + jtable = env->NewObjectArray((jsize) count, cls, nullptr); if (!jtable) { jxbt_throw_jni(env, "Storages table allocation failed"); - return NULL; + return nullptr; } - xbt_dict_cursor_t cursor=NULL; - const char *mount_name, *storage_name; + xbt_dict_cursor_t cursor=nullptr; + const char* mount_name; + const char* storage_name; xbt_dict_foreach(dict,cursor,mount_name,storage_name) { jname = env->NewStringUTF(storage_name); @@ -290,7 +296,7 @@ JNIEXPORT jobjectArray JNICALL Java_org_simgrid_msg_Host_getAttachedStorage(JNIE xbt_dynar_t dyn = MSG_host_get_attached_storage_list(host); int count = xbt_dynar_length(dyn); jclass cls = jxbt_get_class(env, "java/lang/String"); - jtable = env->NewObjectArray((jsize) count, cls, NULL); + jtable = env->NewObjectArray((jsize) count, cls, nullptr); int index; char *storage_name; jstring jstorage_name; @@ -328,14 +334,14 @@ JNIEXPORT jobjectArray JNICALL Java_org_simgrid_msg_Host_all(JNIEnv * env, jclas 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((jsize) count, cls, nullptr); if (!jtable) { jxbt_throw_jni(env, "Hosts table allocation failed"); - return NULL; + return nullptr; } for (index = 0; index < count; index++) { @@ -343,7 +349,7 @@ JNIEXPORT jobjectArray JNICALL Java_org_simgrid_msg_Host_all(JNIEnv * env, jclas jhost = (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_arg, jname); /* FIXME: leak of jname ? */ @@ -374,3 +380,31 @@ JNIEXPORT jdouble JNICALL Java_org_simgrid_msg_Host_getConsumedEnergy (JNIEnv *e return MSG_host_get_consumed_energy(host); } + +JNIEXPORT void JNICALL Java_org_simgrid_msg_Host_setPstate(JNIEnv* env, jobject jhost, jint pstate) +{ + msg_host_t host = jhost_get_native(env, jhost); + MSG_host_set_pstate(host, pstate); +} +JNIEXPORT jint JNICALL Java_org_simgrid_msg_Host_getPstate(JNIEnv* env, jobject jhost) +{ + msg_host_t host = jhost_get_native(env, jhost); + return MSG_host_get_pstate(host); +} +JNIEXPORT jint JNICALL Java_org_simgrid_msg_Host_getPstatesCount(JNIEnv* env, jobject jhost) +{ + msg_host_t host = jhost_get_native(env, jhost); + return MSG_host_get_nb_pstates(host); +} +JNIEXPORT jdouble JNICALL Java_org_simgrid_msg_Host_getCurrentPowerPeak(JNIEnv* env, jobject jhost) +{ + msg_host_t host = jhost_get_native(env, jhost); + return MSG_host_get_current_power_peak(host); +} +JNIEXPORT jdouble JNICALL Java_org_simgrid_msg_Host_getPowerPeakAt(JNIEnv* env, jobject jhost, jint pstate) +{ + msg_host_t host = jhost_get_native(env, jhost); + return MSG_host_get_power_peak_at(host, pstate); +} + +SG_END_DECL()