]> AND Public Git Repository - simgrid.git/blobdiff - src/bindings/ruby/simgrid_ruby.c
Logo AND Algorithmique Numérique Distribuée

Public GIT Repository
We must put the location where we copy the task
[simgrid.git] / src / bindings / ruby / simgrid_ruby.c
index ac65b0d7813e906665a9df733d5a4a8709e90a90..393fec7715092812c18cf55f6f9f002f1c5e34e0 100644 (file)
@@ -16,7 +16,6 @@ VALUE rb_msg;
 VALUE rb_task;
 VALUE rb_host;
 
-
 //Init Msg  From Ruby
 static void msg_init(VALUE Class,VALUE args)
 {
@@ -26,9 +25,8 @@ static void msg_init(VALUE Class,VALUE args)
   VALUE *ptr ;
   // Testing The Args Type
   type =  TYPE(args);
-  if (type != T_ARRAY )
-  {
-    rb_raise(rb_eRuntimeError,"Argh!!! Bad Arguments to msg_init");
+  if (type != T_ARRAY ) {
+    rb_raise(rb_eRuntimeError,"Bad arguments to msg_init (expecting an array)");
     return;
   }
   ptr= RARRAY(args)->ptr;
@@ -37,8 +35,7 @@ static void msg_init(VALUE Class,VALUE args)
   argc++;
   argv = xbt_new0(char *, argc);
   argv[0] = strdup("ruby");
-  for (i=0;i<argc-1;i++)
-  {
+  for (i=0;i<argc-1;i++) {
     VALUE value = ptr[i];
     type = TYPE(value);
     //  if (type == T_STRING)
@@ -47,16 +44,11 @@ static void msg_init(VALUE Class,VALUE args)
   }
   // Calling C Msg_Init Method
   MSG_global_init(&argc,argv);
-  MSG_set_channel_number(10); // Okey !! Okey !! This Must Be Fixed Dynamiclly , But Later ;)
-  SIMIX_context_select_factory("ruby");
 
-  // Free Stuffs
+  // Cleanups
   for (i=0;i<argc;i++)
     free(argv[i]) ;
-
   free (argv);
-  DEBUG0("Msg Init...Done");
-  return;
 }
 //Init Msg_Run From Ruby
 static void msg_run(VALUE class) {
@@ -106,7 +98,6 @@ static void msg_deployApplication(VALUE class,VALUE deploymentFile ) {
   surf_parse_reset_parser();
   surfxml_add_callback(STag_surfxml_process_cb_list,
       rb_application_handler_on_begin_process);
-
   surfxml_add_callback(ETag_surfxml_argument_cb_list,
       rb_application_handler_on_process_arg);
 
@@ -121,6 +112,7 @@ static void msg_deployApplication(VALUE class,VALUE deploymentFile ) {
   if(surf_parse())
     rb_raise(rb_eRuntimeError,"surf_parse() failed");
   surf_parse_close();
+  
   rb_application_handler_on_end_document();
 
   DEBUG1("Deploy Application(%s)...Done",dep_file);
@@ -131,17 +123,22 @@ static void msg_info(VALUE class,VALUE msg) {
   const char *s = RSTRING(msg)->ptr;
   INFO1("%s",s);
 }
+static void msg_debug(VALUE class,VALUE msg) {
+  const char *s = RSTRING(msg)->ptr;
+  DEBUG1("%s",s);
+}
 
-// Get Clock
-static void msg_get_clock(VALUE class) {
+// Get Clock FIXME: return the double instead of float
+static VALUE msg_get_clock(VALUE class) {
 
-  printf("Simulation time %f\n",MSG_get_clock());
+  return rb_float_new(MSG_get_clock());
 
 }
 
 // Ruby intropspection : Instanciate a ruby Class From its Name
 // Used by ProcessFactory::createProcess
 
+// FIXME: KILLME?
 static VALUE msg_new_ruby_instance(VALUE class,VALUE className) {
   ruby_init();
   ruby_init_loadpath();
@@ -150,7 +147,7 @@ static VALUE msg_new_ruby_instance(VALUE class,VALUE className) {
   return rb_funcall3(rb_const_get(rb_cObject, rb_intern(p_className)),rb_intern("new"),0, 0);
 }
 
-//This Time With Args
+//This Time With Args FIXME: KILLME
 static VALUE msg_new_ruby_instance_with_args(VALUE class,VALUE className,VALUE args) {
   ruby_init();
   ruby_init_loadpath();
@@ -159,23 +156,26 @@ static VALUE msg_new_ruby_instance_with_args(VALUE class,VALUE className,VALUE a
 }
 
 
+extern const char*xbt_ctx_factory_to_use; /*Hack: let msg load directly the right factory */
 
 typedef VALUE(*rb_meth)(ANYARGS);
 void Init_simgrid_ruby() {
+  xbt_ctx_factory_to_use = "ruby";
+
   // Modules
   rb_msg = rb_define_module("MSG");
   //Associated Environment Methods!
-  rb_define_method(rb_msg,"init",(rb_meth)msg_init,1);
-  rb_define_method(rb_msg,"run",(rb_meth)msg_run,0);
-  rb_define_method(rb_msg,"createEnvironment",(rb_meth)msg_createEnvironment,1);
-  rb_define_method(rb_msg,"deployApplication",(rb_meth)msg_deployApplication,1);
-  rb_define_method(rb_msg,"info",(rb_meth)msg_info,1);
-  rb_define_method(rb_msg,"getClock",(rb_meth)msg_get_clock,0);
-  rb_define_method(rb_msg,"rubyNewInstance",(rb_meth)msg_new_ruby_instance,1);
-  rb_define_method(rb_msg,"rubyNewInstanceArgs",(rb_meth)msg_new_ruby_instance_with_args,2);
+  rb_define_module_function(rb_msg,"init",(rb_meth)msg_init,1);
+  rb_define_module_function(rb_msg,"run",(rb_meth)msg_run,0);
+  rb_define_module_function(rb_msg,"createEnvironment",(rb_meth)msg_createEnvironment,1);
+  rb_define_module_function(rb_msg,"deployApplication",(rb_meth)msg_deployApplication,1);
+  rb_define_module_function(rb_msg,"info",(rb_meth)msg_info,1);
+  rb_define_module_function(rb_msg,"debug",(rb_meth)msg_debug,1);
+  rb_define_module_function(rb_msg,"getClock",(rb_meth)msg_get_clock,0);
+  rb_define_module_function(rb_msg,"rubyNewInstance",(rb_meth)msg_new_ruby_instance,1);
+  rb_define_module_function(rb_msg,"rubyNewInstanceArgs",(rb_meth)msg_new_ruby_instance_with_args,2);
 
   // Associated Process Methods
-  rb_define_method(rb_msg,"processCreate",(rb_meth)rb_process_create,2);
   rb_define_method(rb_msg,"processSuspend",(rb_meth)rb_process_suspend,1);
   rb_define_method(rb_msg,"processResume",(rb_meth)rb_process_resume,1);
   rb_define_method(rb_msg,"processIsSuspend",(rb_meth)rb_process_isSuspended,1);
@@ -184,10 +184,10 @@ void Init_simgrid_ruby() {
   rb_define_method(rb_msg,"processExit",(rb_meth)rb_process_exit,1);
 
   //Classes
-  rb_task = rb_define_class_under(rb_msg,"Task",rb_cObject);
-  rb_host = rb_define_class_under(rb_msg,"Host",rb_cObject);
+  rb_task = rb_define_class_under(rb_msg,"RbTask",rb_cObject);
+  rb_host = rb_define_class_under(rb_msg,"RbHost",rb_cObject);
 
-  //Task Methods
+  //Task Methods FIXME: Convert to methods
   rb_define_module_function(rb_task,"new",(rb_meth)rb_task_new,3);
   rb_define_module_function(rb_task,"compSize",(rb_meth)rb_task_comp,1);
   rb_define_module_function(rb_task,"name",(rb_meth)rb_task_name,1);
@@ -206,7 +206,5 @@ void Init_simgrid_ruby() {
   rb_define_module_function(rb_host,"number",(rb_meth)rb_host_number,0);
   rb_define_module_function(rb_host,"setData",(rb_meth)rb_host_set_data,2);
   rb_define_module_function(rb_host,"getData",(rb_meth)rb_host_get_data,1);
-  //rb_define_module_function(rb_host,"hasData",host_has_data,1);
   rb_define_module_function(rb_host,"isAvail",(rb_meth)rb_host_is_avail,1);
-
 }