Logo AND Algorithmique Numérique Distribuée

Public GIT Repository
save one pointer per MSG host
[simgrid.git] / src / msg / msg_host.c
index 6b518afd76be2e3354e0084c8f54f3e5d5e59b7e..02a3375faf91687639c21be10c1b7a96bc1dcd71 100644 (file)
@@ -23,7 +23,7 @@
  */
 
 /********************************* Host **************************************/
-m_host_t __MSG_host_create(smx_host_t workstation, void *data)
+m_host_t __MSG_host_create(smx_host_t workstation)
 {
   const char *name;
   simdata_host_t simdata = xbt_new0(s_simdata_host_t, 1);
@@ -33,7 +33,6 @@ m_host_t __MSG_host_create(smx_host_t workstation, void *data)
   /* Host structure */
   host->name = xbt_strdup(name);
   host->simdata = simdata;
-  host->data = data;
 
   simdata->smx_host = workstation;
 
@@ -59,6 +58,25 @@ m_host_t __MSG_host_create(smx_host_t workstation, void *data)
   return host;
 }
 
+/** \ingroup msg_host_management
+ * \brief Finds a m_host_t using its name.
+ *
+ * This is a name directory service
+ * \param name the name of an host.
+ * \return the corresponding host
+ */
+m_host_t MSG_get_host_by_name(const char *name)
+{
+  smx_host_t simix_h = NULL;
+  simix_h = simcall_host_get_by_name(name);
+
+  if (simix_h == NULL)
+    return NULL;
+
+  return (m_host_t) simcall_host_get_data(simix_h);
+}
+
+
 /** \ingroup m_host_management
  *
  * \brief Set the user data of a #m_host_t.
@@ -68,11 +86,7 @@ m_host_t __MSG_host_create(smx_host_t workstation, void *data)
  */
 MSG_error_t MSG_host_set_data(m_host_t host, void *data)
 {
-  xbt_assert((host != NULL), "Invalid parameters");
-  xbt_assert((host->data == NULL), "Data already set");
-
-  /* Assign data */
-  host->data = data;
+  SIMIX_host_set_data(host->simdata->smx_host,data);
 
   return MSG_OK;
 }
@@ -87,10 +101,7 @@ MSG_error_t MSG_host_set_data(m_host_t host, void *data)
 void *MSG_host_get_data(m_host_t host)
 {
 
-  xbt_assert((host != NULL), "Invalid parameters");
-
-  /* Return data */
-  return (host->data);
+  return SIMIX_host_get_data(host->simdata->smx_host);
 }
 
 /** \ingroup m_host_management