initial version
This commit is contained in:
50
sensors/Sensor.h
Normal file
50
sensors/Sensor.h
Normal file
@@ -0,0 +1,50 @@
|
||||
#ifndef SENSOR_H
|
||||
#define SENSOR_H
|
||||
|
||||
#include <vector>
|
||||
#include <QObject>
|
||||
|
||||
/** listen for sensor events */
|
||||
template <typename T> class SensorListener {
|
||||
|
||||
public:
|
||||
|
||||
/** incoming sensor data */
|
||||
virtual void onSensorData(const T& data) = 0;
|
||||
|
||||
};
|
||||
|
||||
|
||||
/** base-class for all sensors */
|
||||
template <typename T> class Sensor {
|
||||
|
||||
private:
|
||||
|
||||
std::vector<SensorListener<T>*> listeners;
|
||||
|
||||
public:
|
||||
|
||||
/** start this sensor */
|
||||
virtual void start() = 0;
|
||||
|
||||
/** stop this sensor */
|
||||
virtual void stop() = 0;
|
||||
|
||||
/** add the given listener to the sensor */
|
||||
void addListener(SensorListener<T>* l) {
|
||||
listeners.push_back(l);
|
||||
}
|
||||
|
||||
protected:
|
||||
|
||||
/** inform all attached listeners */
|
||||
void informListeners(const T& sensorData) const {
|
||||
for (SensorListener<T>* l : listeners) {
|
||||
l->onSensorData(sensorData);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
};
|
||||
|
||||
#endif // SENSOR_H
|
||||
Reference in New Issue
Block a user