Logo AND Algorithmique Numérique Distribuée

Public GIT Repository
New function Process.getCount()
[simgrid.git] / src / jmsg_process.c
index f05d8be..aaa73e7 100644 (file)
@@ -1,6 +1,6 @@
 /* Functions related to the java process instances.                         */
 
-/* Copyright (c) 2007, 2008, 2009, 2010. The SimGrid Team.
+/* Copyright (c) 2007-2012. The SimGrid Team.
  * All rights reserved.                                                     */
 
 /* This program is free software; you can redistribute it and/or modify it
@@ -184,13 +184,33 @@ Java_org_simgrid_msg_Process_fromPID(JNIEnv * env, jclass cls,
   jobject jprocess = native_to_java_process(process);
 
   if (!jprocess) {
-    jxbt_throw_jni(env, "SIMIX_process_get_jprocess() failed");
+    jxbt_throw_jni(env, "get process failed");
     return NULL;
   }
 
   return jprocess;
 }
+JNIEXPORT jobject JNICALL
+Java_org_simgrid_msg_Process_getProperty(JNIEnv *env, jobject jprocess, jobject jname) {
+  msg_process_t process = jprocess_to_native_process(jprocess, env);
+
+  if (!process) {
+    jxbt_throw_notbound(env, "process", jprocess);
+    return NULL;
+  }
+  const char *name = (*env)->GetStringUTFChars(env, jname, 0);
+
+  const char *property = MSG_process_get_property_value(process, name);
+  if (!property) {
+    return NULL;
+  }
+
+  jobject jproperty = (*env)->NewStringUTF(env, property);
+
+  (*env)->ReleaseStringUTFChars(env, jname, name);
 
+  return jproperty;
+}
 JNIEXPORT jobject JNICALL
 Java_org_simgrid_msg_Process_currentProcess(JNIEnv * env, jclass cls)
 {
@@ -228,6 +248,7 @@ Java_org_simgrid_msg_Process_suspend(JNIEnv * env,
                  bprintf("unexpected error , please report this bug"));
 
 }
+
 JNIEXPORT void JNICALL
 Java_org_simgrid_msg_Process_resume(JNIEnv * env,
                                      jobject jprocess)
@@ -245,6 +266,45 @@ Java_org_simgrid_msg_Process_resume(JNIEnv * env,
   jxbt_check_res("MSG_process_resume()", rv, MSG_OK,
                  bprintf("unexpected error , please report this bug"));
 }
+JNIEXPORT void JNICALL
+Java_org_simgrid_msg_Process_setAutoRestart
+    (JNIEnv *env, jobject jprocess, jboolean jauto_restart) {
+  msg_process_t process = jprocess_to_native_process(jprocess, env);
+  xbt_ex_t e;
+
+  int auto_restart = jauto_restart == JNI_TRUE ? 1 : 0;
+
+  if (!process) {
+    jxbt_throw_notbound(env, "process", jprocess);
+    return;
+  }
+
+  TRY {
+    MSG_process_auto_restart_set(process,auto_restart);
+  }
+  CATCH (e) {
+    xbt_ex_free(e);
+  }
+}
+JNIEXPORT void JNICALL
+Java_org_simgrid_msg_Process_restart
+    (JNIEnv *env, jobject jprocess) {
+  msg_process_t process = jprocess_to_native_process(jprocess, env);
+  xbt_ex_t e;
+
+  if (!process) {
+    jxbt_throw_notbound(env, "process", jprocess);
+    return;
+  }
+
+  TRY {
+    MSG_process_restart(process);
+  }
+  CATCH (e) {
+    xbt_ex_free(e);
+  }
+
+}
 JNIEXPORT jboolean JNICALL
 Java_org_simgrid_msg_Process_isSuspended(JNIEnv * env,
                                          jobject jprocess)
@@ -260,7 +320,8 @@ Java_org_simgrid_msg_Process_isSuspended(JNIEnv * env,
   return (jboolean) MSG_process_is_suspended(process);
 }
 
-JNIEXPORT void JNICALL Java_org_simgrid_msg_Process_sleep
+JNIEXPORT void JNICALL
+Java_org_simgrid_msg_Process_sleep
        (JNIEnv *env, jclass cls, jlong jmillis, jint jnanos) {
 
        double time =  jmillis / 1000 + jnanos / 1000;
@@ -340,3 +401,15 @@ Java_org_simgrid_msg_Process_setKillTime (JNIEnv *env , jobject jprocess, jdoubl
        msg_process_t process = jprocess_to_native_process(jprocess, env);
        MSG_process_set_kill_time(process, (double)jkilltime);
 }
+
+JNIEXPORT jint JNICALL
+Java_org_simgrid_msg_Process_getCount(JNIEnv * env, jclass cls) {
+       /* FIXME: the next test on SimGrid version is to ensure that this still compiles with SG 3.8 while the C function were added in SG 3.9 only.
+        * This kind of pimple becomes mandatory when you get so slow to release the java version that it begins evolving further after the C release date.
+        */
+#if SIMGRID_VERSION >= 30900
+  return (jint) MSG_process_get_number();
+#else
+  return (jint) -1;
+#endif
+}