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.
 
 Operation (const Operation &op)
 
 Operation (Operation &&op) noexcept
 
Operationoperator= (const Operation &op)
 Copy assignment operator.
 
Operationoperator= (Operation &&op) noexcept
 Move assignment operator.
 
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 32 of file libxr_rw.hpp.

Member Typedef Documentation

◆ Callback

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

Definition at line 35 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 49 of file libxr_rw.hpp.

50 {
51 READY,
52 RUNNING,
53 DONE,
54 ERROR
55 };

◆ OperationType

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

Operation types. 操作类型。

Definition at line 39 of file libxr_rw.hpp.

40 {
41 CALLBACK,
42 BLOCK,
43 POLLING,
44 NONE
45 };

Constructor & Destructor Documentation

◆ Operation() [1/6]

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

Default constructor, initializes with NONE type.

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

Definition at line 59 of file libxr_rw.hpp.

59: data{nullptr}, type(OperationType::NONE) {}
union LibXR::Operation::@5 data
OperationType type
Definition libxr_rw.hpp:231

◆ Operation() [2/6]

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 72 of file libxr_rw.hpp.

73 : data{.sem_info = {&sem, timeout}}, type(OperationType::BLOCK)
74 {}

◆ Operation() [3/6]

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

Constructs a callback-based operation.

构造基于回调的操作。

Parameters
callbackCallback function reference.

Definition at line 81 of file libxr_rw.hpp.

82 : data{.callback = &callback}, type(OperationType::CALLBACK)
83 {}

◆ Operation() [4/6]

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

Constructs a polling operation.

构造轮询操作。

Parameters
statusReference to polling status.

Definition at line 90 of file libxr_rw.hpp.

91 : data{.status = &status}, type(OperationType::POLLING)
92 {}

◆ Operation() [5/6]

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

Definition at line 94 of file libxr_rw.hpp.

94 : data{nullptr}, type(OperationType::NONE)
95 {
96 *this = op;
97 }

◆ Operation() [6/6]

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

Definition at line 99 of file libxr_rw.hpp.

99 : data{nullptr}, type(OperationType::NONE)
100 {
101 *this = std::move(op);
102 }

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 208 of file libxr_rw.hpp.

209 {
210 if (type == OperationType::POLLING)
211 {
212 *data.status = OperationPollingStatus::RUNNING;
213 }
214 }

◆ 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 110 of file libxr_rw.hpp.

111 {
112 if (this != &op)
113 {
114 type = op.type;
115 switch (type)
116 {
117 case OperationType::CALLBACK:
118 data.callback = op.data.callback;
119 break;
120 case OperationType::BLOCK:
121 data.sem_info.sem = op.data.sem_info.sem;
122 data.sem_info.timeout = op.data.sem_info.timeout;
123 break;
124 case OperationType::POLLING:
125 data.status = op.data.status;
126 break;
127 case OperationType::NONE:
128 data.callback = nullptr;
129 break;
130 }
131 }
132 return *this;
133 }

◆ 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 141 of file libxr_rw.hpp.

142 {
143 if (this != &op)
144 {
145 type = op.type;
146 switch (type)
147 {
148 case OperationType::CALLBACK:
149 data.callback = op.data.callback;
150 break;
151 case OperationType::BLOCK:
152 data.sem_info.sem = op.data.sem_info.sem;
153 data.sem_info.timeout = op.data.sem_info.timeout;
154 break;
155 case OperationType::POLLING:
156 data.status = op.data.status;
157 break;
158 case OperationType::NONE:
159 data.callback = nullptr;
160 break;
161 }
162 }
163 return *this;
164 }

◆ 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 173 of file libxr_rw.hpp.

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

Field Documentation

◆ callback

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

Definition at line 220 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 223 of file libxr_rw.hpp.

◆ status

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

Definition at line 226 of file libxr_rw.hpp.

◆ timeout

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

Definition at line 224 of file libxr_rw.hpp.

◆ type

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

Operation type. 操作类型。

Definition at line 231 of file libxr_rw.hpp.


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