Logo AND Algorithmique Numérique Distribuée

Public GIT Repository
aac298c446bfe889856a298377d9b98768b1d756
[simgrid.git] / src / bindings / ruby / rb_application_handler.c
1 /*
2  * Copyright 2010. The SimGrid Team. All right reserved.
3  *
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.
6  */
7 #include "bindings/ruby_bindings.h"
8 #include "surf/surfxml_parse.h"
9
10 static VALUE application_handler_class; // The Current Instance of ApplicationHandler Class ,is it the same as Current Thread ??!!
11
12
13 // #define MY_DEBUG 
14
15 static void r_init() {
16   ruby_init();
17   ruby_init_loadpath();
18   rb_require("ApplicationHandler.rb");
19   
20
21
22 void rb_application_handler_on_start_document(void) {
23   
24    r_init();
25    application_handler_class = rb_funcall3(rb_const_get(rb_cObject, rb_intern("ApplicationHandler")),  rb_intern("new"), 0, 0);
26    rb_funcall(application_handler_class,rb_intern("onStartDocument"),0);
27  #ifdef MY_DEBUG
28    printf ("application_handler_on_start_document ...Done\n" );
29  #endif
30   
31 }
32
33 void rb_application_handler_on_end_document(void) {
34   rb_funcall(application_handler_class,rb_intern("onEndDocument"),0); 
35 }
36
37 void rb_application_handler_on_begin_process(void) {
38   VALUE hostName = rb_str_new2(A_surfxml_process_host);
39   VALUE function = rb_str_new2(A_surfxml_process_function);
40 #ifdef MY_DEBUG
41    printf ("On_Begin_Process: %s : %s \n",RSTRING(hostName)->ptr,RSTRING(function)->ptr);
42 #endif 
43    rb_funcall(application_handler_class,rb_intern("onBeginProcess"),2,hostName,function); 
44 }
45
46 void rb_application_handler_on_process_arg(void) {
47    VALUE arg = rb_str_new2(A_surfxml_argument_value);
48 #ifdef MY_DEBUG
49    printf ("On_Process_Args >> Sufxml argument value : %s\n",RSTRING(arg)->ptr);
50 #endif
51    rb_funcall(application_handler_class,rb_intern("onProcessArg"),1,arg); 
52 }
53
54 void rb_application_handler_on_property(void) {
55    VALUE id = rb_str_new2(A_surfxml_prop_id);
56    VALUE val =  rb_str_new2(A_surfxml_prop_value);
57    rb_funcall(application_handler_class,rb_intern("onProperty"),2,id,val);
58 }
59
60
61 void rb_application_handler_on_end_process(void) {
62  rb_funcall(application_handler_class,rb_intern("onEndProcess"),0);
63 }