summaryrefslogtreecommitdiffstats
path: root/extensions/openpower-pels/callout.hpp
blob: caf3aec6b77042679569cbbaad8381d9d91fbc2b (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
#pragma once

#include "fru_identity.hpp"
#include "mru.hpp"
#include "pce_identity.hpp"
#include "stream.hpp"

namespace openpower
{
namespace pels
{
namespace src
{

/**
 * @class Callout
 *
 * Represents a single FRU callout in the SRC's FRU callout
 * subsection.
 *
 * The 'Callouts' class holds a list of these objects.
 *
 * The callout priority and location code are in this structure.
 *
 * There can also be up to one each of three types of substructures
 * in a single callout:
 *  * FRU Identity  (must be first if present)
 *  * Power Controlling Enclosure (PCE)
 *  * Manufacturing Replaceable Unit (MRU)
 *
 * These substructures have their own objects managed by unique_ptrs
 * which will only be allocated if those substructures exist.
 */
class Callout
{
  public:
    Callout() = delete;
    ~Callout() = default;
    Callout(const Callout&) = delete;
    Callout& operator=(const Callout&) = delete;
    Callout(Callout&&) = delete;
    Callout& operator=(Callout&&) = delete;

    /**
     * @brief Constructor
     *
     * Fills in this class's data fields from the stream.
     *
     * @param[in] pel - the PEL data stream
     */
    explicit Callout(Stream& pel);

    /**
     * @brief Returns the size of this object when flattened into a PEL
     *
     * @return size_t - The size of the section
     */
    size_t flattenedSize();

    /**
     * @brief Flatten the object into the stream
     *
     * @param[in] stream - The stream to write to
     */
    void flatten(Stream& pel) const;

    /**
     * @brief Returns the flags field of a callout
     *
     * @return uint8_t - The flags
     */
    uint8_t flags() const
    {
        return _flags;
    }

    /**
     * @brief Returns the priority field of a callout
     *
     * @return uint8_t - The priority
     */
    uint8_t priority() const
    {
        return _priority;
    }

    /**
     * @brief Returns the location code of the callout
     *
     * @return std::string - The location code
     */
    std::string locationCode() const
    {
        std::string lc;
        if (!_locationCode.empty())
        {
            // NULL terminated
            lc = static_cast<const char*>(_locationCode.data());
        }
        return lc;
    }

    /**
     * @brief Returns the FRU identity substructure
     *
     * @return const std::unique_ptr<FRUIdentity>&
     */
    const std::unique_ptr<FRUIdentity>& fruIdentity() const
    {
        return _fruIdentity;
    }

    /**
     * @brief Returns the PCE identity substructure
     *
     * @return const std::unique_ptr<PCEIdentity>&
     */
    const std::unique_ptr<PCEIdentity>& pceIdentity() const
    {
        return _pceIdentity;
    }

    /**
     * @brief Returns the MRU identity substructure
     *
     * @return const std::unique_ptr<FRUIdentity>&
     */
    const std::unique_ptr<MRU>& mru() const
    {
        return _mru;
    }

  private:
    /**
     * @brief The size of this structure in the PEL
     */
    uint8_t _size;

    /**
     * @brief The flags byte of this structure
     */
    uint8_t _flags;

    /**
     * @brief The replacement priority
     */
    uint8_t _priority;

    /**
     * @brief The length of the location code field.
     *
     * Includes the NULL termination, and must be a
     * multiple of 4 (padded with zeros)
     */
    uint8_t _locationCodeSize;

    /**
     * @brief NULL terminated location code
     *
     * Includes the NULL termination, and must be a
     * multiple of 4 (padded with zeros)
     */
    std::vector<char> _locationCode;

    /**
     * @brief FRU (Field Replaceable Unit) Identity substructure
     */
    std::unique_ptr<FRUIdentity> _fruIdentity;

    /**
     * @brief PCE (Power Controlling Enclosure) Identity substructure
     */
    std::unique_ptr<PCEIdentity> _pceIdentity;

    /**
     * @brief MRU (Manufacturing Replaceable Unit) substructure
     */
    std::unique_ptr<MRU> _mru;
};

} // namespace src
} // namespace pels
} // namespace openpower
OpenPOWER on IntegriCloud