Logo AND Algorithmique Numérique Distribuée

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