| 1 | #ifndef __PINGPONG_H_
 | 
|---|
 | 2 | #define __PINGPONG_H_
 | 
|---|
 | 3 | 
 | 
|---|
 | 4 | #include "ariba/ariba.h"
 | 
|---|
 | 5 | #include "PingPongMessage.h"
 | 
|---|
 | 6 | #include "ariba/utility/system/StartupInterface.h"
 | 
|---|
 | 7 | #include "ariba/utility/system/Timer.h"
 | 
|---|
 | 8 | 
 | 
|---|
 | 9 | using namespace ariba;
 | 
|---|
 | 10 | using ariba::utility::StartupInterface;
 | 
|---|
 | 11 | using ariba::utility::Timer;
 | 
|---|
 | 12 | 
 | 
|---|
 | 13 | namespace ariba {
 | 
|---|
 | 14 | namespace application {
 | 
|---|
 | 15 | namespace pingpong {
 | 
|---|
 | 16 | 
 | 
|---|
 | 17 | /**
 | 
|---|
 | 18 | /* The PingPong main class
 | 
|---|
 | 19 | /* This class implements an example service for demonstration purposes
 | 
|---|
 | 20 | /* The pingpong class sends and receives messages between two SpoVNet
 | 
|---|
 | 21 | /* instances
 | 
|---|
 | 22 | **/
 | 
|---|
 | 23 | class PingPong :
 | 
|---|
 | 24 |         public NodeListener,
 | 
|---|
 | 25 |         public CommunicationListener,
 | 
|---|
 | 26 |         public StartupInterface,
 | 
|---|
 | 27 |         public Timer {
 | 
|---|
 | 28 | 
 | 
|---|
 | 29 |         use_logging_h(PingPong);
 | 
|---|
 | 30 | 
 | 
|---|
 | 31 | public:
 | 
|---|
 | 32 |         PingPong();
 | 
|---|
 | 33 |         virtual ~PingPong();
 | 
|---|
 | 34 | 
 | 
|---|
 | 35 | protected:
 | 
|---|
 | 36 |         // communication listener interface
 | 
|---|
 | 37 |         virtual bool onLinkRequest(const NodeID& remote, const DataMessage& msg = DataMessage::UNSPECIFIED);
 | 
|---|
 | 38 |         virtual void onMessage(const DataMessage& msg, const NodeID& remote, const LinkID& lnk= LinkID::UNSPECIFIED);
 | 
|---|
 | 39 |         virtual void onLinkUp(const LinkID& lnk, const NodeID& remote);
 | 
|---|
 | 40 |         virtual void onLinkDown(const LinkID& lnk, const NodeID& remote);
 | 
|---|
 | 41 |         virtual void onLinkChanged(const LinkID& lnk, const NodeID& remote);
 | 
|---|
 | 42 |         virtual void onLinkFail(const LinkID& lnk, const NodeID& remote);
 | 
|---|
 | 43 | 
 | 
|---|
 | 44 |         // node listener interface
 | 
|---|
 | 45 |         virtual void onJoinCompleted( const SpoVNetID& vid );
 | 
|---|
 | 46 |         virtual void onJoinFailed( const SpoVNetID& vid );
 | 
|---|
 | 47 |         virtual void onLeaveCompleted( const SpoVNetID& vid );
 | 
|---|
 | 48 |         virtual void onLeaveFailed( const SpoVNetID& vid );
 | 
|---|
 | 49 | 
 | 
|---|
 | 50 |         // startup wrapper interface
 | 
|---|
 | 51 |         virtual void startup();
 | 
|---|
 | 52 |         virtual void shutdown();
 | 
|---|
 | 53 | 
 | 
|---|
 | 54 |         // timer events
 | 
|---|
 | 55 |         virtual void eventFunction();
 | 
|---|
 | 56 | 
 | 
|---|
 | 57 | private:
 | 
|---|
 | 58 |         // the ariba module and a node
 | 
|---|
 | 59 |         AribaModule* ariba;
 | 
|---|
 | 60 |         Node*        node;
 | 
|---|
 | 61 | 
 | 
|---|
 | 62 |         // flag, whether this node initiates or just joins the spovnet
 | 
|---|
 | 63 |         bool isInitiator;
 | 
|---|
 | 64 | 
 | 
|---|
 | 65 |         // the ping pong service id
 | 
|---|
 | 66 |         static ServiceID PINGPONG_SERVICEID;
 | 
|---|
 | 67 | 
 | 
|---|
 | 68 |         // the current ping id
 | 
|---|
 | 69 |         unsigned long pingId;
 | 
|---|
 | 70 | 
 | 
|---|
 | 71 | };
 | 
|---|
 | 72 | 
 | 
|---|
 | 73 | // needed for simulation support
 | 
|---|
 | 74 | ARIBA_SIMULATION_SERVICE(PingPong);
 | 
|---|
 | 75 | 
 | 
|---|
 | 76 | }}} // namespace ariba, application, pingpong
 | 
|---|
 | 77 | 
 | 
|---|
 | 78 | #endif // __PINGPONG_H_
 | 
|---|