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;
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);
}
}
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());
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)
{
- 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))
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();
}
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)
/* 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) {
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;
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);
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());
} 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);
}
}
}
// 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 {
// 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 {
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->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;
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;
#include <string>
#include <xbt/base.h>
+#include <xbt/string.hpp>
#include <simgrid/s4u/forward.hpp>
#include <simgrid/s4u/Actor.hpp>
/** 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);
/* 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) {
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)