James Feist | dc7bbdc | 2019-05-16 15:33:06 -0700 | [diff] [blame] | 1 | #pragma once |
| 2 | |
| 3 | #include <boost/algorithm/string/predicate.hpp> |
James Feist | dc7bbdc | 2019-05-16 15:33:06 -0700 | [diff] [blame] | 4 | #include <sdbusplus/asio/connection.hpp> |
| 5 | #include <sdbusplus/asio/object_server.hpp> |
| 6 | |
Jason M. Bills | 0d5c071 | 2020-12-08 10:10:47 -0800 | [diff] [blame] | 7 | #include <iostream> |
| 8 | |
James Feist | dc7bbdc | 2019-05-16 15:33:06 -0700 | [diff] [blame] | 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"; |
James Feist | 55d4eb5 | 2019-09-30 15:00:40 -0700 | [diff] [blame] | 16 | constexpr const char* associationIface = |
| 17 | "xyz.openbmc_project.Association.Definitions"; |
James Feist | dc7bbdc | 2019-05-16 15:33:06 -0700 | [diff] [blame] | 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 | { |
| 27 | 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 | { |
James Feist | 55d4eb5 | 2019-09-30 15:00:40 -0700 | [diff] [blame] | 34 | association->register_property("Associations", std::set<Association>()); |
| 35 | sensorAssociation->register_property("Associations", |
James Feist | dc7bbdc | 2019-05-16 15:33:06 -0700 | [diff] [blame] | 36 | std::set<Association>()); |
| 37 | association->initialize(); |
| 38 | sensorAssociation->initialize(); |
| 39 | } |
| 40 | ~AssociationManager() |
| 41 | { |
| 42 | objectServer.remove_interface(association); |
| 43 | objectServer.remove_interface(sensorAssociation); |
| 44 | } |
| 45 | |
| 46 | 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 | } |
James Feist | 55d4eb5 | 2019-09-30 15:00:40 -0700 | [diff] [blame] | 66 | association->set_property("Associations", result); |
James Feist | dc7bbdc | 2019-05-16 15:33:06 -0700 | [diff] [blame] | 67 | } |
| 68 | |
| 69 | 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 | } |
James Feist | 55d4eb5 | 2019-09-30 15:00:40 -0700 | [diff] [blame] | 89 | sensorAssociation->set_property("Associations", result); |
James Feist | dc7bbdc | 2019-05-16 15:33:06 -0700 | [diff] [blame] | 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; |
James Feist | 55d4eb5 | 2019-09-30 15:00:40 -0700 | [diff] [blame] | 95 | }; |