#ifndef COMMANDDISPATCHER_H #define COMMANDDISPATCHER_H #include #include #include #include "Task.h" namespace nemo_interface { class TaskDispatcher : QObject { public: TaskDispatcher(); ~TaskDispatcher(); //! //! \brief dispatch Dispatches a task. //! \param c The task to dispatch. //! \return Returns a future containing the QVariant which the task c //! returned. //! std::future dispatch(std::unique_ptr c); //! //! \brief dispatchNext Dispatches the task c as the next task. //! \param c The task to dispatch. //! \return Returns a future containing the QVariant which the task c //! returned. //! std::future dispatchNext(std::unique_ptr c); //! //! \brief clear Clears the task list. //! void clear(); //! //! \brief start Starts task dispatching. This function can be called after //! dispatching has been stopped, e.g. by stop() or reset(). //! void start(); //! //! \brief stop Stops task dispatching. //! //! Stops taks dispatching. The dispatcher will wait for the current task to //! complete and than terminate the dispatcher thread. After stop() has been //! called isInterruptionRequested will return true. This can be used to //! permaturely terminate a task. //! void stop(); //! //! \brief reset Clears the task list and stops dispatching. //! void reset(); bool isInterruptionRequested(); bool isRunning(); std::size_t pendingTasks(); bool idle(); protected: void run(); private: QFuture _future; std::deque> _taskQueue; std::deque> _promiseQueue; bool _running; std::mutex _mutex; }; } // namespace nemo_interface #endif // COMMANDDISPATCHER_H