mainloop.cpp (1f8a9586266d90f8d88b5c1af51833b067d9c0b8) mainloop.cpp (1e6324fa4fc233c3f2913b3d5278aa06e45ff42f)
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>
18#include <cstdlib>
19#include <algorithm>
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>
18#include <cstdlib>
19#include <algorithm>
20
21#include <phosphor-logging/elog-errors.hpp>
20#include "sensorset.hpp"
21#include "hwmon.hpp"
22#include "sysfs.hpp"
23#include "mainloop.hpp"
24#include "env.hpp"
25#include "thresholds.hpp"
26#include "targets.hpp"
27#include "fan_speed.hpp"
28
22#include "sensorset.hpp"
23#include "hwmon.hpp"
24#include "sysfs.hpp"
25#include "mainloop.hpp"
26#include "env.hpp"
27#include "thresholds.hpp"
28#include "targets.hpp"
29#include "fan_speed.hpp"
30
31#include <xyz/openbmc_project/Sensor/Device/error.hpp>
32
33using namespace phosphor::logging;
34
29// Initialization for Warning Objects
30decltype(Thresholds<WarningObject>::setLo) Thresholds<WarningObject>::setLo =
31 &WarningObject::warningLow;
32decltype(Thresholds<WarningObject>::setHi) Thresholds<WarningObject>::setHi =
33 &WarningObject::warningHigh;
34decltype(Thresholds<WarningObject>::getLo) Thresholds<WarningObject>::getLo =
35 &WarningObject::warningLow;
36decltype(Thresholds<WarningObject>::getHi) Thresholds<WarningObject>::getHi =

--- 108 unchanged lines hidden (view full) ---

