Wyatt  1.0.1
SensorManager.cpp
1 #include "sensors/SensorManager.h"
2 
4  this->sensorMap = new std::map<Hardware, ISensor*>;
5 };
6 
8  delete this->sensorMap;
9 };
10 
11 void SensorManager::addSensor(Hardware hardware, ISensor* sensor) {
12 
13  // Ensure that the sensor has not already been added
14  if( this->sensorMap->find(hardware) != this->sensorMap->end() ) {
15  throw DuplicateHardwareException(hardware);
16  }
17  this->sensorMap->insert(std::make_pair(hardware, sensor));
18 };
19 
20 void SensorManager::updateSensors(std::list<IMessage*>* messages) {
21 
22  // For each message, extract the message data and send it to the appropriate sensor.
23  for(IMessage* msg: *messages) {
24 
25  Hardware hardware = msg->getHardware();
26  if( this->sensorMap->find(hardware) == this->sensorMap->end() ) {
27  throw NonexistentHardwareException(hardware);
28  }
29 
30  this->sensorMap->at(msg->getHardware())->updateSensor(msg);
31  }
32 
33  delete messages;
34 };
void addSensor(Hardware hardware, ISensor *sensor) override
void updateSensors(std::list< IMessage * > *messages) override
Definition: ISensor.h:7
~SensorManager() override