From: coldpeace Date: Fri, 19 Mar 2010 16:27:02 +0000 (+0000) Subject: Ruby Msg Binding : new Methods and new Example X-Git-Tag: SVN~461 X-Git-Url: http://info.iut-bm.univ-fcomte.fr/pub/gitweb/simgrid.git/commitdiff_plain/7bcd4cc9d936caa1d23579f7aca67e68fade2a36?ds=sidebyside Ruby Msg Binding : new Methods and new Example git-svn-id: svn+ssh://scm.gforge.inria.fr/svn/simgrid/simgrid/trunk@7278 48e7efb5-ca39-0410-a469-dd3cf9ba447f --- diff --git a/src/bindings/ruby/PingPong.rb b/src/bindings/ruby/PingPong.rb new file mode 100644 index 0000000000..2281b1d4e3 --- /dev/null +++ b/src/bindings/ruby/PingPong.rb @@ -0,0 +1,98 @@ +require 'simgrid' + +include MSG + +##################### +#PingPongTask Class +##################### + +class PingPongTask < MSG::Task + + + def initialize(*args) + #Has No Role, Since Its The Task Class ( Created from C ) tht will be called , + # and any instruction here will be ignored + end + + + +end + +#################### +# Sender Class +#################### + +class Sender < MSG::Process + + def main(args) + MSG::info("Hello from Sender") + hostCount = args.size + MSG::info("Host count :" + hostCount.to_s) + mailboxes = Array.new + + for i in 0..hostCount-1 + + mailboxes<< MSG::Host.getByName(args[i]).name + +# FIXME Handel Exceptions + end + + for i in 0..hostCount-1 + time = MSG.getClock.to_s # to send as a data >> must be a string + MSG::info("sender time :"+time.to_s) + task = PingPongTask.new("PingTask",10000,2000) + task.setData(time) + p "mailboxe >>> "+ mailboxes[i] + task.send(mailboxes[i]) + end + + MSG::info("GoodBye !!!") + + end + + end + +#################### +# Receiver Class +#################### + +class Receiver < MSG::Process + + def main(args) + + MSG::info("Hello from Receiver") + time = MSG.getClock + MSG::info("Try to get a task") + host = MSG::Host.getHostProcess(self) + task = PingPongTask.receive(host.name) + p "task name recevied : "+ task.name + p "data in the task :" + task.data + timeGot = MSG.getClock + timeSent= task.data + MSG::info("Got at time: "+timeGot.to_s) + MSG::info("Was sent at time "+timeSent.to_s) + communicationTime = timeGot - time + MSG::info("Communication Time: "+communicationTime.to_s) + MSG::info("--- bw "+(100000000/communicationTime).to_s+" ----") + MSG::info("GoodBye !!!") + end + + +end + +################################################# +# main chunck +################################################# + +if (ARGV.length == 2) + MSG.createEnvironment(ARGV[0]) + MSG.deployApplication(ARGV[1]) +else + MSG.createEnvironment("ping_pong_platform.xml") + MSG.deployApplication("ping_pong_deployment.xml") + +end + +MSG.run +MSG.exit + \ No newline at end of file diff --git a/src/bindings/ruby/ping_pong_deployment.xml b/src/bindings/ruby/ping_pong_deployment.xml new file mode 100644 index 0000000000..b02edda07d --- /dev/null +++ b/src/bindings/ruby/ping_pong_deployment.xml @@ -0,0 +1,8 @@ + + + + + + + + diff --git a/src/bindings/ruby/ping_pong_platform.xml b/src/bindings/ruby/ping_pong_platform.xml new file mode 100644 index 0000000000..39eddb29e4 --- /dev/null +++ b/src/bindings/ruby/ping_pong_platform.xml @@ -0,0 +1,90 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/src/bindings/ruby/rb_application_handler.c b/src/bindings/ruby/rb_application_handler.c index 63e465a3e6..f145531a7b 100644 --- a/src/bindings/ruby/rb_application_handler.c +++ b/src/bindings/ruby/rb_application_handler.c @@ -10,7 +10,7 @@ XBT_LOG_EXTERNAL_DEFAULT_CATEGORY(ruby); -// Used to instanciate the Process +// Used to instanciate the Process static VALUE args; static VALUE prop; static VALUE function_name; diff --git a/src/bindings/ruby/rb_msg_host.c b/src/bindings/ruby/rb_msg_host.c index 4ac3a82957..bab7b71b8c 100644 --- a/src/bindings/ruby/rb_msg_host.c +++ b/src/bindings/ruby/rb_msg_host.c @@ -70,3 +70,23 @@ VALUE rb_host_is_avail(VALUE class,VALUE host) { return Qfalse; } + +// getHost from process +VALUE rb_host_process(VALUE class,VALUE ruby_process) +{ + + m_process_t process = rb_process_to_native(ruby_process); + m_host_t host; + + + if (!process) { + rb_raise(rb_eRuntimeError,"Process Not Bound...while getting Host"); + return Qnil; // NULL + } + + host = MSG_process_get_host(process); + + return Data_Wrap_Struct(class, 0, rb_host_free, host); + + +} \ No newline at end of file diff --git a/src/bindings/ruby/rb_msg_process.c b/src/bindings/ruby/rb_msg_process.c index dbf8c556fb..9b0f18c09c 100644 --- a/src/bindings/ruby/rb_msg_process.c +++ b/src/bindings/ruby/rb_msg_process.c @@ -140,20 +140,24 @@ void rb_process_kill_down(VALUE class,VALUE ruby_process) { VALUE rb_process_getHost(VALUE class,VALUE ruby_process) { m_process_t process = rb_process_to_native(ruby_process); m_host_t host; + if (!process) { rb_raise(rb_eRuntimeError,"Process Not Bound...while getting Host"); return Qnil; // NULL } - + host = MSG_process_get_host(process); - + + return Data_Wrap_Struct(class, 0, rb_host_free, host); + /*if(host->data) printf("Ok\n"); + if(!host->data) { rb_raise (rb_eRuntimeError,"MSG_process_get_host() failed"); return Qnil; } - - return Data_Wrap_Struct(class, 0, rb_host_free, host); + printf("Houuuuuuuuuuuuuuna3!!\n"); + return Data_Wrap_Struct(class, 0, rb_host_free, host);*/ } void rb_process_exit(VALUE class,VALUE ruby_process) { diff --git a/src/bindings/ruby/rb_msg_task.c b/src/bindings/ruby/rb_msg_task.c index ea770cc9dc..dadc6f5d47 100644 --- a/src/bindings/ruby/rb_msg_task.c +++ b/src/bindings/ruby/rb_msg_task.c @@ -23,6 +23,26 @@ VALUE rb_task_new(VALUE class, VALUE name,VALUE comp_size,VALUE comm_size) { } +// set Data : For the Moment , we will consider Data as asimple String ( char * ) +void rb_task_set_data(VALUE class,VALUE task,VALUE data) +{ + const char *str_data = RSTRING(data)->ptr; + m_task_t tk; + Data_Get_Struct(task, s_m_task_t, tk); + tk->data = (void*)str_data; + +} + +// get Data +VALUE rb_task_get_data(VALUE class,VALUE task) +{ + m_task_t tk; + Data_Get_Struct(task, s_m_task_t, tk); + return rb_str_new2(tk->data); + +} + + //Get Computation Size VALUE rb_task_comp(VALUE class,VALUE task) { double size; @@ -144,3 +164,25 @@ VALUE rb_task_listen_host(VALUE class,VALUE task,VALUE alias,VALUE host) { return Qtrue; return Qfalse; } + + +// Set Priority +void rb_task_set_priority(VALUE class,VALUE task,VALUE priority) +{ + + m_task_t tk; + double prt = NUM2DBL(priority); + Data_Get_Struct(task,s_m_task_t,tk); + MSG_task_set_priority(tk,prt); + +} + +// Cancel +void rb_task_cancel(VALUE class,VALUE task) +{ + m_task_t tk; + Data_Get_Struct(task,s_m_task_t,tk); + MSG_task_cancel(tk); + +} + diff --git a/src/bindings/ruby/simgrid.rb b/src/bindings/ruby/simgrid.rb index 30dc1dfc6a..c618f33a61 100644 --- a/src/bindings/ruby/simgrid.rb +++ b/src/bindings/ruby/simgrid.rb @@ -72,7 +72,6 @@ class MSG::Process < Thread @name = args[0] @pargs = args[1] @properties = args[2] - start() } end @@ -134,7 +133,15 @@ end class MSG::Task < MSG::RbTask def initialize(*args) - super() + super() + end + + def setData(value) + super(self,value) + end + + def data() + super(self) end def name @@ -168,6 +175,15 @@ class MSG::Task < MSG::RbTask def listenFromHost(t_alias,host) super(t_alias,host) end + + def setPriority(priority) + super(self,priority) + end + + def cancel() + super(self) + end + end #################################################### # Host Extend from the native Class RbHost @@ -200,6 +216,11 @@ class MSG::Host < MSG::RbHost def number super() end + + def getHostProcess(process) + super(process) + end + end ######################### # Main chunck diff --git a/src/bindings/ruby/simgrid_ruby.c b/src/bindings/ruby/simgrid_ruby.c index c30de11a01..74fba1d147 100644 --- a/src/bindings/ruby/simgrid_ruby.c +++ b/src/bindings/ruby/simgrid_ruby.c @@ -65,7 +65,7 @@ static void msg_run(VALUE class) { DEBUG0 ("MSG_main finished. Bail out before cleanup since there is a bug in this part."); /* Cleanup Ruby hosts */ - DEBUG0("Clean Ruby World (TODO) "); + DEBUG0("Clean Ruby World "); hosts = MSG_get_host_table(); host_count = MSG_get_host_number(); for (cpt=0;cpt