blob: 215662a528cfc69c58fc8476a706343df1eebbc7 [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 *
17 * @param[in] value - Value to set property to
18 * @param[in] func - Zone set property function pointer
19 *
20 * @return Lambda function
21 * A lambda function to set/update the zone property
22 */
23template <typename T>
24auto setZoneProperty(T (Zone::*func)(T), T&& value)
25{
26 return [func, value = std::forward<T>(value)](auto& zone)
27 {
28 (zone.*func)(value);
29 };
30}
31
32/**
Matthew Barth38a93a82017-05-11 14:12:27 -050033 * @brief A handler function to set/update a property
34 * @details Sets or updates a property's value determined by a combination of
35 * an object's path and property names
36 *
37 * @param[in] path - Object's path name
Matthew Barthcec5ab72017-06-02 15:20:56 -050038 * @param[in] interface - Object's interface name
Matthew Barth38a93a82017-05-11 14:12:27 -050039 * @param[in] property - Object's property name
40 *
41 * @return Lambda function
42 * A lambda function to set/update the property value
43 */
44template <typename T>
Matthew Barthcec5ab72017-06-02 15:20:56 -050045auto setProperty(const char* path, const char* interface, const char* property)
Matthew Barth38a93a82017-05-11 14:12:27 -050046{
47 return [=](auto& zone, T&& arg)
48 {
Matthew Barthcec5ab72017-06-02 15:20:56 -050049 zone.setPropertyValue(path, interface, property, std::forward<T>(arg));
Matthew Barth38a93a82017-05-11 14:12:27 -050050 };
51}
52
Matthew Barth8fa02da2017-09-28 12:18:20 -050053/**
54 * @brief A handler function to set/update service name owner state
55 * @details Sets or updates service name owner state used by a group where
56 * a service name without an owner represents the service no longer exists
57 *
58 * @param[in] group - Group associated with a service
59 *
60 * @return Lambda function
61 * A lambda function to set/update the service name owner state
62 */
63auto setService(Group&& group)
64{
65 return [group = std::move(group)](auto& zone, auto& name, bool hasOwner)
66 {
Matthew Barth5a302572017-10-03 11:27:06 -050067 // Update service name owner state list of a group
68 zone.setServiceOwner(&group, name, hasOwner);
Matthew Barth8fa02da2017-09-28 12:18:20 -050069 };
70}
71
Matthew Barth1499a5c2018-03-20 15:52:33 -050072/**
73 * @brief A handler function to remove an interface from an object path
74 * @details Removes an interface from an object's path which includes removing
75 * all properties that would be under that interface
76 *
77 * @param[in] path - Object's path name
78 * @param[in] interface - Object's interface name
79 *
80 * @return Lambda function
81 * A lambda function to remove the interface
82 */
83auto removeInterface(const char* path, const char* interface)
84{
85 return[=](auto& zone)
86 {
Matthew Barth30abbef2018-04-12 09:40:54 -050087 zone.removeObjectInterface(path, interface);
Matthew Barth1499a5c2018-03-20 15:52:33 -050088 };
89}
90
Matthew Barth38a93a82017-05-11 14:12:27 -050091} // namespace handler
92} // namespace control
93} // namespace fan
94} // namespace phosphor