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 <phosphor-logging/log.hpp>
17 #include <sdbusplus/bus.hpp>
18 #include "event.hpp"
19 #include "fan.hpp"
20 #include "fan_defs.hpp"
21 
22 using namespace phosphor::fan::monitor;
23 using namespace phosphor::logging;
24 
25 
26 int main()
27 {
28     auto bus = sdbusplus::bus::new_default();
29     sd_event* events = nullptr;
30     std::vector<Fan> fans;
31 
32     auto r = sd_event_default(&events);
33     if (r < 0)
34     {
35         log<level::ERR>("Failed call to sd_event_default()",
36                         entry("ERROR=%s", strerror(-r)));
37         return -1;
38     }
39 
40     phosphor::fan::event::EventPtr eventPtr{events};
41 
42     //Attach the event object to the bus object so we can
43     //handle both sd_events (for the timers) and dbus signals.
44     bus.attach_event(eventPtr.get(), SD_EVENT_PRIORITY_NORMAL);
45 
46     for (const auto& fanDef : fanDefinitions)
47     {
48         fans.emplace_back(bus, eventPtr, fanDef);
49     }
50 
51     r = sd_event_loop(eventPtr.get());
52     if (r < 0)
53     {
54         log<level::ERR>("Failed call to sd_event_loop",
55                         entry("ERROR=%s", strerror(-r)));
56     }
57 
58     return -1;
59 }
60