X-Git-Url: http://info.iut-bm.univ-fcomte.fr/pub/gitweb/simgrid.git/blobdiff_plain/39c935d6d5ee86d153f6f7e6a10d723ae7c57f6f..cf454dfcf7c27e86e15af1a45c58dbb7a76e43c8:/include/simgrid/kernel/resource/Resource.hpp diff --git a/include/simgrid/kernel/resource/Resource.hpp b/include/simgrid/kernel/resource/Resource.hpp index 05b5fdd8dc..9be92f6bfe 100644 --- a/include/simgrid/kernel/resource/Resource.hpp +++ b/include/simgrid/kernel/resource/Resource.hpp @@ -6,6 +6,7 @@ #ifndef SIMGRID_KERNEL_RESOURCE_RESOURCE_HPP #define SIMGRID_KERNEL_RESOURCE_RESOURCE_HPP +#include "src/kernel/lmm/maxmin.hpp" // Constraint #include #include #include @@ -19,14 +20,12 @@ namespace resource { /** @ingroup SURF_interface * @brief SURF resource interface class - * @details This is the ancestor class of every resources in SimGrid, such as links, CPU or storage + * @details This is the ancestor class of every resources in SimGrid, such as links, CPU or disk */ class XBT_PUBLIC Resource { - std::string name_; - Model* model_; - bool is_on_ = true; - - lmm::Constraint* const constraint_; + std::string name_ = "unnamed"; + bool is_on_ = true; + bool sealed_ = false; protected: struct Metric { @@ -37,22 +36,9 @@ protected: profile::Event* state_event_ = nullptr; public: - /** - * @brief Constructor of LMM Resources - * - * @param model Model associated to this Resource - * @param name The name of the Resource - * @param constraint The lmm constraint associated to this Resource if it is part of a LMM component - */ - Resource(Model* model, const std::string& name, lmm::Constraint* constraint) - : name_(name), model_(model), constraint_(constraint) - { - } - + Resource(const std::string& name) : name_(name){}; virtual ~Resource() = default; - - /** @brief Get the Model of the current Resource */ - Model* get_model() const { return model_; } + virtual void seal() { sealed_ = true; } /** @brief Get the name of the current Resource */ const std::string& get_name() const { return name_; } @@ -67,23 +53,46 @@ 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; } /** @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); +}; + +template class Resource_T : public Resource { + Model* model_ = nullptr; + lmm::Constraint* constraint_ = nullptr; + +public: + using Resource::Resource; + AnyResource* set_model(Model* model) + { + model_ = model; + return static_cast(this); + } + + Model* get_model() const { return model_; } + + AnyResource* set_constraint(lmm::Constraint* constraint) + { + constraint_ = constraint; + return static_cast(this); + } - /** @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_; } + + /** @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