Logo AND Algorithmique Numérique Distribuée

Public GIT Repository
prefer automatic memory management
[simgrid.git] / src / kernel / resource / Resource.cpp
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 #include "simgrid/kernel/resource/Resource.hpp"
7 #include "src/kernel/lmm/maxmin.hpp" // Constraint
8 #include "src/surf/surf_interface.hpp"
9 #include "src/surf/trace_mgr.hpp"
10
11 namespace simgrid {
12 namespace kernel {
13 namespace resource {
14
15 Resource::Resource(Model* model, const std::string& name, lmm::Constraint* constraint)
16     : name_(name), model_(model), constraint_(constraint)
17 {
18 }
19
20 Resource::~Resource() = default;
21
22 bool Resource::is_on() const
23 {
24   return is_on_;
25 }
26 bool Resource::is_off() const
27 {
28   return not is_on_;
29 }
30
31 void Resource::turn_on()
32 {
33   is_on_ = true;
34 }
35
36 void Resource::turn_off()
37 {
38   is_on_ = false;
39 }
40
41 double Resource::get_load()
42 {
43   return constraint_->get_usage();
44 }
45
46 Model* Resource::get_model() const
47 {
48   return model_;
49 }
50
51 const std::string& Resource::get_name() const
52 {
53   return name_;
54 }
55
56 const char* Resource::get_cname() const
57 {
58   return name_.c_str();
59 }
60
61 bool Resource::operator==(const Resource& other) const
62 {
63   return name_ == other.name_;
64 }
65
66 void Resource::set_state_trace(tmgr_trace_t trace)
67 {
68   xbt_assert(state_event_ == nullptr, "Cannot set a second state trace to %s", get_cname());
69
70   state_event_ = future_evt_set.add_trace(trace, this);
71 }
72
73 kernel::lmm::Constraint* Resource::get_constraint() const
74 {
75   return constraint_;
76 }
77
78 } // namespace resource
79 } // namespace kernel
80 } // namespace simgrid