summaryrefslogtreecommitdiffstats
path: root/src/functor.hpp
diff options
context:
space:
mode:
authorMatthew Barth <msbarth@us.ibm.com>2017-04-12 13:37:29 -0500
committerBrad Bishop <bradleyb@fuzziesquirrel.com>2017-05-15 16:57:10 -0400
commite6af23313890b82c4fca4d61ec1d2d9ff4817870 (patch)
tree09cb9f2930386c79bdea64aaeb92b3277cbf5b72 /src/functor.hpp
parent1febc28a1b9b72c805b74c28c8b505e292591fc5 (diff)
downloadphosphor-dbus-monitor-e6af23313890b82c4fca4d61ec1d2d9ff4817870.tar.gz
phosphor-dbus-monitor-e6af23313890b82c4fca4d61ec1d2d9ff4817870.zip
Add support for processing start event triggers
Process application start event triggers' list of conditions on a group and perform the defined actions. This re-uses the following structs(and their necessary functions) directly from phosphor-inventory-manager: --struct PropertyConditionBase --struct PropertyCondition Change-Id: If4090299fe887ef940320091d4d4be9f6aa7dd29 Signed-off-by: Matthew Barth <msbarth@us.ibm.com>
Diffstat (limited to 'src/functor.hpp')
-rw-r--r--src/functor.hpp115
1 files changed, 115 insertions, 0 deletions
diff --git a/src/functor.hpp b/src/functor.hpp
index 9353763..c2c586e 100644
--- a/src/functor.hpp
+++ b/src/functor.hpp
@@ -23,6 +23,121 @@ auto make_action(T&& action)
return Action(std::forward<T>(action));
}
+struct PropertyConditionBase
+{
+ PropertyConditionBase() = delete;
+ virtual ~PropertyConditionBase() = default;
+ PropertyConditionBase(const PropertyConditionBase&) = default;
+ PropertyConditionBase& operator=(const PropertyConditionBase&) = default;
+ PropertyConditionBase(PropertyConditionBase&&) = default;
+ PropertyConditionBase& operator=(PropertyConditionBase&&) = default;
+
+ /** @brief Constructor
+ *
+ * The service argument can be nullptr. If something
+ * else is provided the function will call the the
+ * service directly. If omitted, the function will
+ * look up the service in the ObjectMapper.
+ *
+ * @param path - The path of the object containing
+ * the property to be tested.
+ * @param iface - The interface hosting the property
+ * to be tested.
+ * @param property - The property to be tested.
+ * @param service - The DBus service hosting the object.
+ */
+ PropertyConditionBase(
+ const char* path,
+ const char* iface,
+ const char* property,
+ const char* service) :
+ _path(path ? path : std::string()),
+ _iface(iface),
+ _property(property),
+ _service(service) {}
+
+ /** @brief Forward comparison to type specific implementation. */
+ virtual bool eval(sdbusplus::message::message&) const = 0;
+
+ /** @brief Test a property value.
+ *
+ * Make a DBus call and test the value of any property.
+ */
+ bool operator()(
+ sdbusplus::bus::bus&,
+ sdbusplus::message::message&,
+ Monitor&) const;
+
+private:
+ std::string _path;
+ std::string _iface;
+ std::string _property;
+ const char* _service;
+};
+
+template <typename T, typename U>
+struct PropertyCondition final : public PropertyConditionBase
+{
+ PropertyCondition() = delete;
+ ~PropertyCondition() = default;
+ PropertyCondition(const PropertyCondition&) = default;
+ PropertyCondition& operator=(const PropertyCondition&) = default;
+ PropertyCondition(PropertyCondition&&) = default;
+ PropertyCondition& operator=(PropertyCondition&&) = default;
+
+ /** @brief Constructor
+ *
+ * The service argument can be nullptr. If something
+ * else is provided the function will call the the
+ * service directly. If omitted, the function will
+ * look up the service in the ObjectMapper.
+ *
+ * @param path - The path of the object containing
+ * the property to be tested.
+ * @param iface - The interface hosting the property
+ * to be tested.
+ * @param property - The property to be tested.
+ * @param condition - The test to run on the property.
+ * @param service - The DBus service hosting the object.
+ */
+ PropertyCondition(
+ const char* path,
+ const char* iface,
+ const char* property,
+ U&& condition,
+ const char* service) :
+ PropertyConditionBase(path, iface, property, service),
+ _condition(std::forward<decltype(condition)>(condition)) {}
+
+ /** @brief Test a property value.
+ *
+ * Make a DBus call and test the value of any property.
+ */
+ bool eval(sdbusplus::message::message& msg) const override
+ {
+ sdbusplus::message::variant<T> value;
+ msg.read(value);
+ return _condition(std::forward<T>(value.template get<T>()));
+ }
+
+private:
+ U _condition;
+};
+
+template <typename T, typename U>
+auto propertyStart(const char* path,
+ const char* iface,
+ const char* property,
+ U&& condition,
+ const char* service = nullptr)
+{
+ return PropertyCondition<T, U>(path,
+ iface,
+ property,
+ std::move(condition),
+ service);
+}
+
} // namespace monitoring
} // namespace dbus
} // namespace phosphor
OpenPOWER on IntegriCloud