2020-01-18 08:38:21 +00:00
|
|
|
/*
|
|
|
|
* Copyright (c) 2018-2020, Andreas Kling <kling@serenityos.org>
|
|
|
|
* All rights reserved.
|
|
|
|
*
|
|
|
|
* Redistribution and use in source and binary forms, with or without
|
|
|
|
* modification, are permitted provided that the following conditions are met:
|
|
|
|
*
|
|
|
|
* 1. Redistributions of source code must retain the above copyright notice, this
|
|
|
|
* list of conditions and the following disclaimer.
|
|
|
|
*
|
|
|
|
* 2. Redistributions in binary form must reproduce the above copyright notice,
|
|
|
|
* this list of conditions and the following disclaimer in the documentation
|
|
|
|
* and/or other materials provided with the distribution.
|
|
|
|
*
|
|
|
|
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
|
|
|
|
* AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
|
|
|
|
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
|
|
|
|
* DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE
|
|
|
|
* FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
|
|
|
|
* DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
|
|
|
|
* SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
|
|
|
|
* CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
|
|
|
|
* OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
|
|
|
|
* OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
|
|
|
*/
|
|
|
|
|
2019-01-15 05:30:19 +00:00
|
|
|
#pragma once
|
|
|
|
|
2019-01-30 17:26:19 +00:00
|
|
|
#include <AK/Badge.h>
|
2019-04-03 10:36:40 +00:00
|
|
|
#include <Kernel/Devices/CharacterDevice.h>
|
2019-01-30 17:26:19 +00:00
|
|
|
#include <Kernel/DoubleBuffer.h>
|
2019-01-15 05:30:19 +00:00
|
|
|
|
2020-02-16 00:27:42 +00:00
|
|
|
namespace Kernel {
|
|
|
|
|
2019-01-15 05:30:19 +00:00
|
|
|
class SlavePTY;
|
|
|
|
|
|
|
|
class MasterPTY final : public CharacterDevice {
|
|
|
|
public:
|
|
|
|
explicit MasterPTY(unsigned index);
|
|
|
|
virtual ~MasterPTY() override;
|
|
|
|
|
2019-01-16 12:36:10 +00:00
|
|
|
unsigned index() const { return m_index; }
|
2019-01-15 05:30:19 +00:00
|
|
|
String pts_name() const;
|
2019-07-03 19:17:35 +00:00
|
|
|
ssize_t on_slave_write(const u8*, ssize_t);
|
2019-01-24 23:13:54 +00:00
|
|
|
bool can_write_from_slave() const;
|
2019-01-30 17:26:19 +00:00
|
|
|
void notify_slave_closed(Badge<SlavePTY>);
|
2019-02-05 11:27:32 +00:00
|
|
|
bool is_closed() const { return m_closed; }
|
2019-01-15 05:30:19 +00:00
|
|
|
|
2019-08-10 16:10:36 +00:00
|
|
|
virtual String absolute_path(const FileDescription&) const override;
|
|
|
|
|
2019-01-15 05:30:19 +00:00
|
|
|
private:
|
2019-01-21 01:33:01 +00:00
|
|
|
// ^CharacterDevice
|
2020-04-10 09:44:42 +00:00
|
|
|
virtual ssize_t read(FileDescription&, size_t, u8*, ssize_t) override;
|
|
|
|
virtual ssize_t write(FileDescription&, size_t, const u8*, ssize_t) override;
|
|
|
|
virtual bool can_read(const FileDescription&, size_t) const override;
|
|
|
|
virtual bool can_write(const FileDescription&, size_t) const override;
|
2019-02-05 11:27:32 +00:00
|
|
|
virtual void close() override;
|
|
|
|
virtual bool is_master_pty() const override { return true; }
|
2020-05-23 11:17:58 +00:00
|
|
|
virtual int ioctl(FileDescription&, unsigned request, FlatPtr arg) override;
|
2019-01-21 01:33:01 +00:00
|
|
|
virtual const char* class_name() const override { return "MasterPTY"; }
|
|
|
|
|
2019-06-21 16:37:47 +00:00
|
|
|
RefPtr<SlavePTY> m_slave;
|
2019-01-15 05:30:19 +00:00
|
|
|
unsigned m_index;
|
2019-02-05 11:27:32 +00:00
|
|
|
bool m_closed { false };
|
2019-01-15 05:30:19 +00:00
|
|
|
DoubleBuffer m_buffer;
|
2019-04-15 22:35:02 +00:00
|
|
|
String m_pts_name;
|
2019-01-15 05:30:19 +00:00
|
|
|
};
|
2020-02-16 00:27:42 +00:00
|
|
|
|
|
|
|
}
|