Patrick Williams | 3667cf3 | 2015-10-20 22:39:11 -0500 | [diff] [blame] | 1 | #include <iostream> |
| 2 | #include <memory> |
| 3 | #include <thread> |
Matthew Barth | 6292aee | 2016-10-06 10:15:48 -0500 | [diff] [blame] | 4 | #include "argument.hpp" |
| 5 | #include "sensorset.hpp" |
| 6 | #include "sensorcache.hpp" |
| 7 | #include "hwmon.hpp" |
| 8 | #include "sysfs.hpp" |
Patrick Williams | 3667cf3 | 2015-10-20 22:39:11 -0500 | [diff] [blame] | 9 | |
| 10 | static void exit_with_error(const char* err, char** argv) |
| 11 | { |
| 12 | ArgumentParser::usage(argv); |
| 13 | std::cerr << std::endl; |
| 14 | std::cerr << "ERROR: " << err << std::endl; |
| 15 | exit(-1); |
| 16 | } |
| 17 | |
| 18 | int main(int argc, char** argv) |
| 19 | { |
| 20 | // Read arguments. |
| 21 | auto options = std::make_unique<ArgumentParser>(argc, argv); |
| 22 | |
| 23 | // Parse out path argument. |
| 24 | auto path = (*options)["path"]; |
| 25 | if (path == ArgumentParser::empty_string) |
| 26 | { |
| 27 | exit_with_error("Path not specified.", argv); |
| 28 | } |
| 29 | |
Vishwanatha Subbanna | 52b8028 | 2016-12-02 23:58:55 +0530 | [diff] [blame^] | 30 | // Finished getting options out, so cleanup the parser. |
| 31 | options.reset(); |
Patrick Williams | 3667cf3 | 2015-10-20 22:39:11 -0500 | [diff] [blame] | 32 | |
| 33 | // Check sysfs for available sensors. |
| 34 | auto sensors = std::make_unique<SensorSet>(path); |
| 35 | auto sensor_cache = std::make_unique<SensorCache>(); |
| 36 | |
| 37 | // TODO: Issue#3 - Need to make calls to the dbus sensor cache here to |
| 38 | // ensure the objects all exist? |
| 39 | |
| 40 | // Polling loop. |
| 41 | while(true) |
| 42 | { |
| 43 | // Iterate through all the sensors. |
| 44 | for(auto& i : *sensors) |
| 45 | { |
| 46 | if (i.second.find(hwmon::entry::input) != i.second.end()) |
| 47 | { |
| 48 | // Read value from sensor. |
| 49 | int value = 0; |
| 50 | read_sysfs(make_sysfs_path(path, |
| 51 | i.first.first, i.first.second, |
| 52 | hwmon::entry::input), |
| 53 | value); |
| 54 | |
| 55 | // Update sensor cache. |
| 56 | if (sensor_cache->update(i.first, value)) |
| 57 | { |
| 58 | // TODO: Issue#4 - dbus event here. |
| 59 | std::cout << i.first.first << i.first.second << " = " |
| 60 | << value << std::endl; |
| 61 | } |
| 62 | } |
| 63 | } |
| 64 | |
| 65 | // Sleep until next interval. |
| 66 | // TODO: Issue#5 - Make this configurable. |
| 67 | // TODO: Issue#6 - Optionally look at polling interval sysfs entry. |
| 68 | { |
| 69 | using namespace std::literals::chrono_literals; |
| 70 | std::this_thread::sleep_for(1s); |
| 71 | } |
| 72 | |
| 73 | // TODO: Issue#7 - Should probably periodically check the SensorSet |
| 74 | // for new entries. |
| 75 | } |
| 76 | |
| 77 | return 0; |
| 78 | } |
| 79 | |