Logo AND Algorithmique Numérique Distribuée

Public GIT Repository
Almost Done ... Still Stuckin' Wiith Some MSG Error while The Slave Should Recieve ...
authorcoldpeace <coldpeace@48e7efb5-ca39-0410-a469-dd3cf9ba447f>
Tue, 16 Feb 2010 16:41:43 +0000 (16:41 +0000)
committercoldpeace <coldpeace@48e7efb5-ca39-0410-a469-dd3cf9ba447f>
Tue, 16 Feb 2010 16:41:43 +0000 (16:41 +0000)
git-svn-id: svn+ssh://scm.gforge.inria.fr/svn/simgrid/simgrid/trunk@7104 48e7efb5-ca39-0410-a469-dd3cf9ba447f

19 files changed:
src/bindings/ruby/ApplicationHandler.rb
src/bindings/ruby/Makefile
src/bindings/ruby/Master.rb
src/bindings/ruby/MasterSlave.rb
src/bindings/ruby/ProcessFactory.rb
src/bindings/ruby/RubyHost.rb
src/bindings/ruby/RubyProcess.rb
src/bindings/ruby/RubyTask.rb
src/bindings/ruby/Semaphore.rb
src/bindings/ruby/Slave.rb
src/bindings/ruby/client.rb
src/bindings/ruby/essai2.c
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_process.c
src/bindings/ruby/rb_msg_process.h
src/bindings/ruby/rb_msg_task.c

index fd13dba..b55dc8e 100644 (file)
@@ -1,11 +1,17 @@
+# 
+#  * $Id$
+#  *
+#  * Copyright 2010 Martin Quinson, Mehdi Fekari           
+#  * All right reserved. 
+#  *
+#  * This program is free software; you can redistribute 
+#  * it and/or modify it under the terms of the license 
+#  *(GNU LGPL) which comes with this package. 
 require 'ProcessFactory'
-
-$DEBUG = true
-
+$DEBUG = false
 class ApplicationHandler
 
-  @processFactory
-  
+  @processFactory  
 #   Initialize
   def initialize()
      #Nothing todo
index 15e55fa..90b9c7b 100644 (file)
@@ -39,9 +39,9 @@ sitelibdir = $(sitedir)/$(ruby_version)
 
 CC = gcc
 LIBRUBY = $(LIBRUBY_SO)
-LIBRUBY_A = lib$(RUBY_SO_NAME)-static.a
-LIBRUBYARG_SHARED = -L../../.libs -l$(RUBY_SO_NAME) -lsimgrid
-LIBRUBYARG_STATIC = -l$(RUBY_SO_NAME)-static
+LIBRUBY_A = lib$(RUBY_SO_NAME)-static.a 
+LIBRUBYARG_SHARED = -l$(RUBY_SO_NAME) -I . ../../.libs/libsimgrid.a -ldl -llua5.1 
+LIBRUBYARG_STATIC = -l$(RUBY_SO_NAME)-static  
 
 RUBY_EXTCONF_H = 
 CFLAGS   =  -fPIC -fno-strict-aliasing -g -g -O2  -fPIC $(cflags) 
index c72321f..f2f1913 100644 (file)
@@ -3,22 +3,17 @@ require 'RubyProcess'
 
 include MSG
 
-class Master < RbProcess
-  
-  
+class Master < RbProcess  
   def initialize()
     super()
-    p RbHost.number()
-      
-    
   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 "Number of Args for Master = " + size.to_s
-   
+  # msg_main : that function that will be executed when Running Simulation
+  def msg_main(args) # args is an array Containin' arguments for function master
+    puts "Hey From Ruby...I'm The Master" 
+    size = args.size
+    puts "Number of Args for Master = " + size.to_s
    for i in 0..size-1
       puts  args[i]
    end
@@ -31,12 +26,13 @@ class Master < RbProcess
    
    #Creating & Sending Task
    for i in 0..numberOfTask
-     
+  
      task = RbTask.new("Task_" + i.to_s, taskComputeSize , taskCommunicationSize );
-     s_alias = "slave " + (i%slaveCount).to_s
+     s_alias = "slave>>" + (i%slaveCount).to_s
      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
@@ -48,4 +44,5 @@ class Master < RbProcess
    end
    puts "Master : Everything's Done"
   end  
-end
+  
+end
\ No newline at end of file
index 92ed0fc..f1f358b 100644 (file)
@@ -3,20 +3,18 @@ require 'RubyProcess'
 require 'Master'
 require 'Slave'
 
-include MSG
+include MSG
 
 # raise "Bad Number Of Arguments" if ARGV.length != 2 
 
 # info("Bye")
 
