2018-11-12 01:28:46 +01:00
|
|
|
#pragma once
|
|
|
|
|
2019-04-29 04:55:54 +02:00
|
|
|
#include <Kernel/DoubleBuffer.h>
|
2019-07-09 14:46:23 +02:00
|
|
|
#include <Kernel/FileSystem/File.h>
|
2019-05-28 11:53:16 +02:00
|
|
|
#include <Kernel/UnixTypes.h>
|
2018-11-12 01:28:46 +01:00
|
|
|
|
2019-06-07 09:36:51 +02:00
|
|
|
class FileDescription;
|
2019-04-29 04:55:54 +02:00
|
|
|
|
|
|
|
class FIFO final : public File {
|
2018-11-12 01:28:46 +01:00
|
|
|
public:
|
2019-07-03 21:17:35 +02:00
|
|
|
enum class Direction : u8 {
|
2019-05-28 11:53:16 +02:00
|
|
|
Neither,
|
|
|
|
Reader,
|
|
|
|
Writer
|
2018-11-12 01:28:46 +01:00
|
|
|
};
|
|
|
|
|
2019-07-03 21:17:35 +02:00
|
|
|
static RefPtr<FIFO> from_fifo_id(u32);
|
2019-04-25 13:52:07 +02:00
|
|
|
|
2019-06-21 18:37:47 +02:00
|
|
|
static NonnullRefPtr<FIFO> create(uid_t);
|
2019-04-29 04:55:54 +02:00
|
|
|
virtual ~FIFO() override;
|
2019-04-25 13:52:07 +02:00
|
|
|
|
|
|
|
uid_t uid() const { return m_uid; }
|
2018-11-12 01:28:46 +01:00
|
|
|
|
2019-06-21 18:37:47 +02:00
|
|
|
NonnullRefPtr<FileDescription> open_direction(Direction);
|
2018-11-12 01:28:46 +01:00
|
|
|
|
2019-04-29 04:55:54 +02:00
|
|
|
void attach(Direction);
|
|
|
|
void detach(Direction);
|
2018-11-12 01:28:46 +01:00
|
|
|
|
|
|
|
private:
|
2019-04-29 04:55:54 +02:00
|
|
|
// ^File
|
2019-07-03 21:17:35 +02:00
|
|
|
virtual ssize_t write(FileDescription&, const u8*, ssize_t) override;
|
|
|
|
virtual ssize_t read(FileDescription&, u8*, ssize_t) override;
|
2019-06-07 09:36:51 +02:00
|
|
|
virtual bool can_read(FileDescription&) const override;
|
|
|
|
virtual bool can_write(FileDescription&) const override;
|
|
|
|
virtual String absolute_path(const FileDescription&) const override;
|
2019-04-29 04:55:54 +02:00
|
|
|
virtual const char* class_name() const override { return "FIFO"; }
|
|
|
|
virtual bool is_fifo() const override { return true; }
|
|
|
|
|
2019-04-25 13:52:07 +02:00
|
|
|
explicit FIFO(uid_t);
|
2018-11-12 01:28:46 +01:00
|
|
|
|
|
|
|
unsigned m_writers { 0 };
|
|
|
|
unsigned m_readers { 0 };
|
2018-12-03 02:24:11 +01:00
|
|
|
DoubleBuffer m_buffer;
|
2019-04-25 13:52:07 +02:00
|
|
|
|
|
|
|
uid_t m_uid { 0 };
|
2018-11-12 01:28:46 +01:00
|
|
|
};
|