Embedded Artistry Framework
Embedded Systems C++ Framework
Public Member Functions | Private Member Functions | Private Attributes | Friends | List of all members
embvm::TimerManager< TMaxTimers, TLock, TTimeUnit, TTimeoutCallback, TTimerDevice >::TimerHandle Class Reference

Handle to a software timer. More...

#include <timer_manager.hpp>

Public Member Functions

 TimerHandle () noexcept
 Default constructor which creates an invalid object. More...
 
 ~TimerHandle () noexcept
 Destroying the TimerHandle also deletes it from the TimerManager's timer allocation queue. More...
 
 TimerHandle (TimerHandle &&rhs) noexcept
 Move Constructor. More...
 
TimerHandleoperator= (TimerHandle &&rhs) noexcept
 Move assignment operator. More...
 
 TimerHandle (const TimerHandle &)=delete
 Delete the copy constructor. More...
 
const TimerHandleoperator= (const TimerHandle &)=delete
 Delete the copy assignment operator. More...
 
bool valid () const noexcept
 Check if the TimerHandle is valid. More...
 
 operator bool () const noexcept
 Operator bool checks validity. More...
 
void destroy () noexcept
 Destroy the TimerHandle. More...
 
bool cancel () noexcept
 Cancel a software timer. More...
 
template<typename TRep , typename TPeriod >
void asyncDelay (const std::chrono::duration< TRep, TPeriod > &delay, const TTimeoutCallback &func) noexcept
 Configure a one-shot delay. More...
 
template<typename TRep , typename TPeriod >
void asyncDelay (const std::chrono::duration< TRep, TPeriod > &delay, TTimeoutCallback &&func) noexcept
 Configure a one-shot delay. More...
 
template<typename TRep , typename TPeriod >
void periodicDelay (const std::chrono::duration< TRep, TPeriod > &delay, const TTimeoutCallback &func) noexcept
 Configure a periodic delay. More...
 
template<typename TRep , typename TPeriod >
void periodicDelay (const std::chrono::duration< TRep, TPeriod > &delay, TTimeoutCallback &&func) noexcept
 Configure a periodic delay. More...
 

Private Member Functions

 TimerHandle (TimerManager *mgr) noexcept
 Private constructor, used by TimerManager::allocate() to create new TimerHandle instances. More...
 

Private Attributes

TimerManagermgr_
 The owning TimerManager. More...
 
TQueueHandle handle_
 The handle for the delayInfo structure which corresponds with this timer. More...
 

Friends

class TimerManager< TMaxTimers, TLock, TTimeUnit, TTimeoutCallback, TTimerDevice >
 

Detailed Description

template<const size_t TMaxTimers = 0, typename TLock = embutil::nop_lock, typename TTimeUnit = embvm::timer::timer_period_t, typename TTimeoutCallback = stdext::inplace_function<void()>, typename TTimerDevice = embvm::timer::Timer>
class embvm::TimerManager< TMaxTimers, TLock, TTimeUnit, TTimeoutCallback, TTimerDevice >::TimerHandle

Handle to a software timer.

TimerHandle represents a handle to an event registration. TimerHandle are created during the TimerManager::allocate() process.

The handle is used to schedule delays:

auto h = tm.allocate();
h.asyncDelay(std::chrono::milliseconds(1), cb_called);

The lifetime of the TimerHandle controls the lifetime of the software timer. If the handle leaves scope, the timer will be automatically unregistered.

Template parameters simply match those in the original TimerManager declaration, since TimerHandle is a class member.

Constructor & Destructor Documentation

◆ TimerHandle() [1/4]

template<const size_t TMaxTimers = 0, typename TLock = embutil::nop_lock, typename TTimeUnit = embvm::timer::timer_period_t, typename TTimeoutCallback = stdext::inplace_function<void()>, typename TTimerDevice = embvm::timer::Timer>
embvm::TimerManager< TMaxTimers, TLock, TTimeUnit, TTimeoutCallback, TTimerDevice >::TimerHandle::TimerHandle ( )
inlinenoexcept

Default constructor which creates an invalid object.

◆ ~TimerHandle()

