Logo AND Algorithmique Numérique Distribuée

Public GIT Repository
Install some kernel header files for the users' plugins and more
[simgrid.git] / include / simgrid / kernel / resource / 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_RESOURCE_RESOURCE_HPP
7 #define SIMGRID_KERNEL_RESOURCE_RESOURCE_HPP
8
9 #include "src/surf/surf_interface.hpp"
10
11 namespace simgrid {
12 namespace kernel {
13 namespace resource {
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 class XBT_PUBLIC Resource {
20 public:
21   /**
22    * @brief Constructor of LMM Resources
23    *
24    * @param model Model associated to this Resource
25    * @param name The name of the Resource
26    * @param constraint The lmm constraint associated to this Resource if it is part of a LMM component
27    */
28   Resource(Model* model, const std::string& name, lmm::Constraint* constraint);
29
30   virtual ~Resource();
31
32   /** @brief Get the Model of the current Resource */
33   Model* model() const;
34
35   /** @brief Get the name of the current Resource */
36   const std::string& getName() const;
37   /** @brief Get the name of the current Resource */
38   const char* getCname() const;
39
40   bool operator==(const Resource& other) const;
41
42   /**
43    * @brief Apply an event of external load event to that resource
44    *
45    * @param event What happened
46    * @param value [TODO]
47    */
48   virtual void apply_event(tmgr_trace_event_t event, double value) = 0;
49
50   /** @brief Check if the current Resource is used (if it currently serves an action) */
51   virtual bool isUsed() = 0;
52
53   /** @brief returns the current load (in flops per second, byte per second or similar) */
54   virtual double getLoad();
55
56   /** @brief Check if the current Resource is active */
57   virtual bool isOn() const;
58   /** @brief Check if the current Resource is shut down */
59   virtual bool isOff() const;
60   /** @brief Turn on the current Resource */
61   virtual void turnOn();
62   /** @brief Turn off the current Resource */
63   virtual void turnOff();
64
65 private:
66   std::string name_;
67   Model* model_;
68   bool isOn_ = true;
69
70 public: /* LMM */
71   /** @brief Get the lmm constraint associated to this Resource if it is part of a LMM component (or null if none) */
72   kernel::lmm::Constraint* constraint() const;
73
74 private:
75   kernel::lmm::Constraint* const constraint_ = nullptr;
76
77 protected:
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 resource
85 } // namespace kernel
86 } // namespace simgrid
87
88 namespace std {
89 template <> class hash<simgrid::kernel::resource::Resource> {
90 public:
91   std::size_t operator()(const simgrid::kernel::resource::Resource& r) const
92   {
93     return (std::size_t)xbt_str_hash(r.getCname());
94   }
95 };
96 } // namespace std
97
98 #endif