UCIEndpoint.h 1.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960
  1. /*
  2. * Copyright (c) 2020, 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 { }
  16. Endpoint() { }
  17. Endpoint(NonnullRefPtr<Core::IODevice> in, NonnullRefPtr<Core::IODevice> out);
  18. virtual void handle_uci() { }
  19. virtual void handle_debug(const DebugCommand&) { }
  20. virtual void handle_isready() { }
  21. virtual void handle_setoption(const SetOptionCommand&) { }
  22. virtual void handle_position(const PositionCommand&) { }
  23. virtual void handle_go(const GoCommand&) { }
  24. virtual void handle_stop() { }
  25. virtual void handle_id(const IdCommand&) { }
  26. virtual void handle_uciok() { }
  27. virtual void handle_readyok() { }
  28. virtual void handle_bestmove(const BestMoveCommand&) { }
  29. virtual void handle_info(const InfoCommand&) { }
  30. void send_command(const Command&);
  31. virtual void event(Core::Event&);
  32. Core::IODevice& in() { return *m_in; }
  33. Core::IODevice& out() { return *m_out; }
  34. void set_in(RefPtr<Core::IODevice> in)
  35. {
  36. m_in = in;
  37. set_in_notifier();
  38. }
  39. void set_out(RefPtr<Core::IODevice> out) { m_out = out; }
  40. private:
  41. void set_in_notifier();
  42. NonnullOwnPtr<Command> read_command();
  43. RefPtr<Core::IODevice> m_in;
  44. RefPtr<Core::IODevice> m_out;
  45. RefPtr<Core::Notifier> m_in_notifier;
  46. };
  47. }