AlexaClientSDK  3.0.0
A cross-platform, modular SDK for interacting with the Alexa Voice Service
Public Types | Public Member Functions | Static Public Member Functions | Static Public Attributes | List of all members
alexaClientSDK::avsCommon::sdkInterfaces::timing::TimerDelegateInterface Class Referenceabstract

#include <TimerDelegateInterface.h>

Inheritance diagram for alexaClientSDK::avsCommon::sdkInterfaces::timing::TimerDelegateInterface:
Inheritance graph
[legend]

Public Types

enum  PeriodType { PeriodType::ABSOLUTE, PeriodType::RELATIVE }
 Specifies different ways to apply the period of a recurring task. More...
 

Public Member Functions

virtual ~TimerDelegateInterface ()=default
 Destructor. More...
 
virtual void start (std::chrono::nanoseconds delay, std::chrono::nanoseconds period, PeriodType periodType, size_t maxCount, std::function< void()> task)=0
 
virtual void stop ()=0
 
virtual bool activate ()=0
 
virtual bool isActive () const =0
 

Static Public Member Functions

static size_t getForever ()
 Static member function to get FOREVER. More...
 

Static Public Attributes

static const size_t FOREVER = 0
 

Detailed Description

A class which contains Timer logic that runs a task after a certain delay. Implementations of this MUST be thread safe.

Member Enumeration Documentation

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

Constructor & Destructor Documentation

◆ ~TimerDelegateInterface()

virtual alexaClientSDK::avsCommon::sdkInterfaces::timing::TimerDelegateInterface::~TimerDelegateInterface ( )
virtualdefault

Destructor.

Member Function Documentation

◆ activate()

virtual bool alexaClientSDK::avsCommon::sdkInterfaces::timing::TimerDelegateInterface::activate ( )
pure virtual

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.

Returns
true if the Timer was previously inactive, else false.

Implemented in alexaClientSDK::avsCommon::utils::timing::test::StopTaskTimer, alexaClientSDK::visualTimeoutManager::test::WarpTimer, and alexaClientSDK::avsCommon::utils::timing::TimerDelegate.

◆ getForever()

static size_t alexaClientSDK::avsCommon::sdkInterfaces::timing::TimerDelegateInterface::getForever ( )
inlinestatic

Static member function to get FOREVER.

◆ isActive()

virtual bool alexaClientSDK::avsCommon::sdkInterfaces::timing::TimerDelegateInterface::isActive ( ) const
pure virtual

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

Returns
true if the Timer is active, else false.

Implemented in alexaClientSDK::avsCommon::utils::timing::test::StopTaskTimer, alexaClientSDK::visualTimeoutManager::test::WarpTimer, and alexaClientSDK::avsCommon::utils::timing::TimerDelegate.

◆ start()

virtual void alexaClientSDK::avsCommon::sdkInterfaces::timing::TimerDelegateInterface::start ( std::chrono::nanoseconds  delay,
std::chrono::nanoseconds  period,
PeriodType  periodType,
size_t  maxCount,
std::function< void()>  task 
)
pure virtual

Waits for the delay, then calls task periodically.

Parameters
delayThe non-negative time to wait before making the first task call.
periodThe non-negative time to wait between subsequent task calls.
periodTypeThe type of period to use when making subsequent task calls.
maxCountThe 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.
taskA callable type representing a task.

Implemented in alexaClientSDK::avsCommon::utils::timing::test::StopTaskTimer, alexaClientSDK::visualTimeoutManager::test::WarpTimer, and alexaClientSDK::avsCommon::utils::timing::TimerDelegate.

◆ stop()

virtual void alexaClientSDK::avsCommon::sdkInterfaces::timing::TimerDelegateInterface::stop ( )
pure virtual

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.

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.

Implemented in alexaClientSDK::avsCommon::utils::timing::test::StopTaskTimer, alexaClientSDK::visualTimeoutManager::test::WarpTimer, and alexaClientSDK::avsCommon::utils::timing::TimerDelegate.

Member Data Documentation

◆ FOREVER

const size_t alexaClientSDK::avsCommon::sdkInterfaces::timing::TimerDelegateInterface::FOREVER = 0
static

Value for start()'s maxCount parameter which indicates that the TimerDelegateInterface should continue firing indefinitely.


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

AlexaClientSDK 3.0.0 - Copyright 2016-2022 Amazon.com, Inc. or its affiliates. All Rights Reserved. Licensed under the Apache License, Version 2.0