GpgFrontend Project
A Free, Powerful, Easy-to-Use, Compact, Cross-Platform, and Installation-Free OpenPGP(pgp) Crypto Tool.
Task.h
1 
29 #pragma once
30 
31 #include "core/GpgFrontendCore.h"
32 #include "core/function/SecureMemoryAllocator.h"
33 #include "core/model/DataObject.h"
34 
35 namespace GpgFrontend::Thread {
36 
37 class TaskRunner;
38 
39 class GPGFRONTEND_CORE_EXPORT Task : public QObject, public QRunnable {
40  Q_OBJECT
41  public:
42  friend class TaskRunner;
43 
44  using TaskRunnable = std::function<int(DataObjectPtr)>;
45  using TaskCallback = std::function<void(int, DataObjectPtr)>;
46 
47  class TaskHandler {
48  public:
49  explicit TaskHandler(Task*);
50 
51  void Start();
52 
53  void Cancel();
54 
55  auto GetTask() -> Task*;
56 
57  private:
58  QPointer<Task> task_;
59  };
60 
65  explicit Task(QString name);
66 
72  explicit Task(TaskRunnable runnable, QString name,
73  DataObjectPtr data_object = nullptr);
74 
80  explicit Task(TaskRunnable runnable, QString name, DataObjectPtr data,
81  TaskCallback callback);
82 
87  ~Task() override;
88 
94  [[nodiscard]] auto GetUUID() const -> QString;
95 
101  [[nodiscard]] auto GetFullID() const -> QString;
102 
108  void HoldOnLifeCycle(bool hold_on);
109 
115  virtual auto Run() -> int;
116 
122  [[nodiscard]] auto GetRTN();
123 
124  public slots:
125 
130  void SafelyRun();
131 
132  signals:
133 
138  void SignalRun();
139 
144  void SignalTaskShouldEnd(int);
145 
150  void SignalTaskEnd();
151 
152  protected:
158  void setRTN(int rtn);
159 
160  private slots:
161 
166  void slot_exception_safe_run() noexcept;
167 
168  private:
169  class Impl;
170  SecureUniquePtr<Impl> p_;
171 
172  void run() override;
173 };
174 } // namespace GpgFrontend::Thread
Definition: TaskRunner.h:37
Definition: Task.cpp:37
Definition: Task.h:39
~Task() override
Destroy the Task object.
Executive files related to the basic operations of GPG.
Definition: ModuleManager.h:39