| 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> | 
|  | 19 | #include <chrono> | 
| Brad Bishop | 74aa4dd | 2017-01-06 09:50:31 -0500 | [diff] [blame] | 20 | #include <algorithm> | 
| Brad Bishop | e55ef3d | 2016-12-19 09:12:40 -0500 | [diff] [blame] | 21 | #include "sensorset.hpp" | 
| Brad Bishop | e55ef3d | 2016-12-19 09:12:40 -0500 | [diff] [blame] | 22 | #include "hwmon.hpp" | 
|  | 23 | #include "sysfs.hpp" | 
| Brad Bishop | d499ca6 | 2016-12-19 09:24:50 -0500 | [diff] [blame] | 24 | #include "mainloop.hpp" | 
| Brad Bishop | f3df6b4 | 2017-01-06 10:14:09 -0500 | [diff] [blame] | 25 | #include "env.hpp" | 
| Brad Bishop | e0b7d05 | 2017-01-06 15:30:23 -0500 | [diff] [blame] | 26 | #include "thresholds.hpp" | 
| Matthew Barth | bf7b7b1 | 2017-03-07 15:46:59 -0600 | [diff] [blame^] | 27 | #include "targets.hpp" | 
| Brad Bishop | e55ef3d | 2016-12-19 09:12:40 -0500 | [diff] [blame] | 28 |  | 
| Saqib Khan | 973886d | 2017-03-15 14:01:16 -0500 | [diff] [blame] | 29 | // Initialization for Warning Objects | 
|  | 30 | decltype(Thresholds<WarningObject>::setLo) Thresholds<WarningObject>::setLo = | 
|  | 31 | &WarningObject::warningLow; | 
|  | 32 | decltype(Thresholds<WarningObject>::setHi) Thresholds<WarningObject>::setHi = | 
|  | 33 | &WarningObject::warningHigh; | 
|  | 34 | decltype(Thresholds<WarningObject>::getLo) Thresholds<WarningObject>::getLo = | 
|  | 35 | &WarningObject::warningLow; | 
|  | 36 | decltype(Thresholds<WarningObject>::getHi) Thresholds<WarningObject>::getHi = | 
|  | 37 | &WarningObject::warningHigh; | 
|  | 38 | decltype(Thresholds<WarningObject>::alarmLo) Thresholds<WarningObject>::alarmLo = | 
|  | 39 | &WarningObject::warningAlarmLow; | 
|  | 40 | decltype(Thresholds<WarningObject>::alarmHi) Thresholds<WarningObject>::alarmHi = | 
|  | 41 | &WarningObject::warningAlarmHigh; | 
|  | 42 |  | 
|  | 43 | // Initialization for Critical Objects | 
|  | 44 | decltype(Thresholds<CriticalObject>::setLo) Thresholds<CriticalObject>::setLo = | 
|  | 45 | &CriticalObject::criticalLow; | 
|  | 46 | decltype(Thresholds<CriticalObject>::setHi) Thresholds<CriticalObject>::setHi = | 
|  | 47 | &CriticalObject::criticalHigh; | 
|  | 48 | decltype(Thresholds<CriticalObject>::getLo) Thresholds<CriticalObject>::getLo = | 
|  | 49 | &CriticalObject::criticalLow; | 
|  | 50 | decltype(Thresholds<CriticalObject>::getHi) Thresholds<CriticalObject>::getHi = | 
|  | 51 | &CriticalObject::criticalHigh; | 
|  | 52 | decltype(Thresholds<CriticalObject>::alarmLo) Thresholds<CriticalObject>::alarmLo = | 
|  | 53 | &CriticalObject::criticalAlarmLow; | 
|  | 54 | decltype(Thresholds<CriticalObject>::alarmHi) Thresholds<CriticalObject>::alarmHi = | 
|  | 55 | &CriticalObject::criticalAlarmHigh; | 
|  | 56 |  | 
| Matthew Barth | bf7b7b1 | 2017-03-07 15:46:59 -0600 | [diff] [blame^] | 57 | // Initialization for Target objects | 
|  | 58 | decltype(Targets<FanSpeedObject>::setTarget) | 
|  | 59 | Targets<FanSpeedObject>::setTarget = &FanSpeedObject::target; | 
|  | 60 | decltype(Targets<FanSpeedObject>::getTarget) | 
|  | 61 | Targets<FanSpeedObject>::getTarget = &FanSpeedObject::target; | 
|  | 62 |  | 
| Saqib Khan | 973886d | 2017-03-15 14:01:16 -0500 | [diff] [blame] | 63 |  | 
| Brad Bishop | 9c7b6e0 | 2016-12-19 12:43:36 -0500 | [diff] [blame] | 64 | using namespace std::literals::chrono_literals; | 
|  | 65 |  | 
| Brad Bishop | 74aa4dd | 2017-01-06 09:50:31 -0500 | [diff] [blame] | 66 | static constexpr auto typeAttrMap = | 
|  | 67 | { | 
|  | 68 | // 1 - hwmon class | 
|  | 69 | // 2 - unit | 
|  | 70 | // 3 - sysfs scaling factor | 
|  | 71 | std::make_tuple( | 
|  | 72 | hwmon::type::ctemp, | 
|  | 73 | ValueInterface::Unit::DegreesC, | 
| Brad Bishop | add9851 | 2017-01-06 22:01:19 -0500 | [diff] [blame] | 74 | -3, | 
|  | 75 | "temperature"), | 
| Brad Bishop | 74aa4dd | 2017-01-06 09:50:31 -0500 | [diff] [blame] | 76 | std::make_tuple( | 
|  | 77 | hwmon::type::cfan, | 
|  | 78 | ValueInterface::Unit::RPMS, | 
| Brad Bishop | add9851 | 2017-01-06 22:01:19 -0500 | [diff] [blame] | 79 | 0, | 
|  | 80 | "fan_tach"), | 
| Brad Bishop | 74aa4dd | 2017-01-06 09:50:31 -0500 | [diff] [blame] | 81 | std::make_tuple( | 
|  | 82 | hwmon::type::cvolt, | 
|  | 83 | ValueInterface::Unit::Volts, | 
| Brad Bishop | add9851 | 2017-01-06 22:01:19 -0500 | [diff] [blame] | 84 | -3, | 
|  | 85 | "voltage"), | 
| Brad Bishop | 5afe21a | 2017-01-06 20:44:05 -0500 | [diff] [blame] | 86 | std::make_tuple( | 
|  | 87 | hwmon::type::ccurr, | 
|  | 88 | ValueInterface::Unit::Amperes, | 
| Brad Bishop | add9851 | 2017-01-06 22:01:19 -0500 | [diff] [blame] | 89 | -3, | 
|  | 90 | "current"), | 
| Brad Bishop | 5afe21a | 2017-01-06 20:44:05 -0500 | [diff] [blame] | 91 | std::make_tuple( | 
|  | 92 | hwmon::type::cenergy, | 
|  | 93 | ValueInterface::Unit::Joules, | 
| Brad Bishop | add9851 | 2017-01-06 22:01:19 -0500 | [diff] [blame] | 94 | -6, | 
|  | 95 | "energy"), | 
| Brad Bishop | 5afe21a | 2017-01-06 20:44:05 -0500 | [diff] [blame] | 96 | std::make_tuple( | 
|  | 97 | hwmon::type::cpower, | 
|  | 98 | ValueInterface::Unit::Watts, | 
| Brad Bishop | add9851 | 2017-01-06 22:01:19 -0500 | [diff] [blame] | 99 | -6, | 
|  | 100 | "power"), | 
| Brad Bishop | 74aa4dd | 2017-01-06 09:50:31 -0500 | [diff] [blame] | 101 | }; | 
|  | 102 |  | 
|  | 103 | auto getHwmonType(decltype(typeAttrMap)::const_reference attrs) | 
|  | 104 | { | 
|  | 105 | return std::get<0>(attrs); | 
|  | 106 | } | 
|  | 107 |  | 
|  | 108 | auto getUnit(decltype(typeAttrMap)::const_reference attrs) | 
|  | 109 | { | 
|  | 110 | return std::get<1>(attrs); | 
|  | 111 | } | 
|  | 112 |  | 
|  | 113 | auto getScale(decltype(typeAttrMap)::const_reference attrs) | 
|  | 114 | { | 
|  | 115 | return std::get<2>(attrs); | 
|  | 116 | } | 
|  | 117 |  | 
| Brad Bishop | add9851 | 2017-01-06 22:01:19 -0500 | [diff] [blame] | 118 | auto getNamespace(decltype(typeAttrMap)::const_reference attrs) | 
|  | 119 | { | 
|  | 120 | return std::get<3>(attrs); | 
|  | 121 | } | 
|  | 122 |  | 
| Brad Bishop | 951a79e | 2017-01-06 21:55:11 -0500 | [diff] [blame] | 123 | using AttributeIterator = decltype(*typeAttrMap.begin()); | 
|  | 124 | using Attributes | 
|  | 125 | = std::remove_cv<std::remove_reference<AttributeIterator>::type>::type; | 
|  | 126 |  | 
|  | 127 | auto getAttributes(const std::string& type, Attributes& attributes) | 
|  | 128 | { | 
|  | 129 | // *INDENT-OFF* | 
|  | 130 | auto a = std::find_if( | 
|  | 131 | typeAttrMap.begin(), | 
|  | 132 | typeAttrMap.end(), | 
|  | 133 | [&](const auto & e) | 
|  | 134 | { | 
|  | 135 | return type == getHwmonType(e); | 
|  | 136 | }); | 
|  | 137 | // *INDENT-ON* | 
|  | 138 |  | 
|  | 139 | if (a == typeAttrMap.end()) | 
|  | 140 | { | 
|  | 141 | return false; | 
|  | 142 | } | 
|  | 143 |  | 
|  | 144 | attributes = *a; | 
|  | 145 | return true; | 
|  | 146 | } | 
|  | 147 |  | 
| Brad Bishop | e9fdee0 | 2017-01-06 10:43:29 -0500 | [diff] [blame] | 148 | auto addValue(const SensorSet::key_type& sensor, | 
| Brad Bishop | 4db6442 | 2017-02-16 11:33:32 -0500 | [diff] [blame] | 149 | const std::string& hwmonRoot, | 
|  | 150 | const std::string& instance, | 
|  | 151 | ObjectInfo& info) | 
| Brad Bishop | e9fdee0 | 2017-01-06 10:43:29 -0500 | [diff] [blame] | 152 | { | 
| Brad Bishop | 30dbcee | 2017-01-18 07:55:42 -0500 | [diff] [blame] | 153 | static constexpr bool deferSignals = true; | 
|  | 154 |  | 
| Brad Bishop | e9fdee0 | 2017-01-06 10:43:29 -0500 | [diff] [blame] | 155 | // Get the initial value for the value interface. | 
|  | 156 | auto& bus = *std::get<sdbusplus::bus::bus*>(info); | 
|  | 157 | auto& obj = std::get<Object>(info); | 
|  | 158 | auto& objPath = std::get<std::string>(info); | 
|  | 159 |  | 
| Brad Bishop | 4db6442 | 2017-02-16 11:33:32 -0500 | [diff] [blame] | 160 | int val = readSysfsWithCallout(hwmonRoot, | 
|  | 161 | instance, | 
|  | 162 | sensor.first, | 
|  | 163 | sensor.second, | 
|  | 164 | hwmon::entry::input); | 
| Brad Bishop | 30dbcee | 2017-01-18 07:55:42 -0500 | [diff] [blame] | 165 | auto iface = std::make_shared<ValueObject>(bus, objPath.c_str(), deferSignals); | 
| Brad Bishop | e9fdee0 | 2017-01-06 10:43:29 -0500 | [diff] [blame] | 166 | iface->value(val); | 
|  | 167 |  | 
| Brad Bishop | 951a79e | 2017-01-06 21:55:11 -0500 | [diff] [blame] | 168 | Attributes attrs; | 
|  | 169 | if (getAttributes(sensor.first, attrs)) | 
| Brad Bishop | e9fdee0 | 2017-01-06 10:43:29 -0500 | [diff] [blame] | 170 | { | 
| Brad Bishop | 951a79e | 2017-01-06 21:55:11 -0500 | [diff] [blame] | 171 | iface->unit(getUnit(attrs)); | 
|  | 172 | iface->scale(getScale(attrs)); | 
| Brad Bishop | e9fdee0 | 2017-01-06 10:43:29 -0500 | [diff] [blame] | 173 | } | 
|  | 174 |  | 
|  | 175 | obj[InterfaceType::VALUE] = iface; | 
|  | 176 | return iface; | 
|  | 177 | } | 
|  | 178 |  | 
| Brad Bishop | b9e2b07 | 2016-12-19 13:47:10 -0500 | [diff] [blame] | 179 | MainLoop::MainLoop( | 
| Brad Bishop | 9c7b6e0 | 2016-12-19 12:43:36 -0500 | [diff] [blame] | 180 | sdbusplus::bus::bus&& bus, | 
| Brad Bishop | b9e2b07 | 2016-12-19 13:47:10 -0500 | [diff] [blame] | 181 | const std::string& path, | 
|  | 182 | const char* prefix, | 
|  | 183 | const char* root) | 
| Brad Bishop | 9c7b6e0 | 2016-12-19 12:43:36 -0500 | [diff] [blame] | 184 | : _bus(std::move(bus)), | 
| Brad Bishop | 03e8735 | 2017-03-07 00:12:22 -0500 | [diff] [blame] | 185 | _manager(_bus, root), | 
| Brad Bishop | 9c7b6e0 | 2016-12-19 12:43:36 -0500 | [diff] [blame] | 186 | _shutdown(false), | 
| Brad Bishop | b8740fc | 2017-02-24 23:38:37 -0500 | [diff] [blame] | 187 | _hwmonRoot(), | 
|  | 188 | _instance(), | 
| Brad Bishop | b9e2b07 | 2016-12-19 13:47:10 -0500 | [diff] [blame] | 189 | _prefix(prefix), | 
| Brad Bishop | 3c344d3 | 2017-01-05 11:48:39 -0500 | [diff] [blame] | 190 | _root(root), | 
|  | 191 | state() | 
| Brad Bishop | d499ca6 | 2016-12-19 09:24:50 -0500 | [diff] [blame] | 192 | { | 
| Brad Bishop | b8740fc | 2017-02-24 23:38:37 -0500 | [diff] [blame] | 193 | std::string p = path; | 
|  | 194 | while (!p.empty() && p.back() == '/') | 
| Brad Bishop | 9c7b6e0 | 2016-12-19 12:43:36 -0500 | [diff] [blame] | 195 | { | 
| Brad Bishop | b8740fc | 2017-02-24 23:38:37 -0500 | [diff] [blame] | 196 | p.pop_back(); | 
| Brad Bishop | 9c7b6e0 | 2016-12-19 12:43:36 -0500 | [diff] [blame] | 197 | } | 
| Brad Bishop | b8740fc | 2017-02-24 23:38:37 -0500 | [diff] [blame] | 198 |  | 
|  | 199 | auto n = p.rfind('/'); | 
|  | 200 | if (n != std::string::npos) | 
|  | 201 | { | 
|  | 202 | _instance.assign(p.substr(n + 1)); | 
|  | 203 | _hwmonRoot.assign(p.substr(0, n)); | 
|  | 204 | } | 
|  | 205 |  | 
|  | 206 | assert(!_instance.empty()); | 
|  | 207 | assert(!_hwmonRoot.empty()); | 
| Brad Bishop | d499ca6 | 2016-12-19 09:24:50 -0500 | [diff] [blame] | 208 | } | 
|  | 209 |  | 
|  | 210 | void MainLoop::shutdown() noexcept | 
|  | 211 | { | 
|  | 212 | _shutdown = true; | 
|  | 213 | } | 
|  | 214 |  | 
|  | 215 | void MainLoop::run() | 
| Brad Bishop | e55ef3d | 2016-12-19 09:12:40 -0500 | [diff] [blame] | 216 | { | 
|  | 217 | // Check sysfs for available sensors. | 
| Brad Bishop | 4db6442 | 2017-02-16 11:33:32 -0500 | [diff] [blame] | 218 | auto sensors = std::make_unique<SensorSet>(_hwmonRoot + '/' + _instance); | 
| Brad Bishop | e55ef3d | 2016-12-19 09:12:40 -0500 | [diff] [blame] | 219 |  | 
| Brad Bishop | 75b4ab8 | 2017-01-06 09:33:50 -0500 | [diff] [blame] | 220 | for (auto& i : *sensors) | 
|  | 221 | { | 
| Brad Bishop | f3df6b4 | 2017-01-06 10:14:09 -0500 | [diff] [blame] | 222 | // Get sensor configuration from the environment. | 
|  | 223 |  | 
| Brad Bishop | 73831cd | 2017-01-06 09:37:22 -0500 | [diff] [blame] | 224 | // Ignore inputs without a label. | 
| Brad Bishop | f3df6b4 | 2017-01-06 10:14:09 -0500 | [diff] [blame] | 225 | auto label = getEnv("LABEL", i.first); | 
| Brad Bishop | 73831cd | 2017-01-06 09:37:22 -0500 | [diff] [blame] | 226 | if (label.empty()) | 
|  | 227 | { | 
|  | 228 | continue; | 
|  | 229 | } | 
|  | 230 |  | 
| Brad Bishop | add9851 | 2017-01-06 22:01:19 -0500 | [diff] [blame] | 231 | Attributes attrs; | 
|  | 232 | if (!getAttributes(i.first.first, attrs)) | 
|  | 233 | { | 
|  | 234 | continue; | 
|  | 235 | } | 
|  | 236 |  | 
| Brad Bishop | 075f7a2 | 2017-01-06 09:45:08 -0500 | [diff] [blame] | 237 | std::string objectPath{_root}; | 
| Brad Bishop | b8740fc | 2017-02-24 23:38:37 -0500 | [diff] [blame] | 238 | objectPath.append(1, '/'); | 
| Brad Bishop | add9851 | 2017-01-06 22:01:19 -0500 | [diff] [blame] | 239 | objectPath.append(getNamespace(attrs)); | 
| Brad Bishop | b8740fc | 2017-02-24 23:38:37 -0500 | [diff] [blame] | 240 | objectPath.append(1, '/'); | 
| Brad Bishop | 075f7a2 | 2017-01-06 09:45:08 -0500 | [diff] [blame] | 241 | objectPath.append(label); | 
|  | 242 |  | 
| Brad Bishop | f7426cf | 2017-01-06 15:36:43 -0500 | [diff] [blame] | 243 | ObjectInfo info(&_bus, std::move(objectPath), Object()); | 
| Brad Bishop | 4db6442 | 2017-02-16 11:33:32 -0500 | [diff] [blame] | 244 | auto valueInterface = addValue(i.first, _hwmonRoot, _instance, info); | 
| Brad Bishop | e0b7d05 | 2017-01-06 15:30:23 -0500 | [diff] [blame] | 245 | auto sensorValue = valueInterface->value(); | 
|  | 246 | addThreshold<WarningObject>(i.first, sensorValue, info); | 
|  | 247 | addThreshold<CriticalObject>(i.first, sensorValue, info); | 
| Matthew Barth | bf7b7b1 | 2017-03-07 15:46:59 -0600 | [diff] [blame^] | 248 | //TODO openbmc/openbmc#1347 | 
|  | 249 | //     Handle application restarts to set/refresh fan speed values | 
|  | 250 | addTarget<FanSpeedObject>(i.first, _hwmonRoot, _instance, info); | 
| Brad Bishop | 075f7a2 | 2017-01-06 09:45:08 -0500 | [diff] [blame] | 251 |  | 
| Brad Bishop | 30dbcee | 2017-01-18 07:55:42 -0500 | [diff] [blame] | 252 | // All the interfaces have been created.  Go ahead | 
|  | 253 | // and emit InterfacesAdded. | 
|  | 254 | valueInterface->emit_object_added(); | 
|  | 255 |  | 
| Brad Bishop | 075f7a2 | 2017-01-06 09:45:08 -0500 | [diff] [blame] | 256 | auto value = std::make_tuple( | 
|  | 257 | std::move(i.second), | 
|  | 258 | std::move(label), | 
| Brad Bishop | f7426cf | 2017-01-06 15:36:43 -0500 | [diff] [blame] | 259 | std::move(info)); | 
| Brad Bishop | 73831cd | 2017-01-06 09:37:22 -0500 | [diff] [blame] | 260 |  | 
| Brad Bishop | 75b4ab8 | 2017-01-06 09:33:50 -0500 | [diff] [blame] | 261 | state[std::move(i.first)] = std::move(value); | 
|  | 262 | } | 
|  | 263 |  | 
| Brad Bishop | 9c7b6e0 | 2016-12-19 12:43:36 -0500 | [diff] [blame] | 264 | { | 
| Brad Bishop | b8740fc | 2017-02-24 23:38:37 -0500 | [diff] [blame] | 265 | std::string busname{_prefix}; | 
|  | 266 | busname.append(1, '.'); | 
|  | 267 | busname.append(_instance); | 
| Brad Bishop | 9c7b6e0 | 2016-12-19 12:43:36 -0500 | [diff] [blame] | 268 | _bus.request_name(busname.c_str()); | 
|  | 269 | } | 
|  | 270 |  | 
| Brad Bishop | e55ef3d | 2016-12-19 09:12:40 -0500 | [diff] [blame] | 271 | // TODO: Issue#3 - Need to make calls to the dbus sensor cache here to | 
|  | 272 | //       ensure the objects all exist? | 
|  | 273 |  | 
|  | 274 | // Polling loop. | 
| Brad Bishop | d499ca6 | 2016-12-19 09:24:50 -0500 | [diff] [blame] | 275 | while (!_shutdown) | 
| Brad Bishop | e55ef3d | 2016-12-19 09:12:40 -0500 | [diff] [blame] | 276 | { | 
|  | 277 | // Iterate through all the sensors. | 
| Brad Bishop | 75b4ab8 | 2017-01-06 09:33:50 -0500 | [diff] [blame] | 278 | for (auto& i : state) | 
| Brad Bishop | e55ef3d | 2016-12-19 09:12:40 -0500 | [diff] [blame] | 279 | { | 
| Brad Bishop | 75b4ab8 | 2017-01-06 09:33:50 -0500 | [diff] [blame] | 280 | auto& attrs = std::get<0>(i.second); | 
|  | 281 | if (attrs.find(hwmon::entry::input) != attrs.end()) | 
| Brad Bishop | e55ef3d | 2016-12-19 09:12:40 -0500 | [diff] [blame] | 282 | { | 
|  | 283 | // Read value from sensor. | 
| Brad Bishop | 4db6442 | 2017-02-16 11:33:32 -0500 | [diff] [blame] | 284 | int value = readSysfsWithCallout(_hwmonRoot, | 
|  | 285 | _instance, | 
|  | 286 | i.first.first, | 
|  | 287 | i.first.second, | 
|  | 288 | hwmon::entry::input); | 
| Brad Bishop | f7426cf | 2017-01-06 15:36:43 -0500 | [diff] [blame] | 289 | auto& objInfo = std::get<ObjectInfo>(i.second); | 
|  | 290 | auto& obj = std::get<Object>(objInfo); | 
| Brad Bishop | dddb715 | 2017-01-06 09:54:23 -0500 | [diff] [blame] | 291 |  | 
| Brad Bishop | e0b7d05 | 2017-01-06 15:30:23 -0500 | [diff] [blame] | 292 | for (auto& iface : obj) | 
| Brad Bishop | dddb715 | 2017-01-06 09:54:23 -0500 | [diff] [blame] | 293 | { | 
| Brad Bishop | e0b7d05 | 2017-01-06 15:30:23 -0500 | [diff] [blame] | 294 | auto valueIface = std::shared_ptr<ValueObject>(); | 
|  | 295 | auto warnIface = std::shared_ptr<WarningObject>(); | 
|  | 296 | auto critIface = std::shared_ptr<CriticalObject>(); | 
|  | 297 |  | 
|  | 298 | switch (iface.first) | 
|  | 299 | { | 
|  | 300 | case InterfaceType::VALUE: | 
|  | 301 | valueIface = std::experimental::any_cast<std::shared_ptr<ValueObject>> | 
|  | 302 | (iface.second); | 
|  | 303 | valueIface->value(value); | 
|  | 304 | break; | 
|  | 305 | case InterfaceType::WARN: | 
|  | 306 | checkThresholds<WarningObject>(iface.second, value); | 
|  | 307 | break; | 
|  | 308 | case InterfaceType::CRIT: | 
|  | 309 | checkThresholds<CriticalObject>(iface.second, value); | 
|  | 310 | break; | 
|  | 311 | default: | 
|  | 312 | break; | 
|  | 313 | } | 
| Brad Bishop | dddb715 | 2017-01-06 09:54:23 -0500 | [diff] [blame] | 314 | } | 
| Brad Bishop | e55ef3d | 2016-12-19 09:12:40 -0500 | [diff] [blame] | 315 | } | 
|  | 316 | } | 
|  | 317 |  | 
| Brad Bishop | 9c7b6e0 | 2016-12-19 12:43:36 -0500 | [diff] [blame] | 318 | // Respond to DBus | 
|  | 319 | _bus.process_discard(); | 
|  | 320 |  | 
| Brad Bishop | e55ef3d | 2016-12-19 09:12:40 -0500 | [diff] [blame] | 321 | // Sleep until next interval. | 
|  | 322 | // TODO: Issue#5 - Make this configurable. | 
|  | 323 | // TODO: Issue#6 - Optionally look at polling interval sysfs entry. | 
| Brad Bishop | 9c7b6e0 | 2016-12-19 12:43:36 -0500 | [diff] [blame] | 324 | _bus.wait((1000000us).count()); | 
| Brad Bishop | e55ef3d | 2016-12-19 09:12:40 -0500 | [diff] [blame] | 325 |  | 
|  | 326 | // TODO: Issue#7 - Should probably periodically check the SensorSet | 
|  | 327 | //       for new entries. | 
|  | 328 | } | 
| Brad Bishop | e55ef3d | 2016-12-19 09:12:40 -0500 | [diff] [blame] | 329 | } | 
|  | 330 |  | 
|  | 331 | // vim: tabstop=8 expandtab shiftwidth=4 softtabstop=4 |