-init(ARGV)
-raise "Bad Number Of Arguments " if (ARGV.length < 2)
+MSG.init(ARGV)
+raise "Bad Number Of Arguments" if (ARGV.length < 2)
+#  p  Host.number()
+MSG.createEnvironment(ARGV[0])
+#  p  Host.number()
+MSG.deployApplication(ARGV[1])
 # p  Host.number()
-createEnvironment(ARGV[0])
-# p  Host.number()
-deployApplication(ARGV[1])
-# p  Host.number()
-
-# run()
+ MSG.run()
 # exit()
index ca34bd3..d31365f 100644 (file)
@@ -1,3 +1,12 @@
+# 
+#  * $Id$
+#  *
+#  * Copyright 2010 Martin Quinson, Mehdi Fekari           
+#  * All right reserved. 
+#  *
+#  * This program is free software; you can redistribute 
+#  * it and/or modify it under the terms of the license 
+#  *(GNU LGPL) which comes with this package. 
 require 'RubyProcess'
 require 'RubyHost'
 class ProcessFactory 
@@ -15,7 +24,6 @@ class ProcessFactory
     end
     
 #     setProcessIdentity
-    
     def setProcessIdentity(hostName,function)
       @hostName = hostName
       @function = function
@@ -30,28 +38,25 @@ class ProcessFactory
     
     end
 
-#     RegisterProcess
-    
-    def registerProcessArg( arg )
+#     RegisterProcess  
+    def registerProcessArg(arg)
       
-      args.push(arg)
+      @args.push(arg)
       
     end
 
 #     CreateProcess
     def createProcess()
       
-      process = rubyNewInstance(@function) 
-#       process = rubyNewInstanceArgs(@function,@args)
-      
-      process.name = @function
-      process.id = process.nextId() # This increment Automaticly  The Static ProcessNextId for The Class RbProces
-#       host = RbHost.getByName(@hostName)
-#       Process.createProcess(process,host)
+      process = rubyNewInstance(@function) #process = rubyNewInstanceArgs(@function,@args) #
       size = @args.size
       for i in 0..size-1
-       process.pargs.push(@args[i])
+       process.pargs.push(@args[i]) 
       end
+      process.name = @function
+      process.id = process.nextId() # This increment Automaticly  The Static ProcessNextId for The Class RbProces
+      host = RbHost.getByName(@hostName)
+      processCreate(process,host)
       process.proprieties = @proprieties
       @proprieties = Hash.new
       
@@ -59,9 +64,7 @@ class ProcessFactory
     
 #     SetProperty
     def setProperty(id,value)
-      
       @proprieties[id] = value
-      
     end
     
 #     End Class
index e6149c4..babdecb 100644 (file)
@@ -1,19 +1,24 @@
+# 
+#  * $Id$
+#  *
+#  * Copyright 2010 Martin Quinson, Mehdi Fekari           
+#  * All right reserved. 
+#  *
+#  * This program is free software; you can redistribute 
+#  * it and/or modify it under the terms of the license 
+#  *(GNU LGPL) which comes with this package. 
+
 require 'msg'
 include MSG
 
 class RbHost < Host
-  
-  
 # Attributes
   attr_accessor :bind, :data 
   
-  
 # Initialize
   def initialize()
     @bind = 0
     @data = nil
   end
   
-  
-
 end
\ No newline at end of file
index 113bf7c..5dce44c 100644 (file)
@@ -1,9 +1,17 @@
+# 
+#  * $Id$
+#  *
+#  * Copyright 2010 Martin Quinson, Mehdi Fekari           
+#  * All right reserved. 
+#  *
+#  * This program is free software; you can redistribute 
+#  * it and/or modify it under the terms of the license 
+#  *(GNU LGPL) which comes with this package. 
+
 require 'msg'
 require 'Semaphore'
 include MSG
-
-$DEBUG = true  # This is a Global Variable Useful for Debugging
-
+$DEBUG = false  # This is a Global Variable Useful for Debugging
 
 class RbProcess < Thread 
   @@nextProcessId = 0
@@ -15,40 +23,22 @@ class RbProcess < Thread
   def initialize(*args)
     
     argc = args.size
-#      Default Init***************************** No Args
-    if argc == 0    #>>> new()
+# Default initializer
+    if argc == 0    #>>> new()  
     super() {
     @id = 0
     @bind = 0
     @name = ""
     @pargs = Array.new()
     init_var()
+    start()
      if $DEBUG
-       puts "Init Default Initialzer..."
+       puts "Init Default Initialzer...Nothing to do...Bye"
      end  
-#     Thread.pass  
-#     sleep   # Sleep Forever ... To Keep Thread Alive ?!!
-    
     }
     end
