X-Git-Url: http://info.iut-bm.univ-fcomte.fr/pub/gitweb/simgrid.git/blobdiff_plain/41f97f763bc1771fe15e96ffcd4ff3e7c76a9a63..63225b9520042ef129adb975132fe68ec5710988:/src/s4u/s4u_Link.cpp diff --git a/src/s4u/s4u_Link.cpp b/src/s4u/s4u_Link.cpp index c084839bcd..4942e65ee6 100644 --- a/src/s4u/s4u_Link.cpp +++ b/src/s4u/s4u_Link.cpp @@ -1,4 +1,4 @@ -/* Copyright (c) 2013-2018. The SimGrid Team. All rights reserved. */ +/* Copyright (c) 2013-2020. 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. */ @@ -13,33 +13,26 @@ #include "src/surf/network_interface.hpp" #include "xbt/log.h" -XBT_LOG_NEW_DEFAULT_SUBCATEGORY(s4u_link, s4u, "Logging specific to the S4U links"); - 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; +template class xbt::Extendable; -void Link::destroy() -{ - if (not currentlyDestroying_) { - currentlyDestroying_ = true; - on_destruction(*this); - Engine::get_instance()->link_unregister(std::string(pimpl_->get_cname())); - } -} +namespace s4u { -Link* Link::by_name(std::string name) +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 std::string& name) { return Engine::get_instance()->link_by_name(name); } -Link* Link::by_name_or_null(std::string name) +Link* Link::by_name_or_null(const std::string& name) { return Engine::get_instance()->link_by_name_or_null(name); } @@ -52,80 +45,72 @@ const char* Link::get_cname() const { return this->pimpl_->get_cname(); } -const char* Link::name() -{ - return get_cname(); -} -bool Link::is_used() +bool Link::is_used() const { return this->pimpl_->is_used(); } -double Link::get_latency() +double Link::get_latency() const { return this->pimpl_->get_latency(); } -double Link::get_bandwidth() +double Link::get_bandwidth() const { return this->pimpl_->get_bandwidth(); } -Link::SharingPolicy Link::get_sharing_policy() +Link::SharingPolicy Link::get_sharing_policy() const { return this->pimpl_->get_sharing_policy(); } -double Link::get_usage() +double Link::get_usage() const { return this->pimpl_->get_constraint()->get_usage(); } void Link::turn_on() { - simgrid::simix::simcall([this]() { this->pimpl_->turn_on(); }); + simgrid::kernel::actor::simcall([this]() { this->pimpl_->turn_on(); }); } void Link::turn_off() { - simgrid::simix::simcall([this]() { this->pimpl_->turn_off(); }); + simgrid::kernel::actor::simcall([this]() { this->pimpl_->turn_off(); }); } -void* Link::get_data() -{ - return this->pimpl_->get_data(); -} -void Link::set_data(void* d) +bool Link::is_on() const { - simgrid::simix::simcall([this, d]() { this->pimpl_->set_data(d); }); + return this->pimpl_->is_on(); } -void Link::set_state_trace(tmgr_trace_t trace) +void Link::set_state_profile(kernel::profile::Profile* profile) { - simgrid::simix::simcall([this, trace]() { this->pimpl_->set_state_trace(trace); }); + simgrid::kernel::actor::simcall([this, profile]() { this->pimpl_->set_state_profile(profile); }); } -void Link::set_bandwidth_trace(tmgr_trace_t trace) +void Link::set_bandwidth_profile(kernel::profile::Profile* profile) { - simgrid::simix::simcall([this, trace]() { this->pimpl_->set_bandwidth_trace(trace); }); + simgrid::kernel::actor::simcall([this, profile]() { this->pimpl_->set_bandwidth_profile(profile); }); } -void Link::set_latency_trace(tmgr_trace_t trace) +void Link::set_latency_profile(kernel::profile::Profile* trace) { - simgrid::simix::simcall([this, trace]() { this->pimpl_->set_latency_trace(trace); }); + simgrid::kernel::actor::simcall([this, trace]() { this->pimpl_->set_latency_profile(trace); }); } -const char* Link::get_property(const char* key) +const char* Link::get_property(const std::string& key) const { return this->pimpl_->get_property(key); } -void Link::set_property(std::string key, std::string value) +void Link::set_property(const std::string& key, const std::string& value) { - simgrid::simix::simcall([this, key, value] { this->pimpl_->set_property(key, value); }); + simgrid::kernel::actor::simcall([this, &key, &value] { this->pimpl_->set_property(key, value); }); } } // namespace s4u } // namespace simgrid /* **************************** Public C interface *************************** */ -const char* sg_link_name(sg_link_t link) +const char* sg_link_name(const_sg_link_t link) { return link->get_cname(); } @@ -134,19 +119,19 @@ sg_link_t sg_link_by_name(const char* name) return simgrid::s4u::Link::by_name(name); } -int sg_link_is_shared(sg_link_t link) +int sg_link_is_shared(const_sg_link_t link) { return (int)link->get_sharing_policy(); } -double sg_link_bandwidth(sg_link_t link) +double sg_link_bandwidth(const_sg_link_t link) { return link->get_bandwidth(); } -double sg_link_latency(sg_link_t link) +double sg_link_latency(const_sg_link_t link) { return link->get_latency(); } -void* sg_link_data(sg_link_t link) +void* sg_link_data(const_sg_link_t link) { return link->get_data(); } @@ -163,7 +148,7 @@ sg_link_t* sg_link_list() { std::vector links = simgrid::s4u::Engine::get_instance()->get_all_links(); - sg_link_t* res = (sg_link_t*)malloc(sizeof(sg_link_t) * links.size()); + sg_link_t* res = xbt_new(sg_link_t, links.size()); memcpy(res, links.data(), sizeof(sg_link_t) * links.size()); return res;