Logo AND Algorithmique Numérique Distribuée

Public GIT Repository
[s4u] Allocate Actors on the heap and return ActorPtr
[simgrid.git] / examples / s4u / basic / s4u_basic.cpp
index 678d16f..7ee0a43 100644 (file)
@@ -1,52 +1,19 @@
-/* Copyright (c) 2006-2015. The SimGrid Team. All rights reserved.          */
+/* Copyright (c) 2006-2016. 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. */
 
-#include "simgrid/s4u.h"
+#include <xbt/sysdep.h>
 
-using namespace simgrid;
-using namespace s4u;
-
-XBT_LOG_NEW_DEFAULT_CATEGORY(s4u_test, "a sample log category");
-
-class Worker : Actor {
-public:
-       Worker(const char*procname, Host *host,int argc, char **argv)
-                       : s4u::Actor(procname,host,argc,argv){}
-
-       int main(int argc, char **argv) {
-               XBT_INFO("Hello s4u, I'm ready to serve");
-
-               char *msg = (char*)recv(*Mailbox::byName("worker"));
-               XBT_INFO("I received '%s'",msg);
-               XBT_INFO("I'm done. See you.");
-               return 1;
-       }
-};
-
-class Master : Actor {
-public:
-       Master(const char*procname, Host *host,int argc, char **argv)
-                       : Actor(procname,host,argc,argv){}
-
-       int main(int argc, char **argv) {
-               const char *msg = "GaBuZoMeu";
-               XBT_INFO("Hello s4u, I have something to send");
-               send(*Mailbox::byName("worker"), xbt_strdup(msg), strlen(msg));
-
-               XBT_INFO("I'm done. See you.");
-               return 1;
-       }
-};
+#include <simgrid/s4u.h>
 
+#include "s4u_basic.h"
 
 int main(int argc, char **argv) {
-       Engine *e = new Engine(&argc,argv);
-       e->loadPlatform("../../platforms/two_hosts_platform.xml");
-
-       new Worker("worker", Host::byName("host0"), 0, NULL);
-       new Master("master", Host::byName("host1"), 0, NULL);
-       e->run();
-       return 0;
+  simgrid::s4u::Engine *e = new simgrid::s4u::Engine(&argc,argv);
+  e->loadPlatform("../../platforms/two_hosts.xml");
+  simgrid::s4u::Actor::createActor("worker", simgrid::s4u::Host::by_name("Tremblay"), Worker());
+  simgrid::s4u::Actor::createActor("master", simgrid::s4u::Host::by_name("Jupiter"), Master());
+  e->run();
+  return 0;
 }