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 | */ |
| 16 | #include <sdbusplus/bus.hpp> |
Matthew Barth | 8600d9a | 2017-06-23 14:38:05 -0500 | [diff] [blame] | 17 | #include <phosphor-logging/log.hpp> |
Matt Spinler | ee7f642 | 2017-05-09 11:03:14 -0500 | [diff] [blame] | 18 | #include "argument.hpp" |
Matt Spinler | e10416e | 2017-04-10 14:15:53 -0500 | [diff] [blame] | 19 | #include "manager.hpp" |
Matthew Barth | 8600d9a | 2017-06-23 14:38:05 -0500 | [diff] [blame] | 20 | #include "event.hpp" |
Matt Spinler | e73446e | 2017-04-10 13:55:52 -0500 | [diff] [blame] | 21 | |
Matt Spinler | ee7f642 | 2017-05-09 11:03:14 -0500 | [diff] [blame] | 22 | using namespace phosphor::fan::control; |
Matthew Barth | 8600d9a | 2017-06-23 14:38:05 -0500 | [diff] [blame] | 23 | using namespace phosphor::logging; |
Matt Spinler | ee7f642 | 2017-05-09 11:03:14 -0500 | [diff] [blame] | 24 | |
Matt Spinler | e73446e | 2017-04-10 13:55:52 -0500 | [diff] [blame] | 25 | int main(int argc, char* argv[]) |
| 26 | { |
| 27 | auto bus = sdbusplus::bus::new_default(); |
Matthew Barth | 8600d9a | 2017-06-23 14:38:05 -0500 | [diff] [blame] | 28 | sd_event* events = nullptr; |
Matt Spinler | ee7f642 | 2017-05-09 11:03:14 -0500 | [diff] [blame] | 29 | phosphor::fan::util::ArgumentParser args(argc, argv); |
Matt Spinler | e73446e | 2017-04-10 13:55:52 -0500 | [diff] [blame] | 30 | |
Matt Spinler | ee7f642 | 2017-05-09 11:03:14 -0500 | [diff] [blame] | 31 | if (argc != 2) |
| 32 | { |
| 33 | args.usage(argv); |
| 34 | exit(-1); |
| 35 | } |
| 36 | |
Matthew Barth | 1418413 | 2017-05-19 14:37:30 -0500 | [diff] [blame] | 37 | Mode mode; |
Matt Spinler | ee7f642 | 2017-05-09 11:03:14 -0500 | [diff] [blame] | 38 | |
| 39 | if (args["init"] == "true") |
| 40 | { |
Matthew Barth | 1418413 | 2017-05-19 14:37:30 -0500 | [diff] [blame] | 41 | mode = Mode::init; |
Matt Spinler | ee7f642 | 2017-05-09 11:03:14 -0500 | [diff] [blame] | 42 | } |
| 43 | else if (args["control"] == "true") |
| 44 | { |
Matthew Barth | 1418413 | 2017-05-19 14:37:30 -0500 | [diff] [blame] | 45 | mode = Mode::control; |
Matt Spinler | ee7f642 | 2017-05-09 11:03:14 -0500 | [diff] [blame] | 46 | } |
| 47 | else |
| 48 | { |
| 49 | args.usage(argv); |
| 50 | exit(-1); |
| 51 | } |
| 52 | |
Matthew Barth | 8600d9a | 2017-06-23 14:38:05 -0500 | [diff] [blame] | 53 | auto r = sd_event_default(&events); |
| 54 | if (r < 0) |
| 55 | { |
| 56 | log<level::ERR>("Failed call to sd_event_default()", |
| 57 | entry("ERROR=%s", strerror(-r))); |
| 58 | return -1; |
| 59 | } |
| 60 | |
| 61 | phosphor::fan::event::EventPtr eventPtr{events}; |
| 62 | |
| 63 | //Attach the event object to the bus object so we can |
| 64 | //handle both sd_events (for the timers) and dbus signals. |
| 65 | bus.attach_event(eventPtr.get(), SD_EVENT_PRIORITY_NORMAL); |
| 66 | |
| 67 | Manager manager(bus, eventPtr, mode); |
Matt Spinler | ee7f642 | 2017-05-09 11:03:14 -0500 | [diff] [blame] | 68 | |
| 69 | //Init mode will just set fans to max and delay |
Matthew Barth | 1418413 | 2017-05-19 14:37:30 -0500 | [diff] [blame] | 70 | if (mode == Mode::init) |
Matt Spinler | ee7f642 | 2017-05-09 11:03:14 -0500 | [diff] [blame] | 71 | { |
| 72 | manager.doInit(); |
| 73 | return 0; |
| 74 | } |
Matthew Barth | 8600d9a | 2017-06-23 14:38:05 -0500 | [diff] [blame] | 75 | else |
Matt Spinler | e73446e | 2017-04-10 13:55:52 -0500 | [diff] [blame] | 76 | { |
Matthew Barth | 8600d9a | 2017-06-23 14:38:05 -0500 | [diff] [blame] | 77 | r = sd_event_loop(eventPtr.get()); |
| 78 | if (r < 0) |
| 79 | { |
| 80 | log<level::ERR>("Failed call to sd_event_loop", |
| 81 | entry("ERROR=%s", strerror(-r))); |
| 82 | } |
Matt Spinler | e73446e | 2017-04-10 13:55:52 -0500 | [diff] [blame] | 83 | } |
| 84 | |
Matthew Barth | 8600d9a | 2017-06-23 14:38:05 -0500 | [diff] [blame] | 85 | return -1; |
Matt Spinler | e73446e | 2017-04-10 13:55:52 -0500 | [diff] [blame] | 86 | } |