SPAOP
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Pages
PingControl.h
Go to the documentation of this file.
1 /*
2  * Copyright 2014 Martin Hansen
3  *
4  * This file is part of SPAOP (Spatial Audio Object Positioner).
5  *
6  * SPAOP is free software: you can redistribute it and/or modify
7  * it under the terms of the GNU General Public License as published by
8  * the Free Software Foundation, either version 3 of the License, or
9  * (at your option) any later version.
10  *
11  * SPAOP is distributed in the hope that it will be useful,
12  * but WITHOUT ANY WARRANTY; without even the implied warranty of
13  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14  * GNU General Public License for more details.
15  *
16  * You should have received a copy of the GNU General Public License
17  * along with SPAOP. If not, see <http://www.gnu.org/licenses/>.
18  */
19 
20 #ifndef PINGCONTROL_H_INCLUDED
21 #define PINGCONTROL_H_INCLUDED
22 
23 #include <memory>
24 
25 #include "ConnectionTimer.h"
26 #include "PingControl.h"
27 #include "WonderHeader.h"
28 
29 #define MAX_PINGS_LOST 5
30 
31 namespace wonder {
32 
37 {
38 public:
39 
44  class Listener
45  {
46  public:
47 
49  virtual ~Listener(){}
50 
58  virtual void connectionLost(const int connectionID) = 0;
59  };
60 
74  Listener* listener, const int connectionID,
75  const int maxLost=MAX_PINGS_LOST);
76 
78  virtual ~PingControl();
79 
87  void start();
88 
94  void stop();
95 
101  void onPing();
102 
103 private:
104 
105  PingControl();
106  PingControl(const PingControl& other);
107  PingControl &operator= (const PingControl& other);
108 
109  std::unique_ptr<ConnectionTimer> timer_;
110  Listener* listener_;
111  const int connectionID_;
112  const int maxLost_;
113  int lostCount_;
114 
115 
116  //==============================================================================
117  //vvvvv Implementing ConnectionTimer::Listener
118 
119  void onTimeout();
120 };
121 
122 }
123 
124 #endif // PINGCONTROL_H_INCLUDED
A class for connection timeout control.
Definition: PingControl.h:36
void stop()
Stops the ping control.
Definition: PingControl.cpp:47
#define MAX_PINGS_LOST
Definition: PingControl.h:29
An interface for a factory class that creates ConnectionTimers.
Definition: ConnectionTimer.h:72
A listener that must be notified by the timer on timeout.
Definition: ConnectionTimer.h:37
void start()
Starts the ping control, resetting the lost pings count.
Definition: PingControl.cpp:41
virtual ~Listener()
Destructor.
Definition: PingControl.h:49
void onPing()
Called when an incoming ping is received.
Definition: PingControl.cpp:53
virtual void connectionLost(const int connectionID)=0
Called when more than maxLost pings did not arrive as expected.
A listener class for callbacks in case loss of connection is detected.
Definition: PingControl.h:44
virtual ~PingControl()
Destructor.
Definition: PingControl.cpp:37