Changes between Version 32 and Version 33 of Documentation/Tutorial/PingPong


Ignore:
Timestamp:
Feb 4, 2010, 5:57:03 PM (15 years ago)
Author:
Christoph Mayer
Comment:

--

Legend:

Unmodified
Added
Removed
Modified
  • Documentation/Tutorial/PingPong

    v32 v33  
    1818
    1919{{{
    20 01 #include <string>
    21 02 #include "ariba/utility/system/StartupWrapper.h"
    22 03 #include "PingPong.h"
    23 04
    24 05 using std::string;
    25 06 using ariba::utility::StartupWrapper;
    26 07 using ariba::application::pingpong::PingPong;
    27 08
    28 09 int main( int argc, char** argv ) {
    29 10
    30 11      // get config file
    31 12      string config = "../etc/settings.cnf";
    32 13      if (argc >= 2) config = argv[1];
    33 14
    34 15      StartupWrapper::initConfig( config );
    35 16      StartupWrapper::initSystem();
    36 17
    37 18      // this will do the main functionality and block
    38 19      PingPong ping;
    39 20      StartupWrapper::startup(&ping, true);
    40 21
    41 22      // --> we will run blocking until <enter> is hit
    42 23
    43 24      StartupWrapper::shutdown(&ping);
    44 25      return 0;
    45 26}
     20     1  #include <string>
     21     2  #include "ariba/utility/system/StartupWrapper.h"
     22     3  #include "PingPong.h"
     23     4 
     24     5  using std::string;
     25     6  using ariba::utility::StartupWrapper;
     26     7  using ariba::application::pingpong::PingPong;
     27     8 
     28     9  int main( int argc, char** argv ) {
     29    10 
     30    11          // get config file
     31    12          string config = "../etc/settings.cnf";
     32    13          if (argc >= 2) config = argv[1];
     33    14 
     34    15          StartupWrapper::initConfig( config );
     35    16          StartupWrapper::startSystem();
     36    17 
     37    18          // this will do the main functionality and block
     38    19          PingPong ping;
     39    20          StartupWrapper::startup(&ping);
     40    21 
     41    22          // --> we will run blocking until <enter> is hit
     42    23 
     43    24          StartupWrapper::shutdown(&ping);
     44    25          StartupWrapper::stopSystem();
     45    26 
     46    27          return 0;
     47    28  }
    4648}}}
    4749The ''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.
    4850Then, 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.
    49 
    5051
    5152Now we look into the ''!PingPong.cpp'', containing the actual ping pong code. We leave out .h files here because they only do definitions. Everyone intending to use ''Ariba'' should be familiar with the subject matter. The first parts look like this:
     
    929339      Name spovnetName("pingpong");
    939440
    94 41      // get initiator flag
    95 42      this->isInitiator = Configuration::instance().read<bool>("node.initiator");
     9541     
     9642     
    969743
    979844      // get node name