libxr  1.0
Want to be the best embedded framework
Loading...
Searching...
No Matches
LibXR::Pipe Class Reference

基于共享队列,由 ReadPort + WritePort 组成的单向管道。 More...

#include <libxr_pipe.hpp>

Collaboration diagram for LibXR::Pipe:
[legend]

Public Member Functions

 Pipe (size_t buffer_size, bool in_isr=false)
 使用指定数据队列容量构造 Pipe。
 
 ~Pipe ()
 析构函数。
 
 Pipe (const Pipe &)=delete
 禁止拷贝以避免重复绑定状态。
 
Pipeoperator= (const Pipe &)=delete
 禁止拷贝赋值以避免重复绑定状态。
 
ReadPortGetReadPort ()
 获取读取端口。
 
WritePortGetWritePort ()
 获取写入端口。
 

Static Private Member Functions

static ErrorCode ReadFun (ReadPort &)
 读端回调(占位,无具体操作)。
 
static ErrorCode WriteFun (WritePort &port)
 写端回调:弹出一次写操作并推动读侧处理。
 

Private Attributes

ReadPort read_port_
 
WritePort write_port_
 
bool in_isr_
 回调是否运行在中断上下文中。 Whether callbacks may run in ISR.
 

Detailed Description

基于共享队列,由 ReadPort + WritePort 组成的单向管道。

Single-direction pipe built from ReadPort + WritePort on a shared queue.

Definition at line 25 of file libxr_pipe.hpp.

Constructor & Destructor Documentation

◆ Pipe() [1/2]

LibXR::Pipe::Pipe ( size_t buffer_size,
bool in_isr = false )
inline

使用指定数据队列容量构造 Pipe。

Construct a Pipe with the given shared data-queue capacity.

Parameters
buffer_size共享数据队列的容量(字节)。 Capacity (in bytes) of the shared data queue.
in_isr指示回调是否可能在中断上下文中运行。 Whether callbacks may run in ISR context.

Definition at line 38 of file libxr_pipe.hpp.

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 }
bool in_isr_
回调是否运行在中断上下文中。 Whether callbacks may run in ISR.
WritePort write_port_
ReadPort read_port_
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

◆ ~Pipe()

LibXR::Pipe::~Pipe ( )
inline

析构函数。

Destructor.

Definition at line 52 of file libxr_pipe.hpp.

52{}

◆ Pipe() [2/2]

LibXR::Pipe::Pipe ( const Pipe & )
delete

禁止拷贝以避免重复绑定状态。

Non-copyable to avoid double-binding internal state.

Member Function Documentation

◆ GetReadPort()

ReadPort & LibXR::Pipe::GetReadPort ( )
inline

获取读取端口。

Get the read endpoint.

Returns
返回内部 ReadPort 的引用。 Reference to the internal ReadPort.

Definition at line 71 of file libxr_pipe.hpp.

71{ return read_port_; }

◆ GetWritePort()

WritePort & LibXR::Pipe::GetWritePort ( )
inline

获取写入端口。

Get the write endpoint.

Returns
返回内部 WritePort 的引用。 Reference to the internal WritePort.

Definition at line 78 of file libxr_pipe.hpp.

78{ return write_port_; }

◆ operator=()

Pipe & LibXR::Pipe::operator= ( const Pipe & )
delete

禁止拷贝赋值以避免重复绑定状态。

Non-copy-assignable to avoid double-binding internal state.

◆ ReadFun()

static ErrorCode LibXR::Pipe::ReadFun ( ReadPort & )
inlinestaticprivate

读端回调(占位,无具体操作)。

Read-side callback (no-op placeholder).

仅用于匹配 ReadPort 回调签名;实际读取推进通常在 ProcessPendingReads() 中进行。 Provided to match the ReadPort callback signature; reading is typically advanced in ProcessPendingReads().

Parameters
portReadPort 引用(未使用)。 ReadPort reference (unused).
Returns
返回 ErrorCode::EMPTY,表示当前无操作。 Returns ErrorCode::EMPTY (no action).

Definition at line 93 of file libxr_pipe.hpp.

93{ return ErrorCode::EMPTY; }

◆ WriteFun()

static ErrorCode LibXR::Pipe::WriteFun ( WritePort & port)
inlinestaticprivate

写端回调:弹出一次写操作并推动读侧处理。

Write-side callback: pop a write op and advance the reader.

从写端操作队列中弹出一个 WriteInfoBlock,并调用 ReadPort::ProcessPendingReads(), 使挂起的读请求可从共享数据队列中取出字节。 Pops a WriteInfoBlock from the write op-queue and calls ReadPort::ProcessPendingReads() so pending reads can pull bytes from the shared data queue.

Parameters
port触发本回调的 WritePort。 The WritePort invoking this callback.
Returns
若已推进返回 ErrorCode::OK;若无可处理操作返回 ErrorCode::EMPTY。 Returns ErrorCode::OK if progressed; ErrorCode::EMPTY if no op was available.

Definition at line 110 of file libxr_pipe.hpp.

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.
122 pipe->read_port_.ProcessPendingReads(pipe->in_isr_);
123
124 return ErrorCode::OK;
125 }
Pipe(size_t buffer_size, bool in_isr=false)
使用指定数据队列容量构造 Pipe。

Field Documentation

◆ in_isr_

bool LibXR::Pipe::in_isr_
private
Initial value:
=
false

回调是否运行在中断上下文中。 Whether callbacks may run in ISR.

Definition at line 131 of file libxr_pipe.hpp.

◆ read_port_

ReadPort LibXR::Pipe::read_port_
private

共享写端数据队列的读端。 Read endpoint sharing the writer's data queue.

Definition at line 127 of file libxr_pipe.hpp.

◆ write_port_

WritePort LibXR::Pipe::write_port_
private

持有共享数据队列(容量为构造参数)的写端。 Write endpoint owning the shared queue.

Definition at line 129 of file libxr_pipe.hpp.


The documentation for this class was generated from the following file: