xref: /openbmc/phosphor-hwmon/readd.cpp (revision 7b587377)
1 /**
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  */
16 #include <iostream>
17 #include <memory>
18 #include "argument.hpp"
19 #include "mainloop.hpp"
20 #include "config.h"
21 #include "sysfs.hpp"
22 
23 static 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 
31 int main(int argc, char** argv)
32 {
33     // Read arguments.
34     auto options = std::make_unique<ArgumentParser>(argc, argv);
35 
36     // Parse out path argument.
37     auto path = (*options)["of-name"];
38     if (path != ArgumentParser::empty_string)
39     {
40         path = sysfs::findHwmon(path);
41     }
42 
43     if (path == ArgumentParser::empty_string)
44     {
45         path = (*options)["path"];
46     }
47 
48     if (path == ArgumentParser::empty_string)
49     {
50         exit_with_error("Path not specified or invalid.", argv);
51     }
52 
53     // Finished getting options out, so cleanup the parser.
54     options.reset();
55 
56     MainLoop loop(
57         sdbusplus::bus::new_default(),
58         path,
59         BUSNAME_PREFIX,
60         SENSOR_ROOT);
61     loop.run();
62 
63     return 0;
64 }
65 
66 // vim: tabstop=8 expandtab shiftwidth=4 softtabstop=4
67