1 #pragma once
2 
3 #include "callout.hpp"
4 #include "stream.hpp"
5 
6 namespace openpower
7 {
8 namespace pels
9 {
10 namespace src
11 {
12 
13 constexpr uint8_t calloutsSubsectionID = 0xC0;
14 constexpr size_t maxNumberOfCallouts = 10;
15 
16 /**
17  * @class Callouts
18  *
19  * This is an optional subsection of the SRC section in a PEL
20  * that holds callouts (represented as Callout objects).
21  * It is at the end of the SRC section, and there can only be one
22  * of these present in the SRC.
23  *
24  * If an SRC doesn't have any callouts, this object won't be created.
25  */
26 class Callouts
27 {
28   public:
29     ~Callouts() = default;
30     Callouts(const Callouts&) = delete;
31     Callouts& operator=(const Callouts&) = delete;
32     Callouts(Callouts&&) = delete;
33     Callouts& operator=(Callouts&&) = delete;
34 
35     /**
36      * @brief Constructor
37      *
38      * Creates the object with no callouts.
39      */
Callouts()40     Callouts() :
41         _subsectionID(calloutsSubsectionID), _subsectionFlags(0),
42         _subsectionWordLength(1)
43     {}
44 
45     /**
46      * @brief Constructor
47      *
48      * Fills in this class's data fields from the stream.
49      *
50      * @param[in] pel - the PEL data stream
51      */
52     explicit Callouts(Stream& pel);
53 
54     /**
55      * @brief Flatten the object into the stream
56      *
57      * @param[in] stream - The stream to write to
58      */
59     void flatten(Stream& pel) const;
60 
61     /**
62      * @brief Returns the size of this object when flattened into a PEL
63      *
64      * @return size_t - The size of the section
65      */
flattenedSize()66     size_t flattenedSize()
67     {
68         return _subsectionWordLength * 4;
69     }
70 
71     /**
72      * @brief Returns the contained callouts
73      *
74      * @return const std::vector<std::unique_ptr<Callout>>&
75      */
callouts() const76     const std::vector<std::unique_ptr<Callout>>& callouts() const
77     {
78         return _callouts;
79     }
80 
81     /**
82      * @brief Adds a callout
83      *
84      * @param[in] callout - The callout to add
85      */
86     void addCallout(std::unique_ptr<Callout> callout);
87 
88   private:
89     /**
90      * @brief The ID of this subsection, which is 0xC0.
91      */
92     uint8_t _subsectionID;
93 
94     /**
95      * @brief Subsection flags.  Always 0.
96      */
97     uint8_t _subsectionFlags;
98 
99     /**
100      * @brief Subsection length in 4B words.
101      *
102      * (Subsection is always a multiple of 4B)
103      */
104     uint16_t _subsectionWordLength;
105 
106     /**
107      * @brief The contained callouts
108      */
109     std::vector<std::unique_ptr<Callout>> _callouts;
110 };
111 
112 } // namespace src
113 
114 } // namespace pels
115 } // namespace openpower
116