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