diff options
author | Matt Spinler <spinler@us.ibm.com> | 2017-04-27 14:32:43 -0500 |
---|---|---|
committer | Matt Spinler <spinler@us.ibm.com> | 2017-05-11 13:52:50 -0500 |
commit | c36168a1a58a26eaade4ca53d68c49cc98303904 (patch) | |
tree | 3635b7b523ce0160d750958ccf4e1c30da18366c | |
parent | a9406a774a35c02fabc94ab842788dd9891f59e8 (diff) | |
download | phosphor-fan-presence-c36168a1a58a26eaade4ca53d68c49cc98303904.tar.gz phosphor-fan-presence-c36168a1a58a26eaade4ca53d68c49cc98303904.zip |
Fill in main() function
Create the Fan objects, and start the dbus/event loop.
Change-Id: I7c6a60bb5d2c20578b529e7e5f3dc13f50e55dd7
Signed-off-by: Matt Spinler <spinler@us.ibm.com>
-rw-r--r-- | monitor/main.cpp | 44 |
1 files changed, 43 insertions, 1 deletions
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 <phosphor-logging/log.hpp> +#include <sdbusplus/bus.hpp> +#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<std::unique_ptr<Fan>> fans; + + auto r = sd_event_default(&events); + if (r < 0) + { + log<level::ERR>("Failed call to sd_event_default()", + entry("ERROR=%s", strerror(-r))); + return -1; + } + + std::shared_ptr<sd_event> 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<Fan>(bus, eventPtr, fanDef)); + } + + r = sd_event_loop(eventPtr.get()); + if (r < 0) + { + log<level::ERR>("Failed call to sd_event_loop", + entry("ERROR=%s", strerror(-r))); + } + + return -1; } |