Changes between Version 26 and Version 27 of Documentation/Tutorial/PingPong


Ignore:
Timestamp:
Apr 28, 2009, 3:53:04 PM (16 years ago)
Author:
huebsch
Comment:

--

Legend:

Unmodified
Added
Removed
Modified
  • Documentation/Tutorial/PingPong

    v26 v27  
    4646}}}
    4747The ''main.cpp'' serves us as an entry point to the application. In the first lines we include class definitions we need here (e.g. strings because we want to handle some). Also, we include the !StartupWrapper class that comes with ''Ariba''. It provides some handy helpers for initialization. Finally, we need to include the ''!PingPong.h'', because this is the actual thing we want to execute.
    48 Then, we declare the used namespaces (lines 05-07) to be able to use the functionalities. Now we get to the main method, being our starting point. After determining the location of our config file, we initialize the system by passing the config file's location to the !StartupWrapper and telling the same to start the architecture up (lines 11-15). Now we are ready to start the ping-pong service, which we first create (line 18). Then we declare the role of the node (initiator or joiner), which is written down in the config file as a bool value. Finally, we start the service up by calling the specific method in the !StartupWrapper. Now the service will run until we press the enter button.
     48Then, we declare the used namespaces (lines 05-07) to be able to use the functionalities. Now we get to the main method, being our starting point. After determining the location of our config file, we initialize the system by passing the config file's location to the !StartupWrapper and telling the same to start the architecture up (lines 15-16). Now we are ready to start the ping-pong service, which we first have to create (line 19). Finally, we start the service up by calling the specific method in the !StartupWrapper. Now the service will run until we press the enter button.
    4949
    5050
     
    5353{{{
    545401 #include "PingPong.h"
    55 02
    56 03 namespace ariba {
    57 04 namespace application {
    58 05 namespace pingpong {
     5502 #include "ariba/utility/configuration/Configuration.h"
     5603
     5704 using ariba::utility::Configuration;
     5805 using namespace ariba;
    595906
    60 07 use_logging_cpp(PingPong);
    61 08 ServiceID PingPong::PINGPONG_ID = ServiceID(111);
    62 09
    63 10 PingPong::PingPong() : pingid( 0 ) {
    64 11 }
    65 12
    66 13 PingPong::~PingPong(){
    67 14 }
    68 15
    69 16 void PingPong::setMode(bool startingNode){
    70 17      startping = startingNode;
    71 18 }
    72 19
    73 20 void PingPong::startup(UnderlayAbstraction* _abstraction){
    74 21      abstraction = _abstraction;
    75 22
    76 23      logging_info( "starting up PingPong service ... " );
    77 24
    78 25      SpoVNetID spovnetid (Identifier(5000));
    79 26
    80 27      NodeID nodeid = (Configuration::instance().exists("BASE_nodeid") ?
    81 28                      NodeID(Identifier(Configuration::instance().read<unsigned long>("BASE_nodeid"))) :
    82 29                      NodeID::UNSPECIFIED);
     6007 namespace ariba {
     6108 namespace application {
     6209 namespace pingpong {
     6310
     6411 // logging
     6512 use_logging_cpp( PingPong );
     6613
     6714 // the service that the pingpong wants to use
     6815 ServiceID PingPong::PINGPONG_SERVICEID = ServiceID( 111 );
     6916
     7017 // construction
     7118 PingPong::PingPong() : pingId( 0 ) {
     7219      Timer::setInterval( 5000 );
     7320 }
     7421
     7522 // destruction
     7623 PingPong::~PingPong() {
     7724 }
     7825
     7926 // implementation of the startup interface
     8027 void PingPong::startup() {
     8128
     8229      logging_info( "starting up PingPong service ... " );
    838330
    84 31      IPv4Locator* locallocator = (Configuration::instance().exists("BASE_localLocator") ?
    85 32                                      &(IPv4Locator::fromString(Configuration::instance().read<string>("BASE_localLocator"))) :
    86 33                                      NULL);
     8431      // create ariba module
     8532      logging_debug( "creating ariba underlay module ... " );
     8633      ariba = new AribaModule();
    878734
    88 35      uint16_t localport = Configuration::instance().exists("BASE_port") ?
    89 36                              Configuration::instance().read<uint16_t>("BASE_port") :
    90 37                              ARIBA_DEFAULT_PORT;
    91 38
    92 39      if( !startping )
    93 40              context = abstraction->createSpoVNet( spovnetid, nodeid, locallocator, localport );
    94 41      else
    95 42              context = abstraction->joinSpoVNet  ( spovnetid, nodeid, locallocator, localport );
     8835      // get the configuration object
     8936      Configuration& config = Configuration::instance();
     9037
     9138      // generate spovnet name
     9239      Name spovnetName("pingpong");
     9340
     9441      // get initiator flag
     9542      this->isInitiator = Configuration::instance().read<bool>("node.initiator");
    969643
    97 44      overlay = &context->getOverlay();
    98 45      overlay->bind( this, PingPong::PINGPONG_ID );
    99 46
    100 47      logging_info( "PingPong started up" );
    101 48
    102 49     
    103 50
    104 51 }
     9744      // get node name
     9845      Name nodeName = Name::UNSPECIFIED;
     9946      if (config.exists("node.name")) nodeName = config.read<string> ("node.name");
     10047
     10148      // configure ariba module
     10249      if (config.exists("ariba.ip.addr")) ariba->setProperty("ip.addr",
     10350                      config.read<string>("ariba.ip.addr"));
     10451      if (config.exists("ariba.tcp.port")) ariba->setProperty("tcp.port",
     10552                      config.read<string>("ariba.tcp.port"));
     10653      if (config.exists("ariba.udp.port")) ariba->setProperty("udp.port",
     10754                      config.read<string>("ariba.udp.port"));
     10855      if (config.exists("ariba.bootstrap.hints")) ariba->setProperty("bootstrap.hints",
     10956                      config.read<string>("ariba.bootstrap.hints"));
     11057
     11158      // start ariba module
     11259      ariba->start();
     11360
     11461      // create node and join
     11562      node = new Node( *ariba, nodeName );
     11663
     11764      // bind communication and node listener
     11865      node->bind( this );                              /*NodeListener*/
     11966      node->bind( this, PingPong::PINGPONG_SERVICEID); /*CommunicationListener*/
     12067
     12168      // start node module
     12269      node->start();
     12370
     12471      // initiate or join the spovnet
     12572      if (!isInitiator) node->join(spovnetName);
     12673      else node->initiate(spovnetName);
     12774
     12875      // ping pong started up...
     12976      logging_info( "pingpong starting up with"
     13077                      << " [spovnetid " << node->getSpoVNetId().toString() << "]"
     13178                      << " and [nodeid " << node->getNodeId().toString() << "]" );
     13279 }
    105133}}}
    106134