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