UCIEndpoint.h 1.6 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061
  1. /*
  2. * Copyright (c) 2020-2022, the SerenityOS developers.
  3. *
  4. * SPDX-License-Identifier: BSD-2-Clause
  5. */
  6. #pragma once
  7. #include <LibChess/UCICommand.h>
  8. #include <LibCore/IODevice.h>
  9. #include <LibCore/Notifier.h>
  10. #include <LibCore/Object.h>
  11. namespace Chess::UCI {
  12. class Endpoint : public Core::Object {
  13. C_OBJECT(Endpoint)
  14. public:
  15. virtual ~Endpoint() override = default;
  16. virtual void handle_uci() { }
  17. virtual void handle_debug(DebugCommand const&) { }
  18. virtual void handle_isready() { }
  19. virtual void handle_setoption(SetOptionCommand const&) { }
  20. virtual void handle_position(PositionCommand const&) { }
  21. virtual void handle_go(GoCommand const&) { }
  22. virtual void handle_stop() { }
  23. virtual void handle_id(IdCommand const&) { }
  24. virtual void handle_uciok() { }
  25. virtual void handle_readyok() { }
  26. virtual void handle_bestmove(BestMoveCommand const&) { }
  27. virtual void handle_info(InfoCommand const&) { }
  28. void send_command(Command const&);
  29. virtual void event(Core::Event&) override;
  30. Core::IODevice& in() { return *m_in; }
  31. Core::IODevice& out() { return *m_out; }
  32. void set_in(RefPtr<Core::IODevice> in)
  33. {
  34. m_in = in;
  35. set_in_notifier();
  36. }
  37. void set_out(RefPtr<Core::IODevice> out) { m_out = out; }
  38. protected:
  39. Endpoint() = default;
  40. Endpoint(NonnullRefPtr<Core::IODevice> in, NonnullRefPtr<Core::IODevice> out);
  41. private:
  42. void set_in_notifier();
  43. NonnullOwnPtr<Command> read_command();
  44. RefPtr<Core::IODevice> m_in;
  45. RefPtr<Core::IODevice> m_out;
  46. RefPtr<Core::Notifier> m_in_notifier;
  47. };
  48. }