summaryrefslogtreecommitdiffstats
path: root/src
diff options
context:
space:
mode:
authorBrad Bishop <bradleyb@fuzziesquirrel.com>2017-05-15 22:27:57 -0400
committerBrad Bishop <bradleyb@fuzziesquirrel.com>2017-05-23 18:56:57 -0400
commit186aa674239777bfba4d4fdf0b5974f40aaff081 (patch)
treee4be81e6a87a10b2c247ac0d3afb0a6a095bddd9 /src
parent83c4349e79252f476912d0305ac0e33828d6d54f (diff)
downloadphosphor-dbus-monitor-186aa674239777bfba4d4fdf0b5974f40aaff081.tar.gz
phosphor-dbus-monitor-186aa674239777bfba4d4fdf0b5974f40aaff081.zip
Add C++ type aliases
Add convenience type aliases for working with references: RefKeyMap: A map with references as keys. TupleRefMap: A map with a tuple of references as keys. RefVector: A vector or references. TupleOfRefs: A tuple of references. Add DBus related convenience type aliases: MapperPath: The Phosphor mapper currently uses a std::string for object paths. This is a bug and will someday be switched to sdbusplus::message::object_path. Add an alias for easy refactoring. InterfacesAdded: The C++ type for the org.freedesktop.DBus.ObjectManager.InterfacesAdded signal argument. PropertiesChanged: The C++ type for the org.freedesktop.DBus.Properties.PropertiesChanged signal argument. GetObject: The C++ type for the xyz.openbmc_project.ObjectMapper.GetMethod method response. Change-Id: I719aa7c610b3312ce8e52825cb07b33a348bf896 Signed-off-by: Brad Bishop <bradleyb@fuzziesquirrel.com>
Diffstat (limited to 'src')
-rw-r--r--src/data_types.hpp41
-rw-r--r--src/tupleref.hpp68
2 files changed, 109 insertions, 0 deletions
diff --git a/src/data_types.hpp b/src/data_types.hpp
index cbe6faf..653b7c3 100644
--- a/src/data_types.hpp
+++ b/src/data_types.hpp
@@ -1,8 +1,12 @@
#pragma once
#include <functional>
+#include <experimental/any>
#include <sdbusplus/bus.hpp>
#include <sdbusplus/message.hpp>
+#include "tupleref.hpp"
+
+namespace any_ns = std::experimental;
namespace phosphor
{
@@ -28,6 +32,43 @@ using Condition = std::function<bool(sdbusplus::bus::bus&,
using Action = std::function<void(sdbusplus::bus::bus&,
Monitor&)>;
+/** @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 >>>;
+
+/** @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 >>;
+
} // namespace monitoring
} // namespace dbus
} // namespace phosphor
diff --git a/src/tupleref.hpp b/src/tupleref.hpp
new file mode 100644
index 0000000..c6a6dcd
--- /dev/null
+++ b/src/tupleref.hpp
@@ -0,0 +1,68 @@
+#pragma once
+
+#include <tuple>
+#include <utility>
+
+namespace phosphor
+{
+namespace dbus
+{
+namespace monitoring
+{
+
+/** @brief A tuple of references. */
+template <typename... T>
+using TupleOfRefs = std::tuple<std::reference_wrapper<T>...>;
+
+namespace detail
+{
+/** @brief Less than implementation for tuples of references. */
+template <size_t size, size_t i, typename T, typename U>
+struct TupleOfRefsLess
+{
+ static constexpr bool compare(const T& l, const U& r)
+ {
+ if (std::get<i>(l).get() < std::get<i>(r).get())
+ {
+ return true;
+ }
+ if (std::get<i>(r).get() < std::get<i>(l).get())
+ {
+ return false;
+ }
+ return TupleOfRefsLess < size, i + 1, T, U >::compare(l, r);
+ }
+};
+
+/** @brief Less than specialization for tuple element sizeof...(tuple) +1. */
+template <size_t size, typename T, typename U>
+struct TupleOfRefsLess<size, size, T, U>
+{
+ static constexpr bool compare(const T& l, const U& r)
+ {
+ return false;
+ }
+};
+} // namespace detail
+
+/** @brief Less than comparison for tuples of references. */
+struct TupleOfRefsLess
+{
+ template <typename... T, typename... U>
+ constexpr bool operator()(
+ const TupleOfRefs<T...>& l,
+ const TupleOfRefs<U...>& r) const
+ {
+ static_assert(sizeof...(T) == sizeof...(U),
+ "Cannot compare tuples of different lengths.");
+ return detail::TupleOfRefsLess <
+ sizeof...(T),
+ 0,
+ TupleOfRefs<T...>,
+ TupleOfRefs<U... >>::compare(l, r);
+ }
+};
+
+} // namespace monitoring
+} // namespace dbus
+} // namespace phosphor
OpenPOWER on IntegriCloud