blob: 6244b9127ca150c744e9c1bd52a693a357e401fd [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>
18#include <thread>
19#include "sensorset.hpp"
20#include "sensorcache.hpp"
21#include "hwmon.hpp"
22#include "sysfs.hpp"
23
24int serverMain(const char* path)
25{
26 // Check sysfs for available sensors.
27 auto sensors = std::make_unique<SensorSet>(path);
28 auto sensor_cache = std::make_unique<SensorCache>();
29
30 // TODO: Issue#3 - Need to make calls to the dbus sensor cache here to
31 // ensure the objects all exist?
32
33 // Polling loop.
34 while (true)
35 {
36 // Iterate through all the sensors.
37 for (auto& i : *sensors)
38 {
39 if (i.second.find(hwmon::entry::input) != i.second.end())
40 {
41 // Read value from sensor.
42 int value = 0;
43 read_sysfs(make_sysfs_path(path,
44 i.first.first, i.first.second,
45 hwmon::entry::input),
46 value);
47
48 // Update sensor cache.
49 if (sensor_cache->update(i.first, value))
50 {
51 // TODO: Issue#4 - dbus event here.
52 std::cout << i.first.first << i.first.second << " = "
53 << value << std::endl;
54 }
55 }
56 }
57
58 // Sleep until next interval.
59 // TODO: Issue#5 - Make this configurable.
60 // TODO: Issue#6 - Optionally look at polling interval sysfs entry.
61 {
62 using namespace std::literals::chrono_literals;
63 std::this_thread::sleep_for(1s);
64 }
65
66 // TODO: Issue#7 - Should probably periodically check the SensorSet
67 // for new entries.
68 }
69
70 return 0;
71}
72
73// vim: tabstop=8 expandtab shiftwidth=4 softtabstop=4