1 /* Host-related bindings to ruby */
3 /* Copyright (c) 2010. The SimGrid Team.
4 * All rights reserved. */
6 /* This program is free software; you can redistribute it and/or modify it
7 * under the terms of the license (GNU LGPL) which comes with this package. */
9 #include "bindings/ruby_bindings.h"
12 void rb_host_free(m_host_t ht)
17 // New Method : return a Host
18 VALUE rb_host_get_by_name(VALUE class, VALUE name)
21 const char *h_name = RSTRING(name)->ptr;
22 m_host_t host = MSG_get_host_by_name(h_name);
24 rb_raise(rb_eRuntimeError,
25 bprintf("No host called '%s' found", h_name));
27 return Data_Wrap_Struct(class, 0, rb_host_free, host);
31 VALUE rb_host_name(VALUE class, VALUE host)
34 // Wrap Ruby Value to m_host_t struct
36 Data_Get_Struct(host, s_m_host_t, ht);
37 return rb_str_new2(MSG_host_get_name(ht));
42 VALUE rb_host_number(VALUE class)
44 return INT2NUM(MSG_get_host_number());
47 // Host Speed ( Double )
48 VALUE rb_host_speed(VALUE class, VALUE host)
51 Data_Get_Struct(host, s_m_host_t, ht);
52 return MSG_get_host_speed(ht);
56 VALUE rb_host_is_avail(VALUE class, VALUE host)
59 Data_Get_Struct(host, s_m_host_t, ht);
61 rb_raise(rb_eRuntimeError, "Host not Bound");
65 if (MSG_host_is_avail(ht))
71 // getHost from process
72 VALUE rb_host_process(VALUE class, VALUE ruby_process)
75 m_process_t process = rb_process_to_native(ruby_process);
80 rb_raise(rb_eRuntimeError, "Process Not Bound...while getting Host");
84 host = MSG_process_get_host(process);
86 return Data_Wrap_Struct(class, 0, rb_host_free, host);
91 VALUE rb_host_get_all_hosts(VALUE class)
96 nb = MSG_get_host_number();
97 hosts = MSG_get_host_table();
98 rb_hosts = rb_ary_new2(nb);
100 for (index = 0; index < nb; index++)
101 rb_ary_push(rb_hosts,
102 Data_Wrap_Struct(class, 0, rb_host_free, hosts[index]));