template<const size_t TMaxTimers = 0, typename TLock = embutil::nop_lock, typename TTimeUnit = embvm::timer::timer_period_t, typename TTimeoutCallback = stdext::inplace_function<void()>, typename TTimerDevice = embvm::timer::Timer>
embvm::TimerManager< TMaxTimers, TLock, TTimeUnit, TTimeoutCallback, TTimerDevice >::TimerHandle::~TimerHandle ( )
inlinenoexcept

Destroying the TimerHandle also deletes it from the TimerManager's timer allocation queue.

◆ TimerHandle() [2/4]

template<const size_t TMaxTimers = 0, typename TLock = embutil::nop_lock, typename TTimeUnit = embvm::timer::timer_period_t, typename TTimeoutCallback = stdext::inplace_function<void()>, typename TTimerDevice = embvm::timer::Timer>
embvm::TimerManager< TMaxTimers, TLock, TTimeUnit, TTimeoutCallback, TTimerDevice >::TimerHandle::TimerHandle ( TimerHandle &&  rhs)
inlinenoexcept

Move Constructor.

◆ TimerHandle() [3/4]

template<const size_t TMaxTimers = 0, typename TLock = embutil::nop_lock, typename TTimeUnit = embvm::timer::timer_period_t, typename TTimeoutCallback = stdext::inplace_function<void()>, typename TTimerDevice = embvm::timer::Timer>
embvm::TimerManager< TMaxTimers, TLock, TTimeUnit, TTimeoutCallback, TTimerDevice >::TimerHandle::TimerHandle ( const TimerHandle )
delete

Delete the copy constructor.

◆ TimerHandle() [4/4]

template<const size_t TMaxTimers = 0, typename TLock = embutil::nop_lock, typename TTimeUnit = embvm::timer::timer_period_t, typename TTimeoutCallback = stdext::inplace_function<void()>, typename TTimerDevice = embvm::timer::Timer>
embvm::TimerManager< TMaxTimers, TLock, TTimeUnit, TTimeoutCallback, TTimerDevice >::TimerHandle::TimerHandle ( TimerManager mgr)
inlineexplicitprivatenoexcept

Private constructor, used by TimerManager::allocate() to create new TimerHandle instances.

Member Function Documentation

◆ asyncDelay() [1/2]

template<const size_t TMaxTimers = 0, typename TLock = embutil::nop_lock, typename TTimeUnit = embvm::timer::timer_period_t, typename TTimeoutCallback = stdext::inplace_function<void()>, typename TTimerDevice = embvm::timer::Timer>
template<typename TRep , typename TPeriod >
void embvm::TimerManager< TMaxTimers, TLock, TTimeUnit, TTimeoutCallback, TTimerDevice >::TimerHandle::asyncDelay ( const std::chrono::duration< TRep, TPeriod > &  delay,
const TTimeoutCallback &  func 
)
inlinenoexcept

Configure a one-shot delay.

Configure the software timer to perform a one-shot asynchronous delay. When the timer expires, the callback will be called. The timer will be removed from the scheduled queue.

Precondition
The TimerHandle is valid.
Postcondition
The periodic delay is scheduled.

The following template parameters should be automatically deduced by the compiler:

Template Parameters
TRepUnderlying storage type (representation) for the time units (e.g., uint32_t, uint64_t)
TPeriodA std::ratio representing the tick period (e.g., std::nano)
Parameters
[in]delaystd::chrono::duration representing the periodic timeout value delta. For example:
std::chrono::duration<uint64_t, std::nano> delay = std::chrono::nanoseconds(1000);
[in]funcFunction object that will be registered as the software timer callback.

References assert, and embvm::timer::oneshot.

◆ asyncDelay() [2/2]

template<const size_t TMaxTimers = 0, typename TLock = embutil::nop_lock, typename TTimeUnit = embvm::timer::timer_period_t, typename TTimeoutCallback = stdext::inplace_function<void()>, typename TTimerDevice = embvm::timer::Timer>
template<typename TRep , typename TPeriod >
void embvm::TimerManager< TMaxTimers, TLock, TTimeUnit, TTimeoutCallback, TTimerDevice >::TimerHandle::asyncDelay ( const std::chrono::duration< TRep, TPeriod > &  delay,
TTimeoutCallback &&  func 
)
inlinenoexcept

Configure a one-shot delay.

Configure the software timer to perform a one-shot asynchronous delay. When the timer expires, the callback will be called. The timer will be removed from the scheduled queue.

Precondition
The TimerHandle is valid.
Postcondition
The periodic delay is scheduled.

