Brad Bishop | e55ef3d | 2016-12-19 09:12:40 -0500 | [diff] [blame] | 1 | /** |
| 2 | * Copyright © 2016 IBM Corporation |
| 3 | * |
| 4 | * Licensed under the Apache License, Version 2.0 (the "License"); |
| 5 | * you may not use this file except in compliance with the License. |
| 6 | * You may obtain a copy of the License at |
| 7 | * |
| 8 | * http://www.apache.org/licenses/LICENSE-2.0 |
| 9 | * |
| 10 | * Unless required by applicable law or agreed to in writing, software |
| 11 | * distributed under the License is distributed on an "AS IS" BASIS, |
| 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
| 13 | * See the License for the specific language governing permissions and |
| 14 | * limitations under the License. |
| 15 | */ |
Brad Bishop | 4d9a35b | 2017-11-14 22:33:03 -0500 | [diff] [blame] | 16 | #include <functional> |
Brad Bishop | e55ef3d | 2016-12-19 09:12:40 -0500 | [diff] [blame] | 17 | #include <iostream> |
| 18 | #include <memory> |
Brad Bishop | 9c7b6e0 | 2016-12-19 12:43:36 -0500 | [diff] [blame] | 19 | #include <cstdlib> |
Patrick Venture | 50cf1c5 | 2018-04-18 09:21:41 -0700 | [diff] [blame] | 20 | #include <cstring> |
Chiabing Lee | c923ce9 | 2017-09-06 15:58:26 +0800 | [diff] [blame] | 21 | #include <string> |
Matthew Barth | d26e277 | 2018-03-22 14:24:06 -0500 | [diff] [blame] | 22 | #include <unordered_set> |
Patrick Venture | 1e6324f | 2017-06-01 14:07:05 -0700 | [diff] [blame] | 23 | |
| 24 | #include <phosphor-logging/elog-errors.hpp> |
Matt Spinler | f9c83c4 | 2017-08-10 08:51:45 -0500 | [diff] [blame] | 25 | #include "config.h" |
Patrick Venture | 0979185 | 2018-04-17 17:40:00 -0700 | [diff] [blame] | 26 | #include "env.hpp" |
| 27 | #include "fan_pwm.hpp" |
| 28 | #include "fan_speed.hpp" |
Brad Bishop | e55ef3d | 2016-12-19 09:12:40 -0500 | [diff] [blame] | 29 | #include "hwmon.hpp" |
Patrick Venture | 75e56c6 | 2018-04-20 18:10:15 -0700 | [diff] [blame] | 30 | #include "hwmonio.hpp" |
Patrick Venture | 0979185 | 2018-04-17 17:40:00 -0700 | [diff] [blame] | 31 | #include "sensorset.hpp" |
Brad Bishop | e55ef3d | 2016-12-19 09:12:40 -0500 | [diff] [blame] | 32 | #include "sysfs.hpp" |
Brad Bishop | d499ca6 | 2016-12-19 09:24:50 -0500 | [diff] [blame] | 33 | #include "mainloop.hpp" |
Matthew Barth | bf7b7b1 | 2017-03-07 15:46:59 -0600 | [diff] [blame] | 34 | #include "targets.hpp" |
Patrick Venture | 0979185 | 2018-04-17 17:40:00 -0700 | [diff] [blame] | 35 | #include "thresholds.hpp" |
Matthew Barth | 3581938 | 2018-04-18 14:53:01 -0500 | [diff] [blame] | 36 | #include "sensor.hpp" |
Brad Bishop | e55ef3d | 2016-12-19 09:12:40 -0500 | [diff] [blame] | 37 | |
Patrick Venture | 1e6324f | 2017-06-01 14:07:05 -0700 | [diff] [blame] | 38 | #include <xyz/openbmc_project/Sensor/Device/error.hpp> |
| 39 | |
| 40 | using namespace phosphor::logging; |
| 41 | |
Saqib Khan | 973886d | 2017-03-15 14:01:16 -0500 | [diff] [blame] | 42 | // Initialization for Warning Objects |
| 43 | decltype(Thresholds<WarningObject>::setLo) Thresholds<WarningObject>::setLo = |
| 44 | &WarningObject::warningLow; |
| 45 | decltype(Thresholds<WarningObject>::setHi) Thresholds<WarningObject>::setHi = |
| 46 | &WarningObject::warningHigh; |
| 47 | decltype(Thresholds<WarningObject>::getLo) Thresholds<WarningObject>::getLo = |
| 48 | &WarningObject::warningLow; |
| 49 | decltype(Thresholds<WarningObject>::getHi) Thresholds<WarningObject>::getHi = |
| 50 | &WarningObject::warningHigh; |
| 51 | decltype(Thresholds<WarningObject>::alarmLo) Thresholds<WarningObject>::alarmLo = |
| 52 | &WarningObject::warningAlarmLow; |
| 53 | decltype(Thresholds<WarningObject>::alarmHi) Thresholds<WarningObject>::alarmHi = |
| 54 | &WarningObject::warningAlarmHigh; |
| 55 | |
| 56 | // Initialization for Critical Objects |
| 57 | decltype(Thresholds<CriticalObject>::setLo) Thresholds<CriticalObject>::setLo = |
| 58 | &CriticalObject::criticalLow; |
| 59 | decltype(Thresholds<CriticalObject>::setHi) Thresholds<CriticalObject>::setHi = |
| 60 | &CriticalObject::criticalHigh; |
| 61 | decltype(Thresholds<CriticalObject>::getLo) Thresholds<CriticalObject>::getLo = |
| 62 | &CriticalObject::criticalLow; |
| 63 | decltype(Thresholds<CriticalObject>::getHi) Thresholds<CriticalObject>::getHi = |
| 64 | &CriticalObject::criticalHigh; |
| 65 | decltype(Thresholds<CriticalObject>::alarmLo) Thresholds<CriticalObject>::alarmLo = |
| 66 | &CriticalObject::criticalAlarmLow; |
| 67 | decltype(Thresholds<CriticalObject>::alarmHi) Thresholds<CriticalObject>::alarmHi = |
| 68 | &CriticalObject::criticalAlarmHigh; |
| 69 | |
Chiabing Lee | c923ce9 | 2017-09-06 15:58:26 +0800 | [diff] [blame] | 70 | // The gain and offset to adjust a value |
| 71 | struct valueAdjust |
| 72 | { |
| 73 | double gain = 1.0; |
| 74 | int offset = 0; |
Matthew Barth | d26e277 | 2018-03-22 14:24:06 -0500 | [diff] [blame] | 75 | std::unordered_set<int> rmRCs; |
Chiabing Lee | c923ce9 | 2017-09-06 15:58:26 +0800 | [diff] [blame] | 76 | }; |
| 77 | |
| 78 | // Store the valueAdjust for sensors |
| 79 | std::map<SensorSet::key_type, valueAdjust> sensorAdjusts; |
| 80 | |
Matthew Barth | d26e277 | 2018-03-22 14:24:06 -0500 | [diff] [blame] | 81 | void addRemoveRCs(const SensorSet::key_type& sensor, |
| 82 | const std::string& rcList) |
| 83 | { |
Matthew Barth | b798527 | 2018-04-17 10:50:36 -0500 | [diff] [blame] | 84 | if (rcList.empty()) |
| 85 | { |
| 86 | return; |
| 87 | } |
| 88 | |
Matthew Barth | d26e277 | 2018-03-22 14:24:06 -0500 | [diff] [blame] | 89 | // Convert to a char* for strtok |
| 90 | std::vector<char> rmRCs(rcList.c_str(), |
| 91 | rcList.c_str() + rcList.size() + 1); |
Patrick Venture | 50cf1c5 | 2018-04-18 09:21:41 -0700 | [diff] [blame] | 92 | auto rmRC = std::strtok(&rmRCs[0], ", "); |
Matthew Barth | d26e277 | 2018-03-22 14:24:06 -0500 | [diff] [blame] | 93 | while (rmRC != nullptr) |
| 94 | { |
| 95 | try |
| 96 | { |
| 97 | sensorAdjusts[sensor].rmRCs.insert(std::stoi(rmRC)); |
| 98 | } |
| 99 | catch (const std::logic_error& le) |
| 100 | { |
| 101 | // Unable to convert to int, continue to next token |
| 102 | std::string name = sensor.first + "_" + sensor.second; |
| 103 | log<level::INFO>("Unable to convert sensor removal return code", |
| 104 | entry("SENSOR=%s", name.c_str()), |
| 105 | entry("RC=%s", rmRC), |
| 106 | entry("EXCEPTION=%s", le.what())); |
| 107 | } |
Patrick Venture | 50cf1c5 | 2018-04-18 09:21:41 -0700 | [diff] [blame] | 108 | rmRC = std::strtok(nullptr, ", "); |
Matthew Barth | d26e277 | 2018-03-22 14:24:06 -0500 | [diff] [blame] | 109 | } |
| 110 | } |
| 111 | |
Matt Spinler | fee106b | 2017-11-29 15:18:05 -0600 | [diff] [blame] | 112 | int64_t adjustValue(const SensorSet::key_type& sensor, int64_t value) |
Chiabing Lee | c923ce9 | 2017-09-06 15:58:26 +0800 | [diff] [blame] | 113 | { |
Patrick Venture | c1cece7 | 2017-11-07 12:09:49 -0800 | [diff] [blame] | 114 | // Because read doesn't have an out pointer to store errors. |
| 115 | // let's assume negative values are errors if they have this |
| 116 | // set. |
| 117 | #ifdef NEGATIVE_ERRNO_ON_FAIL |
| 118 | if (value < 0) |
| 119 | { |
| 120 | return value; |
| 121 | } |
| 122 | #endif |
| 123 | |
Chiabing Lee | c923ce9 | 2017-09-06 15:58:26 +0800 | [diff] [blame] | 124 | const auto& it = sensorAdjusts.find(sensor); |
| 125 | if (it != sensorAdjusts.end()) |
| 126 | { |
| 127 | // Adjust based on gain and offset |
| 128 | value = static_cast<decltype(value)>( |
| 129 | static_cast<double>(value) * it->second.gain |
| 130 | + it->second.offset); |
| 131 | } |
| 132 | return value; |
| 133 | } |
| 134 | |
Brad Bishop | e9fdee0 | 2017-01-06 10:43:29 -0500 | [diff] [blame] | 135 | auto addValue(const SensorSet::key_type& sensor, |
Matthew Barth | d4beecf | 2018-04-03 15:50:22 -0500 | [diff] [blame] | 136 | const RetryIO& retryIO, |
Patrick Venture | 75e56c6 | 2018-04-20 18:10:15 -0700 | [diff] [blame] | 137 | hwmonio::HwmonIO& ioAccess, |
Matthew Barth | 0b30505 | 2018-04-26 09:46:49 -0500 | [diff] [blame^] | 138 | ObjectInfo& info) |
Brad Bishop | e9fdee0 | 2017-01-06 10:43:29 -0500 | [diff] [blame] | 139 | { |
Brad Bishop | 30dbcee | 2017-01-18 07:55:42 -0500 | [diff] [blame] | 140 | static constexpr bool deferSignals = true; |
| 141 | |
Brad Bishop | e9fdee0 | 2017-01-06 10:43:29 -0500 | [diff] [blame] | 142 | // Get the initial value for the value interface. |
| 143 | auto& bus = *std::get<sdbusplus::bus::bus*>(info); |
| 144 | auto& obj = std::get<Object>(info); |
| 145 | auto& objPath = std::get<std::string>(info); |
| 146 | |
Patrick Venture | 7a5285d | 2018-04-17 19:15:05 -0700 | [diff] [blame] | 147 | auto senRmRCs = env::getEnv("REMOVERCS", sensor); |
Matthew Barth | b798527 | 2018-04-17 10:50:36 -0500 | [diff] [blame] | 148 | // Add sensor removal return codes defined per sensor |
| 149 | addRemoveRCs(sensor, senRmRCs); |
Matthew Barth | d26e277 | 2018-03-22 14:24:06 -0500 | [diff] [blame] | 150 | |
Patrick Venture | 7a5285d | 2018-04-17 19:15:05 -0700 | [diff] [blame] | 151 | auto gain = env::getEnv("GAIN", sensor); |
Chiabing Lee | c923ce9 | 2017-09-06 15:58:26 +0800 | [diff] [blame] | 152 | if (!gain.empty()) |
| 153 | { |
| 154 | sensorAdjusts[sensor].gain = std::stod(gain); |
| 155 | } |
| 156 | |
Patrick Venture | 7a5285d | 2018-04-17 19:15:05 -0700 | [diff] [blame] | 157 | auto offset = env::getEnv("OFFSET", sensor); |
Chiabing Lee | c923ce9 | 2017-09-06 15:58:26 +0800 | [diff] [blame] | 158 | if (!offset.empty()) |
| 159 | { |
| 160 | sensorAdjusts[sensor].offset = std::stoi(offset); |
| 161 | } |
| 162 | |
Matthew Barth | ca44c2e | 2018-04-24 15:33:25 -0500 | [diff] [blame] | 163 | int64_t val = 0; |
| 164 | std::shared_ptr<StatusObject> statusIface = nullptr; |
| 165 | auto it = obj.find(InterfaceType::STATUS); |
| 166 | if (it != obj.end()) |
| 167 | { |
| 168 | statusIface = std::experimental::any_cast< |
| 169 | std::shared_ptr<StatusObject>>(it->second); |
| 170 | } |
| 171 | |
| 172 | // If there's no fault file or the sensor has a fault file and |
| 173 | // its status is functional, read the input value. |
| 174 | if (!statusIface || (statusIface && statusIface->functional())) |
| 175 | { |
| 176 | // Retry for up to a second if device is busy |
| 177 | // or has a transient error. |
| 178 | val = ioAccess.read( |
| 179 | sensor.first, |
| 180 | sensor.second, |
| 181 | hwmon::entry::cinput, |
| 182 | std::get<size_t>(retryIO), |
Matthew Barth | 0b30505 | 2018-04-26 09:46:49 -0500 | [diff] [blame^] | 183 | std::get<std::chrono::milliseconds>(retryIO)); |
Matthew Barth | ca44c2e | 2018-04-24 15:33:25 -0500 | [diff] [blame] | 184 | val = adjustValue(sensor, val); |
| 185 | } |
Chiabing Lee | c923ce9 | 2017-09-06 15:58:26 +0800 | [diff] [blame] | 186 | |
Brad Bishop | 30dbcee | 2017-01-18 07:55:42 -0500 | [diff] [blame] | 187 | auto iface = std::make_shared<ValueObject>(bus, objPath.c_str(), deferSignals); |
Brad Bishop | e9fdee0 | 2017-01-06 10:43:29 -0500 | [diff] [blame] | 188 | iface->value(val); |
| 189 | |
Patrick Venture | 0979185 | 2018-04-17 17:40:00 -0700 | [diff] [blame] | 190 | hwmon::Attributes attrs; |
| 191 | if (hwmon::getAttributes(sensor.first, attrs)) |
Brad Bishop | e9fdee0 | 2017-01-06 10:43:29 -0500 | [diff] [blame] | 192 | { |
Patrick Venture | 0979185 | 2018-04-17 17:40:00 -0700 | [diff] [blame] | 193 | iface->unit(hwmon::getUnit(attrs)); |
| 194 | iface->scale(hwmon::getScale(attrs)); |
Brad Bishop | e9fdee0 | 2017-01-06 10:43:29 -0500 | [diff] [blame] | 195 | } |
| 196 | |
Patrick Venture | 7a5285d | 2018-04-17 19:15:05 -0700 | [diff] [blame] | 197 | auto maxValue = env::getEnv("MAXVALUE", sensor); |
James Feist | 7bd5fcf | 2018-01-22 16:14:28 -0800 | [diff] [blame] | 198 | if(!maxValue.empty()) |
| 199 | { |
| 200 | iface->maxValue(std::stoll(maxValue)); |
| 201 | } |
Patrick Venture | 7a5285d | 2018-04-17 19:15:05 -0700 | [diff] [blame] | 202 | auto minValue = env::getEnv("MINVALUE", sensor); |
James Feist | 7bd5fcf | 2018-01-22 16:14:28 -0800 | [diff] [blame] | 203 | if(!minValue.empty()) |
| 204 | { |
| 205 | iface->minValue(std::stoll(minValue)); |
| 206 | } |
| 207 | |
Brad Bishop | e9fdee0 | 2017-01-06 10:43:29 -0500 | [diff] [blame] | 208 | obj[InterfaceType::VALUE] = iface; |
| 209 | return iface; |
| 210 | } |
| 211 | |
Matthew Barth | 979c806 | 2018-04-17 11:37:15 -0500 | [diff] [blame] | 212 | std::string MainLoop::getID(SensorSet::container_t::const_reference sensor) |
Matthew Barth | 31d214c | 2018-03-26 09:54:27 -0500 | [diff] [blame] | 213 | { |
Matthew Barth | 31d214c | 2018-03-26 09:54:27 -0500 | [diff] [blame] | 214 | std::string id; |
| 215 | |
| 216 | /* |
| 217 | * Check if the value of the MODE_<item><X> env variable for the sensor |
| 218 | * is "label", then read the sensor number from the <item><X>_label |
| 219 | * file. The name of the DBUS object would be the value of the env |
| 220 | * variable LABEL_<item><sensorNum>. If the MODE_<item><X> env variable |
| 221 | * doesn't exist, then the name of DBUS object is the value of the env |
| 222 | * variable LABEL_<item><X>. |
| 223 | */ |
Patrick Venture | 7a5285d | 2018-04-17 19:15:05 -0700 | [diff] [blame] | 224 | auto mode = env::getEnv("MODE", sensor.first); |
Matthew Barth | 31d214c | 2018-03-26 09:54:27 -0500 | [diff] [blame] | 225 | if (!mode.compare(hwmon::entry::label)) |
| 226 | { |
Patrick Venture | 7a5285d | 2018-04-17 19:15:05 -0700 | [diff] [blame] | 227 | id = env::getIndirectID( |
Matthew Barth | 31d214c | 2018-03-26 09:54:27 -0500 | [diff] [blame] | 228 | _hwmonRoot + '/' + _instance + '/', sensor.first); |
| 229 | |
| 230 | if (id.empty()) |
| 231 | { |
Matthew Barth | 979c806 | 2018-04-17 11:37:15 -0500 | [diff] [blame] | 232 | return id; |
Matthew Barth | 31d214c | 2018-03-26 09:54:27 -0500 | [diff] [blame] | 233 | } |
| 234 | } |
| 235 | |
| 236 | // Use the ID we looked up above if there was one, |
| 237 | // otherwise use the standard one. |
| 238 | id = (id.empty()) ? sensor.first.second : id; |
| 239 | |
Matthew Barth | 979c806 | 2018-04-17 11:37:15 -0500 | [diff] [blame] | 240 | return id; |
| 241 | } |
| 242 | |
| 243 | SensorIdentifiers MainLoop::getIdentifiers( |
| 244 | SensorSet::container_t::const_reference sensor) |
| 245 | { |
| 246 | std::string id = getID(sensor); |
| 247 | std::string label; |
| 248 | |
| 249 | if (!id.empty()) |
| 250 | { |
| 251 | // Ignore inputs without a label. |
| 252 | label = env::getEnv("LABEL", sensor.first.first, id); |
| 253 | } |
| 254 | |
| 255 | return std::make_tuple(std::move(id), |
| 256 | std::move(label)); |
| 257 | } |
| 258 | |
| 259 | /** |
| 260 | * Reads the environment parameters of a sensor and creates an object with |
| 261 | * atleast the `Value` interface, otherwise returns without creating the object. |
| 262 | * If the `Value` interface is successfully created, by reading the sensor's |
| 263 | * corresponding sysfs file's value, the additional interfaces for the sensor |
Matthew Barth | d238e23 | 2018-04-17 12:01:50 -0500 | [diff] [blame] | 264 | * are created and the InterfacesAdded signal is emitted. The object's state |
| 265 | * data is then returned for sensor state monitoring within the main loop. |
Matthew Barth | 979c806 | 2018-04-17 11:37:15 -0500 | [diff] [blame] | 266 | */ |
Matthew Barth | d238e23 | 2018-04-17 12:01:50 -0500 | [diff] [blame] | 267 | optional_ns::optional<ObjectStateData> MainLoop::getObject( |
| 268 | SensorSet::container_t::const_reference sensor) |
Matthew Barth | 979c806 | 2018-04-17 11:37:15 -0500 | [diff] [blame] | 269 | { |
| 270 | auto properties = getIdentifiers(sensor); |
| 271 | if (std::get<sensorID>(properties).empty() || |
| 272 | std::get<sensorLabel>(properties).empty()) |
Matthew Barth | 31d214c | 2018-03-26 09:54:27 -0500 | [diff] [blame] | 273 | { |
Matthew Barth | d238e23 | 2018-04-17 12:01:50 -0500 | [diff] [blame] | 274 | return {}; |
Matthew Barth | 31d214c | 2018-03-26 09:54:27 -0500 | [diff] [blame] | 275 | } |
| 276 | |
Patrick Venture | 0979185 | 2018-04-17 17:40:00 -0700 | [diff] [blame] | 277 | hwmon::Attributes attrs; |
| 278 | if (!hwmon::getAttributes(sensor.first.first, attrs)) |
Matthew Barth | 31d214c | 2018-03-26 09:54:27 -0500 | [diff] [blame] | 279 | { |
Matthew Barth | d238e23 | 2018-04-17 12:01:50 -0500 | [diff] [blame] | 280 | return {}; |
Matthew Barth | 31d214c | 2018-03-26 09:54:27 -0500 | [diff] [blame] | 281 | } |
| 282 | |
Matthew Barth | b798527 | 2018-04-17 10:50:36 -0500 | [diff] [blame] | 283 | // Get list of return codes for removing sensors on device |
| 284 | auto devRmRCs = env::getEnv("REMOVERCS"); |
| 285 | // Add sensor removal return codes defined at the device level |
| 286 | addRemoveRCs(sensor.first, devRmRCs); |
Matthew Barth | 31d214c | 2018-03-26 09:54:27 -0500 | [diff] [blame] | 287 | |
| 288 | std::string objectPath{_root}; |
| 289 | objectPath.append(1, '/'); |
Patrick Venture | 0979185 | 2018-04-17 17:40:00 -0700 | [diff] [blame] | 290 | objectPath.append(hwmon::getNamespace(attrs)); |
Matthew Barth | 31d214c | 2018-03-26 09:54:27 -0500 | [diff] [blame] | 291 | objectPath.append(1, '/'); |
Matthew Barth | 979c806 | 2018-04-17 11:37:15 -0500 | [diff] [blame] | 292 | objectPath.append(std::get<sensorLabel>(properties)); |
Matthew Barth | 31d214c | 2018-03-26 09:54:27 -0500 | [diff] [blame] | 293 | |
| 294 | ObjectInfo info(&_bus, std::move(objectPath), Object()); |
Patrick Venture | 75e56c6 | 2018-04-20 18:10:15 -0700 | [diff] [blame] | 295 | RetryIO retryIO(hwmonio::retries, hwmonio::delay); |
Matthew Barth | d4beecf | 2018-04-03 15:50:22 -0500 | [diff] [blame] | 296 | if (rmSensors.find(sensor.first) != rmSensors.end()) |
| 297 | { |
| 298 | // When adding a sensor that was purposely removed, |
| 299 | // don't retry on errors when reading its value |
| 300 | std::get<size_t>(retryIO) = 0; |
| 301 | } |
Matthew Barth | 31d214c | 2018-03-26 09:54:27 -0500 | [diff] [blame] | 302 | auto valueInterface = static_cast< |
| 303 | std::shared_ptr<ValueObject>>(nullptr); |
| 304 | try |
| 305 | { |
Matthew Barth | ca44c2e | 2018-04-24 15:33:25 -0500 | [diff] [blame] | 306 | // Add status interface based on _fault file being present |
| 307 | sensor::addStatus(sensor.first, ioAccess, _devPath, info); |
Matthew Barth | 0b30505 | 2018-04-26 09:46:49 -0500 | [diff] [blame^] | 308 | valueInterface = addValue(sensor.first, retryIO, ioAccess, info); |
Matthew Barth | 31d214c | 2018-03-26 09:54:27 -0500 | [diff] [blame] | 309 | } |
| 310 | catch (const std::system_error& e) |
| 311 | { |
Matthew Barth | 38c74e7 | 2018-04-02 12:41:26 -0500 | [diff] [blame] | 312 | auto file = sysfs::make_sysfs_path( |
| 313 | ioAccess.path(), |
| 314 | sensor.first.first, |
| 315 | sensor.first.second, |
| 316 | hwmon::entry::cinput); |
Matthew Barth | 31d214c | 2018-03-26 09:54:27 -0500 | [diff] [blame] | 317 | #ifndef REMOVE_ON_FAIL |
| 318 | // Check sensorAdjusts for sensor removal RCs |
| 319 | const auto& it = sensorAdjusts.find(sensor.first); |
| 320 | if (it != sensorAdjusts.end()) |
| 321 | { |
| 322 | auto rmRCit = it->second.rmRCs.find(e.code().value()); |
| 323 | if (rmRCit != std::end(it->second.rmRCs)) |
| 324 | { |
Matthew Barth | 38c74e7 | 2018-04-02 12:41:26 -0500 | [diff] [blame] | 325 | // Return code found in sensor return code removal list |
| 326 | if (rmSensors.find(sensor.first) == rmSensors.end()) |
| 327 | { |
| 328 | // Trace for sensor not already removed from dbus |
| 329 | log<level::INFO>("Sensor not added to dbus for read fail", |
| 330 | entry("FILE=%s", file.c_str()), |
| 331 | entry("RC=%d", e.code().value())); |
| 332 | rmSensors[std::move(sensor.first)] = |
| 333 | std::move(sensor.second); |
| 334 | } |
Matthew Barth | d238e23 | 2018-04-17 12:01:50 -0500 | [diff] [blame] | 335 | return {}; |
Matthew Barth | 31d214c | 2018-03-26 09:54:27 -0500 | [diff] [blame] | 336 | } |
| 337 | } |
| 338 | #endif |
| 339 | using namespace sdbusplus::xyz::openbmc_project:: |
| 340 | Sensor::Device::Error; |
| 341 | report<ReadFailure>( |
| 342 | xyz::openbmc_project::Sensor::Device:: |
| 343 | ReadFailure::CALLOUT_ERRNO(e.code().value()), |
| 344 | xyz::openbmc_project::Sensor::Device:: |
| 345 | ReadFailure::CALLOUT_DEVICE_PATH(_devPath.c_str())); |
| 346 | |
Matthew Barth | 31d214c | 2018-03-26 09:54:27 -0500 | [diff] [blame] | 347 | log<level::INFO>("Logging failing sysfs file", |
| 348 | entry("FILE=%s", file.c_str())); |
| 349 | #ifdef REMOVE_ON_FAIL |
Matthew Barth | d238e23 | 2018-04-17 12:01:50 -0500 | [diff] [blame] | 350 | return {}; /* skip adding this sensor for now. */ |
Matthew Barth | 31d214c | 2018-03-26 09:54:27 -0500 | [diff] [blame] | 351 | #else |
| 352 | exit(EXIT_FAILURE); |
| 353 | #endif |
| 354 | } |
| 355 | auto sensorValue = valueInterface->value(); |
Matthew Barth | 979c806 | 2018-04-17 11:37:15 -0500 | [diff] [blame] | 356 | addThreshold<WarningObject>(sensor.first.first, |
| 357 | std::get<sensorID>(properties), |
| 358 | sensorValue, |
| 359 | info); |
| 360 | addThreshold<CriticalObject>(sensor.first.first, |
| 361 | std::get<sensorID>(properties), |
| 362 | sensorValue, |
| 363 | info); |
Matthew Barth | 31d214c | 2018-03-26 09:54:27 -0500 | [diff] [blame] | 364 | |
Matthew Barth | 28f8e66 | 2018-03-26 16:57:36 -0500 | [diff] [blame] | 365 | auto target = addTarget<hwmon::FanSpeed>( |
| 366 | sensor.first, ioAccess, _devPath, info); |
| 367 | if (target) |
Matthew Barth | 31d214c | 2018-03-26 09:54:27 -0500 | [diff] [blame] | 368 | { |
Matthew Barth | 28f8e66 | 2018-03-26 16:57:36 -0500 | [diff] [blame] | 369 | target->enable(); |
Matthew Barth | 31d214c | 2018-03-26 09:54:27 -0500 | [diff] [blame] | 370 | } |
Matthew Barth | 28f8e66 | 2018-03-26 16:57:36 -0500 | [diff] [blame] | 371 | addTarget<hwmon::FanPwm>(sensor.first, ioAccess, _devPath, info); |
Matthew Barth | 31d214c | 2018-03-26 09:54:27 -0500 | [diff] [blame] | 372 | |
| 373 | // All the interfaces have been created. Go ahead |
| 374 | // and emit InterfacesAdded. |
| 375 | valueInterface->emit_object_added(); |
| 376 | |
Matthew Barth | d238e23 | 2018-04-17 12:01:50 -0500 | [diff] [blame] | 377 | return std::make_pair(std::move(std::get<sensorLabel>(properties)), |
| 378 | std::move(info)); |
Matthew Barth | 31d214c | 2018-03-26 09:54:27 -0500 | [diff] [blame] | 379 | } |
| 380 | |
Brad Bishop | b9e2b07 | 2016-12-19 13:47:10 -0500 | [diff] [blame] | 381 | MainLoop::MainLoop( |
Brad Bishop | 9c7b6e0 | 2016-12-19 12:43:36 -0500 | [diff] [blame] | 382 | sdbusplus::bus::bus&& bus, |
Brad Bishop | b9e2b07 | 2016-12-19 13:47:10 -0500 | [diff] [blame] | 383 | const std::string& path, |
Brad Bishop | f3aa9ae | 2017-08-25 09:56:02 -0400 | [diff] [blame] | 384 | const std::string& devPath, |
Brad Bishop | b9e2b07 | 2016-12-19 13:47:10 -0500 | [diff] [blame] | 385 | const char* prefix, |
| 386 | const char* root) |
Brad Bishop | 9c7b6e0 | 2016-12-19 12:43:36 -0500 | [diff] [blame] | 387 | : _bus(std::move(bus)), |
Brad Bishop | 03e8735 | 2017-03-07 00:12:22 -0500 | [diff] [blame] | 388 | _manager(_bus, root), |
Brad Bishop | b8740fc | 2017-02-24 23:38:37 -0500 | [diff] [blame] | 389 | _hwmonRoot(), |
| 390 | _instance(), |
Brad Bishop | f3aa9ae | 2017-08-25 09:56:02 -0400 | [diff] [blame] | 391 | _devPath(devPath), |
Brad Bishop | b9e2b07 | 2016-12-19 13:47:10 -0500 | [diff] [blame] | 392 | _prefix(prefix), |
Brad Bishop | 3c344d3 | 2017-01-05 11:48:39 -0500 | [diff] [blame] | 393 | _root(root), |
Brad Bishop | 751043e | 2017-08-29 11:13:46 -0400 | [diff] [blame] | 394 | state(), |
| 395 | ioAccess(path) |
Brad Bishop | d499ca6 | 2016-12-19 09:24:50 -0500 | [diff] [blame] | 396 | { |
Patrick Venture | 73a50c7 | 2018-04-17 15:19:03 -0700 | [diff] [blame] | 397 | // Strip off any trailing slashes. |
Brad Bishop | b8740fc | 2017-02-24 23:38:37 -0500 | [diff] [blame] | 398 | std::string p = path; |
| 399 | while (!p.empty() && p.back() == '/') |
Brad Bishop | 9c7b6e0 | 2016-12-19 12:43:36 -0500 | [diff] [blame] | 400 | { |
Brad Bishop | b8740fc | 2017-02-24 23:38:37 -0500 | [diff] [blame] | 401 | p.pop_back(); |
Brad Bishop | 9c7b6e0 | 2016-12-19 12:43:36 -0500 | [diff] [blame] | 402 | } |
Brad Bishop | b8740fc | 2017-02-24 23:38:37 -0500 | [diff] [blame] | 403 | |
Patrick Venture | 73a50c7 | 2018-04-17 15:19:03 -0700 | [diff] [blame] | 404 | // Given the furthest right /, set instance to |
| 405 | // the basename, and hwmonRoot to the leading path. |
Brad Bishop | b8740fc | 2017-02-24 23:38:37 -0500 | [diff] [blame] | 406 | auto n = p.rfind('/'); |
| 407 | if (n != std::string::npos) |
| 408 | { |
| 409 | _instance.assign(p.substr(n + 1)); |
| 410 | _hwmonRoot.assign(p.substr(0, n)); |
| 411 | } |
| 412 | |
| 413 | assert(!_instance.empty()); |
| 414 | assert(!_hwmonRoot.empty()); |
Brad Bishop | d499ca6 | 2016-12-19 09:24:50 -0500 | [diff] [blame] | 415 | } |
| 416 | |
| 417 | void MainLoop::shutdown() noexcept |
| 418 | { |
Deepak Kodihalli | 2a51a9c | 2018-03-07 02:39:40 -0600 | [diff] [blame] | 419 | timer->state(phosphor::hwmon::timer::OFF); |
| 420 | sd_event_exit(loop, 0); |
| 421 | loop = nullptr; |
Brad Bishop | d499ca6 | 2016-12-19 09:24:50 -0500 | [diff] [blame] | 422 | } |
| 423 | |
| 424 | void MainLoop::run() |
Brad Bishop | e55ef3d | 2016-12-19 09:12:40 -0500 | [diff] [blame] | 425 | { |
Deepak Kodihalli | 2a51a9c | 2018-03-07 02:39:40 -0600 | [diff] [blame] | 426 | init(); |
| 427 | |
| 428 | sd_event_default(&loop); |
| 429 | |
| 430 | std::function<void()> callback(std::bind( |
| 431 | &MainLoop::read, this)); |
| 432 | try |
| 433 | { |
| 434 | timer = std::make_unique<phosphor::hwmon::Timer>( |
| 435 | loop, callback, |
| 436 | std::chrono::microseconds(_interval), |
| 437 | phosphor::hwmon::timer::ON); |
| 438 | |
| 439 | // TODO: Issue#6 - Optionally look at polling interval sysfs entry. |
| 440 | |
| 441 | // TODO: Issue#7 - Should probably periodically check the SensorSet |
| 442 | // for new entries. |
| 443 | |
| 444 | _bus.attach_event(loop, SD_EVENT_PRIORITY_IMPORTANT); |
| 445 | sd_event_loop(loop); |
| 446 | } |
| 447 | catch (const std::system_error& e) |
| 448 | { |
| 449 | log<level::ERR>("Error in sysfs polling loop", |
| 450 | entry("ERROR=%s", e.what())); |
| 451 | throw; |
| 452 | } |
| 453 | } |
| 454 | |
| 455 | void MainLoop::init() |
| 456 | { |
Brad Bishop | e55ef3d | 2016-12-19 09:12:40 -0500 | [diff] [blame] | 457 | // Check sysfs for available sensors. |
Brad Bishop | 4db6442 | 2017-02-16 11:33:32 -0500 | [diff] [blame] | 458 | auto sensors = std::make_unique<SensorSet>(_hwmonRoot + '/' + _instance); |
Brad Bishop | e55ef3d | 2016-12-19 09:12:40 -0500 | [diff] [blame] | 459 | |
Brad Bishop | 75b4ab8 | 2017-01-06 09:33:50 -0500 | [diff] [blame] | 460 | for (auto& i : *sensors) |
| 461 | { |
Matthew Barth | d238e23 | 2018-04-17 12:01:50 -0500 | [diff] [blame] | 462 | auto object = getObject(i); |
| 463 | if (object) |
| 464 | { |
| 465 | // Construct the SensorSet value |
| 466 | // std::tuple<SensorSet::mapped_type, |
| 467 | // std::string(Sensor Label), |
| 468 | // ObjectInfo> |
| 469 | auto value = std::make_tuple(std::move(i.second), |
| 470 | std::move((*object).first), |
| 471 | std::move((*object).second)); |
| 472 | |
| 473 | state[std::move(i.first)] = std::move(value); |
| 474 | } |
Brad Bishop | 75b4ab8 | 2017-01-06 09:33:50 -0500 | [diff] [blame] | 475 | } |
| 476 | |
Patrick Venture | 62503a4 | 2017-05-23 07:30:29 -0700 | [diff] [blame] | 477 | /* If there are no sensors specified by labels, exit. */ |
| 478 | if (0 == state.size()) |
| 479 | { |
Deepak Kodihalli | 2a51a9c | 2018-03-07 02:39:40 -0600 | [diff] [blame] | 480 | exit(0); |
Patrick Venture | 62503a4 | 2017-05-23 07:30:29 -0700 | [diff] [blame] | 481 | } |
| 482 | |
Brad Bishop | 9c7b6e0 | 2016-12-19 12:43:36 -0500 | [diff] [blame] | 483 | { |
Brad Bishop | b8740fc | 2017-02-24 23:38:37 -0500 | [diff] [blame] | 484 | std::string busname{_prefix}; |
Brad Bishop | 4d9a35b | 2017-11-14 22:33:03 -0500 | [diff] [blame] | 485 | busname.append(1, '-'); |
| 486 | busname.append( |
| 487 | std::to_string(std::hash<decltype(_devPath)>{}(_devPath))); |
| 488 | busname.append(".Hwmon1"); |
Brad Bishop | 9c7b6e0 | 2016-12-19 12:43:36 -0500 | [diff] [blame] | 489 | _bus.request_name(busname.c_str()); |
| 490 | } |
| 491 | |
Patrick Venture | ab10f16 | 2017-05-22 09:44:50 -0700 | [diff] [blame] | 492 | { |
Patrick Venture | a24c880 | 2018-04-17 19:38:06 -0700 | [diff] [blame] | 493 | auto interval = env::getEnv("INTERVAL"); |
| 494 | if (!interval.empty()) |
Patrick Venture | ab10f16 | 2017-05-22 09:44:50 -0700 | [diff] [blame] | 495 | { |
Patrick Venture | 50cf1c5 | 2018-04-18 09:21:41 -0700 | [diff] [blame] | 496 | _interval = std::strtoull(interval.c_str(), NULL, 10); |
Patrick Venture | ab10f16 | 2017-05-22 09:44:50 -0700 | [diff] [blame] | 497 | } |
| 498 | } |
Deepak Kodihalli | 2a51a9c | 2018-03-07 02:39:40 -0600 | [diff] [blame] | 499 | } |
Patrick Venture | ab10f16 | 2017-05-22 09:44:50 -0700 | [diff] [blame] | 500 | |
Deepak Kodihalli | 2a51a9c | 2018-03-07 02:39:40 -0600 | [diff] [blame] | 501 | void MainLoop::read() |
| 502 | { |
Brad Bishop | e55ef3d | 2016-12-19 09:12:40 -0500 | [diff] [blame] | 503 | // TODO: Issue#3 - Need to make calls to the dbus sensor cache here to |
| 504 | // ensure the objects all exist? |
| 505 | |
Deepak Kodihalli | 2a51a9c | 2018-03-07 02:39:40 -0600 | [diff] [blame] | 506 | // Iterate through all the sensors. |
| 507 | for (auto& i : state) |
| 508 | { |
| 509 | auto& attrs = std::get<0>(i.second); |
| 510 | if (attrs.find(hwmon::entry::input) != attrs.end()) |
Brad Bishop | e55ef3d | 2016-12-19 09:12:40 -0500 | [diff] [blame] | 511 | { |
Deepak Kodihalli | 2a51a9c | 2018-03-07 02:39:40 -0600 | [diff] [blame] | 512 | // Read value from sensor. |
| 513 | int64_t value; |
| 514 | std::string input = hwmon::entry::cinput; |
| 515 | if (i.first.first == "pwm") { |
| 516 | input = ""; |
| 517 | } |
| 518 | |
| 519 | try |
Brad Bishop | e55ef3d | 2016-12-19 09:12:40 -0500 | [diff] [blame] | 520 | { |
Matthew Barth | 27c4a39 | 2018-04-25 14:38:51 -0500 | [diff] [blame] | 521 | auto& objInfo = std::get<ObjectInfo>(i.second); |
| 522 | auto& obj = std::get<Object>(objInfo); |
| 523 | |
| 524 | auto it = obj.find(InterfaceType::STATUS); |
| 525 | if (it != obj.end()) |
| 526 | { |
Matthew Barth | bfcaf3d | 2018-04-25 15:05:58 -0500 | [diff] [blame] | 527 | auto fault = ioAccess.read( |
| 528 | i.first.first, |
| 529 | i.first.second, |
| 530 | hwmon::entry::fault, |
| 531 | hwmonio::retries, |
| 532 | hwmonio::delay); |
Matthew Barth | 27c4a39 | 2018-04-25 14:38:51 -0500 | [diff] [blame] | 533 | auto statusIface = std::experimental::any_cast< |
| 534 | std::shared_ptr<StatusObject>>(it->second); |
Matthew Barth | bfcaf3d | 2018-04-25 15:05:58 -0500 | [diff] [blame] | 535 | if (!statusIface->functional((fault == 0) ? true : false)) |
Matthew Barth | 27c4a39 | 2018-04-25 14:38:51 -0500 | [diff] [blame] | 536 | { |
| 537 | continue; |
| 538 | } |
| 539 | } |
| 540 | |
Deepak Kodihalli | 2a51a9c | 2018-03-07 02:39:40 -0600 | [diff] [blame] | 541 | // Retry for up to a second if device is busy |
| 542 | // or has a transient error. |
Patrick Venture | 9331ab7 | 2018-01-29 09:48:47 -0800 | [diff] [blame] | 543 | |
Deepak Kodihalli | 2a51a9c | 2018-03-07 02:39:40 -0600 | [diff] [blame] | 544 | value = ioAccess.read( |
| 545 | i.first.first, |
| 546 | i.first.second, |
| 547 | input, |
Patrick Venture | 75e56c6 | 2018-04-20 18:10:15 -0700 | [diff] [blame] | 548 | hwmonio::retries, |
Matthew Barth | 0b30505 | 2018-04-26 09:46:49 -0500 | [diff] [blame^] | 549 | hwmonio::delay); |
Deepak Kodihalli | 2a51a9c | 2018-03-07 02:39:40 -0600 | [diff] [blame] | 550 | |
| 551 | value = adjustValue(i.first, value); |
| 552 | |
Deepak Kodihalli | 2a51a9c | 2018-03-07 02:39:40 -0600 | [diff] [blame] | 553 | for (auto& iface : obj) |
Brad Bishop | dddb715 | 2017-01-06 09:54:23 -0500 | [diff] [blame] | 554 | { |
Deepak Kodihalli | 2a51a9c | 2018-03-07 02:39:40 -0600 | [diff] [blame] | 555 | auto valueIface = std::shared_ptr<ValueObject>(); |
| 556 | auto warnIface = std::shared_ptr<WarningObject>(); |
| 557 | auto critIface = std::shared_ptr<CriticalObject>(); |
Brad Bishop | 754d38c | 2017-09-08 00:46:58 -0400 | [diff] [blame] | 558 | |
Deepak Kodihalli | 2a51a9c | 2018-03-07 02:39:40 -0600 | [diff] [blame] | 559 | switch (iface.first) |
Brad Bishop | e0b7d05 | 2017-01-06 15:30:23 -0500 | [diff] [blame] | 560 | { |
Deepak Kodihalli | 2a51a9c | 2018-03-07 02:39:40 -0600 | [diff] [blame] | 561 | case InterfaceType::VALUE: |
| 562 | valueIface = std::experimental::any_cast<std::shared_ptr<ValueObject>> |
| 563 | (iface.second); |
| 564 | valueIface->value(value); |
| 565 | break; |
| 566 | case InterfaceType::WARN: |
| 567 | checkThresholds<WarningObject>(iface.second, value); |
| 568 | break; |
| 569 | case InterfaceType::CRIT: |
| 570 | checkThresholds<CriticalObject>(iface.second, value); |
| 571 | break; |
| 572 | default: |
| 573 | break; |
Brad Bishop | e0b7d05 | 2017-01-06 15:30:23 -0500 | [diff] [blame] | 574 | } |
Brad Bishop | dddb715 | 2017-01-06 09:54:23 -0500 | [diff] [blame] | 575 | } |
Deepak Kodihalli | 2a51a9c | 2018-03-07 02:39:40 -0600 | [diff] [blame] | 576 | } |
| 577 | catch (const std::system_error& e) |
| 578 | { |
Matthew Barth | 38c74e7 | 2018-04-02 12:41:26 -0500 | [diff] [blame] | 579 | auto file = sysfs::make_sysfs_path( |
| 580 | ioAccess.path(), |
| 581 | i.first.first, |
| 582 | i.first.second, |
| 583 | hwmon::entry::cinput); |
Matthew Barth | 8772ce3 | 2018-03-22 16:03:06 -0500 | [diff] [blame] | 584 | #ifndef REMOVE_ON_FAIL |
| 585 | // Check sensorAdjusts for sensor removal RCs |
| 586 | const auto& it = sensorAdjusts.find(i.first); |
| 587 | if (it != sensorAdjusts.end()) |
| 588 | { |
| 589 | auto rmRCit = it->second.rmRCs.find(e.code().value()); |
| 590 | if (rmRCit != std::end(it->second.rmRCs)) |
| 591 | { |
Matthew Barth | 38c74e7 | 2018-04-02 12:41:26 -0500 | [diff] [blame] | 592 | // Return code found in sensor return code removal list |
| 593 | if (rmSensors.find(i.first) == rmSensors.end()) |
| 594 | { |
| 595 | // Trace for sensor not already removed from dbus |
| 596 | log<level::INFO>( |
| 597 | "Remove sensor from dbus for read fail", |
| 598 | entry("FILE=%s", file.c_str()), |
| 599 | entry("RC=%d", e.code().value())); |
| 600 | // Mark this sensor to be removed from dbus |
| 601 | rmSensors[i.first] = std::get<0>(i.second); |
| 602 | } |
Matthew Barth | 8772ce3 | 2018-03-22 16:03:06 -0500 | [diff] [blame] | 603 | continue; |
| 604 | } |
| 605 | } |
| 606 | #endif |
Deepak Kodihalli | 2a51a9c | 2018-03-07 02:39:40 -0600 | [diff] [blame] | 607 | using namespace sdbusplus::xyz::openbmc_project:: |
| 608 | Sensor::Device::Error; |
| 609 | report<ReadFailure>( |
| 610 | xyz::openbmc_project::Sensor::Device:: |
| 611 | ReadFailure::CALLOUT_ERRNO(e.code().value()), |
| 612 | xyz::openbmc_project::Sensor::Device:: |
| 613 | ReadFailure::CALLOUT_DEVICE_PATH( |
| 614 | _devPath.c_str())); |
Matt Spinler | 9b65f76 | 2017-10-05 10:36:22 -0500 | [diff] [blame] | 615 | |
Deepak Kodihalli | 2a51a9c | 2018-03-07 02:39:40 -0600 | [diff] [blame] | 616 | log<level::INFO>("Logging failing sysfs file", |
| 617 | entry("FILE=%s", file.c_str())); |
Matt Spinler | 9b65f76 | 2017-10-05 10:36:22 -0500 | [diff] [blame] | 618 | |
Matt Spinler | f9c83c4 | 2017-08-10 08:51:45 -0500 | [diff] [blame] | 619 | #ifdef REMOVE_ON_FAIL |
Matthew Barth | 33db92b | 2018-03-26 09:55:19 -0500 | [diff] [blame] | 620 | rmSensors[i.first] = std::get<0>(i.second); |
Matt Spinler | f9c83c4 | 2017-08-10 08:51:45 -0500 | [diff] [blame] | 621 | #else |
Deepak Kodihalli | 2a51a9c | 2018-03-07 02:39:40 -0600 | [diff] [blame] | 622 | exit(EXIT_FAILURE); |
Matt Spinler | f9c83c4 | 2017-08-10 08:51:45 -0500 | [diff] [blame] | 623 | #endif |
Brad Bishop | e55ef3d | 2016-12-19 09:12:40 -0500 | [diff] [blame] | 624 | } |
| 625 | } |
Deepak Kodihalli | 2a51a9c | 2018-03-07 02:39:40 -0600 | [diff] [blame] | 626 | } |
Brad Bishop | e55ef3d | 2016-12-19 09:12:40 -0500 | [diff] [blame] | 627 | |
Matthew Barth | 8772ce3 | 2018-03-22 16:03:06 -0500 | [diff] [blame] | 628 | // Remove any sensors marked for removal |
Matthew Barth | 33db92b | 2018-03-26 09:55:19 -0500 | [diff] [blame] | 629 | for (auto& i : rmSensors) |
Deepak Kodihalli | 2a51a9c | 2018-03-07 02:39:40 -0600 | [diff] [blame] | 630 | { |
Matthew Barth | 33db92b | 2018-03-26 09:55:19 -0500 | [diff] [blame] | 631 | state.erase(i.first); |
Brad Bishop | e55ef3d | 2016-12-19 09:12:40 -0500 | [diff] [blame] | 632 | } |
Matthew Barth | 31d214c | 2018-03-26 09:54:27 -0500 | [diff] [blame] | 633 | |
| 634 | #ifndef REMOVE_ON_FAIL |
| 635 | // Attempt to add any sensors that were removed |
| 636 | auto it = rmSensors.begin(); |
| 637 | while (it != rmSensors.end()) |
| 638 | { |
| 639 | if (state.find(it->first) == state.end()) |
| 640 | { |
| 641 | SensorSet::container_t::value_type ssValueType = |
| 642 | std::make_pair(it->first, it->second); |
Matthew Barth | d238e23 | 2018-04-17 12:01:50 -0500 | [diff] [blame] | 643 | auto object = getObject(ssValueType); |
| 644 | if (object) |
Matthew Barth | 31d214c | 2018-03-26 09:54:27 -0500 | [diff] [blame] | 645 | { |
Matthew Barth | d238e23 | 2018-04-17 12:01:50 -0500 | [diff] [blame] | 646 | // Construct the SensorSet value |
| 647 | // std::tuple<SensorSet::mapped_type, |
| 648 | // std::string(Sensor Label), |
| 649 | // ObjectInfo> |
| 650 | auto value = std::make_tuple(std::move(ssValueType.second), |
| 651 | std::move((*object).first), |
| 652 | std::move((*object).second)); |
| 653 | |
| 654 | state[std::move(ssValueType.first)] = std::move(value); |
| 655 | |
Matthew Barth | 31d214c | 2018-03-26 09:54:27 -0500 | [diff] [blame] | 656 | // Sensor object added, erase entry from removal list |
Matthew Barth | 38c74e7 | 2018-04-02 12:41:26 -0500 | [diff] [blame] | 657 | auto file = sysfs::make_sysfs_path( |
| 658 | ioAccess.path(), |
| 659 | it->first.first, |
| 660 | it->first.second, |
| 661 | hwmon::entry::cinput); |
| 662 | log<level::INFO>( |
| 663 | "Added sensor to dbus after successful read", |
| 664 | entry("FILE=%s", file.c_str())); |
Matthew Barth | 31d214c | 2018-03-26 09:54:27 -0500 | [diff] [blame] | 665 | it = rmSensors.erase(it); |
| 666 | } |
| 667 | else |
| 668 | { |
| 669 | ++it; |
| 670 | } |
| 671 | } |
| 672 | else |
| 673 | { |
| 674 | // Sanity check to remove sensors that were re-added |
| 675 | it = rmSensors.erase(it); |
| 676 | } |
| 677 | } |
| 678 | #endif |
Brad Bishop | e55ef3d | 2016-12-19 09:12:40 -0500 | [diff] [blame] | 679 | } |
| 680 | |
| 681 | // vim: tabstop=8 expandtab shiftwidth=4 softtabstop=4 |