QGroundControl
Ground Control Station for MAVLink Drones
Loading...
Searching...
No Matches
QtRuntimeScheduler.h
Go to the documentation of this file.
1#pragma once
2
3#include <QtCore/QHash>
4#include <QtCore/QPointer>
5
6#include "RuntimeScheduler.h"
7
10{
11 Q_OBJECT
12public:
13 explicit QtRuntimeScheduler(QObject* parent = nullptr);
14 ~QtRuntimeScheduler() override;
15 quint64 nowUs() const override;
16 TaskId schedule(QObject* context, std::chrono::microseconds delay, Callback callback) override;
17 void cancel(TaskId task) override;
18
19protected:
20 void timerEvent(QTimerEvent* event) override;
21
22private:
23 struct Task
24 {
25 TaskId id = 0;
26 QPointer<QObject> context;
27 Callback callback;
28 QMetaObject::Connection contextDestroyed;
29 };
30
31 TaskId _nextTask = 0;
32 QHash<int, Task> _tasks;
33 QHash<TaskId, int> _timers;
34};
std::function< void()> Task
Qt event-loop implementation; no callback runs inside schedule().
void cancel(TaskId task) override
Cancellation from another thread is ignored. All other access and destruction must occur on the owner...
void timerEvent(QTimerEvent *event) override
TaskId schedule(QObject *context, std::chrono::microseconds delay, Callback callback) override
quint64 nowUs() const override
std::function< void()> Callback