Logo AND Algorithmique Numérique Distribuée

Public GIT Repository
basic layer for simdag bindings ( modifyin' the return value of simulate from SD_tas...
[simgrid.git] / src / bindings / rubyDag / rb_simdag.c
1 /* Copyright (c) 2010. The SimGrid Team.
2  * All rights 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 /* 
8  * $Id$
9  *
10  * Copyright 2010 Simgrid Team         
11  * All right reserved. 
12  *
13  * This program is free software; you can redistribute 
14  * it and/or modify it under the terms of the license 
15  *(GNU LGPL) which comes with this package. 
16  */ 
17
18 //FIXME #include "ruby_simdag.h"
19 #include "rb_SD_task.c"
20 #include "rb_SD_workstation.c"
21 #include <simdag/simdag.h>
22 #define MY_DEBUG
23
24 // XBT_LOG_EXTERNAL_DEFAULT_CATEGORY(ruby);
25
26 // MSG Module
27 VALUE rb_dag;
28 // MSG Classes
29 VALUE rb_task;
30 VALUE rb_workstation;
31
32 //Init Msg_Init From Ruby
33 static void sd_init(VALUE Class,VALUE args)
34
35   char **argv=NULL;
36   const char *tmp;
37   int argc,type,i;
38   VALUE *ptr;
39   type = TYPE(args);
40   if ( type != T_ARRAY )
41   {
42    rb_raise(rb_eRuntimeError,"Bad Argument to SD_init");
43    return;
44   }
45   ptr = RARRAY(args)->ptr;
46   argc= RARRAY(args)->len;
47   argc++;
48   argv= xbt_new0(char*,argc);
49   argv[0] = strdup("ruby");
50   for (i=0;i<argc-1;i++)
51   {
52    VALUE value = ptr[i];
53    type = TYPE(value);
54    tmp = RSTRING(value)->ptr;
55    argv[i+1] = strdup(tmp); 
56   }
57   SD_init(&argc,argv);
58   free(argv);
59 //   INFO0("SD Init...Done");
60   printf("SD Init...Done\n");
61   return;
62   
63 }
64
65 //Init Msg_Run From Ruby
66 static void sd_reinit(VALUE class)
67 {
68   SD_application_reinit();
69 }
70  
71 //deploy Application
72 static void sd_createEnvironment(VALUE class,VALUE plateformFile )
73 {   
74    int type = TYPE(plateformFile);
75    if ( type != T_STRING )
76       rb_raise(rb_eRuntimeError,"Bad Argument's Type");  
77    const char * platform =  RSTRING(plateformFile)->ptr;
78    SD_create_environment(platform);
79    printf("Create Environment...Done\n");
80
81  return;  
82 }
83  
84
85 // INFO
86 static void sd_info(VALUE class,VALUE msg)
87 {
88  const char *s = RSTRING(msg)->ptr;
89 //  INFO1("%s",s);
90  printf("%s\n",s);
91 }
92
93 // Get Clock
94 static VALUE sd_get_clock(VALUE class)
95 {
96   return rb_float_new(SD_get_clock());
97 }   
98
99 void Init_dag()
100 {
101    // Modules
102    rb_dag = rb_define_module("DAG");
103     
104    // Classes
105    //Associated Environment Methods!
106    rb_define_method(rb_dag,"init",sd_init,1);
107    rb_define_method(rb_dag,"reinit",sd_reinit,0);
108    rb_define_method(rb_dag,"createEnvironment",sd_createEnvironment,1);
109    rb_define_method(rb_dag,"info",sd_info,1);
110    rb_define_method(rb_dag,"getClock",sd_get_clock,0);
111    
112    //Classes       
113    rb_task = rb_define_class_under(rb_dag,"SdTask",rb_cObject);
114    rb_workstation = rb_define_class_under(rb_dag,"SdWorkstation",rb_cObject);
115 //    TODO Link Class
116     
117    //Task Methods    
118    rb_define_module_function(rb_task,"new",rb_SD_task_new,2);
119 //    rb_define_module_function(rb_task,"free",rb_SD_task_destroy,1);
120    rb_define_module_function(rb_task,"name",rb_SD_task_name,1);
121    rb_define_module_function(rb_task,"schedule",rb_SD_task_schedule,6);
122    rb_define_module_function(rb_task,"unschedule",rb_SD_task_unschedule,1); 
123    rb_define_module_function(rb_task,"addDependency",rb_SD_task_add_dependency,2);
124    rb_define_module_function(rb_task,"executionTime",rb_SD_task_execution_time,6);
125    rb_define_module_function(rb_task,"startTime",rb_SD_task_start_time,1);
126    rb_define_module_function(rb_task,"finishTime",rb_SD_task_finish_time,1);
127    rb_define_module_function(rb_task,"simulate",rb_SD_simulate,1);
128    
129    //Worstation Methods  
130    rb_define_module_function(rb_workstation,"getList",rb_SD_workstation_list,0);
131    rb_define_module_function(rb_workstation,"getNumber",rb_SD_workstation_number,0);
132    rb_define_module_function(rb_workstation,"name",rb_SD_workstation_name,1);
133 }