Bluenet  5.7.0
Bluenet, firmware for nRF52 smart home devices
Loading...
Searching...
No Matches
Component Class Reference

Helper class to manage decoupling of components. More...

#include <cs_Component.h>

Inheritance diagram for Component:
Collaboration diagram for Component:

Public Member Functions

template<class T >
T * getComponent (Component *requester=nullptr)
 Returns a component of type T* from _parent->children(), If not found try again with ancestors: _parent-> ... ->_parent->children(). More...
 
virtual cs_ret_code_t init ()
 Components can implement this if they need to get references to sibling or if they need to do specific initialization. More...
 
void parentAllChildren ()
 utility that loops over all elements of getChildren() and setParent on the non-nullptr ones. More...
 
virtual ~Component ()=default
 

Protected Member Functions

virtual std::vector< Component * > getChildren ()
 Components with children can override this method to return them. More...
 
cs_ret_code_t initChildren ()
 
void setParent (Component *p)
 Children that are instantiated later can also be added individually. More...
 

Private Attributes

Component_parent = nullptr
 

Detailed Description

Helper class to manage decoupling of components.

Features that have many parts, can be organized in components E.g.:

AssetFiltering

These parts may depend on each other, but we don't want to expose their existance to the whole firmware through global/static variables.

Using this class 'sibling components' can query for each others presence in a unified way, without need for static classes or other rigid dependencies.

Constructor & Destructor Documentation

◆ ~Component()

virtual Component::~Component ( )
virtualdefault

Member Function Documentation

◆ getChildren()

virtual std::vector< Component * > Component::getChildren ( )
inlineprotectedvirtual

Components with children can override this method to return them.

This is used by getComponent<> to search for available components.

Reimplemented in Crownstone, AssetFiltering, and SwitchAggregator.

◆ getComponent()

template<class T >
T * Component::getComponent ( Component requester = nullptr)

Returns a component of type T* from _parent->children(), If not found try again with ancestors: _parent-> ... ->_parent->children().

If none-exists, a nullptr is returned.

Usage: auto sibling = getComponent<SiblingComponentType>();

◆ init()

virtual cs_ret_code_t Component::init ( )
inlinevirtual

Components can implement this if they need to get references to sibling or if they need to do specific initialization.

  • Components are responsible for calling init() on their children.
  • init is allowed to assume all siblings are constructed.

E.g.

class componentX : public Component { public: cs_ret_code_t init() { // construct childA ... // construct childZ

return initChildren(); } };

Reimplemented in AssetFiltering, AssetFilterStore, AssetFilterSyncer, AssetForwarder, BehaviourHandler, BehaviourStore, TwilightHandler, AssetStore, NearestCrownstoneTracker, and PresenceHandler.

◆ initChildren()

cs_ret_code_t Component::initChildren ( )
protected
  • parent all non-nullptr children.
  • init all non-nullptr children.

Components are not required to use this. They can call all inits of children in custom order if they need to. (And implement elegant failure.)

Initialisation is in order of the elements of the returnvalue of getChildren.

◆ parentAllChildren()

void Component::parentAllChildren ( )

utility that loops over all elements of getChildren() and setParent on the non-nullptr ones.

◆ setParent()

void Component::setParent ( Component p)
protected

Children that are instantiated later can also be added individually.

Member Data Documentation

◆ _parent

Component* Component::_parent = nullptr
private

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