2020-01-18 11:38:21 +03:00
|
|
|
/*
|
|
|
|
* Copyright (c) 2018-2020, Andreas Kling <kling@serenityos.org>
|
|
|
|
*
|
2021-04-22 11:24:48 +03:00
|
|
|
* SPDX-License-Identifier: BSD-2-Clause
|
2020-01-18 11:38:21 +03:00
|
|
|
*/
|
|
|
|
|
2019-01-16 15:36:10 +03:00
|
|
|
#pragma once
|
|
|
|
|
2019-01-30 20:26:19 +03:00
|
|
|
#include <AK/Badge.h>
|
2019-05-28 12:53:16 +03:00
|
|
|
#include <Kernel/Devices/CharacterDevice.h>
|
2021-07-17 22:09:51 +03:00
|
|
|
#include <Kernel/Mutex.h>
|
2019-01-16 15:36:10 +03:00
|
|
|
|
2020-02-16 03:27:42 +03:00
|
|
|
namespace Kernel {
|
|
|
|
|
2019-01-16 15:36:10 +03:00
|
|
|
class MasterPTY;
|
|
|
|
|
|
|
|
class PTYMultiplexer final : public CharacterDevice {
|
|
|
|
AK_MAKE_ETERNAL
|
|
|
|
public:
|
|
|
|
PTYMultiplexer();
|
|
|
|
virtual ~PTYMultiplexer() override;
|
|
|
|
|
2020-08-25 04:35:19 +03:00
|
|
|
static void initialize()
|
|
|
|
{
|
|
|
|
the();
|
|
|
|
}
|
2019-01-30 20:26:19 +03:00
|
|
|
static PTYMultiplexer& the();
|
|
|
|
|
2019-01-16 15:36:10 +03:00
|
|
|
// ^CharacterDevice
|
2019-06-21 19:37:47 +03:00
|
|
|
virtual KResultOr<NonnullRefPtr<FileDescription>> open(int options) override;
|
2021-03-17 15:18:51 +03:00
|
|
|
virtual KResultOr<size_t> read(FileDescription&, u64, UserOrKernelBuffer&, size_t) override { return 0; }
|
|
|
|
virtual KResultOr<size_t> write(FileDescription&, u64, const UserOrKernelBuffer&, size_t) override { return 0; }
|
2020-04-10 12:44:42 +03:00
|
|
|
virtual bool can_read(const FileDescription&, size_t) const override { return true; }
|
|
|
|
virtual bool can_write(const FileDescription&, size_t) const override { return true; }
|
2019-01-16 15:36:10 +03:00
|
|
|
|
2019-01-30 20:26:19 +03:00
|
|
|
void notify_master_destroyed(Badge<MasterPTY>, unsigned index);
|
|
|
|
|
2020-12-25 20:01:19 +03:00
|
|
|
// ^Device
|
|
|
|
virtual mode_t required_mode() const override { return 0666; }
|
2021-01-21 20:49:56 +03:00
|
|
|
virtual String device_name() const override { return "ptmx"; }
|
2020-12-25 20:01:19 +03:00
|
|
|
|
2019-01-16 15:36:10 +03:00
|
|
|
private:
|
2019-01-21 04:33:01 +03:00
|
|
|
// ^CharacterDevice
|
2021-07-11 02:46:09 +03:00
|
|
|
virtual StringView class_name() const override { return "PTYMultiplexer"; }
|
2019-01-21 04:33:01 +03:00
|
|
|
|
2021-07-17 22:09:51 +03:00
|
|
|
Mutex m_lock { "PTYMultiplexer" };
|
2019-01-30 02:49:20 +03:00
|
|
|
Vector<unsigned> m_freelist;
|
2019-01-16 15:36:10 +03:00
|
|
|
};
|
2020-02-16 03:27:42 +03:00
|
|
|
|
|
|
|
}
|