]> AND Public Git Repository - simgrid.git/blobdiff - include/simgrid/kernel/resource/Resource.hpp
Logo AND Algorithmique Numérique Distribuée

Public GIT Repository
Merge branch 'factor_in_actions' into 'master'
[simgrid.git] / include / simgrid / kernel / resource / Resource.hpp
index 731207b7ff8c32cefa2cdafde493accdc2d8bc17..f1edd894f69bc0712b93f4996889e093b2557547 100644 (file)
@@ -6,6 +6,9 @@
 #ifndef SIMGRID_KERNEL_RESOURCE_RESOURCE_HPP
 #define SIMGRID_KERNEL_RESOURCE_RESOURCE_HPP
 
+#include "src/kernel/lmm/maxmin.hpp" // Constraint
+#include "src/kernel/resource/profile/FutureEvtSet.hpp"
+#include "src/kernel/resource/profile/Profile.hpp"
 #include <simgrid/forward.h>
 #include <xbt/signal.hpp>
 #include <xbt/str.h>
@@ -23,10 +26,8 @@ namespace resource {
  */
 class XBT_PUBLIC Resource {
   std::string name_ = "unnamed";
-  Model* model_     = nullptr;
   bool is_on_       = true;
-
-  lmm::Constraint* constraint_ = nullptr;
+  bool sealed_      = false;
 
 protected:
   struct Metric {
@@ -37,22 +38,15 @@ protected:
   profile::Event* state_event_ = nullptr;
 
 public:
-  Resource(const std::string& name) : name_(name){};
+  explicit Resource(const std::string& name) : name_(name){};
   virtual ~Resource() = default;
-
-  /** @brief Get the Model of the current Resource */
-  Model* get_model() const { return model_; }
-  Resource* set_model(Model* model);
+  virtual void seal() { sealed_ = true; }
 
   /** @brief Get the name of the current Resource */
   const std::string& get_name() const { return name_; }
   /** @brief Get the name of the current Resource */
   const char* get_cname() const { return name_.c_str(); }
 
-  /** @brief Get the lmm constraint associated to this Resource if it is part of a LMM component (or null if none) */
-  lmm::Constraint* get_constraint() const { return constraint_; }
-  Resource* set_constraint(lmm::Constraint* constraint);
-
   bool operator==(const Resource& other) const { return name_ == other.name_; }
 
   /** @brief Apply an event of external load event to that resource */
@@ -61,21 +55,55 @@ public:
   /** @brief Check if the current Resource is used (if it currently serves an action) */
   virtual bool is_used() const = 0;
 
-  /** @brief returns the current load due to activities (in flops per second, byte per second or similar)
-   *
-   * The load due to external usages modeled by profile files is ignored.*/
-  virtual double get_load() const;
-
   /** @brief Check if the current Resource is active */
   virtual bool is_on() const { return is_on_; }
+  virtual bool is_sealed() const { return sealed_; }
+
   /** @brief Turn on the current Resource */
   virtual void turn_on() { is_on_ = true; }
   /** @brief Turn off the current Resource */
   virtual void turn_off() { is_on_ = false; }
+};
+
+template <class AnyResource> class Resource_T : public Resource {
+  Model* model_                = nullptr;
+  lmm::Constraint* constraint_ = nullptr;
+
+public:
+  using Resource::Resource;
   /** @brief setup the profile file with states events (ON or OFF). The profile must contain boolean values. */
-  virtual void set_state_profile(profile::Profile* profile);
+  AnyResource* set_state_profile(profile::Profile* profile)
+  {
+    if (profile) {
+      xbt_assert(state_event_ == nullptr, "Cannot set a second state profile to %s", get_cname());
+      state_event_ = profile->schedule(&profile::future_evt_set, this);
+    }
 
+    return static_cast<AnyResource*>(this);
+  }
+
+  AnyResource* set_model(Model* model)
+  {
+    model_ = model;
+    return static_cast<AnyResource*>(this);
+  }
+
+  Model* get_model() const { return model_; }
+
+  AnyResource* set_constraint(lmm::Constraint* constraint)
+  {
+    constraint_ = constraint;
+    return static_cast<AnyResource*>(this);
+  }
+
+  lmm::Constraint* get_constraint() const { return constraint_; }
+
+  /** @brief returns the current load due to activities (in flops per second, byte per second or similar)
+   *
+   * The load due to external usages modeled by profile files is ignored.*/
+  virtual double get_load() const { return constraint_->get_usage(); }
 };
+
 } // namespace resource
 } // namespace kernel
 } // namespace simgrid