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