2019-01-15 05:30:19 +00:00
|
|
|
#pragma once
|
|
|
|
|
2019-01-30 17:26:19 +00:00
|
|
|
#include <AK/Badge.h>
|
2019-01-23 04:13:17 +00:00
|
|
|
#include <Kernel/CharacterDevice.h>
|
2019-01-30 17:26:19 +00:00
|
|
|
#include <Kernel/DoubleBuffer.h>
|
2019-01-15 05:30:19 +00:00
|
|
|
|
|
|
|
class SlavePTY;
|
|
|
|
|
|
|
|
class MasterPTY final : public CharacterDevice {
|
|
|
|
public:
|
|
|
|
explicit MasterPTY(unsigned index);
|
|
|
|
virtual ~MasterPTY() override;
|
|
|
|
|
2019-01-16 12:36:10 +00:00
|
|
|
unsigned index() const { return m_index; }
|
2019-01-15 05:30:19 +00:00
|
|
|
String pts_name() const;
|
2019-02-05 12:09:01 +00:00
|
|
|
ssize_t on_slave_write(const byte*, size_t);
|
2019-01-24 23:13:54 +00:00
|
|
|
bool can_write_from_slave() const;
|
2019-01-30 17:26:19 +00:00
|
|
|
void notify_slave_closed(Badge<SlavePTY>);
|
2019-02-05 11:27:32 +00:00
|
|
|
bool is_closed() const { return m_closed; }
|
2019-01-15 05:30:19 +00:00
|
|
|
|
|
|
|
private:
|
2019-01-21 01:33:01 +00:00
|
|
|
// ^CharacterDevice
|
2019-02-05 11:27:32 +00:00
|
|
|
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 void close() override;
|
|
|
|
virtual bool is_master_pty() const override { return true; }
|
2019-02-20 22:32:33 +00:00
|
|
|
virtual int ioctl(Process&, unsigned request, unsigned arg) override;
|
2019-01-21 01:33:01 +00:00
|
|
|
virtual const char* class_name() const override { return "MasterPTY"; }
|
|
|
|
|
2019-01-30 17:26:19 +00:00
|
|
|
RetainPtr<SlavePTY> m_slave;
|
2019-01-15 05:30:19 +00:00
|
|
|
unsigned m_index;
|
2019-02-05 11:27:32 +00:00
|
|
|
bool m_closed { false };
|
2019-01-15 05:30:19 +00:00
|
|
|
DoubleBuffer m_buffer;
|
|
|
|
};
|