-    
-    
-    # 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
-    
-  
-    
+       
     # Init with 2 arguments **********************>>>(HostName,Name) Or (Host , Name)
-    
     if argc == 2   
       super(){
       type = args[0].type()
@@ -70,19 +60,14 @@ class RbProcess < Thread
       @@nextProcessId += 1
       @id = @@nextProcessId
       init_var()
+      start()
       createProcess(self,host)
-      if $DEBUG
-      puts "Initilize with 2 args"
-      end
-      
-#       sleep  
+       if $DEBUG
+         puts "Initilize with 2 args"
+       end
       }
     
-    
     end
-    
-    
-    
        
     # Init with 3 arguments **********************(hostName,Name,args[]) or # (Host,Name,args[])
     
@@ -116,103 +101,90 @@ class RbProcess < Thread
 #       sleep #keep the thread running
        }
     end
-
     end
 
-    
-    # Init_var Called By Initialize  
-    
-    
-  def init_var()
-    
+  # Init_var Called By Initialize  
+  def init_var()  
     @proprieties = Hash.new()
     # Process Synchronization Tools
-     @schedBegin = Semaphore.new(0)
-     @schedEnd = Semaphore.new(0)
-      
+    @schedBegin = Semaphore.new(0)
+    @schedEnd = Semaphore.new(0)    
   end
   
+  #main
+  def msg_main(args)
+    # To Be Implemented within The Process...
+    # The Main Code of The Process to be Executed ...
+  end
+     
   
-  
-  
+  # Start : To keep the Process Alive and waitin' via semaphore
+  def start()
+    
+    @schedBegin.acquire()
+    #execute The Main Code of The Process ( Example Master ; Slave ...)     
+    msg_main(@pargs)
+    processExit(self) #Exite the Native Process
+    @schedEnd.release()
+  end
+    
 #   NetxId
   def nextId ()
-    
     @@nextProcessId +=1
     return @@nextProcessId
-    
   end
 
   if $DEBUG
     #Process List
     def processList()
-      
       Thread.list.each {|t| p t}
-      
     end
   end
   
-  
   #Get Own ID
-  
   def getID()
-    
     return @id
-    
   end
   
   # set Id
-  
   def setID(id)
-    
     @id = id
-    
   end
   
   #Get a Process ID
-  
   def processID(process)
-    
     return process.id
-  
   end
   
-    #get Own Name
-  
+  #Get Own Name
   def getName()
-   
     return @name
-  
   end
   
-  #get a Process Name
-  
+  #Get a Process Name
   def processName(process)
-  
     return process.name
-  
   end
   
-  #get Bind
+  #Get Bind
   def getBind()
-    
     return @bind
-    
   end
   
-  #set Binds
+  #Get Binds
   def setBind(bind)
-    
     @bind = bind
-    
   end
     
-      # Stop
-  
   def unschedule() 
-    
-    Thread.pass
+#     Thread.pass
+    @schedEnd.release()
+    @schedBegin.acquire()
+  end
   
+  def schedule()
+    @schedBegin.release()
+    @schedEnd.release()
   end
   
    #C Simualateur Process Equivalent  Management
@@ -220,32 +192,23 @@ class RbProcess < Thread
   
 #   pause
   def pause()
-  
     processSuspend(self)
-  
   end
   
 #   restart
   def restart()
-   
     processResume(self)
-  
   end
   
 #   isSuspended
   def isSuspended()
-  
     processIsSuspended(self)
   end
   
 #   getHost
   def getHost()
-  
     processGetHost(self)
-  
   end
   
-#    The Rest of Methods !!! To be Continued ...
-
+# The Rest of Methods !!! To be Continued ...
 end
\ No newline at end of file
index 5b0a313..9afbf10 100644 (file)
@@ -1,3 +1,12 @@
+# 
+#  * $Id$
+#  *
+#  * Copyright 2010 Martin Quinson, Mehdi Fekari           
+#  * All right reserved. 
+#  *
+#  * This program is free software; you can redistribute 
+#  * it and/or modify it under the terms of the license 
+#  *(GNU LGPL) which comes with this package. 
 require 'msg'
 include MSG
 
@@ -14,8 +23,5 @@ class RbTask < Task
     super(name,comp_size,comm_size)
     end
   
-    
-    
-
 
 end
\ No newline at end of file
index 8da1c42..d8697c5 100644 (file)
@@ -1,45 +1,45 @@
+# 
+#  * $Id$
+#  *
+#  * Copyright 2010 Martin Quinson, Mehdi Fekari           
+#  * All right reserved. 
+#  *
+#  * This program is free software; you can redistribute 
+#  * it and/or modify it under the terms of the license 
+#  *(GNU LGPL) which comes with this package. 
 require 'thread'
 class Semaphore
   
