blob: 439045ed0e2382ba949d379aa1bbee105dfb1c5d [file] [log] [blame]
Matthew Barthb86374d2017-04-12 10:57:19 -05001#pragma once
2
3#include <functional>
Brad Bishop186aa672017-05-15 22:27:57 -04004#include <experimental/any>
Matthew Barthb86374d2017-04-12 10:57:19 -05005#include <sdbusplus/bus.hpp>
6#include <sdbusplus/message.hpp>
Brad Bishop186aa672017-05-15 22:27:57 -04007#include "tupleref.hpp"
8
9namespace any_ns = std::experimental;
Matthew Barthb86374d2017-04-12 10:57:19 -050010
11namespace phosphor
12{
13namespace dbus
14{
15namespace monitoring
16{
17
18class Monitor;
19
Matthew Barthc5736432017-04-17 12:22:50 -050020/** @brief The possible item value types */
Matthew Barthb86374d2017-04-12 10:57:19 -050021using Value = int64_t;
22
Matthew Barthc5736432017-04-17 12:22:50 -050023/** @brief A list of what constructs a unique item and its value */
Matthew Barthb86374d2017-04-12 10:57:19 -050024using Group = std::vector<std::tuple<std::string, Value>>;
25
Matthew Barthc5736432017-04-17 12:22:50 -050026/** @brief A conditional function type for item(s) conditions */
Matthew Barthb86374d2017-04-12 10:57:19 -050027using Condition = std::function<bool(sdbusplus::bus::bus&,
28 sdbusplus::message::message&,
29 Monitor&)>;
30
Matthew Barthc5736432017-04-17 12:22:50 -050031/** @brief A void function type for actions based condition(s) */
Matthew Barthb86374d2017-04-12 10:57:19 -050032using Action = std::function<void(sdbusplus::bus::bus&,
33 Monitor&)>;
34
Brad Bishop186aa672017-05-15 22:27:57 -040035/** @brief A map with references as keys. */
36template <typename Key, typename Value>
37using RefKeyMap = std::map<std::reference_wrapper<Key>, Value, std::less<Key>>;
38
39/** @brief A map with a tuple of references as keys. */
40template <typename Value, typename ...Keys>
41using TupleRefMap = std::map<TupleOfRefs<Keys...>, Value, TupleOfRefsLess>;
42
43/** @brief A vector of references. */
44template <typename T>
45using RefVector = std::vector<std::reference_wrapper<T>>;
46
47/** @brief
48 *
49 * The mapper has a defect such that it provides strings
50 * rather than object paths. Use an alias for easy refactoring
51 * when the mapper is fixed.
52 */
53using MapperPath = std::string;
54
55/** @brief ObjectManager.InterfacesAdded signal signature alias. */
56template <typename T>
57using InterfacesAdded = std::map <
58 std::string,
59 std::map <
60 std::string,
61 sdbusplus::message::variant<T >>>;
62
63/** @brief ObjectMapper.GetObject response signature alias. */
64using GetObject = std::map<MapperPath, std::vector<std::string>>;
65
66/** @brief Properties.GetAll response signature alias. */
67template <typename T>
68using PropertiesChanged = std::map <
69 std::string,
70 sdbusplus::message::variant<T >>;
71
Brad Bishop4b916f12017-05-23 18:06:38 -040072/** @brief Lookup index for properties . */
73// *INDENT-OFF*
74using PropertyIndex = TupleRefMap <
75 TupleOfRefs<
76 const std::string,
77 const std::string,
78 any_ns::any>,
79 const std::string,
80 const std::string,
81 const std::string >;
82// *INDENT-ON*
Brad Bishop893b3482017-05-23 18:17:25 -040083
84/** @brief Convert some C++ types to others.
85 *
86 * Remove type decorators to reduce template specializations.
87 *
88 * 1. Remove references.
89 * 2. Remove 'const' and 'volatile'.
90 */
91template <typename T> struct Downcast
92{
93 using Type = std::remove_cv_t<std::remove_reference_t<T>>;
94};
95template <typename T> using DowncastType =
96 typename Downcast<T>::Type;
97
Matthew Barthb86374d2017-04-12 10:57:19 -050098} // namespace monitoring
99} // namespace dbus
100} // namespace phosphor