Logo AND Algorithmique Numérique Distribuée

Public GIT Repository
4ac3a8295774fb9332072b90662c0a7c55b44e91
[simgrid.git] / src / bindings / ruby / rb_msg_host.c
1 /* Host-related bindings to ruby  */
2
3 /* Copyright 2010. The SimGrid Team. All right reserved. */
4
5 /* This program is free software; you can redistribute it and/or modify it
6  * under the terms of the license (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,bprintf("No host called '%s' found",h_name));
22
23   return Data_Wrap_Struct(class,0,rb_host_free,host);
24 }
25
26 //Get Name
27 VALUE rb_host_name(VALUE class,VALUE host) {
28
29   // Wrap Ruby Value to m_host_t struct
30   m_host_t ht;
31   Data_Get_Struct(host, s_m_host_t, ht);
32   return rb_str_new2(MSG_host_get_name(ht));
33
34 }
35
36 // Get Number
37 VALUE rb_host_number(VALUE class) {
38   return INT2NUM(MSG_get_host_number());
39 }
40
41 // Host Speed ( Double )
42 VALUE rb_host_speed(VALUE class,VALUE host) {
43   m_host_t ht ;
44   Data_Get_Struct(host,s_m_host_t,ht);
45   return MSG_get_host_speed(ht);
46 }
47
48 // Host Set Data
49 void rb_host_set_data(VALUE class,VALUE host,VALUE data) {
50   THROW_UNIMPLEMENTED;
51 }
52
53 // Host Get Data
54 VALUE rb_host_get_data(VALUE class,VALUE host) {
55   THROW_UNIMPLEMENTED;
56   return Qnil;
57 }
58
59 // Host is Avail
60 VALUE rb_host_is_avail(VALUE class,VALUE host) {
61   m_host_t ht;
62   Data_Get_Struct(host,s_m_host_t,ht);
63   if (!ht) {
64     rb_raise(rb_eRuntimeError,"Host not Bound");
65     return Qnil;
66   }
67
68   if(MSG_host_is_avail(ht))
69     return Qtrue;
70
71   return Qfalse;
72 }