blob: 7ac95fc9e40d3bdf86ed393d702f82da262ec357 [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
Brad Bishope55ef3d2016-12-19 09:12:40 -050018#include "mainloop.hpp"
Brad Bishop4da01612017-01-05 21:10:06 -050019#include "sysfs.hpp"
Patrick Williams3667cf32015-10-20 22:39:11 -050020
Patrick Venture17cfad62019-03-11 14:14:30 -070021#include <CLI/CLI.hpp>
Patrick Venture043d3232018-08-31 10:10:53 -070022#include <iostream>
23#include <memory>
24
Patrick Venture17cfad62019-03-11 14:14:30 -070025static void exit_with_error(const std::string& help, const char* err)
Patrick Williams3667cf32015-10-20 22:39:11 -050026{
Patrick Venture2e476ac2019-03-12 16:06:22 -070027 std::cerr << "ERROR: " << err << std::endl << help << std::endl;
Patrick Williams3667cf32015-10-20 22:39:11 -050028 exit(-1);
29}
30
31int main(int argc, char** argv)
32{
33 // Read arguments.
Patrick Venture17cfad62019-03-11 14:14:30 -070034 std::string syspath = "";
35 std::string devpath = "";
36
37 CLI::App app{"OpenBMC Hwmon Daemon"};
38 app.add_option("-p,--path", syspath, "sysfs location to monitor");
39 app.add_option("-o,--dev-path", devpath, "device path to monitor");
40
41 CLI11_PARSE(app, argc, argv);
Patrick Williams3667cf32015-10-20 22:39:11 -050042
43 // Parse out path argument.
Patrick Venture17cfad62019-03-11 14:14:30 -070044 auto path = devpath;
Patrick Venturec897d8b2018-04-23 19:01:56 -070045 auto param = path;
Patrick Venture17cfad62019-03-11 14:14:30 -070046 if (!path.empty())
Brad Bishop4da01612017-01-05 21:10:06 -050047 {
Matt Spinler147b0332018-03-05 12:07:46 -060048 // This path may either be a device path (starts with
49 // /devices), or an open firmware device tree path.
50 if (path.substr(0, 8) == "/devices")
51 {
52 path = sysfs::findHwmonFromDevPath(path);
53 }
54 else
55 {
56 path = sysfs::findHwmonFromOFPath(path);
57 }
Brad Bishop4da01612017-01-05 21:10:06 -050058 }
59
Patrick Venture17cfad62019-03-11 14:14:30 -070060 if (path.empty())
Patrick Williams3667cf32015-10-20 22:39:11 -050061 {
Patrick Venture17cfad62019-03-11 14:14:30 -070062 path = syspath;
Patrick Venturec897d8b2018-04-23 19:01:56 -070063 param = path;
Brad Bishop4da01612017-01-05 21:10:06 -050064 }
65
Patrick Venture17cfad62019-03-11 14:14:30 -070066 if (path.empty())
Brad Bishop4da01612017-01-05 21:10:06 -050067 {
Patrick Venture17cfad62019-03-11 14:14:30 -070068 exit_with_error(app.help("", CLI::AppFormatMode::All),
69 "Path not specified or invalid.");
Patrick Williams3667cf32015-10-20 22:39:11 -050070 }
71
Brad Bishopf3aa9ae2017-08-25 09:56:02 -040072 // Determine the physical device sysfs path.
73 auto calloutPath = sysfs::findCalloutPath(path);
74 if (calloutPath.empty())
75 {
Patrick Venture17cfad62019-03-11 14:14:30 -070076 exit_with_error(app.help("", CLI::AppFormatMode::All),
77 "Unable to determine callout path.");
Brad Bishopf3aa9ae2017-08-25 09:56:02 -040078 }
79
Patrick Venture043d3232018-08-31 10:10:53 -070080 MainLoop loop(sdbusplus::bus::new_default(), param, path, calloutPath,
81 BUSNAME_PREFIX, SENSOR_ROOT);
Brad Bishopd499ca62016-12-19 09:24:50 -050082 loop.run();
83
84 return 0;
Patrick Williams3667cf32015-10-20 22:39:11 -050085}
86
Brad Bishop03476f12016-12-19 13:09:12 -050087// vim: tabstop=8 expandtab shiftwidth=4 softtabstop=4