Logo AND Algorithmique Numérique Distribuée

Public GIT Repository
add Process.daemonize to the Java bindings
[simgrid.git] / src / bindings / java / jmsg_process.cpp
index 000d1d4..1d4b58e 100644 (file)
@@ -9,14 +9,14 @@
 
 #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;
@@ -91,6 +91,18 @@ JNIEXPORT void JNICALL Java_org_simgrid_msg_Process_create(JNIEnv* env, jobject
   env->SetIntField(jprocess, jprocess_field_Process_ppid, (jint) MSG_process_get_PPID(process));
 }
 
+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, jint jresetPID)
 {
   return (jint) MSG_process_killall((int) jresetPID);
@@ -217,13 +229,6 @@ JNIEXPORT void JNICALL Java_org_simgrid_msg_Process_sleep(JNIEnv *env, jclass cl
   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, "");
   }
 }
@@ -296,5 +301,4 @@ JNIEXPORT void JNICALL Java_org_simgrid_msg_Process_setKillTime (JNIEnv *env , j
 JNIEXPORT jint JNICALL Java_org_simgrid_msg_Process_getCount(JNIEnv * env, jclass cls) {
   return (jint) MSG_process_get_number();
 }
-
-SG_END_DECL()
+}