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 <operation.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 23 of file operation.hpp.

Member Typedef Documentation

◆ Callback

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

Definition at line 26 of file operation.hpp.

Member Enumeration Documentation

◆ OperationPollingStatus

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

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

Definition at line 40 of file operation.hpp.

41 {
42 READY,
43 RUNNING,
44 DONE,
45 ERROR
46 };

◆ OperationType

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

Operation types. 操作类型。

Definition at line 30 of file operation.hpp.

31 {
32 CALLBACK,
33 BLOCK,
34 POLLING,
35 NONE
36 };

Constructor & Destructor Documentation

◆ Operation() [1/6]

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

Default constructor, initializes with NONE type.

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

Definition at line 50 of file operation.hpp.

50: data{nullptr}, type(OperationType::NONE) {}
union LibXR::Operation::@5 data
OperationType type

◆ 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 63 of file operation.hpp.

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

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

73 : data{.callback = &callback}, type(OperationType::CALLBACK)
74 {}

◆ 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 81 of file operation.hpp.

82 : data{.status = &status}, type(OperationType::POLLING)
83 {}

◆ Operation() [5/6]

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

Definition at line 85 of file operation.hpp.

85 : data{nullptr}, type(OperationType::NONE)
86 {
87 *this = op;
88 }

◆ Operation() [6/6]

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

Definition at line 90 of file operation.hpp.

90 : data{nullptr}, type(OperationType::NONE)
91 {
92 *this = std::move(op);
93 }

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 199 of file operation.hpp.

200 {
201 if (type == OperationType::POLLING)
202 {
203 *data.status = OperationPollingStatus::RUNNING;
204 }
205 }

◆ 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 101 of file operation.hpp.

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

◆ 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 132 of file operation.hpp.

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

◆ 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 164 of file operation.hpp.

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

Field Documentation

◆ callback

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

Definition at line 211 of file operation.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 214 of file operation.hpp.

◆ status

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

Definition at line 217 of file operation.hpp.

◆ timeout

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

Definition at line 215 of file operation.hpp.

◆ type

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

Operation type. 操作类型。

Definition at line 222 of file operation.hpp.


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