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