Allow multiple objects to be destroyed
Enhance the destroyObject action to take an array
rather than a single path.
Change-Id: Ic1de7274afc253042b590c71ca200618a6ff54d2
Signed-off-by: Brad Bishop <bradleyb@fuzziesquirrel.com>
diff --git a/README.md b/README.md
index 14bc532..5f479fc 100644
--- a/README.md
+++ b/README.md
@@ -74,7 +74,7 @@
**destroyObject**
Supported arguments for the destroyObject action are:
-* path - The path of the object to remove from DBus.
+* paths - The paths of the objects to remove from DBus.
----
**setProperty**
diff --git a/actions.hpp b/actions.hpp
index 3060145..ea7f247 100644
--- a/actions.hpp
+++ b/actions.hpp
@@ -39,12 +39,12 @@
namespace actions
{
-/** @brief Destroy an object action. */
-inline auto destroyObject(const char* path)
+/** @brief Destroy objects action. */
+inline auto destroyObjects(std::vector<const char*> paths)
{
- return [path](auto & m)
+ return [paths = std::move(paths)](auto & m)
{
- m.destroyObject(path);
+ m.destroyObjects(paths);
};
}
diff --git a/example/events.d/match2.yaml b/example/events.d/match2.yaml
index 5fe2388..d59e4da 100644
--- a/example/events.d/match2.yaml
+++ b/example/events.d/match2.yaml
@@ -21,10 +21,10 @@
type: string
value: xxxyyy
actions:
- - name: destroyObject
- path: /deleteme1
- - name: destroyObject
- path: /deleteme2
+ - name: destroyObjects
+ paths:
+ - /deleteme1
+ - /deleteme2
# vim: tabstop=8 expandtab shiftwidth=4 softtabstop=4
diff --git a/manager.cpp b/manager.cpp
index 264037f..e100cd9 100644
--- a/manager.cpp
+++ b/manager.cpp
@@ -195,10 +195,14 @@
}
}
-void Manager::destroyObject(const char* path)
+void Manager::destroyObjects(
+ const std::vector<const char*>& paths)
{
- std::string p{path};
- _refs.erase(_root + p);
+ for (const auto& path : paths)
+ {
+ std::string p{path};
+ _refs.erase(_root + p);
+ }
}
details::holder::Base& Manager::getInterfaceHolder(
diff --git a/manager.hpp b/manager.hpp
index 2ffa47b..bd12ef6 100644
--- a/manager.hpp
+++ b/manager.hpp
@@ -97,8 +97,9 @@
const details::DbusSignal& event,
const EventInfo& info);
- /** @brief Drop an object from DBus. */
- void destroyObject(const char*);
+ /** @brief Drop one or more objects from DBus. */
+ void destroyObjects(
+ const std::vector<const char*>& paths);
/** @brief Invoke an sdbusplus server binding method.
*
diff --git a/pimgen.py b/pimgen.py
index 86643aa..5e2cf00 100755
--- a/pimgen.py
+++ b/pimgen.py
@@ -242,13 +242,15 @@
super(Action, self).__init__(**kw)
-class DestroyObject(Action):
+class DestroyObjects(Action):
'''Assemble a destroyObject action.'''
def __init__(self, **kw):
- args = [TrivialArgument(value=kw.pop('path'), type='string')]
+ values = [{'value': x, 'type': 'string'} for x in kw.pop('paths')]
+ args = [InitializerList(
+ values=[TrivialArgument(**x) for x in values])]
kw['args'] = args
- super(DestroyObject, self).__init__(**kw)
+ super(DestroyObjects, self).__init__(**kw)
class SetProperty(Action):
@@ -299,7 +301,7 @@
'''Assemble an inventory manager event.'''
action_map = {
- 'destroyObject': DestroyObject,
+ 'destroyObjects': DestroyObjects,
'setProperty': SetProperty,
}