Logo AND Algorithmique Numérique Distribuée

Public GIT Repository
Add new line at the end of the file, to avoid a gcc warning (turned into error by...
[simgrid.git] / src / java / jmsg.c
index e74aec4..908c9c1 100644 (file)
 #include "jmsg_host.h"
 #include "jmsg_task.h"
 #include "jmsg_channel.h"
+#include "jmsg_application_handler.h"
 #include "jxbt_utilities.h"
 
+
 #include "jmsg.h"
 
 #include "msg/mailbox.h"
 
+#include "surf/surfxml_parse.h"
+
+
 XBT_LOG_EXTERNAL_DEFAULT_CATEGORY(jmsg);
 
 static JavaVM * __java_vm = NULL;
@@ -119,7 +124,8 @@ Java_simgrid_msg_MsgNative_processCreate(JNIEnv* env, jclass cls, jobject jproce
   SIMIX_jprocess_create(process->name,
                        process->simdata->m_host->simdata->smx_host, 
                        /*data*/ (void*)process,
-                       jprocess,env,
+                       jprocess,
+                       env,
                        &process->simdata->s_process);
 
   
@@ -302,14 +308,8 @@ Java_simgrid_msg_MsgNative_processSelfPPID(JNIEnv* env, jclass cls) {
 }
 
 JNIEXPORT void JNICALL 
-Java_simgrid_msg_MsgNative_processChangeHost(JNIEnv* env, jclass cls, jobject jprocess, jobject jhost){
+Java_simgrid_msg_MsgNative_processChangeHost(JNIEnv* env, jclass cls, jobject jhost){
   m_host_t host = jhost_get_native(env,jhost);
-  m_process_t process = jprocess_to_native_process(jprocess,env);
-       
-  if(!process) {
-    jxbt_throw_notbound(env,"process",jprocess);
-    return;
-  }
        
   if(!host) {
     jxbt_throw_notbound(env,"host",jhost);
@@ -317,7 +317,7 @@ Java_simgrid_msg_MsgNative_processChangeHost(JNIEnv* env, jclass cls, jobject jp
   }
 
   /* try to change the host of the process */
-  if(MSG_OK != MSG_process_change_host(process,host))
+  if(MSG_OK != MSG_process_change_host(host))
     jxbt_throw_native(env, xbt_strdup("MSG_process_change_host() failed"));
 }
 
@@ -844,7 +844,7 @@ Java_simgrid_msg_Msg_init(JNIEnv* env, jclass cls, jobjectArray jargs) {
 
   argc++;
        
-  argv = xbt_new0(char*,1);
+  argv = xbt_new0(char*, argc);
         
   argv[0] = strdup("java");
        
@@ -988,17 +988,26 @@ Java_simgrid_msg_MsgNative_allHosts(JNIEnv * env, jclass cls_arg) {
 JNIEXPORT void JNICALL 
 Java_simgrid_msg_MsgNative_selectContextFactory(JNIEnv * env, jclass class,jstring jname)
 {
-       int rv;
+   char *errmsg = NULL;
+   xbt_ex_t e;
        
-       /* 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);
+   /* get the C string from the java string*/
+   const char* name = (*env)->GetStringUTFChars(env, jname, 0);
+
+   TRY {
+      xbt_context_select_factory(name);
+   } CATCH(e) {
+      errmsg = xbt_strdup(e.msg);
+      xbt_ex_free(e);
+   }
+   
+   (*env)->ReleaseStringUTFChars(env, jname, name);
        
-       if(rv)
-               jxbt_throw_native(env, xbt_strdup("xbt_select_context_factory() failed"));       
+   if(errmsg) {
+      char *thrown = bprintf("xbt_select_context_factory() failed: %s",errmsg);
+      free(errmsg);
+      jxbt_throw_native(env, thrown);
+   }   
 }
 
 JNIEXPORT void JNICALL 
@@ -1131,4 +1140,33 @@ Java_simgrid_msg_MsgNative_taskListenFrom(JNIEnv* env, jclass cls, jstring jalia
   
   return (jint)rv;
 }
+
+JNIEXPORT void JNICALL 
+Java_simgrid_msg_Msg_deployApplication(JNIEnv* env, jclass cls,jstring jdeploymentFile) {
+       
+       const char* deploymentFile = (*env)->GetStringUTFChars(env, jdeploymentFile, 0);
+       
+       surf_parse_reset_parser();
+       
+       surfxml_add_callback(STag_surfxml_process_cb_list, japplication_handler_on_begin_process);
+       
+       surfxml_add_callback(ETag_surfxml_argument_cb_list, japplication_handler_on_process_arg);
+       
+       surfxml_add_callback(STag_surfxml_prop_cb_list, japplication_handler_on_property);
+       
+       surfxml_add_callback(ETag_surfxml_process_cb_list, japplication_handler_on_end_process);
+
+       surf_parse_open(deploymentFile);
+       
+       japplication_handler_on_start_document();
+       
+       if(surf_parse())
+               jxbt_throw_native(env, xbt_strdup("surf_parse() failed"));
+       
+       surf_parse_close();
+       
+       japplication_handler_on_end_document();
+       
+  (*env)->ReleaseStringUTFChars(env, jdeploymentFile, deploymentFile); 
+}