summaryrefslogtreecommitdiff
path: root/Userland/Libraries/LibChess/UCIEndpoint.h
blob: 430d8edcfcdf4e1c9ea10ed2844521dc86fc61e6 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
/*
 * Copyright (c) 2020, the SerenityOS developers.
 *
 * SPDX-License-Identifier: BSD-2-Clause
 */

#pragma once

#include <LibChess/UCICommand.h>
#include <LibCore/IODevice.h>
#include <LibCore/Notifier.h>
#include <LibCore/Object.h>

namespace Chess::UCI {

class Endpoint : public Core::Object {
    C_OBJECT(Endpoint)
public:
    virtual ~Endpoint() override { }

    virtual void handle_uci() { }
    virtual void handle_debug(const DebugCommand&) { }
    virtual void handle_isready() { }
    virtual void handle_setoption(const SetOptionCommand&) { }
    virtual void handle_position(const PositionCommand&) { }
    virtual void handle_go(const GoCommand&) { }
    virtual void handle_stop() { }
    virtual void handle_id(const IdCommand&) { }
    virtual void handle_uciok() { }
    virtual void handle_readyok() { }
    virtual void handle_bestmove(const BestMoveCommand&) { }
    virtual void handle_info(const InfoCommand&) { }

    void send_command(const Command&);

    virtual void event(Core::Event&) override;

    Core::IODevice& in() { return *m_in; }
    Core::IODevice& out() { return *m_out; }

    void set_in(RefPtr<Core::IODevice> in)
    {
        m_in = in;
        set_in_notifier();
    }
    void set_out(RefPtr<Core::IODevice> out) { m_out = out; }

protected:
    Endpoint() { }
    Endpoint(NonnullRefPtr<Core::IODevice> in, NonnullRefPtr<Core::IODevice> out);

private:
    void set_in_notifier();
    NonnullOwnPtr<Command> read_command();

    RefPtr<Core::IODevice> m_in;
    RefPtr<Core::IODevice> m_out;
    RefPtr<Core::Notifier> m_in_notifier;
};

}