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