avr-classes
Public Member Functions | List of all members
TimerServiceHost< SERVICECOUNT > Class Template Reference

#include <timerservicehost.h>

Inheritance diagram for TimerServiceHost< SERVICECOUNT >:
Timer::InterruptHandler

Public Member Functions

 TimerServiceHost (Timer *timer)
 
bool add (TimerService *service)
 
void remove (TimerService *service)
 
virtual void onOutputCompareMatch (void) override
 
- Public Member Functions inherited from Timer::InterruptHandler
virtual void onOverflow (void)
 

Detailed Description

template<uint8_t SERVICECOUNT>
class TimerServiceHost< SERVICECOUNT >

The TimerServiceHost template class is designed to host services derived from Service which can be added and removed at runtime. The host registers as interrupt handler at the Timer instance passed to the constructor, forwarding all Output Compare Match interrupts to the Service::onTick methods. The timer services can implement specific behavior, such as cyclic event creation or time measuring.

Parameters
SERVICECOUNTMaximum number of services that can be registered.

Constructor & Destructor Documentation

◆ TimerServiceHost()

template<uint8_t SERVICECOUNT>
TimerServiceHost< SERVICECOUNT >::TimerServiceHost ( Timer timer)
inline

Constructor.

Parameters
timerPointer to timer instance used by this TimeServiceHost instance.

Member Function Documentation

◆ add()

template<uint8_t SERVICECOUNT>
bool TimerServiceHost< SERVICECOUNT >::add ( TimerService service)
inline

Adds a service. A service can be added only once.

Parameters
serviceService to add.
Returns
True if adding was successful, false otherwise.

◆ onOutputCompareMatch()

template<uint8_t SERVICECOUNT>
virtual void TimerServiceHost< SERVICECOUNT >::onOutputCompareMatch ( void  )
inlineoverridevirtual

Handler for Output Compare Match interrupt.

Reimplemented from Timer::InterruptHandler.

◆ remove()

template<uint8_t SERVICECOUNT>
void TimerServiceHost< SERVICECOUNT >::remove ( TimerService service)
inline

Removes a service.

Parameters
serviceService to remove.