Logo AND Algorithmique Numérique Distribuée

Public GIT Repository
Change getName() and add getCname() in s4u::Mailbox.
authorArnaud Giersch <arnaud.giersch@univ-fcomte.fr>
Sat, 14 Oct 2017 20:40:05 +0000 (22:40 +0200)
committerArnaud Giersch <arnaud.giersch@univ-fcomte.fr>
Sat, 14 Oct 2017 21:51:38 +0000 (23:51 +0200)
examples/s4u/actions-comm/s4u-actions-comm.cpp
examples/s4u/actor-create/s4u-actor-create.cpp
examples/s4u/app-bittorrent/s4u-peer.cpp
examples/s4u/app-masterworker/s4u-app-masterworker.cpp
examples/s4u/app-token-ring/s4u-app-token-ring.cpp
examples/s4u/dht-chord/node.cpp
include/simgrid/s4u/Mailbox.hpp
src/msg/msg_gos.cpp
src/s4u/s4u_mailbox.cpp

index a62e455..5a1faac 100644 (file)
@@ -64,7 +64,7 @@ public:
     double clock                = simgrid::s4u::Engine::getClock();
     simgrid::s4u::MailboxPtr to = simgrid::s4u::Mailbox::byName(simgrid::s4u::this_actor::getName() + "_" + action[2]);
     ACT_DEBUG("Entering Send: %s (size: %g) -- Actor %s on mailbox %s", NAME, size,
     double clock                = simgrid::s4u::Engine::getClock();
     simgrid::s4u::MailboxPtr to = simgrid::s4u::Mailbox::byName(simgrid::s4u::this_actor::getName() + "_" + action[2]);
     ACT_DEBUG("Entering Send: %s (size: %g) -- Actor %s on mailbox %s", NAME, size,
-              simgrid::s4u::this_actor::getCname(), to->getName());
+              simgrid::s4u::this_actor::getCname(), to->getCname());
     to->put(payload, size);
     delete payload;
 
     to->put(payload, size);
     delete payload;
 
@@ -77,7 +77,7 @@ public:
     simgrid::s4u::MailboxPtr from =
         simgrid::s4u::Mailbox::byName(std::string(action[2]) + "_" + simgrid::s4u::this_actor::getName());
 
     simgrid::s4u::MailboxPtr from =
         simgrid::s4u::Mailbox::byName(std::string(action[2]) + "_" + simgrid::s4u::this_actor::getName());
 
-    ACT_DEBUG("Receiving: %s -- Actor %s on mailbox %s", NAME, simgrid::s4u::this_actor::getCname(), from->getName());
+    ACT_DEBUG("Receiving: %s -- Actor %s on mailbox %s", NAME, simgrid::s4u::this_actor::getCname(), from->getCname());
     from->get();
     log_action(action, simgrid::s4u::Engine::getClock() - clock);
   }
     from->get();
     log_action(action, simgrid::s4u::Engine::getClock() - clock);
   }
