libxr  1.0
Want to be the best embedded framework
Loading...
Searching...
No Matches
libxr_pipe.hpp
Go to the documentation of this file.
1#pragma once
14#include "libxr_def.hpp"
15#include "libxr_rw.hpp"
16
17namespace LibXR
18{
25class Pipe
26{
27 public:
38 Pipe(size_t buffer_size, bool in_isr = false)
39 : read_port_(0), write_port_(1, buffer_size), in_isr_(in_isr)
40 {
41 // 绑定回调并共享同一数据队列。
42 // Bind callbacks and share the same data queue.
43 read_port_.read_fun_ = ReadFun;
44 write_port_.write_fun_ = WriteFun;
45 read_port_.queue_data_ = write_port_.queue_data_;
46 }
47
52 ~Pipe() {}
53
58 Pipe(const Pipe&) = delete;
59
64 Pipe& operator=(const Pipe&) = delete;
65
72
79
80 private:
93 static ErrorCode ReadFun(ReadPort&) { return ErrorCode::EMPTY; }
94
110 static ErrorCode WriteFun(WritePort& port)
111 {
112 Pipe* pipe = CONTAINER_OF(&port, Pipe, write_port_);
113 WriteInfoBlock info;
114 if (port.queue_info_->Pop(info) != ErrorCode::OK)
115 {
116 ASSERT(false);
117 return ErrorCode::EMPTY;
118 }
119
120 // 推动读端从共享队列中取数。
121 // Drive the reader to consume from the shared queue.
123
124 return ErrorCode::OK;
125 }
126
131 bool in_isr_ =
132 false;
133};
134} // namespace LibXR
基于共享队列,由 ReadPort + WritePort 组成的单向管道。
~Pipe()
析构函数。
WritePort & GetWritePort()
获取写入端口。
bool in_isr_
回调是否运行在中断上下文中。 Whether callbacks may run in ISR.
Pipe(size_t buffer_size, bool in_isr=false)
使用指定数据队列容量构造 Pipe。
WritePort write_port_
Pipe & operator=(const Pipe &)=delete
禁止拷贝赋值以避免重复绑定状态。
static ErrorCode WriteFun(WritePort &port)
写端回调:弹出一次写操作并推动读侧处理。
ReadPort read_port_
Pipe(const Pipe &)=delete
禁止拷贝以避免重复绑定状态。
static ErrorCode ReadFun(ReadPort &)
读端回调(占位,无具体操作)。
ReadPort & GetReadPort()
获取读取端口。
ReadPort class for handling read operations.
Definition libxr_rw.hpp:269
virtual void ProcessPendingReads(bool in_isr)
Processes pending reads.
Definition libxr_rw.cpp:126
WritePort class for handling write operations.
Definition libxr_rw.hpp:403
LibXR 命名空间
ErrorCode(* ReadFun)(ReadPort &port)
Function pointer type for read operations.
Definition libxr_rw.hpp:246
ErrorCode(* WriteFun)(WritePort &port)
Function pointer type for write operations.
Definition libxr_rw.hpp:242