Logo AND Algorithmique Numérique Distribuée

Public GIT Repository
git-svn-id: svn+ssh://scm.gforge.inria.fr/svn/simgrid/simgrid/trunk@7083 48e7efb5...
authorcoldpeace <coldpeace@48e7efb5-ca39-0410-a469-dd3cf9ba447f>
Thu, 11 Feb 2010 14:13:54 +0000 (14:13 +0000)
committercoldpeace <coldpeace@48e7efb5-ca39-0410-a469-dd3cf9ba447f>
Thu, 11 Feb 2010 14:13:54 +0000 (14:13 +0000)
13 files changed:
src/bindings/ruby/ApplicationHandler.rb
src/bindings/ruby/Master.rb
src/bindings/ruby/MasterSlave.rb
src/bindings/ruby/ProcessFactory.rb
src/bindings/ruby/RubyProcess.rb
src/bindings/ruby/Slave.rb
src/bindings/ruby/client.rb
src/bindings/ruby/rb_application_handler.c
src/bindings/ruby/rb_msg.c
src/bindings/ruby/rb_msg.h
src/bindings/ruby/rb_msg_host.c
src/bindings/ruby/rb_msg_task.c
src/bindings/ruby/rb_msg_task.h

index 0ac51da..fd13dba 100644 (file)
@@ -1,6 +1,6 @@
 require 'ProcessFactory'
 
-$debug = true
+$DEBUG = true
 
 class ApplicationHandler
 
@@ -8,82 +8,72 @@ class ApplicationHandler
   
 #   Initialize
   def initialize()
-     
+     #Nothing todo
   end
   
-    
-#  onStartDocument
+    #  onStartDocument
   def onStartDocument()
     
     @processFactory = ProcessFactory.new
-    
-    if ($debug)
+    if ($DEBUG)
       puts "onStartDocument"
     end
       
-    
   end
   
 #   onBeginProcess
-  def onBeginProcess (hostName ,function)
+  def onBeginProcess(hostName,function)
     
     @processFactory.setProcessIdentity(hostName,function)
     
-     if ($debug)
+     if ($DEBUG)
       puts "onBeginProcess"
      end
     
   end
 
 #   onProperty
-  
-  def onProperty(id,value)
+    def onProperty(id,value)
     
     @processFactory.setProperty(id,value)
     
-     if ($debug)
+     if ($DEBUG)
       puts "onProperty"
      end
     
   end
   
 #   RegisterProcessArg
-  
-  def onProcessArg(arg)
+    def onProcessArg(arg)
     
     @processFactory.registerProcessArg(arg)
       
-      if ($debug)
+      if ($DEBUG)
       puts "onProcessArg"
       end
     
   end
 
 #   OnEndProcess
-  
- def onEndProcess()
+   def onEndProcess()
    
    @processFactory.createProcess()
    
-   if ($debug)
+   if ($DEBUG)
       puts "onEndProcess"
    end
       
  end
 
-
  #  onEndDocument
- def onEndDocument()  
+  def onEndDocument()  
 #    Euh...Actually Nothin' to Do !!
    
-   if($debug)
+   if($DEBUG)
    puts "onEndDocument"
    end
  end
-  
  
-#  End Class
-end
+ #  End Class
+ end
 
index f96c5b2..c72321f 100644 (file)
@@ -6,44 +6,37 @@ include MSG
 class Master < RbProcess
   
   
-
-  
-  def initialize(*args)
-    
+  def initialize()
     super()
-    channel = 0
-    puts "Hey ..from Master"#info("Hey")
+    p RbHost.number()
+      
     
-   slaves = Array.new()
-   
+  end
+  
+  def run(args) # args is an array Containin' arguments for function master
+   puts "Hey From Ruby...I'm The Master" 
    size = args.size
-   
-   puts "Args = " + size
+   puts "Number of Args for Master = " + size.to_s
    
    for i in 0..size-1
-     puts "argv :" + args[1]
+      puts  args[i]
    end
    
-   raise "Master needs 3 arguments" if size < 3
-   
-   numberOfTask = args[0] #convert to int
-   taskComputeSize = args[1] #convert to double
-   taskCommunicationSize = args[2] #convert to double
-   slaveCount = args[3] #convert to int
-   
-   
-#    todo = Array.new(numberOfTask)
+   raise "Master needs 3 arguments" if size < 3 
+   numberOfTask = Integer(args[0]) 
+   taskComputeSize = Float(args[1])
+   taskCommunicationSize = Float(args[2])
+   slaveCount = Integer(args[3]) 
    
    #Creating & Sending Task