145{
146 static constexpr bool deferSignals = true;
147
148 // Get the initial value for the value interface.
149 auto& bus = *std::get<sdbusplus::bus::bus*>(info);
150 auto& obj = std::get<Object>(info);
151 auto& objPath = std::get<std::string>(info);
152
35// Initialization for Warning Objects
36decltype(Thresholds<WarningObject>::setLo) Thresholds<WarningObject>::setLo =
37 &WarningObject::warningLow;
38decltype(Thresholds<WarningObject>::setHi) Thresholds<WarningObject>::setHi =
39 &WarningObject::warningHigh;
40decltype(Thresholds<WarningObject>::getLo) Thresholds<WarningObject>::getLo =
41 &WarningObject::warningLow;
42decltype(Thresholds<WarningObject>::getHi) Thresholds<WarningObject>::getHi =

--- 108 unchanged lines hidden (view full) ---

151{
152 static constexpr bool deferSignals = true;
153
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
153 int val = readSysfsWithCallout(hwmonRoot,
154 instance,
155 sensor.first,
156 sensor.second,
157 hwmon::entry::input);
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
158 auto iface = std::make_shared<ValueObject>(bus, objPath.c_str(), deferSignals);
159 iface->value(val);
160
161 Attributes attrs;
162 if (getAttributes(sensor.first, attrs))
163 {
164 iface->unit(getUnit(attrs));
165 iface->scale(getScale(attrs));

--- 85 unchanged lines hidden (view full) ---

251 std::string objectPath{_root};
252 objectPath.append(1, '/');
253 objectPath.append(getNamespace(attrs));
254 objectPath.append(1, '/');
255 objectPath.append(label);
256
257 ObjectInfo info(&_bus, std::move(objectPath), Object());
258 auto valueInterface = addValue(i.first, _hwmonRoot, _instance, info);
176 auto iface = std::make_shared<ValueObject>(bus, objPath.c_str(), deferSignals);
177 iface->value(val);
178
179 Attributes attrs;
180 if (getAttributes(sensor.first, attrs))
181 {
182 iface->unit(getUnit(attrs));
183 iface->scale(getScale(attrs));

--- 85 unchanged lines hidden (view full) ---

269 std::string objectPath{_root};
270 objectPath.append(1, '/');
271 objectPath.append(getNamespace(attrs));
272 objectPath.append(1, '/');
273 objectPath.append(label);
274
275 ObjectInfo info(&_bus, std::move(objectPath), Object());
276 auto valueInterface = addValue(i.first, _hwmonRoot, _instance, info);
277 if (!valueInterface)
278 {
279 continue; /* skip adding this sensor for now. */
280 }
259 auto sensorValue = valueInterface->value();
260 addThreshold<WarningObject>(i.first, sensorValue, info);
261 addThreshold<CriticalObject>(i.first, sensorValue, info);
262 //TODO openbmc/openbmc#1347
263 // Handle application restarts to set/refresh fan speed values
264 auto target = addTarget<hwmon::FanSpeed>(
265 i.first, _hwmonRoot, _instance, info);
266

--- 36 unchanged lines hidden (view full) ---

303 }
304
305 // TODO: Issue#3 - Need to make calls to the dbus sensor cache here to
306 // ensure the objects all exist?
307
308 // Polling loop.
309 while (!_shutdown)
310 {
281 auto sensorValue = valueInterface->value();
282 addThreshold<WarningObject>(i.first, sensorValue, info);
283 addThreshold<CriticalObject>(i.first, sensorValue, info);
284 //TODO openbmc/openbmc#1347
285 // Handle application restarts to set/refresh fan speed values
286 auto target = addTarget<hwmon::FanSpeed>(
287 i.first, _hwmonRoot, _instance, info);
288

--- 36 unchanged lines hidden (view full) ---

325 }
326
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.
331 while (!_shutdown)
332 {
333 std::vector<SensorSet::key_type> destroy;
311 // Iterate through all the sensors.
312 for (auto& i : state)
313 {
314 auto& attrs = std::get<0>(i.second);
315 if (attrs.find(hwmon::entry::input) != attrs.end())
316 {
317 // Read value from sensor.
334 // Iterate through all the sensors.
335 for (auto& i : state)
336 {
337 auto& attrs = std::get<0>(i.second);
338 if (attrs.find(hwmon::entry::input) != attrs.end())
339 {
340 // Read value from sensor.
318 int value = readSysfsWithCallout(_hwmonRoot,
319 _instance,
320 i.first.first,
321 i.first.second,
322 hwmon::entry::input);
323 auto& objInfo = std::get<ObjectInfo>(i.second);
324 auto& obj = std::get<Object>(objInfo);
325
326 for (auto& iface : obj)
341 int value;
342 try
327 {
343 {
328 auto valueIface = std::shared_ptr<ValueObject>();
329 auto warnIface = std::shared_ptr<WarningObject>();
330 auto critIface = std::shared_ptr<CriticalObject>();
344 value = sysfs::readSysfsWithCallout(_hwmonRoot,
345 _instance,
346 i.first.first,
347 i.first.second,
348 hwmon::entry::input);
331
349
332 switch (iface.first)
350 auto& objInfo = std::get<ObjectInfo>(i.second);
351 auto& obj = std::get<Object>(objInfo);
352
353 for (auto& iface : obj)
333 {
354 {
334 case InterfaceType::VALUE:
335 valueIface = std::experimental::any_cast<std::shared_ptr<ValueObject>>
336 (iface.second);
337 valueIface->value(value);
338 break;
339 case InterfaceType::WARN:
340 checkThresholds<WarningObject>(iface.second, value);
341 break;
342 case InterfaceType::CRIT:
343 checkThresholds<CriticalObject>(iface.second, value);
344 break;
345 default:
346 break;
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 }
347 }
348 }
375 }
376 }
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 }
349 }
350 }
351
384 }
385 }
386
387 for (auto& i : destroy)
388 {
389 state.erase(i);
390 }
391
352 // Respond to DBus
353 _bus.process_discard();
354
355 // Sleep until next interval.
356 // TODO: Issue#6 - Optionally look at polling interval sysfs entry.
357 _bus.wait(_interval);
358
359 // TODO: Issue#7 - Should probably periodically check the SensorSet
360 // for new entries.
361 }
362}
363
364// vim: tabstop=8 expandtab shiftwidth=4 softtabstop=4
392 // Respond to DBus
393 _bus.process_discard();
394
395 // Sleep until next interval.
396 // TODO: Issue#6 - Optionally look at polling interval sysfs entry.
397 _bus.wait(_interval);
398
399 // TODO: Issue#7 - Should probably periodically check the SensorSet
400 // for new entries.
401 }
402}
403
404// vim: tabstop=8 expandtab shiftwidth=4 softtabstop=4