From 762740361e42dd14f5d24d239a29a1e08895ef64 Mon Sep 17 00:00:00 2001 From: mquinson Date: Mon, 1 Mar 2010 15:49:06 +0000 Subject: [PATCH] Use my axe to get ruby bindings compiling. Need to get them working now git-svn-id: svn+ssh://scm.gforge.inria.fr/svn/simgrid/simgrid/trunk@7152 48e7efb5-ca39-0410-a469-dd3cf9ba447f --- src/Makefile.am | 5 +- src/bindings/ruby/rb_msg_host.c | 15 ++-- src/bindings/ruby/rb_msg_process.c | 2 +- src/bindings/ruby/rb_msg_task.c | 119 +++++++++-------------------- src/bindings/ruby/rb_msg_task.h | 58 -------------- src/bindings/ruby_bindings.h | 14 ++++ src/simix/smx_context_lua.c | 2 +- 7 files changed, 60 insertions(+), 155 deletions(-) delete mode 100644 src/bindings/ruby/rb_msg_task.h diff --git a/src/Makefile.am b/src/Makefile.am index 303d760870..dca45a9ebd 100644 --- a/src/Makefile.am +++ b/src/Makefile.am @@ -384,7 +384,10 @@ else EXTRA_DIST += $(LUA_SRC) endif -RUBY_SRC= simix/smx_context_ruby.c bindings/ruby/rb_msg_process.c +RUBY_SRC= simix/smx_context_ruby.c \ + bindings/ruby/rb_msg_process.c \ + bindings/ruby/rb_msg_host.c \ + bindings/ruby/rb_msg_task.c if HAVE_RUBY simgrid_sources += $(RUBY_SRC) else diff --git a/src/bindings/ruby/rb_msg_host.c b/src/bindings/ruby/rb_msg_host.c index cae895f669..f4ecd65962 100644 --- a/src/bindings/ruby/rb_msg_host.c +++ b/src/bindings/ruby/rb_msg_host.c @@ -20,7 +20,7 @@ VALUE rb_host_get_by_name(VALUE class, VALUE 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,rb_host_free,host); } @@ -29,41 +29,38 @@ VALUE rb_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); + Data_Get_Struct(host, s_m_host_t, ht); return rb_str_new2(MSG_host_get_name(ht)); } // Get Number VALUE rb_host_number(VALUE class) { - return INT2NUM(MSG_get_host_number()); - } // Host Speed ( Double ) VALUE rb_host_speed(VALUE class,VALUE host) { m_host_t ht ; - Data_Get_Struct(host,m_host_t,ht); + Data_Get_Struct(host,s_m_host_t,ht); return MSG_get_host_speed(ht); - } // Host Set Data void rb_host_set_data(VALUE class,VALUE host,VALUE data) { - //... + THROW_UNIMPLEMENTED; } // Host Get Data VALUE rb_host_get_data(VALUE class,VALUE host) { - //... + THROW_UNIMPLEMENTED; return Qnil; } // Host is Avail VALUE rb_host_is_avail(VALUE class,VALUE host) { m_host_t ht; - Data_Get_Struct(host,m_host_t,ht); + Data_Get_Struct(host,s_m_host_t,ht); if (!ht) { rb_raise(rb_eRuntimeError,"Host not Bound"); return Qnil; diff --git a/src/bindings/ruby/rb_msg_process.c b/src/bindings/ruby/rb_msg_process.c index 202becc127..b19e39e1f9 100644 --- a/src/bindings/ruby/rb_msg_process.c +++ b/src/bindings/ruby/rb_msg_process.c @@ -130,7 +130,7 @@ void rb_process_create(VALUE class,VALUE ruby_process,VALUE host) { rb_process_bind(ruby_process,process); name = RSTRING(rbName)->ptr; process->name = xbt_strdup(name); - Data_Get_Struct(host,m_host_t,process->simdata->m_host); + Data_Get_Struct(host,s_m_host_t,process->simdata->m_host); if(!(process->simdata->m_host)) // Not Binded { diff --git a/src/bindings/ruby/rb_msg_task.c b/src/bindings/ruby/rb_msg_task.c index 9334a12bd4..0de3ffa898 100644 --- a/src/bindings/ruby/rb_msg_task.c +++ b/src/bindings/ruby/rb_msg_task.c @@ -1,135 +1,110 @@ /* - * $Id$ - * - * Copyright 2010 Martin Quinson, Mehdi Fekari - * All right reserved. + * Copyright 2010. The SimGrid Team. 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" +#include "bindings/ruby_bindings.h" // Free Method -static void task_free(m_task_t tk) { +void rb_task_free(m_task_t tk) { MSG_task_destroy(tk); } // New Method -static VALUE task_new(VALUE class, VALUE name,VALUE comp_size,VALUE comm_size) -{ - +VALUE rb_task_new(VALUE class, VALUE name,VALUE comp_size,VALUE comm_size) { //char * t_name = RSTRING(name)->ptr; m_task_t task = MSG_task_create(RSTRING(name)->ptr,NUM2INT(comp_size),NUM2INT(comm_size),NULL); // Wrap m_task_t to a Ruby Value - return Data_Wrap_Struct(class, 0, task_free, task); + return Data_Wrap_Struct(class, 0, rb_task_free, task); } //Get Computation Size -static VALUE task_comp(VALUE class,VALUE task) -{ +VALUE rb_task_comp(VALUE class,VALUE task) { double size; m_task_t tk; // Wrap Ruby Value to m_task_t struct - Data_Get_Struct(task, m_task_t, tk); + Data_Get_Struct(task, s_m_task_t, tk); size = MSG_task_get_compute_duration(tk); return rb_float_new(size); } //Get Name -static VALUE task_name(VALUE class,VALUE task) -{ +VALUE rb_task_name(VALUE class,VALUE task) { // Wrap Ruby Value to m_task_t struct m_task_t tk; - Data_Get_Struct(task, m_task_t, tk); + Data_Get_Struct(task, s_m_task_t, tk); return rb_str_new2(MSG_task_get_name(tk)); - } // Execute Task -static VALUE task_execute(VALUE class,VALUE task) -{ +VALUE rb_task_execute(VALUE class,VALUE task) { // Wrap Ruby Value to m_task_t struct m_task_t tk; - Data_Get_Struct(task, m_task_t, tk); + Data_Get_Struct(task, s_m_task_t, tk); return INT2NUM(MSG_task_execute(tk)); - } // Sending Task -static void task_send(VALUE class,VALUE task,VALUE mailbox) -{ +void rb_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); + Data_Get_Struct(task, s_m_task_t, tk); int res = MSG_task_send(tk,RSTRING(mailbox)->ptr); if(res != MSG_OK) rb_raise(rb_eRuntimeError,"MSG_task_send failed"); - - return; } -// Recieving Task - -/** -*It Return a Task -*/ - -static VALUE task_receive(VALUE class,VALUE mailbox) -{ +// Receiving Task (returns a Task) +VALUE rb_task_receive(VALUE class,VALUE mailbox) { // Task m_task_t task = NULL; MSG_task_receive(&task,RSTRING(mailbox)->ptr); - return Data_Wrap_Struct(class, 0, task_free, task); + return Data_Wrap_Struct(class, 0, rb_task_free, task); } // Recieve Task 2 // Not Appreciated -static void task_receive2(VALUE class,VALUE task,VALUE mailbox) -{ +void rb_task_receive2(VALUE class,VALUE task,VALUE mailbox) { m_task_t tk; - Data_Get_Struct(task, m_task_t, tk); + Data_Get_Struct(task, s_m_task_t, tk); MSG_task_receive(&tk,RSTRING(mailbox)->ptr); - } // It Return a Native Process ( m_process_t ) -static VALUE task_sender(VALUE class,VALUE task) -{ +VALUE rb_task_sender(VALUE class,VALUE task) { m_task_t tk; - Data_Get_Struct(task,m_task_t,tk); - return MSG_task_get_sender(tk); - + Data_Get_Struct(task,s_m_task_t,tk); + THROW_UNIMPLEMENTED; + return 0;//MSG_task_get_sender(tk); } // it return a Host -static VALUE task_source(VALUE class,VALUE task) -{ +VALUE rb_task_source(VALUE class,VALUE task) { m_task_t tk; - Data_Get_Struct(task,m_task_t,tk); + Data_Get_Struct(task,s_m_task_t,tk); m_host_t host = MSG_task_get_source(tk); - if(!host->data) - { + if(!host->data) { rb_raise(rb_eRuntimeError,"MSG_task_get_source() failed"); return Qnil; } - return host; - + THROW_UNIMPLEMENTED; + return 0;//host; } // Return Boolean -static VALUE task_listen(VALUE class,VALUE task,VALUE alias) -{ +VALUE rb_task_listen(VALUE class,VALUE task,VALUE alias) { m_task_t tk; const char *p_alias; int rv; - Data_Get_Struct(task,m_task_t,tk); + Data_Get_Struct(task,s_m_task_t,tk); p_alias = RSTRING(alias)->ptr; rv = MSG_task_listen(p_alias); @@ -137,51 +112,25 @@ static VALUE task_listen(VALUE class,VALUE task,VALUE alias) if(rv) return Qtrue; return Qfalse; - } // return Boolean -static VALUE task_listen_host(VALUE class,VALUE task,VALUE alias,VALUE host) -{ +VALUE rb_task_listen_host(VALUE class,VALUE task,VALUE alias,VALUE host) { m_task_t tk; m_host_t ht; const char *p_alias; int rv; - Data_Get_Struct(task,m_task_t,tk); - Data_Get_Struct(host,m_host_t,ht); + Data_Get_Struct(task,s_m_task_t,tk); + Data_Get_Struct(host,s_m_host_t,ht); p_alias = RSTRING(alias)->ptr; rv = MSG_task_listen_from_host(p_alias,ht); - if (rv) return Qtrue; - + if (rv) + return Qtrue; return Qfalse; - } -// Put -static void task_put(VALUE class,VALUE task,VALUE host) -{ - - m_task_t tk; - m_host_t ht; - - Data_Get_Struct(task,m_task_t,tk); - Data_Get_Struct(host,m_host_t,ht); - MSG_task_put(tk,ht,PORT_22); //Channel set to 0 - -} - -//get -static VALUE task_get(VALUE class) -{ - - m_task_t task = NULL; - int res = MSG_task_get(&task,PORT_22); // Channel set to 0 - xbt_assert0(res == MSG_OK, "MSG_task_get failed"); - return Data_Wrap_Struct(class, 0, task_free, task); - -} diff --git a/src/bindings/ruby/rb_msg_task.h b/src/bindings/ruby/rb_msg_task.h deleted file mode 100644 index 131196da74..0000000000 --- a/src/bindings/ruby/rb_msg_task.h +++ /dev/null @@ -1,58 +0,0 @@ -#ifndef RB_MSG_TASK_H -#define RB_MSG_TASK_H - -#include -#include -#include "msg/msg.h" -#include "msg/datatypes.h" -#include "xbt/sysdep.h" -#include "xbt/log.h" -#include "xbt/asserts.h" - -typedef enum { - PORT_22 = 0, - MAX_CHANNEL -} channel_t; - -// Free Method -static void task_free(m_task_t tk); - -// New Method >>> Data NULL -static VALUE task_new(VALUE Class, VALUE name,VALUE comp_size,VALUE comm_size); - -//Get Computation Size -static VALUE task_comp(VALUE Class,VALUE task); - -//Get Name -static VALUE task_name(VALUE Class,VALUE task); - -// Execute Task -static VALUE task_execute(VALUE Class,VALUE task); - -// Sending Task -static void task_send(VALUE Class,VALUE task,VALUE mailbox); - -// Recieve : return a task -static VALUE task_receive(VALUE Class,VALUE mailbox); - -// Recieve Task 2 << Not Appreciated -static void task_receive2(VALUE Class,VALUE task,VALUE mailbox); - -// Get Sender -static VALUE task_sender(VALUE Class,VALUE task); - -// Get Source -static VALUE task_source(VALUE Class,VALUE task); - -//Listen From Alias -static VALUE task_listen(VALUE Class,VALUE task,VALUE alias); - -//Listen from Host -static VALUE task_listen_host(VALUE Class,VALUE task,VALUE alias,VALUE host); - -// put -static void task_put(VALUE Class,VALUE task,VALUE host); - -//get -static VALUE task_get(VALUE Class); -#endif \ No newline at end of file diff --git a/src/bindings/ruby_bindings.h b/src/bindings/ruby_bindings.h index 82a8e30573..fca1ace4b9 100644 --- a/src/bindings/ruby_bindings.h +++ b/src/bindings/ruby_bindings.h @@ -102,5 +102,19 @@ void rb_host_set_data(VALUE Class,VALUE host,VALUE data); VALUE rb_host_get_data(VALUE Class,VALUE host); VALUE rb_host_is_avail(VALUE Class,VALUE host); +/* Functions related to tasks */ +void rb_task_free(m_task_t tk); +// New Method >>> Data NULL +VALUE rb_task_new(VALUE Class, VALUE name,VALUE comp_size,VALUE comm_size); +VALUE rb_task_comp(VALUE Class,VALUE task); // Get Computation Size +VALUE rb_task_name(VALUE Class,VALUE task); +VALUE rb_task_execute(VALUE Class,VALUE task); +void rb_task_send(VALUE Class,VALUE task,VALUE mailbox); +VALUE rb_task_receive(VALUE Class,VALUE mailbox);// Receive : return a task +void rb_task_receive2(VALUE Class,VALUE task,VALUE mailbox);// Receive Task 2 << Not Appreciated +VALUE rb_task_sender(VALUE Class,VALUE task); +VALUE rb_task_source(VALUE Class,VALUE task); +VALUE rb_task_listen(VALUE Class,VALUE task,VALUE alias); //Listen From Alias (=mailbox) +VALUE rb_task_listen_host(VALUE Class,VALUE task,VALUE alias,VALUE host); //Listen from Host #endif /* RB_SG_BINDINGS */ diff --git a/src/simix/smx_context_lua.c b/src/simix/smx_context_lua.c index 499a8ad60e..d47c1b1103 100644 --- a/src/simix/smx_context_lua.c +++ b/src/simix/smx_context_lua.c @@ -25,7 +25,7 @@ // FIXME: better location for that extern void MSG_register(lua_State *L); -XBT_LOG_EXTERNAL_DEFAULT_CATEGORY(smx_lua); +XBT_LOG_EXTERNAL_DEFAULT_CATEGORY(lua); typedef struct s_smx_ctx_sysv { SMX_CTX_BASE_T; -- 2.20.1