FougTools  0.7.0dev-046fb6a
Handy tools for C++, Qt and OpenCascade
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Pages
manager.h
Go to the documentation of this file.
1 /****************************************************************************
2 ** FougTools
3 ** Copyright Fougue (30 Mar. 2015)
4 ** contact@fougue.pro
5 **
6 ** This software is a computer program whose purpose is to provide utility
7 ** tools for the C++ language and the Qt toolkit.
8 **
9 ** This software is governed by the CeCILL-C license under French law and
10 ** abiding by the rules of distribution of free software. You can use,
11 ** modify and/ or redistribute the software under the terms of the CeCILL-C
12 ** license as circulated by CEA, CNRS and INRIA at the following URL
13 ** "http://www.cecill.info".
14 ****************************************************************************/
15 
16 #pragma once
17 
18 #include "runner_qthread.h"
19 
20 #include <QtCore/QObject>
21 
22 #include <atomic>
23 #include <unordered_map>
24 
25 namespace qttask {
26 
27 class BaseRunner;
28 class Progress;
29 
32 class Manager : public QObject
33 {
34  Q_OBJECT
35 
36 public:
37  Manager(QObject* parent = nullptr);
38  ~Manager();
39 
53  template<typename SELECTOR = QThread, typename ... ARGS>
54  Runner<SELECTOR>* newTask(ARGS ... args)
55  {
56  auto runner = new Runner<SELECTOR>(this, args ...);
57  runner->m_taskId = m_taskIdSeq.fetch_add(1);
58  return runner;
59  }
60 
61  QString taskTitle(quint64 taskId) const;
62  const Progress* taskProgress(quint64 taskId) const;
63 
64  void requestAbort(quint64 taskId);
65 
66  static Manager* globalInstance();
67 
68 signals:
69  void started(quint64 taskId, const QString& title);
70  void progressStep(quint64 taskId, const QString& title);
71  void progress(quint64 taskId, int percent);
72  void message(quint64 taskId, const QString& msg);
73  void ended(quint64 taskId);
74 
75 private:
76  friend class BaseRunnerSignals;
77 
78  void onAboutToRun(BaseRunner* runner);
79  void onDestroyRequest(BaseRunner* runner);
80  BaseRunner* getRunner(quint64 taskId);
81  const BaseRunner* getRunner(quint64 taskId) const;
82 
83  std::atomic<quint64> m_taskIdSeq;
84  std::unordered_map<quint64, BaseRunner*> m_taskIdToRunner;
85 };
86 
87 } // namespace qttask
Base class for all runner objects.
Definition: base_runner.h:31
Definition: base_runner.h:73
void progress(quint64 taskId, int percent)
static Manager * globalInstance()
Definition: manager.cpp:54
void progressStep(quint64 taskId, const QString &title)
~Manager()
Definition: manager.cpp:30
QString taskTitle(quint64 taskId) const
Definition: manager.cpp:33
const Progress * taskProgress(quint64 taskId) const
Definition: manager.cpp:39
void message(quint64 taskId, const QString &msg)
void ended(quint64 taskId)
Runner< SELECTOR > * newTask(ARGS...args)
Create a ready-to-launch Runner object.
Definition: manager.h:54
Provides feedback on the progress of an executing operation.
Definition: progress.h:29
Central class providing management of tasks and notifications.
Definition: manager.h:32
Provides task Qt signals, to be forwarded to the Manager object.
Definition: base_runner_signals.h:30
void started(quint64 taskId, const QString &title)
Definition: base_runner.cpp:20
Manager(QObject *parent=nullptr)
Definition: manager.cpp:24
void requestAbort(quint64 taskId)
Definition: manager.cpp:45