RumPi 1.0
A self-assembling C++ sensor & actuator library for the Raspberry Pi 5
ComponentManager.h
Go to the documentation of this file.
1#pragma once
2#include <set>
4#include "Common.h"
6
7namespace RumPi
8{
19 {
20 public:
21 //Owns raw component pointers and deletes them in its destructor, so a copy would double-free. Non-copyable.
24
25 private:
27 std::unordered_multimap<const EComponentType, BaseComponent*> myComponents;
28
30 std::set<std::string> myUsedNames;
31
48 std::string MakeNameUnique(const std::string& desiredName);
49
50 public:
63
76 virtual ~ComponentManager();
77
89 virtual void TurnOn() override;
90
102 virtual void TurnOff() override;
103
119 virtual std::string ToString() const override;
120
137 virtual std::string ToString(const EComponentType theComponent) const;
138
150 void Update();
151
166 void UpdateComponentsOfType(const EComponentType typeOfComponentToUpdate);
167
180 virtual void ProcessRawValues() override;
181
197 void AddComponent(BaseComponent* componentToAdd);
198
211 void RemoveComponents(const EComponentType typeOfComponentToRemove);
212
226 void TurnOnComponent(const BaseComponent* componentToTurnOn);
227
240 void TurnOnComponents(const EComponentType typeOfComponentToTurnOn);
241
255 void TurnOffComponent(const BaseComponent* componentToTurnOff);
256
269 void TurnOffComponents(const EComponentType typeOfComponentToTurnOff);
270
283 int GetNumberOfComponents() const;
284
303 BaseComponent* GetComponent(const EComponentType componentType) const;
304
323 bool GetComponentTypes(std::vector<EComponentType>& outComponentTypes) const;
324
341 };
342} // namespace RumPi
Abstract base class for every component (sensor, actuator, etc.) the library manages.
Definition: BaseComponent.h:60
Owns and drives the set of sensor components.
Definition: ComponentManager.h:19
void RemoveComponents(const EComponentType typeOfComponentToRemove)
Removes and deletes every managed component of the given type, freeing their names for reuse.
Definition: ComponentManager.cpp:437
virtual ~ComponentManager()
Frees every component the manager owns, then clears the internal map.
Definition: ComponentManager.cpp:43
SelectedSensorReadings GetSelectedSensorReadings() const
Reads the curated set of sensor values into a SelectedSensorReadings for the Home dashboard.
Definition: ComponentManager.cpp:547
void TurnOnComponent(const BaseComponent *componentToTurnOn)
Turns on the single component matching the given pointer, if the manager holds it.
Definition: ComponentManager.cpp:261
BaseComponent * GetComponent(const EComponentType componentType) const
Gets the first managed component of the given type.
Definition: ComponentManager.cpp:486
virtual void TurnOff() override
Turns off every managed component.
Definition: ComponentManager.cpp:86
ComponentManager & operator=(const ComponentManager &)=delete
virtual void ProcessRawValues() override
Processes the manager's raw values.
Definition: ComponentManager.cpp:215
void UpdateComponentsOfType(const EComponentType typeOfComponentToUpdate)
Polls only the components of the requested type, letting a caller sample a fast sensor (e....
Definition: ComponentManager.cpp:235
void Update()
Polls every managed component once, refreshing their readings.
Definition: ComponentManager.cpp:174
ComponentManager(const ComponentManager &)=delete
void TurnOffComponents(const EComponentType typeOfComponentToTurnOff)
Turns off every managed component of the given type.
Definition: ComponentManager.cpp:340
ComponentManager()
Builds an empty component manager.
Definition: ComponentManager.cpp:26
std::set< std::string > myUsedNames
Tracks the names handed out so far so AddComponent can guarantee every component's name is unique.
Definition: ComponentManager.h:30
bool GetComponentTypes(std::vector< EComponentType > &outComponentTypes) const
Fills the provided vector with the distinct component types the manager currently holds.
Definition: ComponentManager.cpp:518
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
void TurnOffComponent(const BaseComponent *componentToTurnOff)
Turns off the single component matching the given pointer, if the manager holds it.
Definition: ComponentManager.cpp:313
void AddComponent(BaseComponent *componentToAdd)
Adds a component to the manager and gives it a unique name.
Definition: ComponentManager.cpp:367
void TurnOnComponents(const EComponentType typeOfComponentToTurnOn)
Turns on every managed component of the given type.
Definition: ComponentManager.cpp:288
std::unordered_multimap< const EComponentType, BaseComponent * > myComponents
Every managed component, keyed by type. A multimap, so several components can share a single type.
Definition: ComponentManager.h:27
virtual void TurnOn() override
Turns on every managed component.
Definition: ComponentManager.cpp:65
virtual std::string ToString() const override
Serializes every managed component to a JSON string, keyed by each component's unique name.
Definition: ComponentManager.cpp:111
int GetNumberOfComponents() const
Gets how many components (instances, not distinct types) the manager currently holds.
Definition: ComponentManager.cpp:463
A point-in-time copy of the SELECTED sensor readings the Home dashboard surfaces - a deliberately cur...
Definition: SelectedSensorReadings.h:18
RumPi is the library's top-level facade.
Definition: AlertManager.h:6
EComponentType
Identifies each kind of component the library supports.
Definition: BaseComponent.h:14