use line digestion recognition in PingScheduler;
[pingcheck] / src / host / pinginterval.cpp
CommitLineData
91fcc471
TJ
1/*
2The software in this package is distributed under the GNU General
3Public License version 2 (with a special exception described below).
4
5A copy of GNU General Public License (GPL) is included in this distribution,
6in the file COPYING.GPL.
7
8As a special exception, if other files instantiate templates or use macros
9or inline functions from this file, or you compile this file and link it
10with other works to produce a work based on this file, this file
11does not by itself cause the resulting work to be covered
12by the GNU General Public License.
13
14However the source code for this file must still be made available
15in accordance with section (3) of the GNU General Public License.
16
17This exception does not invalidate any other reasons why a work based
18on this file might be covered by the GNU General Public License.
19*/
f4fc8957
GMF
20#include "host/pinginterval.h"
21
780b0bca 22#include "boost_assert_handler.h"
f4fc8957
GMF
23
24//-----------------------------------------------------------------------------
25// PingInterval
26//-----------------------------------------------------------------------------
27
28PingInterval::PingInterval(
29 PingIntervalType interval
30) :
31 OriginalInterval( interval ),
32 Interval( interval )
33{
34 BOOST_ASSERT( 0 < interval );
35}
36
37PingInterval::~PingInterval()
38{
39}
40
6fd0993e 41PingInterval::operator PingIntervalType() const
f4fc8957
GMF
42{
43 BOOST_ASSERT( 0 < Interval );
44
45 return Interval;
46}
47
48void PingInterval::back_to_original()
49{
50 Interval = OriginalInterval;
51
52 BOOST_ASSERT( 0 < Interval );
53}
54
55void PingInterval::speed_up()
56{
57 BOOST_ASSERT( 0 < Interval );
58
59 if ( can_speed_up() )
60 {
61 Interval = Interval / 2;
62 }
63
64 if ( Interval < 1 )
65 {
66 Interval = 1;
67 }
68
69 BOOST_ASSERT( 0 < Interval );
70}
71
242e5fb3 72/** returns true if have not speeded up yet */
f4fc8957
GMF
73bool PingInterval::can_speed_up() const
74{
242e5fb3 75 return Interval == OriginalInterval;
f4fc8957 76}