-  
   Thread.abort_on_exception = true
-
   attr_accessor :permits, :mutex, :cv
-  
-  
-  
+   
   def initialize ( permits )
     
-    
       @permits = permits
       @mutex = Mutex.new
       @cv = ConditionVariable.new
     
   end
-  
-  
+   
+
   def acquire()
 
     raise "Interrupted Thread " if (!Thread.current.alive?)
     @mutex.synchronize {
     while @permits < 1
-      @cv.wait(mutex)
+       @cv.wait(@mutex)
     end
     @permits = @permits - 1
     }
   end
     
-  
   def release()
     @mutex.synchronize{
-      @value = @value + 1
+      
+      @permits += 1
       @cv.signal
-         
+       
       }
-    
   end
   
-  
-
-  
 end
\ No newline at end of file
index 4dc12d0..07e848e 100644 (file)
@@ -8,12 +8,15 @@ class Slave < RbProcess
   def initialize()
     super()
   end
-    
-  def run(args)
+  
+ # msg_main : that function that will be executed when Running Simulation
+  def msg_main(args)
     puts "Hello From Slave"
-    s_mailbox = "slave" + args[0]
+    s_mailbox = "slave>>" + args[0]
     while true
-      task = RbTask.recieve(s_mailbox)
+     
+      p "Hellow...................here3 "+s_mailbox
+      task = RbTask.receive(s_mailbox)
       task_name = RbTask.name(task)
       if ( task_name == "finalize" )
        puts "Slave" + s_mailbox + "got finalize msg"
@@ -27,6 +30,5 @@ class Slave < RbProcess
     
   end
   
-  
 
 # slave = Slave.new
\ No newline at end of file
index 00419d3..96d7290 100644 (file)
@@ -20,17 +20,14 @@ mehdi = "Hey...this is my name"
 
 hash = Hash.new
 
-
 var = "name"
 
 hash[var] = mehdi
 
-
 # puts hash["name"]
 
 array.push(mehdi)
 
-
 #  info("Hey...")
 # puts array[0]
 
@@ -42,14 +39,13 @@ size = array2.size
 
 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()
+#host2 = Host.new()
 #  task_2 = Task.new('task2',12,23)
 #   name1 = task_2.name()
 #  name2 = Task.name(task)
@@ -57,36 +53,25 @@ Task.send(task,"MailBox")
 name = Task.name(task)
 # task.bind
 number = 56
-
 process = rubyNewInstance("RbProcess");#RbProcess.new()
+# process.run()
 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()
 # process2.name = "Hope"
-
 # reader = RubyXML.new();
 # reader.parseApplication("application.xml")
 # reader.printAll()
-
-
-
 # name2 = Task.test()
 # puts name
 # process2 = RbProcess.new()
-
-
-
- #  puts (name)
+# puts (name)
 # init(array)
 # createEnvironment(name);
-# Task.goodbye
-
-
+# Task.goodbye
\ No newline at end of file
index 18a3516..4707095 100644 (file)
@@ -66,11 +66,11 @@ int main(int argc, char ** argv)
   
   
   //keep...
-  VALUE current = rb_thread_current();
+  /*VALUE current = rb_thread_current(); // main One
   test = isAlive(current);
   
   if(TYPE(test) == T_TRUE)
-    printf("The Current Thread is Alive\n");
+    printf("The Current Thread is Alive\n");*/
     
   
   
index 11b5ce3..5d1f8e3 100644 (file)
@@ -1,3 +1,13 @@
+/*
+ * $Id$
+ *
+ * Copyright 2010 Martin Quinson, Mehdi Fekari           
+ * All right reserved. 
+ *
+ * This program is free software; you can redistribute 
+ * it and/or modify it under the terms of the license 
+ *(GNU LGPL) which comes with this package. 
+ */
 #include "rb_application_handler.h"
 #include "surf/surfxml_parse.h"
 #include <stdio.h>
