blob: 522f3db79cc3f88a2fa636cb983417cc2d478a48 [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 /**
Matt Spinler34a904c2020-08-05 14:53:28 -0500126 * @brief Returns the LED group D-Bus paths to use to turn on the
127 * LEDs for the passed in location codes.
128 *
129 * @param[in] locationCodes - The location codes
130 *
131 * @return std::vector<std::string> - The LED group D-Bus paths
Matt Spinler1962e082020-08-05 13:44:53 -0500132 */
133 std::vector<std::string>
134 getLEDGroupPaths(const std::vector<std::string>& locationCodes) const;
135
136 /**
Matt Spinler34a904c2020-08-05 14:53:28 -0500137 * @brief Sets the Assert property on the LED group D-Bus objects
138 *
139 * @param[in] std::vector<std::string> - The LED group D-Bus paths
Matt Spinler1962e082020-08-05 13:44:53 -0500140 */
141 void assertLEDs(const std::vector<std::string>& ledGroups) const;
Matt Spinler05f0c6d2020-08-05 14:21:06 -0500142
143 /**
144 * @brief Checks if the callout priority is one that the policy
145 * may turn on an LED for.
146 *
147 * The priorities it cares about are high, medium, and medium
148 * group A.
149 *
150 * @param[in] priority - The priority value from the PEL
151 *
152 * @return bool - If LightPath cares about a callout with this
153 * priority.
154 */
155 bool isRequiredPriority(uint8_t priority) const;
156
157 /**
158 * @brief Checks if the callout is either a normal FRU
159 * callout or a symbolic FRU callout with a trusted
160 * location code, which is one of the requirements for
161 * LightPath to turn on an LED.
162 *
163 * @param[in] - callout - The Callout object
164 *
165 * @return bool - If the callout is a hardware callout
166 */
167 bool isHardwareCallout(const src::Callout& callout) const;
Matt Spinler1962e082020-08-05 13:44:53 -0500168};
169
170/**
171 * @brief Returns the object for the service indicator policy
172 * implemented on the system.
173 *
174 * @param[in] dataIface - The DataInterface object
175 *
176 * @return std::unique_ptr<Policy> - The policy object
177 *
178 */
179std::unique_ptr<Policy> getPolicy(const DataInterfaceBase& dataIface);
180
181} // namespace openpower::pels::service_indicators