task.hpp 2.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120
  1. #ifndef __TASK_HPP__
  2. #define __TASK_HPP__
  3. #include <QQueue>
  4. #include <QString>
  5. #include <memory>
  6. #include <variant>
  7. #include <vector>
  8. namespace Scheduler {
  9. /**
  10. * Files
  11. */
  12. enum FileType { VIDEO = 1, IMAGE = 2 };
  13. /**
  14. * KFileData
  15. *
  16. * Structure for holding file bytes and metadata
  17. */
  18. struct KFileData {
  19. QString name;
  20. FileType type;
  21. QString path;
  22. QByteArray bytes;
  23. };
  24. /**
  25. * Type namespace
  26. *
  27. * Describes the types of task arguments available for use
  28. */
  29. namespace Type {
  30. static constexpr const char* TEXT = "Text";
  31. static constexpr const char* FILE = "File";
  32. static constexpr const char* STRINGVECTOR = "StringVector";
  33. static constexpr const char* FILEVECTOR = "FileVector";
  34. static constexpr const char* DATETIME = "DateTime";
  35. static constexpr const char* BOOLEAN = "Boolean";
  36. } // namespace Type
  37. /**
  38. * Forward Declarations
  39. */
  40. class TaskArgumentBase;
  41. class Task;
  42. /**
  43. * Aliases
  44. */
  45. using ArgumentType = const char*;
  46. using TypeVariant = std::variant<QString, bool, std::vector<std::string>, std::vector<KFileData>>;
  47. using TaskIterator = std::vector<std::unique_ptr<TaskArgumentBase>>::iterator;
  48. using TaskArguments = std::vector<std::unique_ptr<TaskArgumentBase>>;
  49. using TaskQueue = QQueue<Task>;
  50. /**
  51. * The interface expected on our Task Arguments
  52. */
  53. class TaskArgumentBase {
  54. public:
  55. virtual QString text() const = 0;
  56. virtual void setValue(TypeVariant v) = 0;
  57. };
  58. /**
  59. * TaskArgument
  60. *
  61. * A templated class providing a generic way for handling arguments whose types can be one from the set defined
  62. * by our TypeVariant alias
  63. */
  64. template <typename T>
  65. class TaskArgument : TaskArgumentBase {
  66. public:
  67. TaskArgument(QString n, ArgumentType t, T _value) {
  68. name = n;
  69. type = t;
  70. value = _value;
  71. }
  72. /**
  73. * Move Constructor
  74. *
  75. * @constructor
  76. * @param [in] {TaskArgument&&} a The R-value reference to a TaskArgument
  77. */
  78. TaskArgument(TaskArgument&& a) : name(std::move(a.name)), type(std::move(a.type)), value(std::move(a.value)) {}
  79. /**
  80. * text
  81. * @returns {QString} The name of the argument
  82. */
  83. virtual QString text() const { return name; }
  84. /**
  85. * setValue
  86. * @param [in] {TypeVariant} new_value The new value for this argument
  87. */
  88. virtual void setValue(TypeVariant new_value) override { value = new_value; }
  89. private:
  90. QString name;
  91. ArgumentType type;
  92. T value;
  93. };
  94. /**
  95. * The interface expected to be implemented in all Task types
  96. */
  97. class Task {
  98. public:
  99. virtual void defineTaskArguments() = 0;
  100. virtual const TaskArguments getTaskArguments() = 0;
  101. virtual bool isReady() = 0;
  102. virtual void clear() = 0;
  103. virtual ~Task(){};
  104. };
  105. } // namespace Scheduler
  106. #endif // __TASK_HPP__