Instrument Neutral Distributed Interface INDI 2.2.5
inditimer.h
Go to the documentation of this file.
1/*
2 Copyright (C) 2021 by Pawel Soja <[email protected]>
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
25namespace INDI
26{
27
28class TimerPrivate;
40class 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;
94};
95
96}
The Timer class provides repetitive and single-shot timers.
Definition inditimer.h:41
int interval() const
Returns the timeout interval in milliseconds.
void setSingleShot(bool singleShot)
Set whether the timer is a single-shot timer.
void callOnTimeout(const std::function< void()> &callback)
Definition inditimer.cpp:76
void start()
Starts or restarts the timer with the timeout specified in interval.
Definition inditimer.cpp:82
static void singleShot(int msec, const std::function< void()> &callback)
This static function calls a the given function after a given time interval.
bool isActive() const
Returns true if the timer is running (pending); otherwise returns false.
int remainingTime() const
Returns the timer's remaining value in milliseconds left until the timeout. If the timer not exists,...
void setInterval(int msec)
Set the timeout interval in milliseconds.
virtual ~Timer()
Definition inditimer.cpp:73
void stop()
Stops the timer.
Definition inditimer.cpp:97
virtual void timeout()
This function is called when the timer times out.
std::unique_ptr< TimerPrivate > d_ptr
Definition inditimer.h:92
bool isSingleShot() const
Returns whether the timer is a single-shot timer.
Namespace to encapsulate INDI client, drivers, and mediator classes.