@@ -16,7 +26,6 @@ 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);
@@ -29,7 +38,6 @@ static void  application_handler_on_start_document(void)
 
 static void  application_handler_on_end_document(void)
 {
-  
   //r_init();
   rb_funcall(current,rb_intern("onEndDocument"),0); 
 
@@ -59,23 +67,18 @@ static void  application_handler_on_process_arg(void)
 static void  application_handler_on_property(void)
 {
  
-  //r_init();
-  
+  //r_init()
    VALUE id = rb_str_new2(A_surfxml_prop_id);
    VALUE val =  rb_str_new2(A_surfxml_prop_value);
-  
    rb_funcall(current,rb_intern("onProperty"),2,id,val);
    
-   
 }
 
 
 static void application_handler_on_end_process(void)
 {
   
- //r_init();
+ //r_init()
  rb_funcall(current,rb_intern("onEndProcess"),0);
-  
-  
+    
 }
index 8e469a1..dcdc0a1 100644 (file)
@@ -1,3 +1,14 @@
+/*
+ * $Id$
+ *
+ * Copyright 2010 Martin Quinson, Mehdi Fekari           
+ * All right reserved. 
+ *
+ * This program is free software; you can redistribute 
+ * it and/or modify it under the terms of the license 
+ *(GNU LGPL) which comes with this package. 
+ */
+
 #include "rb_msg.h"
 #include "msg/msg.h"
 #include "msg/datatypes.h"
 #include "xbt/log.h"
 #include "xbt/asserts.h"
 #include "surf/surfxml_parse.h"
-
-
 #include "rb_msg_task.c"
 #include "rb_msg_host.c"
 #include "rb_msg_process.c"
 #include "rb_application_handler.c"
 
-
+#define DEBUG
 //Init Msg_Init From Ruby
-
-
 static void msg_init(VALUE Class,VALUE args)
 {
-  char **argv=NULL;  
+    
+  char **argv=NULL;    
   const char *tmp;
   int argc,type,i;
   VALUE *ptr ;
@@ -30,34 +37,33 @@ static void msg_init(VALUE Class,VALUE args)
     rb_raise(rb_eRuntimeError,"Argh!!! Bad Arguments to msg_init");
     return;
   }
-    
   ptr= RARRAY(args)->ptr;
   argc= RARRAY(args)->len;
-  
 //   Create C Array to Hold Data_Get_Struct 
-  argv = xbt_new0(char *, argc);  // argc or argc +1
+  argc++; 
+  argv = xbt_new0(char *, argc);  
   argv[0] = strdup("ruby");
-  for (i=0;i<argc;i++)
+  for (i=0;i<argc-1;i++)
   {
    VALUE value = ptr[i];
    type = TYPE(value);
 //  if (type == T_STRING)
    tmp = RSTRING(value)->ptr;
-   argv[i+1] = strdup(tmp);
-    
+   argv[i+1] = strdup(tmp); 
   }
-  
   // 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"); 
+  SIMIX_context_select_factory("ruby");
+       
   // Free Stuffs 
   for (i=0;i<argc;i++)
    free(argv[i]) ;
   
   free (argv);
+  #ifdef DEBUG
   printf("Msg Init...Done\n");
+  #endif
   return;
 }
 
@@ -65,34 +71,32 @@ static void msg_init(VALUE Class,VALUE args)
 static void msg_run(VALUE class)
 {
   
+ printf("msg_run msg_run msg_run msg_run...\n");
  xbt_fifo_item_t item = NULL;
  m_host_t host = NULL;
- VALUE rbHost;
-  
+ VALUE rbHost;  
  // Let's Run
+ //printf("msg_run3\n");
  if (MSG_OK != MSG_main()){
-   
    rb_raise(rb_eRuntimeError,"MSG_main() failed");
-   
  }
   DEBUG
     ("MSG_main finished. Bail out before cleanup since there is a bug in this part.");
      /* Cleanup Ruby hosts */
    DEBUG("Clean Ruby World");
    xbt_fifo_foreach(msg_global->host, item, host, m_host_t) {
-   
      //rbHost = (VALUE)host->data;// ??!!
-    
       }
     
+   printf("Let's Cleaaaaaaaaaaaaaaaaaaaaaaaan!!!\n"); 
    if (MSG_OK != MSG_clean()){
-    
      rb_raise(rb_eRuntimeError,"MSG_clean() failed");
    }
     return;
 }
 
-// Create Environment
+//Create Environment
 static void msg_createEnvironment(VALUE class,VALUE plateformFile)
 {
  
@@ -102,16 +106,13 @@ static void msg_createEnvironment(VALUE class,VALUE plateformFile)
    const char * platform =  RSTRING(plateformFile)->ptr;
    MSG_create_environment(platform);
    printf("Create Environment...Done\n");
+
  return; 
-  
 }
-
-
 //deploy Application
-
 static void msg_deployApplication(VALUE class,VALUE deploymentFile )
