X-Git-Url: http://info.iut-bm.univ-fcomte.fr/pub/gitweb/simgrid.git/blobdiff_plain/7410b72db09489e8b9d3ee3cb087f35882397d93..5e1b4fa835cedc144a2ebe97fda0d139d63d3058:/src/bindings/java/jmsg_process.cpp diff --git a/src/bindings/java/jmsg_process.cpp b/src/bindings/java/jmsg_process.cpp index b43ff09f54..6ec0684663 100644 --- a/src/bindings/java/jmsg_process.cpp +++ b/src/bindings/java/jmsg_process.cpp @@ -6,6 +6,8 @@ /* 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 + #include "jmsg_process.h" #include "jmsg.h" @@ -25,14 +27,9 @@ jfieldID jprocess_field_Process_name; jfieldID jprocess_field_Process_pid; jfieldID jprocess_field_Process_ppid; -JNIEXPORT void JNICALL -Java_org_simgrid_msg_Process_exit(JNIEnv *env, jobject jprocess) { - -} - jobject native_to_java_process(msg_process_t process) { - simgrid::java::JavaContext* context = (simgrid::java::JavaContext*) MSG_process_get_smx_ctx(process); + simgrid::kernel::context::JavaContext* context = (simgrid::kernel::context::JavaContext*) MSG_process_get_smx_ctx(process); return context->jprocess; } @@ -49,8 +46,8 @@ void jprocess_delete_global_ref(jobject jprocess, JNIEnv * env) void jprocess_join(jobject jprocess, JNIEnv * env) { msg_process_t process = jprocess_to_native_process(jprocess,env); - simgrid::java::JavaContext* context = (simgrid::java::JavaContext*) MSG_process_get_smx_ctx(process); - xbt_os_thread_join(context->thread,NULL); + simgrid::kernel::context::JavaContext* context = (simgrid::kernel::context::JavaContext*) MSG_process_get_smx_ctx(process); + xbt_os_thread_join(context->thread,nullptr); } msg_process_t jprocess_to_native_process(jobject jprocess, JNIEnv * env) @@ -115,7 +112,7 @@ JNIEXPORT void JNICALL Java_org_simgrid_msg_Process_create(JNIEnv * env, jobject jname = jprocess_get_name(jprocess_arg, env); if (!jname) { jxbt_throw_null(env, - xbt_strdup("Internal error: Process name cannot be NULL")); + xbt_strdup("Internal error: Process name cannot be nullptr")); return; } @@ -142,16 +139,16 @@ JNIEXPORT void JNICALL Java_org_simgrid_msg_Process_create(JNIEnv * env, jobject jdouble jkill = env->GetDoubleField(jprocess, jprocess_field_Process_killTime); /* Actually build the MSG process */ process = MSG_process_create_with_environment(name, [](int argc, char** argv) -> int { - smx_process_t process = SIMIX_process_self(); + smx_actor_t process = SIMIX_process_self(); // This is the jprocess passed as environment. // It would be simplet if we could use a closure. jobject jprocess = (jobject) MSG_process_get_data(process); - simgrid::java::java_main_jprocess(jprocess); + simgrid::kernel::context::java_main_jprocess(jprocess); return 0; }, jprocess, host, /*argc, argv, properties*/ - 0, NULL, NULL); + 0, nullptr, nullptr); MSG_process_set_kill_time(process, (double)jkill); /* bind the java process instance to the native process */ jprocess_bind(jprocess, process, env); @@ -165,7 +162,7 @@ JNIEXPORT void JNICALL Java_org_simgrid_msg_Process_create(JNIEnv * env, jobject env->SetIntField(jprocess, jprocess_field_Process_pid,(jint) MSG_process_get_PID(process)); env->SetIntField(jprocess, jprocess_field_Process_ppid, (jint) MSG_process_get_PPID(process)); /* sets the Host of the process */ - jobject jhost = Java_org_simgrid_msg_Host_getByName(env,NULL, (jstring)jhostname); + jobject jhost = Java_org_simgrid_msg_Host_getByName(env,nullptr, (jstring)jhostname); env->SetObjectField(jprocess, jprocess_field_Process_host, jhost); } @@ -181,14 +178,14 @@ JNIEXPORT jobject JNICALL Java_org_simgrid_msg_Process_fromPID(JNIEnv * env, jcl if (!process) { jxbt_throw_process_not_found(env, bprintf("PID = %d",(int) PID)); - return NULL; + return nullptr; } jobject jprocess = native_to_java_process(process); if (!jprocess) { jxbt_throw_jni(env, "get process failed"); - return NULL; + return nullptr; } return jprocess; @@ -199,13 +196,13 @@ JNIEXPORT jobject JNICALL Java_org_simgrid_msg_Process_getProperty(JNIEnv *env, if (!process) { jxbt_throw_notbound(env, "process", jprocess); - return NULL; + return nullptr; } const char *name = env->GetStringUTFChars((jstring)jname, 0); const char *property = MSG_process_get_property_value(process, name); if (!property) { - return NULL; + return nullptr; } jobject jproperty = env->NewStringUTF(property); @@ -222,7 +219,7 @@ JNIEXPORT jobject JNICALL Java_org_simgrid_msg_Process_getCurrentProcess(JNIEnv if (!process) { jxbt_throw_jni(env, xbt_strdup("MSG_process_self() failed")); - return NULL; + return nullptr; } jprocess = native_to_java_process(process); @@ -274,11 +271,11 @@ JNICALL Java_org_simgrid_msg_Process_setAutoRestart (JNIEnv *env, jobject jproce return; } - TRY { + try { MSG_process_auto_restart_set(process,auto_restart); } - CATCH (e) { - xbt_ex_free(e); + catch (xbt_ex& e) { + // Nothing to do } } @@ -291,11 +288,11 @@ JNIEXPORT void JNICALL Java_org_simgrid_msg_Process_restart (JNIEnv *env, jobjec return; } - TRY { + try { MSG_process_restart(process); } - CATCH (e) { - xbt_ex_free(e); + catch (xbt_ex& e) { + // Nothing to do } } @@ -327,7 +324,7 @@ JNIEXPORT void JNICALL Java_org_simgrid_msg_Process_sleep(JNIEnv *env, jclass cl // is a cancelled_error, see bindings/java/smx_context_java.c, function void smx_ctx_java_stop(smx_context_t context) and src/msg/msg_gos.c // function msg_error_t MSG_process_sleep(double nb_sec) - jxbt_throw_host_failure(env,NULL); + jxbt_throw_host_failure(env,nullptr); } } @@ -352,7 +349,11 @@ JNIEXPORT void JNICALL Java_org_simgrid_msg_Process_kill(JNIEnv * env, jobject j return; } - MSG_process_kill(process); + try { + MSG_process_kill(process); + } catch (xbt_ex& ex) { + XBT_VERB("This process just killed itself."); + } } JNIEXPORT void JNICALL Java_org_simgrid_msg_Process_migrate(JNIEnv * env, jobject jprocess, jobject jhost) @@ -390,4 +391,4 @@ JNIEXPORT jint JNICALL Java_org_simgrid_msg_Process_getCount(JNIEnv * env, jclas return (jint) MSG_process_get_number(); } -} +} // extern C