blob: f66cb4deb78064eeec851e533739ccd43a5806f0 [file] [log] [blame]
James Feistdc7bbdc2019-05-16 15:33:06 -07001#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
8using Association = std::tuple<std::string, std::string, std::string>;
9
10constexpr const char* rootPath = "/xyz/openbmc_project/CallbackManager";
11constexpr const char* sensorPath = "/xyz/openbmc_project/sensors";
12
13constexpr const char* globalInventoryIface =
14 "xyz.openbmc_project.Inventory.Item.Global";
15constexpr const char* associationIface = "org.openbmc.Associations";
16
17namespace threshold
18{
19constexpr const char* critical = "critical";
20constexpr const char* warning = "warning";
21} // namespace threshold
22
23struct 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 setSensorAssociations(critical, warning);
65 association->set_property("associations", result);
66 }
67
68 void setSensorAssociations(const std::vector<std::string>& critical,
69 const std::vector<std::string>& warning)
70 {
71 std::set<Association> result;
72 for (const std::string& path : critical)
73 {
74 if (!boost::starts_with(path, sensorPath))
75 {
76 continue;
77 }
78 result.emplace(threshold::critical, "", path);
79 }
80 for (const std::string& path : warning)
81 {
82 if (!boost::starts_with(path, sensorPath))
83 {
84 continue;
85 }
86 result.emplace(threshold::warning, "", path);
87 }
88 sensorAssociation->set_property("associations", result);
89 }
90
91 sdbusplus::asio::object_server& objectServer;
92 std::shared_ptr<sdbusplus::asio::dbus_interface> association;
93 std::shared_ptr<sdbusplus::asio::dbus_interface> sensorAssociation;
94};