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_SD_task.c
index d3f75d9..740084b 100644 (file)
@@ -1,3 +1,10 @@
+/* Copyright (c) 2010. The SimGrid Team.
+ * All rights reserved.                                                     */
+
+/* This program is free software; you can redistribute it and/or modify it
+  * under the terms of the license (GNU LGPL) which comes with this package. */
+
+//#include "ruby_simdag.h"
 #include "rb_SD_task.h"
 
 // Free Method
@@ -52,8 +59,8 @@ static void rb_SD_task_schedule(VALUE class,VALUE task,VALUE workstation_nb,VALU
   ptr_comm = RARRAY(communication_amount)->ptr;
   
   wrk_list = xbt_new0(SD_workstation_t,wrk_nb);
-  comp_amount = xbt_new0(double,wrk_nb);//malloc(sizeof(double)*wrk_nb); //xbt_new0(double,wrk_nb);
-  comm_amount = xbt_new0(double,wrk_nb);//malloc(sizeof(double)*wrk_nb); //xbt_new0(double,wrk_nb);
+  comp_amount = xbt_new0(double,wrk_nb);
+  comm_amount = xbt_new0(double,wrk_nb);
   
   // wrk_nb == comp_nb == comm_nb ???
   for (i=0;i<wrk_nb;i++)
@@ -68,13 +75,11 @@ static void rb_SD_task_schedule(VALUE class,VALUE task,VALUE workstation_nb,VALU
   for (i=0;i<comm_nb;i++)
     comm_amount[i] = NUM2DBL(ptr_comm[i]);*/
   
-  
   SD_task_schedule(tk,wrk_nb,wrk_list,comp_amount,comm_amount,rt);
   
   xbt_free(wrk_list);
-  // FIXME, used later if wanna calculate start & fininsh time for a task
-  free(comp_amount);
-  free(comm_amount);
+  xbt_free(comp_amount);
+  xbt_free(comm_amount);
   
 
 }
@@ -156,16 +161,17 @@ static VALUE rb_SD_task_finish_time(VALUE class,VALUE task)
 static VALUE rb_SD_simulate(VALUE class,VALUE how_long)
 {
   int i;
+  SD_task_t  task ; 
   double hl = NUM2DBL(how_long);
-  SD_task_t * tasks = SD_simulate(hl); 
+  xbt_dynar_t simulated_tasks = SD_simulate(hl) ;
+  
   VALUE rb_tasks = rb_ary_new();
-  for (i = 0; tasks[i] != NULL; i++)
-    {
-      VALUE tk = Qnil;
-      tk = Data_Wrap_Struct(class, 0, SD_task_free, tasks[i]);
-      rb_ary_push(rb_tasks,tk);
-      
-    }
+  xbt_dynar_foreach(simulated_tasks, i, task){
+    VALUE tk = Qnil;
+    tk = Data_Wrap_Struct(class, 0, SD_task_free, task);
+    rb_ary_push(rb_tasks,tk);
+  }
+  
   return  rb_tasks;
  
 }