]> AND Public Git Repository - simgrid.git/blobdiff - src/s4u/s4u_Link.cpp
Logo AND Algorithmique Numérique Distribuée

Public GIT Repository
better check for mpi_datatype_null
[simgrid.git] / src / s4u / s4u_Link.cpp
index 011917aea18dcb4df42f8a92fbe1c1b4fd39dac4..1a5db6cde0cf10c248886579fd6a47bcd0db808e 100644 (file)
@@ -73,7 +73,7 @@ Link* Link::set_latency(const std::string& value)
 {
   double d_value = 0.0;
   try {
-    d_value = xbt_parse_get_time("", 0, value.c_str(), nullptr, "");
+    d_value = xbt_parse_get_time("", 0, value, "");
   } catch (const simgrid::ParseError&) {
     throw std::invalid_argument(std::string("Impossible to set latency for link: ") + get_name() +
                                 std::string(". Invalid value: ") + value);
@@ -92,6 +92,15 @@ Link* Link::set_bandwidth(double value)
   return this;
 }
 
+Link* Link::set_sharing_policy(Link::SharingPolicy policy)
+{
+  if (policy == SharingPolicy::SPLITDUPLEX)
+    throw std::invalid_argument(std::string("Impossible to set split-duplex for the link: ") + get_name() +
+                                std::string(". You should create a link-up and link-down to emulate this behavior"));
+
+  kernel::actor::simcall([this, policy] { pimpl_->set_sharing_policy(policy); });
+  return this;
+}
 Link::SharingPolicy Link::get_sharing_policy() const
 {
   return this->pimpl_->get_sharing_policy();
@@ -99,10 +108,8 @@ Link::SharingPolicy Link::get_sharing_policy() const
 
 void Link::set_host_wifi_rate(const s4u::Host* host, int level) const
 {
-  xbt_assert(pimpl_->get_sharing_policy() == Link::SharingPolicy::WIFI, "Link %s does not seem to be a wifi link.",
-             get_cname());
   auto* wlink = dynamic_cast<kernel::resource::NetworkWifiLink*>(pimpl_);
-  xbt_assert(wlink != nullptr, "Cannot convert link %s into a wifi link.", get_cname());
+  xbt_assert(wlink != nullptr, "Link %s does not seem to be a wifi link.", get_cname());
   wlink->set_host_rate(host, level);
 }
 
@@ -119,9 +126,10 @@ void Link::turn_off()
 {
   kernel::actor::simcall([this]() { this->pimpl_->turn_off(); });
 }
-void Link::seal()
+Link* Link::seal()
 {
   kernel::actor::simcall([this]() { this->pimpl_->seal(); });
+  return this;
 }
 
 bool Link::is_on() const
@@ -256,7 +264,7 @@ void sg_link_data_set(sg_link_t link, void* data) // XBT_ATTRIB_DEPRECATED_v330
   sg_link_set_data(link, data);
 }
 
-int sg_link_count()
+size_t sg_link_count()
 {
   return simgrid::s4u::Engine::get_instance()->get_link_count();
 }
@@ -265,8 +273,8 @@ sg_link_t* sg_link_list()
 {
   std::vector<simgrid::s4u::Link*> links = simgrid::s4u::Engine::get_instance()->get_all_links();
 
-  sg_link_t* res = xbt_new(sg_link_t, links.size());
-  memcpy(res, links.data(), sizeof(sg_link_t) * links.size());
+  auto* res = xbt_new(sg_link_t, links.size());
+  std::copy(begin(links), end(links), res);
 
   return res;
 }