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)
 使用指定数据队列容量构造 Pipe。
 
 ~Pipe ()
 析构函数。
 
 Pipe (const Pipe &)=delete
 禁止拷贝以避免重复绑定状态。
 
Pipeoperator= (const Pipe &)=delete
 禁止拷贝赋值以避免重复绑定状态。
 
ReadPortGetReadPort ()
 获取读取端口。
 
WritePortGetWritePort ()
 获取写入端口。
 

Static Private Member Functions

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

Private Attributes

ReadPort read_port_
 
WritePort write_port_
 

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)
inline

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

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

Parameters
buffer_size共享数据队列的容量(字节)。 Capacity (in bytes) of the shared data queue.

Definition at line 35 of file libxr_pipe.hpp.

35 : 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 }
WritePort write_port_
ReadPort read_port_
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

◆ ~Pipe()

LibXR::Pipe::~Pipe ( )
inline

析构函数。

Destructor.

Definition at line 48 of file libxr_pipe.hpp.

48{}

◆ 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 67 of file libxr_pipe.hpp.

67{ return read_port_; }

◆ GetWritePort()

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

获取写入端口。

Get the write endpoint.

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

Definition at line 74 of file libxr_pipe.hpp.

74{ 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 & ,
bool  )
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).
in_isr是否在中断上下文中运行。 Whether running in ISR context.
Returns
返回 ErrorCode::PENDING。 Returns ErrorCode::PENDING.

Definition at line 89 of file libxr_pipe.hpp.

89{ return ErrorCode::PENDING; }

◆ WriteFun()

static ErrorCode LibXR::Pipe::WriteFun ( WritePort & port,
bool in_isr )
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.
in_isr是否在中断上下文中运行。 Whether running in ISR context.
Returns
若已推进返回 ErrorCode::OK;若无可处理操作返回 ErrorCode::EMPTY。 Returns ErrorCode::OK if progressed; ErrorCode::EMPTY if no op was available.

Definition at line 107 of file libxr_pipe.hpp.

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 }
Pipe(size_t buffer_size)
使用指定数据队列容量构造 Pipe。

Field Documentation

◆ read_port_

ReadPort LibXR::Pipe::read_port_
private

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

Definition at line 124 of file libxr_pipe.hpp.

◆ write_port_

WritePort LibXR::Pipe::write_port_
private

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

Definition at line 126 of file libxr_pipe.hpp.


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