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:
35 Pipe(size_t buffer_size) : read_port_(0), write_port_(1, buffer_size)
36 {
37 // 绑定回调并共享同一数据队列。
38 // Bind callbacks and share the same data queue.
39 read_port_.read_fun_ = ReadFun;
40 write_port_.write_fun_ = WriteFun;
41 read_port_.queue_data_ = write_port_.queue_data_;
42 }
43
48 ~Pipe() {}
49
54 Pipe(const Pipe&) = delete;
55
60 Pipe& operator=(const Pipe&) = delete;
61
68
75
76 private:
89 static ErrorCode ReadFun(ReadPort&, bool) { return ErrorCode::PENDING; }
90
107 static ErrorCode WriteFun(WritePort& port, bool in_isr)
108 {
109 Pipe* pipe = CONTAINER_OF(&port, Pipe, write_port_);
110 WriteInfoBlock info;
111 if (port.queue_info_->Pop(info) != ErrorCode::OK)
112 {
113 ASSERT(false);
114 return ErrorCode::EMPTY;
115 }
116
117 // 推动读端从共享队列中取数。
118 // Drive the reader to consume from the shared queue.
119 pipe->read_port_.ProcessPendingReads(in_isr);
120
121 return ErrorCode::OK;
122 }
123
128};
129} // namespace LibXR
基于共享队列,由 ReadPort + WritePort 组成的单向管道。
static ErrorCode WriteFun(WritePort &port, bool in_isr)
写端回调:弹出一次写操作并推动读侧处理。
~Pipe()
析构函数。
WritePort & GetWritePort()
获取写入端口。
WritePort write_port_
Pipe & operator=(const Pipe &)=delete
禁止拷贝赋值以避免重复绑定状态。
static ErrorCode ReadFun(ReadPort &, bool)
读端回调(占位,无具体操作)。
Pipe(size_t buffer_size)
使用指定数据队列容量构造 Pipe。
ReadPort read_port_
Pipe(const Pipe &)=delete
禁止拷贝以避免重复绑定状态。
ReadPort & GetReadPort()
获取读取端口。
ReadPort class for handling read operations.
Definition libxr_rw.hpp:272
void ProcessPendingReads(bool in_isr)
Processes pending reads.
Definition libxr_rw.cpp:127
WritePort class for handling write operations.
Definition libxr_rw.hpp:413
LibXR 命名空间
Definition ch32_can.hpp:14
ErrorCode(* ReadFun)(ReadPort &port, bool in_isr)
Function pointer type for read operations.
Definition libxr_rw.hpp:249
ErrorCode(* WriteFun)(WritePort &port, bool in_isr)
Function pointer type for write operations.
Definition libxr_rw.hpp:245