Logo AND Algorithmique Numérique Distribuée

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