source: sample/pingpong/PingPong.cpp@ 2420

Last change on this file since 2420 was 2420, checked in by Christoph Mayer, 16 years ago

-settings an neues format angepasst

File size: 3.0 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 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
125}}} // namespace ariba, application, pingpong
Note: See TracBrowser for help on using the repository browser.