-   for i in 0..numberOfTask 
+   for i in 0..numberOfTask
      
      task = RbTask.new("Task_" + i.to_s, taskComputeSize , taskCommunicationSize );
      s_alias = "slave " + (i%slaveCount).to_s
-     puts "Master Sending "+ RbTask.name(task) + " to " + s_alias
+     puts "Master Sending "+ RbTask.name(task) + " to " + s_alias + " with Comput Size " + RbTask.compSize(task).to_s 
      RbTask.send(task,s_alias)
      puts "Master Done Sending " +RbTask.name(task) + " to " + s_alias
-     
    end
   
    # Sending Finalize Tasks
@@ -53,11 +46,6 @@ class Master < RbProcess
      puts "Master Sending Finalize to " + s_alias
      RbTask.send(RbTask.new("finalize",0,0),s_alias)
    end
-     
    puts "Master : Everything's Done"
-   
-  end
-  
+  end  
 end
-
-
index 1040e42..92ed0fc 100644 (file)
@@ -1,11 +1,22 @@
 require 'msg'
 require 'RubyProcess'
-
 require 'Master'
 require 'Slave'
 
-Msg.init()
-Msg.createEnvironment("../../../examples/msg/msg_platform.xml")
-Msg.deployApplication("MasterSlave_deploy.xml")
-Msg.run()
-Msg.exit()
+include MSG
+
+# raise "Bad Number Of Arguments" if ARGV.length != 2 
+
+# info("Bye")
+
+init(ARGV)
+raise "Bad Number Of Arguments " if (ARGV.length < 2)
+# p  Host.number()
+createEnvironment(ARGV[0])
+# p  Host.number()
+deployApplication(ARGV[1])
+# p  Host.number()
+
+# run()
+# exit()
index 3201ecf..ca34bd3 100644 (file)
@@ -4,8 +4,6 @@ class ProcessFactory
 
 #     Attributes
    attr_accessor :args, :proprieties, :hostName, :function
-    
-   
 #    Initlialize
     def initialize()
     
@@ -18,7 +16,7 @@ class ProcessFactory
     
 #     setProcessIdentity
     
-    def setProcessIdentity( hostName , function)
+    def setProcessIdentity(hostName,function)
       @hostName = hostName
       @function = function
       
@@ -30,7 +28,6 @@ class ProcessFactory
        proprieties.clear   
       end
     
-    
     end
 
 #     RegisterProcess
@@ -42,45 +39,26 @@ class ProcessFactory
     end
 
 #     CreateProcess
-    
     def createProcess()
       
-      
-      
-      process = RbProcess.new()
-      
-      
+      process = rubyNewInstance(@function) 
+#       process = rubyNewInstanceArgs(@function,@args)
       
       process.name = @function
-      
-      
-      process.id = process.nextId() # This increment Automaticly  The Static ProcessNextId for The Class RbProcess
-       
-      
-     
-      
-      host = rbHost.getByName(@hostName)
-      
-      Process.createProcess(process,host) 
-      
+      process.id = process.nextId() # This increment Automaticly  The Static ProcessNextId for The Class RbProces
+#       host = RbHost.getByName(@hostName)
+#       Process.createProcess(process,host)
       size = @args.size
-      
       for i in 0..size-1
-       
        process.pargs.push(@args[i])
-       
       end
-         
       process.proprieties = @proprieties
-      
       @proprieties = Hash.new
       
     end
     
-    
 #     SetProperty
-    
-    def setProperty( id , value )
+    def setProperty(id,value)
       
       @proprieties[id] = value
       
index b2b981d..113bf7c 100644 (file)
@@ -2,149 +2,114 @@ require 'msg'
 require 'Semaphore'
 include MSG
 
-$debug = true  # This is a Global Variable Useful for Debugging
+$DEBUG = true  # This is a Global Variable Useful for Debugging
 
 
-class RbProcess < Thread
-  
-  
-  
-  
+class RbProcess < Thread 
   @@nextProcessId = 0
 # Attributes
   attr_accessor :bind, :id, :proprieties, :name,
       :pargs, :schedBegin, :schedEnd
   
