1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
|
#pragma once
#include <utility>
#include <memory>
#include "utils.hpp"
namespace phosphor
{
namespace inventory
{
namespace manager
{
class Manager;
namespace details
{
using ActionBase = holder::CallableBase<void, Manager&>;
using ActionBasePtr = std::shared_ptr<ActionBase>;
template <typename T>
using Action = holder::CallableHolder<T, void, 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<T>::template make_shared<Action<T>>(
std::forward<T>(action));
}
} // namespace details
namespace actions
{
/** @brief The default action. */
inline void noop(Manager& mgr) noexcept { }
/** @brief Destroy an object action. */
inline auto destroyObject(const char* path)
{
return [path](auto & m)
{
m.destroyObject(path);
};
}
/** @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] path - The DBus path 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>
decltype(auto) setProperty(
const char* path, 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 [path, iface, member,
value = std::forward<V>(value)](auto & m)
{
m.template invokeMethod<T>(
path, iface, member, value);
};
}
} // namespace actions
} // namespace manager
} // namespace inventory
} // namespace phosphor
// vim: tabstop=8 expandtab shiftwidth=4 softtabstop=4
|