2020-01-18 09:38:21 +01:00
|
|
|
/*
|
2021-08-16 22:13:58 +02:00
|
|
|
* Copyright (c) 2018-2021, Andreas Kling <kling@serenityos.org>
|
2020-01-18 09:38:21 +01:00
|
|
|
*
|
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-04-29 04:55:54 +02:00
|
|
|
#include <Kernel/FileSystem/InodeIdentifier.h>
|
2019-04-03 12:28:45 +02:00
|
|
|
#include <Kernel/TTY/TTY.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 MasterPTY;
|
|
|
|
|
|
|
|
|
|
class SlavePTY final : public TTY {
|
|
|
|
|
public:
|
2021-12-29 14:13:12 +02:00
|
|
|
virtual bool unref() const override;
|
2019-01-15 06:30:19 +01:00
|
|
|
virtual ~SlavePTY() override;
|
|
|
|
|
|
2022-04-01 20:58:27 +03:00
|
|
|
void on_master_write(UserOrKernelBuffer const&, size_t);
|
2019-01-16 13:36:10 +01:00
|
|
|
unsigned index() const { return m_index; }
|
2019-01-15 06:30:19 +01:00
|
|
|
|
2020-09-06 18:48:24 +02:00
|
|
|
time_t time_of_last_write() const { return m_time_of_last_write; }
|
|
|
|
|
|
2021-08-22 15:59:47 +02:00
|
|
|
virtual FileBlockerSet& blocker_set() override;
|
2020-11-29 16:05:27 -07:00
|
|
|
|
2019-01-21 02:33:01 +01:00
|
|
|
private:
|
|
|
|
|
// ^TTY
|
2022-03-26 09:06:30 +03:00
|
|
|
virtual ErrorOr<NonnullOwnPtr<KString>> pseudo_name() const override;
|
2022-04-01 20:58:27 +03:00
|
|
|
virtual ErrorOr<size_t> on_tty_write(UserOrKernelBuffer const&, size_t) override;
|
2019-10-20 19:12:00 +13:00
|
|
|
virtual void echo(u8) override;
|
2019-01-21 02:33:01 +01:00
|
|
|
|
|
|
|
|
// ^CharacterDevice
|
2022-04-01 20:58:27 +03:00
|
|
|
virtual bool can_read(OpenFileDescription const&, u64) const override;
|
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 bool can_write(OpenFileDescription const&, u64) const override;
|
2021-10-02 15:24:00 -07:00
|
|
|
virtual StringView class_name() const override { return "SlavePTY"sv; }
|
2021-11-08 00:51:39 +01:00
|
|
|
virtual ErrorOr<void> close() override;
|
2019-01-15 06:30:19 +01:00
|
|
|
|
2019-01-16 02:11:50 +01:00
|
|
|
friend class MasterPTY;
|
2022-02-15 21:41:41 +02:00
|
|
|
SlavePTY(MasterPTY&, unsigned index);
|
2019-01-16 02:11:50 +01:00
|
|
|
|
2022-08-19 20:53:40 +02:00
|
|
|
LockRefPtr<MasterPTY> m_master;
|
2020-09-06 18:48:24 +02:00
|
|
|
time_t m_time_of_last_write { 0 };
|
|
|
|
|
unsigned m_index { 0 };
|
2021-08-16 22:13:58 +02:00
|
|
|
|
|
|
|
|
mutable IntrusiveListNode<SlavePTY> m_list_node;
|
|
|
|
|
|
|
|
|
|
public:
|
2021-09-09 16:30:59 +04:30
|
|
|
using List = IntrusiveList<&SlavePTY::m_list_node>;
|
2021-08-22 01:37:17 +02:00
|
|
|
static SpinlockProtected<SlavePTY::List>& all_instances();
|
2019-01-15 06:30:19 +01:00
|
|
|
};
|
2020-02-16 01:27:42 +01:00
|
|
|
|
|
|
|
|
}
|