CommandEditor.h 828 B

12345678910111213141516171819202122232425262728293031323334353637
  1. #ifndef COMMANDEDITOR_H
  2. #define COMMANDEDITOR_H
  3. #include <atomic>
  4. #include <thread>
  5. #include <mutex>
  6. #include "common/utils/RingBuffer.h"
  7. #include "common/utils/String.h"
  8. class CommandEditor final {
  9. public:
  10. CommandEditor();
  11. ~CommandEditor();
  12. CommandEditor(const CommandEditor& other) = delete;
  13. CommandEditor& operator=(const CommandEditor& other) = delete;
  14. CommandEditor(CommandEditor&& other) = delete;
  15. CommandEditor& operator=(CommandEditor&& other) = delete;
  16. void preTick() const;
  17. void postTick() const;
  18. bool hasCommand() const;
  19. String readCommand();
  20. private:
  21. static void onLineRead(char* line);
  22. void loop();
  23. static std::mutex queueMutex;
  24. static RingBuffer<String, 5> queue;
  25. std::atomic_bool running;
  26. std::thread readThread;
  27. };
  28. #endif