blob: 1cb61a9fc725b86c679e3dfb0296b414fb25f67b [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 Spinler993168d2021-04-07 16:05:03 -0500126 * @brief Returns the inventory D-Bus paths for the passed
127 * in location codes.
Matt Spinler34a904c2020-08-05 14:53:28 -0500128 *
129 * @param[in] locationCodes - The location codes
130 *
Matt Spinler993168d2021-04-07 16:05:03 -0500131 * @return std::vector<std::string> - The inventory D-Bus paths
Matt Spinler1962e082020-08-05 13:44:53 -0500132 */
133 std::vector<std::string>
Matt Spinler993168d2021-04-07 16:05:03 -0500134 getInventoryPaths(const std::vector<std::string>& locationCodes) const;
Matt Spinler1962e082020-08-05 13:44:53 -0500135
136 /**
Matt Spinler993168d2021-04-07 16:05:03 -0500137 * @brief Sets the Functional property on the passed in
138 * inventory paths to false.
Matt Spinler34a904c2020-08-05 14:53:28 -0500139 *
Matt Spinler993168d2021-04-07 16:05:03 -0500140 * There is code watching for this that will then turn on
141 * any LEDs for that FRU.
142 *
143 * @param[in] inventoryPaths - The inventory D-Bus paths
Matt Spinler1962e082020-08-05 13:44:53 -0500144 */
Matt Spinler993168d2021-04-07 16:05:03 -0500145 void setNotFunctional(const std::vector<std::string>& inventoryPaths) const;
Matt Spinler05f0c6d2020-08-05 14:21:06 -0500146
147 /**
Sumit Kumar76198a22021-07-15 05:59:57 -0500148 * @brief Sets the critical association on the passed in
149 * inventory paths.
150 *
151 * @param[in] inventoryPaths - The inventory D-Bus paths
152 */
153 void createCriticalAssociation(
154 const std::vector<std::string>& inventoryPaths) const;
155
156 /**
Matt Spinler05f0c6d2020-08-05 14:21:06 -0500157 * @brief Checks if the callout priority is one that the policy
158 * may turn on an LED for.
159 *
160 * The priorities it cares about are high, medium, and medium
161 * group A.
162 *
163 * @param[in] priority - The priority value from the PEL
164 *
165 * @return bool - If LightPath cares about a callout with this
166 * priority.
167 */
168 bool isRequiredPriority(uint8_t priority) const;
169
170 /**
171 * @brief Checks if the callout is either a normal FRU
172 * callout or a symbolic FRU callout with a trusted
173 * location code, which is one of the requirements for
174 * LightPath to turn on an LED.
175 *
176 * @param[in] - callout - The Callout object
177 *
178 * @return bool - If the callout is a hardware callout
179 */
180 bool isHardwareCallout(const src::Callout& callout) const;
Matt Spinler1962e082020-08-05 13:44:53 -0500181};
182
183/**
184 * @brief Returns the object for the service indicator policy
185 * implemented on the system.
186 *
187 * @param[in] dataIface - The DataInterface object
188 *
189 * @return std::unique_ptr<Policy> - The policy object
190 *
191 */
192std::unique_ptr<Policy> getPolicy(const DataInterfaceBase& dataIface);
193
194} // namespace openpower::pels::service_indicators