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 | |
Brad Bishop | 7b7e712 | 2017-01-21 21:21:46 -0500 | [diff] [blame] | 42 | /** @brief Destroy objects action. */ |
| 43 | inline auto destroyObjects(std::vector<const char*> paths) |
Brad Bishop | 656a7d0 | 2016-10-19 22:20:02 -0400 | [diff] [blame] | 44 | { |
Brad Bishop | 7b7e712 | 2017-01-21 21:21:46 -0500 | [diff] [blame] | 45 | return [paths = std::move(paths)](auto & m) |
Brad Bishop | 7b33777 | 2017-01-12 16:11:24 -0500 | [diff] [blame] | 46 | { |
Brad Bishop | 7b7e712 | 2017-01-21 21:21:46 -0500 | [diff] [blame] | 47 | m.destroyObjects(paths); |
Brad Bishop | 7b33777 | 2017-01-12 16:11:24 -0500 | [diff] [blame] | 48 | }; |
Brad Bishop | 656a7d0 | 2016-10-19 22:20:02 -0400 | [diff] [blame] | 49 | } |
Brad Bishop | da649b1 | 2016-11-30 14:35:02 -0500 | [diff] [blame] | 50 | |
| 51 | /** @brief Set a property action. |
| 52 | * |
| 53 | * Invoke the requested method with a reference to the requested |
| 54 | * sdbusplus server binding interface as a parameter. |
| 55 | * |
| 56 | * @tparam T - The sdbusplus server binding interface type. |
| 57 | * @tparam U - The type of the sdbusplus server binding member |
| 58 | * function that sets the property. |
| 59 | * @tparam V - The property value type. |
| 60 | * |
| 61 | * @param[in] path - The DBus path on which the property should |
| 62 | * be set. |
| 63 | * @param[in] iface - The DBus interface hosting the property. |
| 64 | * @param[in] member - Pointer to sdbusplus server binding member. |
| 65 | * @param[in] value - The value the property should be set to. |
| 66 | * |
| 67 | * @returns - A function object that sets the requested property |
| 68 | * to the requested value. |
| 69 | */ |
| 70 | template <typename T, typename U, typename V> |
Brad Bishop | 5dd1c1e | 2017-01-12 16:14:27 -0500 | [diff] [blame] | 71 | auto setProperty( |
Brad Bishop | 7b33777 | 2017-01-12 16:11:24 -0500 | [diff] [blame] | 72 | const char* path, const char* iface, |
| 73 | U&& member, V&& value) |
Brad Bishop | da649b1 | 2016-11-30 14:35:02 -0500 | [diff] [blame] | 74 | { |
| 75 | // The manager is the only parameter passed to actions. |
| 76 | // Bind the path, interface, interface member function pointer, |
| 77 | // and value to a lambda. When it is called, forward the |
| 78 | // path, interface and value on to the manager member function. |
| 79 | return [path, iface, member, |
Brad Bishop | 7b33777 | 2017-01-12 16:11:24 -0500 | [diff] [blame] | 80 | value = std::forward<V>(value)](auto & m) |
Brad Bishop | da649b1 | 2016-11-30 14:35:02 -0500 | [diff] [blame] | 81 | { |
| 82 | m.template invokeMethod<T>( |
| 83 | path, iface, member, value); |
| 84 | }; |
| 85 | } |
| 86 | |
Brad Bishop | c038e01 | 2016-10-19 13:02:24 -0400 | [diff] [blame] | 87 | } // namespace actions |
| 88 | } // namespace manager |
| 89 | } // namespace inventory |
| 90 | } // namespace phosphor |
| 91 | |
| 92 | // vim: tabstop=8 expandtab shiftwidth=4 softtabstop=4 |