#ifndef COMMANDDISPATCHER_H
#define COMMANDDISPATCHER_H

#include <QThread>
#include <QVariant>

#include "Task.h"

namespace nemo_interface {

class CommandDispatcher : public QThread {
public:
  CommandDispatcher();

  bool interruptionPoint(); // thread safe

  std::future<QVariant> dispatch(const Task &c);     // thread safe
  std::future<QVariant> dispatchNext(const Task &c); // thread safe
  void clear();                                      // thread safe
  void stop();                                       // thread safe
  bool running();                                    // thread safe

private:
  std::atomic_bool _running;
  std::condition_variable _condVar;
  QList<Task> _queue;
  std::mutex _queueMutex;
};
} // namespace nemo_interface

#endif // COMMANDDISPATCHER_H
