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