File indexing completed on 2024-12-08 12:44:37
0001 /* 0002 SPDX-FileCopyrightText: 2014-2015 Daniel Vrátil <dvratil@redhat.com> 0003 SPDX-FileCopyrightText: 2016 Daniel Vrátil <dvratil@kde.org> 0004 SPDX-FileCopyrightText: 2016 Christian Mollekopf <mollekopf@kolabsystems.com> 0005 0006 SPDX-License-Identifier: LGPL-2.0-or-later 0007 */ 0008 0009 #ifndef KASYNC_EXECUTION_P_H_ 0010 #define KASYNC_EXECUTION_P_H_ 0011 0012 #include "kasync_export.h" 0013 0014 #include "debug.h" 0015 0016 #include <QSharedPointer> 0017 #include <QPointer> 0018 #include <QVector> 0019 #include <QObject> 0020 0021 #include <memory> 0022 0023 namespace KAsync { 0024 0025 class FutureBase; 0026 0027 template<typename T> 0028 class Future; 0029 0030 class Tracer; 0031 0032 //@cond PRIVATE 0033 namespace Private 0034 { 0035 0036 class ExecutorBase; 0037 using ExecutorBasePtr = QSharedPointer<ExecutorBase>; 0038 0039 struct Execution; 0040 using ExecutionPtr = QSharedPointer<Execution>; 0041 0042 class ExecutionContext; 0043 0044 enum ExecutionFlag { 0045 Always, 0046 ErrorCase, 0047 GoodCase 0048 }; 0049 0050 struct KASYNC_EXPORT Execution { 0051 explicit Execution(const ExecutorBasePtr &executor) 0052 : executor(executor) 0053 {} 0054 0055 virtual ~Execution() 0056 { 0057 if (resultBase) { 0058 resultBase->releaseExecution(); 0059 delete resultBase; 0060 } 0061 prevExecution.reset(); 0062 } 0063 0064 void setFinished() 0065 { 0066 tracer.reset(); 0067 } 0068 0069 template<typename T> 0070 KAsync::Future<T>* result() const 0071 { 0072 return static_cast<KAsync::Future<T>*>(resultBase); 0073 } 0074 0075 void releaseFuture() 0076 { 0077 resultBase = nullptr; 0078 } 0079 0080 ExecutorBasePtr executor; 0081 ExecutionPtr prevExecution; 0082 std::unique_ptr<Tracer> tracer; 0083 FutureBase *resultBase = nullptr; 0084 }; 0085 0086 class ExecutionContext { 0087 public: 0088 using Ptr = QSharedPointer<ExecutionContext>; 0089 0090 QVector<QPointer<const QObject>> guards; 0091 bool guardIsBroken() const 0092 { 0093 for (const auto &g : guards) { 0094 if (!g) { 0095 return true; 0096 } 0097 } 0098 return false; 0099 } 0100 }; 0101 0102 } // namespace Private 0103 //@endcond 0104 0105 } // namespace KAsync 0106 0107 #endif