X-Git-Url: http://info.iut-bm.univ-fcomte.fr/pub/gitweb/simgrid.git/blobdiff_plain/0bac7d0f735ac8ba47a46e1db4f6d7a7164fe0f2..16bbb8a8212497d9c44c81333ed2c0e689e0c5af:/src/bindings/java/jmsg_host.cpp diff --git a/src/bindings/java/jmsg_host.cpp b/src/bindings/java/jmsg_host.cpp index 5e1019aa38..1d6e2400b7 100644 --- a/src/bindings/java/jmsg_host.cpp +++ b/src/bindings/java/jmsg_host.cpp @@ -72,8 +72,8 @@ Java_org_simgrid_msg_Host_getByName(JNIEnv * env, jclass cls, /* get the C string from the java string */ if (jname == NULL) { - jxbt_throw_null(env,bprintf("No host can have a null name")); - return NULL; + jxbt_throw_null(env,bprintf("No host can have a null name")); + return NULL; } const char *name = env->GetStringUTFChars(jname, 0); /* get the host by name (the hosts are created during the grid resolution) */ @@ -86,7 +86,7 @@ Java_org_simgrid_msg_Host_getByName(JNIEnv * env, jclass cls, } env->ReleaseStringUTFChars(jname, name); - if (!host->facet(JAVA_HOST_LEVEL)) { /* native host not associated yet with java host */ + if (!host->extension(JAVA_HOST_LEVEL)) { /* native host not associated yet with java host */ /* Instantiate a new java host */ jhost = jhost_new_instance(env); @@ -111,11 +111,11 @@ Java_org_simgrid_msg_Host_getByName(JNIEnv * env, jclass cls, /* the native host data field is set with the global reference to the * java host returned by this function */ - host->set_facet(JAVA_HOST_LEVEL, (void *)jhost); + host->extension_set(JAVA_HOST_LEVEL, (void *)jhost); } /* return the global reference to the java host instance */ - return (jobject) host->facet(JAVA_HOST_LEVEL); + return (jobject) host->extension(JAVA_HOST_LEVEL); } JNIEXPORT jobject JNICALL @@ -124,7 +124,7 @@ Java_org_simgrid_msg_Host_currentHost(JNIEnv * env, jclass cls) { msg_host_t host = MSG_host_self(); - if (!host->facet(JAVA_HOST_LEVEL)) { + if (!host->extension(JAVA_HOST_LEVEL)) { /* the native host not yet associated with the java host instance */ /* instanciate a new java host instance */ @@ -148,9 +148,9 @@ Java_org_simgrid_msg_Host_currentHost(JNIEnv * env, jclass cls) { env->SetObjectField(jhost, jhost_field_Host_name, jname); /* Bind & store it */ jhost_bind(jhost, host, env); - host->set_facet(JAVA_HOST_LEVEL, (void *) jhost); + host->extension_set(JAVA_HOST_LEVEL, (void *) jhost); } else { - jhost = (jobject) host->facet(JAVA_HOST_LEVEL); + jhost = (jobject) host->extension(JAVA_HOST_LEVEL); } return jhost; @@ -202,17 +202,6 @@ Java_org_simgrid_msg_Host_getCoreNumber(JNIEnv * env, return (jdouble) MSG_host_get_core_number(host); } -JNIEXPORT jint JNICALL -Java_org_simgrid_msg_Host_getLoad(JNIEnv * env, jobject jhost) { - msg_host_t host = jhost_get_native(env, jhost); - - if (!host) { - jxbt_throw_notbound(env, "host", jhost); - return -1; - } - - return (jint) MSG_get_host_msgload(host); -} JNIEXPORT jobject JNICALL Java_org_simgrid_msg_Host_getProperty(JNIEnv *env, jobject jhost, jobject jname) { msg_host_t host = jhost_get_native(env, jhost); @@ -278,29 +267,29 @@ Java_org_simgrid_msg_Host_getMountedStorage(JNIEnv * env, jobject jhost){ } int index = 0; - jobjectArray jtable; - xbt_dict_t dict = MSG_host_get_mounted_storage_list(host); - int count = xbt_dict_length(dict); - jclass cls = env->FindClass("org/simgrid/msg/Storage"); + jobjectArray jtable; + xbt_dict_t dict = MSG_host_get_mounted_storage_list(host); + 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, NULL); - if (!jtable) { - jxbt_throw_jni(env, "Storages table allocation failed"); - return NULL; - } + if (!jtable) { + jxbt_throw_jni(env, "Storages table allocation failed"); + return NULL; + } - xbt_dict_cursor_t cursor=NULL; - const char *mount_name, *storage_name; + xbt_dict_cursor_t cursor=NULL; + const char *mount_name, *storage_name; - xbt_dict_foreach(dict,cursor,mount_name,storage_name) { - jname = env->NewStringUTF(storage_name); - jstorage = Java_org_simgrid_msg_Storage_getByName(env,cls,jname); - env->SetObjectArrayElement(jtable, index, jstorage); + xbt_dict_foreach(dict,cursor,mount_name,storage_name) { + jname = env->NewStringUTF(storage_name); + jstorage = Java_org_simgrid_msg_Storage_getByName(env,cls,jname); + env->SetObjectArrayElement(jtable, index, jstorage); index++; - } - xbt_dict_free(&dict); - return jtable; + } + xbt_dict_free(&dict); + return jtable; } JNIEXPORT jobjectArray JNICALL @@ -368,13 +357,13 @@ Java_org_simgrid_msg_Host_all(JNIEnv * env, jclass cls_arg) for (index = 0; index < count; index++) { host = xbt_dynar_get_as(table,index,msg_host_t); - jhost = (jobject) host->facet(JAVA_HOST_LEVEL); + jhost = (jobject) host->extension(JAVA_HOST_LEVEL); if (!jhost) { jname = env->NewStringUTF(MSG_host_get_name(host)); jhost = - Java_org_simgrid_msg_Host_getByName(env, cls_arg, jname); + Java_org_simgrid_msg_Host_getByName(env, cls_arg, jname); /* FIXME: leak of jname ? */ } @@ -392,3 +381,17 @@ Java_org_simgrid_msg_Host_setAsyncMailbox(JNIEnv * env, jclass cls_arg, jobject env->ReleaseStringUTFChars((jstring) jname, name); } + +#include "simgrid/plugins/energy.h" +JNIEXPORT jdouble JNICALL Java_org_simgrid_msg_Host_getConsumedEnergy (JNIEnv *env, jobject jhost) { + msg_host_t host = jhost_get_native(env, jhost); + + if (!host) { + jxbt_throw_notbound(env, "host", jhost); + return 0; + } + + return MSG_host_get_consumed_energy(host); + +} +