Logo AND Algorithmique Numérique Distribuée

Public GIT Repository
[sonar] Declare functions "const" in examples/ and teshsuite/.
authorArnaud Giersch <arnaud.giersch@univ-fcomte.fr>
Thu, 2 Jul 2020 19:42:09 +0000 (21:42 +0200)
committerArnaud Giersch <arnaud.giersch@univ-fcomte.fr>
Thu, 2 Jul 2020 20:02:22 +0000 (22:02 +0200)
19 files changed:
examples/s4u/actor-create/s4u-actor-create.cpp
examples/s4u/actor-lifetime/s4u-actor-lifetime.cpp
examples/s4u/actor-yield/s4u-actor-yield.cpp
examples/s4u/app-bittorrent/s4u-peer.cpp
examples/s4u/app-bittorrent/s4u-peer.hpp
examples/s4u/app-bittorrent/s4u-tracker.hpp
examples/s4u/async-waitall/s4u-async-waitall.cpp
examples/s4u/async-waitany/s4u-async-waitany.cpp
examples/s4u/dht-chord/s4u-dht-chord-node.cpp
examples/s4u/dht-chord/s4u-dht-chord.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/io-file-system/s4u-io-file-system.cpp
examples/s4u/replay-comm/s4u-replay-comm.cpp
examples/s4u/replay-io/s4u-replay-io.cpp
teshsuite/s4u/actor-suspend/actor-suspend.cpp

index bff3790..ee1e6ef 100644 (file)
@@ -75,7 +75,7 @@ public:
     msg  = args[1];
     mbox = args[2];
   }
-  void operator()() /* This is the main code of the actor */
+  void operator()() const /* This is the main code of the actor */
   {
     XBT_INFO("Hello s4u, I have something to send");
     simgrid::s4u::Mailbox* mailbox = simgrid::s4u::Mailbox::by_name(mbox);
index 5a945a4..5e3c614 100644 (file)
@@ -20,7 +20,7 @@ public:
       XBT_INFO("Exiting now (done sleeping or got killed).");
     });
   }
-  void operator()()
+  void operator()() const
   {
     XBT_INFO("Hello! I go to sleep.");
     simgrid::s4u::this_actor::sleep_for(10);
index 6abfa67..9ad18b8 100644 (file)
@@ -20,7 +20,7 @@ class yielder {
 
 public:
   explicit yielder(std::vector<std::string> args) { number_of_yields = std::stod(args[1]); }
-  void operator()()
+  void operator()() const
   {
     for (int i = 0; i < number_of_yields; i++)
       simgrid::s4u::this_actor::yield();
index 994d7ac..65db116 100644 (file)
@@ -159,7 +159,7 @@ void Peer::sendRequestTo(Connection* remote_peer, unsigned int piece)
   }
 }
 
-std::string Peer::getStatus()
+std::string Peer::getStatus() const
 {
   std::string res;
   for (unsigned i = 0; i < FILE_PIECES; i++)
@@ -167,7 +167,7 @@ std::string Peer::getStatus()
   return res;
 }
 
-bool Peer::hasFinished()
+bool Peer::hasFinished() const
 {
   return bitfield_ == (1U << FILE_PIECES) - 1U;
 }
@@ -193,7 +193,7 @@ void Peer::updatePiecesCountFromBitfield(unsigned int bitfield)
       pieces_count[i]++;
 }
 
-unsigned int Peer::countPieces(unsigned int bitfield)
+unsigned int Peer::countPieces(unsigned int bitfield) const
 {
   unsigned int count = 0U;
   unsigned int n     = bitfield;
@@ -204,7 +204,7 @@ unsigned int Peer::countPieces(unsigned int bitfield)
   return count;
 }
 
-int Peer::nbInterestedPeers()
+int Peer::nbInterestedPeers() const
 {
   int nb = 0;
   for (auto const& kv : connected_peers)
@@ -629,7 +629,7 @@ void Peer::updateBitfieldBlocks(int piece, int block_index, int block_length)
     bitfield_blocks |= (1ULL << static_cast<unsigned int>(piece * PIECES_BLOCKS + i));
 }
 
-bool Peer::hasCompletedPiece(unsigned int piece)
+bool Peer::hasCompletedPiece(unsigned int piece) const
 {
   for (unsigned int i = 0; i < PIECES_BLOCKS; i++)
     if (not(bitfield_blocks & 1ULL << (piece * PIECES_BLOCKS + i)))
@@ -637,7 +637,7 @@ bool Peer::hasCompletedPiece(unsigned int piece)
   return true;
 }
 
-int Peer::getFirstMissingBlockFrom(int piece)
+int Peer::getFirstMissingBlockFrom(int piece) const
 {
   for (unsigned int i = 0; i < PIECES_BLOCKS; i++)
     if (not(bitfield_blocks & 1ULL << (piece * PIECES_BLOCKS + i)))
@@ -646,7 +646,7 @@ int Peer::getFirstMissingBlockFrom(int piece)
 }
 
 /** Returns a piece that is partially downloaded and stored by the remote peer if any -1 otherwise. */
