QGroundControl
Ground Control Station for MAVLink Drones
Loading...
Searching...
No Matches
RuntimeScheduler.h
Go to the documentation of this file.
1#pragma once
2
3#include <QtCore/QObject>
4
5#include <chrono>
6#include <functional>
7
11class RuntimeScheduler : public QObject
12{
13 Q_OBJECT
14public:
15 using TaskId = quint64;
16 using Callback = std::function<void()>;
17 static constexpr auto MAX_DELAY =
18 std::chrono::duration_cast<std::chrono::microseconds>((std::chrono::nanoseconds::max) ());
19
20 explicit RuntimeScheduler(QObject* parent = nullptr);
21 ~RuntimeScheduler() override;
22
24 [[nodiscard]] static RuntimeScheduler* orDefault(RuntimeScheduler* scheduler, QObject* owner);
25
26 virtual quint64 nowUs() const = 0;
27
28 qint64 nowMs() const { return static_cast<qint64>(nowUs() / 1000); }
29
33 virtual TaskId schedule(QObject* context, std::chrono::microseconds delay, Callback callback) = 0;
35 virtual void cancel(TaskId task) = 0;
36
37protected:
38 bool _canSchedule(QObject* context, std::chrono::microseconds delay, const Callback& callback) const;
39 bool _isCurrentThread() const;
40};
~RuntimeScheduler() override
bool _canSchedule(QObject *context, std::chrono::microseconds delay, const Callback &callback) const
static constexpr auto MAX_DELAY
bool _isCurrentThread() const
virtual quint64 nowUs() const =0
qint64 nowMs() const
std::function< void()> Callback
virtual TaskId schedule(QObject *context, std::chrono::microseconds delay, Callback callback)=0
static RuntimeScheduler * orDefault(RuntimeScheduler *scheduler, QObject *owner)
scheduler, or a QtRuntimeScheduler owned by owner when it is null.
virtual void cancel(TaskId task)=0
Cancellation from another thread is ignored. All other access and destruction must occur on the owner...