blob: cffbd99ba5169fe93d8efb2fc71913414dd4de08 [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>
Paul Fertser74dc24a2022-01-10 11:28:20 +00007#include <sdbusplus/utility/merge_variants.hpp>
Andrew Geisslerae4c95c2020-05-16 13:58:53 -05008#include <string>
Paul Fertser74dc24a2022-01-10 11:28:20 +00009#include <xyz/openbmc_project/Association/Definitions/server.hpp>
10#include <xyz/openbmc_project/Logging/Entry/server.hpp>
11#include <xyz/openbmc_project/Software/Version/server.hpp>
Brad Bishop186aa672017-05-15 22:27:57 -040012
13namespace any_ns = std::experimental;
Matthew Barthb86374d2017-04-12 10:57:19 -050014
15namespace phosphor
16{
17namespace dbus
18{
19namespace monitoring
20{
21
Matt Spinlerdf1b7cf2017-10-31 14:17:23 -050022constexpr auto MAPPER_BUSNAME = "xyz.openbmc_project.ObjectMapper";
23constexpr auto MAPPER_PATH = "/xyz/openbmc_project/object_mapper";
24constexpr auto MAPPER_INTERFACE = "xyz.openbmc_project.ObjectMapper";
Matt Spinler1abcb062018-02-26 09:14:31 -060025
Brad Bishopd1eac882018-03-29 10:34:05 -040026// PropertyIndex::key_type fields
Ratan Gupta90bfaea2017-10-06 20:56:31 +053027constexpr auto pathIndex = 0;
Matt Spinler1abcb062018-02-26 09:14:31 -060028constexpr auto interfaceIndex = 1;
Ratan Gupta90bfaea2017-10-06 20:56:31 +053029constexpr auto propertyIndex = 2;
Matt Spinler1abcb062018-02-26 09:14:31 -060030
Brad Bishopd1eac882018-03-29 10:34:05 -040031// PropertyIndex::mapped_type fields
Matt Spinler1abcb062018-02-26 09:14:31 -060032constexpr auto pathMetaIndex = 0;
33constexpr auto propertyMetaIndex = 1;
Matt Spinlerabe43ab2018-02-19 13:34:43 -060034constexpr auto storageIndex = 2;
Matt Spinler1abcb062018-02-26 09:14:31 -060035
Brad Bishopd1eac882018-03-29 10:34:05 -040036// ConfigPropertyStorage fields
Matt Spinlerabe43ab2018-02-19 13:34:43 -060037constexpr auto valueIndex = 0;
Matt Spinler1abcb062018-02-26 09:14:31 -060038constexpr auto resultIndex = 1;
Matt Spinlerdf1b7cf2017-10-31 14:17:23 -050039
Ratan Guptaa45e0862018-02-21 19:03:13 +053040enum class Context
41{
42 START,
43 SIGNAL,
44};
45
Brad Bishop186aa672017-05-15 22:27:57 -040046/** @brief A map with references as keys. */
47template <typename Key, typename Value>
48using RefKeyMap = std::map<std::reference_wrapper<Key>, Value, std::less<Key>>;
49
50/** @brief A map with a tuple of references as keys. */
Brad Bishopd1eac882018-03-29 10:34:05 -040051template <typename Value, typename... Keys>
Brad Bishop186aa672017-05-15 22:27:57 -040052using TupleRefMap = std::map<TupleOfRefs<Keys...>, Value, TupleOfRefsLess>;
53
54/** @brief A vector of references. */
Patrick Venture3d6d3182018-08-31 09:33:09 -070055template <typename T>
56using RefVector = std::vector<std::reference_wrapper<T>>;
Brad Bishop186aa672017-05-15 22:27:57 -040057
58/** @brief
59 *
60 * The mapper has a defect such that it provides strings
61 * rather than object paths. Use an alias for easy refactoring
62 * when the mapper is fixed.
63 */
64using MapperPath = std::string;
65
66/** @brief ObjectManager.InterfacesAdded signal signature alias. */
67template <typename T>
Brad Bishopd1eac882018-03-29 10:34:05 -040068using InterfacesAdded =
Patrick Williams35b4f332020-05-13 17:53:09 -050069 std::map<std::string, std::map<std::string, std::variant<T>>>;
Paul Fertser74dc24a2022-01-10 11:28:20 +000070using Value = sdbusplus::utility::merge_variants_t<
71 sdbusplus::xyz::openbmc_project::Association::server::Definitions::
72 PropertiesVariant,
73 sdbusplus::xyz::openbmc_project::Logging::server::Entry::PropertiesVariant,
74 sdbusplus::xyz::openbmc_project::Software::server::Version::
75 PropertiesVariant>;
Marri Devender Rao70aafbb2018-04-12 01:11:48 -050076/** @brief ObjectManager.InterfacesAdded signal signature alias. */
77using Interface = std::string;
78using Property = std::string;
79using PathInterfacesAdded = std::map<Interface, std::map<Property, Value>>;
Brad Bishop186aa672017-05-15 22:27:57 -040080
81/** @brief ObjectMapper.GetObject response signature alias. */
82using GetObject = std::map<MapperPath, std::vector<std::string>>;
83
84/** @brief Properties.GetAll response signature alias. */
85template <typename T>
Patrick Williams35b4f332020-05-13 17:53:09 -050086using PropertiesChanged = std::map<std::string, std::variant<T>>;
Brad Bishop186aa672017-05-15 22:27:57 -040087
Brad Bishop4b916f12017-05-23 18:06:38 -040088/** @brief Lookup index for properties . */
89// *INDENT-OFF*
Brad Bishopd1eac882018-03-29 10:34:05 -040090using PropertyIndex =
91 TupleRefMap<TupleOfRefs<const std::string, const std::string,
92 std::tuple<any_ns::any, any_ns::any>>,
93 const std::string, const std::string, const std::string>;
Brad Bishop4b916f12017-05-23 18:06:38 -040094// *INDENT-ON*
Brad Bishop893b3482017-05-23 18:17:25 -040095
96/** @brief Convert some C++ types to others.
97 *
98 * Remove type decorators to reduce template specializations.
99 *
100 * 1. Remove references.
101 * 2. Remove 'const' and 'volatile'.
102 */
Patrick Venture3d6d3182018-08-31 09:33:09 -0700103template <typename T>
104struct Downcast
Brad Bishop893b3482017-05-23 18:17:25 -0400105{
106 using Type = std::remove_cv_t<std::remove_reference_t<T>>;
107};
Patrick Venture3d6d3182018-08-31 09:33:09 -0700108template <typename T>
109using DowncastType = typename Downcast<T>::Type;
Brad Bishop893b3482017-05-23 18:17:25 -0400110
Matthew Barthb86374d2017-04-12 10:57:19 -0500111} // namespace monitoring
112} // namespace dbus
113} // namespace phosphor