Matthew Barth | baeeb8f | 2021-05-13 16:03:54 -0500 | [diff] [blame^] | 1 | #pragma once |
| 2 | |
| 3 | #include "../manager.hpp" |
| 4 | |
| 5 | #include <sdbusplus/message.hpp> |
| 6 | |
| 7 | #include <algorithm> |
| 8 | #include <map> |
| 9 | #include <tuple> |
| 10 | #include <vector> |
| 11 | |
| 12 | namespace phosphor::fan::control::json::trigger::signal |
| 13 | { |
| 14 | |
| 15 | using namespace sdbusplus::message; |
| 16 | |
| 17 | struct Handlers |
| 18 | { |
| 19 | |
| 20 | public: |
| 21 | /** |
| 22 | * @brief Processes a properties changed signal and updates the property's |
| 23 | * value in the manager's object cache |
| 24 | * |
| 25 | * @param[in] msg - The sdbusplus signal message |
| 26 | * @param[in] obj - Object data associated with the signal |
| 27 | * @param[in] mgr - Manager that stores the object cache |
| 28 | */ |
| 29 | static bool propertiesChanged(message& msg, const SignalObject& obj, |
| 30 | Manager& mgr) |
| 31 | { |
| 32 | std::string intf; |
| 33 | msg.read(intf); |
| 34 | if (intf != std::get<Intf>(obj)) |
| 35 | { |
| 36 | // Interface name does not match object's interface |
| 37 | return false; |
| 38 | } |
| 39 | |
| 40 | std::map<std::string, PropertyVariantType> props; |
| 41 | msg.read(props); |
| 42 | auto itProp = props.find(std::get<Prop>(obj)); |
| 43 | if (itProp == props.cend()) |
| 44 | { |
| 45 | // Object's property not in dictionary of properties changed |
| 46 | return false; |
| 47 | } |
| 48 | |
| 49 | mgr.setProperty(std::get<Path>(obj), std::get<Intf>(obj), |
| 50 | std::get<Prop>(obj), itProp->second); |
| 51 | return true; |
| 52 | } |
| 53 | }; |
| 54 | |
| 55 | } // namespace phosphor::fan::control::json::trigger::signal |