blob: 27f555df1fcbba71493cd01c59d91e40bf52c016 [file] [log] [blame]
Matthew Barth38a93a82017-05-11 14:12:27 -05001#pragma once
2
Matt Spinlerc7dfb132025-08-15 11:05:45 -05003#include "types.hpp"
4#include "zone.hpp"
5
6#include <utility>
7
Matthew Barth38a93a82017-05-11 14:12:27 -05008namespace phosphor
9{
10namespace fan
11{
12namespace control
13{
14namespace handler
15{
16
17/**
Matthew Barth1b3e9602019-02-13 11:37:03 -060018 * @brief A handler function to set/update a property on a zone
19 * @details Sets or updates a zone property to the given value using the
20 * provided zone dbus object's set property function
21 *
Matthew Barth59096e52019-02-18 12:23:38 -060022 * @param[in] intf - Interface on zone object
23 * @param[in] prop - Property on interface
Matthew Barth1b3e9602019-02-13 11:37:03 -060024 * @param[in] func - Zone set property function pointer
Matthew Barth59096e52019-02-18 12:23:38 -060025 * @param[in] value - Value to set property to
26 * @param[in] persist - Persist property value or not
Matthew Barth1b3e9602019-02-13 11:37:03 -060027 *
28 * @return Lambda function
29 * A lambda function to set/update the zone property
30 */
31template <typename T>
Matthew Barth3e1bb272020-05-26 11:09:21 -050032auto setZoneProperty(const char* intf, const char* prop, T (Zone::*func)(T),
33 T&& value, bool persist)
Matthew Barth1b3e9602019-02-13 11:37:03 -060034{
Matthew Barth3e1bb272020-05-26 11:09:21 -050035 return [=, value = std::forward<T>(value)](auto& zone) {
Matthew Barth1b3e9602019-02-13 11:37:03 -060036 (zone.*func)(value);
Matthew Barth59096e52019-02-18 12:23:38 -060037 if (persist)
38 {
39 zone.setPersisted(intf, prop);
40 }
Matthew Barth1b3e9602019-02-13 11:37:03 -060041 };
42}
43
44/**
Matthew Barth38a93a82017-05-11 14:12:27 -050045 * @brief A handler function to set/update a property
46 * @details Sets or updates a property's value determined by a combination of
Matthew Barth469d1362018-10-11 14:10:47 -050047 * an object's path, interface, and property names
Matthew Barth38a93a82017-05-11 14:12:27 -050048 *
49 * @param[in] path - Object's path name
Matthew Barthcec5ab72017-06-02 15:20:56 -050050 * @param[in] interface - Object's interface name
Matthew Barth38a93a82017-05-11 14:12:27 -050051 * @param[in] property - Object's property name
52 *
53 * @return Lambda function
54 * A lambda function to set/update the property value
55 */
56template <typename T>
Matthew Barth469d1362018-10-11 14:10:47 -050057auto setProperty()
Matthew Barth38a93a82017-05-11 14:12:27 -050058{
Matthew Barth3e1bb272020-05-26 11:09:21 -050059 return [](auto& zone, auto& path, auto& intf, auto& prop, T&& arg) {
Matthew Barth469d1362018-10-11 14:10:47 -050060 zone.setPropertyValue(path, intf, prop, 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 */
Matthew Barth56f1ffc2021-01-15 16:27:06 -060074inline auto setService(Group&& group)
Matthew Barth8fa02da2017-09-28 12:18:20 -050075{
Matthew Barth3e1bb272020-05-26 11:09:21 -050076 return [group = std::move(group)](auto& zone, auto& name, bool hasOwner) {
Matthew Barth5a302572017-10-03 11:27:06 -050077 // Update service name owner state list of a group
78 zone.setServiceOwner(&group, name, hasOwner);
Matthew Barth8fa02da2017-09-28 12:18:20 -050079 };
80}
81
Matthew Barth1499a5c2018-03-20 15:52:33 -050082/**
83 * @brief A handler function to remove an interface from an object path
84 * @details Removes an interface from an object's path which includes removing
85 * all properties that would be under that interface
86 *
87 * @param[in] path - Object's path name
88 * @param[in] interface - Object's interface name
89 *
90 * @return Lambda function
91 * A lambda function to remove the interface
92 */
Matthew Barth56f1ffc2021-01-15 16:27:06 -060093inline auto removeInterface(const char* path, const char* interface)
Matthew Barth1499a5c2018-03-20 15:52:33 -050094{
Matthew Barth3e1bb272020-05-26 11:09:21 -050095 return [=](auto& zone) { zone.removeObjectInterface(path, interface); };
Matthew Barth1499a5c2018-03-20 15:52:33 -050096}
97
Matthew Barth38a93a82017-05-11 14:12:27 -050098} // namespace handler
99} // namespace control
100} // namespace fan
101} // namespace phosphor