blob: 3c2c2d21db47e77f5810a4e8dedfc61b8fc2c06c [file] [log] [blame]
Brad Bishop29dbfa62016-12-19 13:39:57 -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 */
Patrick Williams3667cf32015-10-20 22:39:11 -050016#include <iostream>
17#include <memory>
Matthew Barth6292aee2016-10-06 10:15:48 -050018#include "argument.hpp"
Brad Bishope55ef3d2016-12-19 09:12:40 -050019#include "mainloop.hpp"
Brad Bishopb9e2b072016-12-19 13:47:10 -050020#include "config.h"
Brad Bishop4da01612017-01-05 21:10:06 -050021#include "sysfs.hpp"
Patrick Williams3667cf32015-10-20 22:39:11 -050022
23static 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
31int main(int argc, char** argv)
32{
33 // Read arguments.
34 auto options = std::make_unique<ArgumentParser>(argc, argv);
35
36 // Parse out path argument.
Matt Spinler147b0332018-03-05 12:07:46 -060037 auto path = (*options)["dev-path"];
Brad Bishop4da01612017-01-05 21:10:06 -050038 if (path != ArgumentParser::empty_string)
39 {
Matt Spinler147b0332018-03-05 12:07:46 -060040 // This path may either be a device path (starts with
41 // /devices), or an open firmware device tree path.
42 if (path.substr(0, 8) == "/devices")
43 {
44 path = sysfs::findHwmonFromDevPath(path);
45 }
46 else
47 {
48 path = sysfs::findHwmonFromOFPath(path);
49 }
Brad Bishop4da01612017-01-05 21:10:06 -050050 }
51
Patrick Williams3667cf32015-10-20 22:39:11 -050052 if (path == ArgumentParser::empty_string)
53 {
Brad Bishop4da01612017-01-05 21:10:06 -050054 path = (*options)["path"];
55 }
56
57 if (path == ArgumentParser::empty_string)
58 {
59 exit_with_error("Path not specified or invalid.", argv);
Patrick Williams3667cf32015-10-20 22:39:11 -050060 }
61
Vishwanatha Subbanna52b80282016-12-02 23:58:55 +053062 // Finished getting options out, so cleanup the parser.
63 options.reset();
Patrick Williams3667cf32015-10-20 22:39:11 -050064
Brad Bishopf3aa9ae2017-08-25 09:56:02 -040065 // Determine the physical device sysfs path.
66 auto calloutPath = sysfs::findCalloutPath(path);
67 if (calloutPath.empty())
68 {
69 exit_with_error("Unable to determine callout path.", argv);
70 }
71
Brad Bishopb9e2b072016-12-19 13:47:10 -050072 MainLoop loop(
Brad Bishop9c7b6e02016-12-19 12:43:36 -050073 sdbusplus::bus::new_default(),
Brad Bishopb9e2b072016-12-19 13:47:10 -050074 path,
Brad Bishopf3aa9ae2017-08-25 09:56:02 -040075 calloutPath,
Brad Bishopb9e2b072016-12-19 13:47:10 -050076 BUSNAME_PREFIX,
77 SENSOR_ROOT);
Brad Bishopd499ca62016-12-19 09:24:50 -050078 loop.run();
79
80 return 0;
Patrick Williams3667cf32015-10-20 22:39:11 -050081}
82
Brad Bishop03476f12016-12-19 13:09:12 -050083// vim: tabstop=8 expandtab shiftwidth=4 softtabstop=4