blob: 6b512fd2ce2eb27c33e68fd079777d0fdb22b9c7 [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 Barth59096e52019-02-18 12:23:38 -060027auto setZoneProperty(const char* intf,
28 const char* prop,
29 T (Zone::*func)(T),
30 T&& value,
31 bool persist)
Matthew Barth1b3e9602019-02-13 11:37:03 -060032{
Matthew Barth59096e52019-02-18 12:23:38 -060033 return [=, value = std::forward<T>(value)](auto& zone)
Matthew Barth1b3e9602019-02-13 11:37:03 -060034 {
35 (zone.*func)(value);
Matthew Barth59096e52019-02-18 12:23:38 -060036 if (persist)
37 {
38 zone.setPersisted(intf, prop);
39 }
Matthew Barth1b3e9602019-02-13 11:37:03 -060040 };
41}
42
43/**
Matthew Barth38a93a82017-05-11 14:12:27 -050044 * @brief A handler function to set/update a property
45 * @details Sets or updates a property's value determined by a combination of
46 * an object's path and property names
47 *
48 * @param[in] path - Object's path name
Matthew Barthcec5ab72017-06-02 15:20:56 -050049 * @param[in] interface - Object's interface name
Matthew Barth38a93a82017-05-11 14:12:27 -050050 * @param[in] property - Object's property name
51 *
52 * @return Lambda function
53 * A lambda function to set/update the property value
54 */
55template <typename T>
Matthew Barthcec5ab72017-06-02 15:20:56 -050056auto setProperty(const char* path, const char* interface, const char* property)
Matthew Barth38a93a82017-05-11 14:12:27 -050057{
58 return [=](auto& zone, T&& arg)
59 {
Matthew Barthcec5ab72017-06-02 15:20:56 -050060 zone.setPropertyValue(path, interface, property, std::forward<T>(arg));
Matthew Barth38a93a82017-05-11 14:12:27 -050061 };
62}
63
Matthew Barth8fa02da2017-09-28 12:18:20 -050064/**
65 * @brief A handler function to set/update service name owner state
66 * @details Sets or updates service name owner state used by a group where
67 * a service name without an owner represents the service no longer exists
68 *
69 * @param[in] group - Group associated with a service
70 *
71 * @return Lambda function
72 * A lambda function to set/update the service name owner state
73 */
74auto setService(Group&& group)
75{
76 return [group = std::move(group)](auto& zone, auto& name, bool hasOwner)
77 {
Matthew Barth5a302572017-10-03 11:27:06 -050078 // Update service name owner state list of a group
79 zone.setServiceOwner(&group, name, hasOwner);
Matthew Barth8fa02da2017-09-28 12:18:20 -050080 };
81}
82
Matthew Barth1499a5c2018-03-20 15:52:33 -050083/**
84 * @brief A handler function to remove an interface from an object path
85 * @details Removes an interface from an object's path which includes removing
86 * all properties that would be under that interface
87 *
88 * @param[in] path - Object's path name
89 * @param[in] interface - Object's interface name
90 *
91 * @return Lambda function
92 * A lambda function to remove the interface
93 */
94auto removeInterface(const char* path, const char* interface)
95{
96 return[=](auto& zone)
97 {
Matthew Barth30abbef2018-04-12 09:40:54 -050098 zone.removeObjectInterface(path, interface);
Matthew Barth1499a5c2018-03-20 15:52:33 -050099 };
100}
101
Matthew Barth38a93a82017-05-11 14:12:27 -0500102} // namespace handler
103} // namespace control
104} // namespace fan
105} // namespace phosphor