25 #include <alchemy/pipe.h> 28 #include <sys/eventfd.h> 35 "/proc/xenomai/registry/rtipc/xddp/";
50 int64_t
read(
void* buf,
size_t buf_size)
override;
51 int64_t
write(
void* buf,
size_t buf_size)
override;
52 int64_t
readRT(
void* buf,
size_t buf_size)
override;
53 int64_t
writeRT(
void* buf,
size_t buf_size)
override;
55 void close()
override;
61 std::string pipe_name;
65 RT_PIPE pipe_handle {};
67 std::array<struct pollfd, 2> xbuf_poll_fd {};
72 : pipe_name(std::string(
"RTXI-pipe-") + std::to_string(
FIFO_COUNT++))
75 pipe_number = rt_pipe_create(
76 &this->pipe_handle, pipe_name.c_str(), P_MINOR_AUTO, fifo_capacity);
77 if (pipe_number < 0) {
78 ERROR_MSG(
"Unable to open real-time X pipe");
81 this->fd = ::open(filename.c_str(), O_RDWR | O_NONBLOCK);
83 this->xbuf_poll_fd[0].fd = this->fd;
84 this->xbuf_poll_fd[0].events = POLLIN;
85 this->close_event_fd = eventfd(0, EFD_NONBLOCK);
86 this->xbuf_poll_fd[1].fd = this->close_event_fd;
87 this->xbuf_poll_fd[1].events = POLLIN;
92 if (::close(this->fd) != 0) {
93 ERROR_MSG(
"Unable to close non-realtime side of X pipe");
95 if (rt_pipe_delete(&this->pipe_handle) < 0) {
96 ERROR_MSG(
"Unable to close real-time side of X pipe");
103 return ::read(this->fd, buf, buf_size);
109 return ::write(this->fd, buf, buf_size);
114 return rt_pipe_read(&this->pipe_handle, buf, buf_size, TM_NONBLOCK);
119 return rt_pipe_write(&this->pipe_handle, buf, buf_size, P_NORMAL);
124 int errcode = ::poll(this->xbuf_poll_fd.data(), 2, -1);
126 ERROR_MSG(
"RT::OS::FIFO(evl)::poll : returned with failure code {} : ",
129 }
else if ((this->xbuf_poll_fd[1].revents & POLLIN) != 0) {
141 std::array<int64_t, 1> buf {};
143 ::write(this->close_event_fd, buf.data(),
sizeof(int64_t));
148 return this->fifo_capacity;
153 auto tmp_fifo = std::make_unique<RT::OS::xenomaiFifo>(fifo_size);
154 fifo = std::move(tmp_fifo);
xenomaiFifo(const xenomaiFifo &fifo)=delete
int64_t read(void *buf, size_t buf_size) override
int64_t writeRT(void *buf, size_t buf_size) override
size_t getCapacity() override
xenomaiFifo(xenomaiFifo &&)=default
xenomaiFifo & operator=(const xenomaiFifo &fifo)=delete
int64_t write(void *buf, size_t buf_size) override
xenomaiFifo & operator=(xenomaiFifo &&)=default
int64_t readRT(void *buf, size_t buf_size) override
void ERROR_MSG(const std::string &errmsg, Args... args)
constexpr std::string_view pipe_filesystem_prefix
int getFifo(std::unique_ptr< Fifo > &fifo, size_t fifo_size)