3 #include "msg/datatypes.h"
4 #include "xbt/sysdep.h"
6 #include "xbt/asserts.h"
7 #include "surf/surfxml_parse.h"
10 #include "rb_msg_task.c"
11 #include "rb_msg_host.c"
12 #include "rb_msg_process.c"
13 #include "rb_application_handler.c"
17 //Init Msg_Init From Ruby
20 static void msg_init(VALUE Class,VALUE args)
30 // Testing The Args Type
35 rb_raise(rb_eRuntimeError,"Argh!! Bad Arguments to msg_init");
39 ptr= RARRAY(args)->ptr;
40 argc= RARRAY(args)->len;
42 // Create C Array to Hold Data_Get_Struct
43 argv = xbt_new0(char *, argc); // argc or argc +1
45 argv[0] = strdup("ruby");
52 // if (type == T_STRING)
53 tmp = RSTRING(value)->ptr;
54 argv[i+1] = strdup(tmp);
58 // Calling C Msg_Init Method
59 MSG_global_init(&argc,argv);
60 MSG_set_channel_number(10); // Okey !! Okey !! This Must Be Fixed Dynamiclly , But Later ;)
61 SIMIX_context_select_factory("ruby");
69 printf("Msg Init...Done\n");
76 //Init Msg_Run From Ruby
77 static void msg_run(VALUE class)
80 xbt_fifo_item_t item = NULL;
85 if (MSG_OK != MSG_main()){
87 rb_raise(rb_eRuntimeError,"MSG_main() failed");
91 ("MSG_main finished. Bail out before cleanup since there is a bug in this part.");
92 /* Cleanup Ruby hosts */
93 DEBUG("Clean Ruby World");
94 xbt_fifo_foreach(msg_global->host, item, host, m_host_t) {
96 //rbHost = (VALUE)host->data;// ??!!
100 if (MSG_OK != MSG_clean()){
102 rb_raise(rb_eRuntimeError,"MSG_clean() failed");
112 // Create Environment
113 static void msg_createEnvironment(VALUE class,VALUE plateformFile)
117 int type = TYPE(plateformFile);
119 if ( type != T_STRING )
120 rb_raise(rb_eRuntimeError,"Bad Argument's Type");
122 const char * platform = RSTRING(plateformFile)->ptr;
124 MSG_create_environment(platform);
131 // deploy Application
133 static void msg_deployApplication(VALUE class,VALUE deploymentFile )
136 int type = TYPE(deploymentFile);
138 if ( type != T_STRING )
139 rb_raise(rb_eRuntimeError,"Bad Argument's Type");
141 const char *dep_file = RSTRING(deploymentFile)->ptr;
144 surf_parse_reset_parser();
146 surfxml_add_callback(STag_surfxml_process_cb_list,
147 application_handler_on_begin_process);
149 surfxml_add_callback(STag_surfxml_argument_cb_list,
150 application_handler_on_process_arg);
152 surfxml_add_callback(STag_surfxml_prop_cb_list,
153 application_handler_on_property);
155 surfxml_add_callback(STag_surfxml_process_cb_list,
156 application_handler_on_end_process);
158 surf_parse_open(dep_file);
160 application_handler_on_start_document();
163 rb_raise(rb_eRuntimeError,"surf_parse() failed");
167 application_handler_on_end_document();
174 static void msg_registerFunction(VALUE class,VALUE function_name,VALUE code)
177 char * fct_name = RSTRING(function_name)->ptr;
178 xbt_main_func_t fct_code
182 static void msg_info(VALUE class,VALUE msg)
184 const char *s = RSTRING(msg)->ptr;
190 static VALUE msg_get_clock(VALUE class)
193 return DBL2NUM(MSG_get_clock());
198 static void msg_paje_out(VALUE class,VALUE pajeFile)
200 const char *pfile = RSTRING(pajeFile)->ptr;
201 MSG_paje_output(pfile);
205 /*****************************************************************************************************************
207 Wrapping MSG module and its Class ( Task,Host) & Methods ( Process's method...ect)
210 the part after "Init_" is the name of the C extension specified in extconf.rb , not the name of C source file
212 *****************************************************************************************************************/
218 rb_msg = rb_define_module("MSG");
220 //Associated Environment Methods!
221 rb_define_method(rb_msg,"init",msg_init,1);
222 rb_define_method(rb_msg,"run",msg_run,0);
223 rb_define_method(rb_msg,"createEnvironment",msg_createEnvironment,1);
224 rb_define_method(rb_msg,"deployApplication",msg_deployApplication,1);
225 rb_define_method(rb_msg,"info",msg_info,1);
226 rb_define_method(rb_msg,"getClock",msg_get_clock,0);
227 rb_define_method(rb_msg,"pajeOutput",msg_paje_out,1);
229 // Associated Process Methods
230 // rb_define_method(rb_msg,"processCreate",processCreate,2);
231 rb_define_method(rb_msg,"processSuspend",processSuspend,1);
232 rb_define_method(rb_msg,"processResume",processResume,1);
233 rb_define_method(rb_msg,"processIsSuspend",processIsSuspend,1);
234 rb_define_method(rb_msg,"processKill",processKill,1);
235 rb_define_method(rb_msg,"processGetHost",processGetHost,1);
238 rb_task = rb_define_class_under(rb_msg,"Task",rb_cObject);
239 rb_host = rb_define_class_under(rb_msg,"Host",rb_cObject);
242 rb_define_module_function(rb_task,"new",task_new,3);
243 rb_define_module_function(rb_task,"compSize",task_comp,1);
244 rb_define_module_function(rb_task,"name",task_name,1);
245 rb_define_module_function(rb_task,"execute",task_execute,1);
246 rb_define_module_function(rb_task,"send",task_send,2);
247 rb_define_module_function(rb_task,"receive",task_receive,1);
248 rb_define_module_function(rb_task,"receive2",task_receive2,2);
249 rb_define_module_function(rb_task,"sender",task_sender,1);
250 rb_define_module_function(rb_task,"source",task_source,1);
251 rb_define_module_function(rb_task,"listen",task_listen,2);
252 rb_define_module_function(rb_task,"listenFromHost",task_listen_host,3);
255 rb_define_module_function(rb_host,"getByName",host_get_by_name,1);
256 rb_define_module_function(rb_host,"name",host_name,1);
257 rb_define_module_function(rb_host,"speed",host_speed,1);
258 rb_define_module_function(rb_host,"number",host_number,0);
259 rb_define_module_function(rb_host,"setData",host_set_data,2);
260 rb_define_module_function(rb_host,"getData",host_get_data,1);
261 // rb_define_module_function(rb_host,"hasData",host_has_data,1);
262 rb_define_module_function(rb_host,"isAvail",host_is_avail,1);