Logo AND Algorithmique Numérique Distribuée

Public GIT Repository
Pass std::string parameters by reference too.
[simgrid.git] / src / s4u / s4u_Link.cpp
1 /* Copyright (c) 2013-2019. 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 <algorithm>
7
8 #include "simgrid/s4u/Engine.hpp"
9 #include "simgrid/s4u/Link.hpp"
10 #include "simgrid/sg_config.hpp"
11 #include "simgrid/simix.hpp"
12 #include "src/kernel/lmm/maxmin.hpp"
13 #include "src/surf/network_interface.hpp"
14 #include "xbt/log.h"
15
16 XBT_LOG_NEW_DEFAULT_SUBCATEGORY(s4u_link, s4u, "Logging specific to the S4U links");
17
18 namespace simgrid {
19 namespace s4u {
20
21 simgrid::xbt::signal<void(Link&)> Link::on_creation;
22 simgrid::xbt::signal<void(Link&)> Link::on_destruction;
23 simgrid::xbt::signal<void(Link&)> Link::on_state_change;
24 simgrid::xbt::signal<void(Link&)> Link::on_bandwidth_change;
25 simgrid::xbt::signal<void(kernel::resource::NetworkAction*, Host* src, Host* dst)> Link::on_communicate;
26 simgrid::xbt::signal<void(kernel::resource::NetworkAction*, kernel::resource::Action::State)>
27     Link::on_communication_state_change;
28
29 Link* Link::by_name(const std::string& name)
30 {
31   return Engine::get_instance()->link_by_name(name);
32 }
33
34 Link* Link::by_name_or_null(const std::string& name)
35 {
36   return Engine::get_instance()->link_by_name_or_null(name);
37 }
38
39 const std::string& Link::get_name() const
40 {
41   return this->pimpl_->get_name();
42 }
43 const char* Link::get_cname() const
44 {
45   return this->pimpl_->get_cname();
46 }
47 bool Link::is_used()
48 {
49   return this->pimpl_->is_used();
50 }
51
52 double Link::get_latency()
53 {
54   return this->pimpl_->get_latency();
55 }
56
57 double Link::get_bandwidth()
58 {
59   return this->pimpl_->get_bandwidth();
60 }
61
62 Link::SharingPolicy Link::get_sharing_policy()
63 {
64   return this->pimpl_->get_sharing_policy();
65 }
66
67 double Link::get_usage()
68 {
69   return this->pimpl_->get_constraint()->get_usage();
70 }
71
72 void Link::turn_on()
73 {
74   simgrid::simix::simcall([this]() { this->pimpl_->turn_on(); });
75 }
76 void Link::turn_off()
77 {
78   simgrid::simix::simcall([this]() { this->pimpl_->turn_off(); });
79 }
80
81 bool Link::is_on() const
82 {
83   return this->pimpl_->is_on();
84 }
85
86 void* Link::get_data()
87 {
88   return this->pimpl_->get_data();
89 }
90 void Link::set_data(void* d)
91 {
92   simgrid::simix::simcall([this, d]() { this->pimpl_->set_data(d); });
93 }
94
95 void Link::set_state_profile(kernel::profile::Profile* profile)
96 {
97   simgrid::simix::simcall([this, profile]() { this->pimpl_->set_state_profile(profile); });
98 }
99 void Link::set_bandwidth_profile(kernel::profile::Profile* profile)
100 {
101   simgrid::simix::simcall([this, profile]() { this->pimpl_->set_bandwidth_profile(profile); });
102 }
103 void Link::set_latency_profile(kernel::profile::Profile* trace)
104 {
105   simgrid::simix::simcall([this, trace]() { this->pimpl_->set_latency_profile(trace); });
106 }
107
108 const char* Link::get_property(const std::string& key)
109 {
110   return this->pimpl_->get_property(key);
111 }
112 void Link::set_property(const std::string& key, const std::string& value)
113 {
114   simgrid::simix::simcall([this, &key, &value] { this->pimpl_->set_property(key, value); });
115 }
116 } // namespace s4u
117 } // namespace simgrid
118
119 /* **************************** Public C interface *************************** */
120
121 const char* sg_link_name(sg_link_t link)
122 {
123   return link->get_cname();
124 }
125 sg_link_t sg_link_by_name(const char* name)
126 {
127   return simgrid::s4u::Link::by_name(name);
128 }
129
130 int sg_link_is_shared(sg_link_t link)
131 {
132   return (int)link->get_sharing_policy();
133 }
134 double sg_link_bandwidth(sg_link_t link)
135 {
136   return link->get_bandwidth();
137 }
138 double sg_link_latency(sg_link_t link)
139 {
140   return link->get_latency();
141 }
142 void* sg_link_data(sg_link_t link)
143 {
144   return link->get_data();
145 }
146 void sg_link_data_set(sg_link_t link, void* data)
147 {
148   link->set_data(data);
149 }
150 int sg_link_count()
151 {
152   return simgrid::s4u::Engine::get_instance()->get_link_count();
153 }
154
155 sg_link_t* sg_link_list()
156 {
157   std::vector<simgrid::s4u::Link*> links = simgrid::s4u::Engine::get_instance()->get_all_links();
158
159   sg_link_t* res = (sg_link_t*)malloc(sizeof(sg_link_t) * links.size());
160   memcpy(res, links.data(), sizeof(sg_link_t) * links.size());
161
162   return res;
163 }