2019-01-15 06:30:19 +01:00
|
|
|
#pragma once
|
|
|
|
|
2019-01-30 18:26:19 +01:00
|
|
|
#include <AK/Badge.h>
|
2019-04-03 12:36:40 +02:00
|
|
|
#include <Kernel/Devices/CharacterDevice.h>
|
2019-01-30 18:26:19 +01:00
|
|
|
#include <Kernel/DoubleBuffer.h>
|
2019-01-15 06:30:19 +01:00
|
|
|
|
|
|
|
class SlavePTY;
|
|
|
|
|
|
|
|
class MasterPTY final : public CharacterDevice {
|
|
|
|
public:
|
|
|
|
explicit MasterPTY(unsigned index);
|
|
|
|
virtual ~MasterPTY() override;
|
|
|
|
|
2019-01-16 13:36:10 +01:00
|
|
|
unsigned index() const { return m_index; }
|
2019-01-15 06:30:19 +01:00
|
|
|
String pts_name() const;
|
2019-02-25 21:19:57 +01:00
|
|
|
ssize_t on_slave_write(const byte*, ssize_t);
|
2019-01-25 00:13:54 +01:00
|
|
|
bool can_write_from_slave() const;
|
2019-01-30 18:26:19 +01:00
|
|
|
void notify_slave_closed(Badge<SlavePTY>);
|
2019-02-05 12:27:32 +01:00
|
|
|
bool is_closed() const { return m_closed; }
|
2019-01-15 06:30:19 +01:00
|
|
|
|
|
|
|
private:
|
2019-01-21 02:33:01 +01:00
|
|
|
// ^CharacterDevice
|
2019-06-07 09:36:51 +02:00
|
|
|
virtual ssize_t read(FileDescription&, byte*, ssize_t) override;
|
|
|
|
virtual ssize_t write(FileDescription&, const byte*, ssize_t) override;
|
|
|
|
virtual bool can_read(FileDescription&) const override;
|
|
|
|
virtual bool can_write(FileDescription&) const override;
|
2019-02-05 12:27:32 +01:00
|
|
|
virtual void close() override;
|
|
|
|
virtual bool is_master_pty() const override { return true; }
|
2019-06-07 09:36:51 +02:00
|
|
|
virtual int ioctl(FileDescription&, unsigned request, unsigned arg) override;
|
2019-01-21 02:33:01 +01:00
|
|
|
virtual const char* class_name() const override { return "MasterPTY"; }
|
|
|
|
|
2019-01-30 18:26:19 +01:00
|
|
|
RetainPtr<SlavePTY> m_slave;
|
2019-01-15 06:30:19 +01:00
|
|
|
unsigned m_index;
|
2019-02-05 12:27:32 +01:00
|
|
|
bool m_closed { false };
|
2019-01-15 06:30:19 +01:00
|
|
|
DoubleBuffer m_buffer;
|
2019-04-16 00:35:02 +02:00
|
|
|
String m_pts_name;
|
2019-01-15 06:30:19 +01:00
|
|
|
};
|