libxr  1.0
Want to be the best embedded framework
Loading...
Searching...
No Matches
LibXR::Operation< Args > Class Template Reference

Defines an operation with different execution modes. More...

#include <libxr_rw.hpp>

Collaboration diagram for LibXR::Operation< Args >:
[legend]

Public Types

enum class  OperationType : uint8_t { CALLBACK , BLOCK , POLLING , NONE }
 
enum class  OperationPollingStatus : uint8_t { READY , RUNNING , DONE , ERROR }
 
using Callback = LibXR::Callback<Args>
 

Public Member Functions

 Operation ()
 Default constructor, initializes with NONE type.
 
 Operation (Semaphore &sem, uint32_t timeout=UINT32_MAX)
 Constructs a blocking operation with a semaphore and timeout.
 
 Operation (Callback &callback)
 Constructs a callback-based operation.
 
 Operation (OperationPollingStatus &status)
 Constructs a polling operation.
 
Operationoperator= (const Operation &op)
 Copy assignment operator.
 
Operationoperator= (Operation &&op) noexcept
 Move assignment operator.
 
template<typename InitOperation , typename = std::enable_if_t<std::is_same_v<std::decay_t<InitOperation>, Operation>>>
 Operation (InitOperation &&op)
 构造一个新的 Operation 对象(初始化操作)。 Constructs a new Operation object (initialization operation).
 
template<typename Status >
void UpdateStatus (bool in_isr, Status &&status)
 Updates operation status based on type.
 
void MarkAsRunning ()
 标记操作为运行状态。 Marks the operation as running.
 

Data Fields

union { 
 
   Callback *   callback 
 
   struct { 
 
      Semaphore *   sem 
 
      uint32_t   timeout 
 
   }   sem_info 
 
