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);
|
---|
41 | virtual void onMessage(const DataMessage& msg, const NodeID& remote,
|
---|
42 | const LinkID& lnk = LinkID::UNSPECIFIED);
|
---|
43 | virtual void onLinkUp(const LinkID& lnk, const NodeID& remote);
|
---|
44 | virtual void onLinkDown(const LinkID& lnk, const NodeID& remote);
|
---|
45 | virtual void onLinkChanged(const LinkID& lnk, const NodeID& remote);
|
---|
46 | virtual void onLinkFail(const LinkID& lnk, const NodeID& remote);
|
---|
47 |
|
---|
48 | // node listener interface
|
---|
49 | virtual void onJoinCompleted(const SpoVNetID& vid);
|
---|
50 | virtual void onJoinFailed(const SpoVNetID& vid);
|
---|
51 | virtual void onLeaveCompleted(const SpoVNetID& vid);
|
---|
52 | virtual void onLeaveFailed(const SpoVNetID& vid);
|
---|
53 |
|
---|
54 | // startup wrapper interface
|
---|
55 | virtual void startup();
|
---|
56 | virtual void shutdown();
|
---|
57 |
|
---|
58 | // timer events
|
---|
59 | virtual void eventFunction();
|
---|
60 |
|
---|
61 | private:
|
---|
62 | // the ariba module and a node
|
---|
63 | AribaModule* ariba;
|
---|
64 | Node* node;
|
---|
65 | string name;
|
---|
66 | int counter;
|
---|
67 | vector<string> names;
|
---|
68 |
|
---|
69 | // the ping pong service id
|
---|
70 | static ServiceID PINGPONG_SERVICEID;
|
---|
71 |
|
---|
72 | // the current ping id
|
---|
73 | unsigned long pingId;
|
---|
74 |
|
---|
75 | };
|
---|
76 |
|
---|
77 | // needed for simulation support
|
---|
78 | ARIBA_SIMULATION_SERVICE(PingPong);
|
---|
79 |
|
---|
80 | }}} // namespace ariba, application, pingpong
|
---|
81 |
|
---|
82 | #endif // __PINGPONG_H_
|
---|