2020-01-18 09:38:21 +01:00
|
|
|
/*
|
|
|
|
* Copyright (c) 2018-2020, Andreas Kling <kling@serenityos.org>
|
|
|
|
*
|
2021-04-22 01:24:48 -07:00
|
|
|
* SPDX-License-Identifier: BSD-2-Clause
|
2020-01-18 09:38:21 +01:00
|
|
|
*/
|
|
|
|
|
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
|
|
|
|
2020-02-16 01:27:42 +01:00
|
|
|
namespace Kernel {
|
|
|
|
|
2019-01-15 06:30:19 +01:00
|
|
|
class SlavePTY;
|
|
|
|
|
|
|
|
class MasterPTY final : public CharacterDevice {
|
|
|
|
public:
|
2022-08-19 20:53:40 +02:00
|
|
|
static ErrorOr<NonnullLockRefPtr<MasterPTY>> try_create(unsigned index);
|
2019-01-15 06:30:19 +01:00
|
|
|
virtual ~MasterPTY() override;
|
|
|
|
|
2019-01-16 13:36:10 +01:00
|
|
|
unsigned index() const { return m_index; }
|
2022-04-01 20:58:27 +03:00
|
|
|
ErrorOr<size_t> on_slave_write(UserOrKernelBuffer const&, size_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
|
|
|
|
2022-04-01 20:58:27 +03:00
|
|
|
virtual ErrorOr<NonnullOwnPtr<KString>> pseudo_path(OpenFileDescription const&) const override;
|
2019-08-10 19:10:36 +03:00
|
|
|
|
2019-01-15 06:30:19 +01:00
|
|
|
private:
|
2022-02-15 21:41:41 +02:00
|
|
|
explicit MasterPTY(unsigned index, NonnullOwnPtr<DoubleBuffer> buffer);
|
2019-01-21 02:33:01 +01:00
|
|
|
// ^CharacterDevice
|
2021-11-08 00:51:39 +01:00
|
|
|
virtual ErrorOr<size_t> read(OpenFileDescription&, u64, UserOrKernelBuffer&, size_t) override;
|
2022-04-01 20:58:27 +03:00
|
|
|
virtual ErrorOr<size_t> write(OpenFileDescription&, u64, UserOrKernelBuffer const&, size_t) override;
|
|
|
|
virtual bool can_read(OpenFileDescription const&, u64) const override;
|
|
|
|
virtual bool can_write(OpenFileDescription const&, u64) const override;
|
2021-11-08 00:51:39 +01:00
|
|
|
virtual ErrorOr<void> close() override;
|
2019-02-05 12:27:32 +01:00
|
|
|
virtual bool is_master_pty() const override { return true; }
|
2021-11-08 00:51:39 +01:00
|
|
|
virtual ErrorOr<void> ioctl(OpenFileDescription&, unsigned request, Userspace<void*> arg) override;
|
2021-10-02 15:24:00 -07:00
|
|
|
virtual StringView class_name() const override { return "MasterPTY"sv; }
|
2019-01-21 02:33:01 +01:00
|
|
|
|
2022-08-19 20:53:40 +02:00
|
|
|
LockRefPtr<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 };
|
2021-08-01 01:54:09 -07:00
|
|
|
NonnullOwnPtr<DoubleBuffer> m_buffer;
|
2019-01-15 06:30:19 +01:00
|
|
|
};
|
2020-02-16 01:27:42 +01:00
|
|
|
|
|
|
|
}
|