Logo AND Algorithmique Numérique Distribuée

Public GIT Repository
objectifies surf::Action::State
authorMartin Quinson <martin.quinson@loria.fr>
Sun, 20 Mar 2016 22:21:36 +0000 (23:21 +0100)
committerMartin Quinson <martin.quinson@loria.fr>
Sun, 20 Mar 2016 22:21:36 +0000 (23:21 +0100)
26 files changed:
src/include/surf/surf.h
src/simix/smx_host.cpp
src/simix/smx_io.cpp
src/simix/smx_network.cpp
src/simix/smx_process.cpp
src/simix/smx_synchro.cpp
src/surf/cpu_cas01.cpp
src/surf/cpu_interface.cpp
src/surf/cpu_interface.hpp
src/surf/cpu_ti.cpp
src/surf/cpu_ti.hpp
src/surf/network_cm02.cpp
src/surf/network_constant.cpp
src/surf/network_ib.cpp
src/surf/network_interface.cpp
src/surf/network_interface.hpp
src/surf/network_ns3.cpp
src/surf/plugins/energy.cpp
src/surf/ptask_L07.cpp
src/surf/storage_interface.cpp
src/surf/storage_interface.hpp
src/surf/storage_n11.cpp
src/surf/surf_interface.cpp
src/surf/surf_interface.hpp
src/surf/vm_hl13.cpp
teshsuite/surf/surf_usage/surf_usage.cpp