-  
-  
-# Initialize
-  
-  
-  # Used in ApplicationHandler to Initialize it
-  
-  
+# Initialize : USED in ApplicationHandler to Initialize it
   def initialize(*args)
     
-   
     argc = args.size
-    
-    
-    
-#      Default Init
+#      Default Init***************************** No Args
     if argc == 0    #>>> new()
     super() {
-    
     @id = 0
     @bind = 0
     @name = ""
     @pargs = Array.new()
-    
     init_var()
-
-         
-    
-     if $debug
-    puts "Init Default Initialzer..."
-     end
-    
-#     Thread.pass   #yield ?!!
+     if $DEBUG
+       puts "Init Default Initialzer..."
+     end  
+#     Thread.pass  
 #     sleep   # Sleep Forever ... To Keep Thread Alive ?!!
     
     }
     end
     
     
-    # Initi with 2 arguments
+    # Init with 1 Argument ***********************>>Name( Not Used )
+    if argc == 1
+      super(){
+       @name = args[0]
+       @pargs = Array.new()
+       init_var()
+       if $DEBUG
+         puts "Init with Name..."
+       end
+      }
+    end
     
-    if argc == 2   # >>>(HostName,Name) Or (Host , Name)
+  
+    
+    # Init with 2 arguments **********************>>>(HostName,Name) Or (Host , Name)
+    
+    if argc == 2   
       super(){
-       
-      
       type = args[0].type()
-      
       if ( type.to_s == "String")
         host = Host.getByName(args[0])
       end
-      
       if ( type.to_s == "MSG::Host")
         host = args[0]  
       end
-      
-      
-      if $debug
+      if $DEBUG
         puts host
       end
-      
-      
       raise "Process Name Cannot Be Null"   if args[1].empty?
-      
       @name = args[1] # First Arg
-      
-      if $debug
+      if $DEBUG
         puts @name
       end
-      
-      
       @pargs = Array.new()    # No Args[] Passed in Arguments
-      
-       @@nextProcessId += 1
-       @id = @@nextProcessId
-      
-       init_var()
-      
-       createProcess(self,host) #TODO >> MSG::Process
-      if $debug
+      @@nextProcessId += 1
+      @id = @@nextProcessId
+      init_var()
+      createProcess(self,host)
+      if $DEBUG
       puts "Initilize with 2 args"
       end
       
-#       sleep  # Keep The Thread Runin' 
+#       sleep  
       }
     
     
     end
     
+    
+    
        
-#     Init with 3 arguments
+    # Init with 3 arguments **********************(hostName,Name,args[]) or # (Host,Name,args[])
     
