Logo AND Algorithmique Numérique Distribuée

Public GIT Repository
cosmetics: reorder file to be consistent with others
[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::onCreation;
21 simgrid::xbt::signal<void(Link&)> Link::onDestruction;
22 simgrid::xbt::signal<void(Link&)> Link::onStateChange;
23 simgrid::xbt::signal<void(Link&)> Link::on_bandwidth_change;
24 simgrid::xbt::signal<void(kernel::resource::NetworkAction*, Host* src, Host* dst)> Link::onCommunicate;
25 simgrid::xbt::signal<void(kernel::resource::NetworkAction*)> Link::onCommunicationStateChange;
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::isUsed()
47 {
48   return this->pimpl_->is_used();
49 }
50
51 double Link::latency()
52 {
53   return this->pimpl_->latency();
54 }
55
56 double Link::bandwidth()
57 {
58   return this->pimpl_->bandwidth();
59 }
60
61 Link::SharingPolicy Link::sharingPolicy()
62 {
63   return this->pimpl_->sharingPolicy();
64 }
65
66 double Link::getUsage()
67 {
68   return this->pimpl_->get_constraint()->get_usage();
69 }
70
71 void Link::turnOn()
72 {
73   simgrid::simix::kernelImmediate([this]() { this->pimpl_->turn_on(); });
74 }
75 void Link::turnOff()
76 {
77   simgrid::simix::kernelImmediate([this]() { this->pimpl_->turn_off(); });
78 }
79
80 void* Link::getData()
81 {
82   return this->pimpl_->getData();
83 }
84 void Link::setData(void* d)
85 {
86   simgrid::simix::kernelImmediate([this, d]() { this->pimpl_->setData(d); });
87 }
88
89 void Link::setStateTrace(tmgr_trace_t trace)
90 {
91   simgrid::simix::kernelImmediate([this, trace]() { this->pimpl_->setStateTrace(trace); });
92 }
93 void Link::setBandwidthTrace(tmgr_trace_t trace)
94 {
95   simgrid::simix::kernelImmediate([this, trace]() { this->pimpl_->setBandwidthTrace(trace); });
96 }
97 void Link::setLatencyTrace(tmgr_trace_t trace)
98 {
99   simgrid::simix::kernelImmediate([this, trace]() { this->pimpl_->setLatencyTrace(trace); });
100 }
101
102 const char* Link::getProperty(const char* key)
103 {
104   return this->pimpl_->getProperty(key);
105 }
106 void Link::setProperty(std::string key, std::string value)
107 {
108   simgrid::simix::kernelImmediate([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->sharingPolicy();
127 }
128 double sg_link_bandwidth(sg_link_t link)
129 {
130   return link->bandwidth();
131 }
132 double sg_link_latency(sg_link_t link)
133 {
134   return link->latency();
135 }
136 void* sg_link_data(sg_link_t link)
137 {
138   return link->getData();
139 }
140 void sg_link_data_set(sg_link_t link, void* data)
141 {
142   link->setData(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 }