+#
+# * $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
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)
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
#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
end
puts "Master : Everything's Done"
end
-end
+
+end
\ No newline at end of file
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()
+#
+# * $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
end
# setProcessIdentity
-
def setProcessIdentity(hostName,function)
@hostName = hostName
@function = function
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
# SetProperty
def setProperty(id,value)
-
@proprieties[id] = value
-
end
# End Class
+#
+# * $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
+#
+# * $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
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()
@@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[])
# 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
# 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
+#
+# * $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
super(name,comp_size,comm_size)
end
-
-
-
end
\ No newline at end of file
+#
+# * $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
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"
end
-
# slave = Slave.new
\ No newline at end of file
hash = Hash.new
-
var = "name"
hash[var] = mehdi
-
# puts hash["name"]
array.push(mehdi)
-
# info("Hey...")
# puts array[0]
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)
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
//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");*/
+/*
+ * $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>
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);
static void application_handler_on_end_document(void)
{
-
//r_init();
rb_funcall(current,rb_intern("onEndDocument"),0);
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);
-
-
+
}
+/*
+ * $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 ;
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;
}
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)
{
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 )
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)
{
INFO("%s",s);
}
-
// Get Clock
static VALUE msg_get_clock(VALUE class)
{
}
-
// Ruby intropspection : Instanciate a ruby Class From its Name
// Used by ProcessFactory::createProcess
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)
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);
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);
// 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);
//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);
+/*
+ * $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
+/*
+ * $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()
// 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)
{
}
// 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
{
initRuby();
-
rb_funcall(ruby_process,rb_intern("join"),0);
}
{
initRuby();
-
rb_funcall(ruby_process,rb_intern("unschedule"),0);
}
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
{
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;
}
{
long bind = (long)(process);
-
process_setBind(ruby_process,bind);
-
}
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
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,
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);
}
{
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);
-
+
}
if (!process)
{
- rb_raise(rb_eRuntimeError,"Process Not Bound");
+ rb_raise(rb_eRuntimeError,"Process Not Bound...while suspending process");
return;
}
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");
{
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;
}
}
-
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
{
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
}
{
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
#include "xbt/sysdep.h"
#include "xbt/log.h"
#include "xbt/asserts.h"
-
#include "rb_msg_host.h"
2 - Functions to Manage The Native Process Simulation Bound >> Down Call
***************************************************************************/
-
-
// Init Ruby : To Call Ruby Methods From C
static void initRuby();
//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
+/*
+ * $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);