Logo AND Algorithmique Numérique Distribuée

Public GIT Repository
a69c7e64cec644255530a9bc139f3939ae80885f
[simgrid.git] / examples / s4u / dumb / s4u_test.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 "simgrid/s4u.h"
7
8 using namespace simgrid;
9
10 XBT_LOG_NEW_DEFAULT_CATEGORY(s4u_test, "a sample log category");
11
12 class Worker : s4u::Process {
13 public:
14         Worker(const char*procname, s4u::Host *host,int argc, char **argv)
15                         : s4u::Process(procname,host,argc,argv){}
16
17         int main(int argc, char **argv) {
18                 XBT_INFO("Hello s4u, I'm ready to serve");
19
20                 char *msg = recvstr("worker");
21                 XBT_INFO("I received '%s'",msg);
22                 XBT_INFO("I'm done. See you.");
23                 return 1;
24         }
25 };
26
27 class Master : s4u::Process {
28 public:
29         Master(const char*procname, s4u::Host *host,int argc, char **argv)
30                         : s4u::Process(procname,host,argc,argv){}
31
32         int main(int argc, char **argv) {
33                 XBT_INFO("Hello s4u, I have something to send");
34                 sendstr("worker","GaBuZoMeu");
35
36                 XBT_INFO("I'm done. See you.");
37                 return 1;
38         }
39 };
40
41
42 int main(int argc, char **argv) {
43         s4u::Engine *e = new s4u::Engine(&argc,argv);
44         e->loadPlatform("../../platforms/two_hosts_platform.xml");
45
46         new Worker("worker", s4u::Host::byName("host0"), 0, NULL);
47         new Master("master", s4u::Host::byName("host1"), 0, NULL);
48         e->run();
49         return 0;
50 }