blob: 36eacf88f6a583f214e78c465dc9ae0f14b924f3 [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 /**
97 * @brief Description TODO
98 */
99 std::vector<std::string> getLocationCodes(
100 const std::vector<std::unique_ptr<src::Callout>>& callouts) const;
101
102 /**
103 * @brief Description TODO
104 */
105 bool ignore(const PEL& pel) const;
106
107 private:
108 /**
109 * @brief Description TODO
110 */
111 std::vector<std::string>
112 getLEDGroupPaths(const std::vector<std::string>& locationCodes) const;
113
114 /**
115 * @brief Description TODO
116 */
117 void assertLEDs(const std::vector<std::string>& ledGroups) const;
118};
119
120/**
121 * @brief Returns the object for the service indicator policy
122 * implemented on the system.
123 *
124 * @param[in] dataIface - The DataInterface object
125 *
126 * @return std::unique_ptr<Policy> - The policy object
127 *
128 */
129std::unique_ptr<Policy> getPolicy(const DataInterfaceBase& dataIface);
130
131} // namespace openpower::pels::service_indicators