Matt Spinler | e567dd2 | 2017-04-27 12:27:17 -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 | c36168a | 2017-04-27 14:32:43 -0500 | [diff] [blame] | 16 | #include <phosphor-logging/log.hpp> |
| 17 | #include <sdbusplus/bus.hpp> |
Matt Spinler | a5763ff | 2017-06-14 15:54:12 -0500 | [diff] [blame] | 18 | #include <systemd/sd-daemon.h> |
Matt Spinler | e824f98 | 2017-05-11 10:07:55 -0500 | [diff] [blame] | 19 | #include "event.hpp" |
Matt Spinler | c36168a | 2017-04-27 14:32:43 -0500 | [diff] [blame] | 20 | #include "fan.hpp" |
| 21 | #include "fan_defs.hpp" |
Matt Spinler | e567dd2 | 2017-04-27 12:27:17 -0500 | [diff] [blame] | 22 | |
Matt Spinler | c36168a | 2017-04-27 14:32:43 -0500 | [diff] [blame] | 23 | using namespace phosphor::fan::monitor; |
| 24 | using namespace phosphor::logging; |
| 25 | |
| 26 | |
Matt Spinler | e567dd2 | 2017-04-27 12:27:17 -0500 | [diff] [blame] | 27 | int main() |
| 28 | { |
Matt Spinler | c36168a | 2017-04-27 14:32:43 -0500 | [diff] [blame] | 29 | auto bus = sdbusplus::bus::new_default(); |
| 30 | sd_event* events = nullptr; |
Matt Spinler | 8420111 | 2017-05-12 11:31:53 -0500 | [diff] [blame] | 31 | std::vector<std::unique_ptr<Fan>> fans; |
Matt Spinler | c36168a | 2017-04-27 14:32:43 -0500 | [diff] [blame] | 32 | |
| 33 | auto r = sd_event_default(&events); |
| 34 | if (r < 0) |
| 35 | { |
| 36 | log<level::ERR>("Failed call to sd_event_default()", |
| 37 | entry("ERROR=%s", strerror(-r))); |
| 38 | return -1; |
| 39 | } |
| 40 | |
Matt Spinler | e824f98 | 2017-05-11 10:07:55 -0500 | [diff] [blame] | 41 | phosphor::fan::event::EventPtr eventPtr{events}; |
Matt Spinler | c36168a | 2017-04-27 14:32:43 -0500 | [diff] [blame] | 42 | |
| 43 | //Attach the event object to the bus object so we can |
| 44 | //handle both sd_events (for the timers) and dbus signals. |
| 45 | bus.attach_event(eventPtr.get(), SD_EVENT_PRIORITY_NORMAL); |
| 46 | |
| 47 | for (const auto& fanDef : fanDefinitions) |
| 48 | { |
Matt Spinler | 8420111 | 2017-05-12 11:31:53 -0500 | [diff] [blame] | 49 | fans.emplace_back(std::make_unique<Fan>(bus, eventPtr, fanDef)); |
Matt Spinler | c36168a | 2017-04-27 14:32:43 -0500 | [diff] [blame] | 50 | } |
| 51 | |
Matt Spinler | a5763ff | 2017-06-14 15:54:12 -0500 | [diff] [blame] | 52 | //Tell systemd we are initialized |
| 53 | r = sd_notify(0, "READY=1"); |
| 54 | if (r < 1) // 0 = nothing sent, < 0 is a failure |
| 55 | { |
| 56 | log<level::ERR>("sd_notify did not send anything", |
| 57 | entry("ERROR=%d", r)); |
| 58 | return -1; |
| 59 | } |
| 60 | |
Matt Spinler | c36168a | 2017-04-27 14:32:43 -0500 | [diff] [blame] | 61 | r = sd_event_loop(eventPtr.get()); |
| 62 | if (r < 0) |
| 63 | { |
| 64 | log<level::ERR>("Failed call to sd_event_loop", |
| 65 | entry("ERROR=%s", strerror(-r))); |
| 66 | } |
| 67 | |
| 68 | return -1; |
Matt Spinler | e567dd2 | 2017-04-27 12:27:17 -0500 | [diff] [blame] | 69 | } |