blob: c7d0466c617d242adcaf468af099a696ce1a3a06 [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.
Brad Bishop4da01612017-01-05 21:10:06 -050037 auto path = (*options)["of-name"];
38 if (path != ArgumentParser::empty_string)
39 {
Patrick Venture1e6324f2017-06-01 14:07:05 -070040 path = sysfs::findHwmon(path);
Brad Bishop4da01612017-01-05 21:10:06 -050041 }
42
Patrick Williams3667cf32015-10-20 22:39:11 -050043 if (path == ArgumentParser::empty_string)
44 {
Brad Bishop4da01612017-01-05 21:10:06 -050045 path = (*options)["path"];
46 }
47
48 if (path == ArgumentParser::empty_string)
49 {
50 exit_with_error("Path not specified or invalid.", argv);
Patrick Williams3667cf32015-10-20 22:39:11 -050051 }
52
Vishwanatha Subbanna52b80282016-12-02 23:58:55 +053053 // Finished getting options out, so cleanup the parser.
54 options.reset();
Patrick Williams3667cf32015-10-20 22:39:11 -050055
Brad Bishopf3aa9ae2017-08-25 09:56:02 -040056 // 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 Bishopb9e2b072016-12-19 13:47:10 -050063 MainLoop loop(
Brad Bishop9c7b6e02016-12-19 12:43:36 -050064 sdbusplus::bus::new_default(),
Brad Bishopb9e2b072016-12-19 13:47:10 -050065 path,
Brad Bishopf3aa9ae2017-08-25 09:56:02 -040066 calloutPath,
Brad Bishopb9e2b072016-12-19 13:47:10 -050067 BUSNAME_PREFIX,
68 SENSOR_ROOT);
Brad Bishopd499ca62016-12-19 09:24:50 -050069 loop.run();
70
71 return 0;
Patrick Williams3667cf32015-10-20 22:39:11 -050072}
73
Brad Bishop03476f12016-12-19 13:09:12 -050074// vim: tabstop=8 expandtab shiftwidth=4 softtabstop=4