1 #pragma once 2 3 #include <sdbusplus/bus.hpp> 4 #include <sdbusplus/sdbus.hpp> 5 #include <sdbusplus/slot.hpp> 6 7 namespace sdbusplus 8 { 9 10 namespace server 11 { 12 13 namespace manager 14 { 15 16 /** @class manager 17 * @brief Provide a C++ holder for a sd-bus object manager. 18 * 19 * Wraps sd_bus_add_object_manager so that an sd-bus owned object manager 20 * can be installed at a path and automatically removed when destructed. 21 */ 22 struct manager : private sdbusplus::bus::details::bus_friend 23 { 24 /* Define all of the basic class operations: 25 * Not allowed: 26 * - Default constructor to avoid nullptrs. 27 * - Copy operations due to internal unique_ptr. 28 * Allowed: 29 * - Move operations. 30 * - Destructor. 31 */ 32 manager() = delete; 33 manager(const manager&) = delete; 34 manager& operator=(const manager&) = delete; 35 manager(manager&&) = default; 36 manager& operator=(manager&&) = default; 37 ~manager() = default; 38 39 /** @brief Register an object manager at a path. 40 * 41 * @param[in] bus - The bus to register on. 42 * @param[in] path - The path to register. 43 */ 44 manager(sdbusplus::bus_t& bus, const char* path) 45 { 46 sd_bus_slot* slot = nullptr; 47 sdbusplus::SdBusInterface* intf = bus.getInterface(); 48 49 intf->sd_bus_add_object_manager(get_busp(bus), &slot, path); 50 51 _slot = std::move(slot); 52 } 53 54 private: 55 slot_t _slot{}; 56 }; 57 58 } // namespace manager 59 60 using manager_t = manager::manager; 61 62 } // namespace server 63 } // namespace sdbusplus 64