-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathfifo.hpp
59 lines (42 loc) · 1.14 KB
/
fifo.hpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
#pragma once
#include <array>
#include <cstddef>
#include <cstdint>
#include "communication_handler.hpp"
namespace ipc {
class Fifo : public ICommunicationHandler {
public:
/**
* Create a new Fifo pipe.
*
* @param path Path to the pipe.
* @param readonly Whether the pipe is for read only.
*/
Fifo(std::string path, bool readonly);
/**
* Destructor for this object to cleanup data and close pipe.
*/
~Fifo() override;
bool open() override;
bool close() override;
bool is_open() const override;
bool await_data() override;
bool has_data() const override;
bool write(const IDataObject &obj) override;
std::variant<std::tuple<DataHeader, DataObject>, CommunicationError> read() override;
/**
* Path of the pipe.
*/
const std::string &path() const { return path_; }
/**
* Whether is pipe is targeted for read only.
*/
bool readonly() const { return readonly_; }
private:
const std::string path_;
const bool readonly_;
int fd_ = -1;
std::uint32_t last_id_ = 0;
std::array<std::byte, BUFFER_SIZE> buffer_{};
};
}