Brad Bishop | 49aefb3 | 2016-10-19 11:54:14 -0400 | [diff] [blame] | 1 | #pragma once |
| 2 | |
Brad Bishop | 67b788d | 2016-11-29 13:09:01 -0500 | [diff] [blame] | 3 | #include "events.hpp" |
Brad Bishop | c1f4798 | 2017-02-09 01:27:38 -0500 | [diff] [blame] | 4 | #include "functor.hpp" |
Deepak Kodihalli | 6620e98 | 2017-08-05 13:09:54 -0500 | [diff] [blame] | 5 | #include "serialize.hpp" |
Patrick Venture | a680d1e | 2018-10-14 13:34:26 -0700 | [diff] [blame] | 6 | #include "types.hpp" |
| 7 | |
Brad Bishop | 25d54b5 | 2018-11-21 12:57:51 -0500 | [diff] [blame] | 8 | #include <any> |
Patrick Venture | a680d1e | 2018-10-14 13:34:26 -0700 | [diff] [blame] | 9 | #include <map> |
| 10 | #include <memory> |
| 11 | #include <sdbusplus/server.hpp> |
| 12 | #include <string> |
| 13 | #include <vector> |
| 14 | #include <xyz/openbmc_project/Inventory/Manager/server.hpp> |
Brad Bishop | 49aefb3 | 2016-10-19 11:54:14 -0400 | [diff] [blame] | 15 | |
| 16 | namespace phosphor |
| 17 | { |
| 18 | namespace inventory |
| 19 | { |
| 20 | namespace manager |
| 21 | { |
Brad Bishop | 451f8d9 | 2016-11-21 14:15:19 -0500 | [diff] [blame] | 22 | |
Patrick Venture | a680d1e | 2018-10-14 13:34:26 -0700 | [diff] [blame] | 23 | template <typename T> |
| 24 | using ServerObject = T; |
Brad Bishop | 451f8d9 | 2016-11-21 14:15:19 -0500 | [diff] [blame] | 25 | |
| 26 | using ManagerIface = |
Brad Bishop | 9aa5e2f | 2017-01-15 19:45:40 -0500 | [diff] [blame] | 27 | sdbusplus::xyz::openbmc_project::Inventory::server::Manager; |
Brad Bishop | 451f8d9 | 2016-11-21 14:15:19 -0500 | [diff] [blame] | 28 | |
Brad Bishop | 79ccaf7 | 2017-01-22 16:00:50 -0500 | [diff] [blame] | 29 | /** @struct PropertiesVariant |
| 30 | * @brief Wrapper for sdbusplus PropertiesVariant. |
| 31 | * |
| 32 | * A wrapper is useful since MakeInterface is instantiated with 'int' |
| 33 | * to deduce the return type of its methods, which does not depend |
| 34 | * on T. |
| 35 | * |
| 36 | * @tparam T - The sdbusplus server binding type. |
| 37 | */ |
Patrick Venture | a680d1e | 2018-10-14 13:34:26 -0700 | [diff] [blame] | 38 | template <typename T, typename Enable = void> |
| 39 | struct PropertiesVariant |
Brad Bishop | 615b2a8 | 2018-03-29 10:32:41 -0400 | [diff] [blame] | 40 | { |
| 41 | }; |
Brad Bishop | 79ccaf7 | 2017-01-22 16:00:50 -0500 | [diff] [blame] | 42 | |
| 43 | template <typename T> |
Brad Bishop | 615b2a8 | 2018-03-29 10:32:41 -0400 | [diff] [blame] | 44 | struct PropertiesVariant< |
| 45 | T, typename std::enable_if<std::is_object<T>::value>::type> |
Brad Bishop | 79ccaf7 | 2017-01-22 16:00:50 -0500 | [diff] [blame] | 46 | { |
| 47 | using Type = typename T::PropertiesVariant; |
| 48 | }; |
| 49 | |
| 50 | template <typename T> |
| 51 | using PropertiesVariantType = typename PropertiesVariant<T>::Type; |
| 52 | |
Patrick Venture | a680d1e | 2018-10-14 13:34:26 -0700 | [diff] [blame] | 53 | template <typename T, typename U = int> |
| 54 | struct HasProperties : std::false_type |
Marri Devender Rao | fa23d70 | 2017-09-02 04:43:42 -0500 | [diff] [blame] | 55 | { |
| 56 | }; |
| 57 | |
| 58 | template <typename T> |
Brad Bishop | 615b2a8 | 2018-03-29 10:32:41 -0400 | [diff] [blame] | 59 | struct HasProperties< |
| 60 | T, decltype((void)std::declval<typename T::PropertiesVariant>(), 0)> |
| 61 | : std::true_type |
Marri Devender Rao | fa23d70 | 2017-09-02 04:43:42 -0500 | [diff] [blame] | 62 | { |
| 63 | }; |
| 64 | |
| 65 | template <typename T, std::enable_if_t<HasProperties<T>::value, bool> = true> |
Brad Bishop | 25d54b5 | 2018-11-21 12:57:51 -0500 | [diff] [blame] | 66 | std::any propMake(sdbusplus::bus::bus& bus, const char* path, |
| 67 | const Interface& props) |
Marri Devender Rao | fa23d70 | 2017-09-02 04:43:42 -0500 | [diff] [blame] | 68 | { |
Brad Bishop | 615b2a8 | 2018-03-29 10:32:41 -0400 | [diff] [blame] | 69 | using InterfaceVariant = std::map<std::string, PropertiesVariantType<T>>; |
Marri Devender Rao | fa23d70 | 2017-09-02 04:43:42 -0500 | [diff] [blame] | 70 | |
| 71 | InterfaceVariant v; |
| 72 | for (const auto& p : props) |
| 73 | { |
Brad Bishop | 615b2a8 | 2018-03-29 10:32:41 -0400 | [diff] [blame] | 74 | v.emplace(p.first, convertVariant<PropertiesVariantType<T>>(p.second)); |
Marri Devender Rao | fa23d70 | 2017-09-02 04:43:42 -0500 | [diff] [blame] | 75 | } |
| 76 | |
Brad Bishop | 25d54b5 | 2018-11-21 12:57:51 -0500 | [diff] [blame] | 77 | return std::any(std::make_shared<T>(bus, path, v)); |
Marri Devender Rao | fa23d70 | 2017-09-02 04:43:42 -0500 | [diff] [blame] | 78 | } |
| 79 | |
| 80 | template <typename T, std::enable_if_t<!HasProperties<T>::value, bool> = false> |
Brad Bishop | 25d54b5 | 2018-11-21 12:57:51 -0500 | [diff] [blame] | 81 | std::any propMake(sdbusplus::bus::bus& bus, const char* path, |
| 82 | const Interface& props) |
Marri Devender Rao | fa23d70 | 2017-09-02 04:43:42 -0500 | [diff] [blame] | 83 | { |
Brad Bishop | 25d54b5 | 2018-11-21 12:57:51 -0500 | [diff] [blame] | 84 | return std::any(std::make_shared<T>(bus, path)); |
Marri Devender Rao | fa23d70 | 2017-09-02 04:43:42 -0500 | [diff] [blame] | 85 | } |
| 86 | |
| 87 | template <typename T, std::enable_if_t<HasProperties<T>::value, bool> = true> |
Brad Bishop | 25d54b5 | 2018-11-21 12:57:51 -0500 | [diff] [blame] | 88 | void propAssign(const Interface& props, std::any& holder) |
Marri Devender Rao | fa23d70 | 2017-09-02 04:43:42 -0500 | [diff] [blame] | 89 | { |
Brad Bishop | 25d54b5 | 2018-11-21 12:57:51 -0500 | [diff] [blame] | 90 | auto& iface = *std::any_cast<std::shared_ptr<T>&>(holder); |
Marri Devender Rao | fa23d70 | 2017-09-02 04:43:42 -0500 | [diff] [blame] | 91 | for (const auto& p : props) |
| 92 | { |
| 93 | iface.setPropertyByName( |
| 94 | p.first, convertVariant<PropertiesVariantType<T>>(p.second)); |
| 95 | } |
| 96 | } |
| 97 | |
| 98 | template <typename T, std::enable_if_t<!HasProperties<T>::value, bool> = false> |
Brad Bishop | 25d54b5 | 2018-11-21 12:57:51 -0500 | [diff] [blame] | 99 | void propAssign(const Interface& props, std::any& holder) |
Marri Devender Rao | fa23d70 | 2017-09-02 04:43:42 -0500 | [diff] [blame] | 100 | { |
| 101 | } |
| 102 | |
| 103 | template <typename T, std::enable_if_t<HasProperties<T>::value, bool> = true> |
Brad Bishop | 615b2a8 | 2018-03-29 10:32:41 -0400 | [diff] [blame] | 104 | void propSerialize(const std::string& path, const std::string& iface, |
Brad Bishop | 25d54b5 | 2018-11-21 12:57:51 -0500 | [diff] [blame] | 105 | const std::any& holder) |
Marri Devender Rao | fa23d70 | 2017-09-02 04:43:42 -0500 | [diff] [blame] | 106 | { |
Brad Bishop | 25d54b5 | 2018-11-21 12:57:51 -0500 | [diff] [blame] | 107 | const auto& object = *std::any_cast<const std::shared_ptr<T>&>(holder); |
Marri Devender Rao | fa23d70 | 2017-09-02 04:43:42 -0500 | [diff] [blame] | 108 | cereal::serialize(path, iface, object); |
| 109 | } |
| 110 | |
| 111 | template <typename T, std::enable_if_t<!HasProperties<T>::value, bool> = false> |
Brad Bishop | 615b2a8 | 2018-03-29 10:32:41 -0400 | [diff] [blame] | 112 | void propSerialize(const std::string& path, const std::string& iface, |
Brad Bishop | 25d54b5 | 2018-11-21 12:57:51 -0500 | [diff] [blame] | 113 | const std::any& holder) |
Marri Devender Rao | fa23d70 | 2017-09-02 04:43:42 -0500 | [diff] [blame] | 114 | { |
| 115 | cereal::serialize(path, iface); |
| 116 | } |
| 117 | |
| 118 | template <typename T, std::enable_if_t<HasProperties<T>::value, bool> = true> |
Brad Bishop | 615b2a8 | 2018-03-29 10:32:41 -0400 | [diff] [blame] | 119 | void propDeSerialize(const std::string& path, const std::string& iface, |
Brad Bishop | 25d54b5 | 2018-11-21 12:57:51 -0500 | [diff] [blame] | 120 | std::any& holder) |
Marri Devender Rao | fa23d70 | 2017-09-02 04:43:42 -0500 | [diff] [blame] | 121 | { |
Brad Bishop | 25d54b5 | 2018-11-21 12:57:51 -0500 | [diff] [blame] | 122 | auto& object = *std::any_cast<std::shared_ptr<T>&>(holder); |
Marri Devender Rao | fa23d70 | 2017-09-02 04:43:42 -0500 | [diff] [blame] | 123 | cereal::deserialize(path, iface, object); |
| 124 | } |
| 125 | |
| 126 | template <typename T, std::enable_if_t<!HasProperties<T>::value, bool> = false> |
Brad Bishop | 615b2a8 | 2018-03-29 10:32:41 -0400 | [diff] [blame] | 127 | void propDeSerialize(const std::string& path, const std::string& iface, |
Brad Bishop | 25d54b5 | 2018-11-21 12:57:51 -0500 | [diff] [blame] | 128 | std::any& holder) |
Marri Devender Rao | fa23d70 | 2017-09-02 04:43:42 -0500 | [diff] [blame] | 129 | { |
| 130 | } |
| 131 | |
Brad Bishop | 65ffffa | 2016-11-29 12:31:31 -0500 | [diff] [blame] | 132 | /** @struct MakeInterface |
| 133 | * @brief Adapt an sdbusplus interface proxy. |
| 134 | * |
| 135 | * Template instances are builder functions that create |
| 136 | * adapted sdbusplus interface proxy interface objects. |
| 137 | * |
| 138 | * @tparam T - The type of the interface being adapted. |
| 139 | */ |
Brad Bishop | 79ccaf7 | 2017-01-22 16:00:50 -0500 | [diff] [blame] | 140 | |
Patrick Venture | a680d1e | 2018-10-14 13:34:26 -0700 | [diff] [blame] | 141 | template <typename T> |
| 142 | struct MakeInterface |
Brad Bishop | 65ffffa | 2016-11-29 12:31:31 -0500 | [diff] [blame] | 143 | { |
Brad Bishop | 25d54b5 | 2018-11-21 12:57:51 -0500 | [diff] [blame] | 144 | static std::any make(sdbusplus::bus::bus& bus, const char* path, |
| 145 | const Interface& props) |
Brad Bishop | 65ffffa | 2016-11-29 12:31:31 -0500 | [diff] [blame] | 146 | { |
Marri Devender Rao | fa23d70 | 2017-09-02 04:43:42 -0500 | [diff] [blame] | 147 | return propMake<T>(bus, path, props); |
Brad Bishop | 65ffffa | 2016-11-29 12:31:31 -0500 | [diff] [blame] | 148 | } |
Brad Bishop | 79ccaf7 | 2017-01-22 16:00:50 -0500 | [diff] [blame] | 149 | |
Brad Bishop | 25d54b5 | 2018-11-21 12:57:51 -0500 | [diff] [blame] | 150 | static void assign(const Interface& props, std::any& holder) |
Brad Bishop | 79ccaf7 | 2017-01-22 16:00:50 -0500 | [diff] [blame] | 151 | { |
Marri Devender Rao | fa23d70 | 2017-09-02 04:43:42 -0500 | [diff] [blame] | 152 | propAssign<T>(props, holder); |
Brad Bishop | 79ccaf7 | 2017-01-22 16:00:50 -0500 | [diff] [blame] | 153 | } |
Deepak Kodihalli | 6620e98 | 2017-08-05 13:09:54 -0500 | [diff] [blame] | 154 | |
Brad Bishop | 615b2a8 | 2018-03-29 10:32:41 -0400 | [diff] [blame] | 155 | static void serialize(const std::string& path, const std::string& iface, |
Brad Bishop | 25d54b5 | 2018-11-21 12:57:51 -0500 | [diff] [blame] | 156 | const std::any& holder) |
Deepak Kodihalli | 6620e98 | 2017-08-05 13:09:54 -0500 | [diff] [blame] | 157 | { |
Marri Devender Rao | fa23d70 | 2017-09-02 04:43:42 -0500 | [diff] [blame] | 158 | propSerialize<T>(path, iface, holder); |
Deepak Kodihalli | 6620e98 | 2017-08-05 13:09:54 -0500 | [diff] [blame] | 159 | } |
Deepak Kodihalli | b28990f | 2017-08-08 07:19:34 -0500 | [diff] [blame] | 160 | |
Brad Bishop | 615b2a8 | 2018-03-29 10:32:41 -0400 | [diff] [blame] | 161 | static void deserialize(const std::string& path, const std::string& iface, |
Brad Bishop | 25d54b5 | 2018-11-21 12:57:51 -0500 | [diff] [blame] | 162 | std::any& holder) |
Deepak Kodihalli | b28990f | 2017-08-08 07:19:34 -0500 | [diff] [blame] | 163 | { |
Marri Devender Rao | fa23d70 | 2017-09-02 04:43:42 -0500 | [diff] [blame] | 164 | propDeSerialize<T>(path, iface, holder); |
Deepak Kodihalli | b28990f | 2017-08-08 07:19:34 -0500 | [diff] [blame] | 165 | } |
Brad Bishop | 65ffffa | 2016-11-29 12:31:31 -0500 | [diff] [blame] | 166 | }; |
Brad Bishop | 49aefb3 | 2016-10-19 11:54:14 -0400 | [diff] [blame] | 167 | |
| 168 | /** @class Manager |
| 169 | * @brief OpenBMC inventory manager implementation. |
| 170 | * |
| 171 | * A concrete implementation for the xyz.openbmc_project.Inventory.Manager |
| 172 | * DBus API. |
| 173 | */ |
Brad Bishop | 615b2a8 | 2018-03-29 10:32:41 -0400 | [diff] [blame] | 174 | class Manager final : public ServerObject<ManagerIface> |
Brad Bishop | 49aefb3 | 2016-10-19 11:54:14 -0400 | [diff] [blame] | 175 | { |
Brad Bishop | 615b2a8 | 2018-03-29 10:32:41 -0400 | [diff] [blame] | 176 | public: |
| 177 | Manager() = delete; |
| 178 | Manager(const Manager&) = delete; |
| 179 | Manager& operator=(const Manager&) = delete; |
| 180 | Manager(Manager&&) = default; |
| 181 | Manager& operator=(Manager&&) = default; |
| 182 | ~Manager() = default; |
Brad Bishop | 49aefb3 | 2016-10-19 11:54:14 -0400 | [diff] [blame] | 183 | |
Brad Bishop | 615b2a8 | 2018-03-29 10:32:41 -0400 | [diff] [blame] | 184 | /** @brief Construct an inventory manager. |
| 185 | * |
| 186 | * @param[in] bus - An sdbusplus bus connection. |
| 187 | * @param[in] busname - The DBus busname to own. |
| 188 | * @param[in] root - The DBus path on which to implement |
| 189 | * an inventory manager. |
| 190 | * @param[in] iface - The DBus inventory interface to implement. |
| 191 | */ |
| 192 | Manager(sdbusplus::bus::bus&&, const char*, const char*, const char*); |
Brad Bishop | 49aefb3 | 2016-10-19 11:54:14 -0400 | [diff] [blame] | 193 | |
Brad Bishop | 615b2a8 | 2018-03-29 10:32:41 -0400 | [diff] [blame] | 194 | using EventInfo = |
| 195 | std::tuple<std::vector<EventBasePtr>, std::vector<Action>>; |
Brad Bishop | 49aefb3 | 2016-10-19 11:54:14 -0400 | [diff] [blame] | 196 | |
Brad Bishop | 615b2a8 | 2018-03-29 10:32:41 -0400 | [diff] [blame] | 197 | /** @brief Start processing DBus messages. */ |
| 198 | void run() noexcept; |
Brad Bishop | 49aefb3 | 2016-10-19 11:54:14 -0400 | [diff] [blame] | 199 | |
Brad Bishop | 615b2a8 | 2018-03-29 10:32:41 -0400 | [diff] [blame] | 200 | /** @brief Provided for testing only. */ |
| 201 | void shutdown() noexcept; |
Brad Bishop | 49aefb3 | 2016-10-19 11:54:14 -0400 | [diff] [blame] | 202 | |
Brad Bishop | 615b2a8 | 2018-03-29 10:32:41 -0400 | [diff] [blame] | 203 | /** @brief sd_bus Notify method implementation callback. */ |
| 204 | void |
| 205 | notify(std::map<sdbusplus::message::object_path, Object> objs) override; |
Brad Bishop | 49aefb3 | 2016-10-19 11:54:14 -0400 | [diff] [blame] | 206 | |
Brad Bishop | 615b2a8 | 2018-03-29 10:32:41 -0400 | [diff] [blame] | 207 | /** @brief Event processing entry point. */ |
| 208 | void handleEvent(sdbusplus::message::message&, const Event& event, |
| 209 | const EventInfo& info); |
Brad Bishop | 49aefb3 | 2016-10-19 11:54:14 -0400 | [diff] [blame] | 210 | |
Brad Bishop | 615b2a8 | 2018-03-29 10:32:41 -0400 | [diff] [blame] | 211 | /** @brief Drop one or more objects from DBus. */ |
| 212 | void destroyObjects(const std::vector<const char*>& paths); |
Brad Bishop | 656a7d0 | 2016-10-19 22:20:02 -0400 | [diff] [blame] | 213 | |
Brad Bishop | 615b2a8 | 2018-03-29 10:32:41 -0400 | [diff] [blame] | 214 | /** @brief Add objects to DBus. */ |
| 215 | void createObjects( |
| 216 | const std::map<sdbusplus::message::object_path, Object>& objs); |
Brad Bishop | eb68a68 | 2017-01-22 00:58:54 -0500 | [diff] [blame] | 217 | |
Brad Bishop | 615b2a8 | 2018-03-29 10:32:41 -0400 | [diff] [blame] | 218 | /** @brief Add or update objects on DBus. */ |
| 219 | void updateObjects( |
| 220 | const std::map<sdbusplus::message::object_path, Object>& objs, |
| 221 | bool restoreFromCache = false); |
Deepak Kodihalli | b28990f | 2017-08-08 07:19:34 -0500 | [diff] [blame] | 222 | |
Brad Bishop | 615b2a8 | 2018-03-29 10:32:41 -0400 | [diff] [blame] | 223 | /** @brief Restore persistent inventory items */ |
| 224 | void restore(); |
Brad Bishop | 79ccaf7 | 2017-01-22 16:00:50 -0500 | [diff] [blame] | 225 | |
Brad Bishop | 615b2a8 | 2018-03-29 10:32:41 -0400 | [diff] [blame] | 226 | /** @brief Invoke an sdbusplus server binding method. |
| 227 | * |
| 228 | * Invoke the requested method with a reference to the requested |
| 229 | * sdbusplus server binding interface as a parameter. |
| 230 | * |
| 231 | * @tparam T - The sdbusplus server binding interface type. |
| 232 | * @tparam U - The type of the sdbusplus server binding member. |
| 233 | * @tparam Args - Argument types of the binding member. |
| 234 | * |
| 235 | * @param[in] path - The DBus path on which the method should |
| 236 | * be invoked. |
| 237 | * @param[in] interface - The DBus interface hosting the method. |
| 238 | * @param[in] member - Pointer to sdbusplus server binding member. |
| 239 | * @param[in] args - Arguments to forward to the binding member. |
| 240 | * |
| 241 | * @returns - The return/value type of the binding method being |
| 242 | * called. |
| 243 | */ |
| 244 | template <typename T, typename U, typename... Args> |
| 245 | decltype(auto) invokeMethod(const char* path, const char* interface, |
| 246 | U&& member, Args&&... args) |
| 247 | { |
| 248 | auto& iface = getInterface<T>(path, interface); |
| 249 | return (iface.*member)(std::forward<Args>(args)...); |
| 250 | } |
Brad Bishop | da649b1 | 2016-11-30 14:35:02 -0500 | [diff] [blame] | 251 | |
Brad Bishop | 615b2a8 | 2018-03-29 10:32:41 -0400 | [diff] [blame] | 252 | using SigArgs = std::vector<std::unique_ptr< |
| 253 | std::tuple<Manager*, const DbusSignal*, const EventInfo*>>>; |
| 254 | using SigArg = SigArgs::value_type::element_type; |
Brad Bishop | 49aefb3 | 2016-10-19 11:54:14 -0400 | [diff] [blame] | 255 | |
Brad Bishop | 615b2a8 | 2018-03-29 10:32:41 -0400 | [diff] [blame] | 256 | private: |
Brad Bishop | 25d54b5 | 2018-11-21 12:57:51 -0500 | [diff] [blame] | 257 | using InterfaceComposite = std::map<std::string, std::any>; |
Brad Bishop | 615b2a8 | 2018-03-29 10:32:41 -0400 | [diff] [blame] | 258 | using ObjectReferences = std::map<std::string, InterfaceComposite>; |
| 259 | using Events = std::vector<EventInfo>; |
Brad Bishop | 90c30bc | 2017-01-22 16:40:47 -0500 | [diff] [blame] | 260 | |
Brad Bishop | 615b2a8 | 2018-03-29 10:32:41 -0400 | [diff] [blame] | 261 | // The int instantiations are safe since the signature of these |
| 262 | // functions don't change from one instantiation to the next. |
| 263 | using MakerType = std::add_pointer_t<decltype(MakeInterface<int>::make)>; |
| 264 | using AssignerType = |
| 265 | std::add_pointer_t<decltype(MakeInterface<int>::assign)>; |
| 266 | using SerializerType = |
| 267 | std::add_pointer_t<decltype(MakeInterface<int>::serialize)>; |
| 268 | using DeserializerType = |
| 269 | std::add_pointer_t<decltype(MakeInterface<int>::deserialize)>; |
| 270 | using Makers = |
| 271 | std::map<std::string, std::tuple<MakerType, AssignerType, |
| 272 | SerializerType, DeserializerType>>; |
Brad Bishop | 49aefb3 | 2016-10-19 11:54:14 -0400 | [diff] [blame] | 273 | |
Brad Bishop | 615b2a8 | 2018-03-29 10:32:41 -0400 | [diff] [blame] | 274 | /** @brief Provides weak references to interface holders. |
| 275 | * |
| 276 | * Common code for all types for the templated getInterface |
| 277 | * methods. |
| 278 | * |
| 279 | * @param[in] path - The DBus path for which the interface |
| 280 | * holder instance should be provided. |
| 281 | * @param[in] interface - The DBus interface for which the |
| 282 | * holder instance should be provided. |
| 283 | * |
| 284 | * @returns A weak reference to the holder instance. |
| 285 | */ |
Brad Bishop | 25d54b5 | 2018-11-21 12:57:51 -0500 | [diff] [blame] | 286 | const std::any& getInterfaceHolder(const char*, const char*) const; |
| 287 | std::any& getInterfaceHolder(const char*, const char*); |
Brad Bishop | b83a21e | 2016-11-30 13:43:37 -0500 | [diff] [blame] | 288 | |
Brad Bishop | 615b2a8 | 2018-03-29 10:32:41 -0400 | [diff] [blame] | 289 | /** @brief Provides weak references to interface holders. |
| 290 | * |
| 291 | * @tparam T - The sdbusplus server binding interface type. |
| 292 | * |
| 293 | * @param[in] path - The DBus path for which the interface |
| 294 | * should be provided. |
| 295 | * @param[in] interface - The DBus interface to obtain. |
| 296 | * |
| 297 | * @returns A weak reference to the interface holder. |
| 298 | */ |
| 299 | template <typename T> |
| 300 | auto& getInterface(const char* path, const char* interface) |
| 301 | { |
| 302 | auto& holder = getInterfaceHolder(path, interface); |
Brad Bishop | 25d54b5 | 2018-11-21 12:57:51 -0500 | [diff] [blame] | 303 | return *std::any_cast<std::shared_ptr<T>&>(holder); |
Brad Bishop | 615b2a8 | 2018-03-29 10:32:41 -0400 | [diff] [blame] | 304 | } |
| 305 | template <typename T> |
| 306 | auto& getInterface(const char* path, const char* interface) const |
| 307 | { |
| 308 | auto& holder = getInterfaceHolder(path, interface); |
Brad Bishop | 25d54b5 | 2018-11-21 12:57:51 -0500 | [diff] [blame] | 309 | return *std::any_cast<T>(holder); |
Brad Bishop | 615b2a8 | 2018-03-29 10:32:41 -0400 | [diff] [blame] | 310 | } |
Brad Bishop | b83a21e | 2016-11-30 13:43:37 -0500 | [diff] [blame] | 311 | |
Brad Bishop | 615b2a8 | 2018-03-29 10:32:41 -0400 | [diff] [blame] | 312 | /** @brief Add or update interfaces on DBus. */ |
| 313 | void updateInterfaces(const sdbusplus::message::object_path& path, |
| 314 | const Object& interfaces, |
| 315 | ObjectReferences::iterator pos, |
| 316 | bool emitSignals = true, |
| 317 | bool restoreFromCache = false); |
Brad Bishop | 79ccaf7 | 2017-01-22 16:00:50 -0500 | [diff] [blame] | 318 | |
Brad Bishop | 615b2a8 | 2018-03-29 10:32:41 -0400 | [diff] [blame] | 319 | /** @brief Provided for testing only. */ |
| 320 | volatile bool _shutdown; |
Brad Bishop | 49aefb3 | 2016-10-19 11:54:14 -0400 | [diff] [blame] | 321 | |
Brad Bishop | 615b2a8 | 2018-03-29 10:32:41 -0400 | [diff] [blame] | 322 | /** @brief Path prefix applied to any relative paths. */ |
| 323 | const char* _root; |
Brad Bishop | 49aefb3 | 2016-10-19 11:54:14 -0400 | [diff] [blame] | 324 | |
Brad Bishop | 615b2a8 | 2018-03-29 10:32:41 -0400 | [diff] [blame] | 325 | /** @brief A container of sdbusplus server interface references. */ |
| 326 | ObjectReferences _refs; |
Brad Bishop | 49aefb3 | 2016-10-19 11:54:14 -0400 | [diff] [blame] | 327 | |
Brad Bishop | 615b2a8 | 2018-03-29 10:32:41 -0400 | [diff] [blame] | 328 | /** @brief A container contexts for signal callbacks. */ |
| 329 | SigArgs _sigargs; |
Brad Bishop | 49aefb3 | 2016-10-19 11:54:14 -0400 | [diff] [blame] | 330 | |
Brad Bishop | 615b2a8 | 2018-03-29 10:32:41 -0400 | [diff] [blame] | 331 | /** @brief A container of sdbusplus signal matches. */ |
| 332 | std::vector<sdbusplus::bus::match_t> _matches; |
Brad Bishop | 49aefb3 | 2016-10-19 11:54:14 -0400 | [diff] [blame] | 333 | |
Brad Bishop | 615b2a8 | 2018-03-29 10:32:41 -0400 | [diff] [blame] | 334 | /** @brief Persistent sdbusplus DBus bus connection. */ |
| 335 | sdbusplus::bus::bus _bus; |
Brad Bishop | 49aefb3 | 2016-10-19 11:54:14 -0400 | [diff] [blame] | 336 | |
Brad Bishop | 615b2a8 | 2018-03-29 10:32:41 -0400 | [diff] [blame] | 337 | /** @brief sdbusplus org.freedesktop.DBus.ObjectManager reference. */ |
| 338 | sdbusplus::server::manager::manager _manager; |
Brad Bishop | 49aefb3 | 2016-10-19 11:54:14 -0400 | [diff] [blame] | 339 | |
Brad Bishop | 615b2a8 | 2018-03-29 10:32:41 -0400 | [diff] [blame] | 340 | /** @brief A container of pimgen generated events and responses. */ |
| 341 | static const Events _events; |
Brad Bishop | 5fbaa7f | 2016-10-31 10:42:41 -0500 | [diff] [blame] | 342 | |
Brad Bishop | 615b2a8 | 2018-03-29 10:32:41 -0400 | [diff] [blame] | 343 | /** @brief A container of pimgen generated factory methods. */ |
| 344 | static const Makers _makers; |
Brad Bishop | 49aefb3 | 2016-10-19 11:54:14 -0400 | [diff] [blame] | 345 | }; |
| 346 | |
| 347 | } // namespace manager |
| 348 | } // namespace inventory |
| 349 | } // namespace phosphor |
| 350 | |
| 351 | // vim: tabstop=8 expandtab shiftwidth=4 softtabstop=4 |