X-Git-Url: http://info.iut-bm.univ-fcomte.fr/pub/gitweb/simgrid.git/blobdiff_plain/aee6610d4ad2377964369760bce27e18a12dd708..1b94b2100679d5b4355fccb6d22927efc12ca5bc:/src/s4u/s4u_Link.cpp diff --git a/src/s4u/s4u_Link.cpp b/src/s4u/s4u_Link.cpp index 512c2a7793..d188198b0c 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" @@ -14,156 +15,149 @@ XBT_LOG_NEW_DEFAULT_SUBCATEGORY(s4u_link, s4u, "Logging specific to the S4U links"); -/********* - * C API * - *********/ +namespace simgrid { +namespace s4u { -const char* sg_link_name(sg_link_t link) +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; + +Link* Link::by_name(const std::string& name) { - return link->get_cname(); + return Engine::get_instance()->link_by_name(name); } -sg_link_t sg_link_by_name(const char* name) + +Link* Link::by_name_or_null(const std::string& name) { - return simgrid::s4u::Link::by_name(name); + return Engine::get_instance()->link_by_name_or_null(name); } -int sg_link_is_shared(sg_link_t link) +const std::string& Link::get_name() const { - return (int)link->sharingPolicy(); + return this->pimpl_->get_name(); } -double sg_link_bandwidth(sg_link_t link) +const char* Link::get_cname() const { - return link->bandwidth(); + return this->pimpl_->get_cname(); } -double sg_link_latency(sg_link_t link) +bool Link::is_used() { - return link->latency(); + return this->pimpl_->is_used(); } -void* sg_link_data(sg_link_t link) + +double Link::get_latency() { - return link->getData(); + return this->pimpl_->get_latency(); } -void sg_link_data_set(sg_link_t link, void* data) + +double Link::get_bandwidth() { - link->setData(data); + return this->pimpl_->get_bandwidth(); } -int sg_link_count() + +Link::SharingPolicy Link::get_sharing_policy() { - return simgrid::kernel::resource::LinkImpl::linksCount(); + return this->pimpl_->get_sharing_policy(); } -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 - - int size = sg_link_count(); - for (int i = 0; i < size; i++) - res[i] = &(list[i]->piface_); // Convert each entry into its interface - return res; -} -void sg_link_exit() +double Link::get_usage() { - simgrid::kernel::resource::LinkImpl::linksExit(); + return this->pimpl_->get_constraint()->get_usage(); } -/*********** - * C++ API * - ***********/ - -namespace simgrid { -namespace s4u { -Link* Link::by_name(const char* name) +void Link::turn_on() { - kernel::resource::LinkImpl* res = kernel::resource::LinkImpl::byName(name); - if (res == nullptr) - return nullptr; - return &res->piface_; + simgrid::simix::simcall([this]() { this->pimpl_->turn_on(); }); } -const std::string& Link::get_name() const +void Link::turn_off() { - return this->pimpl_->get_name(); + simgrid::simix::simcall([this]() { this->pimpl_->turn_off(); }); } -const char* Link::get_cname() const + +bool Link::is_on() const { - return this->pimpl_->get_cname(); + return this->pimpl_->is_on(); } -const char* Link::name() + +void* Link::get_data() { - return get_cname(); + return this->pimpl_->get_data(); } -bool Link::isUsed() +void Link::set_data(void* d) { - return this->pimpl_->is_used(); + simgrid::simix::simcall([this, d]() { this->pimpl_->set_data(d); }); } -double Link::latency() +void Link::set_state_profile(kernel::profile::Profile* profile) { - return this->pimpl_->latency(); + simgrid::simix::simcall([this, profile]() { this->pimpl_->set_state_profile(profile); }); } - -double Link::bandwidth() +void Link::set_bandwidth_profile(kernel::profile::Profile* profile) { - return this->pimpl_->bandwidth(); + simgrid::simix::simcall([this, profile]() { this->pimpl_->set_bandwidth_profile(profile); }); } - -Link::SharingPolicy Link::sharingPolicy() +void Link::set_latency_profile(kernel::profile::Profile* trace) { - return this->pimpl_->sharingPolicy(); + simgrid::simix::simcall([this, trace]() { this->pimpl_->set_latency_profile(trace); }); } -double Link::getUsage() +const char* Link::get_property(const std::string& key) { - return this->pimpl_->get_constraint()->get_usage(); + return this->pimpl_->get_property(key); } +void Link::set_property(const std::string& key, std::string value) +{ + simgrid::simix::simcall([this, key, value] { this->pimpl_->set_property(key, std::move(value)); }); +} +} // namespace s4u +} // namespace simgrid + +/* **************************** Public C interface *************************** */ -void Link::turnOn() +const char* sg_link_name(sg_link_t link) { - simgrid::simix::kernelImmediate([this]() { this->pimpl_->turn_on(); }); + return link->get_cname(); } -void Link::turnOff() +sg_link_t sg_link_by_name(const char* name) { - simgrid::simix::kernelImmediate([this]() { this->pimpl_->turn_off(); }); + return simgrid::s4u::Link::by_name(name); } -void* Link::getData() +int sg_link_is_shared(sg_link_t link) { - return this->pimpl_->getData(); + return (int)link->get_sharing_policy(); } -void Link::setData(void* d) +double sg_link_bandwidth(sg_link_t link) { - simgrid::simix::kernelImmediate([this, d]() { this->pimpl_->setData(d); }); + return link->get_bandwidth(); } - -void Link::setStateTrace(tmgr_trace_t trace) +double sg_link_latency(sg_link_t link) { - simgrid::simix::kernelImmediate([this, trace]() { this->pimpl_->setStateTrace(trace); }); + return link->get_latency(); } -void Link::setBandwidthTrace(tmgr_trace_t trace) +void* sg_link_data(sg_link_t link) { - simgrid::simix::kernelImmediate([this, trace]() { this->pimpl_->setBandwidthTrace(trace); }); + return link->get_data(); } -void Link::setLatencyTrace(tmgr_trace_t trace) +void sg_link_data_set(sg_link_t link, void* data) { - simgrid::simix::kernelImmediate([this, trace]() { this->pimpl_->setLatencyTrace(trace); }); + link->set_data(data); } - -const char* Link::getProperty(const char* key) +int sg_link_count() { - return this->pimpl_->getProperty(key); + return simgrid::s4u::Engine::get_instance()->get_link_count(); } -void Link::setProperty(std::string key, std::string value) + +sg_link_t* sg_link_list() { - simgrid::simix::kernelImmediate([this, key, value] { this->pimpl_->setProperty(key, value); }); -} + std::vector links = simgrid::s4u::Engine::get_instance()->get_all_links(); -/************* - * Callbacks * - *************/ -simgrid::xbt::signal Link::onCreation; -simgrid::xbt::signal Link::onDestruction; -simgrid::xbt::signal Link::onStateChange; -simgrid::xbt::signal Link::onCommunicate; -simgrid::xbt::signal Link::onCommunicationStateChange; -} // namespace s4u -} // namespace simgrid + 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; +}