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) { memset(&data, 0, sizeof(data)); }
union LibXR::Operation::@4 data
OperationType type
Definition libxr_rw.hpp:225

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

172 {
173 switch (type)
174 {
175 case OperationType::CALLBACK:
176 data.callback->Run(in_isr, std::forward<Args>(status)...);
177 break;
178 case OperationType::BLOCK:
179 data.sem_info.sem->PostFromCallback(in_isr);
180 break;
181 case OperationType::POLLING:
182 *data.status = OperationPollingStatus::DONE;
183 break;
184 case OperationType::NONE:
185 break;
186 }
187 }

Field Documentation

◆ callback

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

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

◆ status

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

Definition at line 220 of file libxr_rw.hpp.

◆ timeout

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

Definition at line 218 of file libxr_rw.hpp.

◆ type

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

Operation type. 操作类型。

Definition at line 225 of file libxr_rw.hpp.


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