Logo AND Algorithmique Numérique Distribuée

Public GIT Repository
explicitly capture the variables to please sonar
[simgrid.git] / src / s4u / s4u_link.cpp
1 /* Copyright (c) 2013-2015. The SimGrid Team.
2  * All rights reserved.                                                     */
3
4 /* This program is free software; you can redistribute it and/or modify it
5  * under the terms of the license (GNU LGPL) which comes with this package. */
6
7 #include <algorithm>
8
9 #include "simgrid/s4u/link.hpp"
10 #include "simgrid/sg_config.h"
11 #include "simgrid/simix.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 /*********
18  * C API *
19  *********/
20
21 extern "C" {
22
23 const char* sg_link_name(Link* link)
24 {
25   return link->name();
26 }
27 Link* sg_link_by_name(const char* name)
28 {
29   return Link::byName(name);
30 }
31
32 int sg_link_is_shared(Link* link)
33 {
34   return link->sharingPolicy();
35 }
36 double sg_link_bandwidth(Link* link)
37 {
38   return link->bandwidth();
39 }
40 double sg_link_latency(Link* link)
41 {
42   return link->latency();
43 }
44 void* sg_link_data(Link* link)
45 {
46   return link->getData();
47 }
48 void sg_link_data_set(Link* link, void* data)
49 {
50   link->setData(data);
51 }
52 int sg_link_count()
53 {
54   return simgrid::surf::LinkImpl::linksCount();
55 }
56 Link** sg_link_list()
57 {
58   simgrid::surf::LinkImpl** list = simgrid::surf::LinkImpl::linksList();
59   Link** res                     = (Link**)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 char* Link::name()
87 {
88   return pimpl_->getName();
89 }
90 bool Link::isUsed()
91 {
92   return pimpl_->isUsed();
93 }
94
95 double Link::latency()
96 {
97   return pimpl_->latency();
98 }
99
100 double Link::bandwidth()
101 {
102   return pimpl_->bandwidth();
103 }
104
105 int Link::sharingPolicy()
106 {
107   return pimpl_->sharingPolicy();
108 }
109
110 void Link::turnOn()
111 {
112   simgrid::simix::kernelImmediate([this]() {
113     this->pimpl_->turnOn();
114   });
115 }
116 void Link::turnOff()
117 {
118   simgrid::simix::kernelImmediate([this]() {
119     this->pimpl_->turnOff();
120   });
121 }
122
123 void* Link::getData()
124 {
125   return pimpl_->getData();
126 }
127 void Link::setData(void* d)
128 {
129   simgrid::simix::kernelImmediate([this, d]() {
130     this->pimpl_->setData(d);
131   });
132 }
133
134 void Link::setStateTrace(tmgr_trace_t trace)
135 {
136   simgrid::simix::kernelImmediate([this, trace]() {
137     this->pimpl_->setStateTrace(trace);
138   });
139 }
140 void Link::setBandwidthTrace(tmgr_trace_t trace)
141 {
142   simgrid::simix::kernelImmediate([this, trace]() {
143     this->pimpl_->setBandwidthTrace(trace);
144   });
145 }
146 void Link::setLatencyTrace(tmgr_trace_t trace)
147 {
148   simgrid::simix::kernelImmediate([this, trace]() {
149     this->pimpl_->setLatencyTrace(trace);
150   });
151 }
152 }
153 }