0.2.0
Loading...
Searching...
No Matches
CallbackTimer.hpp
Go to the documentation of this file.
1// This file is part of INSTINCT, the INS Toolkit for Integrated
2// Navigation Concepts and Training by the Institute of Navigation of
3// the University of Stuttgart, Germany.
4//
5// This Source Code Form is subject to the terms of the Mozilla Public
6// License, v. 2.0. If a copy of the MPL was not distributed with this
7// file, You can obtain one at https://mozilla.org/MPL/2.0/.
8
13
14#pragma once
15
16#include <functional>
17#include <thread>
18#include <atomic>
19
22{
23 public:
25 CallbackTimer() = default;
27 CallbackTimer(const CallbackTimer&) = delete;
36
38 void stop();
39
44 void start(int interval, const std::function<void(void*)>& func, void* userData);
45
48 void setInterval(int interval);
49
52 [[nodiscard]] bool is_running() const noexcept;
53
54 private:
56 std::atomic<int> _interval{ 0 };
58 std::atomic<bool> _execute{ false };
60 std::thread _thd;
61};
Manages a thread which calls a specified function at a specified interval.
Definition CallbackTimer.hpp:22
~CallbackTimer()
Destructor.
CallbackTimer(CallbackTimer &&)=delete
Move constructor.
void setInterval(int interval)
Set the Interval of the timer.
void start(int interval, const std::function< void(void *)> &func, void *userData)
Starts the timer.
CallbackTimer()=default
Default constructor.
void stop()
Stops the Timer.
CallbackTimer & operator=(const CallbackTimer &)=delete
Copy assignment operator.
CallbackTimer(const CallbackTimer &)=delete
Copy constructor.
bool is_running() const noexcept
Checks if the timer is currently running.
CallbackTimer & operator=(CallbackTimer &&)=delete
Move assignment operator.