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 "config.h" 17 18 #include "argument.hpp" 19 #include "mainloop.hpp" 20 #include "sysfs.hpp" 21 22 #include <iostream> 23 #include <memory> 24 25 static 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 33 int main(int argc, char** argv) 34 { 35 // Read arguments. 36 auto options = std::make_unique<ArgumentParser>(argc, argv); 37 38 // Parse out path argument. 39 auto path = (*options)["dev-path"]; 40 auto param = path; 41 if (path != ArgumentParser::empty_string) 42 { 43 // 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 } 53 } 54 55 if (path == ArgumentParser::empty_string) 56 { 57 path = (*options)["path"]; 58 param = path; 59 } 60 61 if (path == ArgumentParser::empty_string) 62 { 63 exit_with_error("Path not specified or invalid.", argv); 64 } 65 66 // Finished getting options out, so cleanup the parser. 67 options.reset(); 68 69 // 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 76 MainLoop loop(sdbusplus::bus::new_default(), param, path, calloutPath, 77 BUSNAME_PREFIX, SENSOR_ROOT); 78 loop.run(); 79 80 return 0; 81 } 82 83 // vim: tabstop=8 expandtab shiftwidth=4 softtabstop=4 84