summaryrefslogtreecommitdiff
path: root/Kernel/MasterPTY.h
blob: 822764f57a760ae58113469ba23ba4b5029671d0 (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
#pragma once

#include <VirtualFileSystem/CharacterDevice.h>
#include "DoubleBuffer.h"

class SlavePTY;

class MasterPTY final : public CharacterDevice {
public:
    explicit MasterPTY(unsigned index);
    virtual ~MasterPTY() override;
    void set_slave(SlavePTY& slave) { m_slave = &slave; }

    virtual ssize_t read(Process&, byte*, size_t) override;
    virtual ssize_t write(Process&, const byte*, size_t) override;
    virtual bool can_read(Process&) const override;
    virtual bool can_write(Process&) const override;
    virtual bool is_master_pty() const override { return true; }

    String pts_name() const;
    void on_slave_write(const byte*, size_t);

private:
    unsigned m_index;
    SlavePTY* m_slave { nullptr };
    DoubleBuffer m_buffer;
};