From c36168a1a58a26eaade4ca53d68c49cc98303904 Mon Sep 17 00:00:00 2001 From: Matt Spinler Date: Thu, 27 Apr 2017 14:32:43 -0500 Subject: Fill in main() function Create the Fan objects, and start the dbus/event loop. Change-Id: I7c6a60bb5d2c20578b529e7e5f3dc13f50e55dd7 Signed-off-by: Matt Spinler --- monitor/main.cpp | 44 +++++++++++++++++++++++++++++++++++++++++++- 1 file changed, 43 insertions(+), 1 deletion(-) diff --git a/monitor/main.cpp b/monitor/main.cpp index e468bac..6d51fbb 100644 --- a/monitor/main.cpp +++ b/monitor/main.cpp @@ -13,9 +13,51 @@ * See the License for the specific language governing permissions and * limitations under the License. */ +#include +#include +#include "fan.hpp" +#include "fan_defs.hpp" +using namespace phosphor::fan::monitor; +using namespace phosphor::logging; + + +void EventDeleter(sd_event* event) +{ + sd_event_unref(event); +} int main() { - return 0; + auto bus = sdbusplus::bus::new_default(); + sd_event* events = nullptr; + std::vector> fans; + + auto r = sd_event_default(&events); + if (r < 0) + { + log("Failed call to sd_event_default()", + entry("ERROR=%s", strerror(-r))); + return -1; + } + + std::shared_ptr eventPtr{events, EventDeleter}; + + //Attach the event object to the bus object so we can + //handle both sd_events (for the timers) and dbus signals. + bus.attach_event(eventPtr.get(), SD_EVENT_PRIORITY_NORMAL); + + for (const auto& fanDef : fanDefinitions) + { + fans.emplace_back(std::make_unique(bus, eventPtr, fanDef)); + } + + r = sd_event_loop(eventPtr.get()); + if (r < 0) + { + log("Failed call to sd_event_loop", + entry("ERROR=%s", strerror(-r))); + } + + return -1; } -- cgit v1.2.1