mirror of
https://github.com/ETLCPP/etl.git
synced 2026-10-28 18:07:10 +08:00
Added timer_node and timer_config docs
Added is_registered test to intrusive_timer
This commit is contained in:
parent
74634a54fb
commit
0d41528005
206
docs/timers/timer-node.md
Normal file
206
docs/timers/timer-node.md
Normal file
@ -0,0 +1,206 @@
|
||||
---
|
||||
title: "timer_config / timer_node"
|
||||
---
|
||||
|
||||
{{< callout type="info">}}
|
||||
Header: `timer_node.h`
|
||||
Since: `20.46.0`
|
||||
From: `C++03`
|
||||
{{< /callout >}}
|
||||
|
||||
|
||||
## Class diagram
|
||||
```mermaid
|
||||
classDiagram
|
||||
timer_node <|-- timer_callback_node
|
||||
timer_node <|-- timer_message_node
|
||||
|
||||
timer_node "1" *-- "*" timer_config : contains
|
||||
|
||||
class timer_config {
|
||||
+timer_config()
|
||||
+get_interval() const uint32_t
|
||||
+get_mode() const uint32_t
|
||||
+get_id() const etl::timer::id::type
|
||||
+clear() void
|
||||
}
|
||||
|
||||
class timer_node {
|
||||
+timer_node()
|
||||
+get_config() timer_config&
|
||||
+get_delta() uint32_t
|
||||
+get_interval() uint32_t
|
||||
+get_mode() uint32_t
|
||||
+get_id() etl::timer::id::type
|
||||
+static end() etl::timer_node*
|
||||
}
|
||||
|
||||
class timer_node {
|
||||
+virtual invoke() void
|
||||
}
|
||||
|
||||
class timer_callback_node {
|
||||
+timer_callback_node()
|
||||
+invoke() void override
|
||||
}
|
||||
|
||||
class timer_message_node {
|
||||
+timer_message_node()
|
||||
+invoke() void override
|
||||
}
|
||||
```
|
||||
|
||||
---
|
||||
|
||||
These are supporting class types for `etl::intrusive_timer`.
|
||||
|
||||
## timer_config
|
||||
```cpp
|
||||
class timer_config
|
||||
```
|
||||
**Description**
|
||||
Contains the configuration for a timer.
|
||||
|
||||
---
|
||||
|
||||
```cpp
|
||||
ETL_CONSTEXPR timer_config(uint32_t interval, etl::timer::mode::type mode) ETL_NOEXCEPT
|
||||
```
|
||||
**Description**
|
||||
Constructs a timer configuration.
|
||||
|
||||
**Parameters**
|
||||
`uint32_t interval` : The initial interval for the timer.
|
||||
`etl::timer::mode::type mode` : The initial mode of the timer.
|
||||
|
||||
---
|
||||
|
||||
```cpp
|
||||
ETL_CONSTEXPR uint32_t get_interval() const ETL_NOEXCEPT
|
||||
```
|
||||
**Description**
|
||||
Returns the interval of the timer.
|
||||
|
||||
---
|
||||
|
||||
```cpp
|
||||
ETL_CONSTEXPR etl::timer::mode::type get_mode() const ETL_NOEXCEPT
|
||||
```
|
||||
**Description**
|
||||
Returns the mode of the timer.
|
||||
`etl::timer::mode::No_Mode_Set`
|
||||
`etl::timer::mode::Single_Shot`
|
||||
`etl::timer::mode::Repeating`
|
||||
|
||||
---
|
||||
|
||||
```cpp
|
||||
ETL_CONSTEXPR etl::timer::id::type get_id() const ETL_NOEXCEPT
|
||||
```
|
||||
**Description**
|
||||
Returns the id of the timer.
|
||||
The timer ID is set by registering a node that contains this configuration with an `etl::intrusive_timer`.
|
||||
|
||||
---
|
||||
|
||||
```cpp
|
||||
ETL_CONSTEXPR14 void clear() ETL_NOEXCEPT
|
||||
```
|
||||
**Description**
|
||||
Clears the timer configuration.
|
||||
Interval = `etl::timer::interval::No_Active_Interval`
|
||||
Mode = `etl::timer::mode::No_Mode_Set`
|
||||
ID = `etl::timer::id::No_Timer`
|
||||
|
||||
## timer_node
|
||||
```cpp
|
||||
class timer_node
|
||||
```
|
||||
**Description**
|
||||
Base class for all timer nodes.
|
||||
|
||||
---
|
||||
|
||||
```cpp
|
||||
timer_node(const timer_config& config_) ETL_NOEXCEPT
|
||||
```
|
||||
**Description**
|
||||
Construct from an `etl::timer_config`.
|
||||
|
||||
---
|
||||
|
||||
```cpp
|
||||
timer_node(const timer_node& node_) ETL_NOEXCEPT
|
||||
```
|
||||
**Description**
|
||||
Copy constructor.
|
||||
|
||||
---
|
||||
|
||||
```cpp
|
||||
const timer_config& get_config() const ETL_NOEXCEPT
|
||||
```
|
||||
**Description**
|
||||
Returns the configuration of the timer.
|
||||
|
||||
---
|
||||
|
||||
```cpp
|
||||
ETL_CONSTEXPR uint32_t get_delta() const ETL_NOEXCEPT
|
||||
```
|
||||
**Description**
|
||||
Returns the delta of the timer.
|
||||
|
||||
---
|
||||
|
||||
```cpp
|
||||
ETL_CONSTEXPR uint32_t get_interval() const ETL_NOEXCEPT
|
||||
```
|
||||
**Description**
|
||||
Returns the interval of the timer.
|
||||
|
||||
---
|
||||
|
||||
```cpp
|
||||
ETL_CONSTEXPR etl::timer::mode::type get_mode() const ETL_NOEXCEPT
|
||||
```
|
||||
**Description**
|
||||
Returns the mode of the timer.
|
||||
`etl::timer::mode::No_Mode_Set`
|
||||
`etl::timer::mode::Single_Shot`
|
||||
`etl::timer::mode::Repeating`
|
||||
|
||||
---
|
||||
|
||||
```cpp
|
||||
ETL_CONSTEXPR etl::timer::id::type get_id() const ETL_NOEXCEPT
|
||||
```
|
||||
**Description**
|
||||
Returns the id of the timer.
|
||||
|
||||
---
|
||||
|
||||
```cpp
|
||||
static etl::timer_node* end() ETL_NOEXCEPT
|
||||
```
|
||||
**Description**
|
||||
Returns a pointer to the static sentinel timer node used to mark the end of the intrusive timer lists.
|
||||
|
||||
## timer_callback_node
|
||||
```cpp
|
||||
template <typename TCallback>
|
||||
class timer_callback_node : public etl::timer_node
|
||||
```
|
||||
**Description**
|
||||
A timer node for a function callback using `etl::delegate`, `etl::inplace_function`, or similar.
|
||||
Derived from `etl::timer_node`.
|
||||
|
||||
## timer_message_node
|
||||
```cpp
|
||||
template <typename TMessage>
|
||||
class timer_message_node : public etl::timer_node
|
||||
```
|
||||
**Description**
|
||||
A timer node for a message callback using an `etl::message` derived object.
|
||||
Derived from `etl::timer_node`.
|
||||
Static asserts if `TMessage` is not derived from `etl::imessage`.
|
||||
@ -422,6 +422,20 @@ namespace etl
|
||||
return delta;
|
||||
}
|
||||
|
||||
//*******************************************
|
||||
/// Check if a timer is registered with this timer.
|
||||
//*******************************************
|
||||
bool is_registered(const etl::timer_node& timer_) const ETL_NOEXCEPT
|
||||
{
|
||||
lock_policy.lock();
|
||||
|
||||
bool is_registered = timer_.is_registered_with(this);
|
||||
|
||||
lock_policy.unlock();
|
||||
|
||||
return is_registered;
|
||||
}
|
||||
|
||||
//*******************************************
|
||||
/// Returns the number of registered timers.
|
||||
//*******************************************
|
||||
|
||||
@ -74,12 +74,22 @@ namespace etl
|
||||
friend class timer_node;
|
||||
friend class intrusive_timer;
|
||||
|
||||
//*******************************************
|
||||
/// Default constructor.
|
||||
//*******************************************
|
||||
ETL_CONSTEXPR timer_config() ETL_NOEXCEPT
|
||||
: interval(etl::timer::interval::No_Active_Interval)
|
||||
, mode(etl::timer::mode::No_Mode_Set)
|
||||
, id(etl::timer::id::No_Timer)
|
||||
{
|
||||
}
|
||||
|
||||
//*******************************************
|
||||
/// Constructor.
|
||||
//*******************************************
|
||||
ETL_CONSTEXPR timer_config(uint32_t interval_, etl::timer::mode::type repeating_) ETL_NOEXCEPT
|
||||
ETL_CONSTEXPR timer_config(uint32_t interval_, etl::timer::mode::type mode_) ETL_NOEXCEPT
|
||||
: interval(interval_)
|
||||
, mode(repeating_)
|
||||
, mode(mode_)
|
||||
, id(etl::timer::id::No_Timer)
|
||||
{
|
||||
}
|
||||
@ -95,7 +105,7 @@ namespace etl
|
||||
//*******************************************
|
||||
/// Returns the mode of the timer.
|
||||
//*******************************************
|
||||
ETL_CONSTEXPR uint32_t get_mode() const ETL_NOEXCEPT
|
||||
ETL_CONSTEXPR etl::timer::mode::type get_mode() const ETL_NOEXCEPT
|
||||
{
|
||||
return mode;
|
||||
}
|
||||
@ -125,8 +135,6 @@ namespace etl
|
||||
etl::timer::id::type id; ///< The id of the timer.
|
||||
};
|
||||
|
||||
class sentinal_node;
|
||||
|
||||
//***************************************************************************
|
||||
/// A timer data structure that can be linked into the timer lists.
|
||||
/// Contains a timer configuration.
|
||||
@ -211,7 +219,7 @@ namespace etl
|
||||
//*******************************************
|
||||
/// Returns the mode of the timer.
|
||||
//*******************************************
|
||||
ETL_CONSTEXPR uint32_t get_mode() const ETL_NOEXCEPT
|
||||
ETL_CONSTEXPR etl::timer::mode::type get_mode() const ETL_NOEXCEPT
|
||||
{
|
||||
return config.get_mode();
|
||||
}
|
||||
@ -225,7 +233,7 @@ namespace etl
|
||||
}
|
||||
|
||||
//***************************************************************************
|
||||
/// Returns a reference to the sentinel timer node used to mark the end of
|
||||
/// Returns a pointer to the static sentinel timer node used to mark the end of
|
||||
/// the intrusive timer lists.
|
||||
/// Implemented as a function-local static so that there is only ever one
|
||||
/// instance, regardless of how many translation units include this header.
|
||||
@ -242,7 +250,7 @@ namespace etl
|
||||
private:
|
||||
|
||||
//*******************************************
|
||||
/// Returns the configuration of the timer.
|
||||
/// Sets the configuration of the timer.
|
||||
//*******************************************
|
||||
void set_config(const timer_config& config_) ETL_NOEXCEPT
|
||||
{
|
||||
@ -306,7 +314,7 @@ namespace etl
|
||||
//*******************************************
|
||||
/// Returns true if the timer is registered to the specified owner.
|
||||
//*******************************************
|
||||
bool is_registered_with(void* owner_) const ETL_NOEXCEPT
|
||||
bool is_registered_with(const void* owner_) const ETL_NOEXCEPT
|
||||
{
|
||||
return (registered_next != unlinked()) && (owner == owner_);
|
||||
}
|
||||
@ -385,6 +393,8 @@ namespace etl
|
||||
template <typename TMessage>
|
||||
struct timer_message_node : public timer_node
|
||||
{
|
||||
ETL_STATIC_ASSERT((etl::is_base_of<etl::imessage, TMessage>::value), "TMessage must derive from etl::imessage");
|
||||
|
||||
//*******************************************
|
||||
/// Constructor.
|
||||
//*******************************************
|
||||
|
||||
@ -248,12 +248,22 @@ namespace
|
||||
etl::timer_node node2(etl::timer_config(200, etl::timer::mode::Repeating));
|
||||
etl::timer_node node3(etl::timer_config(300, etl::timer::mode::Repeating));
|
||||
|
||||
CHECK_FALSE(timer_controller.is_registered(node1));
|
||||
CHECK_FALSE(timer_controller.is_registered(node2));
|
||||
CHECK_FALSE(timer_controller.is_registered(node3));
|
||||
|
||||
CHECK_TRUE(timer_controller.register_timer(node1));
|
||||
CHECK_TRUE(timer_controller.is_registered(node1));
|
||||
CHECK_EQUAL(1U, timer_controller.number_of_timers());
|
||||
|
||||
CHECK_TRUE(timer_controller.register_timer(node2));
|
||||
CHECK_TRUE(timer_controller.is_registered(node2));
|
||||
CHECK_EQUAL(2U, timer_controller.number_of_timers());
|
||||
|
||||
CHECK_TRUE(timer_controller.register_timer(node3));
|
||||
CHECK_TRUE(timer_controller.is_registered(node3));
|
||||
CHECK_EQUAL(3U, timer_controller.number_of_timers());
|
||||
|
||||
CHECK_FALSE(timer_controller.is_running());
|
||||
CHECK_EQUAL(0U, lock_policy.get_count());
|
||||
}
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user