Logo AND Algorithmique Numérique Distribuée

Public GIT Repository
Kill the useless NS3Sim class
[simgrid.git] / src / surf / surf_interface.hpp
index de6cfa5..66ed71d 100644 (file)
@@ -19,7 +19,6 @@
 
 #include "xbt/lib.h"
 #include "surf/surf_routing.h"
-#include "simgrid/platf_interface.h"
 #include "surf/surf.h"
 #include "src/surf/surf_private.h"
 #include "src/internal_config.h"
@@ -55,6 +54,10 @@ extern XBT_PRIVATE simgrid::xbt::signal<void(void)> surfExitCallbacks;
 
 int XBT_PRIVATE __surf_is_absolute_file_path(const char *file_path);
 
+static inline char* sg_storage_name(sg_storage_t storage) {
+  return storage->key;
+}
+
 /***********
  * Classes *
  ***********/
@@ -94,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
@@ -128,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();
@@ -223,9 +236,6 @@ private:
   double m_start; /**< start time  */
   char *p_category = NULL;            /**< tracing category for categorized resource utilization monitoring */
 
-  #ifdef HAVE_LATENCY_BOUND_TRACKING
-  int m_latencyLimited;               /**< Set to 1 if is limited by latency, 0 otherwise */
-  #endif
   double    m_cost;
   simgrid::surf::Model *p_model;
   void *p_data = NULL; /**< for your convenience */
@@ -274,31 +284,31 @@ public:
   virtual ~Model();
 
   /** @brief Get the set of [actions](@ref Action) in *ready* state */
-  virtual ActionList* getReadyActionSet() {return p_readyActionSet;}
+  virtual ActionList* getReadyActionSet() {return readyActionSet_;}
 
   /** @brief Get the set of [actions](@ref Action) in *running* state */
-  virtual ActionList* getRunningActionSet() {return p_runningActionSet;}
+  virtual ActionList* getRunningActionSet() {return runningActionSet_;}
 
   /** @brief Get the set of [actions](@ref Action) in *failed* state */
-  virtual ActionList* getFailedActionSet() {return p_failedActionSet;}
+  virtual ActionList* getFailedActionSet() {return failedActionSet_;}
 
   /** @brief Get the set of [actions](@ref Action) in *done* state */
-  virtual ActionList* getDoneActionSet() {return p_doneActionSet;}
+  virtual ActionList* getDoneActionSet() {return doneActionSet_;}
 
   /** @brief Get the set of modified [actions](@ref Action) */
-  virtual ActionLmmListPtr getModifiedSet() {return p_modifiedSet;}
+  virtual ActionLmmListPtr getModifiedSet() {return modifiedSet_;}
 
   /** @brief Get the maxmin system of the current Model */
-  lmm_system_t getMaxminSystem() {return p_maxminSystem;}
+  lmm_system_t getMaxminSystem() {return maxminSystem_;}
 
   /**
    * @brief Get the update mechanism of the current Model
    * @see e_UM_t
    */
-  e_UM_t getUpdateMechanism() {return p_updateMechanism;}
+  e_UM_t getUpdateMechanism() {return updateMechanism_;}
 
   /** @brief Get Action heap */
-  xbt_heap_t getActionHeap() {return p_actionHeap;}
+  xbt_heap_t getActionHeap() {return actionHeap_;}
 
   /**
    * @brief Share the resources between the actions
@@ -330,17 +340,17 @@ public:
   virtual bool next_occuring_event_isIdempotent()=0;
 
 protected:
-  ActionLmmListPtr p_modifiedSet;
-  lmm_system_t p_maxminSystem = nullptr;
-  e_UM_t p_updateMechanism = UM_UNDEFINED;
-  int m_selectiveUpdate;
-  xbt_heap_t p_actionHeap;
+  ActionLmmListPtr modifiedSet_;
+  lmm_system_t maxminSystem_ = nullptr;
+  e_UM_t updateMechanism_ = UM_UNDEFINED;
+  int selectiveUpdate_;
+  xbt_heap_t actionHeap_;
 
 private:
-  ActionList* p_readyActionSet; /**< Actions in state SURF_ACTION_READY */
-  ActionList* p_runningActionSet; /**< Actions in state SURF_ACTION_RUNNING */
-  ActionList* p_failedActionSet; /**< Actions in state SURF_ACTION_FAILED */
-  ActionList* p_doneActionSet; /**< Actions in state SURF_ACTION_DONE */
+  ActionList* readyActionSet_; /**< Actions in state SURF_ACTION_READY */
+  ActionList* runningActionSet_; /**< Actions in state SURF_ACTION_RUNNING */
+  ActionList* failedActionSet_; /**< Actions in state SURF_ACTION_FAILED */
+  ActionList* doneActionSet_; /**< Actions in state SURF_ACTION_DONE */
 };
 
 }
@@ -364,7 +374,7 @@ namespace surf {
 
 /** @ingroup SURF_interface
  * @brief SURF resource interface class
- * @details A resource represent an element of a component (e.g.: a link for the network)
+ * @details This is the ancestor class of every resources in SimGrid, such as links, CPU or storage
  */
 XBT_PUBLIC_CLASS Resource {
 public:
@@ -385,24 +395,15 @@ public:
    */
   Resource(Model *model, const char *name, lmm_constraint_t constraint);
 
-  Resource(Model *model, const char *name, lmm_constraint_t constraint, int initiallyOn);
-
-  /**
-   * @brief Resource constructor
-   *
-   * @param model Model associated to this Resource
-   * @param name The name of the Resource
-   * @param initiallyOn the initial state of the Resource
-   */
-  Resource(Model *model, const char *name, int initiallyOn);
-
   virtual ~Resource();
 
   /** @brief Get the Model of the current Resource */
-  Model *getModel();
+  Model *getModel() const;
 
   /** @brief Get the name of the current Resource */
-  const char *getName();
+  const char *getName() const;
+
+  bool operator==(const Resource &other) const;
 
   /**
    * @brief Apply an event of external load event to that storage
@@ -416,27 +417,38 @@ public:
   virtual bool isUsed()=0;
 
   /** @brief Check if the current Resource is active */
-  virtual bool isOn();
+  virtual bool isOn() const;
   /** @brief Check if the current Resource is shut down */
-  virtual bool isOff();
+  virtual bool isOff() const;
   /** @brief Turn on the current Resource */
   virtual void turnOn();
   /** @brief Turn off the current Resource */
   virtual void turnOff();
 
 private:
-  const char *p_name;
-  Model *p_model;
-  bool m_isOn;
+  const char *name_;
+  Model *model_;
+  bool isOn_ = true;
 
 public: /* LMM */
-  /** @brief Get the lmm constraint associated to this Resource if it is part of a LMM component */
-  lmm_constraint_t getConstraint();
+  /** @brief Get the lmm constraint associated to this Resource if it is part of a LMM component (or null if none) */
+  lmm_constraint_t getConstraint() const;
 protected:
-  lmm_constraint_t p_constraint = nullptr;
+  lmm_constraint_t constraint_ = nullptr;
 };
 
 }
 }
 
+namespace std {
+  template <>
+  struct hash<simgrid::surf::Resource>
+  {
+    std::size_t operator()(const simgrid::surf::Resource& r) const
+    {
+      return (std::size_t) xbt_str_hash(r.getName());
+    }
+  };
+}
+
 #endif /* SURF_MODEL_H_ */