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 >:

Public Types

enum class  OperationType : uint8_t { CALLBACK , BLOCK , POLLING , NONE }
 
enum class  OperationPollingStatus : uint8_t { READY , RUNNING , DONE }
 

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< Args... > &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.
 
 Operation (const Operation &op)
 
 Operation (Operation &&op) noexcept
 构造一个新的 Operation 对象(移动构造函数)。 Constructs a new Operation object (move constructor).
 
void UpdateStatus (bool in_isr, Args &&...args)
 Updates operation status based on type.
 
void MarkAsRunning ()
 标记操作为运行状态。 Marks the operation as running.
 

Data Fields

union { 
 
   Callback< Args... > *   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 Enumeration Documentation

◆ OperationPollingStatus

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

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

Definition at line 43 of file libxr_rw.hpp.

44 {
45 READY,
46 RUNNING,
47 DONE
48 };

◆ OperationType

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

Operation types. 操作类型。

Definition at line 33 of file libxr_rw.hpp.

34 {
35 CALLBACK,
36 BLOCK,
37 POLLING,
38 NONE
39 };

Constructor & Destructor Documentation

◆ Operation() [1/6]

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

Default constructor, initializes with NONE type.

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

Definition at line 52 of file libxr_rw.hpp.

52: type(OperationType::NONE) {}
OperationType type
Definition libxr_rw.hpp:259

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

Definition at line 60 of file libxr_rw.hpp.

60 : type(OperationType::BLOCK)
61 {
62 data.sem_info.sem = &sem;
63 data.sem_info.timeout = timeout;
64 }
union LibXR::Operation::@4 data

◆ Operation() [3/6]

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

Constructs a callback-based operation.

构造基于回调的操作。

Parameters
callbackCallback function reference.

Definition at line 71 of file libxr_rw.hpp.

71 : type(OperationType::CALLBACK)
72 {
73 data.callback = &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 libxr_rw.hpp.

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

◆ Operation() [5/6]

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

Definition at line 146 of file libxr_rw.hpp.

146 : type(op.type)
147 {
148 switch (type)
149 {
150 case OperationType::CALLBACK:
151 data.callback = op.data.callback;
152 break;
153 case OperationType::BLOCK:
154 data.sem = op.data.sem;
155 data.timeout = op.data.timeout;
156 break;
157 case OperationType::POLLING:
158 data.status = op.data.status;
159 break;
160 case OperationType::NONE:
161 break;
162 }
163 }

◆ Operation() [6/6]

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

构造一个新的 Operation 对象(移动构造函数)。 Constructs a new Operation object (move constructor).

该构造函数用于移动另一个 Operation 对象,并接管其内部数据。 This constructor moves another Operation object and takes ownership of its internal data.

Parameters
op要移动的 Operation 对象。 The Operation object to be moved.
Note
该操作不会动态分配内存,仅仅是移动已有数据成员。 This operation does not allocate memory dynamically; it merely moves existing data members.

Definition at line 180 of file libxr_rw.hpp.

180 : type(op.type)
181 {
182 switch (type)
183 {
184 case OperationType::CALLBACK:
185 data.callback = op.data.callback;
186 break;
187 case OperationType::BLOCK:
188 data.sem_info.sem = op.data.sem_info.sem;
189 data.sem_info.timeout = op.data.sem_info.timeout;
190 break;
191 case OperationType::POLLING:
192 data.status = op.data.status;
193 break;
194 case OperationType::NONE:
195 break;
196 }
197 }

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

237 {
238 if (type == OperationType::POLLING)
239 {
240 *data.status = OperationPollingStatus::RUNNING;
241 }
242 }

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

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

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

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

◆ UpdateStatus()

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

Updates operation status based on type.

根据类型更新操作状态。

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

Definition at line 205 of file libxr_rw.hpp.

206 {
207 switch (type)
208 {
209 case OperationType::CALLBACK:
210 data.callback->Run(in_isr, std::forward<Args>(args)...);
211 break;
212 case OperationType::BLOCK:
213 data.sem_info.sem->PostFromCallback(in_isr);
214 break;
215 case OperationType::POLLING:
216 *data.status = OperationPollingStatus::DONE;
217 break;
218 case OperationType::NONE:
219 break;
220 }
221 }
constexpr auto min(T1 a, T2 b) -> typename std::common_type< T1, T2 >::type
计算两个数的最小值

Field Documentation

◆ callback

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

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

◆ status

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

Definition at line 254 of file libxr_rw.hpp.

◆ timeout

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

Definition at line 252 of file libxr_rw.hpp.

◆ type

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

Operation type. 操作类型。

Definition at line 259 of file libxr_rw.hpp.


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