2020-01-18 05:38:21 -03:00
|
|
|
/*
|
2021-08-16 17:13:58 -03:00
|
|
|
* Copyright (c) 2018-2021, Andreas Kling <kling@serenityos.org>
|
2020-01-18 05:38:21 -03:00
|
|
|
*
|
2021-04-22 05:24:48 -03:00
|
|
|
* SPDX-License-Identifier: BSD-2-Clause
|
2020-01-18 05:38:21 -03:00
|
|
|
*/
|
|
|
|
|
|
2019-01-15 03:30:19 -02:00
|
|
|
#pragma once
|
|
|
|
|
|
2019-04-28 23:55:54 -03:00
|
|
|
#include <Kernel/FileSystem/InodeIdentifier.h>
|
2019-04-03 07:28:45 -03:00
|
|
|
#include <Kernel/TTY/TTY.h>
|
2019-01-15 03:30:19 -02:00
|
|
|
|
2020-02-15 21:27:42 -03:00
|
|
|
namespace Kernel {
|
|
|
|
|
|
2019-01-15 03:30:19 -02:00
|
|
|
class MasterPTY;
|
|
|
|
|
|
|
|
|
|
class SlavePTY final : public TTY {
|
|
|
|
|
public:
|
2021-08-16 17:13:58 -03:00
|
|
|
virtual bool unref() const override;
|
2019-01-15 03:30:19 -02:00
|
|
|
virtual ~SlavePTY() override;
|
|
|
|
|
|
2021-06-16 10:20:35 -03:00
|
|
|
void on_master_write(const UserOrKernelBuffer&, size_t);
|
2019-01-16 10:36:10 -02:00
|
|
|
unsigned index() const { return m_index; }
|
2019-01-15 03:30:19 -02:00
|
|
|
|
2020-09-06 13:48:24 -03:00
|
|
|
time_t time_of_last_write() const { return m_time_of_last_write; }
|
|
|
|
|
|
2021-08-22 10:59:47 -03:00
|
|
|
virtual FileBlockerSet& blocker_set() override;
|
2020-11-29 20:05:27 -03:00
|
|
|
|
2019-01-20 23:33:01 -02:00
|
|
|
private:
|
|
|
|
|
// ^TTY
|
2021-05-12 17:47:06 -03:00
|
|
|
virtual String const& tty_name() const override;
|
2021-06-16 10:20:35 -03:00
|
|
|
virtual KResultOr<size_t> on_tty_write(const UserOrKernelBuffer&, size_t) override;
|
2019-10-20 03:12:00 -03:00
|
|
|
virtual void echo(u8) override;
|
2019-01-20 23:33:01 -02:00
|
|
|
|
|
|
|
|
// ^CharacterDevice
|
2021-09-07 08:39:11 -03:00
|
|
|
virtual bool can_read(const OpenFileDescription&, size_t) const override;
|
|
|
|
|
virtual KResultOr<size_t> read(OpenFileDescription&, u64, UserOrKernelBuffer&, size_t) override;
|
|
|
|
|
virtual bool can_write(const OpenFileDescription&, size_t) const override;
|
2021-07-10 20:46:09 -03:00
|
|
|
virtual StringView class_name() const override { return "SlavePTY"; }
|
2020-06-02 13:20:05 -03:00
|
|
|
virtual KResult close() override;
|
2019-01-15 03:30:19 -02:00
|
|
|
|
2019-01-15 23:11:50 -02:00
|
|
|
friend class MasterPTY;
|
|
|
|
|
SlavePTY(MasterPTY&, unsigned index);
|
|
|
|
|
|
2019-06-21 13:37:47 -03:00
|
|
|
RefPtr<MasterPTY> m_master;
|
2020-09-06 13:48:24 -03:00
|
|
|
time_t m_time_of_last_write { 0 };
|
|
|
|
|
unsigned m_index { 0 };
|
2021-02-17 12:37:11 -03:00
|
|
|
String m_tty_name;
|
2021-08-16 17:13:58 -03:00
|
|
|
|
|
|
|
|
mutable IntrusiveListNode<SlavePTY> m_list_node;
|
|
|
|
|
|
|
|
|
|
public:
|
2021-09-09 09:00:59 -03:00
|
|
|
using List = IntrusiveList<&SlavePTY::m_list_node>;
|
2021-08-21 20:37:17 -03:00
|
|
|
static SpinlockProtected<SlavePTY::List>& all_instances();
|
2019-01-15 03:30:19 -02:00
|
|
|
};
|
2020-02-15 21:27:42 -03:00
|
|
|
|
|
|
|
|
}
|