blob: 7fb7dfc1e4a9c2f8e6a0954881f86688266f79bb [file] [log] [blame]
Matthew Barth38a93a82017-05-11 14:12:27 -05001#pragma once
2
3namespace phosphor
4{
5namespace fan
6{
7namespace control
8{
9namespace handler
10{
11
12/**
Matthew Barth1b3e9602019-02-13 11:37:03 -060013 * @brief A handler function to set/update a property on a zone
14 * @details Sets or updates a zone property to the given value using the
15 * provided zone dbus object's set property function
16 *
Matthew Barth59096e52019-02-18 12:23:38 -060017 * @param[in] intf - Interface on zone object
18 * @param[in] prop - Property on interface
Matthew Barth1b3e9602019-02-13 11:37:03 -060019 * @param[in] func - Zone set property function pointer
Matthew Barth59096e52019-02-18 12:23:38 -060020 * @param[in] value - Value to set property to
21 * @param[in] persist - Persist property value or not
Matthew Barth1b3e9602019-02-13 11:37:03 -060022 *
23 * @return Lambda function
24 * A lambda function to set/update the zone property
25 */
26template <typename T>
Matthew Barth3e1bb272020-05-26 11:09:21 -050027auto setZoneProperty(const char* intf, const char* prop, T (Zone::*func)(T),
28 T&& value, bool persist)
Matthew Barth1b3e9602019-02-13 11:37:03 -060029{
Matthew Barth3e1bb272020-05-26 11:09:21 -050030 return [=, value = std::forward<T>(value)](auto& zone) {
Matthew Barth1b3e9602019-02-13 11:37:03 -060031 (zone.*func)(value);
Matthew Barth59096e52019-02-18 12:23:38 -060032 if (persist)
33 {
34 zone.setPersisted(intf, prop);
35 }
Matthew Barth1b3e9602019-02-13 11:37:03 -060036 };
37}
38
39/**
Matthew Barth38a93a82017-05-11 14:12:27 -050040 * @brief A handler function to set/update a property
41 * @details Sets or updates a property's value determined by a combination of
Matthew Barth469d1362018-10-11 14:10:47 -050042 * an object's path, interface, and property names
Matthew Barth38a93a82017-05-11 14:12:27 -050043 *
44 * @param[in] path - Object's path name
Matthew Barthcec5ab72017-06-02 15:20:56 -050045 * @param[in] interface - Object's interface name
Matthew Barth38a93a82017-05-11 14:12:27 -050046 * @param[in] property - Object's property name
47 *
48 * @return Lambda function
49 * A lambda function to set/update the property value
50 */
51template <typename T>
Matthew Barth469d1362018-10-11 14:10:47 -050052auto setProperty()
Matthew Barth38a93a82017-05-11 14:12:27 -050053{
Matthew Barth3e1bb272020-05-26 11:09:21 -050054 return [](auto& zone, auto& path, auto& intf, auto& prop, T&& arg) {
Matthew Barth469d1362018-10-11 14:10:47 -050055 zone.setPropertyValue(path, intf, prop, std::forward<T>(arg));
Matthew Barth38a93a82017-05-11 14:12:27 -050056 };
57}
58
Matthew Barth8fa02da2017-09-28 12:18:20 -050059/**
60 * @brief A handler function to set/update service name owner state
61 * @details Sets or updates service name owner state used by a group where
62 * a service name without an owner represents the service no longer exists
63 *
64 * @param[in] group - Group associated with a service
65 *
66 * @return Lambda function
67 * A lambda function to set/update the service name owner state
68 */
Matthew Barth56f1ffc2021-01-15 16:27:06 -060069inline auto setService(Group&& group)
Matthew Barth8fa02da2017-09-28 12:18:20 -050070{
Matthew Barth3e1bb272020-05-26 11:09:21 -050071 return [group = std::move(group)](auto& zone, auto& name, bool hasOwner) {
Matthew Barth5a302572017-10-03 11:27:06 -050072 // Update service name owner state list of a group
73 zone.setServiceOwner(&group, name, hasOwner);
Matthew Barth8fa02da2017-09-28 12:18:20 -050074 };
75}
76
Matthew Barth1499a5c2018-03-20 15:52:33 -050077/**
78 * @brief A handler function to remove an interface from an object path
79 * @details Removes an interface from an object's path which includes removing
80 * all properties that would be under that interface
81 *
82 * @param[in] path - Object's path name
83 * @param[in] interface - Object's interface name
84 *
85 * @return Lambda function
86 * A lambda function to remove the interface
87 */
Matthew Barth56f1ffc2021-01-15 16:27:06 -060088inline auto removeInterface(const char* path, const char* interface)
Matthew Barth1499a5c2018-03-20 15:52:33 -050089{
Matthew Barth3e1bb272020-05-26 11:09:21 -050090 return [=](auto& zone) { zone.removeObjectInterface(path, interface); };
Matthew Barth1499a5c2018-03-20 15:52:33 -050091}
92
Matthew Barth38a93a82017-05-11 14:12:27 -050093} // namespace handler
94} // namespace control
95} // namespace fan
96} // namespace phosphor