summaryrefslogtreecommitdiffstats
path: root/filters.hpp
diff options
context:
space:
mode:
authorBrad Bishop <bradleyb@fuzziesquirrel.com>2016-11-29 13:09:01 -0500
committerBrad Bishop <bradleyb@fuzziesquirrel.com>2016-12-15 10:55:38 -0500
commit67b788dcbdd960d665e632b4a97e5dea0c97f456 (patch)
tree7c461f00d90a1a451cff6977c851affadd9cf5f7 /filters.hpp
parent9007432a86723dd6542dc3ee1289598537d916e1 (diff)
downloadphosphor-inventory-manager-67b788dcbdd960d665e632b4a97e5dea0c97f456.tar.gz
phosphor-inventory-manager-67b788dcbdd960d665e632b4a97e5dea0c97f456.zip
Move filters.hpp to events.hpp
Prepare for a more generalized event description framework enabling event classes other than DBus signal matches. Filters become a sub-concept within that framework so rename the file. Change-Id: I0be9f9997239aad6e798ca16055aedc3e1233994 Signed-off-by: Brad Bishop <bradleyb@fuzziesquirrel.com>
Diffstat (limited to 'filters.hpp')
-rw-r--r--filters.hpp126
1 files changed, 0 insertions, 126 deletions
diff --git a/filters.hpp b/filters.hpp
deleted file mode 100644
index e2a87e3..0000000
--- a/filters.hpp
+++ /dev/null
@@ -1,126 +0,0 @@
-#pragma once
-
-#include <utility>
-#include <memory>
-#include <sdbusplus/message.hpp>
-#include "utils.hpp"
-
-namespace phosphor
-{
-namespace inventory
-{
-namespace manager
-{
-
-class Manager;
-namespace details
-{
-using FilterBase = holder::CallableBase<
- bool, sdbusplus::message::message&, Manager&>;
-using FilterBasePtr = std::shared_ptr<FilterBase>;
-template <typename T>
-using Filter = holder::CallableHolder<
- T, bool, sdbusplus::message::message&, Manager&>;
-
-/** @brief make_filter
- *
- * Adapt a filter function object.
- *
- * @param[in] filter - The filter being adapted.
- * @returns - The adapted filter.
- *
- * @tparam T - The type of the filter being adapted.
- */
-template <typename T>
-auto make_filter(T&& filter)
-{
- return Filter<T>::template make_shared<Filter<T>>(
- std::forward<T>(filter));
-}
-} // namespace details
-
-namespace filters
-{
-namespace details
-{
-namespace property_condition
-{
-
-/** @struct PropertyCondition
- * @brief Match filter functor that tests a property value.
- *
- * @tparam T - The type of the property being tested.
- * @tparam U - The type of the condition checking functor.
- */
-template <typename T, typename U>
-struct PropertyCondition
-{
- PropertyCondition() = delete;
- ~PropertyCondition() = default;
- PropertyCondition(const PropertyCondition&) = default;
- PropertyCondition & operator=(const PropertyCondition&) = delete;
- PropertyCondition(PropertyCondition&&) = default;
- PropertyCondition& operator=(PropertyCondition&&) = default;
- PropertyCondition(const char *iface, const char *property, U &&condition) :
- _iface(iface),
- _property(property),
- _condition(std::forward<U>(condition)) { }
-
- /** @brief Test a property value.
- *
- * Extract the property from the PropertiesChanged
- * message and run the condition test.
- */
- bool operator()(sdbusplus::message::message &msg, Manager &) const
- {
- std::map<
- std::string,
- sdbusplus::message::variant<T>> properties;
- const char *iface = nullptr;
-
- msg.read(iface);
- if(strcmp(iface, _iface))
- return false;
-
- msg.read(properties);
- auto it = properties.find(_property);
- if(it == properties.cend())
- return false;
-
- return _condition(it->second);
- }
-
- private:
- const char *_iface;
- const char *_property;
- U _condition;
-};
-
-} // namespace property_condition
-} // namespace details
-
-/** @brief The default filter. */
-inline bool none(sdbusplus::message::message &, Manager &) noexcept
-{
- return true;
-}
-
-/** @brief Implicit type deduction for constructing PropertyCondition. */
-template <typename T>
-auto propertyChangedTo(
- const char *iface,
- const char *property,
- T val)
-{
- auto condition = [val = std::move(val)](auto arg){return arg == val;};
- using U = decltype(condition);
- return details::property_condition::PropertyCondition<T, U>(
- iface, property, std::move(condition));
-}
-
-} // namespace filters
-} // namespace manager
-} // namespace inventory
-} // namespace phosphor
-
-// vim: tabstop=8 expandtab shiftwidth=4 softtabstop=4
OpenPOWER on IntegriCloud