1 /* Copyright (c) 2010. The SimGrid Team.
2 * All rights reserved. */
4 /* This program is free software; you can redistribute it and/or modify it
5 * under the terms of the license (GNU LGPL) which comes with this package. */
7 #include "bindings/ruby_bindings.h"
8 #include "surf/surfxml_parse.h"
10 XBT_LOG_EXTERNAL_DEFAULT_CATEGORY(ruby);
12 // Used to instanciate the Process
15 static VALUE function_name;
16 static VALUE host_name;
18 static VALUE rb_process_instance(VALUE fct_name, VALUE arguments,
23 char *p_className = RSTRING(fct_name)->ptr; // name of process is the one of the class
24 return rb_funcall(rb_const_get(rb_cObject, rb_intern(p_className)),
25 rb_intern("new"), 3, fct_name, arguments, properties);
28 // FIXME: don't mess with MSG internals here, use MSG_process_create_with_arguments()
29 static void rb_process_create_with_args(VALUE fct_name, VALUE arguments,
30 VALUE properties, VALUE ht_name)
34 rb_process_instance(fct_name, arguments, properties);
35 m_process_t process; // Native Process to Create
36 const char *name; // Name of C Native Processs
40 rb_raise(rb_eRuntimeError,
41 "Internal error: Process name cannot be NULL");
42 name = RSTRING(fct_name)->ptr;
43 DEBUG1("Create native process %s", name);
45 char **argv = xbt_new(char *, 2);
46 argv[0] = bprintf("%s@%s", name, RSTRING(ht_name)->ptr);
49 // Allocate the data for the simulation
50 process = MSG_process_create_with_arguments(name,
51 (xbt_main_func_t) ruby_process,
53 MSG_get_host_by_name(RSTRING(ht_name)->ptr),
56 // Bind The Ruby Process instance to The Native Process
57 rb_process_bind(ruby_process, process);
61 void rb_application_handler_on_start_document(void)
65 args = rb_ary_new(); // Max length = 16 !!
70 void rb_application_handler_on_end_document(void)
79 void rb_application_handler_on_begin_process(void)
82 host_name = rb_str_new2(A_surfxml_process_host);
83 function_name = rb_str_new2(A_surfxml_process_function);
85 args = rb_ary_new(); // Max length = 16 ?!
90 void rb_application_handler_on_process_arg(void)
93 VALUE arg = rb_str_new2(A_surfxml_argument_value);
94 rb_ary_push(args, arg);
97 void rb_application_handler_on_property(void)
100 VALUE id = rb_str_new2(A_surfxml_prop_id);
101 VALUE val = rb_str_new2(A_surfxml_prop_value);
102 int i_id = NUM2INT(id);
103 rb_ary_store(prop, i_id, val);
107 void rb_application_handler_on_end_process(void)
110 rb_process_create_with_args(function_name, args, prop, host_name);