#include "jmsg_process.h"
-#include "jmsg.h"
-#include "jmsg_host.h"
-#include "jxbt_utilities.h"
#include "JavaContext.hpp"
+#include "jmsg.hpp"
+#include "jmsg_host.h"
+#include "jxbt_utilities.hpp"
XBT_LOG_EXTERNAL_DEFAULT_CATEGORY(java);
-SG_BEGIN_DECL()
+extern "C" {
jfieldID jprocess_field_Process_bind;
jfieldID jprocess_field_Process_host;
env->SetIntField(jprocess, jprocess_field_Process_ppid, (jint) MSG_process_get_PPID(process));
}
-JNIEXPORT jint JNICALL Java_org_simgrid_msg_Process_killAll(JNIEnv * env, jclass cls, jint jresetPID)
+JNIEXPORT void JNICALL Java_org_simgrid_msg_Process_daemonize(JNIEnv* env, jobject jprocess)
+{
+ msg_process_t process = jprocess_to_native(jprocess, env);
+
+ if (not process) {
+ jxbt_throw_notbound(env, "process", jprocess);
+ return;
+ }
+
+ MSG_process_daemonize(process);
+}
+
+JNIEXPORT jint JNICALL Java_org_simgrid_msg_Process_killAll(JNIEnv* env, jclass cls)
{
- return (jint) MSG_process_killall((int) jresetPID);
+ return (jint)MSG_process_killall();
}
JNIEXPORT jobject JNICALL Java_org_simgrid_msg_Process_fromPID(JNIEnv * env, jclass cls, jint pid)
msg_process_t process = MSG_process_from_PID(pid);
if (not process) {
- jxbt_throw_process_not_found(env, bprintf("PID = %d",static_cast<int>(pid)));
+ jxbt_throw_process_not_found(env, std::string("PID = ") + std::to_string(static_cast<int>(pid)));
return nullptr;
}
return jprocess;
}
+JNIEXPORT jint JNICALL Java_org_simgrid_msg_Process_nativeGetPID(JNIEnv* env, jobject jprocess)
+{
+ msg_process_t process = jprocess_to_native(jprocess, env);
+ return MSG_process_get_PID(process);
+}
+
JNIEXPORT jobject JNICALL Java_org_simgrid_msg_Process_getProperty(JNIEnv *env, jobject jprocess, jobject jname) {
msg_process_t process = jprocess_to_native(jprocess, env);
/* try to suspend the process */
msg_error_t rv = MSG_process_suspend(process);
- jxbt_check_res("MSG_process_suspend()", rv, MSG_OK, bprintf("unexpected error , please report this bug"));
+ jxbt_check_res("MSG_process_suspend()", rv, MSG_OK, "unexpected error , please report this bug");
}
JNIEXPORT void JNICALL Java_org_simgrid_msg_Process_resume(JNIEnv * env, jobject jprocess)
/* try to resume the process */
msg_error_t res = MSG_process_resume(process);
- jxbt_check_res("MSG_process_resume()", res, MSG_OK, bprintf("unexpected error , please report this bug"));
+ jxbt_check_res("MSG_process_resume()", res, MSG_OK, "unexpected error , please report this bug");
}
JNIEXPORT void
return;
}
- MSG_process_auto_restart_set(process, (jauto_restart == JNI_TRUE));
+ process->setAutoRestart(jauto_restart == JNI_TRUE);
}
JNIEXPORT void JNICALL Java_org_simgrid_msg_Process_restart (JNIEnv *env, jobject jprocess) {
msg_process_t process = jprocess_to_native(jprocess, env);
- xbt_ex_t e;
if (not process) {
jxbt_throw_notbound(env, "process", jprocess);
if (rv != MSG_OK) {
XBT_DEBUG("Something during the MSG_process_sleep invocation was wrong, trigger a HostFailureException");
- //jmsg_throw_status(env,rv);
-
- // adsein, the code above as been replaced by the code below. Indeed, according to the documentation, a sleep can only
- // trigger a host_failure exception. When the sleep crashes due to a host shutdown, the exception thrown by smx_context_java.c
- // 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, "");
}
}
JNIEXPORT jint JNICALL Java_org_simgrid_msg_Process_getCount(JNIEnv * env, jclass cls) {
return (jint) MSG_process_get_number();
}
-
-SG_END_DECL()
+}