#include "PingPong.h" #include "ariba/utility/configuration/Configuration.h" using ariba::utility::Configuration; using namespace ariba; namespace ariba { namespace application { namespace pingpong { // logging use_logging_cpp( PingPong); // the service id of the ping pong service ServiceID PingPong::PINGPONG_ID = ServiceID(111); // construction PingPong::PingPong() : pingId( 0 ) { } // destruction PingPong::~PingPong() { } // implementation of the startup interface void PingPong::startup() { // create ariba module logging_info("Creating ariba underlay module ... "); ariba = new AribaModule(); logging_info("Starting up PingPong service ... "); // --- get config --- Configuration& config = Configuration::instance(); // generate spovnet name Name spovnetName("pingpong"); // get initiator flag this->isInitiator = Configuration::instance().read ("node.initiator"); // get node name Name nodeName = Name::UNSPECIFIED; if (config.exists("node.name")) nodeName = config.read ("node.name"); // configure ariba module if (config.exists("ariba.ip.addr")) ariba->setProperty("ip.addr", config.read ("ariba.ip.addr")); if (config.exists("ariba.tcp.port")) ariba->setProperty("tcp.port", config.read ("ariba.tcp.port")); if (config.exists("ariba.udp.port")) ariba->setProperty("udp.port", config.read ("ariba.udp.port")); if (config.exists("ariba.bootstrap.hints")) ariba->setProperty("bootstrap.hints", config.read ("ariba.bootstrap.hints")); // start ariba module ariba->start(); // create node and join node = new Node(*ariba, nodeName); // start node module node->start(); if (!isInitiator) { node->join(spovnetName); } else { node->initiate(spovnetName); } // bind communication and node listener node->bind(this); node->bind(this, PingPong::PINGPONG_ID); // ping pong started up... logging_info("PingPong started up"); } // implementation of the startup interface void PingPong::shutdown() { logging_info("PingPong service starting shutdown sequence ..."); // stop timer Timer::stop(); // leave spovnet node->leave(); // unbind listeners node->unbind( this ); node->unbind( this, PingPong::PINGPONG_ID ); logging_info("PingPong service shut down!"); } // node listener interface void PingPong::onJoinCompleted( const SpoVNetID& vid ) { logging_info("PingPong node join completed, spovnetid=" << vid.toString() ); } void PingPong::onJoinFailed( const SpoVNetID& vid ) { logging_info("PingPong node join failed, spovnetid=" << vid.toString() ); } // communication listener bool PingPong::onLinkRequest(const NodeID& remote, Message* msg) { return false; } void PingPong::onMessage(Message* msg, const NodeID& remote, const LinkID& lnk = LinkID::UNSPECIFIED) { PingPongMessage* incoming = msg->decapsulate (); logging_info("received ping message on link " << lnk.toString() << " from node with id " << (int) incoming->getid()); } // timer event void PingPong::eventFunction() { } }}} // namespace ariba, application, pingpong