The following template parameters should be automatically deduced by the compiler:

Template Parameters
TRepUnderlying storage type (representation) for the time units (e.g., uint32_t, uint64_t)
TPeriodA std::ratio representing the tick period (e.g., std::nano)
Parameters
[in]delaystd::chrono::duration representing the periodic timeout value delta. For example:
std::chrono::duration<uint64_t, std::nano> delay = std::chrono::nanoseconds(1000);
[in]funcR-value function object that will be registered as the software timer callback.

References assert, and embvm::timer::oneshot.

◆ cancel()

template<const size_t TMaxTimers = 0, typename TLock = embutil::nop_lock, typename TTimeUnit = embvm::timer::timer_period_t, typename TTimeoutCallback = stdext::inplace_function<void()>, typename TTimerDevice = embvm::timer::Timer>
bool embvm::TimerManager< TMaxTimers, TLock, TTimeUnit, TTimeoutCallback, TTimerDevice >::TimerHandle::cancel ( )
inlinenoexcept

Cancel a software timer.

Request cancellation for a software timer. The cancellation request is best-effort, and the timer may expire before the request is completed.

Precondition
The TimerHandle is valid
Postcondition
The timer is cancelled, or has expired before cancellation was carried out.
Returns
True if the timer was cancelled, false if the timer expired before cancellation.

References assert.

◆ destroy()

template<const size_t TMaxTimers = 0, typename TLock = embutil::nop_lock, typename TTimeUnit = embvm::timer::timer_period_t, typename TTimeoutCallback = stdext::inplace_function<void()>, typename TTimerDevice = embvm::timer::Timer>
void embvm::TimerManager< TMaxTimers, TLock, TTimeUnit, TTimeoutCallback, TTimerDevice >::TimerHandle::destroy ( )
inlinenoexcept

Destroy the TimerHandle.

If the TimerHandle is invalid (i.e. already destroyed), the request will be ignored.

◆ operator bool()

template<const size_t TMaxTimers = 0, typename TLock = embutil::nop_lock, typename TTimeUnit = embvm::timer::timer_period_t, typename TTimeoutCallback = stdext::inplace_function<void()>, typename TTimerDevice = embvm::timer::Timer>
embvm::TimerManager< TMaxTimers, TLock, TTimeUnit, TTimeoutCallback, TTimerDevice >::TimerHandle::operator bool ( ) const
inlinenoexcept

Operator bool checks validity.

Operator bool() is used to check that a TimerHandle is valid.

Returns
true if the TimerHandle is valid, false otherwise

◆ operator=() [1/2]

template<const size_t TMaxTimers = 0, typename TLock = embutil::nop_lock, typename TTimeUnit = embvm::timer::timer_period_t, typename TTimeoutCallback = stdext::inplace_function<void()>, typename TTimerDevice = embvm::timer::Timer>
TimerHandle& embvm::TimerManager< TMaxTimers, TLock, TTimeUnit, TTimeoutCallback, TTimerDevice >::TimerHandle::operator= ( TimerHandle &&  rhs)
inlinenoexcept

Move assignment operator.

References swap.

◆ operator=() [2/2]

template<const size_t TMaxTimers = 0, typename TLock = embutil::nop_lock, typename TTimeUnit = embvm::timer::timer_period_t, typename TTimeoutCallback = stdext::inplace_function<void()>, typename TTimerDevice = embvm::timer::Timer>
const TimerHandle& embvm::TimerManager< TMaxTimers, TLock, TTimeUnit, TTimeoutCallback, TTimerDevice >::TimerHandle::operator= ( const TimerHandle )
delete

Delete the copy assignment operator.

◆ periodicDelay() [1/2]

template<const size_t TMaxTimers = 0, typename TLock = embutil::nop_lock, typename TTimeUnit = embvm::timer::timer_period_t, typename TTimeoutCallback = stdext::inplace_function<void()>, typename TTimerDevice = embvm::timer::Timer>
template<typename TRep , typename TPeriod >
void embvm::TimerManager< TMaxTimers, TLock, TTimeUnit, TTimeoutCallback, TTimerDevice >::TimerHandle::periodicDelay ( const std::chrono::duration< TRep, TPeriod > &  delay,
const TTimeoutCallback &  func 
)
inlinenoexcept

Configure a periodic delay.

