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