27 #include <sys/eventfd.h>  47  int64_t 
read(
void* buf, 
size_t data_size) 
override;
  48  int64_t 
write(
void* buf, 
size_t data_size) 
override;
  49  int64_t 
readRT(
void* buf, 
size_t data_size) 
override;
  50  int64_t 
writeRT(
void* buf, 
size_t data_size) 
override;
  52  void close() 
override;
  56  std::array<int, 2> ui_to_rt {};
  57  std::array<int, 2> rt_to_ui {};
  59  size_t fifo_capacity = 0;
  61  std::array<struct pollfd, 2> xbuf_poll_fd {};
  69  , errcode(pipe2(this->rt_to_ui.data(), O_CLOEXEC))
  71  if (this->errcode != 0) {
  72  ERROR_MSG(
"RT::OS::posixFifo : Unable to create RT to UI buffer");
  75  this->errcode = pipe2(this->ui_to_rt.data(), O_CLOEXEC);
  76  if (this->errcode != 0) {
  77  ERROR_MSG(
"RT::OS::posixFifo : Unable to create UI to RT buffer");
  81  fcntl(this->rt_to_ui[0], F_SETFL, O_NONBLOCK);
  82  fcntl(this->rt_to_ui[1], F_SETFL, O_NONBLOCK);
  83  fcntl(this->ui_to_rt[0], F_SETFL, O_NONBLOCK);
  84  fcntl(this->rt_to_ui[1], F_SETFL, O_NONBLOCK);
  87  fcntl(this->rt_to_ui[1], F_SETPIPE_SZ, size);
  88  fcntl(this->ui_to_rt[1], F_SETPIPE_SZ, size);
  91  this->xbuf_poll_fd[0].fd = this->rt_to_ui[0];
  92  this->xbuf_poll_fd[0].events = POLLIN;
  93  this->close_event_fd = eventfd(0, EFD_NONBLOCK);
  94  this->xbuf_poll_fd[1].fd = this->close_event_fd;
  95  this->xbuf_poll_fd[1].events = POLLIN;
  100  ::close(rt_to_ui[0]);
  101  ::close(rt_to_ui[1]);
  102  ::close(ui_to_rt[0]);
  103  ::close(ui_to_rt[1]);
  108  return ::read(rt_to_ui[0], buf, data_size);
  113  return ::write(ui_to_rt[1], buf, data_size);
  118  return ::read(ui_to_rt[0], buf, data_size);
  123  return ::write(rt_to_ui[1], buf, data_size);
  128  this->errcode = ::poll(this->xbuf_poll_fd.data(), 2, -1);
  130  std::string errbuff(255, 
'\0');
  131  ERROR_MSG(
"RT::OS::FIFO(evl)::poll : returned with failure code {} : ",
  133  ERROR_MSG(
"{}", strerror_r(this->errcode, errbuff.data(), errbuff.size()));
  134  } 
else if ((this->xbuf_poll_fd[1].revents & POLLIN) != 0) {
  141  std::array<int64_t, 1> buf = {1};
  143  ::write(this->close_event_fd, buf.data(), 
sizeof(int64_t));
  148  return this->fifo_capacity;
  153  return this->errcode;
  158  auto tmp_fifo = std::make_unique<RT::OS::posixFifo>(fifo_size);
  159  const int errcode = tmp_fifo->getErrorCode();
  161  std::string errbuff(255, 
'\0');
  163  strerror_r(errcode, errbuff.data(), errbuff.size()));
  165  fifo = std::move(tmp_fifo);
 size_t getCapacity() override
posixFifo(posixFifo &&)=default
posixFifo & operator=(const posixFifo &fifo)=delete
int64_t write(void *buf, size_t data_size) override
int64_t read(void *buf, size_t data_size) override
posixFifo(const posixFifo &fifo)=delete
posixFifo & operator=(posixFifo &&)=default
int64_t readRT(void *buf, size_t data_size) override
int64_t writeRT(void *buf, size_t data_size) override
void ERROR_MSG(const std::string &errmsg, Args... args)
int getFifo(std::unique_ptr< Fifo > &fifo, size_t fifo_size)