#include <Timer.h>
|
| Timer (std::shared_ptr< sdkInterfaces::timing::TimerDelegateFactoryInterface > timerDelegateFactory=avs::initialization::SDKPrimitivesProvider::getInstance() ->getTimerDelegateFactory()) |
|
| ~Timer () |
|
template<typename Rep , typename Period , typename Task , typename... Args> |
bool | start (const std::chrono::duration< Rep, Period > &delay, const std::chrono::duration< Rep, Period > &period, PeriodType periodType, size_t maxCount, Task task, Args &&... args) |
|
template<typename Rep , typename Period , typename Task , typename... Args> |
bool | start (const std::chrono::duration< Rep, Period > &period, PeriodType periodType, size_t maxCount, Task task, Args &&... args) |
|
template<typename Rep , typename Period , typename Task , typename... Args> |
auto | start (const std::chrono::duration< Rep, Period > &delay, Task task, Args &&... args) -> std::future< decltype(task(args...))> |
|
void | stop () |
|
bool | isActive () const |
|
A Timer
is used to schedule a callable type to run in the future.
◆ PeriodType
Specifies different ways to apply the period of a recurring task.
Enumerator |
---|
ABSOLUTE | The period specifies the time from the start of one task call to the start of the next task call. This period type ensures task calls occur on a predictable cadence.
- Note
- A timer makes one task call at a time, so if a task call takes more than one period to execute, the subsequent calls which would have occured while the task was still executing will be skipped, and the next call will not occur until the next period-multiple after the original task call completes.
|
RELATIVE | The period specifies the time from the end of one task call to the start of the next task call. This period type ensures a specific amount of idle time between task calls.
|
◆ Timer()
Contructs a Timer
.
- Parameters
-
◆ ~Timer()
alexaClientSDK::avsCommon::utils::timing::Timer::~Timer |
( |
| ) |
|
◆ getForever()
static size_t alexaClientSDK::avsCommon::utils::timing::Timer::getForever |
( |
| ) |
|
|
inlinestatic |
Static member function to get FOREVER.
◆ getTag()
static std::string alexaClientSDK::avsCommon::utils::timing::Timer::getTag |
( |
| ) |
|
|
inlinestatic |
Static member function to get TAG.
◆ isActive()
bool alexaClientSDK::avsCommon::utils::timing::Timer::isActive |
( |
| ) |
const |
Reports whether the Timer
is active. A timer is considered active if it is waiting to start a call to the task, or if a call to the task is in progress. A timer is only considered inactive if it has not been started, if all requested/scheduled calls to the task have completed, or after a call to stop()
.
- Returns
true
if the Timer
is active, else false
.
◆ start() [1/3]
template<typename Rep , typename Period , typename Task , typename... Args>
bool alexaClientSDK::avsCommon::utils::timing::Timer::start |
( |
const std::chrono::duration< Rep, Period > & |
delay, |
|
|
const std::chrono::duration< Rep, Period > & |
period, |
|
|
PeriodType |
periodType, |
|
|
size_t |
maxCount, |
|
|
Task |
task, |
|
|
Args &&... |
args |
|
) |
| |
Submits a callable type (function, lambda expression, bind expression, or another function object) to be executed after an initial delay, and then called repeatedly on a fixed time schedule. A Timer
instance manages only one running Timer
at a time; calling start()
on an already-running Timer
will fail. Note that the template parameters are typically inferred from the function paramters when calling start()
.
- Template Parameters
-
Rep | A type for measuring 'ticks' in a generic std::chrono::duration . |
Period | A type for representing the number of ticks per second in a generic std::chrono::duration . |
Task | The type of task to execute. |
Args | The argument types for the task to execute. |
- Parameters
-
delay | The non-negative time to wait before making the first task call. Negative values will cause this function to return false. |
period | The non-negative time to wait between subsequent task calls. Negative values will cause this function to return false. |
periodType | The type of period to use when making subsequent task calls. |
maxCount | The desired number of times to call task. Timer::getForever() means to call forever until stop() is called. Note that fewer than maxCount calls may occur if periodType is PeriodType::ABSOLUTE and the task runtime exceeds period . |
task | A callable type representing a task. |
args | The arguments to call the task with. |
- Returns
true
if the timer started, else false
.
◆ start() [2/3]
template<typename Rep , typename Period , typename Task , typename... Args>
auto alexaClientSDK::avsCommon::utils::timing::Timer::start |
( |
const std::chrono::duration< Rep, Period > & |
delay, |
|
|
Task |
task, |
|
|
Args &&... |
args |
|
) |
| -> std::future<decltype(task(args...))> |
Submits a callable type (function, lambda expression, bind expression, or another function object) to be executed once, after the specified duration. A Timer
instance manages only one running Timer
at a time; calling start()
on an already-running Timer
will fail. Note that the template parameters are typically inferred from the function paramters when calling start()
.
- Template Parameters
-
Rep | A type for measuring 'ticks' in a generic std::chrono::duration . |
Period | A type for representing the number of ticks per second in a generic std::chrono::duration . |
Task | The type of task to execute. |
Args | The argument types for the task to execute. |
- Parameters
-
delay | The non-negative time to wait before calling task . Negative values will cause this function to return an invalid future. |
task | A callable type representing a task. |
args | The arguments to call task with. |
- Returns
- A valid
std::future
for the return value of task
if the timer started, else an invalid std::future
. Note that the promise will be broken if stop()
is called before task
is called.
◆ start() [3/3]
template<typename Rep , typename Period , typename Task , typename... Args>
bool alexaClientSDK::avsCommon::utils::timing::Timer::start |
( |
const std::chrono::duration< Rep, Period > & |
period, |
|
|
PeriodType |
periodType, |
|
|
size_t |
maxCount, |
|
|
Task |
task, |
|
|
Args &&... |
args |
|
) |
| |
Submits a callable type (function, lambda expression, bind expression, or another function object) to be executed repeatedly on a fixed time schedule. A Timer
instance manages only one running Timer
at a time; calling start()
on an already-running Timer
will fail. Note that the template parameters are typically inferred from the function paramters when calling start()
.
- Template Parameters
-
Rep | A type for measuring 'ticks' in a generic std::chrono::duration . |
Period | A type for representing the number of ticks per second in a generic std::chrono::duration . |
Task | The type of task to execute. |
Args | The argument types for the task to execute. |
- Parameters
-
period | The non-negative time to wait before each task call. Negative values will cause this function to return false. |
periodType | The type of period to use when making subsequent task calls. |
maxCount | The desired number of times to call task. Timer::getForever() means to call forever until stop() is called. Note that fewer than maxCount calls may occur if periodType is PeriodType::ABSOLUTE and the task runtime exceeds period . |
task | A callable type representing a task. |
args | The arguments to call task with. |
- Returns
true
if the timer started, else false
.
◆ stop()
void alexaClientSDK::avsCommon::utils::timing::Timer::stop |
( |
| ) |
|
Stops the Timer
(if running). This will not interrupt an active call to the task, but will prevent any subequent calls to the task. If stop()
is called while the task is executing, this function will block until the task completes.
- Note
- In the special case that
stop()
is called from inside the task function, stop()
will still prevent any subsequent calls to the task, but will not block as described above.
◆ FOREVER
const size_t alexaClientSDK::avsCommon::utils::timing::Timer::FOREVER = 0 |
|
static |
Value for start()'s
maxCount
parameter which indicates that the Timer
should continue firing indefinitely.
The documentation for this class was generated from the following files:
- /workplace/avs-device-sdk/AVSCommon/Utils/include/AVSCommon/Utils/Timing/Timer.h
- /workplace/avs-device-sdk/AVSCommon/Utils/src/Timer.cpp
AlexaClientSDK 1.26.0 - Copyright 2016-2022 Amazon.com, Inc. or its affiliates. All Rights Reserved.
Licensed under the Apache License, Version 2.0