blob: 731e7e877e2d9f73778a33b90fa0e571e5c99f7f [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
Matthew Barthb86374d2017-04-12 10:57:19 -05005#include <sdbusplus/message.hpp>
Paul Fertser74dc24a2022-01-10 11:28:20 +00006#include <sdbusplus/utility/merge_variants.hpp>
Paul Fertser74dc24a2022-01-10 11:28:20 +00007#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>
Brad Bishop186aa672017-05-15 22:27:57 -040010
George Liu3fe976c2022-06-21 09:37:04 +080011#include <any>
12
Matthew Barthb86374d2017-04-12 10:57:19 -050013namespace phosphor
14{
15namespace dbus
16{
17namespace monitoring
18{
19
Matt Spinlerdf1b7cf2017-10-31 14:17:23 -050020constexpr auto MAPPER_BUSNAME = "xyz.openbmc_project.ObjectMapper";
21constexpr auto MAPPER_PATH = "/xyz/openbmc_project/object_mapper";
22constexpr auto MAPPER_INTERFACE = "xyz.openbmc_project.ObjectMapper";
Matt Spinler1abcb062018-02-26 09:14:31 -060023
Brad Bishopd1eac882018-03-29 10:34:05 -040024// PropertyIndex::key_type fields
Ratan Gupta90bfaea2017-10-06 20:56:31 +053025constexpr auto pathIndex = 0;
Matt Spinler1abcb062018-02-26 09:14:31 -060026constexpr auto interfaceIndex = 1;
Ratan Gupta90bfaea2017-10-06 20:56:31 +053027constexpr auto propertyIndex = 2;
Matt Spinler1abcb062018-02-26 09:14:31 -060028
Brad Bishopd1eac882018-03-29 10:34:05 -040029// PropertyIndex::mapped_type fields
Matt Spinler1abcb062018-02-26 09:14:31 -060030constexpr auto pathMetaIndex = 0;
31constexpr auto propertyMetaIndex = 1;
Matt Spinlerabe43ab2018-02-19 13:34:43 -060032constexpr auto storageIndex = 2;
Matt Spinler1abcb062018-02-26 09:14:31 -060033
Brad Bishopd1eac882018-03-29 10:34:05 -040034// ConfigPropertyStorage fields
Matt Spinlerabe43ab2018-02-19 13:34:43 -060035constexpr auto valueIndex = 0;
Matt Spinler1abcb062018-02-26 09:14:31 -060036constexpr auto resultIndex = 1;
Matt Spinlerdf1b7cf2017-10-31 14:17:23 -050037
Ratan Guptaa45e0862018-02-21 19:03:13 +053038enum class Context
39{
40 START,
41 SIGNAL,
42};
43
Brad Bishop186aa672017-05-15 22:27:57 -040044/** @brief A map with references as keys. */
45template <typename Key, typename Value>
46using RefKeyMap = std::map<std::reference_wrapper<Key>, Value, std::less<Key>>;
47
48/** @brief A map with a tuple of references as keys. */
Brad Bishopd1eac882018-03-29 10:34:05 -040049template <typename Value, typename... Keys>
Brad Bishop186aa672017-05-15 22:27:57 -040050using TupleRefMap = std::map<TupleOfRefs<Keys...>, Value, TupleOfRefsLess>;
51
52/** @brief A vector of references. */
Patrick Venture3d6d3182018-08-31 09:33:09 -070053template <typename T>
54using RefVector = std::vector<std::reference_wrapper<T>>;
Brad Bishop186aa672017-05-15 22:27:57 -040055
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 */
62using MapperPath = std::string;
63
64/** @brief ObjectManager.InterfacesAdded signal signature alias. */
65template <typename T>
Brad Bishopd1eac882018-03-29 10:34:05 -040066using InterfacesAdded =
Patrick Williams35b4f332020-05-13 17:53:09 -050067 std::map<std::string, std::map<std::string, std::variant<T>>>;
Paul Fertser74dc24a2022-01-10 11:28:20 +000068using 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>;
Marri Devender Rao70aafbb2018-04-12 01:11:48 -050074/** @brief ObjectManager.InterfacesAdded signal signature alias. */
75using Interface = std::string;
76using Property = std::string;
77using PathInterfacesAdded = std::map<Interface, std::map<Property, Value>>;
Brad Bishop186aa672017-05-15 22:27:57 -040078
79/** @brief ObjectMapper.GetObject response signature alias. */
80using GetObject = std::map<MapperPath, std::vector<std::string>>;
81
82/** @brief Properties.GetAll response signature alias. */
83template <typename T>
Patrick Williams35b4f332020-05-13 17:53:09 -050084using PropertiesChanged = std::map<std::string, std::variant<T>>;
Brad Bishop186aa672017-05-15 22:27:57 -040085
Brad Bishop4b916f12017-05-23 18:06:38 -040086/** @brief Lookup index for properties . */
87// *INDENT-OFF*
Brad Bishopd1eac882018-03-29 10:34:05 -040088using PropertyIndex =
89 TupleRefMap<TupleOfRefs<const std::string, const std::string,
Patrick Williams26dc0bc2022-06-16 17:06:18 -050090 std::tuple<std::any, std::any>>,
Brad Bishopd1eac882018-03-29 10:34:05 -040091 const std::string, const std::string, const std::string>;
Brad Bishop4b916f12017-05-23 18:06:38 -040092// *INDENT-ON*
Brad Bishop893b3482017-05-23 18:17:25 -040093
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 */
Patrick Venture3d6d3182018-08-31 09:33:09 -0700101template <typename T>
102struct Downcast
Brad Bishop893b3482017-05-23 18:17:25 -0400103{
104 using Type = std::remove_cv_t<std::remove_reference_t<T>>;
105};
Patrick Venture3d6d3182018-08-31 09:33:09 -0700106template <typename T>
107using DowncastType = typename Downcast<T>::Type;
Brad Bishop893b3482017-05-23 18:17:25 -0400108
Matthew Barthb86374d2017-04-12 10:57:19 -0500109} // namespace monitoring
110} // namespace dbus
111} // namespace phosphor