Logo AND Algorithmique Numérique Distribuée

Public GIT Repository
Merge branch 'master' into fix/execute_benched
[simgrid.git] / src / s4u / s4u_link.cpp
1 /* Copyright (c) 2013-2017. 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.h"
10 #include "simgrid/simix.hpp"
11 #include "src/surf/network_interface.hpp"
12 #include "surf/maxmin.hpp"
13 #include "xbt/log.h"
14
15 XBT_LOG_NEW_DEFAULT_SUBCATEGORY(s4u_link, s4u, "Logging specific to the S4U links");
16
17 /*********
18  * C API *
19  *********/
20
21 extern "C" {
22
23 const char* sg_link_name(sg_link_t link)
24 {
25   return link->getCname();
26 }
27 sg_link_t sg_link_by_name(const char* name)
28 {
29   return simgrid::s4u::Link::byName(name);
30 }
31
32 int sg_link_is_shared(sg_link_t link)
33 {
34   return link->sharingPolicy();
35 }
36 double sg_link_bandwidth(sg_link_t link)
37 {
38   return link->bandwidth();
39 }
40 double sg_link_latency(sg_link_t link)
41 {
42   return link->latency();
43 }
44 void* sg_link_data(sg_link_t link)
45 {
46   return link->getData();
47 }
48 void sg_link_data_set(sg_link_t link, void* data)
49 {
50   link->setData(data);
51 }
52 int sg_link_count()
53 {
54   return simgrid::surf::LinkImpl::linksCount();
55 }
56 sg_link_t* sg_link_list()
57 {
58   simgrid::surf::LinkImpl** list = simgrid::surf::LinkImpl::linksList();
59   sg_link_t* res                 = (sg_link_t*)list; // Use the same memory area
60
61   int size = sg_link_count();
62   for (int i = 0; i < size; i++)
63     res[i] = &(list[i]->piface_); // Convert each entry into its interface
64
65   return res;
66 }
67 void sg_link_exit()
68 {
69   simgrid::surf::LinkImpl::linksExit();
70 }
71 }
72
73 /***********
74  * C++ API *
75  ***********/
76
77 namespace simgrid {
78 namespace s4u {
79 Link* Link::byName(const char* name)
80 {
81   surf::LinkImpl* res = surf::LinkImpl::byName(name);
82   if (res == nullptr)
83     return nullptr;
84   return &res->piface_;
85 }
86 const std::string& Link::getName() const
87 {
88   return this->pimpl_->getName();
89 }
90 const char* Link::getCname() const
91 {
92   return this->pimpl_->getCname();
93 }
94 const char* Link::name()
95 {
96   return getCname();
97 }
98 bool Link::isUsed()
99 {
100   return this->pimpl_->isUsed();
101 }
102
103 double Link::latency()
104 {
105   return this->pimpl_->latency();
106 }
107
108 double Link::bandwidth()
109 {
110   return this->pimpl_->bandwidth();
111 }
112
113 int Link::sharingPolicy()
114 {
115   return this->pimpl_->sharingPolicy();
116 }
117
118 double Link::getUsage()
119 {
120   return this->pimpl_->constraint()->get_usage();
121 }
122
123 void Link::turnOn()
124 {
125   simgrid::simix::kernelImmediate([this]() {
126     this->pimpl_->turnOn();
127   });
128 }
129 void Link::turnOff()
130 {
131   simgrid::simix::kernelImmediate([this]() {
132     this->pimpl_->turnOff();
133   });
134 }
135
136 void* Link::getData()
137 {
138   return this->pimpl_->getData();
139 }
140 void Link::setData(void* d)
141 {
142   simgrid::simix::kernelImmediate([this, d]() {
143     this->pimpl_->setData(d);
144   });
145 }
146
147 void Link::setStateTrace(tmgr_trace_t trace)
148 {
149   simgrid::simix::kernelImmediate([this, trace]() {
150     this->pimpl_->setStateTrace(trace);
151   });
152 }
153 void Link::setBandwidthTrace(tmgr_trace_t trace)
154 {
155   simgrid::simix::kernelImmediate([this, trace]() {
156     this->pimpl_->setBandwidthTrace(trace);
157   });
158 }
159 void Link::setLatencyTrace(tmgr_trace_t trace)
160 {
161   simgrid::simix::kernelImmediate([this, trace]() {
162     this->pimpl_->setLatencyTrace(trace);
163   });
164 }
165
166 const char* Link::getProperty(const char* key)
167 {
168   return this->pimpl_->getProperty(key);
169 }
170 void Link::setProperty(std::string key, std::string value)
171 {
172   simgrid::simix::kernelImmediate([this, key, value] { this->pimpl_->setProperty(key, value); });
173 }
174
175 /*************
176  * Callbacks *
177  *************/
178 simgrid::xbt::signal<void(s4u::Link&)> Link::onCreation;
179 simgrid::xbt::signal<void(s4u::Link&)> Link::onDestruction;
180 simgrid::xbt::signal<void(s4u::Link&)> Link::onStateChange;
181 simgrid::xbt::signal<void(surf::NetworkAction*, s4u::Host* src, s4u::Host* dst)> Link::onCommunicate;
182 simgrid::xbt::signal<void(surf::NetworkAction*)> Link::onCommunicationStateChange;
183 }
184 }