X-Git-Url: http://info.iut-bm.univ-fcomte.fr/pub/gitweb/simgrid.git/blobdiff_plain/75e4262bd90620f114bdf576fdc3a63ef9dfb27e..2c0aa88e3d941e79fc79d39e3e58224d282b76d3:/examples/s4u/actor-create/s4u-actor-create.cpp diff --git a/examples/s4u/actor-create/s4u-actor-create.cpp b/examples/s4u/actor-create/s4u-actor-create.cpp index 6f18c3ad4a..874e36ad81 100644 --- a/examples/s4u/actor-create/s4u-actor-create.cpp +++ b/examples/s4u/actor-create/s4u-actor-create.cpp @@ -1,4 +1,4 @@ -/* Copyright (c) 2006-2018. The SimGrid Team. All rights reserved. */ +/* Copyright (c) 2006-2020. 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. */ @@ -7,8 +7,8 @@ * * The first step is to declare the code of your actors (what they do exactly does not matter to this example) and then * you ask SimGrid to start your actors. There is three ways of doing so: - * - Directly, by instantiating your actor as paramter to Actor::create() - * - By first registering your actors before instantiating it; + * - Directly, by instantiating your actor as parameter to Actor::create() + * - By first registering your actors before instantiating it * - Through the deployment file. * * This example shows all these solutions, even if you obviously should use only one of these solutions to start your @@ -27,15 +27,15 @@ XBT_LOG_NEW_DEFAULT_CATEGORY(s4u_actor_create, "The logging channel used in this * * Later, this actor class is instantiated within the simulation. */ -static void receiver(std::string mailbox_name) +static void receiver(const std::string& mailbox_name) { - simgrid::s4u::MailboxPtr mailbox = simgrid::s4u::Mailbox::byName(mailbox_name); + simgrid::s4u::Mailbox* mailbox = simgrid::s4u::Mailbox::by_name(mailbox_name); XBT_INFO("Hello s4u, I'm ready to get any message you'd want on %s", mailbox->get_cname()); - std::string* msg1 = static_cast(mailbox->get()); - std::string* msg2 = static_cast(mailbox->get()); - std::string* msg3 = static_cast(mailbox->get()); + const auto* msg1 = static_cast(mailbox->get()); + const auto* msg2 = static_cast(mailbox->get()); + const auto* msg3 = static_cast(mailbox->get()); XBT_INFO("I received '%s', '%s' and '%s'", msg1->c_str(), msg2->c_str(), msg3->c_str()); delete msg1; delete msg2; @@ -44,15 +44,14 @@ static void receiver(std::string mailbox_name) } /* Our second class of actors is also a function */ -static int forwarder(int argc, char** argv) +static void forwarder(int argc, char** argv) { xbt_assert(argc >= 3, "Actor forwarder requires 2 parameters, but got only %d", argc - 1); - simgrid::s4u::MailboxPtr in = simgrid::s4u::Mailbox::byName(argv[1]); - simgrid::s4u::MailboxPtr out = simgrid::s4u::Mailbox::byName(argv[2]); - std::string* msg = static_cast(in->get()); + simgrid::s4u::Mailbox* in = simgrid::s4u::Mailbox::by_name(argv[1]); + simgrid::s4u::Mailbox* out = simgrid::s4u::Mailbox::by_name(argv[2]); + auto* msg = static_cast(in->get()); XBT_INFO("Forward '%s'.", msg->c_str()); out->put(msg, msg->size()); - return 0; } /* Declares a third class of actors which sends a message to the mailbox 'mb42'. @@ -65,7 +64,7 @@ public: std::string mbox = "mb42"; std::string msg = "GaBuZoMeu"; explicit Sender() = default; /* Sending the default message */ - explicit Sender(std::string arg) : msg(arg) { /* Sending the specified message */} + explicit Sender(const std::string& arg) : msg(arg) { /* Sending the specified message */} explicit Sender(std::vector args) { /* This constructor is used when we start the actor from the deployment file */ @@ -76,10 +75,10 @@ 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::MailboxPtr mailbox = simgrid::s4u::Mailbox::byName(mbox); + simgrid::s4u::Mailbox* mailbox = simgrid::s4u::Mailbox::by_name(mbox); mailbox->put(new std::string(msg), msg.size()); XBT_INFO("I'm done. See you.");