blob: 490e5961a59f421ff15b4d1e28bc2ca0dd8911d5 [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";
James Feist55d4eb52019-09-30 15:00:40 -070015constexpr const char* associationIface =
16 "xyz.openbmc_project.Association.Definitions";
James Feistdc7bbdc2019-05-16 15:33:06 -070017
18namespace threshold
19{
20constexpr const char* critical = "critical";
21constexpr const char* warning = "warning";
22} // namespace threshold
23
24struct AssociationManager
25{
26 AssociationManager(sdbusplus::asio::object_server& objectServer,
27 std::shared_ptr<sdbusplus::asio::connection>& conn) :
28 objectServer(objectServer),
29 association(objectServer.add_interface(rootPath, associationIface)),
30 sensorAssociation(
31 objectServer.add_interface(sensorPath, associationIface))
32 {
James Feist55d4eb52019-09-30 15:00:40 -070033 association->register_property("Associations", std::set<Association>());
34 sensorAssociation->register_property("Associations",
James Feistdc7bbdc2019-05-16 15:33:06 -070035 std::set<Association>());
36 association->initialize();
37 sensorAssociation->initialize();
38 }
39 ~AssociationManager()
40 {
41 objectServer.remove_interface(association);
42 objectServer.remove_interface(sensorAssociation);
43 }
44
45 void setLocalAssociations(const std::vector<std::string>& fatal,
46 const std::vector<std::string>& critical,
47 const std::vector<std::string>& warning)
48 {
49 std::set<Association> result;
50
51 // fatal maps to redfish critical as refish only has 3 states and LED
52 // has 4
53 for (const std::string& path : fatal)
54 {
55 result.emplace(threshold::critical, "", path);
56 }
57 for (const std::string& path : critical)
58 {
59 result.emplace(threshold::warning, "", path);
60 }
61 for (const std::string& path : warning)
62 {
63 result.emplace(threshold::warning, "", path);
64 }
James Feist55d4eb52019-09-30 15:00:40 -070065 association->set_property("Associations", result);
James Feistdc7bbdc2019-05-16 15:33:06 -070066 }
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 }
James Feist55d4eb52019-09-30 15:00:40 -070088 sensorAssociation->set_property("Associations", result);
James Feistdc7bbdc2019-05-16 15:33:06 -070089 }
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;
James Feist55d4eb52019-09-30 15:00:40 -070094};