Brad Bishop | c038e01 | 2016-10-19 13:02:24 -0400 | [diff] [blame] | 1 | #pragma once |
| 2 | |
| 3 | #include <utility> |
| 4 | #include <memory> |
Brad Bishop | 65ffffa | 2016-11-29 12:31:31 -0500 | [diff] [blame^] | 5 | #include "utils.hpp" |
Brad Bishop | c038e01 | 2016-10-19 13:02:24 -0400 | [diff] [blame] | 6 | |
| 7 | namespace phosphor |
| 8 | { |
| 9 | namespace inventory |
| 10 | { |
| 11 | namespace manager |
| 12 | { |
Brad Bishop | 65ffffa | 2016-11-29 12:31:31 -0500 | [diff] [blame^] | 13 | |
Brad Bishop | c0eae11 | 2016-10-19 21:59:47 -0400 | [diff] [blame] | 14 | class Manager; |
Brad Bishop | 65ffffa | 2016-11-29 12:31:31 -0500 | [diff] [blame^] | 15 | namespace details |
| 16 | { |
| 17 | using ActionBase = holder::CallableBase<void, Manager&>; |
| 18 | using ActionBasePtr = std::shared_ptr<ActionBase>; |
| 19 | template <typename T> |
| 20 | using 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 | */ |
| 31 | template <typename T> |
| 32 | auto make_action(T&& action) |
| 33 | { |
| 34 | return Action<T>::template make_shared<Action<T>>( |
| 35 | std::forward<T>(action)); |
| 36 | } |
| 37 | } // namespace details |
Brad Bishop | c0eae11 | 2016-10-19 21:59:47 -0400 | [diff] [blame] | 38 | |
Brad Bishop | c038e01 | 2016-10-19 13:02:24 -0400 | [diff] [blame] | 39 | namespace actions |
| 40 | { |
Brad Bishop | c038e01 | 2016-10-19 13:02:24 -0400 | [diff] [blame] | 41 | |
| 42 | /** @brief The default action. */ |
Brad Bishop | c0eae11 | 2016-10-19 21:59:47 -0400 | [diff] [blame] | 43 | inline void noop(Manager &mgr) noexcept { } |
Brad Bishop | c038e01 | 2016-10-19 13:02:24 -0400 | [diff] [blame] | 44 | |
Brad Bishop | 656a7d0 | 2016-10-19 22:20:02 -0400 | [diff] [blame] | 45 | /** @brief Destroy an object action. */ |
| 46 | inline auto destroyObject(const char *path) |
| 47 | { |
| 48 | return [path](auto &m){m.destroyObject(path);}; |
| 49 | } |
Brad Bishop | c038e01 | 2016-10-19 13:02:24 -0400 | [diff] [blame] | 50 | } // namespace actions |
| 51 | } // namespace manager |
| 52 | } // namespace inventory |
| 53 | } // namespace phosphor |
| 54 | |
| 55 | // vim: tabstop=8 expandtab shiftwidth=4 softtabstop=4 |