![]() |
AlexaClientSDK
3.0.0
A cross-platform, modular SDK for interacting with the Alexa Voice Service
|
#include <StopTaskTimer.h>
Public Member Functions | |
StopTaskTimer () | |
Constructor. More... | |
~StopTaskTimer () | |
Destructor. More... | |
TimerDelegateInterface Functions | |
void | start (std::chrono::nanoseconds delay, std::chrono::nanoseconds period, PeriodType periodType, size_t maxCount, std::function< void()> task) override |
void | stop () override |
bool | activate () override |
bool | isActive () const override |
![]() | |
virtual | ~TimerDelegateInterface ()=default |
Destructor. More... | |
Additional Inherited Members | |
![]() | |
enum | PeriodType { PeriodType::ABSOLUTE, PeriodType::RELATIVE } |
Specifies different ways to apply the period of a recurring task. More... | |
![]() | |
static size_t | getForever () |
Static member function to get FOREVER. More... | |
![]() | |
static const size_t | FOREVER = 0 |
A timer that will call the task when stop() is called. This simulates the limitation that's inherent in the Timer.h API.
Since the task() may be executing naturally when stop() is called, we synchronize the task with a lock so only one instance of it can execute at a given time.
WARNING: The task is executed during stop(), it's possible that the task will fire NOT at the scheduled intervals of the original call to start(). This does not fully conform with the Timer.h API, and should be used for very specific test cases. This should not be used outside of testing.
alexaClientSDK::avsCommon::utils::timing::test::StopTaskTimer::StopTaskTimer | ( | ) |
Constructor.
alexaClientSDK::avsCommon::utils::timing::test::StopTaskTimer::~StopTaskTimer | ( | ) |
Destructor.
|
overridevirtual |
Marks this TimerDelegateInterface
as active for strict ordering purposes. When called, the implementation must atomically set the internal state as active. Functionally this method must behave as an std::atomic_exchange operation.
true
if the Timer
was previously inactive, else false
. Implements alexaClientSDK::avsCommon::sdkInterfaces::timing::TimerDelegateInterface.
|
overridevirtual |
Reports whether the TimerDelegateInterface
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. Examples of these can be after calls to activate() or start(). 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()
.
true
if the Timer
is active, else false
. Implements alexaClientSDK::avsCommon::sdkInterfaces::timing::TimerDelegateInterface.
|
overridevirtual |
Waits for the delay
, then calls task
periodically.
delay | The non-negative time to wait before making the first task call. |
period | The non-negative time to wait between subsequent task calls. |
periodType | The type of period to use when making subsequent task calls. |
maxCount | The desired number of times to call task. TimerDelegateInterface::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. |
Implements alexaClientSDK::avsCommon::sdkInterfaces::timing::TimerDelegateInterface.
|
overridevirtual |
Stops the TimerDelegateInterface
(if running). This should 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.
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. Implements alexaClientSDK::avsCommon::sdkInterfaces::timing::TimerDelegateInterface.
AlexaClientSDK 3.0.0 - Copyright 2016-2022 Amazon.com, Inc. or its affiliates. All Rights Reserved. Licensed under the Apache License, Version 2.0