close Warning: Can't use blame annotator:
No changeset 2312 in the repository

source: sample/tidy_pingpong/TidyPingPong.cpp@ 2392

Last change on this file since 2392 was 2392, checked in by mies, 16 years ago
File size: 3.4 KB
RevLine 
1
2#include "TidyPingPong.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 logging_info("PingPong service shut down!");
97}
98
99// node listener interface
100void PingPong::onJoinCompleted( const SpoVNetID& vid ) {
101 logging_info("PingPong node join completed, spovnetid=" << vid.toString() );
102}
103
104void PingPong::onJoinFailed( const SpoVNetID& vid ) {
105 logging_info("PingPong node join failed, spovnetid=" << vid.toString() );
106}
107
108// communication listener
109bool PingPong::onLinkRequest(const NodeID& remote, Message* msg) {
110 return false;
111}
112
113void PingPong::onMessage(Message* msg, const NodeID& remote, const LinkID& lnk =
114 LinkID::UNSPECIFIED) {
115 PingPongMessage* incoming = msg->decapsulate<PingPongMessage> ();
116
117 logging_info("received ping message on link " << lnk.toString()
118 << " from node with id " << (int) incoming->getid());
119}
120
121// timer event
122void PingPong::eventFunction() {
123
124 logging_info("pinging our remote nodes");
125// RemoteNodes::iterator i = remoteNodes.begin();
126// RemoteNodes::iterator iend = remoteNodes.end();
127//
128// pingid++;
129//
130// for (; i != iend; i++) {
131// logging_info(" -> pinging " << i->first);
132//
133// PingPongMessage pingmsg(pingid);
134// overlay->sendMessage(&pingmsg, i->second);
135// }
136}
137
138}}} // namespace ariba, application, pingpong
Note: See TracBrowser for help on using the repository browser.