1 /** 2 * Copyright © 2017 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 <sdbusplus/bus.hpp> 17 #include <sdeventplus/event.hpp> 18 #include <phosphor-logging/log.hpp> 19 #include "argument.hpp" 20 #include "manager.hpp" 21 #include "sdbusplus.hpp" 22 23 using namespace phosphor::fan::control; 24 using namespace phosphor::logging; 25 26 int main(int argc, char* argv[]) 27 { 28 auto event = sdeventplus::Event::get_default(); 29 auto bus = sdbusplus::bus::new_default(); 30 phosphor::fan::util::ArgumentParser args(argc, argv); 31 32 if (argc != 2) 33 { 34 args.usage(argv); 35 return 1; 36 } 37 38 Mode mode; 39 40 if (args["init"] == "true") 41 { 42 mode = Mode::init; 43 } 44 else if (args["control"] == "true") 45 { 46 mode = Mode::control; 47 } 48 else 49 { 50 args.usage(argv); 51 return 1; 52 } 53 54 //Attach the event object to the bus object so we can 55 //handle both sd_events (for the timers) and dbus signals. 56 bus.attach_event(event.get(), SD_EVENT_PRIORITY_NORMAL); 57 58 try 59 { 60 Manager manager(bus, event, mode); 61 62 //Init mode will just set fans to max and delay 63 if (mode == Mode::init) 64 { 65 manager.doInit(); 66 return 0; 67 } 68 69 return event.loop(); 70 } 71 //Log the useful metadata on these exceptions and let the app 72 //return 1 so it is restarted without a core dump. 73 catch (phosphor::fan::util::DBusServiceError& e) 74 { 75 log<level::ERR>("Uncaught DBus service lookup failure exception", 76 entry("PATH=%s", e.path.c_str()), 77 entry("INTERFACE=%s", e.interface.c_str())); 78 } 79 catch (phosphor::fan::util::DBusMethodError& e) 80 { 81 log<level::ERR>("Uncaught DBus method failure exception", 82 entry("BUSNAME=%s", e.busName.c_str()), 83 entry("PATH=%s", e.path.c_str()), 84 entry("INTERFACE=%s", e.interface.c_str()), 85 entry("METHOD=%s", e.method.c_str())); 86 } 87 catch (phosphor::fan::util::DBusPropertyError& e) 88 { 89 log<level::ERR>("Uncaught DBus property access failure exception", 90 entry("BUSNAME=%s", e.busName.c_str()), 91 entry("PATH=%s", e.path.c_str()), 92 entry("INTERFACE=%s", e.interface.c_str()), 93 entry("PROPERTY=%s", e.property.c_str())); 94 } 95 96 return 1; 97 } 98