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