Logo AND Algorithmique Numérique Distribuée

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