-    if argc == 3  #(hostName,Name,args[]) or # (Host,Name,args[])
+    if argc == 3  
       super(){
-       
        type = args[0].type()
-        
         if( type.to_s == "String")
-#      host = Host.getByName(args[0])
-      host ="Host.getByName(args[0])"
+         host =Host.getByName(args[0])
         end
-      
         if ( type.to_s == "MSG::Host" )
         host = args[0]
         end
-      
-        if $debug
+        if $DEBUG
         puts host
         end
       
-      
         raise "Process Name Cannot Be Null" if args[0].empty? 
-        
         @name = args[1]
-         
         type = args[2].type()
-       
         raise "Third Argument Should be an Array" if type != "Array"
-        
         @pargs = args[3]
-        
-        
         @@nextProcessId +=1
         @id = @@nextProcessId
-      
         init_var()
-             
-         createProcess(self,host)  #TODO  RubyMsg
+        createProcess(self,host)  
         
-      if $debug
+      if $DEBUG
        puts "Initilize with 3 args"
       end
       
@@ -160,7 +125,6 @@ class RbProcess < Thread
     
   def init_var()
     
-    
     @proprieties = Hash.new()
     # Process Synchronization Tools
      @schedBegin = Semaphore.new(0)
@@ -178,13 +142,8 @@ class RbProcess < Thread
     return @@nextProcessId
     
   end
-  
-  
-    
-  
-  
-  
-  if $debug
+
+  if $DEBUG
     #Process List
     def processList()
       
@@ -218,8 +177,7 @@ class RbProcess < Thread
   
   end
   
-  
-  #get Own Name
+    #get Own Name
   
   def getName()
    
@@ -249,9 +207,7 @@ class RbProcess < Thread
     
   end
     
-  
-  
-  # Stop
+      # Stop
   
   def unschedule() 
     
@@ -259,8 +215,7 @@ class RbProcess < Thread
   
   end
   
-  
-  #C Simualateur Process Equivalent  Management
+   #C Simualateur Process Equivalent  Management
   # After Binding Ruby Process to C Process
   
 #   pause
index 3029590..4dc12d0 100644 (file)
@@ -5,35 +5,26 @@ include MSG
 
 class Slave < RbProcess
   
-  def initialize(*args)
-    
+  def initialize()
+    super()
+  end
     
+  def run(args)
     puts "Hello From Slave"
     s_mailbox = "slave" + args[0]
-    
-    
     while true
-      
       task = RbTask.recieve(s_mailbox)
-      
       task_name = RbTask.name(task)
-      
       if ( task_name == "finalize" )
        puts "Slave" + s_mailbox + "got finalize msg"
        break
       end
-      
       puts "Slave " + s_mailbox + "Processing" + RbTask.name(task)
       RbTask.execute(task)
-      
     end
-       
     puts "Slave " + s_mailbox + "I'm Done , See You !!"
-      
-      
     end
     
-    
   end
   
   
index 623e145..00419d3 100644 (file)
@@ -1,5 +1,8 @@
 require 'msg'
 include MSG
+require 'RubyProcess'
+require 'Master'
+require 'RubyHost'
 
 
 array = Array.new()
@@ -8,6 +11,8 @@ array = Array.new()
 array << "Peace!!" << "Hey" << "Euh..."<< "Hey2" << "Euh...2"
 
 
+# process = rubyNewInstanceArgs("Master",array)
+
 # array.clear
 # puts array.empty?
 
@@ -35,31 +40,33 @@ array2 = array
 
 size = array2.size
 
-
-
-
-
-
-task = Task.new('ninou',12,23)
+task = Task.new('marine',12,23)
 puts "Created task :"+task.to_s+" ; name: "+Task.name(task)
+Task.send(task,"MailBox")
+# Task.send(Task.new("finalize",0,0),"alias")
 #task2 =RbTask.new('task2')
 # task = RbTask.new()
 # host = Host.new("Brad")
 
+
  #host2 = Host.new()
 #  task_2 = Task.new('task2',12,23)
 #   name1 = task_2.name()
 #  name2 = Task.name(task)
 #  size = Task.compSize(task)
- name = Task.name(task)
+name = Task.name(task)
 # task.bind
 number = 56
 
-process = RbProcess.new("mon nom")
-puts "Created process :"+process.to_s+" ; name: "+RbProcess.name(task)
+process = rubyNewInstance("RbProcess");#RbProcess.new()
+p  process.class
+# puts "Created process :"+process.to_s+" ; name: "+RbProcess.name(task)
 # name = process.name
 puts name
+
+argue = ARGV[0]
+puts argue
 # puts process.alive?
 # Thread.stop
 # process2 = RbProcess.new()
index 8404a25..11b5ce3 100644 (file)
@@ -2,6 +2,8 @@
 #include "surf/surfxml_parse.h"
 #include <stdio.h>
 
+// #define DEBUG 
+
 static void  r_init()
 {
   
@@ -14,11 +16,14 @@ static void  r_init()
 static void  application_handler_on_start_document(void)
 {
   
+   
    r_init();
    //current One
    current = rb_funcall3(rb_const_get(rb_cObject, rb_intern("ApplicationHandler")),  rb_intern("new"), 0, 0);
    rb_funcall(current,rb_intern("onStartDocument"),0);
-  
+ #ifdef DEBUG
+   printf ("application_handler_on_start_document ...Done\n" );
+ #endif
   
 }
 
@@ -32,28 +37,23 @@ static void  application_handler_on_end_document(void)
 
 static void application_handler_on_begin_process(void) 
 {
-  
   //r_init();
-  
   VALUE hostName = rb_str_new2(A_surfxml_process_host);
   VALUE function = rb_str_new2(A_surfxml_process_function);
-  
+#ifdef DEBUG
+   printf ("On_Begin_Process: %s : %s \n",RSTRING(hostName)->ptr,RSTRING(function)->ptr);
+#endif 
    rb_funcall(current,rb_intern("onBeginProcess"),2,hostName,function); 
-  
-  
 }
 
 static void  application_handler_on_process_arg(void)
 {
-
   //r_init();
-  
    VALUE arg = rb_str_new2(A_surfxml_argument_value);
-  
-   rb_funcall(current,rb_intern("onProcessArg"),1,arg);
-  
-  
+#ifdef DEBUG
+   printf ("On_Process_Args >> Sufxml argument value : %s\n",RSTRING(arg)->ptr);
+#endif
+   rb_funcall(current,rb_intern("onProcessArg"),1,arg); 
 }
 
 static void  application_handler_on_property(void)
index 8776728..8e469a1 100644 (file)
 #include "rb_msg_process.c"
 #include "rb_application_handler.c"
 
-
 
 //Init Msg_Init From Ruby
 
 
 static void msg_init(VALUE Class,VALUE args)
 {
-  
   char **argv=NULL;  
   const char *tmp;
   int argc,type,i;
   VALUE *ptr ;
-  
-  
-  
   // Testing The Args Type
   type =  TYPE(args);
-  
   if (type != T_ARRAY )
   {
-    rb_raise(rb_eRuntimeError,"Argh!! Bad Arguments to msg_init");
+    rb_raise(rb_eRuntimeError,"Argh!!! Bad Arguments to msg_init");
     return;
   }
     
@@ -41,15 +36,12 @@ static void msg_init(VALUE Class,VALUE args)
   
 //   Create C Array to Hold Data_Get_Struct 
   argv = xbt_new0(char *, argc);  // argc or argc +1
-  
   argv[0] = strdup("ruby");
-  
-  
   for (i=0;i<argc;i++)
   {
    VALUE value = ptr[i];
    type = TYPE(value);
-//   if (type == T_STRING)
+//  if (type == T_STRING)
    tmp = RSTRING(value)->ptr;
    argv[i+1] = strdup(tmp);
     
@@ -59,7 +51,6 @@ static void msg_init(VALUE Class,VALUE args)
   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 
   for (i=0;i<argc;i++)
    free(argv[i]) ;
@@ -70,9 +61,6 @@ static void msg_init(VALUE Class,VALUE args)
   return;
 }
 
-
-
-
 //Init Msg_Run From Ruby
 static void msg_run(VALUE class)
 {
@@ -80,7 +68,7 @@ static void msg_run(VALUE class)
  xbt_fifo_item_t item = NULL;
  m_host_t host = NULL;
  VALUE rbHost;
+  
  // Let's Run
  if (MSG_OK != MSG_main()){
    
@@ -101,72 +89,55 @@ static void msg_run(VALUE class)
     
      rb_raise(rb_eRuntimeError,"MSG_clean() failed");
    }
-    
     return;
-    
 }
 
-
-
-
 // Create Environment
 static void msg_createEnvironment(VALUE class,VALUE plateformFile)
 {
  
-  
-  int type = TYPE(plateformFile);
-  
-  if ( type != T_STRING )
-    rb_raise(rb_eRuntimeError,"Bad Argument's Type");
-   
- const char * platform =  RSTRING(plateformFile)->ptr;
- MSG_create_environment(platform);
+   int type = TYPE(plateformFile);
+   if ( type != T_STRING )
+      rb_raise(rb_eRuntimeError,"Bad Argument's Type");  
+   const char * platform =  RSTRING(plateformFile)->ptr;
+   MSG_create_environment(platform);
+   printf("Create Environment...Done\n");
  
  return; 
   
 }
 
 
-// deploy Application
+//deploy Application
 
 static void msg_deployApplication(VALUE class,VALUE deploymentFile )
 {
   
     int type = TYPE(deploymentFile);
-  
     if ( type != T_STRING )
-     rb_raise(rb_eRuntimeError,"Bad Argument's Type");
-  
+       rb_raise(rb_eRuntimeError,"Bad Argument's Type for deployApplication ");
     const char *dep_file = RSTRING(deploymentFile)->ptr;
-    
-    
     surf_parse_reset_parser();
-    
     surfxml_add_callback(STag_surfxml_process_cb_list,
                         application_handler_on_begin_process);
     
-    surfxml_add_callback(STag_surfxml_argument_cb_list,
+    surfxml_add_callback(ETag_surfxml_argument_cb_list,
                         application_handler_on_process_arg);
 
     surfxml_add_callback(STag_surfxml_prop_cb_list,
                         application_handler_on_property);
                         
-    surfxml_add_callback(STag_surfxml_process_cb_list,
+    surfxml_add_callback(ETag_surfxml_process_cb_list,
                         application_handler_on_end_process);
-                        
+                         
     surf_parse_open(dep_file);
-                        
     application_handler_on_start_document();
-    
     if(surf_parse())
-      rb_raise(rb_eRuntimeError,"surf_parse() failed");
-    
-    surf_parse_close();
-    
+       rb_raise(rb_eRuntimeError,"surf_parse() failed");
+    surf_parse_close();   
     application_handler_on_end_document();
-    
-  
+    printf("Deploy Application...Done\n");
 }
 
 
@@ -192,7 +163,7 @@ static VALUE msg_get_clock(VALUE class)
  
   return DBL2NUM(MSG_get_clock());
   
-}
+}   
 
 //pajeOutput
 static void msg_paje_out(VALUE class,VALUE pajeFile)
@@ -202,6 +173,30 @@ static void msg_paje_out(VALUE class,VALUE pajeFile)
   
 }
 
+
+// Ruby intropspection : Instanciate a ruby Class From its Name 
+// Used by ProcessFactory::createProcess
+
+static VALUE msg_new_ruby_instance(VALUE class,VALUE className)
+{
+  ruby_init();
+  ruby_init_loadpath();
+  char * p_className = RSTRING(className)->ptr;
+  
+  return rb_funcall3(rb_const_get(rb_cObject, rb_intern(p_className)),  rb_intern("new"), 0, 0);
+  
+}
+
+//This Time With Args
+
+static VALUE msg_new_ruby_instance_with_args(VALUE class,VALUE className,VALUE args)
+{
+  ruby_init();
+  ruby_init_loadpath();
+  char * p_className = RSTRING(className)->ptr;
+  return rb_funcall(rb_const_get(rb_cObject, rb_intern(p_className)),  rb_intern("new"), 1, args);
+  
+}
 /*****************************************************************************************************************
 
 Wrapping MSG module and its Class ( Task,Host) & Methods ( Process's method...ect)
@@ -225,25 +220,27 @@ void Init_msg()
    rb_define_method(rb_msg,"info",msg_info,1);
    rb_define_method(rb_msg,"getClock",msg_get_clock,0);
    rb_define_method(rb_msg,"pajeOutput",msg_paje_out,1);
-   
+   rb_define_method(rb_msg,"rubyNewInstance",msg_new_ruby_instance,1);
+   rb_define_method(rb_msg,"rubyNewInstanceArgs",msg_new_ruby_instance_with_args,2);
+     
    // Associated Process Methods
-//    rb_define_method(rb_msg,"processCreate",processCreate,2);
+   rb_define_method(rb_msg,"processCreate",processCreate,2);
    rb_define_method(rb_msg,"processSuspend",processSuspend,1);
    rb_define_method(rb_msg,"processResume",processResume,1);
    rb_define_method(rb_msg,"processIsSuspend",processIsSuspend,1);
    rb_define_method(rb_msg,"processKill",processKill,1);
    rb_define_method(rb_msg,"processGetHost",processGetHost,1);
      
-   //Classes
+   //Classes       
    rb_task = rb_define_class_under(rb_msg,"Task",rb_cObject);
    rb_host = rb_define_class_under(rb_msg,"Host",rb_cObject);
-   
-   //Task Methods
+    
+   //Task Methods    
    rb_define_module_function(rb_task,"new",task_new,3);
    rb_define_module_function(rb_task,"compSize",task_comp,1);
    rb_define_module_function(rb_task,"name",task_name,1);
    rb_define_module_function(rb_task,"execute",task_execute,1);
-   rb_define_module_function(rb_task,"send",task_send,2);
+   rb_define_module_function(rb_task,"send",task_send,2); 
    rb_define_module_function(rb_task,"receive",task_receive,1);
    rb_define_module_function(rb_task,"receive2",task_receive2,2);
    rb_define_module_function(rb_task,"sender",task_sender,1);
@@ -255,10 +252,10 @@ void Init_msg()
    rb_define_module_function(rb_host,"getByName",host_get_by_name,1);
    rb_define_module_function(rb_host,"name",host_name,1);
    rb_define_module_function(rb_host,"speed",host_speed,1);
-   rb_define_module_function(rb_host,"number",host_number,0);
+   rb_define_module_function(rb_host,"number",host_number,0); 
    rb_define_module_function(rb_host,"setData",host_set_data,2);
    rb_define_module_function(rb_host,"getData",host_get_data,1);
-//    rb_define_module_function(rb_host,"hasData",host_has_data,1);
+   //rb_define_module_function(rb_host,"hasData",host_has_data,1);
    rb_define_module_function(rb_host,"isAvail",host_is_avail,1);
    
-}
+}  
index d6e3dc4..b27cd57 100644 (file)
@@ -37,11 +37,17 @@ static void msg_registerFunction(VALUE Class,VALUE function_name,VALUE code);
 // Tools
 static void msg_info(VALUE Class,VALUE msg);
 
-//get Clock
+//get Clock  
 static VALUE msg_get_clock(VALUE Class);
 
 //pajeOutput
 static void msg_paje_output(VALUE Class,VALUE pajeFile);
 
 
+// Ruby Introspection : To instanciate a Ruby Class from its Name
+static VALUE msg_new_ruby_instance(VALUE Class,VALUE className);
+
+// The Same ... This Time with Args
+static VALUE msg_new_ruby_instance_with_args(VALUE Class,VALUE className,VALUE args);
+
 #endif
\ No newline at end of file
index 27eefce..9216633 100644 (file)
@@ -5,28 +5,24 @@ static void host_free(m_host_t ht) {
   //Nothing to do !!?
 }
 
-
 // New Method : return a Host
 static VALUE host_get_by_name(VALUE class, VALUE name)
 {
   
-  m_host_t host = MSG_get_host_by_name(RSTRING(name)->ptr);
+  const char * h_name = RSTRING(name)->ptr;
+  m_host_t host = MSG_get_host_by_name(h_name);
   if(!host)
-    
     rb_raise(rb_eRuntimeError,"MSG_get_host_by_name() failled");
   
-  return Data_Wrap_Struct(class, 0, host_free, host);
+  return Data_Wrap_Struct(class,0,host_free,host);
 
 }
 
-
 //Get Name
-
 static VALUE host_name(VALUE class,VALUE host)
 {
   
   // Wrap Ruby Value to m_host_t struct
-  
   m_host_t ht;
   Data_Get_Struct(host, m_host_t, ht);
   return rb_str_new2(MSG_host_get_name(ht));
@@ -36,8 +32,8 @@ static VALUE host_name(VALUE class,VALUE host)
 // Get Number
 static VALUE host_number(VALUE class)
 {
-  return MSG_get_host_number();
+  
+  return INT2NUM(MSG_get_host_number());
   
 }
 
@@ -50,7 +46,6 @@ static VALUE host_speed(VALUE class,VALUE host)
   
 }
 
-
 // Host Set Data
 static void host_set_data(VALUE class,VALUE host,VALUE data)
 {
@@ -64,9 +59,6 @@ static VALUE host_get_data(VALUE class,VALUE host)
   return Qnil;
 }
 
-
-
-
 // Host is Avail
 static VALUE host_is_avail(VALUE class,VALUE host)
 {
index d54b542..1d0e7c3 100644 (file)
@@ -60,15 +60,19 @@ static VALUE task_execute(VALUE class,VALUE task)
 
 // Sending Task
 
-static VALUE task_send(VALUE class,VALUE task,VALUE mailbox)
+static void task_send(VALUE class,VALUE task,VALUE mailbox)
 {
   
     // Wrap Ruby Value to m_task_t struct
+  
   m_task_t tk;
   Data_Get_Struct(task, m_task_t, tk);
-  return INT2NUM(MSG_task_send(tk,RSTRING(mailbox)->ptr));
-  
+  int res = MSG_task_send(tk,RSTRING(mailbox)->ptr);
+  if(res != MSG_OK)
+   rb_raise(rb_eRuntimeError,"MSG_task_send failed");
   
+  return;
 }
 
 // Recieving Task 
index f8d8170..9f82517 100644 (file)
@@ -24,8 +24,8 @@ static VALUE task_name(VALUE Class,VALUE task);
 // Execute Task
 static VALUE task_execute(VALUE Class,VALUE task);
 
-// Sending Task
-static VALUE task_send(VALUE Class,VALUE task,VALUE mailbox);
+// Sending Task 
+static void task_send(VALUE Class,VALUE task,VALUE mailbox);
 
 // Recieve : return a task
 static VALUE task_receive(VALUE Class,VALUE mailbox);