-{
+{   
   
     int type = TYPE(deploymentFile);
     if ( type != T_STRING )
@@ -137,18 +138,9 @@ static void msg_deployApplication(VALUE class,VALUE deploymentFile )
     surf_parse_close();   
     application_handler_on_end_document();
     printf("Deploy Application...Done\n");
+   
 }
 
-
-
-static void msg_registerFunction(VALUE class,VALUE function_name,VALUE code)
-{
-  
- char * fct_name = RSTRING(function_name)->ptr;
-// xbt_main_func_t fct_code
-  
-}
 // INFO
 static void msg_info(VALUE class,VALUE msg)
 {
@@ -156,7 +148,6 @@ static void msg_info(VALUE class,VALUE msg)
  INFO("%s",s);
 }
 
-
 // Get Clock
 static VALUE msg_get_clock(VALUE class)
 {
@@ -173,7 +164,6 @@ static void msg_paje_out(VALUE class,VALUE pajeFile)
   
 }
 
-
 // Ruby intropspection : Instanciate a ruby Class From its Name 
 // Used by ProcessFactory::createProcess
 
@@ -183,20 +173,19 @@ static VALUE msg_new_ruby_instance(VALUE class,VALUE className)
   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);
+  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);
+  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)
@@ -205,13 +194,10 @@ To Ruby
  the part after "Init_" is the name of the C extension specified in extconf.rb , not the name of C source file
  
 *****************************************************************************************************************/
-
 void Init_msg()
 {
-  
-  // Modules
+   // Modules
    rb_msg = rb_define_module("MSG");
-    
    //Associated Environment Methods!
    rb_define_method(rb_msg,"init",msg_init,1);
    rb_define_method(rb_msg,"run",msg_run,0);
@@ -230,11 +216,12 @@ void Init_msg()
    rb_define_method(rb_msg,"processIsSuspend",processIsSuspend,1);
    rb_define_method(rb_msg,"processKill",processKill,1);
    rb_define_method(rb_msg,"processGetHost",processGetHost,1);
-     
+   rb_define_method(rb_msg,"processExit",processExit,1);
+   
    //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    
    rb_define_module_function(rb_task,"new",task_new,3);
    rb_define_module_function(rb_task,"compSize",task_comp,1);
index b27cd57..c14656d 100644 (file)
@@ -30,10 +30,6 @@ static void msg_createEnvironment(VALUE Class,VALUE plateformFile);
 // deploy Application
 static void msg_deployApplication(VALUE Class,VALUE deploymntFile);
 
-
-// Register Function
-static void msg_registerFunction(VALUE Class,VALUE function_name,VALUE code);
-
 // Tools
 static void msg_info(VALUE Class,VALUE msg);
 
@@ -43,7 +39,6 @@ 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);
 
index 9216633..68b888a 100644 (file)
@@ -1,3 +1,13 @@
+/*
+ * $Id$
+ *
+ * Copyright 2010 Martin Quinson, Mehdi Fekari           
+ * All right reserved. 
+ *
+ * This program is free software; you can redistribute 
+ * it and/or modify it under the terms of the license 
+ *(GNU LGPL) which comes with this package. 
+ */
 #include "rb_msg_host.h"
 
 // Free Method
index 6fada0a..bb2b81e 100644 (file)
@@ -1,5 +1,17 @@
+/*
+ * $Id$
+ *
+ * Copyright 2010 Martin Quinson, Mehdi Fekari           
+ * All right reserved. 
+ *
+ * This program is free software; you can redistribute 
+ * it and/or modify it under the terms of the license 
+ *(GNU LGPL) which comes with this package. 
+ */
+
 #include "rb_msg_process.h"
 
+#define DEBUG
 // Init Ruby
 
 static void initRuby()
@@ -29,11 +41,9 @@ static VALUE process_getName( VALUE ruby_process )
   // instance = rb_funcall3(rb_const_get(rb_cObject, rb_intern("RbProcess")),  rb_intern("new"), 0, 0);
    return rb_funcall(ruby_process,rb_intern("getName"),0);
   
-  
 }
 
 // Get  Process ID
-
 static VALUE process_getID(VALUE ruby_process)
 {
 
@@ -43,30 +53,23 @@ static VALUE process_getID(VALUE ruby_process)
 }
 
 // Get Bind
-
 static VALUE process_getBind(VALUE ruby_process)
 {
  
   initRuby();
   return rb_funcall(ruby_process,rb_intern("getBind"),0);
   
-  
 }
 
 
 // Set Bind
-
 static void process_setBind(VALUE ruby_process,long bind)
 {
 
   initRuby();
-  
   VALUE r_bind = LONG2FIX(bind);
-  
   rb_funcall(ruby_process,rb_intern("setBind"),1,r_bind);
   
-  
-  
 }
 
 // isAlive
@@ -94,7 +97,6 @@ static void process_join( VALUE ruby_process )
 {
   
  initRuby();
  rb_funcall(ruby_process,rb_intern("join"),0);
   
 }
