Andrew Geissler | 62817fa9 | 2017-03-20 14:20:49 -0500 | [diff] [blame^] | 1 | #include <stdio.h> |
| 2 | #include <stdlib.h> |
| 3 | #include <errno.h> |
| 4 | #include <systemd/sd-bus.h> |
| 5 | #include <mapper.h> |
| 6 | #include "host-ipmid/ipmid-api.h" |
| 7 | #include "host-interface.hpp" |
| 8 | #include <config.h> |
| 9 | |
| 10 | void register_host_services() __attribute__((constructor)); |
| 11 | |
| 12 | //------------------------------------------------------ |
| 13 | // Callback register function |
| 14 | // ----------------------------------------------------- |
| 15 | |
| 16 | // Globals to keep the object alive during process life |
| 17 | std::unique_ptr<sdbusplus::bus::bus> sdbus = nullptr; |
| 18 | // TODO openbmc/openbmc#1581 - unique_ptr causes seg fault |
| 19 | phosphor::host::Host* host = nullptr; |
| 20 | |
| 21 | void register_host_services() |
| 22 | { |
| 23 | // Gets a hook onto SYSTEM bus used by host-ipmid |
| 24 | sd_bus *bus = ipmid_get_sd_bus_connection(); |
| 25 | |
| 26 | sdbus = std::make_unique<sdbusplus::bus::bus>(bus); |
| 27 | |
| 28 | // Create new xyz.openbmc_project.host object on the bus |
| 29 | auto objPathInst = std::string{CONTROL_HOST_OBJPATH} + '0'; |
| 30 | |
| 31 | // Add sdbusplus ObjectManager. |
| 32 | sdbusplus::server::manager::manager objManager(*sdbus, |
| 33 | objPathInst.c_str()); |
| 34 | |
| 35 | host = new phosphor::host::Host(*sdbus, |
| 36 | objPathInst.c_str()); |
| 37 | |
| 38 | sdbus->request_name(CONTROL_HOST_BUSNAME); |
| 39 | } |