Logo AND Algorithmique Numérique Distribuée

Public GIT Repository
[sonar] Constify pointer and reference local variables in src/surf/.
[simgrid.git] / src / surf / sg_platf.cpp
index 9f7b635..6247def 100644 (file)
@@ -33,11 +33,12 @@ XBT_PRIVATE std::map<std::string, simgrid::kernel::resource::StorageImpl*> mount
 XBT_PRIVATE std::vector<std::string> known_storages;
 
 namespace simgrid {
-namespace surf {
-
-simgrid::xbt::signal<void(kernel::routing::ClusterCreationArgs const&)> on_cluster;
-}
-}
+namespace kernel {
+namespace routing {
+xbt::signal<void(ClusterCreationArgs const&)> on_cluster_creation;
+} // namespace routing
+} // namespace kernel
+} // namespace simgrid
 
 static int surf_parse_models_setup_already_called = 0;
 std::map<std::string, simgrid::kernel::resource::StorageType*> storage_types;
@@ -57,7 +58,7 @@ void sg_platf_init()
 
 /** Module management function: frees all internal data structures */
 void sg_platf_exit() {
-  simgrid::surf::on_cluster.disconnect_slots();
+  simgrid::kernel::routing::on_cluster_creation.disconnect_slots();
   simgrid::s4u::Engine::on_platform_created.disconnect_slots();
 
   /* make sure that we will reinit the models while loading the platf once reinited */
@@ -193,9 +194,9 @@ void sg_platf_new_cluster(simgrid::kernel::routing::ClusterCreationArgs* cluster
     XBT_DEBUG("<host\tid=\"%s\"\tpower=\"%f\">", host_id.c_str(), cluster->speeds.front());
 
     simgrid::kernel::routing::HostCreationArgs host;
-    host.id = host_id.c_str();
+    host.id = host_id;
     if ((cluster->properties != nullptr) && (not cluster->properties->empty())) {
-      host.properties = new std::unordered_map<std::string, std::string>;
+      host.properties = new std::unordered_map<std::string, std::string>();
 
       for (auto const& elm : *cluster->properties)
         host.properties->insert({elm.first, elm.second});
@@ -217,8 +218,8 @@ void sg_platf_new_cluster(simgrid::kernel::routing::ClusterCreationArgs* cluster
     // other columns are to store one or more link for the node
 
     //add a loopback link
-    simgrid::s4u::Link* linkUp   = nullptr;
-    simgrid::s4u::Link* linkDown = nullptr;
+    const simgrid::s4u::Link* linkUp   = nullptr;
+    const simgrid::s4u::Link* linkDown = nullptr;
     if(cluster->loopback_bw > 0 || cluster->loopback_lat > 0){
       std::string tmp_link = link_id + "_loopback";
       XBT_DEBUG("<loopback\tid=\"%s\"\tbw=\"%f\"/>", tmp_link.c_str(), cluster->loopback_bw);
@@ -277,7 +278,6 @@ void sg_platf_new_cluster(simgrid::kernel::routing::ClusterCreationArgs* cluster
 
   //Make the backbone
   if ((cluster->bb_bw > 0) || (cluster->bb_lat > 0)) {
-
     simgrid::kernel::routing::LinkCreationArgs link;
     link.id        = std::string(cluster->id)+ "_backbone";
     link.bandwidths.push_back(cluster->bb_bw);
@@ -293,7 +293,7 @@ void sg_platf_new_cluster(simgrid::kernel::routing::ClusterCreationArgs* cluster
   XBT_DEBUG("</AS>");
   sg_platf_new_Zone_seal();
 
-  simgrid::surf::on_cluster(*cluster);
+  simgrid::kernel::routing::on_cluster_creation(*cluster);
   delete cluster->radicals;
 }
 
@@ -316,7 +316,7 @@ void sg_platf_new_cabinet(simgrid::kernel::routing::CabinetCreationArgs* cabinet
     simgrid::kernel::routing::HostCreationArgs host;
     host.pstate           = 0;
     host.core_amount      = 1;
-    host.id               = hostname.c_str();
+    host.id               = hostname;
     host.speed_per_pstate.push_back(cabinet->speed);
     sg_platf_new_host(&host);
 
@@ -352,7 +352,7 @@ void sg_platf_new_storage(simgrid::kernel::routing::StorageCreationArgs* storage
   xbt_assert(std::find(known_storages.begin(), known_storages.end(), storage->id) == known_storages.end(),
              "Refusing to add a second storage named \"%s\"", storage->id.c_str());
 
-  simgrid::kernel::resource::StorageType* stype;
+  const simgrid::kernel::resource::StorageType* stype;
   auto st = storage_types.find(storage->type_id);
   if (st != storage_types.end()) {
     stype = st->second;
@@ -446,12 +446,12 @@ void sg_platf_new_actor(simgrid::kernel::routing::ActorCreationArgs* actor)
     }
     xbt_die("%s", msg.c_str());
   }
-  simgrid::simix::ActorCodeFactory& factory = SIMIX_get_actor_code_factory(actor->function);
+  const simgrid::simix::ActorCodeFactory& factory = SIMIX_get_actor_code_factory(actor->function);
   xbt_assert(factory, "Error while creating an actor from the XML file: Function '%s' not registered", actor->function);
 
   double start_time = actor->start_time;
   double kill_time  = actor->kill_time;
-  bool auto_restart = actor->on_failure != simgrid::kernel::routing::ActorOnFailure::DIE;
+  bool auto_restart = actor->restart_on_failure;
 
   std::string actor_name     = actor->args[0];
   simgrid::simix::ActorCode code = factory(std::move(actor->args));
@@ -460,10 +460,9 @@ void sg_platf_new_actor(simgrid::kernel::routing::ActorCreationArgs* actor)
   simgrid::kernel::actor::ProcessArg* arg =
       new simgrid::kernel::actor::ProcessArg(actor_name, code, nullptr, host, kill_time, properties, auto_restart);
 
-  host->pimpl_->actors_at_boot_.emplace_back(arg);
+  host->pimpl_->add_actor_at_boot(arg);
 
   if (start_time > SIMIX_get_clock()) {
-
     arg = new simgrid::kernel::actor::ProcessArg(actor_name, code, nullptr, host, kill_time, properties, auto_restart);
 
     XBT_DEBUG("Process %s@%s will be started at time %f", arg->name.c_str(), arg->host->get_cname(), start_time);
@@ -501,7 +500,7 @@ void sg_platf_new_peer(simgrid::kernel::routing::PeerCreationArgs* peer)
 
   std::vector<double> speed_per_pstate;
   speed_per_pstate.push_back(peer->speed);
-  simgrid::s4u::Host* host = as->create_host(peer->id.c_str(), speed_per_pstate, 1, nullptr);
+  simgrid::s4u::Host* host = as->create_host(peer->id, speed_per_pstate, 1, nullptr);
 
   as->set_peer_link(host->get_netpoint(), peer->bw_in, peer->bw_out, peer->coord);
 
@@ -646,8 +645,8 @@ void sg_platf_new_Zone_set_properties(std::unordered_map<std::string, std::strin
 {
   xbt_assert(current_routing, "Cannot set properties of the current Zone: none under construction");
 
-  for (auto kv = props->begin(); kv != props->end(); ++kv)
-    current_routing->get_iface()->set_property(kv->first, kv->second);
+  if (props)
+    current_routing->set_properties(*props);
 }
 
 /**
@@ -672,8 +671,8 @@ void sg_platf_new_hostlink(simgrid::kernel::routing::HostLinkCreationArgs* hostl
   xbt_assert(dynamic_cast<simgrid::kernel::routing::ClusterZone*>(current_routing),
              "Only hosts from Cluster and Vivaldi ASes can get a host_link.");
 
-  simgrid::s4u::Link* linkUp   = simgrid::s4u::Link::by_name_or_null(hostlink->link_up);
-  simgrid::s4u::Link* linkDown = simgrid::s4u::Link::by_name_or_null(hostlink->link_down);
+  const simgrid::s4u::Link* linkUp   = simgrid::s4u::Link::by_name_or_null(hostlink->link_up);
+  const simgrid::s4u::Link* linkDown = simgrid::s4u::Link::by_name_or_null(hostlink->link_down);
 
   xbt_assert(linkUp, "Link '%s' not found!", hostlink->link_up.c_str());
   xbt_assert(linkDown, "Link '%s' not found!", hostlink->link_down.c_str());