index d83d75a..8753058 100644 (file)
@@ -73,7 +73,7 @@ public:
   }
   void operator()()
   {
   }
   void operator()()
   {
-    XBT_INFO("Hello s4u, I'm ready to get any message you'd want on %s", mailbox->getName());
+    XBT_INFO("Hello s4u, I'm ready to get any message you'd want on %s", mailbox->getCname());
 
     std::string* msg1 = static_cast<std::string*>(mailbox->get());
     std::string* msg2 = static_cast<std::string*>(mailbox->get());
 
     std::string* msg1 = static_cast<std::string*>(mailbox->get());
     std::string* msg2 = static_cast<std::string*>(mailbox->get());
index 8f57ee9..3225496 100644 (file)
@@ -128,13 +128,13 @@ void Peer::sendHandshakeToAllPeers()
 void Peer::sendMessage(simgrid::s4u::MailboxPtr mailbox, e_message_type type, uint64_t size)
 {
   const char* type_names[6] = {"HANDSHAKE", "CHOKE", "UNCHOKE", "INTERESTED", "NOTINTERESTED", "CANCEL"};
 void Peer::sendMessage(simgrid::s4u::MailboxPtr mailbox, e_message_type type, uint64_t size)
 {
   const char* type_names[6] = {"HANDSHAKE", "CHOKE", "UNCHOKE", "INTERESTED", "NOTINTERESTED", "CANCEL"};
-  XBT_DEBUG("Sending %s to %s", type_names[type], mailbox->getName());
+  XBT_DEBUG("Sending %s to %s", type_names[type], mailbox->getCname());
   mailbox->put_init(new Message(type, id, bitfield_, mailbox_), size)->detach();
 }
 
 void Peer::sendBitfield(simgrid::s4u::MailboxPtr mailbox)
 {
   mailbox->put_init(new Message(type, id, bitfield_, mailbox_), size)->detach();
 }
 
 void Peer::sendBitfield(simgrid::s4u::MailboxPtr mailbox)
 {
-  XBT_DEBUG("Sending a BITFIELD to %s", mailbox->getName());
+  XBT_DEBUG("Sending a BITFIELD to %s", mailbox->getCname());
   mailbox
       ->put_init(new Message(MESSAGE_BITFIELD, id, bitfield_, mailbox_),
                  MESSAGE_BITFIELD_SIZE + BITS_TO_BYTES(FILE_PIECES))
   mailbox
       ->put_init(new Message(MESSAGE_BITFIELD, id, bitfield_, mailbox_),
                  MESSAGE_BITFIELD_SIZE + BITS_TO_BYTES(FILE_PIECES))
@@ -144,7 +144,7 @@ void Peer::sendBitfield(simgrid::s4u::MailboxPtr mailbox)
 void Peer::sendPiece(simgrid::s4u::MailboxPtr mailbox, unsigned int piece, int block_index, int block_length)
 {
   xbt_assert(not hasNotPiece(piece), "Tried to send a unavailable piece.");
 void Peer::sendPiece(simgrid::s4u::MailboxPtr mailbox, unsigned int piece, int block_index, int block_length)
 {
   xbt_assert(not hasNotPiece(piece), "Tried to send a unavailable piece.");
-  XBT_DEBUG("Sending the PIECE %u (%d,%d) to %s", piece, block_index, block_length, mailbox->getName());
+  XBT_DEBUG("Sending the PIECE %u (%d,%d) to %s", piece, block_index, block_length, mailbox->getCname());
   mailbox->put_init(new Message(MESSAGE_PIECE, id, mailbox_, piece, block_index, block_length), BLOCK_SIZE)->detach();
 }
 
   mailbox->put_init(new Message(MESSAGE_PIECE, id, mailbox_, piece, block_index, block_length), BLOCK_SIZE)->detach();
 }
 
@@ -164,7 +164,7 @@ void Peer::sendRequestTo(Connection* remote_peer, unsigned int piece)
   int block_index = getFirstMissingBlockFrom(piece);
   if (block_index != -1) {
     int block_length = MIN(BLOCKS_REQUESTED, PIECES_BLOCKS - block_index);
   int block_index = getFirstMissingBlockFrom(piece);
   if (block_index != -1) {
     int block_length = MIN(BLOCKS_REQUESTED, PIECES_BLOCKS - block_index);
-    XBT_DEBUG("Sending a REQUEST to %s for piece %u (%d,%d)", remote_peer->mailbox_->getName(), piece, block_index,
+    XBT_DEBUG("Sending a REQUEST to %s for piece %u (%d,%d)", remote_peer->mailbox_->getCname(), piece, block_index,
               block_length);
     remote_peer->mailbox_
         ->put_init(new Message(MESSAGE_REQUEST, id, mailbox_, piece, block_index, block_length), MESSAGE_REQUEST_SIZE)
               block_length);
     remote_peer->mailbox_
         ->put_init(new Message(MESSAGE_REQUEST, id, mailbox_, piece, block_index, block_length), MESSAGE_REQUEST_SIZE)
@@ -233,7 +233,7 @@ void Peer::leech()
 
   /* Send a "handshake" message to all the peers it got (since it couldn't have gotten more than 50 peers) */
   sendHandshakeToAllPeers();
 
   /* Send a "handshake" message to all the peers it got (since it couldn't have gotten more than 50 peers) */
   sendHandshakeToAllPeers();
-  XBT_DEBUG("Starting main leech loop listening on mailbox: %s", mailbox_->getName());
+  XBT_DEBUG("Starting main leech loop listening on mailbox: %s", mailbox_->getCname());
 
   void* data = nullptr;
   while (simgrid::s4u::Engine::getClock() < deadline && countPieces(bitfield_) < FILE_PIECES) {
 
   void* data = nullptr;
   while (simgrid::s4u::Engine::getClock() < deadline && countPieces(bitfield_) < FILE_PIECES) {
@@ -299,7 +299,7 @@ void Peer::handleMessage()
   const char* type_names[10] = {"HANDSHAKE", "CHOKE",    "UNCHOKE", "INTERESTED", "NOTINTERESTED",
                                 "HAVE",      "BITFIELD", "REQUEST", "PIECE",      "CANCEL"};
 
   const char* type_names[10] = {"HANDSHAKE", "CHOKE",    "UNCHOKE", "INTERESTED", "NOTINTERESTED",
                                 "HAVE",      "BITFIELD", "REQUEST", "PIECE",      "CANCEL"};
 
-  XBT_DEBUG("Received a %s message from %s", type_names[message->type], message->return_mailbox->getName());
+  XBT_DEBUG("Received a %s message from %s", type_names[message->type], message->return_mailbox->getCname());
 
   auto known_peer         = connected_peers.find(message->peer_id);
   Connection* remote_peer = (known_peer == connected_peers.end()) ? nullptr : known_peer->second;
 
   auto known_peer         = connected_peers.find(message->peer_id);
   Connection* remote_peer = (known_peer == connected_peers.end()) ? nullptr : known_peer->second;
index e21badf..199299a 100644 (file)
@@ -37,7 +37,7 @@ public:
 
       if (number_of_tasks < 10000 || i % 10000 == 0)
         XBT_INFO("Sending \"%s\" (of %ld) to mailbox \"%s\"", (std::string("Task_") + std::to_string(i)).c_str(),
 
       if (number_of_tasks < 10000 || i % 10000 == 0)
         XBT_INFO("Sending \"%s\" (of %ld) to mailbox \"%s\"", (std::string("Task_") + std::to_string(i)).c_str(),
-                 number_of_tasks, mailbox->getName());
+                 number_of_tasks, mailbox->getCname());
 
       /* - Send the computation amount to the @ref worker */
       mailbox->put(new double(comp_size), comm_size);
 
       /* - Send the computation amount to the @ref worker */
       mailbox->put(new double(comp_size), comm_size);
index 51d44f4..388e19f 100644 (file)
@@ -38,7 +38,7 @@ public:
 
     if (rank == 0) {
       /* The root process (rank 0) first sends the token then waits to receive it back */
 
     if (rank == 0) {
       /* The root process (rank 0) first sends the token then waits to receive it back */
-      XBT_INFO("Host \"%u\" send 'Token' to Host \"%s\"", rank, neighbor_mailbox->getName());
+      XBT_INFO("Host \"%u\" send 'Token' to Host \"%s\"", rank, neighbor_mailbox->getCname());
       std::string msg = "Token";
       neighbor_mailbox->put(&msg, task_comm_size);
       std::string* res = static_cast<std::string*>(my_mailbox->get());
       std::string msg = "Token";
       neighbor_mailbox->put(&msg, task_comm_size);
       std::string* res = static_cast<std::string*>(my_mailbox->get());
@@ -46,7 +46,7 @@ public:
     } else {
       std::string* res = static_cast<std::string*>(my_mailbox->get());
       XBT_INFO("Host \"%u\" received \"%s\"", rank, res->c_str());
     } else {
       std::string* res = static_cast<std::string*>(my_mailbox->get());
       XBT_INFO("Host \"%u\" received \"%s\"", rank, res->c_str());
-      XBT_INFO("Host \"%u\" send 'Token' to Host \"%s\"", rank, neighbor_mailbox->getName());
+      XBT_INFO("Host \"%u\" send 'Token' to Host \"%s\"", rank, neighbor_mailbox->getCname());
       neighbor_mailbox->put(res, task_comm_size);
     }
   }
       neighbor_mailbox->put(res, task_comm_size);
     }
   }
index a31877f..4a73c0f 100644 (file)
@@ -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_,
   }
   // receive the answer
   XBT_DEBUG("Sent 'Predecessor Alive' request to %d, waiting for the answer on my mailbox '%s'", pred_id_,
-            message->answer_to->getName());
+            message->answer_to->getCname());
   simgrid::s4u::CommPtr comm = return_mailbox->get_async(&data);
 
   try {
   simgrid::s4u::CommPtr comm = return_mailbox->get_async(&data);
 
   try {
@@ -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,
 
   // receive the answer
   XBT_DEBUG("Sent 'Get Predecessor' request to %d, waiting for the answer on my mailbox '%s'", ask_to,
-            message->answer_to->getName());
+            message->answer_to->getCname());
   simgrid::s4u::CommPtr comm = return_mailbox->get_async(&data);
 
   try {
   simgrid::s4u::CommPtr comm = return_mailbox->get_async(&data);
 
   try {
@@ -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->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->getName(), message->request_id,
+                message->issuer_host_name.c_str(), message->answer_to->getCname(), message->request_id,
                 message->answer_id);
       message->answer_to->put_init(message, 10)->detach(ChordMessage::destroy);
     } else {
                 message->answer_id);
       message->answer_to->put_init(message, 10)->detach(ChordMessage::destroy);
     } else {
@@ -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->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->getName(), message->answer_id);
+              message->issuer_host_name.c_str(), message->answer_to->getCname(), message->answer_id);
     message->answer_to->put_init(message, 10)->detach(ChordMessage::destroy);
     break;
 
     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(),
     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->getName());
+              message->answer_to->getCname());
     message->answer_to->put_init(message, 10)->detach(ChordMessage::destroy);
     break;
 
     message->answer_to->put_init(message, 10)->detach(ChordMessage::destroy);
     break;
 
