mirror of
https://github.com/RGBCube/serenity
synced 2025-05-31 15:48:12 +00:00
Chess: Slightly improve error propagation during startup
This commit is contained in:
parent
0fe29a48ad
commit
449911c286
4 changed files with 14 additions and 15 deletions
|
@ -55,7 +55,7 @@ void Engine::connect_to_engine_service()
|
||||||
close(rpipefds[1]);
|
close(rpipefds[1]);
|
||||||
|
|
||||||
auto infile = Core::File::adopt_fd(rpipefds[0], Core::File::OpenMode::Read).release_value_but_fixme_should_propagate_errors();
|
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();
|
auto outfile = Core::File::adopt_fd(wpipefds[1], Core::File::OpenMode::Write).release_value_but_fixme_should_propagate_errors();
|
||||||
set_out(move(outfile));
|
set_out(move(outfile));
|
||||||
|
|
|
@ -12,14 +12,6 @@
|
||||||
|
|
||||||
namespace Chess::UCI {
|
namespace Chess::UCI {
|
||||||
|
|
||||||
Endpoint::Endpoint(NonnullOwnPtr<Core::File> in, NonnullOwnPtr<Core::File> 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)
|
void Endpoint::send_command(Command const& command)
|
||||||
{
|
{
|
||||||
auto command_string = command.to_string().release_value_but_fixme_should_propagate_errors();
|
auto command_string = command.to_string().release_value_but_fixme_should_propagate_errors();
|
||||||
|
|
|
@ -41,17 +41,17 @@ public:
|
||||||
|
|
||||||
virtual void event(Core::Event&) override;
|
virtual void event(Core::Event&) override;
|
||||||
|
|
||||||
void set_in(NonnullOwnPtr<Core::File> in)
|
ErrorOr<void> set_in(NonnullOwnPtr<Core::File> in)
|
||||||
{
|
{
|
||||||
m_in_fd = in->fd();
|
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();
|
set_in_notifier();
|
||||||
|
return {};
|
||||||
}
|
}
|
||||||
void set_out(NonnullOwnPtr<Core::File> out) { m_out = move(out); }
|
void set_out(NonnullOwnPtr<Core::File> out) { m_out = move(out); }
|
||||||
|
|
||||||
protected:
|
protected:
|
||||||
Endpoint() = default;
|
Endpoint() = default;
|
||||||
Endpoint(NonnullOwnPtr<Core::File> in, NonnullOwnPtr<Core::File> out);
|
|
||||||
virtual void custom_event(Core::CustomEvent&) override;
|
virtual void custom_event(Core::CustomEvent&) override;
|
||||||
|
|
||||||
private:
|
private:
|
||||||
|
|
|
@ -12,8 +12,15 @@
|
||||||
#include <LibChess/UCIEndpoint.h>
|
#include <LibChess/UCIEndpoint.h>
|
||||||
|
|
||||||
class ChessEngine : public Chess::UCI::Endpoint {
|
class ChessEngine : public Chess::UCI::Endpoint {
|
||||||
C_OBJECT(ChessEngine)
|
C_OBJECT_ABSTRACT(ChessEngine)
|
||||||
public:
|
public:
|
||||||
|
static ErrorOr<NonnullRefPtr<ChessEngine>> try_create(NonnullOwnPtr<Core::File> in, NonnullOwnPtr<Core::File> 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 ~ChessEngine() override = default;
|
||||||
|
|
||||||
virtual void handle_uci() override;
|
virtual void handle_uci() override;
|
||||||
|
@ -26,8 +33,8 @@ public:
|
||||||
Function<void(int)> on_quit;
|
Function<void(int)> on_quit;
|
||||||
|
|
||||||
private:
|
private:
|
||||||
ChessEngine(NonnullOwnPtr<Core::File> in, NonnullOwnPtr<Core::File> out)
|
ChessEngine()
|
||||||
: Endpoint(move(in), move(out))
|
: Endpoint()
|
||||||
{
|
{
|
||||||
on_command_read_error = [](auto command, auto error) {
|
on_command_read_error = [](auto command, auto error) {
|
||||||
outln("{}: '{}'", error, command);
|
outln("{}: '{}'", error, command);
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue