Logo AND Algorithmique Numérique Distribuée

Public GIT Repository
Rework the OO design of S4U comms
[simgrid.git] / examples / s4u / actor-create / s4u_actor-create.cpp
index 61bfedd..857b60a 100644 (file)
@@ -7,7 +7,7 @@
  *
  * 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();
+ *  - Directly, by instantiating your actor as paramter to Actor::create()
  *  - By first registering your actors before instantiating it;
  *  - Through the deployment file.
  *
@@ -30,9 +30,7 @@ XBT_LOG_NEW_DEFAULT_CATEGORY(s4u_actor_create, "The logging channel used in this
 class Sender {
 public:
   std::string msg = "GaBuZoMeu";
-  explicit Sender(){
-      /* Constructor used when no parameter is passed to the actor */
-  };
+  explicit Sender() = default;
   explicit Sender(std::vector<std::string> args)
   {
     /* This constructor is used when we pass parameters to the actor */
@@ -44,7 +42,7 @@ public:
     XBT_INFO("Hello s4u, I have something to send");
     simgrid::s4u::MailboxPtr mailbox = simgrid::s4u::Mailbox::byName("mb42");
 
-    simgrid::s4u::this_actor::send(mailbox, xbt_strdup(msg.c_str()), msg.size());
+    mailbox->send(xbt_strdup(msg.c_str()), msg.size());
     XBT_INFO("I'm done. See you.");
   }
 };
@@ -76,9 +74,11 @@ public:
   {
     XBT_INFO("Hello s4u, I'm ready to get any message you'd want on %s", mailbox->name());
 
-    char* msg1 = static_cast<char*>(simgrid::s4u::this_actor::recv(mailbox));
-    char* msg2 = static_cast<char*>(simgrid::s4u::this_actor::recv(mailbox));
+    char* msg1 = static_cast<char*>(mailbox->recv());
+    char* msg2 = static_cast<char*>(mailbox->recv());
     XBT_INFO("I received '%s' and '%s'", msg1, msg2);
+    xbt_free(msg1);
+    xbt_free(msg2);
     XBT_INFO("I'm done. See you.");
   }
 };
@@ -114,5 +114,7 @@ int main(int argc, char** argv)
   e->run();
 
   /* Once the simulation is done, the program is ended */
+  delete e;
+
   return 0;
 }