Logo AND Algorithmique Numérique Distribuée

Public GIT Repository
11b3e114608f0845760dd782a13d034fa7cabab3
[simgrid.git] / examples / s4u / basic / s4u_basic.cpp
1 /* Copyright (c) 2006-2015. The SimGrid Team. All rights reserved.          */
2
3 /* This program is free software; you can redistribute it and/or modify it
4  * under the terms of the license (GNU LGPL) which comes with this package. */
5
6 #include <xbt/sysdep.h>
7
8 #include "simgrid/s4u.h"
9
10 XBT_LOG_NEW_DEFAULT_CATEGORY(s4u_test, "a sample log category");
11
12 class Worker {
13 public:
14   void operator()() {
15     XBT_INFO("Hello s4u, I'm ready to serve");
16     char *msg = (char*)simgrid::s4u::this_actor::recv(*simgrid::s4u::Mailbox::byName("worker"));
17     XBT_INFO("I received '%s'",msg);
18     XBT_INFO("I'm done. See you.");
19   }
20 };
21
22 class Master {
23 public:
24   void operator()() {
25     const char *msg = "GaBuZoMeu";
26     XBT_INFO("Hello s4u, I have something to send");
27     simgrid::s4u::this_actor::send(*simgrid::s4u::Mailbox::byName("worker"), xbt_strdup(msg), strlen(msg));
28     XBT_INFO("I'm done. See you.");
29   }
30 };
31
32
33 int main(int argc, char **argv) {
34   simgrid::s4u::Engine *e = new simgrid::s4u::Engine(&argc,argv);
35   e->loadPlatform("../../platforms/two_hosts_platform.xml");
36   new simgrid::s4u::Actor("worker", simgrid::s4u::Host::by_name("host0"), Worker());
37   new simgrid::s4u::Actor("master", simgrid::s4u::Host::by_name("host1"), 0, Master());
38   e->run();
39   return 0;
40 }