1 #pragma once
2 
3 #include "tupleref.hpp"
4 
5 #include <sdbusplus/message.hpp>
6 #include <sdbusplus/utility/merge_variants.hpp>
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>
10 
11 #include <any>
12 
13 namespace phosphor
14 {
15 namespace dbus
16 {
17 namespace monitoring
18 {
19 
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";
23 
24 // PropertyIndex::key_type fields
25 constexpr auto pathIndex = 0;
26 constexpr auto interfaceIndex = 1;
27 constexpr auto propertyIndex = 2;
28 
29 // PropertyIndex::mapped_type fields
30 constexpr auto pathMetaIndex = 0;
31 constexpr auto propertyMetaIndex = 1;
32 constexpr auto storageIndex = 2;
33 
34 // ConfigPropertyStorage fields
35 constexpr auto valueIndex = 0;
36 constexpr auto resultIndex = 1;
37 
38 enum class Context
39 {
40     START,
41     SIGNAL,
42 };
43 
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. */
49 template <typename Value, typename... Keys>
50 using TupleRefMap = std::map<TupleOfRefs<Keys...>, Value, TupleOfRefsLess>;
51 
52 /** @brief A vector of references. */
53 template <typename T>
54 using RefVector = std::vector<std::reference_wrapper<T>>;
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>
66 using InterfacesAdded =
67     std::map<std::string, std::map<std::string, std::variant<T>>>;
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>;
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>>;
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>
84 using PropertiesChanged = std::map<std::string, std::variant<T>>;
85 
86 /** @brief Lookup index for properties . */
87 // *INDENT-OFF*
88 using PropertyIndex =
89     TupleRefMap<TupleOfRefs<const std::string, const std::string,
90                             std::tuple<std::any, std::any>>,
91                 const std::string, const std::string, const std::string>;
92 // *INDENT-ON*
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  */
101 template <typename T>
102 struct Downcast
103 {
104     using Type = std::remove_cv_t<std::remove_reference_t<T>>;
105 };
106 template <typename T>
107 using DowncastType = typename Downcast<T>::Type;
108 
109 } // namespace monitoring
110 } // namespace dbus
111 } // namespace phosphor
112