2 * Copyright 2010. The SimGrid Team. All right reserved.
4 * This program is free software; you can redistribute
5 * it and/or modify it under the terms of the license
6 *(GNU LGPL) which comes with this package.
8 #include "bindings/ruby_bindings.h"
11 void rb_task_free(m_task_t tk) {
16 VALUE rb_task_new(VALUE class, VALUE name,VALUE comp_size,VALUE comm_size) {
17 //char * t_name = RSTRING(name)->ptr;
18 m_task_t task = MSG_task_create(RSTRING(name)->ptr,NUM2INT(comp_size),NUM2INT(comm_size),NULL);
19 // Wrap m_task_t to a Ruby Value
20 return Data_Wrap_Struct(class, 0, rb_task_free, task);
24 //Get Computation Size
25 VALUE rb_task_comp(VALUE class,VALUE task) {
28 // Wrap Ruby Value to m_task_t struct
29 Data_Get_Struct(task, s_m_task_t, tk);
30 size = MSG_task_get_compute_duration(tk);
31 return rb_float_new(size);
35 VALUE rb_task_name(VALUE class,VALUE task) {
37 // Wrap Ruby Value to m_task_t struct
39 Data_Get_Struct(task, s_m_task_t, tk);
40 return rb_str_new2(MSG_task_get_name(tk));
44 VALUE rb_task_execute(VALUE class,VALUE task) {
46 // Wrap Ruby Value to m_task_t struct
48 Data_Get_Struct(task, s_m_task_t, tk);
49 return INT2NUM(MSG_task_execute(tk));
53 void rb_task_send(VALUE class,VALUE task,VALUE mailbox) {
55 // Wrap Ruby Value to m_task_t struct
57 Data_Get_Struct(task, s_m_task_t, tk);
58 int res = MSG_task_send(tk,RSTRING(mailbox)->ptr);
60 rb_raise(rb_eRuntimeError,"MSG_task_send failed");
63 // Receiving Task (returns a Task)
64 VALUE rb_task_receive(VALUE class,VALUE mailbox) {
67 MSG_task_receive(&task,RSTRING(mailbox)->ptr);
68 return Data_Wrap_Struct(class, 0, rb_task_free, task);
73 void rb_task_receive2(VALUE class,VALUE task,VALUE mailbox) {
75 Data_Get_Struct(task, s_m_task_t, tk);
76 MSG_task_receive(&tk,RSTRING(mailbox)->ptr);
79 // It Return a Native Process ( m_process_t )
80 VALUE rb_task_sender(VALUE class,VALUE task) {
82 Data_Get_Struct(task,s_m_task_t,tk);
84 return 0;//MSG_task_get_sender(tk);
88 VALUE rb_task_source(VALUE class,VALUE task) {
90 Data_Get_Struct(task,s_m_task_t,tk);
92 m_host_t host = MSG_task_get_source(tk);
94 rb_raise(rb_eRuntimeError,"MSG_task_get_source() failed");
102 VALUE rb_task_listen(VALUE class,VALUE task,VALUE alias) {
107 Data_Get_Struct(task,s_m_task_t,tk);
108 p_alias = RSTRING(alias)->ptr;
110 rv = MSG_task_listen(p_alias);
118 VALUE rb_task_listen_host(VALUE class,VALUE task,VALUE alias,VALUE host) {
125 Data_Get_Struct(task,s_m_task_t,tk);
126 Data_Get_Struct(host,s_m_host_t,ht);
127 p_alias = RSTRING(alias)->ptr;
129 rv = MSG_task_listen_from_host(p_alias,ht);