blob: 0966ee4d5441cf8ac8f6fd32408c46be9e29b40e [file] [log] [blame]
Brad Bishopc038e012016-10-19 13:02:24 -04001#pragma once
2
3#include <utility>
4#include <memory>
Brad Bishop65ffffa2016-11-29 12:31:31 -05005#include "utils.hpp"
Brad Bishopc038e012016-10-19 13:02:24 -04006
7namespace phosphor
8{
9namespace inventory
10{
11namespace manager
12{
Brad Bishop65ffffa2016-11-29 12:31:31 -050013
Brad Bishopc0eae112016-10-19 21:59:47 -040014class Manager;
Brad Bishop65ffffa2016-11-29 12:31:31 -050015namespace details
16{
17using ActionBase = holder::CallableBase<void, Manager&>;
18using ActionBasePtr = std::shared_ptr<ActionBase>;
19template <typename T>
20using Action = holder::CallableHolder<T, void, Manager&>;
21
22/** @brief make_action
23 *
24 * Adapt an action function object.
25 *
26 * @param[in] action - The action being adapted.
27 * @returns - The adapted action.
28 *
29 * @tparam T - The type of the action being adapted.
30 */
31template <typename T>
32auto make_action(T&& action)
33{
34 return Action<T>::template make_shared<Action<T>>(
35 std::forward<T>(action));
36}
37} // namespace details
Brad Bishopc0eae112016-10-19 21:59:47 -040038
Brad Bishopc038e012016-10-19 13:02:24 -040039namespace actions
40{
Brad Bishopc038e012016-10-19 13:02:24 -040041
42/** @brief The default action. */
Brad Bishopc0eae112016-10-19 21:59:47 -040043inline void noop(Manager &mgr) noexcept { }
Brad Bishopc038e012016-10-19 13:02:24 -040044
Brad Bishop656a7d02016-10-19 22:20:02 -040045/** @brief Destroy an object action. */
46inline auto destroyObject(const char *path)
47{
48 return [path](auto &m){m.destroyObject(path);};
49}
Brad Bishopc038e012016-10-19 13:02:24 -040050} // namespace actions
51} // namespace manager
52} // namespace inventory
53} // namespace phosphor
54
55// vim: tabstop=8 expandtab shiftwidth=4 softtabstop=4