#pragma once #include "types.hpp" #include namespace phosphor { namespace fan { namespace control { class Zone; using namespace phosphor::logging; /** * @brief Create a handler function object * * @param[in] handler - The handler being created * * @return - The created handler function object */ template auto make_handler(T&& handler) { return Handler(std::forward(handler)); } /** * @brief Create an action function object * * @param[in] action - The action being created * * @return - The created action function object */ template auto make_action(T&& action) { return Action(std::forward(action)); } /** * @struct Property Changed * @brief A match filter functor for Dbus property value changed signals * * @tparam T - The type of the property value * @tparam U - The type of the handler */ template struct PropertyChanged { PropertyChanged() = delete; ~PropertyChanged() = default; PropertyChanged(const PropertyChanged&) = default; PropertyChanged& operator=(const PropertyChanged&) = default; PropertyChanged(PropertyChanged&&) = default; PropertyChanged& operator=(PropertyChanged&&) = default; PropertyChanged(const char* iface, const char* property, U&& handler) : _iface(iface), _property(property), _handler(std::forward(handler)) { } /** @brief Run signal handler function * * Extract the property from the PropertiesChanged * message and run the handler function. */ void operator()(sdbusplus::bus::bus&, sdbusplus::message::message& msg, Zone& zone) const { std::map> properties; const char* iface = nullptr; msg.read(iface); if (!iface || strcmp(iface, _iface)) { return; } msg.read(properties); auto it = properties.find(_property); if (it == properties.cend()) { log("Unable to find property on interface", entry("PROPERTY=%s", _property), entry("INTERFACE=%s", _iface)); return; } _handler(zone, std::forward(it->second.template get())); } private: const char* _iface; const char* _property; U _handler; }; /** * @brief Used to process a Dbus property changed signal event * * @param[in] iface - Sensor value interface * @param[in] property - Sensor value property * @param[in] handler - Handler function to perform * * @tparam T - The type of the property * @tparam U - The type of the handler */ template auto propertySignal(const char* iface, const char* property, U&& handler) { return PropertyChanged(iface, property, std::forward(handler)); } } // namespace control } // namespace fan } // namespace phosphor