Logo AND Algorithmique Numérique Distribuée

Public GIT Repository
Compile fix
[simgrid.git] / src / bindings / ruby / rb_msg_host.c
index 138f922..895ae1d 100644 (file)
@@ -1,6 +1,7 @@
 /* Host-related bindings to ruby  */
 
-/* Copyright 2010. The SimGrid Team. All right reserved. */
+/* Copyright (c) 2010. The SimGrid Team.
+ * All rights reserved.                                                     */
 
 /* This program is free software; you can redistribute it and/or modify it
  * under the terms of the license (GNU LGPL) which comes with this package. */
@@ -8,23 +9,27 @@
 #include "bindings/ruby_bindings.h"
 
 // Free Method
-void rb_host_free(m_host_t ht) {
+void rb_host_free(m_host_t ht)
+{
   //Nothing to do !!?
 }
 
 // New Method : return a Host
-VALUE rb_host_get_by_name(VALUE class, VALUE name) {
+VALUE rb_host_get_by_name(VALUE class, VALUE name)
+{
 
-  const char * h_name = RSTRING(name)->ptr;
+  const char *h_name = RSTRING(name)->ptr;
   m_host_t host = MSG_get_host_by_name(h_name);
-  if(!host)
-    rb_raise(rb_eRuntimeError,bprintf("No host called '%s' found",h_name));
+  if (!host)
+    rb_raise(rb_eRuntimeError,
+             bprintf("No host called '%s' found", h_name));
 
-  return Data_Wrap_Struct(class,0,rb_host_free,host);
+  return Data_Wrap_Struct(class, 0, rb_host_free, host);
 }
 
 //Get Name
-VALUE rb_host_name(VALUE class,VALUE host) {
+VALUE rb_host_name(VALUE class, VALUE host)
+{
 
   // Wrap Ruby Value to m_host_t struct
   m_host_t ht;
@@ -34,70 +39,67 @@ VALUE rb_host_name(VALUE class,VALUE host) {
 }
 
 // Get Number
-VALUE rb_host_number(VALUE class) {
+VALUE rb_host_number(VALUE class)
+{
   return INT2NUM(MSG_get_host_number());
 }
 
 // Host Speed ( Double )
-VALUE rb_host_speed(VALUE class,VALUE host) {
-  m_host_t ht ;
-  Data_Get_Struct(host,s_m_host_t,ht);
+VALUE rb_host_speed(VALUE class, VALUE host)
+{
+  m_host_t ht;
+  Data_Get_Struct(host, s_m_host_t, ht);
   return MSG_get_host_speed(ht);
 }
 
 // Host is Avail
-VALUE rb_host_is_avail(VALUE class,VALUE host) {
+VALUE rb_host_is_avail(VALUE class, VALUE host)
+{
   m_host_t ht;
-  Data_Get_Struct(host,s_m_host_t,ht);
+  Data_Get_Struct(host, s_m_host_t, ht);
   if (!ht) {
-    rb_raise(rb_eRuntimeError,"Host not Bound");
+    rb_raise(rb_eRuntimeError, "Host not Bound");
     return Qnil;
   }
 
-  if(MSG_host_is_avail(ht))
+  if (MSG_host_is_avail(ht))
     return Qtrue;
 
   return Qfalse;
 }
 
 // getHost from process
-VALUE rb_host_process(VALUE class,VALUE ruby_process)
+VALUE rb_host_process(VALUE class, VALUE ruby_process)
 {
-  
- m_process_t process = rb_process_to_native(ruby_process);
+
 m_process_t process = rb_process_to_native(ruby_process);
   m_host_t host;
-  
+
 
   if (!process) {
-    rb_raise(rb_eRuntimeError,"Process Not Bound...while getting Host");
-    return Qnil; // NULL
+    rb_raise(rb_eRuntimeError, "Process Not Bound...while getting Host");
+    return Qnil;                // NULL
   }
-  
+
   host = MSG_process_get_host(process);
-  
-  return Data_Wrap_Struct(class, 0, rb_host_free, host); 
+
+  return Data_Wrap_Struct(class, 0, rb_host_free, host);
 
 }
 
 // get all hosts
 VALUE rb_host_get_all_hosts(VALUE class)
 {
- int index;
- VALUE hosts_table;
- VALUE rbHost;
- m_host_t host;
-
- int count = xbt_fifo_size(msg_global->host);
- m_host_t *table = (m_host_t *)xbt_fifo_to_array(msg_global->host);
- hosts_table = rb_ary_new2(count);
-
- for (index=0;index<count;index++)
- {
-        rbHost = Qnil;
-        host = table[index];
-        rbHost = Data_Wrap_Struct(class, 0, rb_host_free, host);
-        rb_ary_push(hosts_table,rbHost);
- }
-
- return hosts_table;
+  int nb, index;
+  m_host_t *hosts;
+  VALUE rb_hosts;
+  nb = MSG_get_host_number();
+  hosts = MSG_get_host_table();
+  rb_hosts = rb_ary_new2(nb);
+
+  for (index = 0; index < nb; index++)
+    rb_ary_push(rb_hosts,
+                Data_Wrap_Struct(class, 0, rb_host_free, hosts[index]));
+
+  return rb_hosts;
 }