AlexaClientSDK  3.0.0
A cross-platform, modular SDK for interacting with the Alexa Voice Service
Public Member Functions | List of all members
alexaClientSDK::notifier::Notifier< ObserverType > Class Template Reference

Generic implementation of NotifierInterface. More...

#include <Notifier.h>

Inheritance diagram for alexaClientSDK::notifier::Notifier< ObserverType >:
Inheritance graph
[legend]
Collaboration diagram for alexaClientSDK::notifier::Notifier< ObserverType >:
Collaboration graph
[legend]

Public Member Functions

 Notifier ()
 
NotifierInterface methods
void addObserver (const std::shared_ptr< ObserverType > &observer) override
 Add an observer. More...
 
void removeObserver (const std::shared_ptr< ObserverType > &observer) override
 Remove an observer. More...
 
void addWeakPtrObserver (const std::weak_ptr< ObserverType > &observer) override
 Add a weak reference to an observer. More...
 
void removeWeakPtrObserver (const std::weak_ptr< ObserverType > &observer) override
 Remove an observer. More...
 
void notifyObservers (std::function< void(const std::shared_ptr< ObserverType > &)> notify) override
 Notify the observers in the order that they were added. More...
 
bool notifyObserversInReverse (std::function< void(const std::shared_ptr< ObserverType > &)> notify) override
 Notify the observers in the reverse order that they were added. More...
 
void setAddObserverFunction (std::function< void(const std::shared_ptr< ObserverType > &)> addObserverFunc) override
 Set a function for notifications on an observer additions. More...
 
- Public Member Functions inherited from alexaClientSDK::notifierInterfaces::NotifierInterface< ObserverType >
virtual ~NotifierInterface ()=default
 

Detailed Description

template<typename ObserverType>
class alexaClientSDK::notifier::Notifier< ObserverType >

Generic implementation of NotifierInterface.

Notifier maintains a set of observers that are notified with a caller defined function.

Template Parameters
ObserverTypeThe type of observer notified by the template instantiation.

Constructor & Destructor Documentation

◆ Notifier()

template<typename ObserverType >
alexaClientSDK::notifier::Notifier< ObserverType >::Notifier ( )
inline

Member Function Documentation

◆ addObserver()

template<typename ObserverType>
void alexaClientSDK::notifier::Notifier< ObserverType >::addObserver ( const std::shared_ptr< ObserverType > &  observer)
inlineoverridevirtual

Add an observer.

Method adds a strong reference to observer. If the same observer has already been added as a strong or weak reference, the method does nothing.

If the observer function has been installed prior to this call, it will be invoked with the newly added observer.

Parameters
[in]observerThe observer to add. If observer is nullptr, the method does nothing.
Deprecated:
In the future, Notifier will no longer maintain the life cycle of its observers. Please start using the new addWeakPtrObserver() API instead.

Implements alexaClientSDK::notifierInterfaces::NotifierInterface< ObserverType >.

◆ addWeakPtrObserver()

template<typename ObserverType>
void alexaClientSDK::notifier::Notifier< ObserverType >::addWeakPtrObserver ( const std::weak_ptr< ObserverType > &  observer)
inlineoverridevirtual

Add a weak reference to an observer.

Method adds a weak reference to observer. If the same observer has already been added as a strong or weak reference, the method does nothing.

If the observer function has been installed prior to this call, it will be invoked with the newly added observer.

Parameters
[in]observerThe observer to add. If observer is nullptr, the method does nothing.
Note
Lifecycle of observer will not be managed by the Notifier. If observer object is expired, then no callback will be called to that object.

Implements alexaClientSDK::notifierInterfaces::NotifierInterface< ObserverType >.

◆ notifyObservers()

template<typename ObserverType>
void alexaClientSDK::notifier::Notifier< ObserverType >::notifyObservers ( std::function< void(const std::shared_ptr< ObserverType > &)>  notify)
inlineoverridevirtual

Notify the observers in the order that they were added.

Parameters
[in]notifyThe function to invoke to notify an observer.

Implements alexaClientSDK::notifierInterfaces::NotifierInterface< ObserverType >.

◆ notifyObserversInReverse()

template<typename ObserverType>
bool alexaClientSDK::notifier::Notifier< ObserverType >::notifyObserversInReverse ( std::function< void(const std::shared_ptr< ObserverType > &)>  notify)
inlineoverridevirtual

Notify the observers in the reverse order that they were added.

Parameters
notifyThe function to invoke to notify an observer.
Returns
true if (and only if) all observers were notified (observers added during calls to this method will miss out).

Implements alexaClientSDK::notifierInterfaces::NotifierInterface< ObserverType >.

◆ removeObserver()

template<typename ObserverType>
void alexaClientSDK::notifier::Notifier< ObserverType >::removeObserver ( const std::shared_ptr< ObserverType > &  observer)
inlineoverridevirtual

Remove an observer.

Method removes a strong or weak reference to observer. If the class doesn't have a strong or weak reference to observer, the method does nothing.

Parameters
[in]observerThe observer to remove. If observer is nullptr, the method does nothing.
Deprecated:
In the future, Notifier will no longer maintain the life cycle of its observers. Please start using the new removeWeakPtrObserver() API instead.

Implements alexaClientSDK::notifierInterfaces::NotifierInterface< ObserverType >.

◆ removeWeakPtrObserver()

template<typename ObserverType>
void alexaClientSDK::notifier::Notifier< ObserverType >::removeWeakPtrObserver ( const std::weak_ptr< ObserverType > &  observer)
inlineoverridevirtual

Remove an observer.

Method removes a strong or weak reference to observer. If the class doesn't have a strong or weak reference to observer, the method does nothing.

Parameters
[in]observerThe observer to remove. If observer is nullptr, the method does nothing.

Implements alexaClientSDK::notifierInterfaces::NotifierInterface< ObserverType >.

◆ setAddObserverFunction()

template<typename ObserverType>
void alexaClientSDK::notifier::Notifier< ObserverType >::setAddObserverFunction ( std::function< void(const std::shared_ptr< ObserverType > &)>  postAddFunc)
inlineoverridevirtual

Set a function for notifications on an observer additions.

Set the function to be called after an observer is added (for example, to notify the newly-added observer of the current state).

If there's any observers that were added before setAddObserverFunction is called, those added observers will be notified as well.

Use caution when setting this function. The function MUST be reentrant, or else you run the risk of deadlock. When an observer adds itself to a NotifierInterface, this function will be called in the same context.

Parameters
[in]postAddFuncThe function to call after an observer is added.

Implements alexaClientSDK::notifierInterfaces::NotifierInterface< ObserverType >.


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