diff options
-rw-r--r-- | monitor/fan.cpp | 22 | ||||
-rw-r--r-- | monitor/fan.hpp | 7 | ||||
-rw-r--r-- | monitor/tach_sensor.cpp | 20 |
3 files changed, 37 insertions, 12 deletions
diff --git a/monitor/fan.cpp b/monitor/fan.cpp index f3937c2..6d88d2a 100644 --- a/monitor/fan.cpp +++ b/monitor/fan.cpp @@ -49,13 +49,21 @@ Fan::Fan(sdbusplus::bus::bus& bus, for (auto& s : sensors) { - _sensors.emplace_back( - std::make_unique<TachSensor>(bus, - *this, - std::get<sensorNameField>(s), - std::get<hasTargetField>(s), - std::get<timeoutField>(def), - events)); + try + { + _sensors.emplace_back( + std::make_unique<TachSensor>( + bus, + *this, + std::get<sensorNameField>(s), + std::get<hasTargetField>(s), + std::get<timeoutField>(def), + events)); + } + catch (InvalidSensorError& e) + { + + } } //Start from a known state of functional diff --git a/monitor/fan.hpp b/monitor/fan.hpp index 8e7f86f..0004353 100644 --- a/monitor/fan.hpp +++ b/monitor/fan.hpp @@ -14,6 +14,13 @@ namespace fan namespace monitor { +/** + * @class InvalidSensorError + * + * An exception type for sensors that don't exist or + * are otherwise inaccessible. + */ +class InvalidSensorError : public std::exception {}; /** * @class Fan diff --git a/monitor/tach_sensor.cpp b/monitor/tach_sensor.cpp index 0ec52ba..a4ebcd9 100644 --- a/monitor/tach_sensor.cpp +++ b/monitor/tach_sensor.cpp @@ -77,11 +77,21 @@ TachSensor::TachSensor(sdbusplus::bus::bus& bus, _timer(events, [this, &fan](){ fan.timerExpired(*this); }) { //Load in starting Target and Input values - readProperty(FAN_SENSOR_VALUE_INTF, - FAN_VALUE_PROPERTY, - _name, - _bus, - _tachInput); + + try + { + // Use getProperty directly to allow a missing sensor object + // to abort construction. + _tachInput = util::SDBusPlus::getProperty<decltype(_tachInput)>( + _bus, + _name, + FAN_SENSOR_VALUE_INTF, + FAN_VALUE_PROPERTY); + } + catch (std::exception& e) + { + throw InvalidSensorError(); + } if (_hasTarget) { |