Changes between Version 32 and Version 33 of Documentation/Tutorial/PingPong
- Timestamp:
- Feb 4, 2010, 5:57:03 PM (15 years ago)
Legend:
- Unmodified
- Added
- Removed
- Modified
-
Documentation/Tutorial/PingPong
v32 v33 18 18 19 19 {{{ 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 } 46 48 }}} 47 49 The ''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 50 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 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 50 51 51 52 Now 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: … … 92 93 39 Name spovnetName("pingpong"); 93 94 40 94 41 // get initiator flag95 42 this->isInitiator = Configuration::instance().read<bool>("node.initiator");95 41 96 42 96 97 43 97 98 44 // get node name