index f7d280d..3ca3459 100644 (file)
@@ -9,6 +9,7 @@
 #include <string>
 
 #include <xbt/base.h>
 #include <string>
 
 #include <xbt/base.h>
+#include <xbt/string.hpp>
 
 #include <simgrid/s4u/forward.hpp>
 #include <simgrid/s4u/Actor.hpp>
 
 #include <simgrid/s4u/forward.hpp>
 #include <simgrid/s4u/Actor.hpp>
@@ -120,8 +121,10 @@ public:
   /** private function, do not use. FIXME: make me protected */
   kernel::activity::MailboxImpl* getImpl() { return pimpl_; }
 
   /** private function, do not use. FIXME: make me protected */
   kernel::activity::MailboxImpl* getImpl() { return pimpl_; }
 
-  /** Gets the name of that mailbox */
-  const char* getName();
+  /** @brief Retrieves the name of that mailbox as a C++ string */
+  const simgrid::xbt::string& getName() const;
+  /** @brief Retrieves the name of that mailbox as a C string */
+  const char* getCname() const;
 
   /** Retrieve the mailbox associated to the given C string */
   static MailboxPtr byName(const char *name);
 
   /** Retrieve the mailbox associated to the given C string */
   static MailboxPtr byName(const char *name);
index 3846e9e..d6ef1f3 100644 (file)
@@ -270,7 +270,7 @@ msg_error_t MSG_task_receive_ext_bounded(msg_task_t * task, const char *alias, d
   /* Try to receive it by calling SIMIX network layer */
   try {
     simcall_comm_recv(MSG_process_self()->getImpl(), mailbox->getImpl(), task, nullptr, nullptr, nullptr, nullptr, timeout, rate);
   /* Try to receive it by calling SIMIX network layer */
   try {
     simcall_comm_recv(MSG_process_self()->getImpl(), mailbox->getImpl(), task, nullptr, nullptr, nullptr, nullptr, timeout, rate);
-    XBT_DEBUG("Got task %s from %s", (*task)->name, mailbox->getName());
+    XBT_DEBUG("Got task %s from %s", (*task)->name, mailbox->getCname());
     (*task)->simdata->setNotUsed();
   }
   catch (xbt_ex& e) {
     (*task)->simdata->setNotUsed();
   }
   catch (xbt_ex& e) {
index a3dbf16..32ab0bb 100644 (file)
@@ -16,9 +16,14 @@ XBT_LOG_NEW_DEFAULT_SUBCATEGORY(s4u_channel,s4u,"S4U Communication Mailboxes");
 namespace simgrid {
 namespace s4u {
 
 namespace simgrid {
 namespace s4u {
 
-const char* Mailbox::getName()
+const simgrid::xbt::string& Mailbox::getName() const
 {
 {
-  return pimpl_->name_.c_str();
+  return pimpl_->getName();
+}
+
+const char* Mailbox::getCname() const
+{
+  return pimpl_->getCname();
 }
 
 MailboxPtr Mailbox::byName(const char*name)
 }
 
 MailboxPtr Mailbox::byName(const char*name)