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 | */ |
| 16 | #include <iostream> |
| 17 | #include <memory> |
Brad Bishop | 9c7b6e0 | 2016-12-19 12:43:36 -0500 | [diff] [blame] | 18 | #include <cstdlib> |
Brad Bishop | 74aa4dd | 2017-01-06 09:50:31 -0500 | [diff] [blame] | 19 | #include <algorithm> |
Patrick Venture | 1e6324f | 2017-06-01 14:07:05 -0700 | [diff] [blame^] | 20 | |
| 21 | #include <phosphor-logging/elog-errors.hpp> |
Brad Bishop | e55ef3d | 2016-12-19 09:12:40 -0500 | [diff] [blame] | 22 | #include "sensorset.hpp" |
Brad Bishop | e55ef3d | 2016-12-19 09:12:40 -0500 | [diff] [blame] | 23 | #include "hwmon.hpp" |
| 24 | #include "sysfs.hpp" |
Brad Bishop | d499ca6 | 2016-12-19 09:24:50 -0500 | [diff] [blame] | 25 | #include "mainloop.hpp" |
Brad Bishop | f3df6b4 | 2017-01-06 10:14:09 -0500 | [diff] [blame] | 26 | #include "env.hpp" |
Brad Bishop | e0b7d05 | 2017-01-06 15:30:23 -0500 | [diff] [blame] | 27 | #include "thresholds.hpp" |
Matthew Barth | bf7b7b1 | 2017-03-07 15:46:59 -0600 | [diff] [blame] | 28 | #include "targets.hpp" |
Matthew Barth | 048ac87 | 2017-03-09 14:36:08 -0600 | [diff] [blame] | 29 | #include "fan_speed.hpp" |
Brad Bishop | e55ef3d | 2016-12-19 09:12:40 -0500 | [diff] [blame] | 30 | |
Patrick Venture | 1e6324f | 2017-06-01 14:07:05 -0700 | [diff] [blame^] | 31 | #include <xyz/openbmc_project/Sensor/Device/error.hpp> |
| 32 | |
| 33 | using namespace phosphor::logging; |
| 34 | |
Saqib Khan | 973886d | 2017-03-15 14:01:16 -0500 | [diff] [blame] | 35 | // Initialization for Warning Objects |
| 36 | decltype(Thresholds<WarningObject>::setLo) Thresholds<WarningObject>::setLo = |
| 37 | &WarningObject::warningLow; |
| 38 | decltype(Thresholds<WarningObject>::setHi) Thresholds<WarningObject>::setHi = |
| 39 | &WarningObject::warningHigh; |
| 40 | decltype(Thresholds<WarningObject>::getLo) Thresholds<WarningObject>::getLo = |
| 41 | &WarningObject::warningLow; |
| 42 | decltype(Thresholds<WarningObject>::getHi) Thresholds<WarningObject>::getHi = |
| 43 | &WarningObject::warningHigh; |
| 44 | decltype(Thresholds<WarningObject>::alarmLo) Thresholds<WarningObject>::alarmLo = |
| 45 | &WarningObject::warningAlarmLow; |
| 46 | decltype(Thresholds<WarningObject>::alarmHi) Thresholds<WarningObject>::alarmHi = |
| 47 | &WarningObject::warningAlarmHigh; |
| 48 | |
| 49 | // Initialization for Critical Objects |
| 50 | decltype(Thresholds<CriticalObject>::setLo) Thresholds<CriticalObject>::setLo = |
| 51 | &CriticalObject::criticalLow; |
| 52 | decltype(Thresholds<CriticalObject>::setHi) Thresholds<CriticalObject>::setHi = |
| 53 | &CriticalObject::criticalHigh; |
| 54 | decltype(Thresholds<CriticalObject>::getLo) Thresholds<CriticalObject>::getLo = |
| 55 | &CriticalObject::criticalLow; |
| 56 | decltype(Thresholds<CriticalObject>::getHi) Thresholds<CriticalObject>::getHi = |
| 57 | &CriticalObject::criticalHigh; |
| 58 | decltype(Thresholds<CriticalObject>::alarmLo) Thresholds<CriticalObject>::alarmLo = |
| 59 | &CriticalObject::criticalAlarmLow; |
| 60 | decltype(Thresholds<CriticalObject>::alarmHi) Thresholds<CriticalObject>::alarmHi = |
| 61 | &CriticalObject::criticalAlarmHigh; |
| 62 | |
| 63 | |
Brad Bishop | 9c7b6e0 | 2016-12-19 12:43:36 -0500 | [diff] [blame] | 64 | |
Brad Bishop | 74aa4dd | 2017-01-06 09:50:31 -0500 | [diff] [blame] | 65 | static constexpr auto typeAttrMap = |
| 66 | { |
| 67 | // 1 - hwmon class |
| 68 | // 2 - unit |
| 69 | // 3 - sysfs scaling factor |
| 70 | std::make_tuple( |
| 71 | hwmon::type::ctemp, |
| 72 | ValueInterface::Unit::DegreesC, |
Brad Bishop | add9851 | 2017-01-06 22:01:19 -0500 | [diff] [blame] | 73 | -3, |
| 74 | "temperature"), |
Brad Bishop | 74aa4dd | 2017-01-06 09:50:31 -0500 | [diff] [blame] | 75 | std::make_tuple( |
| 76 | hwmon::type::cfan, |
| 77 | ValueInterface::Unit::RPMS, |
Brad Bishop | add9851 | 2017-01-06 22:01:19 -0500 | [diff] [blame] | 78 | 0, |
| 79 | "fan_tach"), |
Brad Bishop | 74aa4dd | 2017-01-06 09:50:31 -0500 | [diff] [blame] | 80 | std::make_tuple( |
| 81 | hwmon::type::cvolt, |
| 82 | ValueInterface::Unit::Volts, |
Brad Bishop | add9851 | 2017-01-06 22:01:19 -0500 | [diff] [blame] | 83 | -3, |
| 84 | "voltage"), |
Brad Bishop | 5afe21a | 2017-01-06 20:44:05 -0500 | [diff] [blame] | 85 | std::make_tuple( |
| 86 | hwmon::type::ccurr, |
| 87 | ValueInterface::Unit::Amperes, |
Brad Bishop | add9851 | 2017-01-06 22:01:19 -0500 | [diff] [blame] | 88 | -3, |
| 89 | "current"), |
Brad Bishop | 5afe21a | 2017-01-06 20:44:05 -0500 | [diff] [blame] | 90 | std::make_tuple( |
| 91 | hwmon::type::cenergy, |
| 92 | ValueInterface::Unit::Joules, |
Brad Bishop | add9851 | 2017-01-06 22:01:19 -0500 | [diff] [blame] | 93 | -6, |
| 94 | "energy"), |
Brad Bishop | 5afe21a | 2017-01-06 20:44:05 -0500 | [diff] [blame] | 95 | std::make_tuple( |
| 96 | hwmon::type::cpower, |
| 97 | ValueInterface::Unit::Watts, |
Brad Bishop | add9851 | 2017-01-06 22:01:19 -0500 | [diff] [blame] | 98 | -6, |
| 99 | "power"), |
Brad Bishop | 74aa4dd | 2017-01-06 09:50:31 -0500 | [diff] [blame] | 100 | }; |
| 101 | |
| 102 | auto getHwmonType(decltype(typeAttrMap)::const_reference attrs) |
| 103 | { |
| 104 | return std::get<0>(attrs); |
| 105 | } |
| 106 | |
| 107 | auto getUnit(decltype(typeAttrMap)::const_reference attrs) |
| 108 | { |
| 109 | return std::get<1>(attrs); |
| 110 | } |
| 111 | |
| 112 | auto getScale(decltype(typeAttrMap)::const_reference attrs) |
| 113 | { |
| 114 | return std::get<2>(attrs); |
| 115 | } |
| 116 | |
Brad Bishop | add9851 | 2017-01-06 22:01:19 -0500 | [diff] [blame] | 117 | auto getNamespace(decltype(typeAttrMap)::const_reference attrs) |
| 118 | { |
| 119 | return std::get<3>(attrs); |
| 120 | } |
| 121 | |
Brad Bishop | 951a79e | 2017-01-06 21:55:11 -0500 | [diff] [blame] | 122 | using AttributeIterator = decltype(*typeAttrMap.begin()); |
| 123 | using Attributes |
| 124 | = std::remove_cv<std::remove_reference<AttributeIterator>::type>::type; |
| 125 | |
| 126 | auto getAttributes(const std::string& type, Attributes& attributes) |
| 127 | { |
| 128 | // *INDENT-OFF* |
| 129 | auto a = std::find_if( |
| 130 | typeAttrMap.begin(), |
| 131 | typeAttrMap.end(), |
| 132 | [&](const auto & e) |
| 133 | { |
| 134 | return type == getHwmonType(e); |
| 135 | }); |
| 136 | // *INDENT-ON* |
| 137 | |
| 138 | if (a == typeAttrMap.end()) |
| 139 | { |
| 140 | return false; |
| 141 | } |
| 142 | |
| 143 | attributes = *a; |
| 144 | return true; |
| 145 | } |
| 146 | |
Brad Bishop | e9fdee0 | 2017-01-06 10:43:29 -0500 | [diff] [blame] | 147 | auto addValue(const SensorSet::key_type& sensor, |
Brad Bishop | 4db6442 | 2017-02-16 11:33:32 -0500 | [diff] [blame] | 148 | const std::string& hwmonRoot, |
| 149 | const std::string& instance, |
| 150 | ObjectInfo& info) |
Brad Bishop | e9fdee0 | 2017-01-06 10:43:29 -0500 | [diff] [blame] | 151 | { |
Brad Bishop | 30dbcee | 2017-01-18 07:55:42 -0500 | [diff] [blame] | 152 | static constexpr bool deferSignals = true; |
| 153 | |
Brad Bishop | e9fdee0 | 2017-01-06 10:43:29 -0500 | [diff] [blame] | 154 | // Get the initial value for the value interface. |
| 155 | auto& bus = *std::get<sdbusplus::bus::bus*>(info); |
| 156 | auto& obj = std::get<Object>(info); |
| 157 | auto& objPath = std::get<std::string>(info); |
| 158 | |
Patrick Venture | 1e6324f | 2017-06-01 14:07:05 -0700 | [diff] [blame^] | 159 | int val; |
| 160 | try |
| 161 | { |
| 162 | val = sysfs::readSysfsWithCallout(hwmonRoot, |
| 163 | instance, |
| 164 | sensor.first, |
| 165 | sensor.second, |
| 166 | hwmon::entry::input); |
| 167 | } |
| 168 | catch(const std::exception& ioe) |
| 169 | { |
| 170 | using namespace sdbusplus::xyz::openbmc_project::Sensor::Device::Error; |
| 171 | commit<ReadFailure>(); |
| 172 | |
| 173 | return static_cast<std::shared_ptr<ValueObject>>(nullptr); |
| 174 | } |
| 175 | |
Brad Bishop | 30dbcee | 2017-01-18 07:55:42 -0500 | [diff] [blame] | 176 | auto iface = std::make_shared<ValueObject>(bus, objPath.c_str(), deferSignals); |
Brad Bishop | e9fdee0 | 2017-01-06 10:43:29 -0500 | [diff] [blame] | 177 | iface->value(val); |
| 178 | |
Brad Bishop | 951a79e | 2017-01-06 21:55:11 -0500 | [diff] [blame] | 179 | Attributes attrs; |
| 180 | if (getAttributes(sensor.first, attrs)) |
Brad Bishop | e9fdee0 | 2017-01-06 10:43:29 -0500 | [diff] [blame] | 181 | { |
Brad Bishop | 951a79e | 2017-01-06 21:55:11 -0500 | [diff] [blame] | 182 | iface->unit(getUnit(attrs)); |
| 183 | iface->scale(getScale(attrs)); |
Brad Bishop | e9fdee0 | 2017-01-06 10:43:29 -0500 | [diff] [blame] | 184 | } |
| 185 | |
| 186 | obj[InterfaceType::VALUE] = iface; |
| 187 | return iface; |
| 188 | } |
| 189 | |
Brad Bishop | b9e2b07 | 2016-12-19 13:47:10 -0500 | [diff] [blame] | 190 | MainLoop::MainLoop( |
Brad Bishop | 9c7b6e0 | 2016-12-19 12:43:36 -0500 | [diff] [blame] | 191 | sdbusplus::bus::bus&& bus, |
Brad Bishop | b9e2b07 | 2016-12-19 13:47:10 -0500 | [diff] [blame] | 192 | const std::string& path, |
| 193 | const char* prefix, |
| 194 | const char* root) |
Brad Bishop | 9c7b6e0 | 2016-12-19 12:43:36 -0500 | [diff] [blame] | 195 | : _bus(std::move(bus)), |
Brad Bishop | 03e8735 | 2017-03-07 00:12:22 -0500 | [diff] [blame] | 196 | _manager(_bus, root), |
Brad Bishop | 9c7b6e0 | 2016-12-19 12:43:36 -0500 | [diff] [blame] | 197 | _shutdown(false), |
Brad Bishop | b8740fc | 2017-02-24 23:38:37 -0500 | [diff] [blame] | 198 | _hwmonRoot(), |
| 199 | _instance(), |
Brad Bishop | b9e2b07 | 2016-12-19 13:47:10 -0500 | [diff] [blame] | 200 | _prefix(prefix), |
Brad Bishop | 3c344d3 | 2017-01-05 11:48:39 -0500 | [diff] [blame] | 201 | _root(root), |
| 202 | state() |
Brad Bishop | d499ca6 | 2016-12-19 09:24:50 -0500 | [diff] [blame] | 203 | { |
Brad Bishop | b8740fc | 2017-02-24 23:38:37 -0500 | [diff] [blame] | 204 | std::string p = path; |
| 205 | while (!p.empty() && p.back() == '/') |
Brad Bishop | 9c7b6e0 | 2016-12-19 12:43:36 -0500 | [diff] [blame] | 206 | { |
Brad Bishop | b8740fc | 2017-02-24 23:38:37 -0500 | [diff] [blame] | 207 | p.pop_back(); |
Brad Bishop | 9c7b6e0 | 2016-12-19 12:43:36 -0500 | [diff] [blame] | 208 | } |
Brad Bishop | b8740fc | 2017-02-24 23:38:37 -0500 | [diff] [blame] | 209 | |
| 210 | auto n = p.rfind('/'); |
| 211 | if (n != std::string::npos) |
| 212 | { |
| 213 | _instance.assign(p.substr(n + 1)); |
| 214 | _hwmonRoot.assign(p.substr(0, n)); |
| 215 | } |
| 216 | |
| 217 | assert(!_instance.empty()); |
| 218 | assert(!_hwmonRoot.empty()); |
Brad Bishop | d499ca6 | 2016-12-19 09:24:50 -0500 | [diff] [blame] | 219 | } |
| 220 | |
| 221 | void MainLoop::shutdown() noexcept |
| 222 | { |
| 223 | _shutdown = true; |
| 224 | } |
| 225 | |
| 226 | void MainLoop::run() |
Brad Bishop | e55ef3d | 2016-12-19 09:12:40 -0500 | [diff] [blame] | 227 | { |
| 228 | // Check sysfs for available sensors. |
Brad Bishop | 4db6442 | 2017-02-16 11:33:32 -0500 | [diff] [blame] | 229 | auto sensors = std::make_unique<SensorSet>(_hwmonRoot + '/' + _instance); |
Brad Bishop | e55ef3d | 2016-12-19 09:12:40 -0500 | [diff] [blame] | 230 | |
Brad Bishop | 75b4ab8 | 2017-01-06 09:33:50 -0500 | [diff] [blame] | 231 | for (auto& i : *sensors) |
| 232 | { |
Tom Joseph | 1f8a958 | 2017-06-12 20:10:59 +0530 | [diff] [blame] | 233 | std::string label; |
Brad Bishop | f3df6b4 | 2017-01-06 10:14:09 -0500 | [diff] [blame] | 234 | |
Tom Joseph | 1f8a958 | 2017-06-12 20:10:59 +0530 | [diff] [blame] | 235 | /* |
| 236 | * Check if the value of the MODE_<item><X> env variable for the sensor |
| 237 | * is "label", then read the sensor number from the <item><X>_label |
| 238 | * file. The name of the DBUS object would be the value of the env |
| 239 | * variable LABEL_<item><sensorNum>. If the MODE_<item><X> env variable |
| 240 | * does'nt exist, then the name of DBUS object is the value of the env |
| 241 | * variable LABEL_<item><X>. |
| 242 | */ |
| 243 | auto mode = getEnv("MODE", i.first); |
| 244 | if (!mode.compare(hwmon::entry::label)) |
Brad Bishop | 73831cd | 2017-01-06 09:37:22 -0500 | [diff] [blame] | 245 | { |
Tom Joseph | 1f8a958 | 2017-06-12 20:10:59 +0530 | [diff] [blame] | 246 | label = getIndirectLabelEnv( |
| 247 | "LABEL", _hwmonRoot + '/' + _instance + '/', i.first); |
| 248 | if (label.empty()) |
| 249 | { |
| 250 | continue; |
| 251 | } |
| 252 | } |
| 253 | else |
| 254 | { |
| 255 | // Ignore inputs without a label. |
| 256 | label = getEnv("LABEL", i.first); |
| 257 | if (label.empty()) |
| 258 | { |
| 259 | continue; |
| 260 | } |
Brad Bishop | 73831cd | 2017-01-06 09:37:22 -0500 | [diff] [blame] | 261 | } |
| 262 | |
Brad Bishop | add9851 | 2017-01-06 22:01:19 -0500 | [diff] [blame] | 263 | Attributes attrs; |
| 264 | if (!getAttributes(i.first.first, attrs)) |
| 265 | { |
| 266 | continue; |
| 267 | } |
| 268 | |
Brad Bishop | 075f7a2 | 2017-01-06 09:45:08 -0500 | [diff] [blame] | 269 | std::string objectPath{_root}; |
Brad Bishop | b8740fc | 2017-02-24 23:38:37 -0500 | [diff] [blame] | 270 | objectPath.append(1, '/'); |
Brad Bishop | add9851 | 2017-01-06 22:01:19 -0500 | [diff] [blame] | 271 | objectPath.append(getNamespace(attrs)); |
Brad Bishop | b8740fc | 2017-02-24 23:38:37 -0500 | [diff] [blame] | 272 | objectPath.append(1, '/'); |
Brad Bishop | 075f7a2 | 2017-01-06 09:45:08 -0500 | [diff] [blame] | 273 | objectPath.append(label); |
| 274 | |
Brad Bishop | f7426cf | 2017-01-06 15:36:43 -0500 | [diff] [blame] | 275 | ObjectInfo info(&_bus, std::move(objectPath), Object()); |
Brad Bishop | 4db6442 | 2017-02-16 11:33:32 -0500 | [diff] [blame] | 276 | auto valueInterface = addValue(i.first, _hwmonRoot, _instance, info); |
Patrick Venture | 1e6324f | 2017-06-01 14:07:05 -0700 | [diff] [blame^] | 277 | if (!valueInterface) |
| 278 | { |
| 279 | continue; /* skip adding this sensor for now. */ |
| 280 | } |
Brad Bishop | e0b7d05 | 2017-01-06 15:30:23 -0500 | [diff] [blame] | 281 | auto sensorValue = valueInterface->value(); |
| 282 | addThreshold<WarningObject>(i.first, sensorValue, info); |
| 283 | addThreshold<CriticalObject>(i.first, sensorValue, info); |
Matthew Barth | bf7b7b1 | 2017-03-07 15:46:59 -0600 | [diff] [blame] | 284 | //TODO openbmc/openbmc#1347 |
| 285 | // Handle application restarts to set/refresh fan speed values |
Matt Spinler | 0a8de64 | 2017-05-11 10:59:39 -0500 | [diff] [blame] | 286 | auto target = addTarget<hwmon::FanSpeed>( |
| 287 | i.first, _hwmonRoot, _instance, info); |
| 288 | |
| 289 | if (target) |
| 290 | { |
| 291 | target->enable(); |
| 292 | } |
Brad Bishop | 075f7a2 | 2017-01-06 09:45:08 -0500 | [diff] [blame] | 293 | |
Brad Bishop | 30dbcee | 2017-01-18 07:55:42 -0500 | [diff] [blame] | 294 | // All the interfaces have been created. Go ahead |
| 295 | // and emit InterfacesAdded. |
| 296 | valueInterface->emit_object_added(); |
| 297 | |
Brad Bishop | 075f7a2 | 2017-01-06 09:45:08 -0500 | [diff] [blame] | 298 | auto value = std::make_tuple( |
| 299 | std::move(i.second), |
| 300 | std::move(label), |
Brad Bishop | f7426cf | 2017-01-06 15:36:43 -0500 | [diff] [blame] | 301 | std::move(info)); |
Brad Bishop | 73831cd | 2017-01-06 09:37:22 -0500 | [diff] [blame] | 302 | |
Brad Bishop | 75b4ab8 | 2017-01-06 09:33:50 -0500 | [diff] [blame] | 303 | state[std::move(i.first)] = std::move(value); |
| 304 | } |
| 305 | |
Patrick Venture | 62503a4 | 2017-05-23 07:30:29 -0700 | [diff] [blame] | 306 | /* If there are no sensors specified by labels, exit. */ |
| 307 | if (0 == state.size()) |
| 308 | { |
| 309 | return; |
| 310 | } |
| 311 | |
Brad Bishop | 9c7b6e0 | 2016-12-19 12:43:36 -0500 | [diff] [blame] | 312 | { |
Brad Bishop | b8740fc | 2017-02-24 23:38:37 -0500 | [diff] [blame] | 313 | std::string busname{_prefix}; |
| 314 | busname.append(1, '.'); |
| 315 | busname.append(_instance); |
Brad Bishop | 9c7b6e0 | 2016-12-19 12:43:36 -0500 | [diff] [blame] | 316 | _bus.request_name(busname.c_str()); |
| 317 | } |
| 318 | |
Patrick Venture | ab10f16 | 2017-05-22 09:44:50 -0700 | [diff] [blame] | 319 | { |
| 320 | auto interval = getenv("INTERVAL"); |
| 321 | if (interval) |
| 322 | { |
| 323 | _interval = strtoull(interval, NULL, 10); |
| 324 | } |
| 325 | } |
| 326 | |
Brad Bishop | e55ef3d | 2016-12-19 09:12:40 -0500 | [diff] [blame] | 327 | // TODO: Issue#3 - Need to make calls to the dbus sensor cache here to |
| 328 | // ensure the objects all exist? |
| 329 | |
| 330 | // Polling loop. |
Brad Bishop | d499ca6 | 2016-12-19 09:24:50 -0500 | [diff] [blame] | 331 | while (!_shutdown) |
Brad Bishop | e55ef3d | 2016-12-19 09:12:40 -0500 | [diff] [blame] | 332 | { |
Patrick Venture | 1e6324f | 2017-06-01 14:07:05 -0700 | [diff] [blame^] | 333 | std::vector<SensorSet::key_type> destroy; |
Brad Bishop | e55ef3d | 2016-12-19 09:12:40 -0500 | [diff] [blame] | 334 | // Iterate through all the sensors. |
Brad Bishop | 75b4ab8 | 2017-01-06 09:33:50 -0500 | [diff] [blame] | 335 | for (auto& i : state) |
Brad Bishop | e55ef3d | 2016-12-19 09:12:40 -0500 | [diff] [blame] | 336 | { |
Brad Bishop | 75b4ab8 | 2017-01-06 09:33:50 -0500 | [diff] [blame] | 337 | auto& attrs = std::get<0>(i.second); |
| 338 | if (attrs.find(hwmon::entry::input) != attrs.end()) |
Brad Bishop | e55ef3d | 2016-12-19 09:12:40 -0500 | [diff] [blame] | 339 | { |
| 340 | // Read value from sensor. |
Patrick Venture | 1e6324f | 2017-06-01 14:07:05 -0700 | [diff] [blame^] | 341 | int value; |
| 342 | try |
Brad Bishop | dddb715 | 2017-01-06 09:54:23 -0500 | [diff] [blame] | 343 | { |
Patrick Venture | 1e6324f | 2017-06-01 14:07:05 -0700 | [diff] [blame^] | 344 | value = sysfs::readSysfsWithCallout(_hwmonRoot, |
| 345 | _instance, |
| 346 | i.first.first, |
| 347 | i.first.second, |
| 348 | hwmon::entry::input); |
Brad Bishop | e0b7d05 | 2017-01-06 15:30:23 -0500 | [diff] [blame] | 349 | |
Patrick Venture | 1e6324f | 2017-06-01 14:07:05 -0700 | [diff] [blame^] | 350 | auto& objInfo = std::get<ObjectInfo>(i.second); |
| 351 | auto& obj = std::get<Object>(objInfo); |
| 352 | |
| 353 | for (auto& iface : obj) |
Brad Bishop | e0b7d05 | 2017-01-06 15:30:23 -0500 | [diff] [blame] | 354 | { |
Patrick Venture | 1e6324f | 2017-06-01 14:07:05 -0700 | [diff] [blame^] | 355 | auto valueIface = std::shared_ptr<ValueObject>(); |
| 356 | auto warnIface = std::shared_ptr<WarningObject>(); |
| 357 | auto critIface = std::shared_ptr<CriticalObject>(); |
| 358 | |
| 359 | switch (iface.first) |
| 360 | { |
| 361 | case InterfaceType::VALUE: |
| 362 | valueIface = std::experimental::any_cast<std::shared_ptr<ValueObject>> |
| 363 | (iface.second); |
| 364 | valueIface->value(value); |
| 365 | break; |
| 366 | case InterfaceType::WARN: |
| 367 | checkThresholds<WarningObject>(iface.second, value); |
| 368 | break; |
| 369 | case InterfaceType::CRIT: |
| 370 | checkThresholds<CriticalObject>(iface.second, value); |
| 371 | break; |
| 372 | default: |
| 373 | break; |
| 374 | } |
Brad Bishop | e0b7d05 | 2017-01-06 15:30:23 -0500 | [diff] [blame] | 375 | } |
Brad Bishop | dddb715 | 2017-01-06 09:54:23 -0500 | [diff] [blame] | 376 | } |
Patrick Venture | 1e6324f | 2017-06-01 14:07:05 -0700 | [diff] [blame^] | 377 | catch (const std::exception& e) |
| 378 | { |
| 379 | using namespace sdbusplus::xyz::openbmc_project::Sensor::Device::Error; |
| 380 | commit<ReadFailure>(); |
| 381 | |
| 382 | destroy.push_back(i.first); |
| 383 | } |
Brad Bishop | e55ef3d | 2016-12-19 09:12:40 -0500 | [diff] [blame] | 384 | } |
| 385 | } |
| 386 | |
Patrick Venture | 1e6324f | 2017-06-01 14:07:05 -0700 | [diff] [blame^] | 387 | for (auto& i : destroy) |
| 388 | { |
| 389 | state.erase(i); |
| 390 | } |
| 391 | |
Brad Bishop | 9c7b6e0 | 2016-12-19 12:43:36 -0500 | [diff] [blame] | 392 | // Respond to DBus |
| 393 | _bus.process_discard(); |
| 394 | |
Brad Bishop | e55ef3d | 2016-12-19 09:12:40 -0500 | [diff] [blame] | 395 | // Sleep until next interval. |
Brad Bishop | e55ef3d | 2016-12-19 09:12:40 -0500 | [diff] [blame] | 396 | // TODO: Issue#6 - Optionally look at polling interval sysfs entry. |
Patrick Venture | ab10f16 | 2017-05-22 09:44:50 -0700 | [diff] [blame] | 397 | _bus.wait(_interval); |
Brad Bishop | e55ef3d | 2016-12-19 09:12:40 -0500 | [diff] [blame] | 398 | |
| 399 | // TODO: Issue#7 - Should probably periodically check the SensorSet |
| 400 | // for new entries. |
| 401 | } |
Brad Bishop | e55ef3d | 2016-12-19 09:12:40 -0500 | [diff] [blame] | 402 | } |
| 403 | |
| 404 | // vim: tabstop=8 expandtab shiftwidth=4 softtabstop=4 |