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 }
 
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 };

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

54 : type(OperationType::NONE) {
55 memset(&data, 0, sizeof(data));
56 }
union LibXR::Operation::@4 data
OperationType type
Definition libxr_rw.hpp:227

◆ 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).

Definition at line 64 of file libxr_rw.hpp.

64 : type(OperationType::BLOCK)
65 {
66 data.sem_info.sem = &sem;
67 data.sem_info.timeout = timeout;
68 }

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

75 : type(OperationType::CALLBACK)
76 {
77 data.callback = &callback;
78 }

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

85 : type(OperationType::POLLING)
86 {
87 data.status = &status;
88 }

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

162 {
163 *this = std::forward<InitOperation>(op);
164 }

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

205 {
206 if (type == OperationType::POLLING)
207 {
208 *data.status = OperationPollingStatus::RUNNING;
209 }
210 }

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

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

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

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

◆ 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<Args>(status)...);
179 break;
180 case OperationType::BLOCK:
181 data.sem_info.sem->PostFromCallback(in_isr);
182 break;
183 case OperationType::POLLING:
184 *data.status = OperationPollingStatus::DONE;
185 break;
186 case OperationType::NONE:
187 break;
188 }
189 }

Field Documentation

◆ callback

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

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

◆ status

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

Definition at line 222 of file libxr_rw.hpp.

◆ timeout

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

Definition at line 220 of file libxr_rw.hpp.

◆ type

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

Operation type. 操作类型。

Definition at line 227 of file libxr_rw.hpp.


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