X-Git-Url: http://info.iut-bm.univ-fcomte.fr/pub/gitweb/simgrid.git/blobdiff_plain/4a6b0a991a67e6f2f67c03fed43529e078da7115..7b138f8b1ed3e8816eda5cb26deb71fe81b4087a:/src/bindings/java/jmsg_host.cpp diff --git a/src/bindings/java/jmsg_host.cpp b/src/bindings/java/jmsg_host.cpp index dba26b2996..0dc3098e6f 100644 --- a/src/bindings/java/jmsg_host.cpp +++ b/src/bindings/java/jmsg_host.cpp @@ -54,8 +54,7 @@ jboolean jhost_is_valid(jobject jhost, JNIEnv * env) { } } -JNIEXPORT void JNICALL -Java_org_simgrid_msg_Host_nativeInit(JNIEnv *env, jclass cls) { +JNIEXPORT void JNICALL Java_org_simgrid_msg_Host_nativeInit(JNIEnv *env, jclass cls) { jclass class_Host = env->FindClass("org/simgrid/msg/Host"); jhost_method_Host_constructor = env->GetMethodID(class_Host, "", "()V"); jhost_field_Host_bind = jxbt_get_jfield(env,class_Host, "bind", "J"); @@ -64,16 +63,15 @@ Java_org_simgrid_msg_Host_nativeInit(JNIEnv *env, jclass cls) { jxbt_throw_native(env,bprintf("Can't find some fields in Java class. You should report this bug.")); } } -JNIEXPORT jobject JNICALL -Java_org_simgrid_msg_Host_getByName(JNIEnv * env, jclass cls, - jstring jname) { + +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) */ @@ -82,18 +80,17 @@ Java_org_simgrid_msg_Host_getByName(JNIEnv * env, jclass cls, 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); if (!jhost) { jxbt_throw_jni(env, "java host instantiation failed"); - return NULL; + return nullptr; } /* get a global reference to the newly created host */ @@ -101,16 +98,14 @@ Java_org_simgrid_msg_Host_getByName(JNIEnv * env, jclass cls, 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); /* bind the java host and the native host */ jhost_bind(jhost, host, env); - /* the native host data field is set with the global reference to the - * java host returned by this function - */ + /* 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); } @@ -118,8 +113,7 @@ Java_org_simgrid_msg_Host_getByName(JNIEnv * env, jclass cls, return (jobject) host->extension(JAVA_HOST_LEVEL); } -JNIEXPORT jobject JNICALL -Java_org_simgrid_msg_Host_currentHost(JNIEnv * env, jclass cls) { +JNIEXPORT jobject JNICALL Java_org_simgrid_msg_Host_currentHost(JNIEnv * env, jclass cls) { jobject jhost; msg_host_t host = MSG_host_self(); @@ -132,7 +126,7 @@ Java_org_simgrid_msg_Host_currentHost(JNIEnv * env, jclass cls) { if (!jhost) { jxbt_throw_jni(env, "java host instantiation failed"); - return NULL; + return nullptr; } /* get a global reference to the newly created host */ @@ -140,7 +134,7 @@ Java_org_simgrid_msg_Host_currentHost(JNIEnv * env, jclass cls) { 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); @@ -156,29 +150,24 @@ Java_org_simgrid_msg_Host_currentHost(JNIEnv * env, jclass cls) { return jhost; } -JNIEXPORT void JNICALL -Java_org_simgrid_msg_Host_on(JNIEnv *env, jobject jhost) { +JNIEXPORT void JNICALL Java_org_simgrid_msg_Host_on(JNIEnv *env, jobject jhost) { msg_host_t host = jhost_get_native(env, jhost); MSG_host_on(host); } -JNIEXPORT void JNICALL -Java_org_simgrid_msg_Host_off(JNIEnv *env, jobject jhost) { +JNIEXPORT void JNICALL Java_org_simgrid_msg_Host_off(JNIEnv *env, jobject jhost) { msg_host_t host = jhost_get_native(env, jhost); MSG_host_off(host); } -JNIEXPORT jint JNICALL -Java_org_simgrid_msg_Host_getCount(JNIEnv * env, jclass cls) { +JNIEXPORT jint JNICALL Java_org_simgrid_msg_Host_getCount(JNIEnv * env, jclass cls) { xbt_dynar_t hosts = MSG_hosts_as_dynar(); int nb_host = xbt_dynar_length(hosts); xbt_dynar_free(&hosts); return (jint) nb_host; } -JNIEXPORT jdouble JNICALL -Java_org_simgrid_msg_Host_getSpeed(JNIEnv * env, - jobject jhost) { +JNIEXPORT jdouble JNICALL Java_org_simgrid_msg_Host_getSpeed(JNIEnv * env, jobject jhost) { msg_host_t host = jhost_get_native(env, jhost); if (!host) { @@ -186,12 +175,10 @@ Java_org_simgrid_msg_Host_getSpeed(JNIEnv * env, return -1; } - return (jdouble) MSG_get_host_speed(host); + return (jdouble) MSG_host_get_speed(host); } -JNIEXPORT jdouble JNICALL -Java_org_simgrid_msg_Host_getCoreNumber(JNIEnv * env, - jobject jhost) { +JNIEXPORT jdouble JNICALL Java_org_simgrid_msg_Host_getCoreNumber(JNIEnv * env, jobject jhost) { msg_host_t host = jhost_get_native(env, jhost); if (!host) { @@ -202,19 +189,18 @@ Java_org_simgrid_msg_Host_getCoreNumber(JNIEnv * env, return (jdouble) MSG_host_get_core_number(host); } -JNIEXPORT jobject JNICALL -Java_org_simgrid_msg_Host_getProperty(JNIEnv *env, jobject jhost, jobject jname) { +JNIEXPORT jobject JNICALL Java_org_simgrid_msg_Host_getProperty(JNIEnv *env, jobject jhost, jobject jname) { msg_host_t host = jhost_get_native(env, jhost); 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); @@ -240,10 +226,10 @@ Java_org_simgrid_msg_Host_setProperty(JNIEnv *env, jobject jhost, jobject jname, env->ReleaseStringUTFChars((jstring) jvalue, value_java); env->ReleaseStringUTFChars((jstring) jname, name); - } -JNIEXPORT jboolean JNICALL -Java_org_simgrid_msg_Host_isOn(JNIEnv * env, jobject jhost) { + +JNIEXPORT jboolean JNICALL Java_org_simgrid_msg_Host_isOn(JNIEnv * env, jobject jhost) +{ msg_host_t host = jhost_get_native(env, jhost); if (!host) { @@ -254,9 +240,8 @@ Java_org_simgrid_msg_Host_isOn(JNIEnv * env, jobject jhost) { return (jboolean) MSG_host_is_on(host); } -JNIEXPORT jobjectArray JNICALL -Java_org_simgrid_msg_Host_getMountedStorage(JNIEnv * env, jobject jhost){ - +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; @@ -272,15 +257,16 @@ Java_org_simgrid_msg_Host_getMountedStorage(JNIEnv * env, jobject jhost){ 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); @@ -292,8 +278,8 @@ Java_org_simgrid_msg_Host_getMountedStorage(JNIEnv * env, jobject jhost){ return jtable; } -JNIEXPORT jobjectArray JNICALL -Java_org_simgrid_msg_Host_getAttachedStorage(JNIEnv * env, jobject jhost){ +JNIEXPORT jobjectArray JNICALL Java_org_simgrid_msg_Host_getAttachedStorage(JNIEnv * env, jobject jhost) +{ msg_host_t host = jhost_get_native(env, jhost); if (!host) { @@ -305,7 +291,7 @@ Java_org_simgrid_msg_Host_getAttachedStorage(JNIEnv * env, jobject jhost){ 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; @@ -318,8 +304,8 @@ Java_org_simgrid_msg_Host_getAttachedStorage(JNIEnv * env, jobject jhost){ return jtable; } -JNIEXPORT jobjectArray JNICALL -Java_org_simgrid_msg_Host_getStorageContent(JNIEnv * env, jobject jhost){ +JNIEXPORT jobjectArray JNICALL Java_org_simgrid_msg_Host_getStorageContent(JNIEnv * env, jobject jhost) +{ msg_host_t host = jhost_get_native(env, jhost); if (!host) { @@ -329,9 +315,7 @@ Java_org_simgrid_msg_Host_getStorageContent(JNIEnv * env, jobject jhost){ return (jobjectArray)MSG_host_get_storage_content(host); } - -JNIEXPORT jobjectArray JNICALL -Java_org_simgrid_msg_Host_all(JNIEnv * env, jclass cls_arg) +JNIEXPORT jobjectArray JNICALL Java_org_simgrid_msg_Host_all(JNIEnv * env, jclass cls_arg) { int index; jobjectArray jtable; @@ -345,14 +329,14 @@ Java_org_simgrid_msg_Host_all(JNIEnv * env, jclass cls_arg) 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++) { @@ -362,8 +346,7 @@ Java_org_simgrid_msg_Host_all(JNIEnv * env, jclass cls_arg) if (!jhost) { jname = env->NewStringUTF(MSG_host_get_name(host)); - jhost = - Java_org_simgrid_msg_Host_getByName(env, cls_arg, jname); + jhost = Java_org_simgrid_msg_Host_getByName(env, cls_arg, jname); /* FIXME: leak of jname ? */ } @@ -373,17 +356,16 @@ Java_org_simgrid_msg_Host_all(JNIEnv * env, jclass cls_arg) return jtable; } -JNIEXPORT void JNICALL -Java_org_simgrid_msg_Host_setAsyncMailbox(JNIEnv * env, jclass cls_arg, jobject jname){ - +JNIEXPORT void JNICALL Java_org_simgrid_msg_Host_setAsyncMailbox(JNIEnv * env, jclass cls_arg, jobject jname) +{ const char *name = env->GetStringUTFChars((jstring) jname, 0); MSG_mailbox_set_async(name); env->ReleaseStringUTFChars((jstring) jname, name); - } #include "simgrid/plugins/energy.h" -JNIEXPORT jdouble JNICALL Java_org_simgrid_msg_Host_getConsumedEnergy (JNIEnv *env, jobject jhost) { +JNIEXPORT jdouble JNICALL Java_org_simgrid_msg_Host_getConsumedEnergy (JNIEnv *env, jobject jhost) +{ msg_host_t host = jhost_get_native(env, jhost); if (!host) { @@ -392,6 +374,4 @@ JNIEXPORT jdouble JNICALL Java_org_simgrid_msg_Host_getConsumedEnergy (JNIEnv *e } return MSG_host_get_consumed_energy(host); - } -