@@ -105,7 +107,6 @@ static void process_unschedule( VALUE ruby_process )
 {
  
   initRuby();
-  
   rb_funcall(ruby_process,rb_intern("unschedule"),0);
   
 }
@@ -114,17 +115,12 @@ static void process_unschedule( VALUE ruby_process )
 
 static void process_schedule( VALUE ruby_process )
 {
-  
+   
  initRuby();
- rb_funcall(ruby_process,rb_intern("run"),0);
+ rb_funcall(ruby_process,rb_intern("schedule"),0);
   
 }
 
-
-
-
-
 /***************************************************
 
 Function for Native Process ( Bound ) Management
@@ -139,15 +135,12 @@ static m_process_t process_to_native(VALUE ruby_process)
 {
   
   VALUE id = process_getBind(ruby_process);
-  
   if (!id)
   {
    rb_raise(rb_eRuntimeError,"Process Not Bound >>> id_Bind Null");
    return NULL;
   }
-  
   long l_id= FIX2LONG(id);
-  
   return (m_process_t)l_id;
   
 }
@@ -158,10 +151,8 @@ static void processBind(VALUE ruby_process,m_process_t process)
 {
   
   long bind = (long)(process);
-  
   process_setBind(ruby_process,bind);
   
-  
 }
 
 
@@ -173,33 +164,23 @@ static void processCreate(VALUE class,VALUE ruby_process,VALUE host)
  VALUE rbName;      // Name of Java Process instance
  m_process_t process; // Native Process to Create
  const char * name ; // Name of C Native Process
  char alias[MAX_ALIAS_NAME + 1 ] = {0};
-  
  msg_mailbox_t mailbox;
  rbName = process_getName(ruby_process);
+
  if(!rbName)
  {
-   
   rb_raise(rb_eRuntimeError,"Internal error : Process Name Cannot be NULL");
-  return;
-   
+  return; 
  } 
  // Allocate the data for the simulation
  process = xbt_new0(s_m_process_t,1);
  process->simdata = xbt_new0(s_simdata_process_t,1);
  // Do we Really Need to Create Ruby Process Instance , >> process is already a Ruby Process !! So..Keep on ;)
  // Bind The Ruby Process instance to The Native Process
  processBind(ruby_process,process); 
  name = RSTRING(rbName)->ptr;
  process->name = xbt_strdup(name);
  Data_Get_Struct(host,m_host_t,process->simdata->m_host);
 
  if(!(process->simdata->m_host)) // Not Binded
@@ -207,20 +188,22 @@ static void processCreate(VALUE class,VALUE ruby_process,VALUE host)
    free(process->simdata);
    free(process->data);
    free(process);
-   rb_raise(rb_eRuntimeError,"Host not bound");
+   rb_raise(rb_eRuntimeError,"Host not bound...while creating native process");
    return;
  }
  process->simdata->PID = msg_global->PID++; //  msg_global ??
- DEBUG 
+ /*DEBUG 
  ("fil in process %s/%s (pid=%d) %p (sd=%p, host=%p, host->sd=%p) ",
   process->name ,process->simdata->m_host->name,process->simdata->PID,
   process,process->simdata, process->simdata->m_host,
-  process->simdata->m_host->simdata);
-  
+  process->simdata->m_host->simdata);*/
+  
+ #ifdef DEBUG
+ printf("fill in process %s/%s (pid=%d) %p (sd%=%p , host=%p, host->sd=%p)\n",
+       process->name , process->simdata->m_host->name,process->simdata->PID,
+       process,process->simdata, process->simdata->m_host,
+       process->simdata->m_host->simdata);
+ #endif
   process->simdata->s_process =
   SIMIX_process_create(process->name,
                       (xbt_main_func_t)ruby_process,
@@ -228,9 +211,10 @@ static void processCreate(VALUE class,VALUE ruby_process,VALUE host)
                       process->simdata->m_host->simdata->smx_host->name,
                       0,NULL,NULL);
 
-
- DEBUG ( "context created (s_process=%p)",process->simdata->s_process);
+ //DEBUG ( "context created (s_process=%p)",process->simdata->s_process);
+ #ifdef DEBUG
+ printf("context created (s_process=%p)\n",process->simdata->s_process);
+ #endif
  if (SIMIX_process_self()) { // SomeOne Created Me !!
    process->simdata->PPID = MSG_process_get_PID(SIMIX_process_self()->data);
  }
@@ -238,18 +222,14 @@ static void processCreate(VALUE class,VALUE ruby_process,VALUE host)
  {
    process->simdata->PPID = -1;
  }
-  
   process->simdata->last_errno = MSG_OK;
-  
   // let's Add the Process to the list of the Simulation's Processes
