blob: 6d51fbbca4b947d324c198814c2ddae99873a1ab [file] [log] [blame]
Matt Spinlere567dd22017-04-27 12:27:17 -05001/**
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 Spinlerc36168a2017-04-27 14:32:43 -050016#include <phosphor-logging/log.hpp>
17#include <sdbusplus/bus.hpp>
18#include "fan.hpp"
19#include "fan_defs.hpp"
Matt Spinlere567dd22017-04-27 12:27:17 -050020
Matt Spinlerc36168a2017-04-27 14:32:43 -050021using namespace phosphor::fan::monitor;
22using namespace phosphor::logging;
23
24
25void EventDeleter(sd_event* event)
26{
27 sd_event_unref(event);
28}
Matt Spinlere567dd22017-04-27 12:27:17 -050029
30int main()
31{
Matt Spinlerc36168a2017-04-27 14:32:43 -050032 auto bus = sdbusplus::bus::new_default();
33 sd_event* events = nullptr;
34 std::vector<std::unique_ptr<Fan>> fans;
35
36 auto r = sd_event_default(&events);
37 if (r < 0)
38 {
39 log<level::ERR>("Failed call to sd_event_default()",
40 entry("ERROR=%s", strerror(-r)));
41 return -1;
42 }
43
44 std::shared_ptr<sd_event> eventPtr{events, EventDeleter};
45
46 //Attach the event object to the bus object so we can
47 //handle both sd_events (for the timers) and dbus signals.
48 bus.attach_event(eventPtr.get(), SD_EVENT_PRIORITY_NORMAL);
49
50 for (const auto& fanDef : fanDefinitions)
51 {
52 fans.emplace_back(std::make_unique<Fan>(bus, eventPtr, fanDef));
53 }
54
55 r = sd_event_loop(eventPtr.get());
56 if (r < 0)
57 {
58 log<level::ERR>("Failed call to sd_event_loop",
59 entry("ERROR=%s", strerror(-r)));
60 }
61
62 return -1;
Matt Spinlere567dd22017-04-27 12:27:17 -050063}