Brad Bishop | 29dbfa6 | 2016-12-19 13:39:57 -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 | */ |
Patrick Williams | 3667cf3 | 2015-10-20 22:39:11 -0500 | [diff] [blame] | 16 | #include <iostream> |
| 17 | #include <memory> |
Matthew Barth | 6292aee | 2016-10-06 10:15:48 -0500 | [diff] [blame] | 18 | #include "argument.hpp" |
Brad Bishop | e55ef3d | 2016-12-19 09:12:40 -0500 | [diff] [blame] | 19 | #include "mainloop.hpp" |
Brad Bishop | b9e2b07 | 2016-12-19 13:47:10 -0500 | [diff] [blame] | 20 | #include "config.h" |
Brad Bishop | 4da0161 | 2017-01-05 21:10:06 -0500 | [diff] [blame] | 21 | #include "sysfs.hpp" |
Patrick Williams | 3667cf3 | 2015-10-20 22:39:11 -0500 | [diff] [blame] | 22 | |
| 23 | static void exit_with_error(const char* err, char** argv) |
| 24 | { |
| 25 | ArgumentParser::usage(argv); |
| 26 | std::cerr << std::endl; |
| 27 | std::cerr << "ERROR: " << err << std::endl; |
| 28 | exit(-1); |
| 29 | } |
| 30 | |
| 31 | int main(int argc, char** argv) |
| 32 | { |
| 33 | // Read arguments. |
| 34 | auto options = std::make_unique<ArgumentParser>(argc, argv); |
| 35 | |
| 36 | // Parse out path argument. |
Brad Bishop | 4da0161 | 2017-01-05 21:10:06 -0500 | [diff] [blame] | 37 | auto path = (*options)["of-name"]; |
| 38 | if (path != ArgumentParser::empty_string) |
| 39 | { |
Patrick Venture | 1e6324f | 2017-06-01 14:07:05 -0700 | [diff] [blame] | 40 | path = sysfs::findHwmon(path); |
Brad Bishop | 4da0161 | 2017-01-05 21:10:06 -0500 | [diff] [blame] | 41 | } |
| 42 | |
Patrick Williams | 3667cf3 | 2015-10-20 22:39:11 -0500 | [diff] [blame] | 43 | if (path == ArgumentParser::empty_string) |
| 44 | { |
Brad Bishop | 4da0161 | 2017-01-05 21:10:06 -0500 | [diff] [blame] | 45 | path = (*options)["path"]; |
| 46 | } |
| 47 | |
| 48 | if (path == ArgumentParser::empty_string) |
| 49 | { |
| 50 | exit_with_error("Path not specified or invalid.", argv); |
Patrick Williams | 3667cf3 | 2015-10-20 22:39:11 -0500 | [diff] [blame] | 51 | } |
| 52 | |
Vishwanatha Subbanna | 52b8028 | 2016-12-02 23:58:55 +0530 | [diff] [blame] | 53 | // Finished getting options out, so cleanup the parser. |
| 54 | options.reset(); |
Patrick Williams | 3667cf3 | 2015-10-20 22:39:11 -0500 | [diff] [blame] | 55 | |
Brad Bishop | f3aa9ae | 2017-08-25 09:56:02 -0400 | [diff] [blame^] | 56 | // Determine the physical device sysfs path. |
| 57 | auto calloutPath = sysfs::findCalloutPath(path); |
| 58 | if (calloutPath.empty()) |
| 59 | { |
| 60 | exit_with_error("Unable to determine callout path.", argv); |
| 61 | } |
| 62 | |
Brad Bishop | b9e2b07 | 2016-12-19 13:47:10 -0500 | [diff] [blame] | 63 | MainLoop loop( |
Brad Bishop | 9c7b6e0 | 2016-12-19 12:43:36 -0500 | [diff] [blame] | 64 | sdbusplus::bus::new_default(), |
Brad Bishop | b9e2b07 | 2016-12-19 13:47:10 -0500 | [diff] [blame] | 65 | path, |
Brad Bishop | f3aa9ae | 2017-08-25 09:56:02 -0400 | [diff] [blame^] | 66 | calloutPath, |
Brad Bishop | b9e2b07 | 2016-12-19 13:47:10 -0500 | [diff] [blame] | 67 | BUSNAME_PREFIX, |
| 68 | SENSOR_ROOT); |
Brad Bishop | d499ca6 | 2016-12-19 09:24:50 -0500 | [diff] [blame] | 69 | loop.run(); |
| 70 | |
| 71 | return 0; |
Patrick Williams | 3667cf3 | 2015-10-20 22:39:11 -0500 | [diff] [blame] | 72 | } |
| 73 | |
Brad Bishop | 03476f1 | 2016-12-19 13:09:12 -0500 | [diff] [blame] | 74 | // vim: tabstop=8 expandtab shiftwidth=4 softtabstop=4 |