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