Logo AND Algorithmique Numérique Distribuée

Public GIT Repository
Merge branch 'master' of git+ssh://scm.gforge.inria.fr//gitroot/simgrid/simgrid
[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 <simgrid/forward.h>
10 #include <xbt/signal.hpp>
11 #include <xbt/str.h>
12 #include <xbt/utility.hpp>
13
14 namespace simgrid {
15 namespace kernel {
16 namespace resource {
17
18 /** @ingroup SURF_interface
19  * @brief SURF resource interface class
20  * @details This is the ancestor class of every resources in SimGrid, such as links, CPU or storage
21  */
22 class XBT_PUBLIC Resource {
23 public:
24   /**
25    * @brief Constructor of LMM Resources
26    *
27    * @param model Model associated to this Resource
28    * @param name The name of the Resource
29    * @param constraint The lmm constraint associated to this Resource if it is part of a LMM component
30    */
31   Resource(Model* model, const std::string& name, lmm::Constraint* constraint);
32
33   virtual ~Resource();
34
35   /** @brief Get the Model of the current Resource */
36   Model* model() const;
37
38   /** @brief Get the name of the current Resource */
39   const std::string& getName() const;
40   /** @brief Get the name of the current Resource */
41   const char* getCname() const;
42
43   bool operator==(const Resource& other) const;
44
45   /**
46    * @brief Apply an event of external load event to that resource
47    *
48    * @param event What happened
49    * @param value [TODO]
50    */
51   virtual void apply_event(TraceEvent* event, double value) = 0;
52
53   /** @brief Check if the current Resource is used (if it currently serves an action) */
54   virtual bool isUsed() = 0;
55
56   /** @brief returns the current load (in flops per second, byte per second or similar) */
57   virtual double getLoad();
58
59   /** @brief Check if the current Resource is active */
60   virtual bool isOn() const;
61   /** @brief Check if the current Resource is shut down */
62   virtual bool isOff() const;
63   /** @brief Turn on the current Resource */
64   virtual void turnOn();
65   /** @brief Turn off the current Resource */
66   virtual void turnOff();
67
68 private:
69   std::string name_;
70   Model* model_;
71   bool isOn_ = true;
72
73 public: /* LMM */
74   /** @brief Get the lmm constraint associated to this Resource if it is part of a LMM component (or null if none) */
75   kernel::lmm::Constraint* constraint() const;
76
77 private:
78   kernel::lmm::Constraint* const constraint_ = nullptr;
79
80 protected:
81   struct Metric {
82     double peak;       /**< The peak of the metric, ie its max value */
83     double scale;      /**< Current availability of the metric according to the traces, in [0,1] */
84     TraceEvent* event; /**< The associated trace event associated to the metric */
85   };
86 };
87 } // namespace resource
88 } // namespace kernel
89 } // namespace simgrid
90
91 namespace std {
92 template <> class hash<simgrid::kernel::resource::Resource> {
93 public:
94   std::size_t operator()(const simgrid::kernel::resource::Resource& r) const
95   {
96     return (std::size_t)xbt_str_hash(r.getCname());
97   }
98 };
99 } // namespace std
100
101 #endif