blob: 1190d858637352cc2eb6a5005d3106c913f66316 [file] [log] [blame]
Brad Bishope55ef3d2016-12-19 09:12:40 -05001/**
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 Bishop9c7b6e02016-12-19 12:43:36 -050018#include <cstdlib>
Chiabing Leec923ce92017-09-06 15:58:26 +080019#include <string>
Patrick Venture1e6324f2017-06-01 14:07:05 -070020
21#include <phosphor-logging/elog-errors.hpp>
Matt Spinlerf9c83c42017-08-10 08:51:45 -050022#include "config.h"
Brad Bishope55ef3d2016-12-19 09:12:40 -050023#include "sensorset.hpp"
Brad Bishope55ef3d2016-12-19 09:12:40 -050024#include "hwmon.hpp"
25#include "sysfs.hpp"
Brad Bishopd499ca62016-12-19 09:24:50 -050026#include "mainloop.hpp"
Brad Bishopf3df6b42017-01-06 10:14:09 -050027#include "env.hpp"
Brad Bishope0b7d052017-01-06 15:30:23 -050028#include "thresholds.hpp"
Matthew Barthbf7b7b12017-03-07 15:46:59 -060029#include "targets.hpp"
Matthew Barth048ac872017-03-09 14:36:08 -060030#include "fan_speed.hpp"
Brad Bishope55ef3d2016-12-19 09:12:40 -050031
Patrick Venture1e6324f2017-06-01 14:07:05 -070032#include <xyz/openbmc_project/Sensor/Device/error.hpp>
33
34using namespace phosphor::logging;
35
Saqib Khan973886d2017-03-15 14:01:16 -050036// Initialization for Warning Objects
37decltype(Thresholds<WarningObject>::setLo) Thresholds<WarningObject>::setLo =
38 &WarningObject::warningLow;
39decltype(Thresholds<WarningObject>::setHi) Thresholds<WarningObject>::setHi =
40 &WarningObject::warningHigh;
41decltype(Thresholds<WarningObject>::getLo) Thresholds<WarningObject>::getLo =
42 &WarningObject::warningLow;
43decltype(Thresholds<WarningObject>::getHi) Thresholds<WarningObject>::getHi =
44 &WarningObject::warningHigh;
45decltype(Thresholds<WarningObject>::alarmLo) Thresholds<WarningObject>::alarmLo =
46 &WarningObject::warningAlarmLow;
47decltype(Thresholds<WarningObject>::alarmHi) Thresholds<WarningObject>::alarmHi =
48 &WarningObject::warningAlarmHigh;
49
50// Initialization for Critical Objects
51decltype(Thresholds<CriticalObject>::setLo) Thresholds<CriticalObject>::setLo =
52 &CriticalObject::criticalLow;
53decltype(Thresholds<CriticalObject>::setHi) Thresholds<CriticalObject>::setHi =
54 &CriticalObject::criticalHigh;
55decltype(Thresholds<CriticalObject>::getLo) Thresholds<CriticalObject>::getLo =
56 &CriticalObject::criticalLow;
57decltype(Thresholds<CriticalObject>::getHi) Thresholds<CriticalObject>::getHi =
58 &CriticalObject::criticalHigh;
59decltype(Thresholds<CriticalObject>::alarmLo) Thresholds<CriticalObject>::alarmLo =
60 &CriticalObject::criticalAlarmLow;
61decltype(Thresholds<CriticalObject>::alarmHi) Thresholds<CriticalObject>::alarmHi =
62 &CriticalObject::criticalAlarmHigh;
63
Chiabing Leec923ce92017-09-06 15:58:26 +080064// The gain and offset to adjust a value
65struct valueAdjust
66{
67 double gain = 1.0;
68 int offset = 0;
69};
70
71// Store the valueAdjust for sensors
72std::map<SensorSet::key_type, valueAdjust> sensorAdjusts;
73
Brad Bishop74aa4dd2017-01-06 09:50:31 -050074static constexpr auto typeAttrMap =
75{
76 // 1 - hwmon class
77 // 2 - unit
78 // 3 - sysfs scaling factor
79 std::make_tuple(
80 hwmon::type::ctemp,
81 ValueInterface::Unit::DegreesC,
Brad Bishopadd98512017-01-06 22:01:19 -050082 -3,
83 "temperature"),
Brad Bishop74aa4dd2017-01-06 09:50:31 -050084 std::make_tuple(
85 hwmon::type::cfan,
86 ValueInterface::Unit::RPMS,
Brad Bishopadd98512017-01-06 22:01:19 -050087 0,
88 "fan_tach"),
Brad Bishop74aa4dd2017-01-06 09:50:31 -050089 std::make_tuple(
90 hwmon::type::cvolt,
91 ValueInterface::Unit::Volts,
Brad Bishopadd98512017-01-06 22:01:19 -050092 -3,
93 "voltage"),
Brad Bishop5afe21a2017-01-06 20:44:05 -050094 std::make_tuple(
95 hwmon::type::ccurr,
96 ValueInterface::Unit::Amperes,
Brad Bishopadd98512017-01-06 22:01:19 -050097 -3,
98 "current"),
Brad Bishop5afe21a2017-01-06 20:44:05 -050099 std::make_tuple(
100 hwmon::type::cenergy,
101 ValueInterface::Unit::Joules,
Brad Bishopadd98512017-01-06 22:01:19 -0500102 -6,
103 "energy"),
Brad Bishop5afe21a2017-01-06 20:44:05 -0500104 std::make_tuple(
105 hwmon::type::cpower,
106 ValueInterface::Unit::Watts,
Brad Bishopadd98512017-01-06 22:01:19 -0500107 -6,
108 "power"),
Brad Bishop74aa4dd2017-01-06 09:50:31 -0500109};
110
111auto getHwmonType(decltype(typeAttrMap)::const_reference attrs)
112{
113 return std::get<0>(attrs);
114}
115
116auto getUnit(decltype(typeAttrMap)::const_reference attrs)
117{
118 return std::get<1>(attrs);
119}
120
121auto getScale(decltype(typeAttrMap)::const_reference attrs)
122{
123 return std::get<2>(attrs);
124}
125
Brad Bishopadd98512017-01-06 22:01:19 -0500126auto getNamespace(decltype(typeAttrMap)::const_reference attrs)
127{
128 return std::get<3>(attrs);
129}
130
Brad Bishop951a79e2017-01-06 21:55:11 -0500131using AttributeIterator = decltype(*typeAttrMap.begin());
132using Attributes
133 = std::remove_cv<std::remove_reference<AttributeIterator>::type>::type;
134
135auto getAttributes(const std::string& type, Attributes& attributes)
136{
137 // *INDENT-OFF*
138 auto a = std::find_if(
139 typeAttrMap.begin(),
140 typeAttrMap.end(),
141 [&](const auto & e)
142 {
143 return type == getHwmonType(e);
144 });
145 // *INDENT-ON*
146
147 if (a == typeAttrMap.end())
148 {
149 return false;
150 }
151
152 attributes = *a;
153 return true;
154}
155
Chiabing Leec923ce92017-09-06 15:58:26 +0800156int adjustValue(const SensorSet::key_type& sensor, int value)
157{
158 const auto& it = sensorAdjusts.find(sensor);
159 if (it != sensorAdjusts.end())
160 {
161 // Adjust based on gain and offset
162 value = static_cast<decltype(value)>(
163 static_cast<double>(value) * it->second.gain
164 + it->second.offset);
165 }
166 return value;
167}
168
Brad Bishope9fdee02017-01-06 10:43:29 -0500169auto addValue(const SensorSet::key_type& sensor,
Brad Bishop751043e2017-08-29 11:13:46 -0400170 const std::string& devPath,
171 sysfs::hwmonio::HwmonIO& ioAccess,
Brad Bishop4db64422017-02-16 11:33:32 -0500172 ObjectInfo& info)
Brad Bishope9fdee02017-01-06 10:43:29 -0500173{
Brad Bishop30dbcee2017-01-18 07:55:42 -0500174 static constexpr bool deferSignals = true;
175
Brad Bishope9fdee02017-01-06 10:43:29 -0500176 // Get the initial value for the value interface.
177 auto& bus = *std::get<sdbusplus::bus::bus*>(info);
178 auto& obj = std::get<Object>(info);
179 auto& objPath = std::get<std::string>(info);
180
Brad Bishop751043e2017-08-29 11:13:46 -0400181 auto val = 0;
182 try
183 {
184 // Retry for up to a second if device is busy
Brad Bishop754d38c2017-09-08 00:46:58 -0400185 // or has a transient error.
186 val = ioAccess.read(
Brad Bishop751043e2017-08-29 11:13:46 -0400187 sensor.first,
188 sensor.second,
Brad Bishop754d38c2017-09-08 00:46:58 -0400189 hwmon::entry::cinput,
190 sysfs::hwmonio::retries,
191 sysfs::hwmonio::delay);
Brad Bishop751043e2017-08-29 11:13:46 -0400192 }
193 catch (const std::system_error& e)
194 {
195 using namespace sdbusplus::xyz::openbmc_project::Sensor::Device::Error;
196 report<ReadFailure>(
197 xyz::openbmc_project::Sensor::Device::
198 ReadFailure::CALLOUT_ERRNO(e.code().value()),
199 xyz::openbmc_project::Sensor::Device::
200 ReadFailure::CALLOUT_DEVICE_PATH(devPath.c_str()));
201
Matt Spinler9b65f762017-10-05 10:36:22 -0500202 auto file = sysfs::make_sysfs_path(
203 ioAccess.path(),
204 sensor.first,
205 sensor.second,
206 hwmon::entry::cinput);
207
208 log<level::INFO>("Logging failing sysfs file",
209 entry("FILE=%s", file.c_str()));
210
Brad Bishop751043e2017-08-29 11:13:46 -0400211 return static_cast<std::shared_ptr<ValueObject>>(nullptr);
Patrick Venture1e6324f2017-06-01 14:07:05 -0700212 }
213
Chiabing Leec923ce92017-09-06 15:58:26 +0800214 auto gain = getEnv("GAIN", sensor);
215 if (!gain.empty())
216 {
217 sensorAdjusts[sensor].gain = std::stod(gain);
218 }
219
220 auto offset = getEnv("OFFSET", sensor);
221 if (!offset.empty())
222 {
223 sensorAdjusts[sensor].offset = std::stoi(offset);
224 }
225
226 val = adjustValue(sensor, val);
227
Brad Bishop30dbcee2017-01-18 07:55:42 -0500228 auto iface = std::make_shared<ValueObject>(bus, objPath.c_str(), deferSignals);
Brad Bishope9fdee02017-01-06 10:43:29 -0500229 iface->value(val);
230
Brad Bishop951a79e2017-01-06 21:55:11 -0500231 Attributes attrs;
232 if (getAttributes(sensor.first, attrs))
Brad Bishope9fdee02017-01-06 10:43:29 -0500233 {
Brad Bishop951a79e2017-01-06 21:55:11 -0500234 iface->unit(getUnit(attrs));
235 iface->scale(getScale(attrs));
Brad Bishope9fdee02017-01-06 10:43:29 -0500236 }
237
238 obj[InterfaceType::VALUE] = iface;
239 return iface;
240}
241
Brad Bishopb9e2b072016-12-19 13:47:10 -0500242MainLoop::MainLoop(
Brad Bishop9c7b6e02016-12-19 12:43:36 -0500243 sdbusplus::bus::bus&& bus,
Brad Bishopb9e2b072016-12-19 13:47:10 -0500244 const std::string& path,
Brad Bishopf3aa9ae2017-08-25 09:56:02 -0400245 const std::string& devPath,
Brad Bishopb9e2b072016-12-19 13:47:10 -0500246 const char* prefix,
247 const char* root)
Brad Bishop9c7b6e02016-12-19 12:43:36 -0500248 : _bus(std::move(bus)),
Brad Bishop03e87352017-03-07 00:12:22 -0500249 _manager(_bus, root),
Brad Bishop9c7b6e02016-12-19 12:43:36 -0500250 _shutdown(false),
Brad Bishopb8740fc2017-02-24 23:38:37 -0500251 _hwmonRoot(),
252 _instance(),
Brad Bishopf3aa9ae2017-08-25 09:56:02 -0400253 _devPath(devPath),
Brad Bishopb9e2b072016-12-19 13:47:10 -0500254 _prefix(prefix),
Brad Bishop3c344d32017-01-05 11:48:39 -0500255 _root(root),
Brad Bishop751043e2017-08-29 11:13:46 -0400256 state(),
257 ioAccess(path)
Brad Bishopd499ca62016-12-19 09:24:50 -0500258{
Brad Bishopb8740fc2017-02-24 23:38:37 -0500259 std::string p = path;
260 while (!p.empty() && p.back() == '/')
Brad Bishop9c7b6e02016-12-19 12:43:36 -0500261 {
Brad Bishopb8740fc2017-02-24 23:38:37 -0500262 p.pop_back();
Brad Bishop9c7b6e02016-12-19 12:43:36 -0500263 }
Brad Bishopb8740fc2017-02-24 23:38:37 -0500264
265 auto n = p.rfind('/');
266 if (n != std::string::npos)
267 {
268 _instance.assign(p.substr(n + 1));
269 _hwmonRoot.assign(p.substr(0, n));
270 }
271
272 assert(!_instance.empty());
273 assert(!_hwmonRoot.empty());
Brad Bishopd499ca62016-12-19 09:24:50 -0500274}
275
276void MainLoop::shutdown() noexcept
277{
278 _shutdown = true;
279}
280
281void MainLoop::run()
Brad Bishope55ef3d2016-12-19 09:12:40 -0500282{
283 // Check sysfs for available sensors.
Brad Bishop4db64422017-02-16 11:33:32 -0500284 auto sensors = std::make_unique<SensorSet>(_hwmonRoot + '/' + _instance);
Brad Bishope55ef3d2016-12-19 09:12:40 -0500285
Brad Bishop75b4ab82017-01-06 09:33:50 -0500286 for (auto& i : *sensors)
287 {
Tom Joseph1f8a9582017-06-12 20:10:59 +0530288 std::string label;
Matt Spinler4b68c4e2017-10-12 16:44:53 -0500289 std::string id;
Brad Bishopf3df6b42017-01-06 10:14:09 -0500290
Tom Joseph1f8a9582017-06-12 20:10:59 +0530291 /*
292 * Check if the value of the MODE_<item><X> env variable for the sensor
293 * is "label", then read the sensor number from the <item><X>_label
294 * file. The name of the DBUS object would be the value of the env
295 * variable LABEL_<item><sensorNum>. If the MODE_<item><X> env variable
Matt Spinler4b68c4e2017-10-12 16:44:53 -0500296 * doesn't exist, then the name of DBUS object is the value of the env
Tom Joseph1f8a9582017-06-12 20:10:59 +0530297 * variable LABEL_<item><X>.
298 */
299 auto mode = getEnv("MODE", i.first);
300 if (!mode.compare(hwmon::entry::label))
Brad Bishop73831cd2017-01-06 09:37:22 -0500301 {
Matt Spinler4b68c4e2017-10-12 16:44:53 -0500302 id = getIndirectID(
303 _hwmonRoot + '/' + _instance + '/', i.first);
304
305 if (id.empty())
Tom Joseph1f8a9582017-06-12 20:10:59 +0530306 {
307 continue;
308 }
309 }
Matt Spinler4b68c4e2017-10-12 16:44:53 -0500310
311 //In this loop, use the ID we looked up above if
312 //there was one, otherwise use the standard one.
313 id = (id.empty()) ? i.first.second : id;
314
315 // Ignore inputs without a label.
316 label = getEnv("LABEL", i.first.first, id);
317 if (label.empty())
Tom Joseph1f8a9582017-06-12 20:10:59 +0530318 {
Matt Spinler4b68c4e2017-10-12 16:44:53 -0500319 continue;
Brad Bishop73831cd2017-01-06 09:37:22 -0500320 }
321
Brad Bishopadd98512017-01-06 22:01:19 -0500322 Attributes attrs;
323 if (!getAttributes(i.first.first, attrs))
324 {
325 continue;
326 }
327
Brad Bishop075f7a22017-01-06 09:45:08 -0500328 std::string objectPath{_root};
Brad Bishopb8740fc2017-02-24 23:38:37 -0500329 objectPath.append(1, '/');
Brad Bishopadd98512017-01-06 22:01:19 -0500330 objectPath.append(getNamespace(attrs));
Brad Bishopb8740fc2017-02-24 23:38:37 -0500331 objectPath.append(1, '/');
Brad Bishop075f7a22017-01-06 09:45:08 -0500332 objectPath.append(label);
333
Brad Bishopf7426cf2017-01-06 15:36:43 -0500334 ObjectInfo info(&_bus, std::move(objectPath), Object());
Brad Bishop751043e2017-08-29 11:13:46 -0400335 auto valueInterface = addValue(i.first, _devPath, ioAccess, info);
Patrick Venture1e6324f2017-06-01 14:07:05 -0700336 if (!valueInterface)
337 {
Matt Spinlerf9c83c42017-08-10 08:51:45 -0500338#ifdef REMOVE_ON_FAIL
Patrick Venture1e6324f2017-06-01 14:07:05 -0700339 continue; /* skip adding this sensor for now. */
Matt Spinlerf9c83c42017-08-10 08:51:45 -0500340#else
341 exit(EXIT_FAILURE);
342#endif
Patrick Venture1e6324f2017-06-01 14:07:05 -0700343 }
Brad Bishope0b7d052017-01-06 15:30:23 -0500344 auto sensorValue = valueInterface->value();
Matt Spinlerccfc77b2017-10-12 16:49:24 -0500345 addThreshold<WarningObject>(i.first.first, id, sensorValue, info);
346 addThreshold<CriticalObject>(i.first.first, id, sensorValue, info);
Matt Spinlera3eb8e32017-10-12 16:42:49 -0500347
Matt Spinler0a8de642017-05-11 10:59:39 -0500348 auto target = addTarget<hwmon::FanSpeed>(
Brad Bishop751043e2017-08-29 11:13:46 -0400349 i.first, ioAccess.path(), _devPath, info);
Matt Spinler0a8de642017-05-11 10:59:39 -0500350
351 if (target)
352 {
353 target->enable();
354 }
Brad Bishop075f7a22017-01-06 09:45:08 -0500355
Brad Bishop30dbcee2017-01-18 07:55:42 -0500356 // All the interfaces have been created. Go ahead
357 // and emit InterfacesAdded.
358 valueInterface->emit_object_added();
359
Brad Bishop075f7a22017-01-06 09:45:08 -0500360 auto value = std::make_tuple(
361 std::move(i.second),
362 std::move(label),
Brad Bishopf7426cf2017-01-06 15:36:43 -0500363 std::move(info));
Brad Bishop73831cd2017-01-06 09:37:22 -0500364
Brad Bishop75b4ab82017-01-06 09:33:50 -0500365 state[std::move(i.first)] = std::move(value);
366 }
367
Patrick Venture62503a42017-05-23 07:30:29 -0700368 /* If there are no sensors specified by labels, exit. */
369 if (0 == state.size())
370 {
371 return;
372 }
373
Brad Bishop9c7b6e02016-12-19 12:43:36 -0500374 {
Brad Bishopb8740fc2017-02-24 23:38:37 -0500375 std::string busname{_prefix};
376 busname.append(1, '.');
377 busname.append(_instance);
Brad Bishop9c7b6e02016-12-19 12:43:36 -0500378 _bus.request_name(busname.c_str());
379 }
380
Patrick Ventureab10f162017-05-22 09:44:50 -0700381 {
382 auto interval = getenv("INTERVAL");
383 if (interval)
384 {
385 _interval = strtoull(interval, NULL, 10);
386 }
387 }
388
Brad Bishope55ef3d2016-12-19 09:12:40 -0500389 // TODO: Issue#3 - Need to make calls to the dbus sensor cache here to
390 // ensure the objects all exist?
391
392 // Polling loop.
Brad Bishopd499ca62016-12-19 09:24:50 -0500393 while (!_shutdown)
Brad Bishope55ef3d2016-12-19 09:12:40 -0500394 {
Matt Spinlerf9c83c42017-08-10 08:51:45 -0500395#ifdef REMOVE_ON_FAIL
Patrick Venture1e6324f2017-06-01 14:07:05 -0700396 std::vector<SensorSet::key_type> destroy;
Matt Spinlerf9c83c42017-08-10 08:51:45 -0500397#endif
Brad Bishope55ef3d2016-12-19 09:12:40 -0500398 // Iterate through all the sensors.
Brad Bishop75b4ab82017-01-06 09:33:50 -0500399 for (auto& i : state)
Brad Bishope55ef3d2016-12-19 09:12:40 -0500400 {
Brad Bishop75b4ab82017-01-06 09:33:50 -0500401 auto& attrs = std::get<0>(i.second);
402 if (attrs.find(hwmon::entry::input) != attrs.end())
Brad Bishope55ef3d2016-12-19 09:12:40 -0500403 {
404 // Read value from sensor.
Patrick Venture1e6324f2017-06-01 14:07:05 -0700405 int value;
406 try
Brad Bishopdddb7152017-01-06 09:54:23 -0500407 {
Brad Bishop754d38c2017-09-08 00:46:58 -0400408 // Retry for up to a second if device is busy
409 // or has a transient error.
410
Brad Bishop751043e2017-08-29 11:13:46 -0400411 value = ioAccess.read(
412 i.first.first,
413 i.first.second,
Brad Bishop754d38c2017-09-08 00:46:58 -0400414 hwmon::entry::cinput,
415 sysfs::hwmonio::retries,
416 sysfs::hwmonio::delay);
Brad Bishope0b7d052017-01-06 15:30:23 -0500417
Chiabing Leec923ce92017-09-06 15:58:26 +0800418 value = adjustValue(i.first, value);
419
Patrick Venture1e6324f2017-06-01 14:07:05 -0700420 auto& objInfo = std::get<ObjectInfo>(i.second);
421 auto& obj = std::get<Object>(objInfo);
422
423 for (auto& iface : obj)
Brad Bishope0b7d052017-01-06 15:30:23 -0500424 {
Patrick Venture1e6324f2017-06-01 14:07:05 -0700425 auto valueIface = std::shared_ptr<ValueObject>();
426 auto warnIface = std::shared_ptr<WarningObject>();
427 auto critIface = std::shared_ptr<CriticalObject>();
428
429 switch (iface.first)
430 {
431 case InterfaceType::VALUE:
432 valueIface = std::experimental::any_cast<std::shared_ptr<ValueObject>>
433 (iface.second);
434 valueIface->value(value);
435 break;
436 case InterfaceType::WARN:
437 checkThresholds<WarningObject>(iface.second, value);
438 break;
439 case InterfaceType::CRIT:
440 checkThresholds<CriticalObject>(iface.second, value);
441 break;
442 default:
443 break;
444 }
Brad Bishope0b7d052017-01-06 15:30:23 -0500445 }
Brad Bishopdddb7152017-01-06 09:54:23 -0500446 }
Brad Bishop751043e2017-08-29 11:13:46 -0400447 catch (const std::system_error& e)
Patrick Venture1e6324f2017-06-01 14:07:05 -0700448 {
Brad Bishop751043e2017-08-29 11:13:46 -0400449 using namespace sdbusplus::xyz::openbmc_project::
450 Sensor::Device::Error;
451 report<ReadFailure>(
452 xyz::openbmc_project::Sensor::Device::
453 ReadFailure::CALLOUT_ERRNO(e.code().value()),
454 xyz::openbmc_project::Sensor::Device::
455 ReadFailure::CALLOUT_DEVICE_PATH(
456 _devPath.c_str()));
Matt Spinler9b65f762017-10-05 10:36:22 -0500457
458 auto file = sysfs::make_sysfs_path(
459 ioAccess.path(),
460 i.first.first,
461 i.first.second,
462 hwmon::entry::cinput);
463
464 log<level::INFO>("Logging failing sysfs file",
465 entry("FILE=%s", file.c_str()));
466
Matt Spinlerf9c83c42017-08-10 08:51:45 -0500467#ifdef REMOVE_ON_FAIL
Patrick Venture1e6324f2017-06-01 14:07:05 -0700468 destroy.push_back(i.first);
Matt Spinlerf9c83c42017-08-10 08:51:45 -0500469#else
470 exit(EXIT_FAILURE);
471#endif
Patrick Venture1e6324f2017-06-01 14:07:05 -0700472 }
Brad Bishope55ef3d2016-12-19 09:12:40 -0500473 }
474 }
475
Matt Spinlerf9c83c42017-08-10 08:51:45 -0500476#ifdef REMOVE_ON_FAIL
Patrick Venture1e6324f2017-06-01 14:07:05 -0700477 for (auto& i : destroy)
478 {
479 state.erase(i);
480 }
Matt Spinlerf9c83c42017-08-10 08:51:45 -0500481#endif
Patrick Venture1e6324f2017-06-01 14:07:05 -0700482
Brad Bishop9c7b6e02016-12-19 12:43:36 -0500483 // Respond to DBus
484 _bus.process_discard();
485
Brad Bishope55ef3d2016-12-19 09:12:40 -0500486 // Sleep until next interval.
Brad Bishope55ef3d2016-12-19 09:12:40 -0500487 // TODO: Issue#6 - Optionally look at polling interval sysfs entry.
Patrick Ventureab10f162017-05-22 09:44:50 -0700488 _bus.wait(_interval);
Brad Bishope55ef3d2016-12-19 09:12:40 -0500489
490 // TODO: Issue#7 - Should probably periodically check the SensorSet
491 // for new entries.
492 }
Brad Bishope55ef3d2016-12-19 09:12:40 -0500493}
494
495// vim: tabstop=8 expandtab shiftwidth=4 softtabstop=4