ladybird/Kernel/FileSystem/FIFO.h

45 lines
1.1 KiB
C
Raw Normal View History

#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>
2019-04-29 04:55:54 +02:00
class FileDescriptor;
class FIFO final : public File {
public:
enum class Direction : byte {
Neither, Reader, Writer
};
static RetainPtr<FIFO> from_fifo_id(dword);
static Retained<FIFO> create(uid_t);
2019-04-29 04:55:54 +02:00
virtual ~FIFO() override;
uid_t uid() const { return m_uid; }
2019-04-29 04:55:54 +02:00
Retained<FileDescriptor> open_direction(Direction);
2019-04-29 04:55:54 +02:00
void attach(Direction);
void detach(Direction);
private:
2019-04-29 04:55:54 +02:00
// ^File
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; }
explicit FIFO(uid_t);
unsigned m_writers { 0 };
unsigned m_readers { 0 };
DoubleBuffer m_buffer;
uid_t m_uid { 0 };
};