Logo AND Algorithmique Numérique Distribuée

Public GIT Repository
snake_case s4u::Mailbox
[simgrid.git] / examples / s4u / dht-chord / s4u-dht-chord-node.cpp
index 4a73c0f..e618a38 100644 (file)
@@ -1,4 +1,4 @@
-/* Copyright (c) 2010-2017. The SimGrid Team. All rights reserved.          */
+/* Copyright (c) 2010-2018. 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. */
@@ -52,8 +52,8 @@ Node::Node(std::vector<std::string> args)
 
   // initialize my node
   id_                = std::stoi(args[1]);
-  stream             = simgrid::s4u::this_actor::getHost()->extension<HostChord>()->getStream();
-  mailbox_           = simgrid::s4u::Mailbox::byName(std::to_string(id_));
+  stream             = simgrid::s4u::this_actor::get_host()->extension<HostChord>()->getStream();
+  mailbox_           = simgrid::s4u::Mailbox::by_name(std::to_string(id_));
   next_finger_to_fix = 0;
   fingers_           = new int[nb_bits];
 
@@ -63,7 +63,7 @@ Node::Node(std::vector<std::string> args)
 
   if (args.size() == 3) { // first ring
     deadline_   = std::stod(args[2]);
-    start_time_ = simgrid::s4u::Engine::getClock();
+    start_time_ = simgrid::s4u::Engine::get_clock();
     XBT_DEBUG("Create a new Chord ring...");
   } else {
     known_id_   = std::stoi(args[2]);
@@ -117,7 +117,7 @@ void Node::notifyAndQuit()
 
   XBT_DEBUG("Sending a 'PREDECESSOR_LEAVING' to my successor %d", fingers_[0]);
   try {
-    simgrid::s4u::Mailbox::byName(std::to_string(fingers_[0]))->put(pred_msg, 10, timeout);
+    simgrid::s4u::Mailbox::by_name(std::to_string(fingers_[0]))->put(pred_msg, 10, timeout);
   } catch (xbt_ex& e) {
     if (e.category == timeout_error) {
       XBT_DEBUG("Timeout expired when sending a 'PREDECESSOR_LEAVING' to my successor %d", fingers_[0]);
@@ -133,7 +133,7 @@ void Node::notifyAndQuit()
     XBT_DEBUG("Sending a 'SUCCESSOR_LEAVING' to my predecessor %d", pred_id_);
 
     try {
-      simgrid::s4u::Mailbox::byName(std::to_string(pred_id_))->put(succ_msg, 10, timeout);
+      simgrid::s4u::Mailbox::by_name(std::to_string(pred_id_))->put(succ_msg, 10, timeout);
     } catch (xbt_ex& e) {
       if (e.category == timeout_error) {
         XBT_DEBUG("Timeout expired when sending a 'SUCCESSOR_LEAVING' to my predecessor %d", pred_id_);
@@ -184,7 +184,7 @@ void Node::setPredecessor(int predecessor_id)
 void Node::fixFingers()
 {
   XBT_DEBUG("Fixing fingers");
-  int id = findSuccessor(id_ + powers2[next_finger_to_fix]);
+  int id = findSuccessor(id_ + (1U << next_finger_to_fix));
   if (id != -1) {
     if (id != fingers_[next_finger_to_fix]) {
       setFinger(next_finger_to_fix, id);
@@ -201,7 +201,7 @@ void Node::printFingerTable()
     XBT_VERB("My finger table:");
     XBT_VERB("Start | Succ");
     for (int i = 0; i < nb_bits; i++) {
-      XBT_VERB(" %3d  | %3d", (id_ + powers2[i]) % nb_keys, fingers_[i]);
+      XBT_VERB(" %3u  | %3d", (id_ + (1U << i)) % nb_keys, fingers_[i]);
     }
 
     XBT_VERB("Predecessor: %d", pred_id_);
@@ -216,8 +216,8 @@ void Node::checkPredecessor()
   if (pred_id_ == -1)
     return;
 
-  simgrid::s4u::MailboxPtr mailbox        = simgrid::s4u::Mailbox::byName(std::to_string(pred_id_));
-  simgrid::s4u::MailboxPtr return_mailbox = simgrid::s4u::Mailbox::byName(std::to_string(id_) + "_is_alive");
+  simgrid::s4u::MailboxPtr mailbox        = simgrid::s4u::Mailbox::by_name(std::to_string(pred_id_));
+  simgrid::s4u::MailboxPtr return_mailbox = simgrid::s4u::Mailbox::by_name(std::to_string(id_) + "_is_alive");
 
   ChordMessage* message = new ChordMessage(PREDECESSOR_ALIVE);
   message->request_id   = pred_id_;
@@ -235,7 +235,7 @@ void Node::checkPredecessor()
   }
   // receive the answer
   XBT_DEBUG("Sent 'Predecessor Alive' request to %d, waiting for the answer on my mailbox '%s'", pred_id_,
-            message->answer_to->getCname());
+            message->answer_to->get_cname());
   simgrid::s4u::CommPtr comm = return_mailbox->get_async(&data);
 
   try {
@@ -259,8 +259,8 @@ int Node::remoteGetPredecessor(int ask_to)
 {
   int predecessor_id                      = -1;
   void* data                              = nullptr;
-  simgrid::s4u::MailboxPtr mailbox        = simgrid::s4u::Mailbox::byName(std::to_string(ask_to));
-  simgrid::s4u::MailboxPtr return_mailbox = simgrid::s4u::Mailbox::byName(std::to_string(id_) + "_pred");
+  simgrid::s4u::MailboxPtr mailbox        = simgrid::s4u::Mailbox::by_name(std::to_string(ask_to));
+  simgrid::s4u::MailboxPtr return_mailbox = simgrid::s4u::Mailbox::by_name(std::to_string(id_) + "_pred");
 
   ChordMessage* message = new ChordMessage(GET_PREDECESSOR);
   message->request_id   = id_;
@@ -280,7 +280,7 @@ int Node::remoteGetPredecessor(int ask_to)
 
   // receive the answer
   XBT_DEBUG("Sent 'Get Predecessor' request to %d, waiting for the answer on my mailbox '%s'", ask_to,
-            message->answer_to->getCname());
+            message->answer_to->get_cname());
   simgrid::s4u::CommPtr comm = return_mailbox->get_async(&data);
 
   try {
@@ -335,8 +335,8 @@ int Node::remoteFindSuccessor(int ask_to, int id)
 {
   int successor                           = -1;
   void* data                              = nullptr;
-  simgrid::s4u::MailboxPtr mailbox        = simgrid::s4u::Mailbox::byName(std::to_string(ask_to));
-  simgrid::s4u::MailboxPtr return_mailbox = simgrid::s4u::Mailbox::byName(std::to_string(id_) + "_succ");
+  simgrid::s4u::MailboxPtr mailbox        = simgrid::s4u::Mailbox::by_name(std::to_string(ask_to));
+  simgrid::s4u::MailboxPtr return_mailbox = simgrid::s4u::Mailbox::by_name(std::to_string(id_) + "_succ");
 
   ChordMessage* message = new ChordMessage(FIND_SUCCESSOR);
   message->request_id   = id_;
@@ -393,7 +393,7 @@ void Node::remoteNotify(int notify_id, int predecessor_candidate_id)
 
   // send a "Notify" request to notify_id
   XBT_DEBUG("Sending a 'Notify' request to %d", notify_id);
-  simgrid::s4u::MailboxPtr mailbox = simgrid::s4u::Mailbox::byName(std::to_string(notify_id));
+  simgrid::s4u::MailboxPtr mailbox = simgrid::s4u::Mailbox::by_name(std::to_string(notify_id));
   mailbox->put_init(message, 10)->detach(ChordMessage::destroy);
 }
 
@@ -432,7 +432,7 @@ void Node::handleMessage(ChordMessage* message)
       message->type = FIND_SUCCESSOR_ANSWER;
       message->answer_id = fingers_[0];
       XBT_DEBUG("Sending back a 'Find Successor Answer' to %s (mailbox %s): the successor of %d is %d",
-                message->issuer_host_name.c_str(), message->answer_to->getCname(), message->request_id,
+                message->issuer_host_name.c_str(), message->answer_to->get_cname(), message->request_id,
                 message->answer_id);
       message->answer_to->put_init(message, 10)->detach(ChordMessage::destroy);
     } else {
@@ -440,7 +440,7 @@ void Node::handleMessage(ChordMessage* message)
       int closest = closestPrecedingFinger(message->request_id);
       XBT_DEBUG("Forwarding the 'Find Successor' request for id %d to my closest preceding finger %d",
           message->request_id, closest);
-      simgrid::s4u::MailboxPtr mailbox = simgrid::s4u::Mailbox::byName(std::to_string(closest));
+      simgrid::s4u::MailboxPtr mailbox = simgrid::s4u::Mailbox::by_name(std::to_string(closest));
       mailbox->put_init(message, 10)->detach(ChordMessage::destroy);
     }
     break;
@@ -450,7 +450,7 @@ void Node::handleMessage(ChordMessage* message)
     message->type = GET_PREDECESSOR_ANSWER;
     message->answer_id = pred_id_;
     XBT_DEBUG("Sending back a 'Get Predecessor Answer' to %s via mailbox '%s': my predecessor is %d",
-              message->issuer_host_name.c_str(), message->answer_to->getCname(), message->answer_id);
+              message->issuer_host_name.c_str(), message->answer_to->get_cname(), message->answer_id);
     message->answer_to->put_init(message, 10)->detach(ChordMessage::destroy);
     break;
 
@@ -488,7 +488,7 @@ void Node::handleMessage(ChordMessage* message)
     XBT_DEBUG("Receiving a 'Predecessor Alive' request from %s", message->issuer_host_name.c_str());
     message->type = PREDECESSOR_ALIVE_ANSWER;
     XBT_DEBUG("Sending back a 'Predecessor Alive Answer' to %s (mailbox %s)", message->issuer_host_name.c_str(),
-              message->answer_to->getCname());
+              message->answer_to->get_cname());
     message->answer_to->put_init(message, 10)->detach(ChordMessage::destroy);
     break;