diff --git a/Userland/Games/Chess/Engine.cpp b/Userland/Games/Chess/Engine.cpp index b70b83169d3..cfe75024822 100644 --- a/Userland/Games/Chess/Engine.cpp +++ b/Userland/Games/Chess/Engine.cpp @@ -55,7 +55,7 @@ void Engine::connect_to_engine_service() close(rpipefds[1]); auto infile = Core::File::adopt_fd(rpipefds[0], Core::File::OpenMode::Read).release_value_but_fixme_should_propagate_errors(); - set_in(move(infile)); + set_in(move(infile)).release_value_but_fixme_should_propagate_errors(); auto outfile = Core::File::adopt_fd(wpipefds[1], Core::File::OpenMode::Write).release_value_but_fixme_should_propagate_errors(); set_out(move(outfile)); diff --git a/Userland/Libraries/LibChess/UCIEndpoint.cpp b/Userland/Libraries/LibChess/UCIEndpoint.cpp index 52ac7f74fa8..a137124adbc 100644 --- a/Userland/Libraries/LibChess/UCIEndpoint.cpp +++ b/Userland/Libraries/LibChess/UCIEndpoint.cpp @@ -12,14 +12,6 @@ namespace Chess::UCI { -Endpoint::Endpoint(NonnullOwnPtr in, NonnullOwnPtr out) - : m_in_fd(in->fd()) - , m_in(Core::BufferedFile::create(move(in)).release_value_but_fixme_should_propagate_errors()) - , m_out(move(out)) -{ - set_in_notifier(); -} - void Endpoint::send_command(Command const& command) { auto command_string = command.to_string().release_value_but_fixme_should_propagate_errors(); diff --git a/Userland/Libraries/LibChess/UCIEndpoint.h b/Userland/Libraries/LibChess/UCIEndpoint.h index f23bf893857..8c2104162ba 100644 --- a/Userland/Libraries/LibChess/UCIEndpoint.h +++ b/Userland/Libraries/LibChess/UCIEndpoint.h @@ -41,17 +41,17 @@ public: virtual void event(Core::Event&) override; - void set_in(NonnullOwnPtr in) + ErrorOr set_in(NonnullOwnPtr in) { m_in_fd = in->fd(); - m_in = Core::BufferedFile::create(move(in)).release_value_but_fixme_should_propagate_errors(); + m_in = TRY(Core::BufferedFile::create(move(in))); set_in_notifier(); + return {}; } void set_out(NonnullOwnPtr out) { m_out = move(out); } protected: Endpoint() = default; - Endpoint(NonnullOwnPtr in, NonnullOwnPtr out); virtual void custom_event(Core::CustomEvent&) override; private: diff --git a/Userland/Services/ChessEngine/ChessEngine.h b/Userland/Services/ChessEngine/ChessEngine.h index 4a95d47c26e..69c20fae9e3 100644 --- a/Userland/Services/ChessEngine/ChessEngine.h +++ b/Userland/Services/ChessEngine/ChessEngine.h @@ -12,8 +12,15 @@ #include class ChessEngine : public Chess::UCI::Endpoint { - C_OBJECT(ChessEngine) + C_OBJECT_ABSTRACT(ChessEngine) public: + static ErrorOr> try_create(NonnullOwnPtr in, NonnullOwnPtr out) + { + auto engine = TRY(adopt_nonnull_ref_or_enomem(new (nothrow) ChessEngine())); + TRY(engine->set_in(move(in))); + engine->set_out(move(out)); + return engine; + } virtual ~ChessEngine() override = default; virtual void handle_uci() override; @@ -26,8 +33,8 @@ public: Function on_quit; private: - ChessEngine(NonnullOwnPtr in, NonnullOwnPtr out) - : Endpoint(move(in), move(out)) + ChessEngine() + : Endpoint() { on_command_read_error = [](auto command, auto error) { outln("{}: '{}'", error, command);