summaryrefslogtreecommitdiffstats
path: root/src/data_types.hpp
blob: cf0d69e324720bf85031984ddc88c8c5716f8175 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
#pragma once

#include <experimental/any>
#include <sdbusplus/message.hpp>
#include "tupleref.hpp"

namespace any_ns = std::experimental;

namespace phosphor
{
namespace dbus
{
namespace monitoring
{

constexpr auto MAPPER_BUSNAME = "xyz.openbmc_project.ObjectMapper";
constexpr auto MAPPER_PATH = "/xyz/openbmc_project/object_mapper";
constexpr auto MAPPER_INTERFACE = "xyz.openbmc_project.ObjectMapper";

// PropertyIndex::key_type fields
constexpr auto pathIndex = 0;
constexpr auto interfaceIndex = 1;
constexpr auto propertyIndex = 2;

// PropertyIndex::mapped_type fields
constexpr auto pathMetaIndex = 0;
constexpr auto propertyMetaIndex = 1;
constexpr auto storageIndex = 2;

// ConfigPropertyStorage fields
constexpr auto valueIndex = 0;
constexpr auto resultIndex = 1;

enum class Context
{
    START,
    SIGNAL,
};

/** @brief A map with references as keys. */
template <typename Key, typename Value>
using RefKeyMap = std::map<std::reference_wrapper<Key>, Value, std::less<Key>>;

/** @brief A map with a tuple of references as keys. */
template <typename Value, typename... Keys>
using TupleRefMap = std::map<TupleOfRefs<Keys...>, Value, TupleOfRefsLess>;

/** @brief A vector of references. */
template <typename T> using RefVector = std::vector<std::reference_wrapper<T>>;

/** @brief
 *
 *  The mapper has a defect such that it provides strings
 *  rather than object paths.  Use an alias for easy refactoring
 *  when the mapper is fixed.
 */
using MapperPath = std::string;

/** @brief ObjectManager.InterfacesAdded signal signature alias. */
template <typename T>
using InterfacesAdded =
    std::map<std::string,
             std::map<std::string, sdbusplus::message::variant<T>>>;
using Value =
    sdbusplus::message::variant<bool, uint8_t, int16_t, uint16_t, int32_t,
                                uint32_t, int64_t, uint64_t, std::string>;

/** @brief ObjectManager.InterfacesAdded signal signature alias. */
using Interface = std::string;
using Property = std::string;
using PathInterfacesAdded = std::map<Interface, std::map<Property, Value>>;

/** @brief ObjectMapper.GetObject response signature alias. */
using GetObject = std::map<MapperPath, std::vector<std::string>>;

/** @brief Properties.GetAll response signature alias. */
template <typename T>
using PropertiesChanged = std::map<std::string, sdbusplus::message::variant<T>>;

/** @brief Lookup index for properties . */
// *INDENT-OFF*
using PropertyIndex =
    TupleRefMap<TupleOfRefs<const std::string, const std::string,
                            std::tuple<any_ns::any, any_ns::any>>,
                const std::string, const std::string, const std::string>;
// *INDENT-ON*

/** @brief Convert some C++ types to others.
 *
 *  Remove type decorators to reduce template specializations.
 *
 *  1. Remove references.
 *  2. Remove 'const' and 'volatile'.
 */
template <typename T> struct Downcast
{
    using Type = std::remove_cv_t<std::remove_reference_t<T>>;
};
template <typename T> using DowncastType = typename Downcast<T>::Type;

} // namespace monitoring
} // namespace dbus
} // namespace phosphor
OpenPOWER on IntegriCloud