From: mquinson Date: Mon, 1 Mar 2010 15:11:01 +0000 (+0000) Subject: More ruby cleanups: stop defining everything static, and prefix functions with rb_... X-Git-Tag: SVN~588 X-Git-Url: http://info.iut-bm.univ-fcomte.fr/pub/gitweb/simgrid.git/commitdiff_plain/d15a4cc7241eb025d70551d1fd7eff95d99bf167?ds=sidebyside More ruby cleanups: stop defining everything static, and prefix functions with rb_ instead git-svn-id: svn+ssh://scm.gforge.inria.fr/svn/simgrid/simgrid/trunk@7150 48e7efb5-ca39-0410-a469-dd3cf9ba447f --- diff --git a/src/bindings/lua/Msglua.c b/src/bindings/lua/Msglua.c index 29cf399ae1..e152066f22 100644 --- a/src/bindings/lua/Msglua.c +++ b/src/bindings/lua/Msglua.c @@ -11,6 +11,7 @@ #include "xbt/asserts.h" +XBT_LOG_NEW_DEFAULT_SUBCATEGORY(lua,bindings,"Lua Bindings"); /* @@ -22,9 +23,6 @@ */ -XBT_LOG_NEW_DEFAULT_SUBCATEGORY(smx_lua,simix, - "Messages specific for this lua example"); - #define TASK "Msg.Task" #define HOST "Msg.Host" diff --git a/src/bindings/ruby/rb_msg_host.c b/src/bindings/ruby/rb_msg_host.c index 68b888a0d7..cae895f669 100644 --- a/src/bindings/ruby/rb_msg_host.c +++ b/src/bindings/ruby/rb_msg_host.c @@ -1,23 +1,19 @@ /* - * $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_host.h" +#include "bindings/ruby_bindings.h" // Free Method -static void host_free(m_host_t ht) { +void rb_host_free(m_host_t ht) { //Nothing to do !!? } // New Method : return a Host -static VALUE host_get_by_name(VALUE class, VALUE name) -{ +VALUE rb_host_get_by_name(VALUE class, VALUE name) { const char * h_name = RSTRING(name)->ptr; m_host_t host = MSG_get_host_by_name(h_name); @@ -29,8 +25,7 @@ static VALUE host_get_by_name(VALUE class, VALUE name) } //Get Name -static VALUE host_name(VALUE class,VALUE host) -{ +VALUE rb_host_name(VALUE class,VALUE host) { // Wrap Ruby Value to m_host_t struct m_host_t ht; @@ -40,16 +35,14 @@ static VALUE host_name(VALUE class,VALUE host) } // Get Number -static VALUE host_number(VALUE class) -{ +VALUE rb_host_number(VALUE class) { return INT2NUM(MSG_get_host_number()); } // Host Speed ( Double ) -static VALUE host_speed(VALUE class,VALUE host) -{ +VALUE rb_host_speed(VALUE class,VALUE host) { m_host_t ht ; Data_Get_Struct(host,m_host_t,ht); return MSG_get_host_speed(ht); @@ -57,26 +50,21 @@ static VALUE host_speed(VALUE class,VALUE host) } // Host Set Data -static void host_set_data(VALUE class,VALUE host,VALUE data) -{ +void rb_host_set_data(VALUE class,VALUE host,VALUE data) { //... } // Host Get Data -static VALUE host_get_data(VALUE class,VALUE host) -{ +VALUE rb_host_get_data(VALUE class,VALUE host) { //... return Qnil; } // Host is Avail -static VALUE host_is_avail(VALUE class,VALUE host) -{ - +VALUE rb_host_is_avail(VALUE class,VALUE host) { m_host_t ht; Data_Get_Struct(host,m_host_t,ht); - if (!ht) - { + if (!ht) { rb_raise(rb_eRuntimeError,"Host not Bound"); return Qnil; } diff --git a/src/bindings/ruby/rb_msg_host.h b/src/bindings/ruby/rb_msg_host.h deleted file mode 100644 index 911ac533aa..0000000000 --- a/src/bindings/ruby/rb_msg_host.h +++ /dev/null @@ -1,32 +0,0 @@ -#ifndef RB_MSG_HOST -#define RB_MSG_HOST - -#include -#include "msg/msg.h" - -// Free Method -static void host_free(m_host_t ht); - -// New Method -static VALUE host_get_by_name(VALUE Class, VALUE name); - -//Get Name -static VALUE host_name(VALUE Class,VALUE host); - -//Get Number -static VALUE host_number(VALUE Class); - -// get Speed -static VALUE host_speed(VALUE Class,VALUE host); - -// Set Data -static void host_set_data(VALUE Class,VALUE host,VALUE data); - -// Get Data -static VALUE host_get_data( VALUE Class,VALUE host); - - -//is Available -static VALUE host_is_avail(VALUE Class,VALUE host); - -#endif \ 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 e6df224d29..202becc127 100644 --- a/src/bindings/ruby/rb_msg_process.c +++ b/src/bindings/ruby/rb_msg_process.c @@ -6,9 +6,11 @@ *(GNU LGPL) which comes with this package. */ +#include "msg/private.h" /* s_simdata_process_t */ #include "bindings/ruby_bindings.h" -#define DEBUG +XBT_LOG_NEW_DEFAULT_SUBCATEGORY(ruby,bindings,"Ruby Bindings"); + // Init Ruby void initRuby(void) { ruby_init(); @@ -31,77 +33,53 @@ VALUE rb_process_getName(VALUE ruby_process) { } // Get Process ID -static VALUE process_getID(VALUE ruby_process) -{ - +VALUE rb_process_getID(VALUE ruby_process) { initRuby(); return rb_funcall(ruby_process,rb_intern("getID"),0); - } // Get Bind -static VALUE process_getBind(VALUE ruby_process) -{ - +VALUE rb_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) -{ - +void rb_process_setBind(VALUE ruby_process,long bind) { initRuby(); VALUE r_bind = LONG2FIX(bind); rb_funcall(ruby_process,rb_intern("setBind"),1,r_bind); - } // isAlive -static VALUE process_isAlive(VALUE ruby_process) -{ - +VALUE rb_process_isAlive(VALUE ruby_process) { initRuby(); return rb_funcall(ruby_process,rb_intern("alive?"),0); - } // Kill Process -static void process_kill(VALUE ruby_process) -{ - +void rb_process_kill_up(VALUE ruby_process) { initRuby(); rb_funcall(ruby_process,rb_intern("kill"),0); - } // join Process -static void process_join( VALUE ruby_process ) -{ - +void rb_process_join( VALUE ruby_process ) { initRuby(); rb_funcall(ruby_process,rb_intern("join"),0); - } // unschedule Process -static void process_unschedule( VALUE ruby_process ) -{ - +void rb_process_unschedule( VALUE ruby_process ) { initRuby(); rb_funcall(ruby_process,rb_intern("unschedule"),0); - } // schedule Process -static void process_schedule( VALUE ruby_process ) -{ - +void rb_process_schedule( VALUE ruby_process ) { initRuby(); rb_funcall(ruby_process,rb_intern("schedule"),0); - } /*************************************************** @@ -113,43 +91,32 @@ Methods Belong to MSG Module ****************************************************/ // Process To Native - -static m_process_t process_to_native(VALUE ruby_process) -{ - - VALUE id = process_getBind(ruby_process); - if (!id) - { +m_process_t rb_process_to_native(VALUE ruby_process) { + VALUE id = rb_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; - } // Bind Process - -static void processBind(VALUE ruby_process,m_process_t process) -{ - +void rb_process_bind(VALUE ruby_process,m_process_t process) { long bind = (long)(process); - process_setBind(ruby_process,bind); - + rb_process_setBind(ruby_process,bind); } // processCreate -static void processCreate(VALUE class,VALUE ruby_process,VALUE host) -{ - +void rb_process_create(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); + rbName = rb_process_getName(ruby_process); if(!rbName) { rb_raise(rb_eRuntimeError,"Internal error : Process Name Cannot be NULL"); @@ -160,7 +127,7 @@ static void processCreate(VALUE class,VALUE ruby_process,VALUE host) 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); + 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); @@ -175,12 +142,11 @@ static void processCreate(VALUE class,VALUE ruby_process,VALUE host) } process->simdata->PID = msg_global->PID++; // msg_global ?? -#ifdef DEBUG - printf("fill in process %s/%s (pid=%d) %p (sd%=%p , host=%p, host->sd=%p)\n", + DEBUG7("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, @@ -188,9 +154,8 @@ static void processCreate(VALUE class,VALUE ruby_process,VALUE host) process->simdata->m_host->simdata->smx_host->name, 0,NULL,NULL); -#ifdef DEBUG - printf("context created (s_process=%p)\n",process->simdata->s_process); -#endif + DEBUG1("context created (s_process=%p)\n",process->simdata->s_process); + if (SIMIX_process_self()) { // SomeOne Created Me !! process->simdata->PPID = MSG_process_get_PID(SIMIX_process_self()->data); } @@ -210,14 +175,11 @@ static void processCreate(VALUE class,VALUE ruby_process,VALUE host) // Process Management +void rb_process_suspend(VALUE class,VALUE ruby_process) { -static void processSuspend(VALUE class,VALUE ruby_process) -{ + m_process_t process = rb_process_to_native(ruby_process); - m_process_t process = process_to_native(ruby_process); - - if (!process) - { + if (!process) { rb_raise(rb_eRuntimeError,"Process Not Bound...while suspending process"); return; } @@ -226,91 +188,69 @@ static void processSuspend(VALUE class,VALUE ruby_process) if ( MSG_OK != MSG_process_suspend(process)) rb_raise(rb_eRuntimeError,"MSG_process_suspend() failed"); - - } -static void processResume(VALUE class,VALUE ruby_process) -{ - m_process_t process = process_to_native(ruby_process); - if (!process) - { +void rb_process_resume(VALUE class,VALUE ruby_process) { + m_process_t process = rb_process_to_native(ruby_process); + if (!process) { 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"); - } -static VALUE processIsSuspend(VALUE class,VALUE ruby_process) -{ - - m_process_t process = process_to_native(ruby_process); - if (!process) - { +VALUE rb_process_isSuspended(VALUE class,VALUE ruby_process) { + m_process_t process = rb_process_to_native(ruby_process); + if (!process) { rb_raise (rb_eRuntimeError,"Process not Bound...while testing if suspended"); - return; + return Qfalse; } - // 1 is The Process is Suspended , 0 Otherwise if(MSG_process_is_suspended(process)) return Qtrue; - return Qfalse; - } -static void processKill(VALUE class,VALUE ruby_process) -{ - m_process_t process = process_to_native(ruby_process); +void rb_process_kill_down(VALUE class,VALUE ruby_process) { + m_process_t process = rb_process_to_native(ruby_process); - if(!process) - { + if(!process) { rb_raise (rb_eRuntimeError,"Process Not Bound...while killing process"); - return ; + return; } // Delete The Global Reference / Ruby Process - process_kill(ruby_process); + rb_process_kill_up(ruby_process); // Delete the Native Process MSG_process_kill(process); - } -static VALUE processGetHost(VALUE class,VALUE ruby_process) -{ - - m_process_t process = process_to_native(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) - { + if (!process) { rb_raise(rb_eRuntimeError,"Process Not Bound...while getting Host"); return Qnil; // NULL } host = MSG_process_get_host(process); - if(!host->data) - { + if(!host->data) { rb_raise (rb_eRuntimeError,"MSG_process_get_host() failed"); return Qnil; } - return Data_Wrap_Struct(class, 0, host_free, host); - + return Data_Wrap_Struct(class, 0, rb_host_free, host); } -static void processExit(VALUE class,VALUE ruby_process) -{ - - m_process_t process = process_to_native(ruby_process); - if(!process) - { +void rb_process_exit(VALUE class,VALUE ruby_process) { + m_process_t process = rb_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); - } diff --git a/src/bindings/ruby_bindings.h b/src/bindings/ruby_bindings.h index e62264e41d..82a8e30573 100644 --- a/src/bindings/ruby_bindings.h +++ b/src/bindings/ruby_bindings.h @@ -19,8 +19,7 @@ #include "msg/msg.h" #include "msg/datatypes.h" -//#include "msg/private.h" -//#include "msg/mailbox.h" +#include "msg/mailbox.h" /* MAX_ALIAS_NAME (FIXME: kill it)*/ #include "surf/surfxml_parse.h" #include "simix/simix.h" #include "simix/private.h" @@ -66,7 +65,7 @@ VALUE rb_process_getID(VALUE ruby_process); VALUE rb_process_getBind(VALUE ruby_class); void rb_process_setBind(VALUE ruby_class,long bind); VALUE rb_process_isAlive(VALUE ruby_process); -void rb_process_kill(VALUE ruby_process); +void rb_process_kill_up(VALUE ruby_process); void rb_process_join( VALUE ruby_process ); void rb_process_unschedule( VALUE ruby_process ); void rb_process_schedule( VALUE ruby_process ); @@ -82,29 +81,26 @@ void rb_process_schedule( VALUE ruby_process ); //friend Method // Not belong to the Class but Called within !! m_process_t rb_process_to_native(VALUE ruby_process); - // Binding Process >> Friend Method -void rb_processBind(VALUE ruby_class,m_process_t process); - -// CreateProcess Method -void rb_processCreate(VALUE Class,VALUE rb_process,VALUE host); - -// ProcessSuspend -void rb_processSuspend(VALUE Class,VALUE ruby_process); - -// ProcessResume -void rb_processResume(VALUE Class,VALUE ruby_process); - -//ProcessIsSuspend return Boolean ( Qtrue / Qfalse ) -VALUE rb_processIsSuspend(VALUE Class,VALUE ruby_process); - -//Processkill -void rb_processKill(VALUE Class,VALUE ruby_process); - -//ProcessGetHost -VALUE rb_processGetHost(VALUE Class,VALUE ruby_process); +void rb_process_bind(VALUE ruby_class,m_process_t process); +void rb_process_create(VALUE Class,VALUE rb_process,VALUE host); +void rb_process_suspend(VALUE Class,VALUE ruby_process); +void rb_process_resume(VALUE Class,VALUE ruby_process); +// Returns Boolean ( Qtrue / Qfalse ) +VALUE rb_process_isSuspended(VALUE Class,VALUE ruby_process); +void rb_process_kill_down(VALUE Class,VALUE ruby_process); +VALUE rb_process_getHost(VALUE Class,VALUE ruby_process); +void rb_process_exit(VALUE Class,VALUE ruby_process); + +/* Functions related to hosts */ +void rb_host_free(m_host_t ht); +VALUE rb_host_get_by_name(VALUE Class, VALUE name); +VALUE rb_host_name(VALUE Class,VALUE host); +VALUE rb_host_number(VALUE Class); +VALUE rb_host_speed(VALUE Class,VALUE host); +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); -//ProcessExit -void rb_processExit(VALUE Class,VALUE ruby_process); #endif /* RB_SG_BINDINGS */ diff --git a/src/simix/smx_context_ruby.c b/src/simix/smx_context_ruby.c index 8c453177cc..b5062bb60d 100644 --- a/src/simix/smx_context_ruby.c +++ b/src/simix/smx_context_ruby.c @@ -150,7 +150,7 @@ static void smx_ctx_ruby_stop(smx_context_t context) rb_process_schedule(current->process); process = ctx_ruby->process; // interupt/kill The Ruby Process - rb_process_kill(process); + rb_process_kill_up(process); } } }else { diff --git a/src/xbt/log.c b/src/xbt/log.c index b1f767cacf..15bbb9a10a 100644 --- a/src/xbt/log.c +++ b/src/xbt/log.c @@ -518,6 +518,7 @@ XBT_LOG_NEW_CATEGORY(xbt, "All XBT categories (simgrid toolbox)"); XBT_LOG_NEW_CATEGORY(surf, "All SURF categories"); XBT_LOG_NEW_CATEGORY(msg, "All MSG categories"); XBT_LOG_NEW_CATEGORY(simix, "All SIMIX categories"); +XBT_LOG_NEW_CATEGORY(bindings, "All bindings categories"); XBT_LOG_NEW_DEFAULT_SUBCATEGORY(log, xbt, "Loggings from the logging mechanism itself");