RumPi 1.0
A self-assembling C++ sensor & actuator library for the Raspberry Pi 5
RumPi::ComponentManager Class Reference

Owns and drives the set of sensor components. More...

#include <ComponentManager.h>

Inheritance diagram for RumPi::ComponentManager:
[legend]
Collaboration diagram for RumPi::ComponentManager:
[legend]

Public Member Functions

 ComponentManager (const ComponentManager &)=delete
 
ComponentManageroperator= (const ComponentManager &)=delete
 
 ComponentManager ()
 Builds an empty component manager. More...
 
virtual ~ComponentManager ()
 Frees every component the manager owns, then clears the internal map. More...
 
virtual void TurnOn () override
 Turns on every managed component. More...
 
virtual void TurnOff () override
 Turns off every managed component. More...
 
virtual std::string ToString () const override
 Serializes every managed component to a JSON string, keyed by each component's unique name. More...
 
virtual std::string ToString (const EComponentType theComponent) const
 Serializes a single managed component (the first of the given type) to a JSON string. More...
 
void Update ()
 Polls every managed component once, refreshing their readings. More...
 
void UpdateComponentsOfType (const EComponentType typeOfComponentToUpdate)
 Polls only the components of the requested type, letting a caller sample a fast sensor (e.g. More...
 
virtual void ProcessRawValues () override
 Processes the manager's raw values. More...
 
void AddComponent (BaseComponent *componentToAdd)
 Adds a component to the manager and gives it a unique name. More...
 
void RemoveComponents (const EComponentType typeOfComponentToRemove)
 Removes and deletes every managed component of the given type, freeing their names for reuse. More...
 
void TurnOnComponent (const BaseComponent *componentToTurnOn)
 Turns on the single component matching the given pointer, if the manager holds it. More...
 
void TurnOnComponents (const EComponentType typeOfComponentToTurnOn)
 Turns on every managed component of the given type. More...
 
void TurnOffComponent (const BaseComponent *componentToTurnOff)
 Turns off the single component matching the given pointer, if the manager holds it. More...
 
void TurnOffComponents (const EComponentType typeOfComponentToTurnOff)
 Turns off every managed component of the given type. More...
 
int GetNumberOfComponents () const
 Gets how many components (instances, not distinct types) the manager currently holds. More...
 
BaseComponentGetComponent (const EComponentType componentType) const
 Gets the first managed component of the given type. More...
 
bool GetComponentTypes (std::vector< EComponentType > &outComponentTypes) const
 Fills the provided vector with the distinct component types the manager currently holds. More...
 
SelectedSensorReadings GetSelectedSensorReadings () const
 Reads the curated set of sensor values into a SelectedSensorReadings for the Home dashboard. More...
 
- Public Member Functions inherited from RumPi::BaseComponent
 BaseComponent ()
 Builds a base component with an unknown type and an empty name. More...
 
virtual ~BaseComponent ()
 Virtual destructor so deleting a component through a BaseComponent* also cleans up the concrete subclass. More...
 
virtual void TurnOn ()=0
 Turns the component on (e.g. More...
 
virtual void TurnOff ()=0
 Turns the component off. More...
 
virtual std::string ToString () const =0
 Serializes the component's current readings to a string (usually JSON). More...
 
virtual void ProcessRawValues ()=0
 Reads and processes the component's latest raw values (called once per poll). More...
 
virtual EComponentType GetComponentType () const
 Gets the component's type. More...
 
const std::string & GetName () const
 Gets the component's unique per-instance name. More...
 
void SetName (const std::string &name)
 Sets the component's unique per-instance name. More...
 

Private Member Functions

std::string MakeNameUnique (const std::string &desiredName)
 Returns a unique name based on desiredName: the bare name if it is free, otherwise the name with " 2", " 3", ... appended until it is unused. More...
 

Private Attributes

std::unordered_multimap< const EComponentType, BaseComponent * > myComponents
 Every managed component, keyed by type. A multimap, so several components can share a single type. More...
 
std::set< std::string > myUsedNames
 Tracks the names handed out so far so AddComponent can guarantee every component's name is unique. More...
 

Additional Inherited Members

- Static Public Member Functions inherited from RumPi::BaseComponent
static std::string ComponentTypeToString (const EComponentType theComponentTypeToConvert)
 Maps an EComponentType to its string name. More...
 
static EComponentType StringToComponentType (const std::string &theComponentTypeName)
 Maps a type name back to its EComponentType (the inverse of ComponentTypeToString), so the client can turn the type carried on the wire back into a value it can look an icon up with. More...
 
- Protected Attributes inherited from RumPi::BaseComponent
EComponentType myComponentType
 The kind of component this is (set by each concrete subclass). More...
 
std::string myName
 A unique per-instance name, assigned when the component is added to the manager. More...
 

Detailed Description

Owns and drives the set of sensor components.

NOT internally synchronized: it is populated on the setup thread (during RumPi::Initialize, before any poll thread starts) and thereafter driven by a single poll thread (Update/ToString/GetSelectedSensorReadings/...). Do not call AddComponent/RemoveComponents concurrently with the polling methods - add a lock here first if a future design needs concurrent access.

Author
Eddie O'Hagan
Date
8/13/2026

Constructor & Destructor Documentation

◆ ComponentManager() [1/2]

RumPi::ComponentManager::ComponentManager ( const ComponentManager )
delete

◆ ComponentManager() [2/2]

RumPi::ComponentManager::ComponentManager ( )

Builds an empty component manager.

Components are added afterwards via AddComponent().

Author
Eddie O'Hagan
Date
8/13/2026
manager.AddComponent(new LED(PIN_GPIO_12));
ComponentManager()
Builds an empty component manager.
Definition: ComponentManager.cpp:26
constexpr unsigned int PIN_GPIO_12
BCM GPIO pin 12.
Definition: Common.h:38

◆ ~ComponentManager()

RumPi::ComponentManager::~ComponentManager ( )
virtual

Frees every component the manager owns, then clears the internal map.

Author
Eddie O'Hagan
Date
8/13/2026
//...use it...
delete manager; //also deletes every component it holds.

Member Function Documentation

◆ AddComponent()

void RumPi::ComponentManager::AddComponent ( BaseComponent componentToAdd)

Adds a component to the manager and gives it a unique name.

A blank name (e.g. the receiver, added directly rather than through the manifest) is defaulted to the type name; a duplicate name is disambiguated with a numeric suffix and a warning. Ignored if the component is null.

Author
Eddie O'Hagan
Date
8/13/2026
manager.AddComponent(new LED(PIN_GPIO_12));
Parameters
[in]componentToAddThe component to add (the manager takes ownership and may rename it).

◆ GetComponent()

BaseComponent * RumPi::ComponentManager::GetComponent ( const EComponentType  componentType) const

Gets the first managed component of the given type.

Author
Eddie O'Hagan
Date
8/13/2026
BaseComponent* dht = manager.GetComponent(EComponentType::E_DHT11);
if (dht != nullptr)
{
//use it...
}
BaseComponent()
Builds a base component with an unknown type and an empty name.
Definition: BaseComponent.cpp:17
Parameters
[in]componentTypeThe type of component to fetch.
Returns
The first component of that type, or nullptr if none is managed.

◆ GetComponentTypes()

bool RumPi::ComponentManager::GetComponentTypes ( std::vector< EComponentType > &  outComponentTypes) const

Fills the provided vector with the distinct component types the manager currently holds.

Author
Eddie O'Hagan
Date
8/13/2026
std::vector<EComponentType> types;
if (manager.GetComponentTypes(types) == true)
{
//types now lists each distinct type present.
}
Parameters
[out]outComponentTypesFilled with the distinct types present.
Returns
true if at least one type was found; false otherwise.

◆ GetNumberOfComponents()

int RumPi::ComponentManager::GetNumberOfComponents ( ) const

Gets how many components (instances, not distinct types) the manager currently holds.

Author
Eddie O'Hagan
Date
8/13/2026
int count = manager.GetNumberOfComponents();
Returns
The number of managed components.

◆ GetSelectedSensorReadings()

SelectedSensorReadings RumPi::ComponentManager::GetSelectedSensorReadings ( ) const

Reads the curated set of sensor values into a SelectedSensorReadings for the Home dashboard.

Uses the first component of each type (the fixed tiles show one reading per kind, not an aggregate). Call it on the same thread that Update()s the components, since it reads their getters live.

Author
Eddie O'Hagan
Date
8/13/2026
manager.Update();
SelectedSensorReadings readings = manager.GetSelectedSensorReadings();
Returns
The curated dashboard readings, populated from whichever sensors are present.

◆ MakeNameUnique()

std::string RumPi::ComponentManager::MakeNameUnique ( const std::string &  desiredName)
private

Returns a unique name based on desiredName: the bare name if it is free, otherwise the name with " 2", " 3", ... appended until it is unused.

The chosen name is recorded so future calls stay unique.

Author
Eddie O'Hagan
Date
8/13/2026
//Two LEDs added with no explicit name become "LED" and "LED 2".
std::string name = MakeNameUnique("LED");
std::string MakeNameUnique(const std::string &desiredName)
Returns a unique name based on desiredName: the bare name if it is free, otherwise the name with " 2"...
Definition: ComponentManager.cpp:409
Parameters
[in]desiredNameThe name to make unique.
Returns
A name guaranteed not to clash with any previously handed out.

◆ operator=()

ComponentManager & RumPi::ComponentManager::operator= ( const ComponentManager )
delete

◆ ProcessRawValues()

void RumPi::ComponentManager::ProcessRawValues ( )
overridevirtual

Processes the manager's raw values.

A ComponentManager is itself a BaseComponent, so this simply updates everything it manages.

Author
Eddie O'Hagan
Date
8/13/2026
manager.ProcessRawValues(); //equivalent to manager.Update().

Implements RumPi::BaseComponent.

◆ RemoveComponents()

void RumPi::ComponentManager::RemoveComponents ( const EComponentType  typeOfComponentToRemove)

Removes and deletes every managed component of the given type, freeing their names for reuse.

Author
Eddie O'Hagan
Date
8/13/2026
manager.RemoveComponents(EComponentType::E_LED); //drop and delete all LEDs.
Parameters
[in]typeOfComponentToRemoveThe type of component to remove.

◆ ToString() [1/2]

std::string RumPi::ComponentManager::ToString ( ) const
overridevirtual

Serializes every managed component to a JSON string, keyed by each component's unique name.

The type travels alongside so a client can pick the right icon/panel, and "data" carries the component's own serialized readings.

Author
Eddie O'Hagan
Date
8/13/2026
std::string json = manager.ToString(); //e.g. {"DHT11":{"type":"DHT11","data":"..."}}
Returns
A JSON string describing every managed component.

Implements RumPi::BaseComponent.

◆ ToString() [2/2]

std::string RumPi::ComponentManager::ToString ( const EComponentType  theComponent) const
virtual

Serializes a single managed component (the first of the given type) to a JSON string.

If no component of that type is managed, a warning is reported and an empty JSON object is returned so the caller can still parse it.

Author
Eddie O'Hagan
Date
8/13/2026
std::string dht = manager.ToString(EComponentType::E_DHT11);
Parameters
[in]theComponentThe type of component to serialize.
Returns
The component's serialized data, or "{}" if no component of that type is managed.

◆ TurnOff()

void RumPi::ComponentManager::TurnOff ( )
overridevirtual

Turns off every managed component.

Author
Eddie O'Hagan
Date
8/13/2026
manager.TurnOff();

Implements RumPi::BaseComponent.

◆ TurnOffComponent()

void RumPi::ComponentManager::TurnOffComponent ( const BaseComponent componentToTurnOff)

Turns off the single component matching the given pointer, if the manager holds it.

Author
Eddie O'Hagan
Date
8/13/2026
BaseComponent* led = manager.GetComponent(EComponentType::E_LED);
manager.TurnOffComponent(led);
Parameters
[in]componentToTurnOffThe component to turn off.

◆ TurnOffComponents()

void RumPi::ComponentManager::TurnOffComponents ( const EComponentType  typeOfComponentToTurnOff)

Turns off every managed component of the given type.

Author
Eddie O'Hagan
Date
8/13/2026
manager.TurnOffComponents(EComponentType::E_LED); //turn off all LEDs.
Parameters
[in]typeOfComponentToTurnOffThe type of component to turn off.

◆ TurnOn()

void RumPi::ComponentManager::TurnOn ( )
overridevirtual

Turns on every managed component.

Author
Eddie O'Hagan
Date
8/13/2026
manager.TurnOn();

Implements RumPi::BaseComponent.

◆ TurnOnComponent()

void RumPi::ComponentManager::TurnOnComponent ( const BaseComponent componentToTurnOn)

Turns on the single component matching the given pointer, if the manager holds it.

Author
Eddie O'Hagan
Date
8/13/2026
BaseComponent* led = manager.GetComponent(EComponentType::E_LED);
manager.TurnOnComponent(led);
Parameters
[in]componentToTurnOnThe component to turn on.

◆ TurnOnComponents()

void RumPi::ComponentManager::TurnOnComponents ( const EComponentType  typeOfComponentToTurnOn)

Turns on every managed component of the given type.

Author
Eddie O'Hagan
Date
8/13/2026
manager.TurnOnComponents(EComponentType::E_LED); //turn on all LEDs.
Parameters
[in]typeOfComponentToTurnOnThe type of component to turn on.

◆ Update()

void RumPi::ComponentManager::Update ( )

Polls every managed component once, refreshing their readings.

Called every tick to update the sensors.

Author
Eddie O'Hagan
Date
8/13/2026
manager.Update(); //refresh every component's readings.

◆ UpdateComponentsOfType()

void RumPi::ComponentManager::UpdateComponentsOfType ( const EComponentType  typeOfComponentToUpdate)

Polls only the components of the requested type, letting a caller sample a fast sensor (e.g.

wind) on a tighter cadence than the full Update() pass without over-polling the slower sensors.

Author
Eddie O'Hagan
Date
8/13/2026
manager.UpdateComponentsOfType(EComponentType::E_QSFS01); //sample the wind sensor now.
Parameters
[in]typeOfComponentToUpdateThe component type to poll.

Member Data Documentation

◆ myComponents

std::unordered_multimap<const EComponentType, BaseComponent*> RumPi::ComponentManager::myComponents
private

Every managed component, keyed by type. A multimap, so several components can share a single type.

◆ myUsedNames

std::set<std::string> RumPi::ComponentManager::myUsedNames
private

Tracks the names handed out so far so AddComponent can guarantee every component's name is unique.


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