Logo AND Algorithmique Numérique Distribuée

Public GIT Repository
move the definition of resource's Metric as an inner class
[simgrid.git] / src / kernel / model / Resource.hpp
1 /* Copyright (c) 2004-2018. The SimGrid Team. All rights reserved.          */
2
3 /* This program is free software; you can redistribute it and/or modify it
4  * under the terms of the license (GNU LGPL) which comes with this package. */
5
6 #ifndef SIMGRID_KERNEL_MODEL_RESOURCE_HPP
7 #define SIMGRID_KERNEL_MODEL_RESOURCE_HPP
8
9 #include "src/surf/surf_interface.hpp"
10
11 namespace simgrid {
12 namespace kernel {
13 namespace model {
14
15 /** @ingroup SURF_interface
16  * @brief SURF resource interface class
17  * @details This is the ancestor class of every resources in SimGrid, such as links, CPU or storage
18  */
19 XBT_PUBLIC_CLASS Resource
20 {
21 public:
22   /**
23    * @brief Constructor of LMM Resources
24    *
25    * @param model Model associated to this Resource
26    * @param name The name of the Resource
27    * @param constraint The lmm constraint associated to this Resource if it is part of a LMM component
28    */
29   Resource(surf::Model * model, const std::string& name, lmm::Constraint* constraint);
30
31   virtual ~Resource();
32
33   /** @brief Get the Model of the current Resource */
34   surf::Model* model() const;
35
36   /** @brief Get the name of the current Resource */
37   const std::string& getName() const;
38   /** @brief Get the name of the current Resource */
39   const char* getCname() const;
40
41   bool operator==(const Resource& other) const;
42
43   /**
44    * @brief Apply an event of external load event to that resource
45    *
46    * @param event What happened
47    * @param value [TODO]
48    */
49   virtual void apply_event(tmgr_trace_event_t event, double value) = 0;
50
51   /** @brief Check if the current Resource is used (if it currently serves an action) */
52   virtual bool isUsed() = 0;
53
54   /** @brief returns the current load (in flops per second, byte per second or similar) */
55   virtual double getLoad();
56
57   /** @brief Check if the current Resource is active */
58   virtual bool isOn() const;
59   /** @brief Check if the current Resource is shut down */
60   virtual bool isOff() const;
61   /** @brief Turn on the current Resource */
62   virtual void turnOn();
63   /** @brief Turn off the current Resource */
64   virtual void turnOff();
65
66 private:
67   std::string name_;
68   surf::Model* model_;
69   bool isOn_ = true;
70
71 public: /* LMM */
72   /** @brief Get the lmm constraint associated to this Resource if it is part of a LMM component (or null if none) */
73   kernel::lmm::Constraint* constraint() const;
74
75 protected:
76   const kernel::lmm::Constraint* constraint_ = nullptr;
77
78   struct Metric {
79     double peak;              /**< The peak of the metric, ie its max value */
80     double scale;             /**< Current availability of the metric according to the traces, in [0,1] */
81     tmgr_trace_event_t event; /**< The associated trace event associated to the metric */
82   };
83 };
84 } // namespace model
85 } // namespace kernel
86 } // namespace simgrid
87
88 namespace std {
89 template <> class hash<simgrid::kernel::model::Resource> {
90 public:
91   std::size_t operator()(const simgrid::kernel::model::Resource& r) const
92   {
93     return (std::size_t)xbt_str_hash(r.getCname());
94   }
95 };
96 } // namespace std
97
98 #endif