RumPi 1.0
A self-assembling C++ sensor & actuator library for the Raspberry Pi 5
BaseComponent.h
Go to the documentation of this file.
1#pragma once
2#include "../Common.h"
3
4namespace RumPi
5{
13 enum class EComponentType
14 {
18 E_DHT11,
22 E_LED,
24 E_Motor,
25 E_MQ2,
26 E_MQ3,
27 E_MQ4,
28 E_MQ5,
29 E_MQ6,
30 E_MQ7,
31 E_MQ8,
32 E_MQ9,
33 E_MQ135,
42 E_Relay,
49 };
50
60 {
61 protected:
64
67 std::string myName;
68
69 public:
83
95 virtual ~BaseComponent();
96
108 virtual void TurnOn() = 0;
109
121 virtual void TurnOff() = 0;
122
136 virtual std::string ToString() const = 0;
137
149 virtual void ProcessRawValues() = 0;
150
166 static std::string ComponentTypeToString(const EComponentType theComponentTypeToConvert);
167
183 static EComponentType StringToComponentType(const std::string& theComponentTypeName);
184
200 virtual EComponentType GetComponentType() const;
201
214 const std::string& GetName() const;
215
229 void SetName(const std::string& name);
230 };
231} // namespace RumPi
Abstract base class for every component (sensor, actuator, etc.) the library manages.
Definition: BaseComponent.h:60
virtual ~BaseComponent()
Virtual destructor so deleting a component through a BaseComponent* also cleans up the concrete subcl...
Definition: BaseComponent.cpp:34
virtual void ProcessRawValues()=0
Reads and processes the component's latest raw values (called once per poll).
virtual std::string ToString() const =0
Serializes the component's current readings to a string (usually JSON).
BaseComponent()
Builds a base component with an unknown type and an empty name.
Definition: BaseComponent.cpp:17
const std::string & GetName() const
Gets the component's unique per-instance name.
Definition: BaseComponent.cpp:260
std::string myName
A unique per-instance name, assigned when the component is added to the manager.
Definition: BaseComponent.h:67
static std::string ComponentTypeToString(const EComponentType theComponentTypeToConvert)
Maps an EComponentType to its string name.
Definition: BaseComponent.cpp:54
static EComponentType StringToComponentType(const std::string &theComponentTypeName)
Maps a type name back to its EComponentType (the inverse of ComponentTypeToString),...
Definition: BaseComponent.cpp:209
EComponentType myComponentType
The kind of component this is (set by each concrete subclass).
Definition: BaseComponent.h:63
virtual void TurnOff()=0
Turns the component off.
virtual EComponentType GetComponentType() const
Gets the component's type.
Definition: BaseComponent.cpp:243
void SetName(const std::string &name)
Sets the component's unique per-instance name.
Definition: BaseComponent.cpp:278
virtual void TurnOn()=0
Turns the component on (e.g.
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