Logo AND Algorithmique Numérique Distribuée

Public GIT Repository
[sonar] Constify pointer and reference parameters in examples/.
authorArnaud Giersch <arnaud.giersch@univ-fcomte.fr>
Fri, 27 Dec 2019 16:09:41 +0000 (17:09 +0100)
committerArnaud Giersch <arnaud.giersch@univ-fcomte.fr>
Fri, 27 Dec 2019 17:22:38 +0000 (18:22 +0100)
13 files changed:
examples/s4u/actor-migrate/s4u-actor-migrate.cpp
examples/s4u/app-bittorrent/s4u-peer.cpp
examples/s4u/app-bittorrent/s4u-peer.hpp
examples/s4u/dht-kademlia/answer.cpp
examples/s4u/dht-kademlia/answer.hpp
examples/s4u/dht-kademlia/node.cpp
examples/s4u/dht-kademlia/node.hpp
examples/s4u/engine-filtering/s4u-engine-filtering.cpp
examples/s4u/replay-comm/s4u-replay-comm.cpp
examples/s4u/replay-io/s4u-replay-io.cpp
examples/s4u/synchro-semaphore/s4u-synchro-semaphore.cpp
examples/smpi/replay/replay.cpp
examples/smpi/replay_multiple_manual_deploy/replay_multiple_manual.cpp

index be035df..b697d8b 100644 (file)
@@ -21,7 +21,7 @@
 
 XBT_LOG_NEW_DEFAULT_CATEGORY(s4u_actor_migration, "Messages specific for this s4u example");
 
-static void worker(simgrid::s4u::Host* first, simgrid::s4u::Host* second)
+static void worker(simgrid::s4u::Host* first, const simgrid::s4u::Host* second)
 {
   double flopAmount = first->get_speed() * 5 + second->get_speed() * 5;
 
index a5e59bb..84d3196 100644 (file)
@@ -172,12 +172,12 @@ bool Peer::hasFinished()
 }
 
 /** Indicates if the remote peer has a piece not stored by the local peer */
-bool Peer::isInterestedBy(Connection* remote_peer)
+bool Peer::isInterestedBy(const Connection* remote_peer) const
 {
   return remote_peer->bitfield & (bitfield_ ^ ((1 << FILE_PIECES) - 1));
 }
 