-  
   xbt_fifo_unshift(msg_global->process_list,process);
-  
   sprintf(alias,"%s:%s",(process->simdata->m_host->simdata->smx_host)->name,
          process->name);
          
   mailbox = MSG_mailbox_new(alias);
-  
+
 }
 
 
@@ -262,7 +242,7 @@ static void processSuspend(VALUE class,VALUE ruby_process)
   
   if (!process)
   {
-    rb_raise(rb_eRuntimeError,"Process Not Bound");
+    rb_raise(rb_eRuntimeError,"Process Not Bound...while suspending process");
     return;  
   }
   
@@ -276,15 +256,12 @@ static void processSuspend(VALUE class,VALUE ruby_process)
 
 static void processResume(VALUE class,VALUE ruby_process)
 {
-  
   m_process_t process = process_to_native(ruby_process);
-  
   if (!process)
   {
-    rb_raise(rb_eRuntimeError,"Process not Bound");
+    rb_raise(rb_eRuntimeError,"Process not Bound...while resuming process");
     return ;
   }
-  
   // Trying to resume the process
   if ( MSG_OK != MSG_process_resume(process))
     rb_raise(rb_eRuntimeError,"MSG_process_resume() failed");
@@ -295,10 +272,9 @@ static VALUE processIsSuspend(VALUE class,VALUE ruby_process)
 {
   
   m_process_t process = process_to_native(ruby_process);
-  
   if (!process)
   {
-    rb_raise (rb_eRuntimeError,"Process not Bound");
+    rb_raise (rb_eRuntimeError,"Process not Bound...while testing if suspended");
     return;
   }
   
@@ -310,14 +286,13 @@ static VALUE processIsSuspend(VALUE class,VALUE ruby_process)
   
 }
 
-
 static void processKill(VALUE class,VALUE ruby_process)
 {
  m_process_t process = process_to_native(ruby_process);
  
  if(!process)
  {
-  rb_raise (rb_eRuntimeError,"Process Not Bound");
+  rb_raise (rb_eRuntimeError,"Process Not Bound...while killing process");
   return ;
  }
   // Delete The Global Reference / Ruby Process
@@ -331,12 +306,11 @@ static VALUE processGetHost(VALUE class,VALUE ruby_process)
 {
   
   m_process_t process = process_to_native(ruby_process);
-  
   m_host_t host;
   
   if (!process)
   {
-  rb_raise(rb_eRuntimeError,"Process Not Bound");
+  rb_raise(rb_eRuntimeError,"Process Not Bound...while getting Host");
   return Qnil; // NULL
   }
   
@@ -346,9 +320,21 @@ static VALUE processGetHost(VALUE class,VALUE ruby_process)
   {
    rb_raise (rb_eRuntimeError,"MSG_process_get_host() failed");
    return Qnil;
-    
   }
   
    return Data_Wrap_Struct(class, 0, host_free, host);
   
+}
+
+static void processExit(VALUE class,VALUE ruby_process)
+{
+  
+  m_process_t process = process_to_native(ruby_process);
+  if(!process)
+  {
+   rb_raise(rb_eRuntimeError,"Process Not Bound...while exiting process");
+   return;
+  }
+  SIMIX_context_stop(SIMIX_process_self()->context);
+  
 }
\ No newline at end of file
index d51b398..860f9a2 100644 (file)
@@ -14,7 +14,6 @@
 #include "xbt/sysdep.h"        
 #include "xbt/log.h"
 #include "xbt/asserts.h"
-
 #include "rb_msg_host.h"
 
 
@@ -25,8 +24,6 @@ There are 2 section in This File:
 2 - Functions to Manage The Native Process Simulation Bound >> Down Call
 
 ***************************************************************************/
-
-
 // Init Ruby : To Call Ruby Methods From C
 
 static void initRuby();
@@ -102,5 +99,7 @@ static void processKill(VALUE Class,VALUE ruby_process);
 //ProcessGetHost
 static VALUE processGetHost(VALUE Class,VALUE ruby_process);
 
+//ProcessExit
+static void processExit(VALUE Class,VALUE ruby_process); 
 
 #endif
\ No newline at end of file
index 1d0e7c3..8043af4 100644 (file)
@@ -1,6 +1,15 @@
+/*
+ * $Id$
+ *
+ * Copyright 2010 Martin Quinson, Mehdi Fekari           
+ * All right reserved. 
+ *
+ * This program is free software; you can redistribute 
+ * it and/or modify it under the terms of the license 
+ *(GNU LGPL) which comes with this package. 
+ */
 #include "rb_msg_task.h"
 
-
 // Free Method
 static void task_free(m_task_t tk) {
   MSG_task_destroy(tk);