libxr
Embedded C++ framework for bare-metal, RTOS and Linux
Loading...
Searching...
No Matches
libxr_pipe.hpp
Go to the documentation of this file.
1#pragma once
2
8#include "libxr_def.hpp"
9#include "libxr_rw.hpp"
10
11namespace LibXR
12{
13
29class Pipe
30{
31 public:
38 explicit Pipe(size_t buffer_size) : read_port_(0), write_port_(0, buffer_size)
39 {
40 ASSERT(write_port_.queue_data_ != nullptr);
41 read_port_.BindQueue(write_port_.queue_data_);
42 write_port_ = &WriteFun;
43 }
44
51 ~Pipe() = default;
52
54 Pipe(const Pipe&) = delete;
55 Pipe& operator=(const Pipe&) = delete;
56
61 ReadPort& GetReadPort() { return read_port_; }
62
67 WritePort& GetWritePort() { return write_port_; }
68
69 private:
77 static void WriteFun(WritePort& port, bool in_isr)
78 {
79 auto* pipe = LibXR::ContainerOf(&port, &Pipe::write_port_);
80 pipe->read_port_.NotifyDataAvailable(in_isr);
81 }
82
83 ReadPort read_port_;
84 WritePort write_port_;
85};
86
87} // namespace LibXR
由读写端口组成的单向管道 / Unidirectional pipe connecting read and write ports.
~Pipe()=default
析构管道 / Destroy the pipe.
WritePort & GetWritePort()
获取写端口 / Get the write endpoint.
Pipe(size_t buffer_size)
构造管道并绑定共享队列 / Construct a pipe and bind its shared queue.
Pipe(const Pipe &)=delete
端口状态与共享队列不可复制 / Endpoint state and the shared queue cannot be copied.
ReadPort & GetReadPort()
获取读端口 / Get the read endpoint.
基于 SPSC 字节队列的读端口 / Read endpoint backed by an SPSC byte queue.
Definition read_port.hpp:30
基于 SPSC 字节队列的写端口 / Write endpoint backed by an SPSC byte queue.
LibXR 命名空间 / LibXR namespace.
Definition ch32_can.hpp:14
void(* WriteFun)(WritePort &port, bool in_isr)
写入进度通知函数类型 / Write progress notification function type.
OwnerType * ContainerOf(MemberType *ptr, MemberType OwnerType::*member) noexcept
通过成员指针恢复其所属对象指针 Recover the owning object pointer from a member pointer