Brad Bishop | 49aefb3 | 2016-10-19 11:54:14 -0400 | [diff] [blame] | 1 | #pragma once |
| 2 | |
| 3 | #include <map> |
| 4 | #include <memory> |
| 5 | #include <string> |
| 6 | #include <vector> |
| 7 | #include <sdbusplus/server.hpp> |
Brad Bishop | e30dd77 | 2016-11-12 21:39:28 -0500 | [diff] [blame] | 8 | #include "xyz/openbmc_project/Inventory/Manager/server.hpp" |
Brad Bishop | 67b788d | 2016-11-29 13:09:01 -0500 | [diff] [blame^] | 9 | #include "events.hpp" |
Brad Bishop | c038e01 | 2016-10-19 13:02:24 -0400 | [diff] [blame] | 10 | #include "actions.hpp" |
Brad Bishop | 49aefb3 | 2016-10-19 11:54:14 -0400 | [diff] [blame] | 11 | |
| 12 | namespace phosphor |
| 13 | { |
| 14 | namespace inventory |
| 15 | { |
| 16 | namespace manager |
| 17 | { |
| 18 | namespace details |
| 19 | { |
Brad Bishop | 451f8d9 | 2016-11-21 14:15:19 -0500 | [diff] [blame] | 20 | |
| 21 | template <typename T> |
| 22 | using ServerObject = typename sdbusplus::server::object::object<T>; |
| 23 | |
| 24 | using ManagerIface = |
| 25 | sdbusplus::server::xyz::openbmc_project::Inventory::Manager; |
| 26 | |
Brad Bishop | 65ffffa | 2016-11-29 12:31:31 -0500 | [diff] [blame] | 27 | /** @struct MakeInterface |
| 28 | * @brief Adapt an sdbusplus interface proxy. |
| 29 | * |
| 30 | * Template instances are builder functions that create |
| 31 | * adapted sdbusplus interface proxy interface objects. |
| 32 | * |
| 33 | * @tparam T - The type of the interface being adapted. |
| 34 | */ |
| 35 | template <typename T> |
| 36 | struct MakeInterface |
| 37 | { |
| 38 | static decltype(auto) make(sdbusplus::bus::bus &bus, const char *path) |
| 39 | { |
| 40 | using HolderType = holder::Holder<std::unique_ptr<T>>; |
| 41 | return static_cast<std::unique_ptr<holder::Base>>( |
| 42 | HolderType::template make_unique<HolderType>( |
| 43 | std::forward<std::unique_ptr<T>>( |
| 44 | std::make_unique<T>( |
| 45 | std::forward<decltype(bus)>(bus), |
| 46 | std::forward<decltype(path)>(path))))); |
| 47 | } |
| 48 | }; |
Brad Bishop | 49aefb3 | 2016-10-19 11:54:14 -0400 | [diff] [blame] | 49 | } // namespace details |
| 50 | |
| 51 | /** @class Manager |
| 52 | * @brief OpenBMC inventory manager implementation. |
| 53 | * |
| 54 | * A concrete implementation for the xyz.openbmc_project.Inventory.Manager |
| 55 | * DBus API. |
| 56 | */ |
| 57 | class Manager final : |
Brad Bishop | 451f8d9 | 2016-11-21 14:15:19 -0500 | [diff] [blame] | 58 | public details::ServerObject<details::ManagerIface> |
Brad Bishop | 49aefb3 | 2016-10-19 11:54:14 -0400 | [diff] [blame] | 59 | { |
| 60 | public: |
| 61 | Manager() = delete; |
| 62 | Manager(const Manager&) = delete; |
| 63 | Manager& operator=(const Manager&) = delete; |
| 64 | Manager(Manager&&) = default; |
| 65 | Manager& operator=(Manager&&) = default; |
| 66 | ~Manager() = default; |
| 67 | |
| 68 | /** @brief Construct an inventory manager. |
| 69 | * |
| 70 | * @param[in] bus - An sdbusplus bus connection. |
| 71 | * @param[in] busname - The DBus busname to own. |
| 72 | * @param[in] root - The DBus path on which to implement |
| 73 | * an inventory manager. |
| 74 | * @param[in] iface - The DBus inventory interface to implement. |
| 75 | */ |
| 76 | Manager(sdbusplus::bus::bus &&, const char *, const char*, const char*); |
| 77 | |
| 78 | using Object = std::map< |
| 79 | std::string, std::map< |
| 80 | std::string, sdbusplus::message::variant<std::string>>>; |
| 81 | |
| 82 | /** @brief Start processing DBus messages. */ |
| 83 | void run() noexcept; |
| 84 | |
| 85 | /** @brief Provided for testing only. */ |
| 86 | void shutdown() noexcept; |
| 87 | |
| 88 | /** @brief sd_bus Notify method implementation callback. */ |
| 89 | void notify(std::string path, Object) override; |
| 90 | |
| 91 | /** @brief sd_bus signal callback. */ |
| 92 | void signal(sdbusplus::message::message &, auto &); |
| 93 | |
Brad Bishop | 656a7d0 | 2016-10-19 22:20:02 -0400 | [diff] [blame] | 94 | /** @brief Drop an object from DBus. */ |
| 95 | void destroyObject(const char *); |
| 96 | |
Brad Bishop | c038e01 | 2016-10-19 13:02:24 -0400 | [diff] [blame] | 97 | using Event = std::tuple< |
| 98 | const char *, |
Brad Bishop | 65ffffa | 2016-11-29 12:31:31 -0500 | [diff] [blame] | 99 | details::FilterBasePtr, |
Brad Bishop | 9007432 | 2016-11-29 13:05:57 -0500 | [diff] [blame] | 100 | std::vector<details::ActionBasePtr>>; |
Brad Bishop | 49aefb3 | 2016-10-19 11:54:14 -0400 | [diff] [blame] | 101 | using SigArgs = std::vector< |
| 102 | std::unique_ptr< |
| 103 | std::tuple< |
| 104 | Manager *, |
| 105 | const Event *>>>; |
| 106 | using SigArg = SigArgs::value_type::element_type; |
| 107 | |
| 108 | private: |
Brad Bishop | 65ffffa | 2016-11-29 12:31:31 -0500 | [diff] [blame] | 109 | using HolderPtr = std::unique_ptr<details::holder::Base>; |
Brad Bishop | 49aefb3 | 2016-10-19 11:54:14 -0400 | [diff] [blame] | 110 | using InterfaceComposite = std::map<std::string, HolderPtr>; |
| 111 | using ObjectReferences = std::map<std::string, InterfaceComposite>; |
| 112 | using Events = std::map<const char *, Event>; |
Brad Bishop | 5fbaa7f | 2016-10-31 10:42:41 -0500 | [diff] [blame] | 113 | using MakerType = HolderPtr(*)( |
| 114 | sdbusplus::bus::bus &, const char *); |
| 115 | using Makers = std::map<std::string, MakerType>; |
Brad Bishop | 49aefb3 | 2016-10-19 11:54:14 -0400 | [diff] [blame] | 116 | |
| 117 | /** @brief Provided for testing only. */ |
| 118 | bool _shutdown; |
| 119 | |
| 120 | /** @brief Path prefix applied to any relative paths. */ |
| 121 | const char * _root; |
| 122 | |
| 123 | /** @brief A container of sdbusplus server interface references. */ |
| 124 | ObjectReferences _refs; |
| 125 | |
| 126 | /** @brief A container contexts for signal callbacks. */ |
| 127 | SigArgs _sigargs; |
| 128 | |
| 129 | /** @brief A container of sdbusplus signal matches. */ |
| 130 | std::vector<sdbusplus::server::match::match> _matches; |
| 131 | |
| 132 | /** @brief Persistent sdbusplus DBus bus connection. */ |
| 133 | sdbusplus::bus::bus _bus; |
| 134 | |
| 135 | /** @brief sdbusplus org.freedesktop.DBus.ObjectManager reference. */ |
| 136 | sdbusplus::server::manager::manager _manager; |
| 137 | |
| 138 | /** @brief A container of pimgen generated events and responses. */ |
| 139 | static const Events _events; |
Brad Bishop | 5fbaa7f | 2016-10-31 10:42:41 -0500 | [diff] [blame] | 140 | |
| 141 | /** @brief A container of pimgen generated factory methods. */ |
| 142 | static const Makers _makers; |
Brad Bishop | 49aefb3 | 2016-10-19 11:54:14 -0400 | [diff] [blame] | 143 | }; |
| 144 | |
| 145 | } // namespace manager |
| 146 | } // namespace inventory |
| 147 | } // namespace phosphor |
| 148 | |
| 149 | // vim: tabstop=8 expandtab shiftwidth=4 softtabstop=4 |