From: navarrop Date: Wed, 24 Feb 2010 12:54:54 +0000 (+0000) Subject: Be compatible with ruby. X-Git-Tag: SVN~618 X-Git-Url: http://info.iut-bm.univ-fcomte.fr/pub/gitweb/simgrid.git/commitdiff_plain/9fbe3cc5376b8ab4fed68921e4b5b405160c63fd Be compatible with ruby. git-svn-id: svn+ssh://scm.gforge.inria.fr/svn/simgrid/simgrid/trunk@7120 48e7efb5-ca39-0410-a469-dd3cf9ba447f --- diff --git a/buildtools/CPACK/simgrid_CMakeList/src/bindings/ruby/rb_msg_host.c b/buildtools/CPACK/simgrid_CMakeList/src/bindings/ruby/rb_msg_host.c new file mode 100644 index 0000000000..8f8ff0f754 --- /dev/null +++ b/buildtools/CPACK/simgrid_CMakeList/src/bindings/ruby/rb_msg_host.c @@ -0,0 +1,88 @@ +/* + * $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 +void host_free(m_host_t ht) { + //Nothing to do !!? +} + +// New Method : return a Host +static VALUE 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); + if(!host) + rb_raise(rb_eRuntimeError,"MSG_get_host_by_name() failled"); + + return Data_Wrap_Struct(class,0,host_free,host); + +} + +//Get Name +static VALUE 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); + return rb_str_new2(MSG_host_get_name(ht)); + +} + +// Get Number +static VALUE host_number(VALUE class) +{ + + return INT2NUM(MSG_get_host_number()); + +} + +// Host Speed ( Double ) +static VALUE host_speed(VALUE class,VALUE host) +{ + m_host_t ht ; + Data_Get_Struct(host,m_host_t,ht); + return MSG_get_host_speed(ht); + +} + +// Host Set Data +static void host_set_data(VALUE class,VALUE host,VALUE data) +{ + //... +} + +// Host Get Data +static VALUE host_get_data(VALUE class,VALUE host) +{ + //... + return Qnil; +} + +// Host is Avail +static VALUE host_is_avail(VALUE class,VALUE host) +{ + + m_host_t ht; + Data_Get_Struct(host,m_host_t,ht); + if (!ht) + { + rb_raise(rb_eRuntimeError,"Host not Bound"); + return Qnil; + } + + if(MSG_host_is_avail(ht)) + return Qtrue; + + return Qfalse; +} diff --git a/buildtools/CPACK/simgrid_CMakeList/src/bindings/ruby/rb_msg_host.h b/buildtools/CPACK/simgrid_CMakeList/src/bindings/ruby/rb_msg_host.h new file mode 100644 index 0000000000..e76c0481ae --- /dev/null +++ b/buildtools/CPACK/simgrid_CMakeList/src/bindings/ruby/rb_msg_host.h @@ -0,0 +1,32 @@ +#ifndef RB_MSG_HOST +#define RB_MSG_HOST + +#include +#include "msg/msg.h" + +// Free Method +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 diff --git a/buildtools/CPACK/simgrid_CMakeList/tools/gras/stub_generator.c b/buildtools/CPACK/simgrid_CMakeList/tools/gras/stub_generator.c new file mode 100644 index 0000000000..b1d6fe7ead --- /dev/null +++ b/buildtools/CPACK/simgrid_CMakeList/tools/gras/stub_generator.c @@ -0,0 +1,177 @@ +/* $Id: stub_generator.c 6309 2009-05-26 15:29:22Z mquinson $ */ + +/* gras_stub_generator - creates the main() to use a GRAS program */ + +/* Copyright (c) 2003-2007 Martin Quinson, Arnaud Legrand, Malek Cherier. */ +/* All rights 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. */ + +/* specific to Borland Compiler */ +#ifdef __BORLANDDC__ +#pragma hdrstop +#endif + +#include +#include "xbt/sysdep.h" +#include "xbt/function_types.h" +#include "xbt/log.h" +#include "surf/surfxml_parse.h" +#include "surf/surf.h" +#include "portable.h" /* Needed for the time of the SIMIX convertion */ + +#include "gras_stub_generator.h" +#include + + + +XBT_LOG_NEW_DEFAULT_SUBCATEGORY(stubgen, gras, "Stub generator"); + + +#ifdef _WIN32 +#include +#endif + +/* specific to Borland Compiler */ +#ifdef __BORLANDDC__ +#pragma argsused +#endif + + +/**********************************************/ +/********* Parse XML deployment file **********/ +/**********************************************/ +xbt_dict_t process_function_set = NULL; +xbt_dynar_t process_list = NULL; +xbt_dict_t machine_set = NULL; + +void s_process_free(void *process) +{ + s_process_t *p = (s_process_t *) process; + int i; + for (i = 0; i < p->argc; i++) + free(p->argv[i]); + free(p->argv); + free(p->host); +} + +static s_process_t process; + +static void parse_process_init(void) +{ + xbt_dict_set(process_function_set, A_surfxml_process_function, NULL, NULL); + xbt_dict_set(machine_set, A_surfxml_process_host, NULL, NULL); + process.argc = 1; + process.argv = xbt_new(char *, 1); + process.argv[0] = xbt_strdup(A_surfxml_process_function); + process.host = strdup(A_surfxml_process_host); + /*VERB1("Function: %s",A_surfxml_process_function); */ +} + +static void parse_argument(void) +{ + process.argc++; + process.argv = xbt_realloc(process.argv, (process.argc) * sizeof(char *)); + process.argv[(process.argc) - 1] = xbt_strdup(A_surfxml_argument_value); +} + +static void parse_process_finalize(void) +{ + xbt_dynar_push(process_list, &process); + /*VERB1("Function: %s",process.argv[0]); */ +} + +/*void surfxml_add_callback(xbt_dynar_t cb_list, void_f_void_t function) +{ + xbt_dynar_push(cb_list, &function); +}*/ + + +int main(int argc, char *argv[]) +{ + char *project_name = NULL; + char *deployment_file = NULL; + int i; + + surf_init(&argc, argv); + process_function_set = xbt_dict_new(); + process_list = xbt_dynar_new(sizeof(s_process_t), s_process_free); + machine_set = xbt_dict_new(); + + for (i = 1; i < argc; i++) { + int need_removal = 0; + if (!strncmp("--extra-process=", argv[i], strlen("--extra-process="))) { + xbt_dict_set(process_function_set, argv[i] + strlen("--extra-process="), + NULL, NULL); + need_removal = 1; + } + + + if (need_removal) { /* remove the handled argument from argv */ + int j; + for (j = i + 1; j < argc; j++) { + argv[j - 1] = argv[j]; + } + argv[j - 1] = NULL; + argc--; + i--; /* compensate effect of next loop incrementation */ + } + } + + xbt_assert1((argc >= 3), + "Usage: %s project_name deployment_file [deployment_file...]\n", + argv[0]); + + project_name = argv[1]; + + surf_parse_reset_parser(); + DEBUG2("%p %p", parse_process_init, &parse_process_init); + surfxml_add_callback(STag_surfxml_process_cb_list, &parse_process_init); + surfxml_add_callback(ETag_surfxml_argument_cb_list, &parse_argument); + surfxml_add_callback(ETag_surfxml_process_cb_list, &parse_process_finalize); + + for (i = 2; i < argc; i++) { + deployment_file = argv[i]; + surf_parse_open(deployment_file); + if (surf_parse()) + xbt_assert1(0, "Parse error in %s", deployment_file); + + surf_parse_close(); + } + + + warning = xbt_new(char, strlen(WARN) + strlen(deployment_file) + 10); + sprintf(warning, WARN, deployment_file); + + /*if(XBT_LOG_ISENABLED(stubgen, xbt_log_priority_debug)) { + xbt_dict_cursor_t cursor=NULL; + char *key = NULL; + void *data = NULL; + + for (cursor=NULL, xbt_dict_cursor_first((process_function_set),&(cursor)) ; + xbt_dict_cursor_get_or_free(&(cursor),&(key),(void**)(&data)); + xbt_dict_cursor_step(cursor) ) { + DEBUG1("Function %s", key); + } + + xbt_dict_dump(process_function_set,print); + } */ + + generate_sim(project_name); + generate_rl(project_name); + generate_makefile_local(project_name, deployment_file); +#ifdef _WIN32 + generate_borland_simulation_project(project_name); + generate_borland_real_life_project(project_name); + generate_simulation_dsp_file(project_name); + generate_real_live_dsp_file(project_name); + + if (__gras_path) + xbt_free(__gras_path); +#endif + + free(warning); + surf_exit(); + return 0; +} diff --git a/buildtools/CPACK/src/CMakeCompleteInFiles.txt b/buildtools/CPACK/src/CMakeCompleteInFiles.txt index 8fb357cb5c..62e84e9391 100644 --- a/buildtools/CPACK/src/CMakeCompleteInFiles.txt +++ b/buildtools/CPACK/src/CMakeCompleteInFiles.txt @@ -4,17 +4,17 @@ include(CheckIncludeFiles) include(CheckLibraryExists) set(CONTEXT_UCONTEXT 0) SET(CONTEXT_THREADS 0) - +SET(HAVE_RUBY_H 0) if(NOT disable_ruby) SET(RUBY_PATH "non") find_program(FIND_EXE NAMES find) exec_program("${FIND_EXE} /usr/lib -name ruby.h" OUTPUT_VARIABLE RUBY_PATH) string(REPLACE "/ruby.h" "/" RUBY_PATH ${RUBY_PATH}) message("RUBY_PATH ${RUBY_PATH}") - CHECK_INCLUDE_FILE(${RUBY_PATH}ruby.h HAVE_RUBY_H) - if(HAVE_RUBY_H) - add_definitions("-I${RUBY_PATH} -I${PROJECT_DIRECTORY}/src/bindings/ruby -I${PROJECT_DIRECTORY}/src/simix") - endif(HAVE_RUBY_H) + if(RUBY_PATH) + SET(HAVE_RUBY_H 1) + add_definitions("-I${RUBY_PATH} -I${PROJECT_DIRECTORY}/src/bindings/ruby -I${PROJECT_DIRECTORY}/src/simix -fPIC") + endif(RUBY_PATH) endif(NOT disable_ruby) #-------------------------------------------------------------------------------------------------- diff --git a/buildtools/CPACK/src/CMakeMakeExeLib.txt b/buildtools/CPACK/src/CMakeMakeExeLib.txt index 813d986713..3a16f86dc8 100644 --- a/buildtools/CPACK/src/CMakeMakeExeLib.txt +++ b/buildtools/CPACK/src/CMakeMakeExeLib.txt @@ -1,18 +1,27 @@ ### Make Libs include(${PROJECT_DIRECTORY}/CPACK/src/CMakeFLEXml.txt) +set(MSG_SRC_bis +${PROJECT_DIRECTORY}/src/bindings/ruby/rb_application_handler.c +${PROJECT_DIRECTORY}/src/bindings/ruby/rb_msg_task.c +${PROJECT_DIRECTORY}/src/bindings/ruby/rb_msg_process.c +${PROJECT_DIRECTORY}/src/bindings/ruby/rb_msg_host.c +${PROJECT_DIRECTORY}/src/bindings/ruby/rb_msg.c +) if(supernovae) include(${PROJECT_DIRECTORY}/CPACK/src/CMakeSupernovae.txt) else(supernovae) - add_library(simgrid SHARED ${simgrid_sources}) + add_library(simgrid STATIC ${simgrid_sources}) add_library(gras SHARED ${gras_sources}) add_library(smpi STATIC ${SMPI_SRC}) + add_library(msg STATIC ${MSG_SRC_bis}) endif(supernovae) set(GRAS_DEP "pthread") set(SIMGRID_DEP "") -set(SMPI_DEP "") +set(SMPI_DEP "simgrid") +set(MSG_DEP "pthread -lrt -ldl -lcrypt -lm -lc") if(CMAKE_SYSTEM_NAME MATCHES "Darwin") add_definitions("-D_XOPEN_SOURCE") @@ -43,10 +52,10 @@ endif(HAVE_GTNETS) #set(CMAKE_C_FLAGS "-fprofile-arcs -ftest-coverage") #add_definitions (-fprofile-arcs -ftest-coverage) -target_link_libraries(simgrid ${SIMGRID_DEP} ${SIMGRID_DEP_GTNETS}-fprofile-arcs) -target_link_libraries(gras ${GRAS_DEP} -fprofile-arcs) +target_link_libraries(simgrid ${SIMGRID_DEP} ${SIMGRID_DEP_GTNETS} ruby1.8 msg -fprofile-arcs) +target_link_libraries(gras ${GRAS_DEP} msg -fprofile-arcs) target_link_libraries(smpi ${SMPI_DEP} -fprofile-arcs) - +target_link_libraries(msg ${MSG_DEP} -fprofile-arcs) ### Make EXEs #tools