   OperationPollingStatus *   status 
 
data 
 
OperationType type
 

Detailed Description

template<typename Args>
class LibXR::Operation< Args >

Defines an operation with different execution modes.

定义了一种具有不同执行模式的操作。

Template Parameters
ArgsThe parameter types for callback operations.
Args用于回调操作的参数类型。

Definition at line 28 of file libxr_rw.hpp.

Member Typedef Documentation

◆ Callback

template<typename Args >
using LibXR::Operation< Args >::Callback = LibXR::Callback<Args>

Definition at line 31 of file libxr_rw.hpp.

Member Enumeration Documentation

◆ OperationPollingStatus

template<typename Args >
enum class LibXR::Operation::OperationPollingStatus : uint8_t
strong

Polling operation status. 轮询操作的状态。

Definition at line 45 of file libxr_rw.hpp.

46 {
47 READY,
48 RUNNING,
49 DONE,
50 ERROR
51 };

◆ OperationType

template<typename Args >
enum class LibXR::Operation::OperationType : uint8_t
strong

Operation types. 操作类型。

Definition at line 35 of file libxr_rw.hpp.

36 {
37 CALLBACK,
38 BLOCK,
39 POLLING,
40 NONE
41 };

Constructor & Destructor Documentation

◆ Operation() [1/5]

template<typename Args >
LibXR::Operation< Args >::Operation ( )
inline

Default constructor, initializes with NONE type.

默认构造函数,初始化为NONE类型。

Definition at line 55 of file libxr_rw.hpp.

55: type(OperationType::NONE) { Memory::FastSet(&data, 0, sizeof(data)); }
static void FastSet(void *dst, uint8_t value, size_t size)
快速内存填充 / Fast memory fill
union LibXR::Operation::@5 data
OperationType type
Definition libxr_rw.hpp:236

◆ Operation() [2/5]

template<typename Args >
LibXR::Operation< Args >::Operation ( Semaphore & sem,
uint32_t timeout = UINT32_MAX )
inline

Constructs a blocking operation with a semaphore and timeout.

使用信号量和超时构造阻塞操作。

Parameters
semSemaphore reference.
timeoutTimeout duration (default is maximum).
Note
sem must be dedicated to one live BLOCK call at a time. Reuse is allowed only after that call returns.
sem 在任一时刻只能服务一个存活中的 BLOCK 调用; 只有在该调用返回后才能复用。

Definition at line 68 of file libxr_rw.hpp.

68 : type(OperationType::BLOCK)
69 {
70 data.sem_info.sem = &sem;
71 data.sem_info.timeout = timeout;
72 }

◆ Operation() [3/5]

template<typename Args >
LibXR::Operation< Args >::Operation ( Callback & callback)
inline

Constructs a callback-based operation.

构造基于回调的操作。

Parameters
callbackCallback function reference.

Definition at line 79 of file libxr_rw.hpp.

79 : type(OperationType::CALLBACK)
80 {
81 data.callback = &callback;
82 }

◆ Operation() [4/5]

template<typename Args >
LibXR::Operation< Args >::Operation ( OperationPollingStatus & status)
inline

Constructs a polling operation.

构造轮询操作。

Parameters
statusReference to polling status.

Definition at line 89 of file libxr_rw.hpp.

89 : type(OperationType::POLLING)
90 {
91 data.status = &status;
92 }

◆ Operation() [5/5]

template<typename Args >
template<typename InitOperation , typename = std::enable_if_t<std::is_same_v<std::decay_t<InitOperation>, Operation>>>
LibXR::Operation< Args >::Operation ( InitOperation< Args > && op)
inline

构造一个新的 Operation 对象(初始化操作)。 Constructs a new Operation object (initialization operation).

该构造函数用于初始化一个 Operation 对象,接收一个初始化操作作为参数。 This constructor initializes an Operation object with an initialization operation as a parameter.

Definition at line 165 of file libxr_rw.hpp.

166 {
167 *this = std::forward<InitOperation>(op);
168 }

Member Function Documentation

◆ MarkAsRunning()

template<typename Args >
void LibXR::Operation< Args >::MarkAsRunning ( )
inline

标记操作为运行状态。 Marks the operation as running.

该函数用于在操作类型为 POLLING 时,将 data.status 设置为 RUNNING, 以指示该操作正在执行中。 This function sets data.status to RUNNING when the operation type is POLLING, indicating that the operation is currently in progress.

Note
该方法仅适用于 OperationType::POLLING 类型的操作,其他类型不会受到影响。 This method only applies to operations of type OperationType::POLLING, and other types remain unaffected.

Definition at line 212 of file libxr_rw.hpp.

213 {
214 if (type == OperationType::POLLING)
215 {
216 *data.status = OperationPollingStatus::RUNNING;
217 }
218 }

◆ operator=() [1/2]

template<typename Args >
Operation & LibXR::Operation< Args >::operator= ( const Operation< Args > & op)
inline

Copy assignment operator.

复制赋值运算符。

Parameters
opAnother Operation instance.
Returns
Reference to this operation.

Definition at line 100 of file libxr_rw.hpp.

101 {
102 if (this != &op)
103 {
104 type = op.type;
105 switch (type)
106 {
107 case OperationType::CALLBACK:
108 data.callback = op.data.callback;
109 break;
110 case OperationType::BLOCK:
111 data.sem_info.sem = op.data.sem_info.sem;
112 data.sem_info.timeout = op.data.sem_info.timeout;
113 break;
114 case OperationType::POLLING:
115 data.status = op.data.status;
116 break;
117 case OperationType::NONE:
118 break;
119 }
120 }
121 return *this;
122 }

◆ operator=() [2/2]

template<typename Args >
Operation & LibXR::Operation< Args >::operator= ( Operation< Args > && op)
inlinenoexcept

Move assignment operator.

移动赋值运算符。

Parameters
opAnother Operation instance.
Returns
Reference to this operation.

Definition at line 130 of file libxr_rw.hpp.

131 {
132 if (this != &op)
133 {
134 type = op.type;
135 switch (type)
136 {
137 case OperationType::CALLBACK:
138 data.callback = op.data.callback;
139 break;
140 case OperationType::BLOCK:
141 data.sem_info.sem = op.data.sem_info.sem;
142 data.sem_info.timeout = op.data.sem_info.timeout;
143 break;
144 case OperationType::POLLING:
145 data.status = op.data.status;
146 break;
147 case OperationType::NONE:
148 break;
149 }
150 }
151 return *this;
152 }

◆ UpdateStatus()

template<typename Args >
template<typename Status >
void LibXR::Operation< Args >::UpdateStatus ( bool in_isr,
Status && status )
inline

Updates operation status based on type.

根据类型更新操作状态。

Parameters
in_isrIndicates if executed within an interrupt.
argsParameters passed to the callback.

Definition at line 177 of file libxr_rw.hpp.

178 {
179 switch (type)
180 {
181 case OperationType::CALLBACK:
182 data.callback->Run(in_isr, std::forward<Status>(status));
183 break;
184 case OperationType::BLOCK:
185 // BLOCK waits are signaled by semaphore only; the owning port keeps the
186 // final ErrorCode in its block_result_ handoff state.
187 // BLOCK 只通过信号量唤醒;最终 ErrorCode 由端口侧 block_result_ 交接。
188 data.sem_info.sem->PostFromCallback(in_isr);
189 break;
190 case OperationType::POLLING:
191 *data.status = (status == ErrorCode::OK) ? OperationPollingStatus::DONE
192 : OperationPollingStatus::ERROR;
193 break;
194 case OperationType::NONE:
195 break;
196 }
197 }

Field Documentation

◆ callback

template<typename Args >
Callback* LibXR::Operation< Args >::callback

Definition at line 224 of file libxr_rw.hpp.

◆ [union]

union { ... } LibXR::Operation< Args >::data

Data storage for different operation types. 存储不同操作类型的数据。

◆ sem

template<typename Args >
Semaphore* LibXR::Operation< Args >::sem

Definition at line 227 of file libxr_rw.hpp.

◆ status

template<typename Args >
OperationPollingStatus* LibXR::Operation< Args >::status

Definition at line 230 of file libxr_rw.hpp.

◆ timeout

template<typename Args >
uint32_t LibXR::Operation< Args >::timeout

Definition at line 228 of file libxr_rw.hpp.

◆ type

template<typename Args >
OperationType LibXR::Operation< Args >::type

Operation type. 操作类型。

Definition at line 236 of file libxr_rw.hpp.


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