-int Peer::partiallyDownloadedPiece(const Connection* remote_peer)
+int Peer::partiallyDownloadedPiece(const Connection* remote_peer) const
 {
   for (unsigned int i = 0; i < FILE_PIECES; i++)
     if (remotePeerHasMissingPiece(remote_peer, i) && isNotDownloadingPiece(i) && getFirstMissingBlockFrom(i) > 0)
index 0175e26..4a3c84c 100644 (file)
@@ -52,9 +52,9 @@ public:
   Peer& operator=(const Peer&) = delete;
   void operator()();
 
-  std::string getStatus();
-  bool hasFinished();
-  int nbInterestedPeers();
+  std::string getStatus() const;
+  bool hasFinished() const;
+  int nbInterestedPeers() const;
   bool isInterestedBy(const Connection* remote_peer) const;
   bool isInterestedByFree(const Connection* remote_peer) const;
   void updateActivePeersSet(Connection* remote_peer);
@@ -62,19 +62,19 @@ public:
   void updateChokedPeers();
 
   bool hasNotPiece(unsigned int piece) const { return not(bitfield_ & 1U << piece); }
-  bool remotePeerHasMissingPiece(const Connection* remote_peer, unsigned int piece)
+  bool remotePeerHasMissingPiece(const Connection* remote_peer, unsigned int piece) const
   {
     return hasNotPiece(piece) && remote_peer->hasPiece(piece);
   }
-  bool hasCompletedPiece(unsigned int piece);
-  unsigned int countPieces(unsigned int bitfield);
+  bool hasCompletedPiece(unsigned int piece) const;
+  unsigned int countPieces(unsigned int bitfield) const;
   /** Check that a piece is not currently being download by the peer. */
   bool isNotDownloadingPiece(unsigned int piece) const { return not(current_pieces & 1U << piece); }
-  int partiallyDownloadedPiece(const Connection* remote_peer);
+  int partiallyDownloadedPiece(const Connection* remote_peer) const;
   void updatePiecesCountFromBitfield(unsigned int bitfield);
   void removeCurrentPiece(Connection* remote_peer, unsigned int current_piece);
   void updateBitfieldBlocks(int piece, int block_index, int block_length);
-  int getFirstMissingBlockFrom(int piece);
+  int getFirstMissingBlockFrom(int piece) const;
   int selectPieceToDownload(const Connection* remote_peer);
   void requestNewPieceTo(Connection* remote_peer);
 
index 8fc72ce..acdb129 100644 (file)
@@ -17,8 +17,8 @@ class TrackerQuery {
 public:
   explicit TrackerQuery(int peer_id, simgrid::s4u::Mailbox* return_mailbox)
       : peer_id(peer_id), return_mailbox(return_mailbox){};
-  int getPeerId() { return peer_id; }
-  simgrid::s4u::Mailbox* getReturnMailbox() { return return_mailbox; }
+  int getPeerId() const { return peer_id; }
+  simgrid::s4u::Mailbox* getReturnMailbox() const { return return_mailbox; }
 };
 
 class TrackerAnswer {
@@ -27,7 +27,7 @@ class TrackerAnswer {
 public:
   explicit TrackerAnswer(int /*interval*/) /*: interval(interval)*/ {}
   void addPeer(int peer) { peers.insert(peer); }
-  const std::set<int>& getPeers() { return peers; }
+  const std::set<int>& getPeers() const { return peers; }
 };
 
 class Tracker {
index 141d749..0818656 100644 (file)
@@ -32,7 +32,7 @@ public:
     msg_size        = std::stod(args[2]);
     receivers_count = std::stol(args[3]);
   }
-  void operator()()
+  void operator()() const
   {
     // sphinx-doc: init-begin (this line helps the doc to build; ignore it)
     /* Vector in which we store all ongoing communications */
index ef890fe..d4ef016 100644 (file)
@@ -37,7 +37,7 @@ public:
     msg_size        = std::stod(args[2]);
     receivers_count = std::stol(args[3]);
   }
-  void operator()()
+  void operator()() const
   {
     /* Vector in which we store all ongoing communications */
     std::vector<simgrid::s4u::CommPtr> pending_comms;
index fe914e7..fbfdec6 100644 (file)
@@ -364,7 +364,7 @@ void Node::notify(int predecessor_candidate_id)
 }
 
 /* Notifies a remote node that its predecessor may have changed. */
-void Node::remoteNotify(int notify_id, int predecessor_candidate_id)
+void Node::remoteNotify(int notify_id, int predecessor_candidate_id) const
 {
   ChordMessage* message = new ChordMessage(NOTIFY);
   message->request_id   = predecessor_candidate_id;
index bac34b5..4b9e85f 100644 (file)
@@ -81,7 +81,7 @@ public:
   int remoteFindSuccessor(int ask_to, int id);
 
   void notify(int predecessor_candidate_id);
-  void remoteNotify(int notify_id, int predecessor_candidate_id);
+  void remoteNotify(int notify_id, int predecessor_candidate_id) const;
   void stabilize();
   void handleMessage(ChordMessage* message);
 
index 6d5515c..8e3b0ab 100644 (file)
@@ -11,7 +11,7 @@ XBT_LOG_EXTERNAL_DEFAULT_CATEGORY(kademlia_node);
 namespace kademlia {
 
 /** @brief Prints a answer_t, for debugging purposes */
-void Answer::print()
+void Answer::print() const
 {
   XBT_INFO("Searching %08x, size %zu", destination_id_, nodes_.size());
   unsigned int i = 0;
index de5e1c9..2c11211 100644 (file)
@@ -23,7 +23,7 @@ public:
   unsigned int getDestinationId() const { return destination_id_; }
   size_t getSize() const { return nodes_.size(); }
   const std::vector<std::pair<unsigned int, unsigned int>>& getNodes() const { return nodes_; }
-  void print();
+  void print() const;
   unsigned int merge(const Answer* a);
   void trim();
   bool destinationFound() const;
index c8ac463..265cdc0 100644 (file)
@@ -76,7 +76,7 @@ bool Node::join(unsigned int known_id)
   * @param id node we are querying
   * @param destination node we are trying to find.
   */
-void Node::sendFindNode(unsigned int id, unsigned int destination)
+void Node::sendFindNode(unsigned int id, unsigned int destination) const
 {
   /* Gets the mailbox to send to */
   simgrid::s4u::Mailbox* mailbox = simgrid::s4u::Mailbox::by_name(std::to_string(id));
@@ -94,7 +94,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(const Answer* node_list)
+unsigned int Node::sendFindNodeToBest(const Answer* node_list) const
 {
   unsigned int i           = 0;
   unsigned int j           = 0;
@@ -281,7 +281,7 @@ void Node::handleFindNode(const Message* msg)
   msg->answer_to_->put_init(answer, 1)->detach(kademlia::destroy);
 }
 
-void Node::displaySuccessRate()
+void Node::displaySuccessRate() const
 {
   XBT_INFO("%u/%u FIND_NODE have succeeded", find_node_success, find_node_success + find_node_failed);
 }
index ab64fa7..f65106c 100644 (file)
@@ -24,17 +24,17 @@ public:
   explicit Node(unsigned int node_id) : id_(node_id), table(node_id) {}
   Node(const Node&) = delete;
   Node& operator=(const Node&) = delete;
-  unsigned int getId() { return id_; }
+  unsigned int getId() const { return id_; }
 
   bool join(unsigned int known_id);
-  void sendFindNode(unsigned int id, unsigned int destination);
-  unsigned int sendFindNodeToBest(const Answer* node_list);
+  void sendFindNode(unsigned int id, unsigned int destination) const;
+  unsigned int sendFindNodeToBest(const Answer* node_list) const;
   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(const Message* msg);
-  void displaySuccessRate();
+  void displaySuccessRate() const;
 };
 } // namespace kademlia
 // identifier functions
index 639e1ed..b240d22 100644 (file)
@@ -29,7 +29,7 @@ static bool filter_speed_more_than_50Mf(const simgrid::s4u::Host* host)
  */
 class SingleCore {
 public:
-  bool operator()(const simgrid::s4u::Host* host) { return host->get_core_count() == 1; }
+  bool operator()(const simgrid::s4u::Host* host) const { return host->get_core_count() == 1; }
 };
 
 /* This functor is a bit more complex, as it saves the current state when created.
index 46f1e02..bdc6629 100644 (file)
@@ -13,7 +13,7 @@ XBT_LOG_NEW_DEFAULT_CATEGORY(s4u_test, "a sample log category");
 
 class MyHost {
 public:
-  void show_info(std::vector<simgrid::s4u::Disk*> const& disks)
+  void show_info(std::vector<simgrid::s4u::Disk*> const& disks) const
   {
     XBT_INFO("Storage info on %s:", simgrid::s4u::Host::current()->get_cname());
 
@@ -24,7 +24,7 @@ public:
     }
   }
 
-  void operator()()
+  void operator()() const
   {
     std::vector<simgrid::s4u::Disk*> const& disks = simgrid::s4u::Host::current()->get_disks();
 
index 5f3071c..0543bc5 100644 (file)
@@ -35,7 +35,7 @@ public:
     simgrid::xbt::replay_runner(actor_name, trace_filename);
   }
 
-  void operator()()
+  void operator()() const
   {
     // Nothing to do here
   }
index f5205e4..509995c 100644 (file)
@@ -44,7 +44,7 @@ public:
     simgrid::xbt::replay_runner(actor_name, nullptr);
   }
 
-  void operator()()
+  void operator()() const
   {
     // Nothing to do here
   }
index b34d160..e509b37 100644 (file)
@@ -18,7 +18,7 @@ simgrid::s4u::ActorPtr receiver;
 
 class Receiver {
 public:
-  void operator()()
+  void operator()() const
   {
     XBT_INFO("Starting.");
     auto mailbox = simgrid::s4u::Mailbox::by_name("receiver");
@@ -29,7 +29,7 @@ public:
 
 class Suspender {
 public:
-  void operator()()
+  void operator()() const
   {
     XBT_INFO("Suspend the receiver...");
     receiver->suspend();