summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorBrad Bishop <bradleyb@fuzziesquirrel.com>2017-02-09 01:27:38 -0500
committerPatrick Williams <patrick@stwcx.xyz>2017-02-15 17:43:18 +0000
commitc1f4798d36e63842c97692ca1a36c0975da18c09 (patch)
tree8268892833c89fba16aa364ef129c91afb455105
parent02ca0219c1e20f4f51eba068a9a9e272a60f7385 (diff)
downloadphosphor-inventory-manager-c1f4798d36e63842c97692ca1a36c0975da18c09.tar.gz
phosphor-inventory-manager-c1f4798d36e63842c97692ca1a36c0975da18c09.zip
Merge actions.hpp and events.hpp
Move all action/filter functors to a common functor.hpp. The intent of this refactoring is to facilitate reuse of functors in more than one context. - Moved functors from actions.hpp and events.hpp to functor.hpp. - Renamed events.cpp to functor.cpp. - Moved Action/Filter types to types.hpp. - Minor namespace shuffling. - Update pimgen to render according to the new namespaces. Change-Id: I630ec1587b8a48f6dc2eac1111365035873310d9 Signed-off-by: Brad Bishop <bradleyb@fuzziesquirrel.com>
-rw-r--r--Makefile.am2
-rw-r--r--actions.hpp101
-rw-r--r--events.hpp238
-rw-r--r--functor.cpp (renamed from events.cpp)9
-rw-r--r--functor.hpp320
-rw-r--r--generated.mako.cpp1
-rw-r--r--manager.hpp2
-rwxr-xr-xpimgen.py57
-rw-r--r--types.hpp6
9 files changed, 355 insertions, 381 deletions
diff --git a/Makefile.am b/Makefile.am
index 572a994..1697e2b 100644
--- a/Makefile.am
+++ b/Makefile.am
@@ -13,8 +13,8 @@ phosphor_inventory_LDFLAGS = $(SDBUSPLUS_LIBS)
phosphor_inventory_CFLAGS = $(SDBUSPLUS_CFLAGS)
libmanagercommon_la_SOURCES = \
- events.cpp \
errors.cpp \
+ functor.cpp \
manager.cpp
libmanagercommon_la_LIBADD = $(SDBUSPLUS_LIBS) $(PHOSPHOR_DBUS_INTERFACES_LIBS)
libmanagercommon_la_CFLAGS = $(SDBUSPLUS_CFLAGS) $(PHOSPHOR_DBUS_INTERACES_CFLAGS)
diff --git a/actions.hpp b/actions.hpp
deleted file mode 100644
index 31932b2..0000000
--- a/actions.hpp
+++ /dev/null
@@ -1,101 +0,0 @@
-#pragma once
-
-#include <utility>
-#include <memory>
-#include <functional>
-#include "utils.hpp"
-#include "types.hpp"
-
-namespace phosphor
-{
-namespace inventory
-{
-namespace manager
-{
-
-class Manager;
-
-using Action = std::function<void (sdbusplus::bus::bus&, Manager&)>;
-
-/** @brief make_action
- *
- * Adapt an action function object.
- *
- * @param[in] action - The action being adapted.
- * @returns - The adapted action.
- *
- * @tparam T - The type of the action being adapted.
- */
-template <typename T>
-auto make_action(T&& action)
-{
- return Action(std::forward<T>(action));
-}
-
-namespace actions
-{
-
-/** @brief Destroy objects action. */
-inline auto destroyObjects(std::vector<const char*>&& paths)
-{
- return [ = ](auto&, auto & m)
- {
- m.destroyObjects(paths);
- };
-}
-
-/** @brief Create objects action. */
-inline auto createObjects(
- std::map<sdbusplus::message::object_path, Object>&& objs)
-{
- return [ = ](auto&, auto & m)
- {
- m.createObjects(objs);
- };
-}
-
-/** @brief Set a property action.
- *
- * Invoke the requested method with a reference to the requested
- * sdbusplus server binding interface as a parameter.
- *
- * @tparam T - The sdbusplus server binding interface type.
- * @tparam U - The type of the sdbusplus server binding member
- * function that sets the property.
- * @tparam V - The property value type.
- *
- * @param[in] paths - The DBus paths on which the property should
- * be set.
- * @param[in] iface - The DBus interface hosting the property.
- * @param[in] member - Pointer to sdbusplus server binding member.
- * @param[in] value - The value the property should be set to.
- *
- * @returns - A function object that sets the requested property
- * to the requested value.
- */
-template <typename T, typename U, typename V>
-auto setProperty(
- std::vector<const char*>&& paths, const char* iface,
- U&& member, V&& value)
-{
- // The manager is the only parameter passed to actions.
- // Bind the path, interface, interface member function pointer,
- // and value to a lambda. When it is called, forward the
- // path, interface and value on to the manager member function.
- return [paths, iface, member,
- value = std::forward<V>(value)](auto&, auto & m)
- {
- for (auto p : paths)
- {
- m.template invokeMethod<T>(
- p, iface, member, value);
- }
- };
-}
-
-} // namespace actions
-} // namespace manager
-} // namespace inventory
-} // namespace phosphor
-
-// vim: tabstop=8 expandtab shiftwidth=4 softtabstop=4
diff --git a/events.hpp b/events.hpp
index ef9d085..38c24e4 100644
--- a/events.hpp
+++ b/events.hpp
@@ -1,10 +1,6 @@
#pragma once
-#include <utility>
-#include <memory>
-#include <functional>
-#include <sdbusplus/message.hpp>
-#include "utils.hpp"
+#include "types.hpp"
namespace phosphor
{
@@ -14,8 +10,6 @@ namespace manager
{
class Manager;
-using Filter = std::function <
- bool (sdbusplus::bus::bus&, sdbusplus::message::message&, Manager&) >;
/** @struct Event
* @brief Event object interface.
@@ -82,236 +76,6 @@ struct DbusSignal final : public Event
const char* signature;
};
-/** @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(std::forward<T>(filter));
-}
-
-namespace filters
-{
-namespace property_condition
-{
-
-/** @struct PropertyChangedCondition
- * @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 PropertyChangedCondition
-{
- PropertyChangedCondition() = delete;
- ~PropertyChangedCondition() = default;
- PropertyChangedCondition(const PropertyChangedCondition&) = default;
- PropertyChangedCondition& operator=(const PropertyChangedCondition&) = default;
- PropertyChangedCondition(PropertyChangedCondition&&) = default;
- PropertyChangedCondition& operator=(PropertyChangedCondition&&) = default;
- PropertyChangedCondition(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::bus::bus&,
- sdbusplus::message::message& msg,
- Manager&) const
- {
- std::map <
- std::string,
- sdbusplus::message::variant<T >> properties;
- const char* iface = nullptr;
-
- msg.read(iface);
- if (!iface || strcmp(iface, _iface))
- {
- return false;
- }
-
- msg.read(properties);
- auto it = properties.find(_property);
- if (it == properties.cend())
- {
- return false;
- }
-
- return _condition(
- std::forward<T>(it->second.template get<T>()));
- }
-
- private:
- const char* _iface;
- const char* _property;
- U _condition;
-};
-
-/** @struct PropertyConditionBase
- * @brief Match filter functor that tests a property value.
- *
- * Base class for PropertyCondition - factored out code that
- * doesn't need to be templated.
- */
-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),
- _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&,
- Manager&) const;
-
- private:
- std::string _path;
- std::string _iface;
- std::string _property;
- const char* _service;
-};
-
-/** @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 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;
-};
-
-} // namespace property_condition
-
-/** @brief Implicit type deduction for constructing PropertyChangedCondition. */
-template <typename T>
-auto propertyChangedTo(
- const char* iface,
- const char* property,
- T&& val)
-{
- auto condition = [val = std::forward<T>(val)](T && arg)
- {
- return arg == val;
- };
- using U = decltype(condition);
- return property_condition::PropertyChangedCondition<T, U>(
- iface, property, std::move(condition));
-}
-
-/** @brief Implicit type deduction for constructing PropertyCondition. */
-template <typename T>
-auto propertyIs(
- const char* path,
- const char* iface,
- const char* property,
- T&& val,
- const char* service = nullptr)
-{
- auto condition = [val = std::forward<T>(val)](T && arg)
- {
- return arg == val;
- };
- using U = decltype(condition);
- return property_condition::PropertyCondition<T, U>(
- path, iface, property, std::move(condition), service);
-}
-
-} // namespace filters
} // namespace manager
} // namespace inventory
} // namespace phosphor
diff --git a/events.cpp b/functor.cpp
index 6f5bb59..a657257 100644
--- a/events.cpp
+++ b/functor.cpp
@@ -13,7 +13,7 @@
* See the License for the specific language governing permissions and
* limitations under the License.
*/
-#include "events.hpp"
+#include "functor.hpp"
#include <sdbusplus/bus.hpp>
namespace phosphor
@@ -22,9 +22,7 @@ namespace inventory
{
namespace manager
{
-namespace filters
-{
-namespace property_condition
+namespace functor
{
bool PropertyConditionBase::operator()(
@@ -87,8 +85,7 @@ bool PropertyConditionBase::operator()(
return eval(hostResponseMsg);
}
-} // namespace property_condition
-} // namespace filters
+} // namespace functor
} // namespace manager
} // namespace inventory
} // namespace phosphor
diff --git a/functor.hpp b/functor.hpp
new file mode 100644
index 0000000..265e467
--- /dev/null
+++ b/functor.hpp
@@ -0,0 +1,320 @@
+#pragma once
+
+#include <utility>
+#include <memory>
+#include <sdbusplus/bus.hpp>
+#include "utils.hpp"
+#include "types.hpp"
+
+namespace phosphor
+{
+namespace inventory
+{
+namespace manager
+{
+
+class Manager;
+
+/** @brief make_action
+ *
+ * Adapt an action function object.
+ *
+ * @param[in] action - The action being adapted.
+ * @returns - The adapted action.
+ *
+ * @tparam T - The type of the action being adapted.
+ */
+template <typename T>
+auto make_action(T&& action)
+{
+ return Action(std::forward<T>(action));
+}
+
+/** @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(std::forward<T>(filter));
+}
+
+namespace functor
+{
+
+/** @brief Destroy objects action. */
+inline auto destroyObjects(std::vector<const char*>&& paths)
+{
+ return [ = ](auto&, auto & m)
+ {
+ m.destroyObjects(paths);
+ };
+}
+
+/** @brief Create objects action. */
+inline auto createObjects(
+ std::map<sdbusplus::message::object_path, Object>&& objs)
+{
+ return [ = ](auto&, auto & m)
+ {
+ m.createObjects(objs);
+ };
+}
+
+/** @brief Set a property action.
+ *
+ * Invoke the requested method with a reference to the requested
+ * sdbusplus server binding interface as a parameter.
+ *
+ * @tparam T - The sdbusplus server binding interface type.
+ * @tparam U - The type of the sdbusplus server binding member
+ * function that sets the property.
+ * @tparam V - The property value type.
+ *
+ * @param[in] paths - The DBus paths on which the property should
+ * be set.
+ * @param[in] iface - The DBus interface hosting the property.
+ * @param[in] member - Pointer to sdbusplus server binding member.
+ * @param[in] value - The value the property should be set to.
+ *
+ * @returns - A function object that sets the requested property
+ * to the requested value.
+ */
+template <typename T, typename U, typename V>
+auto setProperty(
+ std::vector<const char*>&& paths, const char* iface,
+ U&& member, V&& value)
+{
+ // The manager is the only parameter passed to actions.
+ // Bind the path, interface, interface member function pointer,
+ // and value to a lambda. When it is called, forward the
+ // path, interface and value on to the manager member function.
+ return [paths, iface, member,
+ value = std::forward<V>(value)](auto&, auto & m)
+ {
+ for (auto p : paths)
+ {
+ m.template invokeMethod<T>(
+ p, iface, member, value);
+ }
+ };
+}
+
+/** @struct PropertyChangedCondition
+ * @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 PropertyChangedCondition
+{
+ PropertyChangedCondition() = delete;
+ ~PropertyChangedCondition() = default;
+ PropertyChangedCondition(const PropertyChangedCondition&) = default;
+ PropertyChangedCondition& operator=(const PropertyChangedCondition&) = default;
+ PropertyChangedCondition(PropertyChangedCondition&&) = default;
+ PropertyChangedCondition& operator=(PropertyChangedCondition&&) = default;
+ PropertyChangedCondition(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::bus::bus&,
+ sdbusplus::message::message& msg,
+ Manager&) const
+ {
+ std::map <
+ std::string,
+ sdbusplus::message::variant<T >> properties;
+ const char* iface = nullptr;
+
+ msg.read(iface);
+ if (!iface || strcmp(iface, _iface))
+ {
+ return false;
+ }
+
+ msg.read(properties);
+ auto it = properties.find(_property);
+ if (it == properties.cend())
+ {
+ return false;
+ }
+
+ return _condition(
+ std::forward<T>(it->second.template get<T>()));
+ }
+
+ private:
+ const char* _iface;
+ const char* _property;
+ U _condition;
+};
+
+/** @struct PropertyConditionBase
+ * @brief Match filter functor that tests a property value.
+ *
+ * Base class for PropertyCondition - factored out code that
+ * doesn't need to be templated.
+ */
+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),
+ _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&,
+ Manager&) const;
+
+ private:
+ std::string _path;
+ std::string _iface;
+ std::string _property;
+ const char* _service;
+};
+
+/** @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 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;
+};
+
+/** @brief Implicit type deduction for constructing PropertyChangedCondition. */
+template <typename T>
+auto propertyChangedTo(
+ const char* iface,
+ const char* property,
+ T&& val)
+{
+ auto condition = [val = std::forward<T>(val)](T && arg)
+ {
+ return arg == val;
+ };
+ using U = decltype(condition);
+ return PropertyChangedCondition<T, U>(
+ iface, property, std::move(condition));
+}
+
+/** @brief Implicit type deduction for constructing PropertyCondition. */
+template <typename T>
+auto propertyIs(
+ const char* path,
+ const char* iface,
+ const char* property,
+ T&& val,
+ const char* service = nullptr)
+{
+ auto condition = [val = std::forward<T>(val)](T && arg)
+ {
+ return arg == val;
+ };
+ using U = decltype(condition);
+ return PropertyCondition<T, U>(
+ path, iface, property, std::move(condition), service);
+}
+} // namespace functor
+} // namespace manager
+} // namespace inventory
+} // namespace phosphor
+
+// vim: tabstop=8 expandtab shiftwidth=4 softtabstop=4
diff --git a/generated.mako.cpp b/generated.mako.cpp
index fe2c6cb..235e58a 100644
--- a/generated.mako.cpp
+++ b/generated.mako.cpp
@@ -3,6 +3,7 @@
// This file was auto generated. Do not edit.
#include "manager.hpp"
#include "utils.hpp"
+#include "functor.hpp"
% for i in interfaces:
#include <${i.header()}>
% endfor
diff --git a/manager.hpp b/manager.hpp
index 806a9a4..797880b 100644
--- a/manager.hpp
+++ b/manager.hpp
@@ -7,7 +7,7 @@
#include <sdbusplus/server.hpp>
#include <xyz/openbmc_project/Inventory/Manager/server.hpp>
#include "events.hpp"
-#include "actions.hpp"
+#include "functor.hpp"
#include "types.hpp"
namespace phosphor
diff --git a/pimgen.py b/pimgen.py
index be66bb0..2193c90 100755
--- a/pimgen.py
+++ b/pimgen.py
@@ -67,7 +67,7 @@ class Template(NamedElement):
'''Associate a template name with its namespace.'''
def __init__(self, **kw):
- self.namespace = kw.pop('namespace')
+ self.namespace = kw.pop('namespace', [])
super(Template, self).__init__(**kw)
def qualified(self):
@@ -206,44 +206,24 @@ class Vector(MethodCall):
super(Vector, self).__init__(**kw)
-class Wrapper(MethodCall):
- '''Convenience type for functions that wrap other functions.'''
-
- def __init__(self, **kw):
- m = MethodCall(
- name=kw.pop('name'),
- namespace=kw.pop('namespace', []),
- templates=kw.pop('templates', []),
- args=kw.pop('args', []))
-
- kw['name'] = kw.pop('wrapper_name')
- kw['namespace'] = kw.pop('wrapper_namespace', [])
- kw['args'] = [m]
- super(Wrapper, self).__init__(**kw)
-
-
-class Filter(Wrapper):
+class Filter(MethodCall):
'''Convenience type for filters'''
def __init__(self, **kw):
- kw['wrapper_name'] = 'make_filter'
- kw['wrapper_namespace'] = []
- kw['namespace'] = ['filters']
+ kw['name'] = 'make_filter'
super(Filter, self).__init__(**kw)
-class Action(Wrapper):
+class Action(MethodCall):
'''Convenience type for actions'''
def __init__(self, **kw):
- kw['wrapper_name'] = 'make_action'
- kw['wrapper_namespace'] = []
- kw['namespace'] = ['actions']
+ kw['name'] = 'make_action'
super(Action, self).__init__(**kw)
-class CreateObjects(Action):
- '''Assemble a createObjects action.'''
+class CreateObjects(MethodCall):
+ '''Assemble a createObjects functor.'''
def __init__(self, **kw):
objs = []
@@ -273,22 +253,24 @@ class CreateObjects(Action):
objs.append(InitializerList(values=[key_o, value_i]))
kw['args'] = [InitializerList(values=objs)]
+ kw['namespace'] = ['functor']
super(CreateObjects, self).__init__(**kw)
-class DestroyObjects(Action):
- '''Assemble a destroyObject action.'''
+class DestroyObjects(MethodCall):
+ '''Assemble a destroyObject functor.'''
def __init__(self, **kw):
values = [{'value': x, 'type': 'string'} for x in kw.pop('paths')]
args = [InitializerList(
values=[TrivialArgument(**x) for x in values])]
kw['args'] = args
+ kw['namespace'] = ['functor']
super(DestroyObjects, self).__init__(**kw)
-class SetProperty(Action):
- '''Assemble a setProperty action.'''
+class SetProperty(MethodCall):
+ '''Assemble a setProperty functor.'''
def __init__(self, **kw):
args = []
@@ -317,11 +299,12 @@ class SetProperty(Action):
kw['templates'] = [Template(name=name, namespace=namespace)]
kw['args'] = args
+ kw['namespace'] = ['functor']
super(SetProperty, self).__init__(**kw)
-class PropertyChanged(Filter):
- '''Assemble a propertyChanged filter.'''
+class PropertyChanged(MethodCall):
+ '''Assemble a propertyChanged functor.'''
def __init__(self, **kw):
args = []
@@ -331,11 +314,12 @@ class PropertyChanged(Filter):
decorators=[
Literal(kw['value'].get('type', None))], **kw.pop('value')))
kw['args'] = args
+ kw['namespace'] = ['functor']
super(PropertyChanged, self).__init__(**kw)
-class PropertyIs(Filter):
- '''Assemble a propertyIs filter.'''
+class PropertyIs(MethodCall):
+ '''Assemble a propertyIs functor.'''
def __init__(self, **kw):
args = []
@@ -351,6 +335,7 @@ class PropertyIs(Filter):
args.append(TrivialArgument(value=service, type='string'))
kw['args'] = args
+ kw['namespace'] = ['functor']
super(PropertyIs, self).__init__(**kw)
@@ -373,6 +358,7 @@ class Event(MethodCall):
filters = [
self.filter_map[x['name']](**x) for x in kw.pop('filters', [])]
+ filters = [Filter(args=[x]) for x in filters]
filters = Vector(
templates=[Template(name='Filter', namespace=[])],
args=filters)
@@ -392,6 +378,7 @@ class Event(MethodCall):
action_type = Template(name='Action', namespace=[])
action_args = [
self.action_map[x['name']](**x) for x in kw.pop('actions', [])]
+ action_args = [Action(args=[x]) for x in action_args]
actions = Vector(
templates=[action_type],
args=action_args)
diff --git a/types.hpp b/types.hpp
index fff52d5..d2105aa 100644
--- a/types.hpp
+++ b/types.hpp
@@ -4,6 +4,7 @@
#include <string>
#include <sdbusplus/message.hpp>
#include <experimental/any>
+#include <functional>
namespace phosphor
{
@@ -12,6 +13,7 @@ namespace inventory
namespace manager
{
+class Manager;
namespace any_ns = std::experimental;
/** @brief Inventory manager supported property types. */
@@ -27,6 +29,10 @@ using ObjectType = std::map<std::string, InterfaceType<T>>;
using Interface = InterfaceType<InterfaceVariantType>;
using Object = ObjectType<InterfaceVariantType>;
+using Action = std::function<void (sdbusplus::bus::bus&, Manager&)>;
+using Filter = std::function <
+ bool (sdbusplus::bus::bus&, sdbusplus::message::message&, Manager&) >;
+
} // namespace manager
} // namespace inventory
} // namespace phosphor
OpenPOWER on IntegriCloud