|
libxr
1.0
Want to be the best embedded framework
|
WritePort class for handling write operations. More...
#include <write_port.hpp>
Data Structures | |
| class | Stream |
Public Types | |
| enum class | BusyState : uint32_t { LOCKED , BLOCK_PUBLISHING = 1 , BLOCK_WAITING = 2 , BLOCK_CLAIMED , BLOCK_DETACHED = 4 , RESETTING = 5 , IDLE = UINT32_MAX } |
Public Member Functions | |
| WritePort (size_t queue_size=3, size_t buffer_size=128) | |
| 构造一个新的 WritePort 对象。 Constructs a new WritePort object. | |
| size_t | EmptySize () |
| 获取数据队列的剩余可用空间。 Gets the remaining available space in the data queue. | |
| size_t | Size () |
| 获取当前数据队列的已使用大小。 Gets the used size of the current data queue. | |
| bool | Writable () |
| 判断端口是否可写。 Checks whether the port is writable. | |
| WritePort & | operator= (WriteFun fun) |
| 赋值运算符重载,用于设置写入函数。 Overloaded assignment operator to set the write function. | |
| void | Finish (bool in_isr, ErrorCode ans, WriteInfoBlock &info) |
| 更新写入操作的状态。 Updates the status of the write operation. | |
| void | MarkAsRunning (WriteOperation &op) |
| 标记写入操作为运行中。 Marks the write operation as running. | |
| ErrorCode | operator() (ConstRawData data, WriteOperation &op, bool in_isr=false) |
| 执行写入操作。 Performs a write operation. | |
| void | FailAndClearAll (ErrorCode reason, bool in_isr) |
| 失败完成并清空当前所有挂起写操作。 | |
| ErrorCode | CommitWrite (ConstRawData data, WriteOperation &op, bool pushed=false, bool in_isr=false) |
| 提交写入操作。 Commits a write operation. | |
Data Fields | |
| WriteFun | write_fun_ = nullptr |
| Driver/backend write entry. 底层驱动或后端写入入口。 | |
| LockFreeQueue< WriteInfoBlock > * | queue_info_ |
| Metadata queue for pending write batches. 挂起写批次的元数据队列。 | |
| LockFreeQueue< uint8_t > * | queue_data_ |
| Payload queue for pending write bytes. 挂起写入字节的数据队列。 | |
| std::atomic< BusyState > | busy_ {BusyState::IDLE} |
| Shared submit/wait handoff state. 共享的提交/等待交接状态。 | |
| ErrorCode | block_result_ = ErrorCode::OK |
| Final status for the current BLOCK write. 当前 BLOCK 写入的最终结果。 | |
WritePort class for handling write operations.
处理写入操作的WritePort类。
Definition at line 18 of file write_port.hpp.
|
strong |
Definition at line 45 of file write_port.hpp.
| WritePort::WritePort | ( | size_t | queue_size = 3, |
| size_t | buffer_size = 128 ) |
构造一个新的 WritePort 对象。 Constructs a new WritePort object.
该构造函数初始化无锁操作队列 queue_info_ 和数据块队列 queue_data_。 This constructor initializes the lock-free operation queue queue_info_ and the data block queue queue_data_.
| queue_size | 队列的大小,默认为 3。 The size of the queue, default is 3. |
| buffer_size | 缓存数据字节队列的容量,默认为 128。 Capacity of the cached-byte queue, default is 128. |
Definition at line 10 of file write_port.cpp.
| ErrorCode WritePort::CommitWrite | ( | ConstRawData | data, |
| WriteOperation & | op, | ||
| bool | pushed = false, | ||
| bool | in_isr = false ) |
提交写入操作。 Commits a write operation.
| data | 写入的原始数据 / Raw data to be written |
| op | 写入操作对象,包含操作类型和同步机制。 Write operation object containing the operation type and synchronization |
| pushed | 数据是否已经推送到缓冲区 / Whether the data has been pushed to the buffer |
| in_isr | 指示是否在中断上下文中执行。 Indicates whether the operation is executed in an interrupt context. |
Definition at line 117 of file write_port.cpp.
| size_t WritePort::EmptySize | ( | ) |
获取数据队列的剩余可用空间。 Gets the remaining available space in the data queue.
Definition at line 19 of file write_port.cpp.
| void WritePort::FailAndClearAll | ( | ErrorCode | reason, |
| bool | in_isr ) |
失败完成并清空当前所有挂起写操作。
Fail-complete and clear all currently pending write operations.
| reason | 最终失败原因 / Final failure reason |
| in_isr | 是否在 ISR 上下文 / Whether running in ISR context |
Definition at line 284 of file write_port.cpp.
| void WritePort::Finish | ( | bool | in_isr, |
| ErrorCode | ans, | ||
| WriteInfoBlock & | info ) |
更新写入操作的状态。 Updates the status of the write operation.
该函数在写入操作完成时更新对应 info 的状态,并调用 UpdateStatus 更新 op。 This function updates the status stored in info and calls UpdateStatus on op when a write operation completes.
| in_isr | 指示是否在中断上下文中执行。 Indicates whether the operation is executed in an interrupt context. |
| ans | 错误码,用于指示操作的结果。 Error code indicating the result of the operation. |
| op | 需要更新状态的 WriteOperation 引用。 Reference to the WriteOperation whose status needs to be updated. |
Definition at line 39 of file write_port.cpp.
| void WritePort::MarkAsRunning | ( | WriteOperation & | op | ) |
标记写入操作为运行中。 Marks the write operation as running.
该函数用于将 op 标记为运行状态,以指示当前正在进行写入操作。 This function marks op as running to indicate an ongoing write operation.
| op | 需要更新状态的 WriteOperation 引用。 Reference to the WriteOperation whose status needs to be updated. |
Definition at line 86 of file write_port.cpp.
| ErrorCode WritePort::operator() | ( | ConstRawData | data, |
| WriteOperation & | op, | ||
| bool | in_isr = false ) |
执行写入操作。 Performs a write operation.
该函数检查端口是否可写,并根据 data.size_ 和 op 的类型执行不同的操作。 This function checks if the port is writable and performs different actions based on data.size_ and the type of op.
| data | 需要写入的原始数据。 Raw data to be written. |
| op | 写入操作对象,包含操作类型和同步机制。 Write operation object containing the operation type and synchronization mechanism. |
| in_isr | 指示是否在中断上下文中执行。 Indicates whether the operation is executed in an interrupt context. |
Definition at line 88 of file write_port.cpp.
赋值运算符重载,用于设置写入函数。 Overloaded assignment operator to set the write function.
该函数允许使用 WriteFun 类型的函数对象赋值给 WritePort,从而设置 write_fun_。 This function allows assigning a WriteFun function object to WritePort, setting write_fun_.
| fun | 要分配的写入函数。 The write function to be assigned. |
Definition at line 33 of file write_port.cpp.
| size_t WritePort::Size | ( | ) |
获取当前数据队列的已使用大小。 Gets the used size of the current data queue.
Definition at line 25 of file write_port.cpp.
| bool WritePort::Writable | ( | ) |
判断端口是否可写。 Checks whether the port is writable.
Definition at line 31 of file write_port.cpp.
| ErrorCode LibXR::WritePort::block_result_ = ErrorCode::OK |
Final status for the current BLOCK write. 当前 BLOCK 写入的最终结果。
Definition at line 69 of file write_port.hpp.
| std::atomic<BusyState> LibXR::WritePort::busy_ {BusyState::IDLE} |
Shared submit/wait handoff state. 共享的提交/等待交接状态。
Definition at line 68 of file write_port.hpp.
| LockFreeQueue<uint8_t>* LibXR::WritePort::queue_data_ |
Payload queue for pending write bytes. 挂起写入字节的数据队列。
Definition at line 66 of file write_port.hpp.
| LockFreeQueue<WriteInfoBlock>* LibXR::WritePort::queue_info_ |
Metadata queue for pending write batches. 挂起写批次的元数据队列。
Definition at line 64 of file write_port.hpp.
| WriteFun LibXR::WritePort::write_fun_ = nullptr |
Driver/backend write entry. 底层驱动或后端写入入口。
Definition at line 63 of file write_port.hpp.