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 | 59096e5 | 2019-02-18 12:23:38 -0600 | [diff] [blame^] | 27 | auto setZoneProperty(const char* intf, |
| 28 | const char* prop, |
| 29 | T (Zone::*func)(T), |
| 30 | T&& value, |
| 31 | bool persist) |
Matthew Barth | 1b3e960 | 2019-02-13 11:37:03 -0600 | [diff] [blame] | 32 | { |
Matthew Barth | 59096e5 | 2019-02-18 12:23:38 -0600 | [diff] [blame^] | 33 | return [=, value = std::forward<T>(value)](auto& zone) |
Matthew Barth | 1b3e960 | 2019-02-13 11:37:03 -0600 | [diff] [blame] | 34 | { |
| 35 | (zone.*func)(value); |
Matthew Barth | 59096e5 | 2019-02-18 12:23:38 -0600 | [diff] [blame^] | 36 | if (persist) |
| 37 | { |
| 38 | zone.setPersisted(intf, prop); |
| 39 | } |
Matthew Barth | 1b3e960 | 2019-02-13 11:37:03 -0600 | [diff] [blame] | 40 | }; |
| 41 | } |
| 42 | |
| 43 | /** |
Matthew Barth | 38a93a8 | 2017-05-11 14:12:27 -0500 | [diff] [blame] | 44 | * @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 Barth | cec5ab7 | 2017-06-02 15:20:56 -0500 | [diff] [blame] | 49 | * @param[in] interface - Object's interface name |
Matthew Barth | 38a93a8 | 2017-05-11 14:12:27 -0500 | [diff] [blame] | 50 | * @param[in] property - Object's property name |
| 51 | * |
| 52 | * @return Lambda function |
| 53 | * A lambda function to set/update the property value |
| 54 | */ |
| 55 | template <typename T> |
Matthew Barth | cec5ab7 | 2017-06-02 15:20:56 -0500 | [diff] [blame] | 56 | auto setProperty(const char* path, const char* interface, const char* property) |
Matthew Barth | 38a93a8 | 2017-05-11 14:12:27 -0500 | [diff] [blame] | 57 | { |
| 58 | return [=](auto& zone, T&& arg) |
| 59 | { |
Matthew Barth | cec5ab7 | 2017-06-02 15:20:56 -0500 | [diff] [blame] | 60 | zone.setPropertyValue(path, interface, property, std::forward<T>(arg)); |
Matthew Barth | 38a93a8 | 2017-05-11 14:12:27 -0500 | [diff] [blame] | 61 | }; |
| 62 | } |
| 63 | |
Matthew Barth | 8fa02da | 2017-09-28 12:18:20 -0500 | [diff] [blame] | 64 | /** |
| 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 | */ |
| 74 | auto setService(Group&& group) |
| 75 | { |
| 76 | return [group = std::move(group)](auto& zone, auto& name, bool hasOwner) |
| 77 | { |
Matthew Barth | 5a30257 | 2017-10-03 11:27:06 -0500 | [diff] [blame] | 78 | // Update service name owner state list of a group |
| 79 | zone.setServiceOwner(&group, name, hasOwner); |
Matthew Barth | 8fa02da | 2017-09-28 12:18:20 -0500 | [diff] [blame] | 80 | }; |
| 81 | } |
| 82 | |
Matthew Barth | 1499a5c | 2018-03-20 15:52:33 -0500 | [diff] [blame] | 83 | /** |
| 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 | */ |
| 94 | auto removeInterface(const char* path, const char* interface) |
| 95 | { |
| 96 | return[=](auto& zone) |
| 97 | { |
Matthew Barth | 30abbef | 2018-04-12 09:40:54 -0500 | [diff] [blame] | 98 | zone.removeObjectInterface(path, interface); |
Matthew Barth | 1499a5c | 2018-03-20 15:52:33 -0500 | [diff] [blame] | 99 | }; |
| 100 | } |
| 101 | |
Matthew Barth | 38a93a8 | 2017-05-11 14:12:27 -0500 | [diff] [blame] | 102 | } // namespace handler |
| 103 | } // namespace control |
| 104 | } // namespace fan |
| 105 | } // namespace phosphor |