Logo AND Algorithmique Numérique Distribuée

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