source: sample/pingpong/PingPong.cpp@ 2432

Last change on this file since 2432 was 2432, checked in by Christoph Mayer, 15 years ago

-korrektes shutdown

File size: 3.1 KB
Line 
1
2#include "PingPong.h"
3#include "ariba/utility/configuration/Configuration.h"
4
5using ariba::utility::Configuration;
6using namespace ariba;
7
8namespace ariba {
9namespace application {
10namespace pingpong {
11
12// logging
13use_logging_cpp( PingPong);
14
15// the service id of the ping pong service
16ServiceID PingPong::PINGPONG_ID = ServiceID(111);
17
18// construction
19PingPong::PingPong() : pingId( 0 ) {
20}
21
22// destruction
23PingPong::~PingPong() {
24}
25
26// implementation of the startup interface
27void PingPong::startup() {
28
29 // create ariba module
30 logging_info("Creating ariba underlay module ... ");
31 ariba = new AribaModule();
32
33 logging_info("Starting up PingPong service ... ");
34
35 // --- get config ---
36 Configuration& config = Configuration::instance();
37
38 // generate spovnet name
39 Name spovnetName("pingpong");
40
41 // get initiator flag
42 this->isInitiator = Configuration::instance().read<bool> ("node.initiator");
43
44 // get node name
45 Name nodeName = Name::UNSPECIFIED;
46 if (config.exists("node.name")) nodeName
47 = config.read<string> ("node.name");
48
49 // configure ariba module
50 if (config.exists("ariba.ip.addr")) ariba->setProperty("ip.addr",
51 config.read<string> ("ariba.ip.addr"));
52 if (config.exists("ariba.tcp.port")) ariba->setProperty("tcp.port",
53 config.read<string> ("ariba.tcp.port"));
54 if (config.exists("ariba.udp.port")) ariba->setProperty("udp.port",
55 config.read<string> ("ariba.udp.port"));
56 if (config.exists("ariba.bootstrap.hints")) ariba->setProperty("bootstrap.hints",
57 config.read<string> ("ariba.bootstrap.hints"));
58
59 // start ariba module
60 ariba->start();
61
62 // create node and join
63 node = new Node( *ariba, nodeName );
64
65 // start node module
66 node->start();
67
68 if (!isInitiator) {
69 node->join(spovnetName);
70 } else {
71 node->initiate(spovnetName);
72 }
73
74 // bind communication and node listener
75 node->bind(this);
76 node->bind(this, PingPong::PINGPONG_ID);
77
78 // ping pong started up...
79 logging_info("PingPong started up");
80}
81
82// implementation of the startup interface
83void PingPong::shutdown() {
84 logging_info("PingPong service starting shutdown sequence ...");
85
86 // stop timer
87 Timer::stop();
88
89 // leave spovnet
90 node->leave();
91
92 // unbind listeners
93 node->unbind( this );
94 node->unbind( this, PingPong::PINGPONG_ID );
95
96 ariba->stop();
97 delete node;
98 delete ariba;
99
100 logging_info("PingPong service shut down!");
101}
102
103// node listener interface
104void PingPong::onJoinCompleted( const SpoVNetID& vid ) {
105 logging_info("PingPong node join completed, spovnetid=" << vid.toString() );
106}
107
108void PingPong::onJoinFailed( const SpoVNetID& vid ) {
109 logging_info("PingPong node join failed, spovnetid=" << vid.toString() );
110}
111
112// communication listener
113bool PingPong::onLinkRequest(const NodeID& remote, Message* msg) {
114 return false;
115}
116
117void PingPong::onMessage(Message* msg, const NodeID& remote, const LinkID& lnk =
118 LinkID::UNSPECIFIED) {
119 PingPongMessage* incoming = msg->decapsulate<PingPongMessage> ();
120
121 logging_info("received ping message on link " << lnk.toString()
122 << " from node with id " << (int) incoming->getid());
123}
124
125// timer event
126void PingPong::eventFunction() {
127}
128
129}}} // namespace ariba, application, pingpong
Note: See TracBrowser for help on using the repository browser.