X-Git-Url: http://info.iut-bm.univ-fcomte.fr/pub/gitweb/simgrid.git/blobdiff_plain/5ce7954780a1bff9dec8111b835749decb85a158..fbf5fafb60eb44c0c00a7283fd05a6dec5f2b58f:/src/s4u/s4u_Link.cpp diff --git a/src/s4u/s4u_Link.cpp b/src/s4u/s4u_Link.cpp index b6b1a5814d..86f5c313bc 100644 --- a/src/s4u/s4u_Link.cpp +++ b/src/s4u/s4u_Link.cpp @@ -1,10 +1,11 @@ -/* Copyright (c) 2013-2018. The SimGrid Team. All rights reserved. */ +/* Copyright (c) 2013-2019. The SimGrid Team. All rights reserved. */ /* This program is free software; you can redistribute it and/or modify it * under the terms of the license (GNU LGPL) which comes with this package. */ #include +#include "simgrid/s4u/Engine.hpp" #include "simgrid/s4u/Link.hpp" #include "simgrid/sg_config.hpp" #include "simgrid/simix.hpp" @@ -17,20 +18,24 @@ XBT_LOG_NEW_DEFAULT_SUBCATEGORY(s4u_link, s4u, "Logging specific to the S4U link namespace simgrid { namespace s4u { -simgrid::xbt::signal Link::on_creation; -simgrid::xbt::signal Link::on_destruction; -simgrid::xbt::signal Link::on_state_change; -simgrid::xbt::signal Link::on_bandwidth_change; -simgrid::xbt::signal Link::on_communicate; -simgrid::xbt::signal Link::on_communication_state_change; +xbt::signal Link::on_creation; +xbt::signal Link::on_destruction; +xbt::signal Link::on_state_change; +xbt::signal Link::on_bandwidth_change; +xbt::signal Link::on_communicate; +xbt::signal + Link::on_communication_state_change; -Link* Link::by_name(const char* name) +Link* Link::by_name(const std::string& name) { - kernel::resource::LinkImpl* res = kernel::resource::LinkImpl::byName(name); - if (res == nullptr) - return nullptr; - return &res->piface_; + return Engine::get_instance()->link_by_name(name); } + +Link* Link::by_name_or_null(const std::string& name) +{ + return Engine::get_instance()->link_by_name_or_null(name); +} + const std::string& Link::get_name() const { return this->pimpl_->get_name(); @@ -39,73 +44,74 @@ const char* Link::get_cname() const { return this->pimpl_->get_cname(); } -const char* Link::name() -{ - return get_cname(); -} -bool Link::isUsed() +bool Link::is_used() { return this->pimpl_->is_used(); } -double Link::latency() +double Link::get_latency() { - return this->pimpl_->latency(); + return this->pimpl_->get_latency(); } -double Link::bandwidth() +double Link::get_bandwidth() { - return this->pimpl_->bandwidth(); + return this->pimpl_->get_bandwidth(); } -Link::SharingPolicy Link::sharingPolicy() +Link::SharingPolicy Link::get_sharing_policy() { - return this->pimpl_->sharingPolicy(); + return this->pimpl_->get_sharing_policy(); } -double Link::getUsage() +double Link::get_usage() { return this->pimpl_->get_constraint()->get_usage(); } -void Link::turnOn() +void Link::turn_on() { - simgrid::simix::kernelImmediate([this]() { this->pimpl_->turn_on(); }); + simgrid::simix::simcall([this]() { this->pimpl_->turn_on(); }); } -void Link::turnOff() +void Link::turn_off() { - simgrid::simix::kernelImmediate([this]() { this->pimpl_->turn_off(); }); + simgrid::simix::simcall([this]() { this->pimpl_->turn_off(); }); } -void* Link::getData() +bool Link::is_on() const { - return this->pimpl_->getData(); + return this->pimpl_->is_on(); } -void Link::setData(void* d) + +void* Link::get_data() +{ + return this->pimpl_->get_data(); +} +void Link::set_data(void* d) { - simgrid::simix::kernelImmediate([this, d]() { this->pimpl_->setData(d); }); + simgrid::simix::simcall([this, d]() { this->pimpl_->set_data(d); }); } -void Link::setStateTrace(tmgr_trace_t trace) +void Link::set_state_profile(kernel::profile::Profile* profile) { - simgrid::simix::kernelImmediate([this, trace]() { this->pimpl_->setStateTrace(trace); }); + simgrid::simix::simcall([this, profile]() { this->pimpl_->set_state_profile(profile); }); } -void Link::setBandwidthTrace(tmgr_trace_t trace) +void Link::set_bandwidth_profile(kernel::profile::Profile* profile) { - simgrid::simix::kernelImmediate([this, trace]() { this->pimpl_->setBandwidthTrace(trace); }); + simgrid::simix::simcall([this, profile]() { this->pimpl_->set_bandwidth_profile(profile); }); } -void Link::setLatencyTrace(tmgr_trace_t trace) +void Link::set_latency_profile(kernel::profile::Profile* trace) { - simgrid::simix::kernelImmediate([this, trace]() { this->pimpl_->setLatencyTrace(trace); }); + simgrid::simix::simcall([this, trace]() { this->pimpl_->set_latency_profile(trace); }); } -const char* Link::getProperty(const char* key) +const char* Link::get_property(const std::string& key) { - return this->pimpl_->getProperty(key); + return this->pimpl_->get_property(key); } -void Link::setProperty(std::string key, std::string value) +void Link::set_property(const std::string& key, const std::string& value) { - simgrid::simix::kernelImmediate([this, key, value] { this->pimpl_->setProperty(key, value); }); + simgrid::simix::simcall([this, &key, &value] { this->pimpl_->set_property(key, value); }); } } // namespace s4u } // namespace simgrid @@ -123,40 +129,35 @@ sg_link_t sg_link_by_name(const char* name) int sg_link_is_shared(sg_link_t link) { - return (int)link->sharingPolicy(); + return (int)link->get_sharing_policy(); } double sg_link_bandwidth(sg_link_t link) { - return link->bandwidth(); + return link->get_bandwidth(); } double sg_link_latency(sg_link_t link) { - return link->latency(); + return link->get_latency(); } void* sg_link_data(sg_link_t link) { - return link->getData(); + return link->get_data(); } void sg_link_data_set(sg_link_t link, void* data) { - link->setData(data); + link->set_data(data); } int sg_link_count() { - return simgrid::kernel::resource::LinkImpl::linksCount(); + return simgrid::s4u::Engine::get_instance()->get_link_count(); } + sg_link_t* sg_link_list() { - simgrid::kernel::resource::LinkImpl** list = simgrid::kernel::resource::LinkImpl::linksList(); - sg_link_t* res = (sg_link_t*)list; // Use the same memory area + std::vector links = simgrid::s4u::Engine::get_instance()->get_all_links(); - int size = sg_link_count(); - for (int i = 0; i < size; i++) - res[i] = &(list[i]->piface_); // Convert each entry into its interface + sg_link_t* res = (sg_link_t*)malloc(sizeof(sg_link_t) * links.size()); + memcpy(res, links.data(), sizeof(sg_link_t) * links.size()); return res; } -void sg_link_exit() -{ - simgrid::kernel::resource::LinkImpl::linksExit(); -}