Logo AND Algorithmique Numérique Distribuée

Public GIT Repository
Use xbt_XXX_is_empty() instead of testing xbt_XXX_length() against 0.
[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     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     VALUE value = ptr[i];
51     type = TYPE(value);
52     tmp = RSTRING(value)->ptr;
53     argv[i + 1] = strdup(tmp);
54   }
55   SD_init(&argc, argv);
56   free(argv);
57 //   XBT_INFO("SD Init...Done");
58   printf("SD Init...Done\n");
59   return;
60
61 }
62
63 //Init Msg_Run From Ruby
64 static void sd_reinit(VALUE class)
65 {
66   SD_application_reinit();
67 }
68
69 //deploy Application
70 static void sd_createEnvironment(VALUE class, VALUE plateformFile)
71 {
72   int type = TYPE(plateformFile);
73   if (type != T_STRING)
74     rb_raise(rb_eRuntimeError, "Bad Argument's Type");
75   const char *platform = RSTRING(plateformFile)->ptr;
76   SD_create_environment(platform);
77   printf("Create Environment...Done\n");
78
79   return;
80 }
81
82
83 // INFO
84 static void sd_info(VALUE class, VALUE msg)
85 {
86   const char *s = RSTRING(msg)->ptr;
87 //  XBT_INFO("%s",s);
88   printf("%s\n", s);
89 }
90
91 // Get Clock
92 static VALUE sd_get_clock(VALUE class)
93 {
94   return rb_float_new(SD_get_clock());
95 }
96
97 void Init_dag()
98 {
99   // Modules
100   rb_dag = rb_define_module("DAG");
101
102   // Classes
103   //Associated Environment Methods!
104   rb_define_method(rb_dag, "init", sd_init, 1);
105   rb_define_method(rb_dag, "reinit", sd_reinit, 0);
106   rb_define_method(rb_dag, "createEnvironment", sd_createEnvironment, 1);
107   rb_define_method(rb_dag, "info", sd_info, 1);
108   rb_define_method(rb_dag, "getClock", sd_get_clock, 0);
109
110   //Classes       
111   rb_task = rb_define_class_under(rb_dag, "SdTask", rb_cObject);
112   rb_workstation =
113       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,
122                             1);
123   rb_define_module_function(rb_task, "addDependency",
124                             rb_SD_task_add_dependency, 2);
125   rb_define_module_function(rb_task, "executionTime",
126                             rb_SD_task_execution_time, 6);
127   rb_define_module_function(rb_task, "startTime", rb_SD_task_start_time,
128                             1);
129   rb_define_module_function(rb_task, "finishTime", rb_SD_task_finish_time,
130                             1);
131   rb_define_module_function(rb_task, "simulate", rb_SD_simulate, 1);
132
133   //Worstation Methods  
134   rb_define_module_function(rb_workstation, "getList",
135                             rb_SD_workstation_list, 0);
136   rb_define_module_function(rb_workstation, "getNumber",
137                             rb_SD_workstation_number, 0);
138   rb_define_module_function(rb_workstation, "name", rb_SD_workstation_name,
139                             1);
140 }