Logo AND Algorithmique Numérique Distribuée

Public GIT Repository
f4ecd659620c89079cf076f05a7c483c5faf4243
[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,rb_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, s_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   return INT2NUM(MSG_get_host_number());
40 }
41
42 // Host Speed ( Double )
43 VALUE rb_host_speed(VALUE class,VALUE host) {
44   m_host_t ht ;
45   Data_Get_Struct(host,s_m_host_t,ht);
46   return MSG_get_host_speed(ht);
47 }
48
49 // Host Set Data
50 void rb_host_set_data(VALUE class,VALUE host,VALUE data) {
51   THROW_UNIMPLEMENTED;
52 }
53
54 // Host Get Data
55 VALUE rb_host_get_data(VALUE class,VALUE host) {
56   THROW_UNIMPLEMENTED;
57   return Qnil;
58 }
59
60 // Host is Avail
61 VALUE rb_host_is_avail(VALUE class,VALUE host) {
62   m_host_t ht;
63   Data_Get_Struct(host,s_m_host_t,ht);
64   if (!ht) {
65     rb_raise(rb_eRuntimeError,"Host not Bound");
66     return Qnil;
67   }
68   
69   if(MSG_host_is_avail(ht))
70     return Qtrue;
71   
72   return Qfalse;
73 }