Logo AND Algorithmique Numérique Distribuée

Public GIT Repository
last changes of cpp wrappers examples
[simgrid.git] / examples / cxx / autoDestination / Forwarder.cxx
1 #include "Forwarder.hpp"
2 #include "BasicTask.hpp"
3 #include "FinalizeTask.hpp"
4
5 #include <Host.hpp>
6 #include <HostNotFoundException.hpp>
7
8 #include <Msg.hpp>
9
10 MSG_IMPLEMENT_DYNAMIC(Forwarder, Process)
11
12 int Forwarder::main(int argc, char** argv)
13 {
14         info("Hello");
15         
16         int aliasCount = argc;
17         
18         int taskCount = 0;
19         
20         Task* taskReceived;
21         Task* finalizeTask;
22         BasicTask* basicTask;
23         
24         while(true) 
25         {
26                 taskReceived = Task::receive();
27         
28                 if(taskReceived->isInstanceOf("FinalizeTask")) 
29                 {
30                         info("All tasks have been dispatched. Let's tell everybody the computation is over.");
31         
32                         for (int i = 0; i < aliasCount; i++) 
33                         {
34                                 finalizeTask = new FinalizeTask();
35                                 finalizeTask->send(argv[i]);
36                         }
37                         
38                         delete taskReceived;
39         
40                         break;
41                 }
42         
43                 basicTask = reinterpret_cast<BasicTask*>(taskReceived);
44         
45                 info(TEXT_("Received \"") + TEXT_(basicTask->getName()) + TEXT_("\" "));
46         
47                 info(TEXT_("Sending \"") + TEXT_(basicTask->getName()) + TEXT_("\" to \"") + TEXT_(argv[taskCount % aliasCount]));
48         
49                 basicTask->send(argv[taskCount % aliasCount]);
50         
51                 taskCount++;
52         }
53         
54         
55         info("I'm done. See you!");
56
57         delete this;
58         
59         return 0;
60 }