1 #pragma once 2 3 namespace phosphor 4 { 5 namespace fan 6 { 7 namespace control 8 { 9 namespace handler 10 { 11 12 /** 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] intf - Interface on zone object 18 * @param[in] prop - Property on interface 19 * @param[in] func - Zone set property function pointer 20 * @param[in] value - Value to set property to 21 * @param[in] persist - Persist property value or not 22 * 23 * @return Lambda function 24 * A lambda function to set/update the zone property 25 */ 26 template <typename T> 27 auto setZoneProperty(const char* intf, 28 const char* prop, 29 T (Zone::*func)(T), 30 T&& value, 31 bool persist) 32 { 33 return [=, value = std::forward<T>(value)](auto& zone) 34 { 35 (zone.*func)(value); 36 if (persist) 37 { 38 zone.setPersisted(intf, prop); 39 } 40 }; 41 } 42 43 /** 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 49 * @param[in] interface - Object's interface name 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> 56 auto setProperty(const char* path, const char* interface, const char* property) 57 { 58 return [=](auto& zone, T&& arg) 59 { 60 zone.setPropertyValue(path, interface, property, std::forward<T>(arg)); 61 }; 62 } 63 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 { 78 // Update service name owner state list of a group 79 zone.setServiceOwner(&group, name, hasOwner); 80 }; 81 } 82 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 { 98 zone.removeObjectInterface(path, interface); 99 }; 100 } 101 102 } // namespace handler 103 } // namespace control 104 } // namespace fan 105 } // namespace phosphor 106