1 #pragma once 2 3 #include <boost/algorithm/string/predicate.hpp> 4 #include <sdbusplus/asio/connection.hpp> 5 #include <sdbusplus/asio/object_server.hpp> 6 7 #include <iostream> 8 9 using Association = std::tuple<std::string, std::string, std::string>; 10 11 constexpr const char* rootPath = "/xyz/openbmc_project/CallbackManager"; 12 constexpr const char* sensorPath = "/xyz/openbmc_project/sensors"; 13 14 constexpr const char* globalInventoryIface = 15 "xyz.openbmc_project.Inventory.Item.Global"; 16 constexpr const char* associationIface = 17 "xyz.openbmc_project.Association.Definitions"; 18 19 namespace threshold 20 { 21 constexpr const char* critical = "critical"; 22 constexpr const char* warning = "warning"; 23 } // namespace threshold 24 25 struct AssociationManager 26 { AssociationManagerAssociationManager27 AssociationManager(sdbusplus::asio::object_server& objectServer, 28 std::shared_ptr<sdbusplus::asio::connection>& conn) : 29 objectServer(objectServer), 30 association(objectServer.add_interface(rootPath, associationIface)), 31 sensorAssociation( 32 objectServer.add_interface(sensorPath, associationIface)) 33 { 34 association->register_property("Associations", std::set<Association>()); 35 sensorAssociation->register_property("Associations", 36 std::set<Association>()); 37 association->initialize(); 38 sensorAssociation->initialize(); 39 } ~AssociationManagerAssociationManager40 ~AssociationManager() 41 { 42 objectServer.remove_interface(association); 43 objectServer.remove_interface(sensorAssociation); 44 } 45 setLocalAssociationsAssociationManager46 void setLocalAssociations(const std::vector<std::string>& fatal, 47 const std::vector<std::string>& critical, 48 const std::vector<std::string>& warning) 49 { 50 std::set<Association> result; 51 52 // fatal maps to redfish critical as refish only has 3 states and LED 53 // has 4 54 for (const std::string& path : fatal) 55 { 56 result.emplace(threshold::critical, "", path); 57 } 58 for (const std::string& path : critical) 59 { 60 result.emplace(threshold::warning, "", path); 61 } 62 for (const std::string& path : warning) 63 { 64 result.emplace(threshold::warning, "", path); 65 } 66 association->set_property("Associations", result); 67 } 68 setSensorAssociationsAssociationManager69 void setSensorAssociations(const std::vector<std::string>& critical, 70 const std::vector<std::string>& warning) 71 { 72 std::set<Association> result; 73 for (const std::string& path : critical) 74 { 75 if (!boost::starts_with(path, sensorPath)) 76 { 77 continue; 78 } 79 result.emplace(threshold::critical, "", path); 80 } 81 for (const std::string& path : warning) 82 { 83 if (!boost::starts_with(path, sensorPath)) 84 { 85 continue; 86 } 87 result.emplace(threshold::warning, "", path); 88 } 89 sensorAssociation->set_property("Associations", result); 90 } 91 92 sdbusplus::asio::object_server& objectServer; 93 std::shared_ptr<sdbusplus::asio::dbus_interface> association; 94 std::shared_ptr<sdbusplus::asio::dbus_interface> sensorAssociation; 95 }; 96