2018-11-12 01:28:46 +01:00
|
|
|
#pragma once
|
|
|
|
|
2019-04-29 04:55:54 +02:00
|
|
|
#include <Kernel/DoubleBuffer.h>
|
2019-01-23 05:13:17 +01:00
|
|
|
#include <Kernel/UnixTypes.h>
|
2019-04-29 04:55:54 +02:00
|
|
|
#include <Kernel/File.h>
|
2018-11-12 01:28:46 +01:00
|
|
|
|
2019-04-29 04:55:54 +02:00
|
|
|
class FileDescriptor;
|
|
|
|
|
|
|
|
class FIFO final : public File {
|
2018-11-12 01:28:46 +01:00
|
|
|
public:
|
2019-05-18 04:14:22 +02:00
|
|
|
enum class Direction : byte {
|
2018-11-12 01:28:46 +01:00
|
|
|
Neither, Reader, Writer
|
|
|
|
};
|
|
|
|
|
2019-04-25 13:52:07 +02:00
|
|
|
static RetainPtr<FIFO> from_fifo_id(dword);
|
|
|
|
|
|
|
|
static Retained<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-04-29 04:55:54 +02:00
|
|
|
Retained<FileDescriptor> 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-04-29 13:58:40 +02:00
|
|
|
virtual ssize_t write(FileDescriptor&, const byte*, ssize_t) override;
|
|
|
|
virtual ssize_t read(FileDescriptor&, byte*, ssize_t) override;
|
|
|
|
virtual bool can_read(FileDescriptor&) const override;
|
|
|
|
virtual bool can_write(FileDescriptor&) const override;
|
2019-05-03 20:42:43 +02:00
|
|
|
virtual String absolute_path(FileDescriptor&) 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
|
|
|
};
|