Logo AND Algorithmique Numérique Distribuée

Public GIT Repository
Do not include C files. Instead, add them to the project file. Hopefully, this will...
[simgrid.git] / src / java / jmsg.c
index d40d249d78495d45053aea092026e339d438779a..9d7c85adea9c7f2ad45de8c63ddc85abc35f080b 100644 (file)
@@ -12,7 +12,8 @@
 #include "msg/msg.h"
 #include "msg/private.h"
 #include "simix/private.h"
-#include "java/jxbt_context.h"
+#include "xbt/xbt_jcontext.h"
+#include "xbt/xbt_context_factory.h"
 
 #include "jmsg_process.h"
 #include "jmsg_host.h"
 #include "jmsg_channel.h"
 #include "jxbt_utilities.h"
 
-XBT_LOG_NEW_DEFAULT_CATEGORY(jmsg,"MSG for Java(TM)");
-
 #include "jmsg.h"
 
+XBT_LOG_EXTERNAL_DEFAULT_CATEGORY(jmsg);
+
 static JavaVM * __java_vm = NULL;
 
+static jobject
+native_to_java_process(m_process_t process);
+
 JavaVM *
 get_java_VM(void) {
        return __java_vm;
@@ -41,6 +45,12 @@ get_current_thread_env(void) {
         return env;
 }
 
+static jobject
+native_to_java_process(m_process_t process)
+{
+       return ((xbt_jcontext_t)(process->simdata->s_process->simdata->context))->jprocess;     
+}
+
 
 /*
  * The MSG process connected functions implementation.                                 
@@ -108,6 +118,8 @@ Java_simgrid_msg_Msg_processCreate(JNIEnv* env, jclass cls, jobject jprocess_arg
                        /*data*/ (void*)process,
                        jprocess,env,
                        &process->simdata->s_process);
+
+  
   DEBUG1("context created (s_process=%p)",process->simdata->s_process);
 
 
@@ -176,7 +188,7 @@ Java_simgrid_msg_Msg_processKill(JNIEnv* env, jclass cls, jobject jprocess) {
   }
 
   /* delete the global reference */
-  jprocess_delete_global_ref(SIMIX_process_get_jprocess(process->simdata->s_process),env);
+  jprocess_delete_global_ref(native_to_java_process(process),env);
        
   /* kill the native process (this wrapper is call by the destructor of the java 
    * process instance)
@@ -216,12 +228,12 @@ Java_simgrid_msg_Msg_processFromPID(JNIEnv* env, jclass cls, jint PID) {
     return NULL;
   }
 
-  if(!SIMIX_process_get_jprocess(process->simdata->s_process)) {
+  if(!native_to_java_process(process)) {
     jxbt_throw_native(env, xbt_strdup("SIMIX_process_get_jprocess() failed"));
     return NULL;
   }
 
-  return (jobject)SIMIX_process_get_jprocess(process->simdata->s_process);
+  return (jobject)(native_to_java_process(process));
 }
 
 
@@ -260,7 +272,7 @@ Java_simgrid_msg_Msg_processSelf(JNIEnv* env, jclass cls) {
     return NULL;
   }
 
-  jprocess = SIMIX_process_get_jprocess(process->simdata->s_process);
+  jprocess = native_to_java_process(process);
 
   if(!jprocess)
     jxbt_throw_native(env, xbt_strdup("SIMIX_process_get_jprocess() failed"));
@@ -583,7 +595,7 @@ Java_simgrid_msg_Msg_taskGetSender(JNIEnv* env , jclass cls , jobject jtask) {
   }
        
   process = MSG_task_get_sender(task);
-  return SIMIX_process_get_jprocess(process->simdata->s_process);
+  return (jobject)native_to_java_process(process);
 }
 
 JNIEXPORT jobject JNICALL 
@@ -600,7 +612,7 @@ Java_simgrid_msg_Msg_parallelTaskGetSender(JNIEnv* env , jclass cls , jobject jt
        
   process = MSG_task_get_sender(task);
        
-  return SIMIX_process_get_jprocess(process->simdata->s_process);
+  return (jobject)native_to_java_process(process);
 }
 
 JNIEXPORT jobject JNICALL 
@@ -1099,7 +1111,7 @@ Java_simgrid_msg_Msg_processExit(JNIEnv* env, jclass cls, jobject jprocess) {
     return;
   }
 
-  jcontext_exit(process->simdata->s_process->simdata->context,0,get_current_thread_env());
+  xbt_context_stop(0);
 }
 
 JNIEXPORT void JNICALL 
@@ -1160,4 +1172,20 @@ Java_simgrid_msg_Msg_allHosts(JNIEnv * env, jclass cls_arg) {
   return jtable;
 }
 
+
+JNIEXPORT void JNICALL 
+Java_simgrid_msg_Msg_selectContextFactory(JNIEnv * env, jclass class,jstring jname)
+{
+       int rv;
+       
+       /* get the C string from the java string*/
+       const char* name = (*env)->GetStringUTFChars(env, jname, 0);
+
+       rv = xbt_context_select_factory(name);
+               
+       (*env)->ReleaseStringUTFChars(env, jname, name);
+       
+       if(rv)
+               jxbt_throw_native(env, xbt_strdup("xbt_select_context_factory() failed"));       
+}