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 | * |
| 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 | */ |
| 23 | template <typename T> |
| 24 | auto 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 Barth | 38a93a8 | 2017-05-11 14:12:27 -0500 | [diff] [blame] | 33 | * @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 Barth | cec5ab7 | 2017-06-02 15:20:56 -0500 | [diff] [blame] | 38 | * @param[in] interface - Object's interface name |
Matthew Barth | 38a93a8 | 2017-05-11 14:12:27 -0500 | [diff] [blame] | 39 | * @param[in] property - Object's property name |
| 40 | * |
| 41 | * @return Lambda function |
| 42 | * A lambda function to set/update the property value |
| 43 | */ |
| 44 | template <typename T> |
Matthew Barth | cec5ab7 | 2017-06-02 15:20:56 -0500 | [diff] [blame] | 45 | auto setProperty(const char* path, const char* interface, const char* property) |
Matthew Barth | 38a93a8 | 2017-05-11 14:12:27 -0500 | [diff] [blame] | 46 | { |
| 47 | return [=](auto& zone, T&& arg) |
| 48 | { |
Matthew Barth | cec5ab7 | 2017-06-02 15:20:56 -0500 | [diff] [blame] | 49 | zone.setPropertyValue(path, interface, property, std::forward<T>(arg)); |
Matthew Barth | 38a93a8 | 2017-05-11 14:12:27 -0500 | [diff] [blame] | 50 | }; |
| 51 | } |
| 52 | |
Matthew Barth | 8fa02da | 2017-09-28 12:18:20 -0500 | [diff] [blame] | 53 | /** |
| 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 | */ |
| 63 | auto setService(Group&& group) |
| 64 | { |
| 65 | return [group = std::move(group)](auto& zone, auto& name, bool hasOwner) |
| 66 | { |
Matthew Barth | 5a30257 | 2017-10-03 11:27:06 -0500 | [diff] [blame] | 67 | // Update service name owner state list of a group |
| 68 | zone.setServiceOwner(&group, name, hasOwner); |
Matthew Barth | 8fa02da | 2017-09-28 12:18:20 -0500 | [diff] [blame] | 69 | }; |
| 70 | } |
| 71 | |
Matthew Barth | 1499a5c | 2018-03-20 15:52:33 -0500 | [diff] [blame] | 72 | /** |
| 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 | */ |
| 83 | auto removeInterface(const char* path, const char* interface) |
| 84 | { |
| 85 | return[=](auto& zone) |
| 86 | { |
Matthew Barth | 30abbef | 2018-04-12 09:40:54 -0500 | [diff] [blame] | 87 | zone.removeObjectInterface(path, interface); |
Matthew Barth | 1499a5c | 2018-03-20 15:52:33 -0500 | [diff] [blame] | 88 | }; |
| 89 | } |
| 90 | |
Matthew Barth | 38a93a8 | 2017-05-11 14:12:27 -0500 | [diff] [blame] | 91 | } // namespace handler |
| 92 | } // namespace control |
| 93 | } // namespace fan |
| 94 | } // namespace phosphor |