blob: 81bb8cb902ca69ad6bbf042693cca221c1a7a8b9 [file] [log] [blame]
Matthew Barthb86374d2017-04-12 10:57:19 -05001#pragma once
2
Patrick Venture3d6d3182018-08-31 09:33:09 -07003#include "tupleref.hpp"
4
Brad Bishop186aa672017-05-15 22:27:57 -04005#include <experimental/any>
Matthew Barthb86374d2017-04-12 10:57:19 -05006#include <sdbusplus/message.hpp>
Andrew Geisslerae4c95c2020-05-16 13:58:53 -05007#include <string>
Brad Bishop186aa672017-05-15 22:27:57 -04008
9namespace any_ns = std::experimental;
Matthew Barthb86374d2017-04-12 10:57:19 -050010
11namespace phosphor
12{
13namespace dbus
14{
15namespace monitoring
16{
17
Matt Spinlerdf1b7cf2017-10-31 14:17:23 -050018constexpr auto MAPPER_BUSNAME = "xyz.openbmc_project.ObjectMapper";
19constexpr auto MAPPER_PATH = "/xyz/openbmc_project/object_mapper";
20constexpr auto MAPPER_INTERFACE = "xyz.openbmc_project.ObjectMapper";
Matt Spinler1abcb062018-02-26 09:14:31 -060021
Brad Bishopd1eac882018-03-29 10:34:05 -040022// PropertyIndex::key_type fields
Ratan Gupta90bfaea2017-10-06 20:56:31 +053023constexpr auto pathIndex = 0;
Matt Spinler1abcb062018-02-26 09:14:31 -060024constexpr auto interfaceIndex = 1;
Ratan Gupta90bfaea2017-10-06 20:56:31 +053025constexpr auto propertyIndex = 2;
Matt Spinler1abcb062018-02-26 09:14:31 -060026
Brad Bishopd1eac882018-03-29 10:34:05 -040027// PropertyIndex::mapped_type fields
Matt Spinler1abcb062018-02-26 09:14:31 -060028constexpr auto pathMetaIndex = 0;
29constexpr auto propertyMetaIndex = 1;
Matt Spinlerabe43ab2018-02-19 13:34:43 -060030constexpr auto storageIndex = 2;
Matt Spinler1abcb062018-02-26 09:14:31 -060031
Brad Bishopd1eac882018-03-29 10:34:05 -040032// ConfigPropertyStorage fields
Matt Spinlerabe43ab2018-02-19 13:34:43 -060033constexpr auto valueIndex = 0;
Matt Spinler1abcb062018-02-26 09:14:31 -060034constexpr auto resultIndex = 1;
Matt Spinlerdf1b7cf2017-10-31 14:17:23 -050035
Ratan Guptaa45e0862018-02-21 19:03:13 +053036enum class Context
37{
38 START,
39 SIGNAL,
40};
41
Brad Bishop186aa672017-05-15 22:27:57 -040042/** @brief A map with references as keys. */
43template <typename Key, typename Value>
44using RefKeyMap = std::map<std::reference_wrapper<Key>, Value, std::less<Key>>;
45
46/** @brief A map with a tuple of references as keys. */
Brad Bishopd1eac882018-03-29 10:34:05 -040047template <typename Value, typename... Keys>
Brad Bishop186aa672017-05-15 22:27:57 -040048using TupleRefMap = std::map<TupleOfRefs<Keys...>, Value, TupleOfRefsLess>;
49
50/** @brief A vector of references. */
Patrick Venture3d6d3182018-08-31 09:33:09 -070051template <typename T>
52using RefVector = std::vector<std::reference_wrapper<T>>;
Brad Bishop186aa672017-05-15 22:27:57 -040053
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 */
60using MapperPath = std::string;
61
62/** @brief ObjectManager.InterfacesAdded signal signature alias. */
63template <typename T>
Brad Bishopd1eac882018-03-29 10:34:05 -040064using InterfacesAdded =
Patrick Williams35b4f332020-05-13 17:53:09 -050065 std::map<std::string, std::map<std::string, std::variant<T>>>;
66using Value = std::variant<bool, uint8_t, int16_t, uint16_t, int32_t, uint32_t,
67 int64_t, uint64_t, std::string>;
Marri Devender Rao70aafbb2018-04-12 01:11:48 -050068
69/** @brief ObjectManager.InterfacesAdded signal signature alias. */
70using Interface = std::string;
71using Property = std::string;
72using PathInterfacesAdded = std::map<Interface, std::map<Property, Value>>;
Brad Bishop186aa672017-05-15 22:27:57 -040073
74/** @brief ObjectMapper.GetObject response signature alias. */
75using GetObject = std::map<MapperPath, std::vector<std::string>>;
76
77/** @brief Properties.GetAll response signature alias. */
78template <typename T>
Patrick Williams35b4f332020-05-13 17:53:09 -050079using PropertiesChanged = std::map<std::string, std::variant<T>>;
Brad Bishop186aa672017-05-15 22:27:57 -040080
Brad Bishop4b916f12017-05-23 18:06:38 -040081/** @brief Lookup index for properties . */
82// *INDENT-OFF*
Brad Bishopd1eac882018-03-29 10:34:05 -040083using 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 Bishop4b916f12017-05-23 18:06:38 -040087// *INDENT-ON*
Brad Bishop893b3482017-05-23 18:17:25 -040088
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 Venture3d6d3182018-08-31 09:33:09 -070096template <typename T>
97struct Downcast
Brad Bishop893b3482017-05-23 18:17:25 -040098{
99 using Type = std::remove_cv_t<std::remove_reference_t<T>>;
100};
Patrick Venture3d6d3182018-08-31 09:33:09 -0700101template <typename T>
102using DowncastType = typename Downcast<T>::Type;
Brad Bishop893b3482017-05-23 18:17:25 -0400103
Matthew Barthb86374d2017-04-12 10:57:19 -0500104} // namespace monitoring
105} // namespace dbus
106} // namespace phosphor