Logo AND Algorithmique Numérique Distribuée

Public GIT Repository
More ruby cleanups: stop defining everything static, and prefix functions with rb_...
[simgrid.git] / src / bindings / ruby / rb_msg_host.c
1 /*
2  * Copyright 2010. The SimGrid Team. All right reserved.
3  *
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. 
7  */
8 #include "bindings/ruby_bindings.h"
9
10 // Free Method
11 void rb_host_free(m_host_t ht) {
12   //Nothing to do !!?
13 }
14
15 // New Method : return a Host
16 VALUE rb_host_get_by_name(VALUE class, VALUE name) {
17   
18   const char * h_name = RSTRING(name)->ptr;
19   m_host_t host = MSG_get_host_by_name(h_name);
20   if(!host)
21     rb_raise(rb_eRuntimeError,"MSG_get_host_by_name() failled");
22   
23   return Data_Wrap_Struct(class,0,host_free,host);
24
25 }
26
27 //Get Name
28 VALUE rb_host_name(VALUE class,VALUE host) {
29   
30   // Wrap Ruby Value to m_host_t struct
31   m_host_t ht;
32   Data_Get_Struct(host, m_host_t, ht);
33   return rb_str_new2(MSG_host_get_name(ht));
34    
35 }
36
37 // Get Number
38 VALUE rb_host_number(VALUE class) {
39   
40   return INT2NUM(MSG_get_host_number());
41   
42 }
43
44 // Host Speed ( Double )
45 VALUE rb_host_speed(VALUE class,VALUE host) {
46   m_host_t ht ;
47   Data_Get_Struct(host,m_host_t,ht);
48   return MSG_get_host_speed(ht);
49   
50 }
51
52 // Host Set Data
53 void rb_host_set_data(VALUE class,VALUE host,VALUE data) {
54   //...
55 }
56
57 // Host Get Data
58 VALUE rb_host_get_data(VALUE class,VALUE host) {
59   //...
60   return Qnil;
61 }
62
63 // Host is Avail
64 VALUE rb_host_is_avail(VALUE class,VALUE host) {
65   m_host_t ht;
66   Data_Get_Struct(host,m_host_t,ht);
67   if (!ht) {
68     rb_raise(rb_eRuntimeError,"Host not Bound");
69     return Qnil;
70   }
71   
72   if(MSG_host_is_avail(ht))
73     return Qtrue;
74   
75   return Qfalse;
76 }