-bool Peer::isInterestedByFree(Connection* remote_peer)
+bool Peer::isInterestedByFree(const Connection* remote_peer) const
 {
   for (unsigned int i = 0; i < FILE_PIECES; i++)
     if (hasNotPiece(i) && remote_peer->hasPiece(i) && isNotDownloadingPiece(i))
index ecc5994..4282830 100644 (file)
@@ -25,7 +25,7 @@ public:
 
   explicit Connection(int id) : id(id), mailbox_(simgrid::s4u::Mailbox::by_name(std::to_string(id))){};
   void addSpeedValue(double speed) { peer_speed = peer_speed * 0.6 + speed * 0.4; }
-  bool hasPiece(unsigned int piece) { return bitfield & 1U << piece; }
+  bool hasPiece(unsigned int piece) const { return bitfield & 1U << piece; }
 };
 
 class Peer {
@@ -53,17 +53,17 @@ public:
   std::string getStatus();
   bool hasFinished();
   int nbInterestedPeers();
-  bool isInterestedBy(Connection* remote_peer);
-  bool isInterestedByFree(Connection* remote_peer);
+  bool isInterestedBy(const Connection* remote_peer) const;
+  bool isInterestedByFree(const Connection* remote_peer) const;
   void updateActivePeersSet(Connection* remote_peer);
   void updateInterestedAfterReceive();
   void updateChokedPeers();
 
-  bool hasNotPiece(unsigned int piece) { return not(bitfield_ & 1U << piece); }
+  bool hasNotPiece(unsigned int piece) const { return not(bitfield_ & 1U << piece); }
   bool hasCompletedPiece(unsigned int piece);
   unsigned int countPieces(unsigned int bitfield);
   /** Check that a piece is not currently being download by the peer. */
-  bool isNotDownloadingPiece(unsigned int piece) { return not(current_pieces & 1U << piece); }
+  bool isNotDownloadingPiece(unsigned int piece) const { return not(current_pieces & 1U << piece); }
   int partiallyDownloadedPiece(Connection* remote_peer);
   void updatePiecesCountFromBitfield(unsigned int bitfield);
   void removeCurrentPiece(Connection* remote_peer, unsigned int current_piece);
index 0afc935..4ffe046 100644 (file)
@@ -27,7 +27,7 @@ void Answer::print()
 /** @brief Merge two answers together, only keeping the best nodes
   * @param source the source of the nodes to add
   */
-unsigned int Answer::merge(Answer* source)
+unsigned int Answer::merge(const Answer* source)
 {
   if (this == source)
     return 0;
index ab93e99..c513478 100644 (file)
@@ -23,10 +23,10 @@ public:
   std::vector<std::pair<unsigned int, unsigned int>> nodes;
   explicit Answer(unsigned int destination_id) : destination_id_(destination_id) {}
   virtual ~Answer() = default;
-  unsigned int getDestinationId() { return destination_id_; }
+  unsigned int getDestinationId() const { return destination_id_; }
   unsigned int getSize() { return size_; }
   void print();
-  unsigned int merge(Answer* a);
+  unsigned int merge(const Answer* a);
   void trim();
   bool destinationFound();
   void addBucket(const kademlia::Bucket* bucket);
index 961e8b9..8ab688c 100644 (file)
@@ -93,7 +93,7 @@ void Node::sendFindNode(unsigned int id, unsigned int destination)
   * Sends to the best "KADEMLIA_ALPHA" nodes in the "node_list" array a "FIND_NODE" request, to ask them for their best
   * nodes
   */
-unsigned int Node::sendFindNodeToBest(Answer* node_list)
+unsigned int Node::sendFindNodeToBest(const Answer* node_list)
 {
   unsigned int i           = 0;
   unsigned int j           = 0;
@@ -268,7 +268,7 @@ void Node::randomLookup()
 }
 
 /** @brief Handles the answer to an incoming "find_node" task */
-void Node::handleFindNode(Message* msg)
+void Node::handleFindNode(const Message* msg)
 {
   routingTableUpdate(msg->sender_id_);
   XBT_VERB("Received a FIND_NODE from %s (%s), he's trying to find %08x", msg->answer_to_->get_cname(),
index 4004615..a9f5bf9 100644 (file)
@@ -28,12 +28,12 @@ public:
 
   bool join(unsigned int known_id);
   void sendFindNode(unsigned int id, unsigned int destination);
-  unsigned int sendFindNodeToBest(Answer* node_list);
+  unsigned int sendFindNodeToBest(const Answer* node_list);
   void routingTableUpdate(unsigned int id);
   Answer* findClosest(unsigned int destination_id);
   bool findNode(unsigned int id_to_find, bool count_in_stats);
   void randomLookup();
-  void handleFindNode(Message* msg);
+  void handleFindNode(const Message* msg);
 };
 }
 // identifier functions
index d03ea86..4940300 100644 (file)
@@ -19,7 +19,7 @@ XBT_LOG_NEW_DEFAULT_CATEGORY(s4u_engine_filtering, "Messages specific for this s
 
 namespace filter {
 /* First example of thing that we can use as a filtering criteria: a simple boolean function */
-static bool filter_speed_more_than_50Mf(simgrid::s4u::Host* host)
+static bool filter_speed_more_than_50Mf(const simgrid::s4u::Host* host)
 {
   return host->get_speed() > 50E6;
 }
@@ -29,7 +29,7 @@ static bool filter_speed_more_than_50Mf(simgrid::s4u::Host* host)
  */
 class SingleCore {
 public:
-  bool operator()(simgrid::s4u::Host* host) { return host->get_core_count() == 1; }
+  bool operator()(const simgrid::s4u::Host* host) { return host->get_core_count() == 1; }
 };
 
 /* This functor is a bit more complex, as it saves the current state when created.
@@ -60,7 +60,7 @@ int main(int argc, char* argv[])
   /* Use a lambda function to filter hosts: We only want multicore hosts */
   XBT_INFO("Hosts currently registered with this engine: %zu", e.get_host_count());
   std::vector<simgrid::s4u::Host*> list =
-      e.get_filtered_hosts([](simgrid::s4u::Host* host) { return host->get_core_count() > 1; });
+      e.get_filtered_hosts([](const simgrid::s4u::Host* host) { return host->get_core_count() > 1; });
 
   for (auto& host : list)
     XBT_INFO("The following hosts have more than one core: %s", host->get_cname());
index 95affd0..580b978 100644 (file)
@@ -18,7 +18,7 @@ XBT_LOG_NEW_DEFAULT_CATEGORY(replay_comm, "Messages specific for this msg exampl
   } else                                                                                                               \
   ((void)0)
 
-static void log_action(simgrid::xbt::ReplayAction& action, double date)
+static void log_action(const simgrid::xbt::ReplayAction& action, double date)
 {
   if (XBT_LOG_ISENABLED(replay_comm, xbt_log_priority_verbose)) {
     std::string s = boost::algorithm::join(action, " ");
index 07ea1ea..1602dda 100644 (file)
@@ -21,7 +21,7 @@ static std::unordered_map<std::string, simgrid::s4u::File*> opened_files;
   } else                                                                                                               \
     ((void)0)
 
-static void log_action(simgrid::xbt::ReplayAction& action, double date)
+static void log_action(const simgrid::xbt::ReplayAction& action, double date)
 {
   if (XBT_LOG_ISENABLED(replay_io, xbt_log_priority_verbose)) {
     std::string s = boost::algorithm::join(action, " ");
index f129940..34542e7 100644 (file)
@@ -16,8 +16,7 @@ const char* buffer;                                                        /* Wh
 simgrid::s4u::SemaphorePtr sem_empty = simgrid::s4u::Semaphore::create(1); /* indicates whether the buffer is empty */
 simgrid::s4u::SemaphorePtr sem_full  = simgrid::s4u::Semaphore::create(0); /* indicates whether the buffer is full */
 
-
-static void producer(std::vector<std::string>* args)
+static void producer(const std::vector<std::string>* args)
 {
   for (auto str : *args) {
     sem_empty->acquire();
index 429a3a2..d8c23d0 100644 (file)
@@ -14,7 +14,7 @@ XBT_LOG_NEW_DEFAULT_CATEGORY(msg_test, "Messages specific for this msg example")
 
 /* This shows how to extend the trace format by adding a new kind of events.
    This function is registered through xbt_replay_action_register() below. */
-static void action_blah(simgrid::xbt::ReplayAction& /*args*/)
+static void action_blah(const simgrid::xbt::ReplayAction& /*args*/)
 {
   /* Add your answer to the blah event here.
      args is a strings array containing the blank-separated parameters found in the trace for this event instance. */
index 8524a1a..5c0a1fe 100644 (file)
@@ -65,7 +65,7 @@ static void smpi_replay_process(Job* job, simgrid::s4u::BarrierPtr barrier, int
 }
 
 // Sleeps for a given amount of time
-static int sleeper_process(int* param)
+static int sleeper_process(const int* param)
 {
   XBT_DEBUG("Sleeping for %d seconds", *param);
   simgrid::s4u::this_actor::sleep_for(*param);
@@ -106,7 +106,7 @@ static int job_executor_process(Job* job)
 }
 
 // Executes a workload of SMPI processes
-static int workload_executor_process(std::vector<Job*>* workload)
+static int workload_executor_process(const std::vector<Job*>* workload)
 {
   for (Job* job : *workload) {
     // Let's wait until the job's waiting time if needed