index 9b0bd39..fa33de3 100644 (file)
@@ -140,24 +140,7 @@ typedef struct surf_model_description {
 XBT_PUBLIC(int) find_model_description(s_surf_model_description_t * table, const char *name);
 XBT_PUBLIC(void) model_help(const char *category, s_surf_model_description_t * table);
 
-/** @ingroup SURF_interface
- *  @brief Action states
- *
- *  @see Action
- */
-typedef enum {
-  SURF_ACTION_READY = 0,        /**< Ready        */
-  SURF_ACTION_RUNNING,          /**< Running      */
-  SURF_ACTION_FAILED,           /**< Task Failure */
-  SURF_ACTION_DONE,             /**< Completed    */
-  SURF_ACTION_TO_FREE,          /**< Action to free in next cleanup */
-  SURF_ACTION_NOT_IN_THE_SYSTEM /**< Not in the system anymore. Why did you ask ? */
-} e_surf_action_state_t;
-
-/** @ingroup SURF_vm_interface
- *
- *
- */
+/** @ingroup SURF_vm_interface */
 /* FIXME: Where should the VM state be defined? */
 typedef enum {
   SURF_VM_STATE_CREATED, /**< created, but not yet started */
index 3ec8f17..4c0fd12 100644 (file)
@@ -483,7 +483,7 @@ void SIMIX_post_host_execute(smx_synchro_t synchro)
     /* 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;
-  } else if (synchro->execution.surf_exec->getState() == SURF_ACTION_FAILED) {
+  } else if (synchro->execution.surf_exec->getState() == simgrid::surf::Action::State::failed) {
     /* If the host running the synchro didn't fail, then the synchro was
      * canceled */
     synchro->state = SIMIX_CANCELED;
index 046ff2f..96224c6 100644 (file)
@@ -326,11 +326,11 @@ void SIMIX_post_io(smx_synchro_t synchro)
 
   switch (synchro->io.surf_io->getState()) {
 
-    case SURF_ACTION_FAILED:
+    case simgrid::surf::Action::State::failed:
       synchro->state = SIMIX_FAILED;
       break;
 
-    case SURF_ACTION_DONE:
+    case simgrid::surf::Action::State::done:
       synchro->state = SIMIX_DONE;
       break;
 
index b57a60e..9b79a4f 100644 (file)
@@ -707,7 +707,7 @@ static inline void SIMIX_comm_start(smx_synchro_t synchro)
     synchro->state = SIMIX_RUNNING;
 
     /* If a link is failed, detect it immediately */
-    if (synchro->comm.surf_comm->getState() == SURF_ACTION_FAILED) {
+    if (synchro->comm.surf_comm->getState() == simgrid::surf::Action::State::failed) {
       XBT_DEBUG("Communication from '%s' to '%s' failed to start because of a link failure",
                 sg_host_get_name(sender), sg_host_get_name(receiver));
       synchro->state = SIMIX_LINK_FAILURE;
@@ -875,19 +875,19 @@ void SIMIX_post_comm(smx_synchro_t synchro)
 {
   /* Update synchro state */
   if (synchro->comm.src_timeout &&
-      synchro->comm.src_timeout->getState() == SURF_ACTION_DONE)
+      synchro->comm.src_timeout->getState() == simgrid::surf::Action::State::done)
     synchro->state = SIMIX_SRC_TIMEOUT;
   else if (synchro->comm.dst_timeout &&
-    synchro->comm.dst_timeout->getState() == SURF_ACTION_DONE)
+    synchro->comm.dst_timeout->getState() == simgrid::surf::Action::State::done)
     synchro->state = SIMIX_DST_TIMEOUT;
   else if (synchro->comm.src_timeout &&
-    synchro->comm.src_timeout->getState() == SURF_ACTION_FAILED)
+    synchro->comm.src_timeout->getState() == simgrid::surf::Action::State::failed)
     synchro->state = SIMIX_SRC_HOST_FAILURE;
   else if (synchro->comm.dst_timeout &&
-      synchro->comm.dst_timeout->getState() == SURF_ACTION_FAILED)
+      synchro->comm.dst_timeout->getState() == simgrid::surf::Action::State::failed)
     synchro->state = SIMIX_DST_HOST_FAILURE;
   else if (synchro->comm.surf_comm &&
-    synchro->comm.surf_comm->getState() == SURF_ACTION_FAILED) {
+    synchro->comm.surf_comm->getState() == simgrid::surf::Action::State::failed) {
     XBT_DEBUG("Puta madre. Surf says that the link broke");
     synchro->state = SIMIX_LINK_FAILURE;
   } else
index 81e6ab5..93c852e 100644 (file)
@@ -926,13 +926,13 @@ void SIMIX_post_process_sleep(smx_synchro_t synchro)
   while ((simcall = (smx_simcall_t) xbt_fifo_shift(synchro->simcalls))) {
 
     switch (synchro->sleep.surf_sleep->getState()){
-      case SURF_ACTION_FAILED:
+      case simgrid::surf::Action::State::failed:
         simcall->issuer->context->iwannadie = 1;
         //SMX_EXCEPTION(simcall->issuer, host_error, 0, "Host failed");
         state = SIMIX_SRC_HOST_FAILURE;
         break;
 
-      case SURF_ACTION_DONE:
+      case simgrid::surf::Action::State::done:
         state = SIMIX_DONE;
         break;
 
index b8eff39..de245a8 100644 (file)
@@ -82,9 +82,9 @@ void SIMIX_post_synchro(smx_synchro_t synchro)
 {
   XBT_IN("(%p)",synchro);
   xbt_assert(synchro->type == SIMIX_SYNC_SYNCHRO);
-  if (synchro->synchro.sleep->getState() == SURF_ACTION_FAILED)
+  if (synchro->synchro.sleep->getState() == simgrid::surf::Action::State::failed)
     synchro->state = SIMIX_FAILED;
-  else if(synchro->synchro.sleep->getState() == SURF_ACTION_DONE)
+  else if(synchro->synchro.sleep->getState() == simgrid::surf::Action::State::done)
     synchro->state = SIMIX_SRC_TIMEOUT;
 
   SIMIX_synchro_finish(synchro);  
index 2c4435c..d48972e 100644 (file)
@@ -164,11 +164,11 @@ void CpuCas01::apply_event(tmgr_trace_iterator_t event, double value)
       while ((var = lmm_get_var_from_cnst(getModel()->getMaxminSystem(), cnst, &elem))) {
         Action *action = static_cast<Action*>(lmm_variable_id(var));
 
-        if (action->getState() == SURF_ACTION_RUNNING ||
-            action->getState() == SURF_ACTION_READY ||
-            action->getState() == SURF_ACTION_NOT_IN_THE_SYSTEM) {
+        if (action->getState() == Action::State::running ||
+            action->getState() == Action::State::ready ||
+            action->getState() == Action::State::not_in_the_system) {
           action->setFinishTime(date);
-          action->setState(SURF_ACTION_FAILED);
+          action->setState(Action::State::failed);
         }
       }
     }
index 94ba64d..cb9e788 100644 (file)
@@ -24,7 +24,7 @@ namespace surf {
  * Callbacks *
  *************/
 
-simgrid::xbt::signal<void(CpuAction*, e_surf_action_state_t, e_surf_action_state_t)> cpuActionStateChangedCallbacks;
+simgrid::xbt::signal<void(CpuAction*, Action::State, Action::State)> cpuActionStateChangedCallbacks;
 
 /*********
  * Model *
@@ -50,7 +50,7 @@ void CpuModel::updateActionsStateLazy(double now, double /*delta*/)
 
     /* set the remains to 0 due to precision problems when updating the remaining amount */
     action->setRemains(0);
-    action->setState(SURF_ACTION_DONE);
+    action->setState(Action::State::done);
     action->heapRemove(getActionHeap()); //FIXME: strange call since action was already popped
   }
   if (TRACE_is_enabled()) {
@@ -106,11 +106,11 @@ void CpuModel::updateActionsStateFull(double now, double delta)
     if ((action->getRemainsNoUpdate() <= 0) &&
         (lmm_get_variable_weight(action->getVariable()) > 0)) {
       action->finish();
-      action->setState(SURF_ACTION_DONE);
+      action->setState(Action::State::done);
     } else if ((action->getMaxDuration() != NO_MAX_DURATION) &&
                (action->getMaxDuration() <= 0)) {
       action->finish();
-      action->setState(SURF_ACTION_DONE);
+      action->setState(Action::State::done);
     }
   }
 }
@@ -330,10 +330,10 @@ void CpuAction::setAffinity(Cpu *cpu, unsigned long mask)
   XBT_OUT();
 }
 
-simgrid::xbt::signal<void(simgrid::surf::CpuAction*, e_surf_action_state_t)> CpuAction::onStateChange;
+simgrid::xbt::signal<void(simgrid::surf::CpuAction*, Action::State)> CpuAction::onStateChange;
 
-void CpuAction::setState(e_surf_action_state_t state){
-  e_surf_action_state_t previous = getState();
+void CpuAction::setState(Action::State state){
+  Action::State previous = getState();
   Action::setState(state);
   onStateChange(this, previous);
 }
index 380e6b7..5716541 100644 (file)
@@ -148,9 +148,9 @@ XBT_PUBLIC_CLASS CpuAction : public simgrid::surf::Action {
 friend XBT_PUBLIC(Cpu*) getActionCpu(CpuAction *action);
 public:
   /** @brief Callbacks handler which emit the callbacks after CpuAction State changed *
-   * @details Callback functions have the following signature: `void(CpuAction *action, e_surf_action_state_t previous)`
+   * @details Callback functions have the following signature: `void(CpuAction *action, simgrid::surf::Action::State previous)`
    */
-  static simgrid::xbt::signal<void(simgrid::surf::CpuAction*, e_surf_action_state_t)> onStateChange;
+  static simgrid::xbt::signal<void(simgrid::surf::CpuAction*, simgrid::surf::Action::State)> onStateChange;
 
   CpuAction(simgrid::surf::Model *model, double cost, bool failed)
   : Action(model, cost, failed) {} //FIXME:DEADCODE?
@@ -160,11 +160,10 @@ public:
   /** @brief Set the affinity of the current CpuAction */
   virtual void setAffinity(Cpu *cpu, unsigned long mask);
 
-  void setState(e_surf_action_state_t state);
+  void setState(simgrid::surf::Action::State state) override;
 
   void updateRemainingLazy(double now);
   std::list<Cpu*> cpus();
-
 };
 
 }
index 39c4b5c..4e7b6e6 100644 (file)
@@ -449,7 +449,7 @@ void CpuTiModel::updateActionsState(double now, double /*delta*/)
     action->finish();
     /* set the remains to 0 due to precision problems when updating the remaining amount */
     action->setRemains(0);
-    action->setState(SURF_ACTION_DONE);
+    action->setState(Action::State::done);
     /* update remaining amount of all actions */
     action->cpu_->updateRemainingAmount(surf_get_clock());
   }
@@ -533,11 +533,11 @@ void CpuTi::apply_event(tmgr_trace_iterator_t event, double value)
           ; it != itend ; ++it) {
 
         CpuTiAction *action = &*it;
-        if (action->getState() == SURF_ACTION_RUNNING
-         || action->getState() == SURF_ACTION_READY
-         || action->getState() == SURF_ACTION_NOT_IN_THE_SYSTEM) {
+        if (action->getState() == Action::State::running
+         || action->getState() == Action::State::ready
+         || action->getState() == Action::State::not_in_the_system) {
           action->setFinishTime(date);
-          action->setState(SURF_ACTION_FAILED);
+          action->setState(Action::State::failed);
           if (action->indexHeap_ >= 0) {
             CpuTiAction *heap_act = (CpuTiAction*)
                 xbt_heap_remove(static_cast<CpuTiModel*>(getModel())->tiActionHeap_, action->indexHeap_);
@@ -748,7 +748,7 @@ void CpuTiAction::updateIndexHeap(int i)
   indexHeap_ = i;
 }
 
-void CpuTiAction::setState(e_surf_action_state_t state)
+void CpuTiAction::setState(Action::State state)
 {
   CpuAction::setState(state);
   cpu_->modified(true);
@@ -774,7 +774,7 @@ int CpuTiAction::unref()
 
 void CpuTiAction::cancel()
 {
-  this->setState(SURF_ACTION_FAILED);
+  this->setState(Action::State::failed);
   xbt_heap_remove(getModel()->getActionHeap(), this->indexHeap_);
   cpu_->modified(true);
   return;
index bf841ed..9d3491d 100644 (file)
@@ -84,7 +84,7 @@ class CpuTiAction: public CpuAction {
 public:
   CpuTiAction(CpuTiModel *model, double cost, bool failed, CpuTi *cpu);
 
-  void setState(e_surf_action_state_t state) override;
+  void setState(simgrid::surf::Action::State state) override;
   int unref() override;
   void cancel() override;
   void updateIndexHeap(int i);
index d88a052..a32ccb8 100644 (file)
@@ -215,7 +215,7 @@ void NetworkCm02Model::updateActionsStateLazy(double now, double /*delta*/)
       XBT_DEBUG("Action %p finished", action);
       action->setRemains(0);
       action->finish();
-      action->setState(SURF_ACTION_DONE);
+      action->setState(Action::State::done);
       action->heapRemove(actionHeap_);
 
       action->gapRemove();
@@ -280,12 +280,12 @@ void NetworkCm02Model::updateActionsStateFull(double now, double delta)
     if ((action->getRemains() <= 0) &&
         (lmm_get_variable_weight(action->getVariable()) > 0)) {
       action->finish();
-      action->setState(SURF_ACTION_DONE);
+      action->setState(Action::State::done);
       action->gapRemove();
     } else if (((action->getMaxDuration() != NO_MAX_DURATION)
         && (action->getMaxDuration() <= 0))) {
       action->finish();
-      action->setState(SURF_ACTION_DONE);
+      action->setState(Action::State::done);
       action->gapRemove();
     }
   }
@@ -438,10 +438,10 @@ void NetworkCm02Link::apply_event(tmgr_trace_iterator_t triggered, double value)
       while ((var = lmm_get_var_from_cnst(getModel()->getMaxminSystem(), getConstraint(), &elem))) {
         Action *action = static_cast<Action*>( lmm_variable_id(var) );
 
-        if (action->getState() == SURF_ACTION_RUNNING ||
-            action->getState() == SURF_ACTION_READY) {
+        if (action->getState() == Action::State::running ||
+            action->getState() == Action::State::ready) {
           action->setFinishTime(now);
-          action->setState(SURF_ACTION_FAILED);
+          action->setState(Action::State::failed);
         }
       }
     }
@@ -532,13 +532,13 @@ void NetworkCm02Action::updateRemainingLazy(double now)
   if (m_remains <= 0 &&
       (lmm_get_variable_weight(getVariable()) > 0)) {
     finish();
-    setState(SURF_ACTION_DONE);
+    setState(Action::State::done);
 
     heapRemove(getModel()->getActionHeap());
   } else if (((m_maxDuration != NO_MAX_DURATION)
       && (m_maxDuration <= 0))) {
     finish();
-    setState(SURF_ACTION_DONE);
+    setState(Action::State::done);
     heapRemove(getModel()->getActionHeap());
   }
 
index d7dd2ad..e68c91d 100644 (file)
@@ -69,11 +69,11 @@ namespace simgrid {
 
         if (action->getRemainsNoUpdate() <= 0) {
           action->finish();
-          action->setState(SURF_ACTION_DONE);
+          action->setState(Action::State::done);
         } else if ((action->getMaxDuration() != NO_MAX_DURATION)
             && (action->getMaxDuration() <= 0)) {
           action->finish();
-          action->setState(SURF_ACTION_DONE);
+          action->setState(Action::State::done);
         }
       }
     }
index d373a38..de2c180 100644 (file)
@@ -33,10 +33,10 @@ static void IB_create_host_callback(simgrid::s4u::Host& host){
 
 static void IB_action_state_changed_callback(
     simgrid::surf::NetworkAction *action,
-    e_surf_action_state_t statein, e_surf_action_state_t stateout)
+    simgrid::surf::Action::State statein, simgrid::surf::Action::State stateout)
 {
   using namespace simgrid::surf;
-  if(statein!=SURF_ACTION_RUNNING|| stateout!=SURF_ACTION_DONE)
+  if(statein!=simgrid::surf::Action::State::running || stateout!=simgrid::surf::Action::State::done)
     return;
   std::pair<IBNode*,IBNode*> pair = ((NetworkIBModel*)surf_network_model)->active_comms[action];
   XBT_DEBUG("IB callback - action %p finished", action);
index ae90c04..a4b3e23 100644 (file)
@@ -95,7 +95,7 @@ namespace simgrid {
     simgrid::xbt::signal<void(simgrid::surf::Link*)> Link::onDestruction;
     simgrid::xbt::signal<void(simgrid::surf::Link*)> Link::onStateChange;
 
-    simgrid::xbt::signal<void(simgrid::surf::NetworkAction*, e_surf_action_state_t, e_surf_action_state_t)> networkActionStateChangedCallbacks;
+    simgrid::xbt::signal<void(simgrid::surf::NetworkAction*, simgrid::surf::Action::State, simgrid::surf::Action::State)> networkActionStateChangedCallbacks;
     simgrid::xbt::signal<void(simgrid::surf::NetworkAction*, simgrid::surf::NetCard *src, simgrid::surf::NetCard *dst, double size, double rate)> networkCommunicateCallbacks;
 
   }
@@ -265,8 +265,8 @@ namespace simgrid {
      * Action *
      **********/
 
-    void NetworkAction::setState(e_surf_action_state_t state){
-      e_surf_action_state_t old = getState();
+    void NetworkAction::setState(Action::State state){
+      Action::State old = getState();
       Action::setState(state);
       networkActionStateChangedCallbacks(this, old, state);
     }
index 0369963..4b4c256 100644 (file)
@@ -35,8 +35,8 @@ namespace simgrid {
 
 
     /** @brief Callback signal fired when the state of a NetworkAction changes
-     *  Signature: `void(NetworkAction *action, e_surf_action_state_t old, e_surf_action_state_t current)` */
-    XBT_PUBLIC_DATA(simgrid::xbt::signal<void(simgrid::surf::NetworkAction*, e_surf_action_state_t, e_surf_action_state_t)>) networkActionStateChangedCallbacks;
+     *  Signature: `void(NetworkAction *action, simgrid::surf::Action::State old, simgrid::surf::Action::State current)` */
+    XBT_PUBLIC_DATA(simgrid::xbt::signal<void(simgrid::surf::NetworkAction*, simgrid::surf::Action::State, simgrid::surf::Action::State)>) networkActionStateChangedCallbacks;
 
     /** @brief Callback signal fired when a NetworkAction is created (when a communication starts)
      *  Signature: `void(NetworkAction *action, RoutingEdge *src, RoutingEdge *dst, double size, double rate)` */
@@ -274,7 +274,7 @@ namespace simgrid {
       NetworkAction(simgrid::surf::Model *model, double cost, bool failed, lmm_variable_t var)
       : simgrid::surf::Action(model, cost, failed, var) {};
 
-      void setState(e_surf_action_state_t state);
+      void setState(simgrid::surf::Action::State state) override;
 
       double latency_;
       double latCurrent_;
index 59a28ea..d3f0405 100644 (file)
@@ -323,7 +323,7 @@ void NetworkNS3Model::updateActionsState(double now, double delta)
     action->setRemains(action->getCost() - ns3_get_socket_sent(data));
 
     if (TRACE_is_enabled() &&
-        action->getState() == SURF_ACTION_RUNNING){
+        action->getState() == Action::State::running){
       double data_sent = ns3_get_socket_sent(data);
       double data_delta_sent = data_sent - action->m_lastSent;
 
@@ -341,7 +341,7 @@ void NetworkNS3Model::updateActionsState(double now, double delta)
       xbt_dynar_push(socket_to_destroy,&key);
       XBT_DEBUG("Destroy socket %p of action %p", key, action);
       action->finish();
-      action->setState(SURF_ACTION_DONE);
+      action->setState(Action::State::done);
     }
   }
 
index fdd672d..8abd780 100644 (file)
@@ -205,7 +205,7 @@ static void onCreation(simgrid::s4u::Host& host) {
   host.extension_set(new HostEnergy(&host));
 }
 
-static void onActionStateChange(simgrid::surf::CpuAction *action, e_surf_action_state_t previous) {
+static void onActionStateChange(simgrid::surf::CpuAction *action, simgrid::surf::Action::State previous) {
   for(simgrid::surf::Cpu* cpu : action->cpus()) {
     const char *name = cpu->getName();
     sg_host_t sghost = sg_host_by_name(name);
index be2a600..558a96b 100644 (file)
@@ -143,11 +143,11 @@ void HostL07Model::updateActionsState(double /*now*/, double delta) {
     if ((action->getRemains() <= 0) &&
         (lmm_get_variable_weight(action->getVariable()) > 0)) {
       action->finish();
-      action->setState(SURF_ACTION_DONE);
+      action->setState(Action::State::done);
     } else if ((action->getMaxDuration() != NO_MAX_DURATION) &&
                (action->getMaxDuration() <= 0)) {
       action->finish();
-      action->setState(SURF_ACTION_DONE);
+      action->setState(Action::State::done);
     } else {
       /* Need to check that none of the model has failed */
       lmm_constraint_t cnst = NULL;
@@ -159,7 +159,7 @@ void HostL07Model::updateActionsState(double /*now*/, double delta) {
         if (static_cast<HostImpl*>(constraint_id)->isOff()) {
           XBT_DEBUG("Action (%p) Failed!!", action);
           action->finish();
-          action->setState(SURF_ACTION_FAILED);
+          action->setState(Action::State::failed);
           break;
         }
       }
index 61c105c..cf639a3 100644 (file)
@@ -27,10 +27,10 @@ namespace surf {
  * Callbacks *
  *************/
 
-simgrid::xbt::signal<void(simgrid::surf::Storage*)> storageCreatedCallbacks;
-simgrid::xbt::signal<void(simgrid::surf::Storage*)> storageDestructedCallbacks;
-simgrid::xbt::signal<void(simgrid::surf::Storage*, int, int)> storageStateChangedCallbacks; // signature: wasOn, isOn
-simgrid::xbt::signal<void(simgrid::surf::StorageAction*, e_surf_action_state_t, e_surf_action_state_t)> storageActionStateChangedCallbacks;
+simgrid::xbt::signal<void(Storage*)> storageCreatedCallbacks;
+simgrid::xbt::signal<void(Storage*)> storageDestructedCallbacks;
+simgrid::xbt::signal<void(Storage*, int, int)> storageStateChangedCallbacks; // signature: wasOn, isOn
+simgrid::xbt::signal<void(StorageAction*, Action::State, Action::State)> storageActionStateChangedCallbacks;
 
 /*********
  * Model *
@@ -196,8 +196,8 @@ StorageAction::StorageAction(Model *model, double cost, bool failed, lmm_variabl
   progress = 0;
 }
 
-void StorageAction::setState(e_surf_action_state_t state){
-  e_surf_action_state_t old = getState();
+void StorageAction::setState(Action::State state){
+  Action::State old = getState();
   Action::setState(state);
   storageActionStateChangedCallbacks(this, old, state);
 }
index 3ba65bf..e00bd45 100644 (file)
@@ -48,9 +48,9 @@ XBT_PUBLIC_DATA(simgrid::xbt::signal<void(simgrid::surf::Storage*, int, int)>) s
 
 /** @ingroup SURF_callbacks
  * @brief Callbacks handler which emit the callbacks after StorageAction State changed *
- * @details Callback functions have the following signature: `void(StorageAction *action, e_surf_action_state_t old, e_surf_action_state_t current)`
+ * @details Callback functions have the following signature: `void(StorageAction *action, simgrid::surf::Action::State old, simgrid::surf::Action::State current)`
  */
-XBT_PUBLIC_DATA(simgrid::xbt::signal<void(simgrid::surf::StorageAction*, e_surf_action_state_t, e_surf_action_state_t)>) storageActionStateChangedCallbacks;
+XBT_PUBLIC_DATA(simgrid::xbt::signal<void(simgrid::surf::StorageAction*, simgrid::surf::Action::State, simgrid::surf::Action::State)>) storageActionStateChangedCallbacks;
 
 /*********
  * Model *
@@ -268,7 +268,7 @@ public:
   StorageAction(Model *model, double cost, bool failed, lmm_variable_t var,
       Storage *storage, e_surf_action_storage_type_t type);
 
-  void setState(e_surf_action_state_t state);
+  void setState(simgrid::surf::Action::State state) override;
 
   e_surf_action_storage_type_t m_type;
   Storage *p_storage;
index e647885..81308c1 100644 (file)
@@ -201,17 +201,17 @@ void StorageN11Model::updateActionsState(double /*now*/, double delta)
         action->p_storage->m_usedSize == action->p_storage->m_size)
     {
       action->finish();
-      action->setState(SURF_ACTION_FAILED);
+      action->setState(Action::State::failed);
     } else if ((action->getRemainsNoUpdate() <= 0) &&
         (lmm_get_variable_weight(action->getVariable()) > 0))
     {
       action->finish();
-      action->setState(SURF_ACTION_DONE);
+      action->setState(Action::State::done);
     } else if ((action->getMaxDuration() != NO_MAX_DURATION) &&
         (action->getMaxDuration() <= 0))
     {
       action->finish();
-      action->setState(SURF_ACTION_DONE);
+      action->setState(Action::State::done);
     }
   }
   return;
@@ -309,7 +309,7 @@ StorageAction *StorageN11::write(surf_file_t fd, sg_size_t size)
   m_usedSize -= (fd->size - fd->current_position);
   // If the storage is full before even starting to write
   if(m_usedSize==m_size) {
-    action->setState(SURF_ACTION_FAILED);
+    action->setState(Action::State::failed);
   }
   return action;
 }
@@ -365,7 +365,7 @@ int StorageN11Action::unref()
 
 void StorageN11Action::cancel()
 {
-  setState(SURF_ACTION_FAILED);
+  setState(Action::State::failed);
   return;
 }
 
index 1dcc754..6373037 100644 (file)
@@ -674,38 +674,41 @@ void Action::finish() {
     m_finish = surf_get_clock();
 }
 
-e_surf_action_state_t Action::getState()
+Action::State Action::getState()
 {
   if (p_stateSet ==  getModel()->getReadyActionSet())
-    return SURF_ACTION_READY;
+    return Action::State::ready;
   if (p_stateSet ==  getModel()->getRunningActionSet())
-    return SURF_ACTION_RUNNING;
+    return Action::State::running;
   if (p_stateSet ==  getModel()->getFailedActionSet())
-    return SURF_ACTION_FAILED;
+    return Action::State::failed;
   if (p_stateSet ==  getModel()->getDoneActionSet())
-    return SURF_ACTION_DONE;
-  return SURF_ACTION_NOT_IN_THE_SYSTEM;
+    return Action::State::done;
+  return Action::State::not_in_the_system;
 }
 
-void Action::setState(e_surf_action_state_t state)
+void Action::setState(Action::State state)
 {
-  //surf_action_state_t action_state = &(action->model_type->states);
-  XBT_IN("(%p,%s)", this, surf_action_state_names[state]);
   p_stateSet->erase(p_stateSet->iterator_to(*this));
-  if (state == SURF_ACTION_READY)
+  switch (state) {
+  case Action::State::ready:
     p_stateSet = getModel()->getReadyActionSet();
-  else if (state == SURF_ACTION_RUNNING)
+    break;
+  case Action::State::running:
     p_stateSet = getModel()->getRunningActionSet();
-  else if (state == SURF_ACTION_FAILED)
+    break;
+  case Action::State::failed:
     p_stateSet = getModel()->getFailedActionSet();
-  else if (state == SURF_ACTION_DONE)
+    break;
+  case Action::State::done:
     p_stateSet = getModel()->getDoneActionSet();
-  else
+    break;
+  default:
     p_stateSet = NULL;
-
+    break;
+  }
   if (p_stateSet)
     p_stateSet->push_back(*this);
-  XBT_OUT();
 }
 
 double Action::getBound()
@@ -774,7 +777,7 @@ void Action::setPriority(double priority)
 }
 
 void Action::cancel(){
-  setState(SURF_ACTION_FAILED);
+  setState(Action::State::failed);
   if (getModel()->getUpdateMechanism() == UM_LAZY) {
     if (action_lmm_hook.is_linked())
       getModel()->getModifiedSet()->erase(getModel()->getModifiedSet()->iterator_to(*this));
@@ -922,12 +925,12 @@ void Action::updateRemainingLazy(double now)
     if ((m_remains <= 0) &&
         (lmm_get_variable_weight(getVariable()) > 0)) {
       finish();
-      setState(SURF_ACTION_DONE);
+      setState(Action::State::done);
       heapRemove(getModel()->getActionHeap());
     } else if (((m_maxDuration != NO_MAX_DURATION)
         && (m_maxDuration <= 0))) {
       finish();
-      setState(SURF_ACTION_DONE);
+      setState(Action::State::done);
       heapRemove(getModel()->getActionHeap());
     }
   }
index 6d98129..f51e48b 100644 (file)
@@ -97,6 +97,16 @@ public:
   typedef boost::intrusive::member_hook<
     Action, boost::intrusive::list_member_hook<>, &Action::action_hook> ActionOptions;
   typedef boost::intrusive::list<Action, ActionOptions> ActionList;
+
+  enum class State {
+    ready = 0,        /**< Ready        */
+    running,          /**< Running      */
+    failed,           /**< Task Failure */
+    done,             /**< Completed    */
+    to_free,          /**< Action to free in next cleanup */
+    not_in_the_system /**< Not in the system anymore. Why did you ask ? */
+  };
+
 private:
   /**
    * @brief Common initializations for the constructors
@@ -131,9 +141,9 @@ public:
   void finish();
 
   /** @brief Get the [state](\ref e_surf_action_state_t) of the current Action */
-  e_surf_action_state_t getState(); /**< get the state*/
+  Action::State getState(); /**< get the state*/
   /** @brief Set the [state](\ref e_surf_action_state_t) of the current Action */
-  virtual void setState(e_surf_action_state_t state);
+  virtual void setState(Action::State state);
 
   /** @brief Get the bound of the current Action */
   double getBound();
index 63248cf..b17a570 100644 (file)
@@ -193,9 +193,9 @@ void VMHL13::migrate(sg_host_t host_dest)
      /* create a cpu action bound to the pm model at the destination. */
      CpuAction *new_cpu_action = static_cast<CpuAction*>(host_dest->pimpl_cpu->execution_start(0));
 
-     e_surf_action_state_t state = p_action->getState();
-     if (state != SURF_ACTION_DONE)
-       XBT_CRITICAL("FIXME: may need a proper handling, %d", state);
+     Action::State state = p_action->getState();
+     if (state != Action::State::done)
+       XBT_CRITICAL("FIXME: may need a proper handling, %d", static_cast<int>(state));
      if (p_action->getRemainsNoUpdate() > 0)
        XBT_CRITICAL("FIXME: need copy the state(?), %f", p_action->getRemainsNoUpdate());
 
index 4b5a9e9..17c8002 100644 (file)
 #include "xbt/log.h"
 XBT_LOG_NEW_DEFAULT_CATEGORY(surf_test, "Messages specific for surf example");
 
-static const char *string_action(e_surf_action_state_t state)
+static const char *string_action(simgrid::surf::Action::State state)
 {
   switch (state) {
-  case (SURF_ACTION_READY):
+  case (simgrid::surf::Action::State::ready):
     return "SURF_ACTION_READY";
-  case (SURF_ACTION_RUNNING):
+  case (simgrid::surf::Action::State::running):
     return "SURF_ACTION_RUNNING";
-  case (SURF_ACTION_FAILED):
+  case (simgrid::surf::Action::State::failed):
     return "SURF_ACTION_FAILED";
-  case (SURF_ACTION_DONE):
+  case (simgrid::surf::Action::State::done):
     return "SURF_ACTION_DONE";
-  case (SURF_ACTION_NOT_IN_THE_SYSTEM):
+  case (simgrid::surf::Action::State::not_in_the_system):
     return "SURF_ACTION_NOT_IN_THE_SYSTEM";
   default:
     return "INVALID STATE";
@@ -59,9 +59,9 @@ int main(int argc, char **argv)
   surf_action_t actionC = surf_host_sleep(hostB, 7.32);
 
   /* Use whatever calling style you want... */
-  e_surf_action_state_t stateActionA = actionA->getState(); /* When you know actionA model type */
-  e_surf_action_state_t stateActionB = actionB->getState(); /* If you're unsure about it's model type */
-  e_surf_action_state_t stateActionC = actionC->getState(); /* When you know actionA model type */
+  simgrid::surf::Action::State stateActionA = actionA->getState(); /* When you know actionA model type */
+  simgrid::surf::Action::State stateActionB = actionB->getState(); /* If you're unsure about it's model type */
+  simgrid::surf::Action::State stateActionC = actionC->getState(); /* When you know actionA model type */
 
   /* And just look at the state of these tasks */
   XBT_INFO("actionA state: %s", string_action(stateActionA));