1 #pragma once
2 
3 namespace phosphor
4 {
5 namespace fan
6 {
7 namespace control
8 {
9 namespace handler
10 {
11 
12 /**
13  * @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  *
17  * @param[in] intf - Interface on zone object
18  * @param[in] prop - Property on interface
19  * @param[in] func - Zone set property function pointer
20  * @param[in] value - Value to set property to
21  * @param[in] persist - Persist property value or not
22  *
23  * @return Lambda function
24  *     A lambda function to set/update the zone property
25  */
26 template <typename T>
27 auto setZoneProperty(const char* intf, const char* prop, T (Zone::*func)(T),
28                      T&& value, bool persist)
29 {
30     return [=, value = std::forward<T>(value)](auto& zone) {
31         (zone.*func)(value);
32         if (persist)
33         {
34             zone.setPersisted(intf, prop);
35         }
36     };
37 }
38 
39 /**
40  * @brief A handler function to set/update a property
41  * @details Sets or updates a property's value determined by a combination of
42  * an object's path, interface, and property names
43  *
44  * @param[in] path - Object's path name
45  * @param[in] interface - Object's interface name
46  * @param[in] property - Object's property name
47  *
48  * @return Lambda function
49  *     A lambda function to set/update the property value
50  */
51 template <typename T>
52 auto setProperty()
53 {
54     return [](auto& zone, auto& path, auto& intf, auto& prop, T&& arg) {
55         zone.setPropertyValue(path, intf, prop, std::forward<T>(arg));
56     };
57 }
58 
59 /**
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  */
69 inline auto setService(Group&& group)
70 {
71     return [group = std::move(group)](auto& zone, auto& name, bool hasOwner) {
72         // Update service name owner state list of a group
73         zone.setServiceOwner(&group, name, hasOwner);
74     };
75 }
76 
77 /**
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  */
88 inline auto removeInterface(const char* path, const char* interface)
89 {
90     return [=](auto& zone) { zone.removeObjectInterface(path, interface); };
91 }
92 
93 } // namespace handler
94 } // namespace control
95 } // namespace fan
96 } // namespace phosphor
97