Changes between Version 37 and Version 38 of Documentation/Tutorial/PingPong


Ignore:
Timestamp:
Feb 4, 2010, 6:06:09 PM (15 years ago)
Author:
Christoph Mayer
Comment:

--

Legend:

Unmodified
Added
Removed
Modified
  • Documentation/Tutorial/PingPong

    v37 v38  
    4949}}}
    5050The ''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.
    51 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.
     51Then, we declare the used namespaces (lines 5-7) 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.
    5252
    5353Now 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:
     
    153153}}}
    154154
    155 First we include the .h file, define the namespace, turn logging functionality on (line 12) and set the ID of the Service. Every service using ''Ariba'' is connected to a specific ID that may be chosen initially and arbitrarily. This ID serves ''Ariba'' to distinguish between several services that may use it concurrently.
    156 
    157 After definitions for construction und destruction (the first also setting a timer to 5 seconds), we come to the ''startup'' method.
    158 The ''startup'' method (lines 20 ff.) is called from the !StartupWrapper, jolting the operation of the ping pong service. Here, we first create an AribaModule object, serving as our port to ''Ariba'' (line 33). Then, we give our network instance a specific name (being ''spovnet'' in the example), before we collect some configurational parameters (lines 46-56). Those parameters are defined in the config file, they serve e.g. in giving IP adresses and port numbers to ariba instances. In line 56, we start ''Ariba''. Also, we need a ''Node'' object, reflecting our application running over ''Ariba'' (more than one could possibly be using one Ariba). This is created in line 62 and the bound to the ariba object with its specific ServiceID. After this bnind operation, the ''Node'' is able to receive signals and messages from ''Ariba''. After this, we start the node object and either initiate or join the network instance (depending on the role of the actual node, wich could be initiator or joiner).
    159 Finally, we may give out all kinds of logging infos by calling the method logging_info (line 76).
     155First we include the .h file, define the namespace, turn logging functionality on (line 13) and set the ID of the Service. Every service using ''Ariba'' is connected to a specific ID that may be chosen initially and arbitrarily. This ID serves ''Ariba'' to distinguish between several services that may use it concurrently.
     156
     157After definitions for construction und destruction (the first also setting a timer to 1 second), we come to the ''startup'' method.
     158The ''startup'' method (lines 28 ff.) is called from the !StartupWrapper, jolting the operation of the ping pong service. Here, we first create an AribaModule object, serving as our port to ''Ariba'' (line 34). Then, we give our network instance a specific name (being ''spovnet'' in the example), before we collect some configurational parameters (lines 41-65). Those parameters are defined in the config file, they serve e.g. in giving IP adresses and port numbers to ariba instances. In line 68, we start ''Ariba''. Also, we need a ''Node'' object, reflecting our application running over ''Ariba'' (more than one could possibly be using one Ariba). This is created in line 71 and the bound to the ariba object with its specific ServiceID. After this bind operation, the ''Node'' is able to receive signals and messages from ''Ariba''. After this, we start the node object and either initiate or join the network instance (depending on the role of the actual node, wich could be initiator or joiner).
     159Finally, we may give out all kinds of logging infos by calling the method logging_info (e.g. line 93).
    160160 
    161161
     
    238238}}}
    239239
    240 Everytime the timer 'fires', ''eventFunction'' is called on a node. In this example, every node sends a message to every node that is part of the network at this point in time. To accomplish this, it builds a message (line 15) and iterates through all neighboring nodes (line 20-23). To each of this nodes, it sends the message. Sending messages is simply done by passing the message object to ''Ariba'', together with the target node ID. . We will now take a short look at how such a message is composed in the ping pong example.
     240Everytime the timer 'fires', ''eventFunction'' is called on a node. In this example, every node sends a message to every node that is part of the network at this point in time. To accomplish this, it builds a message (line 138) and iterates through all neighboring nodes (line 156-159). To each of this nodes, it sends the message. Sending messages is simply done by passing the message object to ''Ariba'', together with the target node ID. . We will now take a short look at how such a message is composed in the ping pong example.
    241241
    242242{{{
     
    285285}}}
    286286
    287 Getting back to ''!PingPong.cpp'': After the initiator has send a message to a joiner, it will arrive and has to be handled. This is accomplished in ''receiveMessage'' (the name says it). Every received message has to be decapsulated by a service, casting the data back to the service's message format (line 132).
    288 
     287Getting back to ''!PingPong.cpp'': After the initiator has send a message to a joiner, it will arrive and has to be handled. This is accomplished in ''receiveMessage'' (the name says it). Every received message has to be decapsulated by a service, casting the data back to the service's message format (line 188).
     288