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