QGroundControl
Ground Control Station for MAVLink Drones
Loading...
Searching...
No Matches
AsyncFunctionState.h
Go to the documentation of this file.
1#pragma once
2
3#include "WaitStateBase.h"
4
5#include <functional>
6
15{
16 Q_OBJECT
17 Q_DISABLE_COPY(AsyncFunctionState)
18
19public:
20 using SetupFunction = std::function<void(AsyncFunctionState* state)>;
21
27 AsyncFunctionState(const QString& stateName, QState* parent, SetupFunction setupFunction, int timeoutMsecs = 0);
28
30 void complete() { waitComplete(); }
31
33 void fail() { waitFailed(); }
34
38 template<typename Func>
39 void connectToCompletion(typename QtPrivate::FunctionPointer<Func>::Object* sender, Func signal)
40 {
41 _completionConnection = connect(sender, signal, this, [this]() {
42 complete();
43 });
44 }
45
48 template<typename Func, typename Slot>
49 void connectToCompletion(typename QtPrivate::FunctionPointer<Func>::Object* sender, Func signal, Slot slot)
50 {
51 _completionConnection = connect(sender, signal, this, slot);
52 }
53
54protected:
55 void connectWaitSignal() override;
56 void disconnectWaitSignal() override;
57 void onWaitEntered() override;
58
59private:
60 SetupFunction _setupFunction;
61 QMetaObject::Connection _completionConnection;
62};
void connectToCompletion(typename QtPrivate::FunctionPointer< Func >::Object *sender, Func signal)
void complete()
Call this to signal that the async operation has completed successfully.
void connectWaitSignal() override
Subclasses override to set up their signal connections.
void disconnectWaitSignal() override
Subclasses override to tear down their signal connections.
void onWaitEntered() override
Called when the state is entered - subclasses should call base implementation.
void fail()
Call this to signal that the async operation has failed.
void connectToCompletion(typename QtPrivate::FunctionPointer< Func >::Object *sender, Func signal, Slot slot)
std::function< void(AsyncFunctionState *state)> SetupFunction
QString stateName() const
int timeoutMsecs() const