Logo AND Algorithmique Numérique Distribuée

Public GIT Repository
Add some patches for delete some warnings with cmake.
[simgrid.git] / buildtools / CPACK / Patch / 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 //Get Name
41 static VALUE task_name(VALUE class,VALUE task)
42 {
43   
44   // Wrap Ruby Value to m_task_t struct
45   m_task_t *tk;
46   Data_Get_Struct(task, m_task_t, tk);
47   return rb_str_new2(MSG_task_get_name(*tk));
48    
49 }
50
51 // Execute Task
52 static VALUE task_execute(VALUE class,VALUE task)
53 {
54   
55   // Wrap Ruby Value to m_task_t struct
56   m_task_t *tk;
57   Data_Get_Struct(task, m_task_t, tk);
58   return INT2NUM(MSG_task_execute(*tk));
59   
60 }
61
62 // Sending Task
63 static void task_send(VALUE class,VALUE task,VALUE mailbox)
64 {
65   
66   // Wrap Ruby Value to m_task_t struct
67   m_task_t *tk;
68   Data_Get_Struct(task, m_task_t, tk);
69   int res = MSG_task_send(*tk,RSTRING(mailbox)->ptr);
70   if(res != MSG_OK)
71    rb_raise(rb_eRuntimeError,"MSG_task_send failed");
72   
73   return;
74 }
75
76 // Recieving Task 
77
78 /**
79 *It Return a Task 
80 */
81
82 static VALUE task_receive(VALUE class,VALUE mailbox)
83 {
84   // Task
85   m_task_t task = NULL;
86   MSG_task_receive(&task,RSTRING(mailbox)->ptr);
87   return Data_Wrap_Struct(class, 0, task_free, task);
88 }
89
90 // Recieve Task 2
91 // Not Appreciated 
92 static void task_receive2(VALUE class,VALUE task,VALUE mailbox)
93 {
94   m_task_t *tk;
95   Data_Get_Struct(task, m_task_t, tk);
96   MSG_task_receive(tk,RSTRING(mailbox)->ptr);
97   
98 }
99
100 // It Return a Native Process ( m_process_t )
101 static VALUE task_sender(VALUE class,VALUE task)
102 {
103   m_task_t *tk;
104   Data_Get_Struct(task,m_task_t,tk);
105   return (VALUE) MSG_task_get_sender(*tk);
106 }
107
108 // it return a Host 
109 static VALUE task_source(VALUE class,VALUE task)
110 {
111   m_task_t *tk;
112   Data_Get_Struct(task,m_task_t,tk);
113   
114   m_host_t host = MSG_task_get_source(*tk);
115   if(!host->data)
116   {
117     rb_raise(rb_eRuntimeError,"MSG_task_get_source() failed");
118     return Qnil;
119   }
120   return (VALUE) host;
121   
122 }
123
124 // Return Boolean
125 static VALUE task_listen(VALUE class,VALUE task,VALUE alias)
126 {
127  m_task_t *tk;
128  const char *p_alias;
129  int rv;
130  
131  Data_Get_Struct(task,m_task_t,tk);
132  p_alias = RSTRING(alias)->ptr;
133  
134  rv = MSG_task_listen(p_alias);
135  
136  if(rv) return Qtrue;
137  
138  return Qfalse;
139
140 }
141
142 // return Boolean
143 static VALUE task_listen_host(VALUE class,VALUE task,VALUE alias,VALUE host)
144 {
145   
146  m_task_t *tk;
147  m_host_t *ht;
148  const char *p_alias;
149  int rv;
150  
151  Data_Get_Struct(task,m_task_t,tk);
152  Data_Get_Struct(host,m_host_t,ht);
153  p_alias = RSTRING(alias)->ptr;
154  
155  rv = MSG_task_listen_from_host(p_alias,*ht);
156  
157  if (rv) return Qtrue;
158  
159  return Qfalse;
160  
161 }
162
163
164 // Put
165 static void task_put(VALUE class,VALUE task,VALUE host)
166 {
167   
168  m_task_t *tk;
169  m_host_t *ht;
170  
171  Data_Get_Struct(task,m_task_t,tk);
172  Data_Get_Struct(host,m_host_t,ht);
173  MSG_task_put(*tk,*ht,PORT_22);  //Channel set to 0
174  
175 }
176
177 //get 
178 static VALUE task_get(VALUE class)
179 {
180   
181  m_task_t task = NULL;
182  int res = MSG_task_get(&task,PORT_22); // Channel set to 0
183  xbt_assert0(res == MSG_OK, "MSG_task_get failed");
184  return Data_Wrap_Struct(class, 0, task_free, task);
185  
186 }