blob: 292c30dc50832cfa21275f4b23cbcac6e3a77035 [file] [log] [blame]
Matt Spinler1962e082020-08-05 13:44:53 -05001#pragma once
2
3#include "data_interface.hpp"
4#include "pel.hpp"
5
6namespace openpower::pels::service_indicators
7{
8
9/**
10 * @class Policy
11 *
12 * The base class for service indicator policies.
13 */
14class Policy
15{
16 public:
17 Policy() = delete;
18 virtual ~Policy() = default;
19 Policy(const Policy&) = default;
20 Policy& operator=(const Policy&) = default;
21 Policy(Policy&&) = default;
22 Policy& operator=(Policy&&) = default;
23
24 /**
25 * @brief Constructor
26 *
27 * @param[in] dataIface - The DataInterface object
28 */
29 explicit Policy(const DataInterfaceBase& dataIface) : _dataIface(dataIface)
30 {
31 }
32
33 /**
34 * @brief Pure virtual function for activating service indicators
35 * based on PEL contents.
36 *
37 * @param[in] pel - The PEL
38 */
39 virtual void activate(const PEL& pel) = 0;
40
41 protected:
42 /**
43 * @brief Reference to the DataInterface object
44 */
45 const DataInterfaceBase& _dataIface;
46};
47
48/**
49 * @class LightPath
50 *
51 * This class implements the 'LightPath' IBM policy for
52 * activating LEDs. It has a set of rules to use to choose
53 * which callouts inside PELs should have their LEDs asserted,
54 * and then activates them by writing the Assert property on
55 * LED group D-Bus objects.
56 */
57class LightPath : public Policy
58{
59 public:
60 LightPath() = delete;
61 virtual ~LightPath() = default;
62 LightPath(const LightPath&) = default;
63 LightPath& operator=(const LightPath&) = default;
64 LightPath(LightPath&&) = default;
65 LightPath& operator=(LightPath&&) = default;
66
67 /**
68 * @brief Constructor
69 *
70 * @param[in] dataIface - The DataInterface object
71 */
72 explicit LightPath(const DataInterfaceBase& dataIface) : Policy(dataIface)
73 {
74 }
75
76 /**
77 * @brief Turns on LEDs for certain FRUs called out in the PEL.
78 *
79 * First it selectively chooses location codes listed in the FRU
80 * callout section that it wants to turn on LEDs for. Next it
81 * looks up the inventory D-Bus paths for the FRU represented by
82 * those location codes, and then looks for associations to the
83 * LED group objects for those inventory paths. After it has
84 * the LED group object, it sets the Asserted property on it.
85 *
86 * It only does the above for PELs that were created by the BMC
87 * or hostboot and have the Serviceable action flag set.
88 *
89 * If there are problems looking up any inventory path or LED
90 * group, then it will stop and not activate any LEDs at all.
91 *
92 * @param[in] pel - The PEL
93 */
94 void activate(const PEL& pel) override;
95
96 /**
Matt Spinler05f0c6d2020-08-05 14:21:06 -050097 * @brief Returns the location codes for the FRU callouts in the
98 * callouts list that need their LEDs turned on.
99 *
100 * This is public so it can be tested.
101 *
102 * @param[in] callouts - The Callout list from a PEL
103 *
104 * @return std::vector<std::string> - The location codes
Matt Spinler1962e082020-08-05 13:44:53 -0500105 */
106 std::vector<std::string> getLocationCodes(
107 const std::vector<std::unique_ptr<src::Callout>>& callouts) const;
108
109 /**
Matt Spinler05f0c6d2020-08-05 14:21:06 -0500110 * @brief Function called to check if the code even needs to
111 * bother looking in the callouts to find LEDs to turn on.
112 *
113 * It will ignore all PELs except for those created by the BMC or
114 * hostboot that have the Serviceable action flag set.
115 *
116 * This is public so it can be tested.
117 *
118 * @param[in] pel - The PEL
119 *
120 * @return bool - If the PEL should be ignored or not.
Matt Spinler1962e082020-08-05 13:44:53 -0500121 */
122 bool ignore(const PEL& pel) const;
123
124 private:
125 /**
126 * @brief Description TODO
127 */
128 std::vector<std::string>
129 getLEDGroupPaths(const std::vector<std::string>& locationCodes) const;
130
131 /**
132 * @brief Description TODO
133 */
134 void assertLEDs(const std::vector<std::string>& ledGroups) const;
Matt Spinler05f0c6d2020-08-05 14:21:06 -0500135
136 /**
137 * @brief Checks if the callout priority is one that the policy
138 * may turn on an LED for.
139 *
140 * The priorities it cares about are high, medium, and medium
141 * group A.
142 *
143 * @param[in] priority - The priority value from the PEL
144 *
145 * @return bool - If LightPath cares about a callout with this
146 * priority.
147 */
148 bool isRequiredPriority(uint8_t priority) const;
149
150 /**
151 * @brief Checks if the callout is either a normal FRU
152 * callout or a symbolic FRU callout with a trusted
153 * location code, which is one of the requirements for
154 * LightPath to turn on an LED.
155 *
156 * @param[in] - callout - The Callout object
157 *
158 * @return bool - If the callout is a hardware callout
159 */
160 bool isHardwareCallout(const src::Callout& callout) const;
Matt Spinler1962e082020-08-05 13:44:53 -0500161};
162
163/**
164 * @brief Returns the object for the service indicator policy
165 * implemented on the system.
166 *
167 * @param[in] dataIface - The DataInterface object
168 *
169 * @return std::unique_ptr<Policy> - The policy object
170 *
171 */
172std::unique_ptr<Policy> getPolicy(const DataInterfaceBase& dataIface);
173
174} // namespace openpower::pels::service_indicators