Instrument Neutral Distributed Interface INDI  1.9.2
inditimer.h
Go to the documentation of this file.
1 /*
2  Copyright (C) 2021 by Pawel Soja <kernel32.pl@gmail.com>
3 
4  This library is free software; you can redistribute it and/or
5  modify it under the terms of the GNU Lesser General Public
6  License as published by the Free Software Foundation; either
7  version 2.1 of the License, or (at your option) any later version.
8 
9  This library is distributed in the hope that it will be useful,
10  but WITHOUT ANY WARRANTY; without even the implied warranty of
11  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
12  Lesser General Public License for more details.
13 
14  You should have received a copy of the GNU Lesser General Public
15  License along with this library; if not, write to the Free Software
16  Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
17 */
18 
19 #pragma once
20 
21 #include "indimacros.h"
22 #include <memory>
23 #include <functional>
24 
25 namespace INDI
26 {
27 
28 class TimerPrivate;
40 class Timer
41 {
42  DECLARE_PRIVATE(Timer)
43 
44 public:
45  Timer();
46  virtual ~Timer();
47 
48 public:
50  void start();
51 
53  void start(int msec);
54 
56  void stop();
57 
58 public:
59  void callOnTimeout(const std::function<void()> &callback);
60 
61 public:
63  void setInterval(int msec);
64 
66  void setSingleShot(bool singleShot);
67 
68 public:
70  bool isActive() const;
71 
73  bool isSingleShot() const;
74 
78  int remainingTime() const;
79 
81  int interval() const;
82 
83 public:
85  static void singleShot(int msec, const std::function<void()> &callback);
86 
87 public:
89  virtual void timeout();
90 
91 protected:
92  std::unique_ptr<TimerPrivate> d_ptr;
93  Timer(TimerPrivate &dd);
94 };
95 
96 }
INDI::Timer::isActive
bool isActive() const
Returns true if the timer is running (pending); otherwise returns false.
Definition: inditimer.cpp:111
INDI::Timer::remainingTime
int remainingTime() const
Returns the timer's remaining value in milliseconds left until the timeout. If the timer not exists,...
Definition: inditimer.cpp:123
indimacros.h
INDI::Timer
The Timer class provides repetitive and single-shot timers.
Definition: inditimer.h:40
INDI::Timer::Timer
Timer()
Definition: inditimer.cpp:61
INDI::Timer::start
void start()
Starts or restarts the timer with the timeout specified in interval.
Definition: inditimer.cpp:78
INDI::Timer::setSingleShot
void setSingleShot(bool singleShot)
Set whether the timer is a single-shot timer.
Definition: inditimer.cpp:105
INDI::Timer::setInterval
void setInterval(int msec)
Set the timeout interval in milliseconds.
Definition: inditimer.cpp:99
INDI::Timer::~Timer
virtual ~Timer()
Definition: inditimer.cpp:69
INDI::Timer::isSingleShot
bool isSingleShot() const
Returns whether the timer is a single-shot timer.
Definition: inditimer.cpp:117
INDI::Timer::callOnTimeout
void callOnTimeout(const std::function< void()> &callback)
Definition: inditimer.cpp:72
INDI::Timer::d_ptr
std::unique_ptr< TimerPrivate > d_ptr
Definition: inditimer.h:92
INDI::Timer::stop
void stop()
Stops the timer.
Definition: inditimer.cpp:93
INDI::TimerPrivate
Definition: inditimer_p.h:28
INDI
Namespace to encapsulate INDI client, drivers, and mediator classes.
Definition: AlignmentSubsystemForClients.cpp:11
INDI::Timer::singleShot
static void singleShot(int msec, const std::function< void()> &callback)
This static function calls a the given function after a given time interval.
Definition: inditimer.cpp:142
INDI::Timer::timeout
virtual void timeout()
This function is called when the timer times out.
Definition: inditimer.cpp:135
INDI::Timer::interval
int interval() const
Returns the timeout interval in milliseconds.
Definition: inditimer.cpp:129