Configure the software timer to perform a periodic delay. When the timer expires, the callback will be called adn the timer will be automatically re-added to the scheduled timer queue.

Precondition
The TimerHandle is valid.
Postcondition
The periodic delay is scheduled.

The following template parameters should be automatically deduced by the compiler:

Template Parameters
TRepUnderlying storage type (representation) for the time units (e.g., uint32_t, uint64_t)
TPeriodA std::ratio representing the tick period (e.g., std::nano)
Parameters
[in]delaystd::chrono::duration representing the periodic timeout value delta. For example:
std::chrono::duration<uint64_t, std::nano> delay = std::chrono::nanoseconds(1000);
[in]funcFunction object that will be registered as the software timer callback.

References assert, and embvm::timer::periodic.

◆ periodicDelay() [2/2]

template<const size_t TMaxTimers = 0, typename TLock = embutil::nop_lock, typename TTimeUnit = embvm::timer::timer_period_t, typename TTimeoutCallback = stdext::inplace_function<void()>, typename TTimerDevice = embvm::timer::Timer>
template<typename TRep , typename TPeriod >
void embvm::TimerManager< TMaxTimers, TLock, TTimeUnit, TTimeoutCallback, TTimerDevice >::TimerHandle::periodicDelay ( const std::chrono::duration< TRep, TPeriod > &  delay,
TTimeoutCallback &&  func 
)
inlinenoexcept

Configure a periodic delay.

Configure the software timer to perform a periodic delay. When the timer expires, the callback will be called adn the timer will be automatically re-added to the scheduled timer queue.

Precondition
The TimerHandle is valid.
Postcondition
The periodic delay is scheduled.

The following template parameters should be automatically deduced by the compiler:

Template Parameters
TRepUnderlying storage type (representation) for the time units (e.g., uint32_t, uint64_t)
TPeriodA std::ratio representing the tick period (e.g., std::nano)
Parameters
[in]delaystd::chrono::duration representing the periodic timeout value delta. For example:
std::chrono::duration<uint64_t, std::nano> delay = std::chrono::nanoseconds(1000);
[in]funcR-value function object that will be registered as the software timer callback.

References assert, and embvm::timer::periodic.

◆ valid()

template<const size_t TMaxTimers = 0, typename TLock = embutil::nop_lock, typename TTimeUnit = embvm::timer::timer_period_t, typename TTimeoutCallback = stdext::inplace_function<void()>, typename TTimerDevice = embvm::timer::Timer>
bool embvm::TimerManager< TMaxTimers, TLock, TTimeUnit, TTimeoutCallback, TTimerDevice >::TimerHandle::valid ( ) const
inlinenoexcept

Check if the TimerHandle is valid.

Returns
true if the TimerHandle is valid, false otherwise

Friends And Related Function Documentation

◆ TimerManager< TMaxTimers, TLock, TTimeUnit, TTimeoutCallback, TTimerDevice >

template<const size_t TMaxTimers = 0, typename TLock = embutil::nop_lock, typename TTimeUnit = embvm::timer::timer_period_t, typename TTimeoutCallback = stdext::inplace_function<void()>, typename TTimerDevice = embvm::timer::Timer>
friend class TimerManager< TMaxTimers, TLock, TTimeUnit, TTimeoutCallback, TTimerDevice >
friend

Member Data Documentation

◆ handle_

template<const size_t TMaxTimers = 0, typename TLock = embutil::nop_lock, typename TTimeUnit = embvm::timer::timer_period_t, typename TTimeoutCallback = stdext::inplace_function<void()>, typename TTimerDevice = embvm::timer::Timer>
TQueueHandle embvm::TimerManager< TMaxTimers, TLock, TTimeUnit, TTimeoutCallback, TTimerDevice >::TimerHandle::handle_
private

The handle for the delayInfo structure which corresponds with this timer.

◆ mgr_

template<const size_t TMaxTimers = 0, typename TLock = embutil::nop_lock, typename TTimeUnit = embvm::timer::timer_period_t, typename TTimeoutCallback = stdext::inplace_function<void()>, typename TTimerDevice = embvm::timer::Timer>
TimerManager* embvm::TimerManager< TMaxTimers, TLock, TTimeUnit, TTimeoutCallback, TTimerDevice >::TimerHandle::mgr_
private

The owning TimerManager.


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