Matthew Barth | b86374d | 2017-04-12 10:57:19 -0500 | [diff] [blame] | 1 | #pragma once |
| 2 | |
Patrick Venture | 3d6d318 | 2018-08-31 09:33:09 -0700 | [diff] [blame] | 3 | #include "tupleref.hpp" |
| 4 | |
Matthew Barth | b86374d | 2017-04-12 10:57:19 -0500 | [diff] [blame] | 5 | #include <sdbusplus/message.hpp> |
Paul Fertser | 74dc24a | 2022-01-10 11:28:20 +0000 | [diff] [blame] | 6 | #include <sdbusplus/utility/merge_variants.hpp> |
Paul Fertser | 74dc24a | 2022-01-10 11:28:20 +0000 | [diff] [blame] | 7 | #include <xyz/openbmc_project/Association/Definitions/server.hpp> |
| 8 | #include <xyz/openbmc_project/Logging/Entry/server.hpp> |
| 9 | #include <xyz/openbmc_project/Software/Version/server.hpp> |
Brad Bishop | 186aa67 | 2017-05-15 22:27:57 -0400 | [diff] [blame] | 10 | |
George Liu | 3fe976c | 2022-06-21 09:37:04 +0800 | [diff] [blame] | 11 | #include <any> |
| 12 | |
Matthew Barth | b86374d | 2017-04-12 10:57:19 -0500 | [diff] [blame] | 13 | namespace phosphor |
| 14 | { |
| 15 | namespace dbus |
| 16 | { |
| 17 | namespace monitoring |
| 18 | { |
| 19 | |
Matt Spinler | df1b7cf | 2017-10-31 14:17:23 -0500 | [diff] [blame] | 20 | constexpr auto MAPPER_BUSNAME = "xyz.openbmc_project.ObjectMapper"; |
| 21 | constexpr auto MAPPER_PATH = "/xyz/openbmc_project/object_mapper"; |
| 22 | constexpr auto MAPPER_INTERFACE = "xyz.openbmc_project.ObjectMapper"; |
Matt Spinler | 1abcb06 | 2018-02-26 09:14:31 -0600 | [diff] [blame] | 23 | |
Brad Bishop | d1eac88 | 2018-03-29 10:34:05 -0400 | [diff] [blame] | 24 | // PropertyIndex::key_type fields |
Ratan Gupta | 90bfaea | 2017-10-06 20:56:31 +0530 | [diff] [blame] | 25 | constexpr auto pathIndex = 0; |
Matt Spinler | 1abcb06 | 2018-02-26 09:14:31 -0600 | [diff] [blame] | 26 | constexpr auto interfaceIndex = 1; |
Ratan Gupta | 90bfaea | 2017-10-06 20:56:31 +0530 | [diff] [blame] | 27 | constexpr auto propertyIndex = 2; |
Matt Spinler | 1abcb06 | 2018-02-26 09:14:31 -0600 | [diff] [blame] | 28 | |
Brad Bishop | d1eac88 | 2018-03-29 10:34:05 -0400 | [diff] [blame] | 29 | // PropertyIndex::mapped_type fields |
Matt Spinler | 1abcb06 | 2018-02-26 09:14:31 -0600 | [diff] [blame] | 30 | constexpr auto pathMetaIndex = 0; |
| 31 | constexpr auto propertyMetaIndex = 1; |
Matt Spinler | abe43ab | 2018-02-19 13:34:43 -0600 | [diff] [blame] | 32 | constexpr auto storageIndex = 2; |
Matt Spinler | 1abcb06 | 2018-02-26 09:14:31 -0600 | [diff] [blame] | 33 | |
Brad Bishop | d1eac88 | 2018-03-29 10:34:05 -0400 | [diff] [blame] | 34 | // ConfigPropertyStorage fields |
Matt Spinler | abe43ab | 2018-02-19 13:34:43 -0600 | [diff] [blame] | 35 | constexpr auto valueIndex = 0; |
Matt Spinler | 1abcb06 | 2018-02-26 09:14:31 -0600 | [diff] [blame] | 36 | constexpr auto resultIndex = 1; |
Matt Spinler | df1b7cf | 2017-10-31 14:17:23 -0500 | [diff] [blame] | 37 | |
Ratan Gupta | a45e086 | 2018-02-21 19:03:13 +0530 | [diff] [blame] | 38 | enum class Context |
| 39 | { |
| 40 | START, |
| 41 | SIGNAL, |
| 42 | }; |
| 43 | |
Brad Bishop | 186aa67 | 2017-05-15 22:27:57 -0400 | [diff] [blame] | 44 | /** @brief A map with references as keys. */ |
| 45 | template <typename Key, typename Value> |
| 46 | using RefKeyMap = std::map<std::reference_wrapper<Key>, Value, std::less<Key>>; |
| 47 | |
| 48 | /** @brief A map with a tuple of references as keys. */ |
Brad Bishop | d1eac88 | 2018-03-29 10:34:05 -0400 | [diff] [blame] | 49 | template <typename Value, typename... Keys> |
Brad Bishop | 186aa67 | 2017-05-15 22:27:57 -0400 | [diff] [blame] | 50 | using TupleRefMap = std::map<TupleOfRefs<Keys...>, Value, TupleOfRefsLess>; |
| 51 | |
| 52 | /** @brief A vector of references. */ |
Patrick Venture | 3d6d318 | 2018-08-31 09:33:09 -0700 | [diff] [blame] | 53 | template <typename T> |
| 54 | using RefVector = std::vector<std::reference_wrapper<T>>; |
Brad Bishop | 186aa67 | 2017-05-15 22:27:57 -0400 | [diff] [blame] | 55 | |
| 56 | /** @brief |
| 57 | * |
| 58 | * The mapper has a defect such that it provides strings |
| 59 | * rather than object paths. Use an alias for easy refactoring |
| 60 | * when the mapper is fixed. |
| 61 | */ |
| 62 | using MapperPath = std::string; |
| 63 | |
| 64 | /** @brief ObjectManager.InterfacesAdded signal signature alias. */ |
| 65 | template <typename T> |
Brad Bishop | d1eac88 | 2018-03-29 10:34:05 -0400 | [diff] [blame] | 66 | using InterfacesAdded = |
Patrick Williams | 35b4f33 | 2020-05-13 17:53:09 -0500 | [diff] [blame] | 67 | std::map<std::string, std::map<std::string, std::variant<T>>>; |
Paul Fertser | 74dc24a | 2022-01-10 11:28:20 +0000 | [diff] [blame] | 68 | using Value = sdbusplus::utility::merge_variants_t< |
| 69 | sdbusplus::xyz::openbmc_project::Association::server::Definitions:: |
| 70 | PropertiesVariant, |
| 71 | sdbusplus::xyz::openbmc_project::Logging::server::Entry::PropertiesVariant, |
| 72 | sdbusplus::xyz::openbmc_project::Software::server::Version:: |
| 73 | PropertiesVariant>; |
Marri Devender Rao | 70aafbb | 2018-04-12 01:11:48 -0500 | [diff] [blame] | 74 | /** @brief ObjectManager.InterfacesAdded signal signature alias. */ |
| 75 | using Interface = std::string; |
| 76 | using Property = std::string; |
| 77 | using PathInterfacesAdded = std::map<Interface, std::map<Property, Value>>; |
Brad Bishop | 186aa67 | 2017-05-15 22:27:57 -0400 | [diff] [blame] | 78 | |
| 79 | /** @brief ObjectMapper.GetObject response signature alias. */ |
| 80 | using GetObject = std::map<MapperPath, std::vector<std::string>>; |
| 81 | |
| 82 | /** @brief Properties.GetAll response signature alias. */ |
| 83 | template <typename T> |
Patrick Williams | 35b4f33 | 2020-05-13 17:53:09 -0500 | [diff] [blame] | 84 | using PropertiesChanged = std::map<std::string, std::variant<T>>; |
Brad Bishop | 186aa67 | 2017-05-15 22:27:57 -0400 | [diff] [blame] | 85 | |
Brad Bishop | 4b916f1 | 2017-05-23 18:06:38 -0400 | [diff] [blame] | 86 | /** @brief Lookup index for properties . */ |
| 87 | // *INDENT-OFF* |
Brad Bishop | d1eac88 | 2018-03-29 10:34:05 -0400 | [diff] [blame] | 88 | using PropertyIndex = |
| 89 | TupleRefMap<TupleOfRefs<const std::string, const std::string, |
Patrick Williams | 26dc0bc | 2022-06-16 17:06:18 -0500 | [diff] [blame] | 90 | std::tuple<std::any, std::any>>, |
Brad Bishop | d1eac88 | 2018-03-29 10:34:05 -0400 | [diff] [blame] | 91 | const std::string, const std::string, const std::string>; |
Brad Bishop | 4b916f1 | 2017-05-23 18:06:38 -0400 | [diff] [blame] | 92 | // *INDENT-ON* |
Brad Bishop | 893b348 | 2017-05-23 18:17:25 -0400 | [diff] [blame] | 93 | |
| 94 | /** @brief Convert some C++ types to others. |
| 95 | * |
| 96 | * Remove type decorators to reduce template specializations. |
| 97 | * |
| 98 | * 1. Remove references. |
| 99 | * 2. Remove 'const' and 'volatile'. |
| 100 | */ |
Patrick Venture | 3d6d318 | 2018-08-31 09:33:09 -0700 | [diff] [blame] | 101 | template <typename T> |
| 102 | struct Downcast |
Brad Bishop | 893b348 | 2017-05-23 18:17:25 -0400 | [diff] [blame] | 103 | { |
| 104 | using Type = std::remove_cv_t<std::remove_reference_t<T>>; |
| 105 | }; |
Patrick Venture | 3d6d318 | 2018-08-31 09:33:09 -0700 | [diff] [blame] | 106 | template <typename T> |
| 107 | using DowncastType = typename Downcast<T>::Type; |
Brad Bishop | 893b348 | 2017-05-23 18:17:25 -0400 | [diff] [blame] | 108 | |
Matthew Barth | b86374d | 2017-04-12 10:57:19 -0500 | [diff] [blame] | 109 | } // namespace monitoring |
| 110 | } // namespace dbus |
| 111 | } // namespace phosphor |