blob: 78a70a0349b9d8a5c76d1abc1aa75efe5f1ccf9c [file] [log] [blame]
James Feistdc7bbdc2019-05-16 15:33:06 -07001#pragma once
2
3#include <boost/algorithm/string/predicate.hpp>
James Feistdc7bbdc2019-05-16 15:33:06 -07004#include <sdbusplus/asio/connection.hpp>
5#include <sdbusplus/asio/object_server.hpp>
6
Jason M. Bills0d5c0712020-12-08 10:10:47 -08007#include <iostream>
8
James Feistdc7bbdc2019-05-16 15:33:06 -07009using Association = std::tuple<std::string, std::string, std::string>;
10
11constexpr const char* rootPath = "/xyz/openbmc_project/CallbackManager";
12constexpr const char* sensorPath = "/xyz/openbmc_project/sensors";
13
14constexpr const char* globalInventoryIface =
15 "xyz.openbmc_project.Inventory.Item.Global";
James Feist55d4eb52019-09-30 15:00:40 -070016constexpr const char* associationIface =
17 "xyz.openbmc_project.Association.Definitions";
James Feistdc7bbdc2019-05-16 15:33:06 -070018
19namespace threshold
20{
21constexpr const char* critical = "critical";
22constexpr const char* warning = "warning";
23} // namespace threshold
24
25struct 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 Feist55d4eb52019-09-30 15:00:40 -070034 association->register_property("Associations", std::set<Association>());
35 sensorAssociation->register_property("Associations",
James Feistdc7bbdc2019-05-16 15:33:06 -070036 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 Feist55d4eb52019-09-30 15:00:40 -070066 association->set_property("Associations", result);
James Feistdc7bbdc2019-05-16 15:33:06 -070067 }
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 Feist55d4eb52019-09-30 15:00:40 -070089 sensorAssociation->set_property("Associations", result);
James Feistdc7bbdc2019-05-16 15:33:06 -070090 }
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 Feist55d4eb52019-09-30 15:00:40 -070095};