Logo AND Algorithmique Numérique Distribuée

Public GIT Repository
redefinition of task and host ruby classes to adopte an object-oriented approach
authorcoldpeace <coldpeace@48e7efb5-ca39-0410-a469-dd3cf9ba447f>
Thu, 4 Mar 2010 10:01:30 +0000 (10:01 +0000)
committercoldpeace <coldpeace@48e7efb5-ca39-0410-a469-dd3cf9ba447f>
Thu, 4 Mar 2010 10:01:30 +0000 (10:01 +0000)
git-svn-id: svn+ssh://scm.gforge.inria.fr/svn/simgrid/simgrid/trunk@7182 48e7efb5-ca39-0410-a469-dd3cf9ba447f

src/bindings/ruby/MasterSlave.rb
src/bindings/ruby/rb_msg_task.c
src/bindings/ruby/simgrid.rb
src/bindings/ruby/simgrid_ruby.c

index e945b7a..ebc7787 100644 (file)
@@ -27,11 +27,11 @@ class Master < MSG::Process
    for i in 0..numberOfTask-1
      task = MSG::Task.new("Task_"+ i.to_s, taskComputeSize , taskCommunicationSize);
      mailbox = "slave " + (i%slaveCount).to_s
-     MSG::info("Master Sending "+ MSG::Task.name(task) + " to " + mailbox + " with Comput Size " + 
-          MSG::Task.compSize(task).to_s)
+     MSG::info("Master Sending "+ task.name + " to " + mailbox + " with Comput Size " + 
+          task.compSize.to_s)
 #          task.compSize.to_s) # FIXME: This version creates a deadlock. Interesting
-     MSG::Task.send(task,mailbox)
-     MSG::info("Master Done Sending " +MSG::Task.name(task) + " to " + mailbox)
+     task.send(mailbox)
+     MSG::info("Master Done Sending " + task.name + " to " + mailbox)
    end
   
    # Sending Finalize MSG::Tasks
@@ -39,7 +39,8 @@ class Master < MSG::Process
    for i in 0..slaveCount-1
      mailbox = "slave " + i.to_s
      MSG::info("Master Sending Finalize to " + mailbox)
-     MSG::Task.send(Task.new("finalize",0,0),mailbox)
+     finalize_task = Task.new("finalize",0,0)
+     finalize_task.send(mailbox)
    end
    MSG::info("Master : Everything's Done")
   end    
@@ -55,14 +56,13 @@ class Slave < MSG::Process
     while true
        info("Ready to Receive Task")
        task = MSG::Task.receive(mailbox)
-       task_name = MSG::Task.name(task)
        MSG::info("Task Received : " + task.name)
        if (task_name == "finalize")
               MSG::info("Slave" + s_mailbox + "got finalize msg")
               break
        end
-       MSG::info("Slave " + s_mailbox + " ...Processing" + MSG::Task.name(task))
-       MSG::Task.execute(task)
+       MSG::info("Slave " + s_mailbox + " ...Processing" + task.name)
+       task.execute
     end
     MSG::info("Slave " + s_mailbox +  "I'm Done , See You !!")
   end    
@@ -84,5 +84,5 @@ end
 
 # Thread.list.each {|t| p t}
 MSG.run
-MSG.getClock #FIXME: write "puts MSG.getClock" instead
+puts "Simulation time : " + MSG.getClock .to_s
 # exit()
index 63c53ec..fcca601 100644 (file)
@@ -37,7 +37,7 @@ VALUE rb_task_comp(VALUE class,VALUE task) {
 VALUE rb_task_name(VALUE class,VALUE task) {
 
   // Wrap Ruby Value to m_task_t struct
-  m_task_t tk;
+  m_task_t tk; 
   Data_Get_Struct(task, s_m_task_t, tk);
   return rb_str_new2(MSG_task_get_name(tk));
 }
index daa12ea..3c5eede 100644 (file)
@@ -54,14 +54,12 @@ class MSG::Process < Thread
   @@nextProcessId = 0
 
 # Attributes
-  attr_reader :bind, :id, :name, :pargs # Read only
-  attr_accessor :properties             # R/W 
+  attr_reader :bind, :id, :name, :pargs ,:properties# Read only
   
-
     def initialize(*args)
       super(){
        
-     raise "Bad Number Of arguments to create a Ruby Process (name,args,prop) " if args.size < 3
+     raise "Bad Number Of arguments to create a Ruby Process (name,args,prop) " if args.size < 3
      
     @schedBegin = Semaphore.new(0)
     @schedEnd = Semaphore.new(0)    
@@ -70,14 +68,10 @@ class MSG::Process < Thread
     @name = args[0]
     @pargs = args[1]
     @properties = args[2]
-    
-     start()
-      
+    start()
       }
-      
     end
     
-    
   # main
   def main(args) 
     # To be overriden by childs
@@ -90,7 +84,7 @@ class MSG::Process < Thread
     # execute the main code of the process     
     MSG::debug("Begin execution")
     main(@pargs)
-    processExit(self) # Exit the Native Process
+    processExit(self) # Exit the Native Process
     @schedEnd.release
   end
     
@@ -135,6 +129,88 @@ class MSG::Process < Thread
 # The Rest of Methods !!! To be Continued ... FIXME: what's missing?
 end
 
+############################################
+# Task Extend from the native Class RbTask
+############################################
+class MSG::Task < MSG::RbTask
+
+  def initialize(*args)
+     super()
+  end
+  
+  def name
+     super(self)
+  end
+  
+  def compSize
+     super(self)
+  end
+  
+  def send(mailbox)
+    super(mailbox)
+  end
+  
+  def receive(mailbox)
+    super(mailbox)
+  end
+  
+  def source
+    super(self)
+  end
+  
+  def sender
+    super(self)
+  end
+  
+  def listen(t_alias)
+    super(t_alias)
+  end
+  
+  def execute
+    super(self)
+  end
+    
+  def listenFromHost(t_alias,host)
+    super(t_alias,host)
+  end
+    
+end  
+
+############################################
+# Host Extend from the native Class RbHost
+############################################
+class MSG::Host < MSG::RbHost
+
+  def getByName(name)
+    super(name)
+  end
+  
+  def name
+    super(self)
+  end
+  
+  def speed
+    super(self)
+  end
+  
+  def getData
+    super(self)
+  end
+  
+  def setData(data)
+    super(self,data)
+  end
+  
+  def isAvail
+    super(self)
+  end
+  
+  def number
+    super()
+  end
+  
+end
+
 #########################
 # Main chunck 
 #########################
index c8984e5..8bd78e6 100644 (file)
@@ -128,10 +128,10 @@ static void msg_debug(VALUE class,VALUE msg) {
   DEBUG1("%s",s);
 }
 
-// Get Clock FIXME: return the double instead of displaying it
-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());
 
 }
 
@@ -183,8 +183,8 @@ 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 FIXME: Convert to methods
   rb_define_module_function(rb_task,"new",(rb_meth)rb_task_new,3);