Logo AND Algorithmique Numérique Distribuée

Public GIT Repository
Almost Done ... Still Stuckin' Wiith Some MSG Error while The Slave Should Recieve ...
[simgrid.git] / src / bindings / ruby / rb_msg_task.c
1 /*
2  * $Id$
3  *
4  * Copyright 2010 Martin Quinson, Mehdi Fekari           
5  * All right reserved. 
6  *
7  * This program is free software; you can redistribute 
8  * it and/or modify it under the terms of the license 
9  *(GNU LGPL) which comes with this package. 
10  */
11 #include "rb_msg_task.h"
12
13 // Free Method
14 static void task_free(m_task_t tk) {
15   MSG_task_destroy(tk);
16 }
17
18 // New Method
19 static VALUE task_new(VALUE class, VALUE name,VALUE comp_size,VALUE comm_size)
20 {
21   
22   //char * t_name = RSTRING(name)->ptr;
23   m_task_t task = MSG_task_create(RSTRING(name)->ptr,NUM2INT(comp_size),NUM2INT(comm_size),NULL);
24   // Wrap m_task_t to a Ruby Value
25   return Data_Wrap_Struct(class, 0, task_free, task);
26
27 }
28
29 //Get Computation Size
30 static VALUE task_comp(VALUE class,VALUE task)
31 {
32   double size;
33   m_task_t tk;
34   // Wrap Ruby Value to m_task_t struct
35   Data_Get_Struct(task, m_task_t, tk);
36   size = MSG_task_get_compute_duration(tk);
37   return rb_float_new(size);
38 }
39
40
41 //Get Name
42
43 static VALUE task_name(VALUE class,VALUE task)
44 {
45   
46   // Wrap Ruby Value to m_task_t struct
47   
48   m_task_t tk;
49   Data_Get_Struct(task, m_task_t, tk);
50   return rb_str_new2(MSG_task_get_name(tk));
51    
52 }
53
54
55
56
57 // Execute Task
58
59 static VALUE task_execute(VALUE class,VALUE task)
60 {
61   
62   // Wrap Ruby Value to m_task_t struct
63   m_task_t tk;
64   Data_Get_Struct(task, m_task_t, tk);
65   return INT2NUM(MSG_task_execute(tk));
66   
67   
68 }
69
70 // Sending Task
71
72 static void task_send(VALUE class,VALUE task,VALUE mailbox)
73 {
74   
75     // Wrap Ruby Value to m_task_t struct
76   
77   m_task_t tk;
78   Data_Get_Struct(task, m_task_t, tk);
79   int res = MSG_task_send(tk,RSTRING(mailbox)->ptr);
80  
81   if(res != MSG_OK)
82    rb_raise(rb_eRuntimeError,"MSG_task_send failed");
83   
84   return;
85 }
86
87 // Recieving Task 
88
89 /**
90 *It Return a Task 
91 */
92
93 static VALUE task_receive(VALUE class,VALUE mailbox)
94 {
95   m_task_t tk; 
96   MSG_task_receive(tk,RSTRING(mailbox)->ptr); 
97   return Data_Wrap_Struct(class, 0, task_free, tk);
98 }
99
100 // Recieve Task 2
101 // Not Appreciated 
102 static VALUE task_receive2(VALUE class,VALUE task,VALUE mailbox)
103 {
104   m_task_t tk;
105   Data_Get_Struct(task, m_task_t, tk);
106   return INT2NUM(MSG_task_receive(tk,RSTRING(mailbox)->ptr)); 
107   
108 }
109
110
111 // It Return a Native Process ( m_process_t )
112 static VALUE task_sender(VALUE class,VALUE task)
113 {
114   m_task_t tk;
115   Data_Get_Struct(task,m_task_t,tk);
116   return MSG_task_get_sender(tk);
117   
118 }
119
120 // it return a Host 
121 static VALUE task_source(VALUE class,VALUE task)
122 {
123   m_task_t tk;
124   Data_Get_Struct(task,m_task_t,tk);
125   
126   m_host_t host = MSG_task_get_source(tk);
127   if(!host->data)
128   {
129     rb_raise(rb_eRuntimeError,"MSG_task_get_source() failed");
130     return Qnil;
131   }
132   return host;
133   
134 }
135
136 // Return Boolean
137 static VALUE task_listen(VALUE class,VALUE task,VALUE alias)
138 {
139  m_task_t tk;
140  const char *p_alias;
141  int rv;
142  
143  Data_Get_Struct(task,m_task_t,tk);
144  p_alias = RSTRING(alias)->ptr;
145  
146  rv = MSG_task_listen(p_alias);
147  
148  if(rv) return Qtrue;
149  
150  return Qfalse;
151
152 }
153
154 // return Boolean
155 static VALUE task_listen_host(VALUE class,VALUE task,VALUE alias,VALUE host)
156 {
157   
158  m_task_t tk;
159  m_host_t ht;
160  const char *p_alias;
161  int rv;
162  
163  Data_Get_Struct(task,m_task_t,tk);
164  Data_Get_Struct(host,m_host_t,ht);
165  p_alias = RSTRING(alias)->ptr;
166  
167  rv = MSG_task_listen_from_host(p_alias,ht);
168  
169  if (rv) return Qtrue;
170  
171  return Qfalse;
172  
173  
174   
175 }