blob: be599628a0c25f378a593f9dad093d0251f92d69 [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 Venture043d3232018-08-31 10:10:53 -070016#include "config.h"
17
Matthew Barth6292aee2016-10-06 10:15:48 -050018#include "argument.hpp"
Brad Bishope55ef3d2016-12-19 09:12:40 -050019#include "mainloop.hpp"
Brad Bishop4da01612017-01-05 21:10:06 -050020#include "sysfs.hpp"
Patrick Williams3667cf32015-10-20 22:39:11 -050021
Patrick Venture043d3232018-08-31 10:10:53 -070022#include <iostream>
23#include <memory>
24
Patrick Williams3667cf32015-10-20 22:39:11 -050025static void exit_with_error(const char* err, char** argv)
26{
27 ArgumentParser::usage(argv);
28 std::cerr << std::endl;
29 std::cerr << "ERROR: " << err << std::endl;
30 exit(-1);
31}
32
33int main(int argc, char** argv)
34{
35 // Read arguments.
36 auto options = std::make_unique<ArgumentParser>(argc, argv);
37
38 // Parse out path argument.
Matt Spinler147b0332018-03-05 12:07:46 -060039 auto path = (*options)["dev-path"];
Patrick Venturec897d8b2018-04-23 19:01:56 -070040 auto param = path;
Brad Bishop4da01612017-01-05 21:10:06 -050041 if (path != ArgumentParser::empty_string)
42 {
Matt Spinler147b0332018-03-05 12:07:46 -060043 // This path may either be a device path (starts with
44 // /devices), or an open firmware device tree path.
45 if (path.substr(0, 8) == "/devices")
46 {
47 path = sysfs::findHwmonFromDevPath(path);
48 }
49 else
50 {
51 path = sysfs::findHwmonFromOFPath(path);
52 }
Brad Bishop4da01612017-01-05 21:10:06 -050053 }
54
Patrick Williams3667cf32015-10-20 22:39:11 -050055 if (path == ArgumentParser::empty_string)
56 {
Brad Bishop4da01612017-01-05 21:10:06 -050057 path = (*options)["path"];
Patrick Venturec897d8b2018-04-23 19:01:56 -070058 param = path;
Brad Bishop4da01612017-01-05 21:10:06 -050059 }
60
61 if (path == ArgumentParser::empty_string)
62 {
63 exit_with_error("Path not specified or invalid.", argv);
Patrick Williams3667cf32015-10-20 22:39:11 -050064 }
65
Vishwanatha Subbanna52b80282016-12-02 23:58:55 +053066 // Finished getting options out, so cleanup the parser.
67 options.reset();
Patrick Williams3667cf32015-10-20 22:39:11 -050068
Brad Bishopf3aa9ae2017-08-25 09:56:02 -040069 // Determine the physical device sysfs path.
70 auto calloutPath = sysfs::findCalloutPath(path);
71 if (calloutPath.empty())
72 {
73 exit_with_error("Unable to determine callout path.", argv);
74 }
75
Patrick Venture043d3232018-08-31 10:10:53 -070076 MainLoop loop(sdbusplus::bus::new_default(), param, path, calloutPath,
77 BUSNAME_PREFIX, 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