blob: 6be64314ad67b9efec5b8d346adcba6d52f9c01b [file] [log] [blame]
Matthew Barthb86374d2017-04-12 10:57:19 -05001#pragma once
2
Brad Bishop186aa672017-05-15 22:27:57 -04003#include <experimental/any>
Matthew Barthb86374d2017-04-12 10:57:19 -05004#include <sdbusplus/message.hpp>
Brad Bishop186aa672017-05-15 22:27:57 -04005#include "tupleref.hpp"
6
7namespace any_ns = std::experimental;
Matthew Barthb86374d2017-04-12 10:57:19 -05008
9namespace phosphor
10{
11namespace dbus
12{
13namespace monitoring
14{
15
Matt Spinlerdf1b7cf2017-10-31 14:17:23 -050016constexpr auto MAPPER_BUSNAME = "xyz.openbmc_project.ObjectMapper";
17constexpr auto MAPPER_PATH = "/xyz/openbmc_project/object_mapper";
18constexpr auto MAPPER_INTERFACE = "xyz.openbmc_project.ObjectMapper";
Matt Spinler1abcb062018-02-26 09:14:31 -060019
Brad Bishopd1eac882018-03-29 10:34:05 -040020// PropertyIndex::key_type fields
Ratan Gupta90bfaea2017-10-06 20:56:31 +053021constexpr auto pathIndex = 0;
Matt Spinler1abcb062018-02-26 09:14:31 -060022constexpr auto interfaceIndex = 1;
Ratan Gupta90bfaea2017-10-06 20:56:31 +053023constexpr auto propertyIndex = 2;
Matt Spinler1abcb062018-02-26 09:14:31 -060024
Brad Bishopd1eac882018-03-29 10:34:05 -040025// PropertyIndex::mapped_type fields
Matt Spinler1abcb062018-02-26 09:14:31 -060026constexpr auto pathMetaIndex = 0;
27constexpr auto propertyMetaIndex = 1;
Matt Spinlerabe43ab2018-02-19 13:34:43 -060028constexpr auto storageIndex = 2;
Matt Spinler1abcb062018-02-26 09:14:31 -060029
Brad Bishopd1eac882018-03-29 10:34:05 -040030// ConfigPropertyStorage fields
Matt Spinlerabe43ab2018-02-19 13:34:43 -060031constexpr auto valueIndex = 0;
Matt Spinler1abcb062018-02-26 09:14:31 -060032constexpr auto resultIndex = 1;
Matt Spinlerdf1b7cf2017-10-31 14:17:23 -050033
Ratan Guptaa45e0862018-02-21 19:03:13 +053034enum class Context
35{
36 START,
37 SIGNAL,
38};
39
Brad Bishop186aa672017-05-15 22:27:57 -040040/** @brief A map with references as keys. */
41template <typename Key, typename Value>
42using RefKeyMap = std::map<std::reference_wrapper<Key>, Value, std::less<Key>>;
43
44/** @brief A map with a tuple of references as keys. */
Brad Bishopd1eac882018-03-29 10:34:05 -040045template <typename Value, typename... Keys>
Brad Bishop186aa672017-05-15 22:27:57 -040046using TupleRefMap = std::map<TupleOfRefs<Keys...>, Value, TupleOfRefsLess>;
47
48/** @brief A vector of references. */
Brad Bishopd1eac882018-03-29 10:34:05 -040049template <typename T> using RefVector = std::vector<std::reference_wrapper<T>>;
Brad Bishop186aa672017-05-15 22:27:57 -040050
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 */
57using MapperPath = std::string;
58
59/** @brief ObjectManager.InterfacesAdded signal signature alias. */
60template <typename T>
Brad Bishopd1eac882018-03-29 10:34:05 -040061using InterfacesAdded =
62 std::map<std::string,
63 std::map<std::string, sdbusplus::message::variant<T>>>;
Brad Bishop186aa672017-05-15 22:27:57 -040064
65/** @brief ObjectMapper.GetObject response signature alias. */
66using GetObject = std::map<MapperPath, std::vector<std::string>>;
67
68/** @brief Properties.GetAll response signature alias. */
69template <typename T>
Brad Bishopd1eac882018-03-29 10:34:05 -040070using PropertiesChanged = std::map<std::string, sdbusplus::message::variant<T>>;
Brad Bishop186aa672017-05-15 22:27:57 -040071
Brad Bishop4b916f12017-05-23 18:06:38 -040072/** @brief Lookup index for properties . */
73// *INDENT-OFF*
Brad Bishopd1eac882018-03-29 10:34:05 -040074using PropertyIndex =
75 TupleRefMap<TupleOfRefs<const std::string, const std::string,
76 std::tuple<any_ns::any, any_ns::any>>,
77 const std::string, const std::string, const std::string>;
Brad Bishop4b916f12017-05-23 18:06:38 -040078// *INDENT-ON*
Brad Bishop893b3482017-05-23 18:17:25 -040079
80/** @brief Convert some C++ types to others.
81 *
82 * Remove type decorators to reduce template specializations.
83 *
84 * 1. Remove references.
85 * 2. Remove 'const' and 'volatile'.
86 */
87template <typename T> struct Downcast
88{
89 using Type = std::remove_cv_t<std::remove_reference_t<T>>;
90};
Brad Bishopd1eac882018-03-29 10:34:05 -040091template <typename T> using DowncastType = typename Downcast<T>::Type;
Brad Bishop893b3482017-05-23 18:17:25 -040092
Matthew Barthb86374d2017-04-12 10:57:19 -050093} // namespace monitoring
94} // namespace dbus
95} // namespace phosphor