Logo AND Algorithmique Numérique Distribuée

Public GIT Repository
[simix] Call directly the C++ SURF API instead of calling the C bindings
[simgrid.git] / src / simix / smx_host.cpp
index 71bf7a5..65d59d6 100644 (file)
@@ -10,6 +10,7 @@
 #include "xbt/dict.h"
 #include "mc/mc.h"
 #include "src/mc/mc_replay.h"
+#include "src/surf/host_interface.hpp"
 
 XBT_LOG_NEW_DEFAULT_SUBCATEGORY(simix_host, simix,
                                 "SIMIX hosts");
@@ -43,8 +44,9 @@ void SIMIX_host_on(sg_host_t h)
 
   xbt_assert((host != NULL), "Invalid parameters");
 
-  if (h->getState()==SURF_RESOURCE_OFF) {
-    surf_host_set_state(surf_host_resource_priv(h), SURF_RESOURCE_ON);
+  if (h->isOff()) {
+    simgrid::surf::Host* surf_host = h->extension<simgrid::surf::Host>();
+    surf_host_turn_on(surf_host);
 
     unsigned int cpt;
     smx_process_arg_t arg;
@@ -96,8 +98,9 @@ void SIMIX_host_off(sg_host_t h, smx_process_t issuer)
 
   xbt_assert((host != NULL), "Invalid parameters");
 
-  if (h->getState()==SURF_RESOURCE_ON) {
-       surf_host_set_state(surf_host_resource_priv(h), SURF_RESOURCE_OFF);
+  if (h->isOn()) {
+    simgrid::surf::Host* surf_host = h->extension<simgrid::surf::Host>();
+    surf_host_turn_off(surf_host);
 
     /* Clean Simulator data */
     if (xbt_swag_size(host->process_list) != 0) {
@@ -107,6 +110,8 @@ void SIMIX_host_off(sg_host_t h, smx_process_t issuer)
         XBT_DEBUG("Killing %s on %s by %s", process->name,  sg_host_get_name(process->host), issuer->name);
       }
     }
+  } else {
+    XBT_INFO("Host %s is already off",h->getName().c_str());
   }
 }
 
@@ -240,7 +245,7 @@ void SIMIX_host_add_auto_restart_process(sg_host_t host,
   arg->properties = properties;
   arg->auto_restart = auto_restart;
 
-  if( sg_host_get_state(host) == SURF_RESOURCE_OFF
+  if( ! sg_host_is_on(host)
       && !xbt_dict_get_or_null(watched_hosts_lib,sg_host_get_name(host))){
     xbt_dict_set(watched_hosts_lib,sg_host_get_name(host),host,NULL);
     XBT_DEBUG("Have pushed host %s to watched_hosts_lib because state == SURF_RESOURCE_OFF",sg_host_get_name(host));
@@ -499,7 +504,7 @@ void SIMIX_execution_finish(smx_synchro_t synchro)
             (int)synchro->state);
     }
     /* check if the host is down */
-    if (simcall->issuer->host->getState() != SURF_RESOURCE_ON) {
+    if (simcall->issuer->host->isOff()) {
       simcall->issuer->context->iwannadie = 1;
     }
 
@@ -517,7 +522,7 @@ void SIMIX_post_host_execute(smx_synchro_t synchro)
 {
   if (synchro->type == SIMIX_SYNC_EXECUTE && /* FIMXE: handle resource failure
                                                * for parallel tasks too */
-      synchro->execution.host->getState() == SURF_RESOURCE_OFF) {
+      synchro->execution.host->isOff()) {
     /* If the host running the synchro failed, notice it so that the asking
      * process can be killed if it runs on that host itself */
     synchro->state = SIMIX_FAILED;
@@ -559,24 +564,22 @@ void SIMIX_set_category(smx_synchro_t synchro, const char *category)
  */
 void SIMIX_host_get_params(sg_host_t ind_vm, vm_params_t params)
 {
-  /* jump to ws_get_params(). */
-  surf_host_get_params(ind_vm, params);
+  ind_vm->extension<simgrid::surf::Host>()->getParams(params);
 }
 
 void SIMIX_host_set_params(sg_host_t ind_vm, vm_params_t params)
 {
-  /* jump to ws_set_params(). */
-  surf_host_set_params(ind_vm, params);
+  ind_vm->extension<simgrid::surf::Host>()->setParams(params);
 }
 
-xbt_dict_t SIMIX_host_get_mounted_storage_list(sg_host_t host){
+xbt_dict_t SIMIX_host_get_mounted_storage_list(sg_host_t host)
+{
   xbt_assert((host != NULL), "Invalid parameters (simix host is NULL)");
-
-  return surf_host_get_mounted_storage_list(host);
+  return host->extension<simgrid::surf::Host>()->getMountedStorageList();
 }
 
-xbt_dynar_t SIMIX_host_get_attached_storage_list(sg_host_t host){
+xbt_dynar_t SIMIX_host_get_attached_storage_list(sg_host_t host)
+{
   xbt_assert((host != NULL), "Invalid parameters (simix host is NULL)");
-
-  return surf_host_get_attached_storage_list(host);
+  return host->extension<simgrid::surf::Host>()->getAttachedStorageList();
 }