blob: 78edc771fd001451aa0031c04147ce818461a933 [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"];
Patrick Venturec897d8b2018-04-23 19:01:56 -070038 auto param = path;
Brad Bishop4da01612017-01-05 21:10:06 -050039 if (path != ArgumentParser::empty_string)
40 {
Matt Spinler147b0332018-03-05 12:07:46 -060041 // This path may either be a device path (starts with
42 // /devices), or an open firmware device tree path.
43 if (path.substr(0, 8) == "/devices")
44 {
45 path = sysfs::findHwmonFromDevPath(path);
46 }
47 else
48 {
49 path = sysfs::findHwmonFromOFPath(path);
50 }
Brad Bishop4da01612017-01-05 21:10:06 -050051 }
52
Patrick Williams3667cf32015-10-20 22:39:11 -050053 if (path == ArgumentParser::empty_string)
54 {
Brad Bishop4da01612017-01-05 21:10:06 -050055 path = (*options)["path"];
Patrick Venturec897d8b2018-04-23 19:01:56 -070056 param = path;
Brad Bishop4da01612017-01-05 21:10:06 -050057 }
58
59 if (path == ArgumentParser::empty_string)
60 {
61 exit_with_error("Path not specified or invalid.", argv);
Patrick Williams3667cf32015-10-20 22:39:11 -050062 }
63
Vishwanatha Subbanna52b80282016-12-02 23:58:55 +053064 // Finished getting options out, so cleanup the parser.
65 options.reset();
Patrick Williams3667cf32015-10-20 22:39:11 -050066
Brad Bishopf3aa9ae2017-08-25 09:56:02 -040067 // Determine the physical device sysfs path.
68 auto calloutPath = sysfs::findCalloutPath(path);
69 if (calloutPath.empty())
70 {
71 exit_with_error("Unable to determine callout path.", argv);
72 }
73
Brad Bishopb9e2b072016-12-19 13:47:10 -050074 MainLoop loop(
Brad Bishop9c7b6e02016-12-19 12:43:36 -050075 sdbusplus::bus::new_default(),
Patrick Venturec897d8b2018-04-23 19:01:56 -070076 param,
Brad Bishopb9e2b072016-12-19 13:47:10 -050077 path,
Brad Bishopf3aa9ae2017-08-25 09:56:02 -040078 calloutPath,
Brad Bishopb9e2b072016-12-19 13:47:10 -050079 BUSNAME_PREFIX,
80 SENSOR_ROOT);
Brad Bishopd499ca62016-12-19 09:24:50 -050081 loop.run();
82
83 return 0;
Patrick Williams3667cf32015-10-20 22:39:11 -050084}
85
Brad Bishop03476f12016-12-19 13:09:12 -050086// vim: tabstop=8 expandtab shiftwidth=4 softtabstop=4