summaryrefslogtreecommitdiffstats
path: root/src/include/usr/hwpf/fapi/fapiReturnCodeDataRef.H
blob: 866dc0737b2770603f4858b541a950e7c2b0ce01 (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
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
//  IBM_PROLOG_BEGIN_TAG
//  This is an automatically generated prolog.
//
//  $Source: src/include/usr/hwpf/fapi/fapiReturnCodeDataRef.H $
//
//  IBM CONFIDENTIAL
//
//  COPYRIGHT International Business Machines Corp. 2011
//
//  p1
//
//  Object Code Only (OCO) source materials
//  Licensed Internal Code Source Materials
//  IBM HostBoot Licensed Internal Code
//
//  The source code for this program is not published or other-
//  wise divested of its trade secrets, irrespective of what has
//  been deposited with the U.S. Copyright Office.
//
//  Origin: 30
//
//  IBM_PROLOG_END
/**
 *  @file fapiReturnCodeDataRef.H
 *
 *  @brief Defines the ReturnCodeDataRef class that provides a pointer and a
 *         reference count to a platform specific ReturnCodeData object.
 */

/*
 * Change Log ******************************************************************
 * Flag     Defect/Feature  User        Date        Description
 * ------   --------------  ----------  ----------- ----------------------------
 *                          mjjones     04/13/2011  Created.
 *                          mjjones     07/05/2011. Removed const from data
 *                          mjjones     07/25/2011  Added support for FFDC
 */

#ifndef FAPIRETURNCODEDATAREF_H_
#define FAPIRETURNCODEDATAREF_H_

#include <stdint.h>
#include <stddef.h>

namespace fapi
{

/**
 * @class ReturnCodeDataRef
 *
 * This class is a simple reference counter. Derived classes are used by a
 * ReturnCode object in order to maintain a count of how many ReturnCode objects
 * have a reference to the object.
 *
 * A ReturnCodeDataRef object is not thread safe, multiple threads must not use
 * the same ReturnCodeDataRef object concurrently.
 */
class ReturnCodeDataRef
{
public:

    /**
     * @brief Constructor
     */
    ReturnCodeDataRef();

    /**
     * @brief Destructor
     */
    virtual ~ReturnCodeDataRef();

    /**
     * @brief Increments the ref count
     */
    void incRefCount();

    /**
     * @brief Decrements the ref count
     *
     * @return bool True if zero reached
     */
    bool decRefCountCheckZero();

private:

    // Copy constructor and assignment operator disabled
    ReturnCodeDataRef(const ReturnCodeDataRef & i_right);
    ReturnCodeDataRef & operator=(const ReturnCodeDataRef & i_right);

    // The reference count (how many ReturnCodes are pointing to this object)
    uint32_t iv_refCount;
};

/**
 * @class ReturnCodePlatDataRef
 *
 * This class contains a pointer to PlatData and inherits from ReturnCodeDataRef
 * for a reference count recording how many ReturnCodes have a pointer to it.
 *
 * It is used exclusively by the ReturnCode class. Multiple copies of a
 * ReturnCode will all point to the same ReturnCodePlatDataRef. The ReturnCodes
 * maintain the reference count, the last ReturnCode to remove its reference
 * will delete the ReturnCodePlatDataRef which in turn deletes the PlatData.
 * The PlatData pointer is maintained in this class so that releasing the data
 * releases it from all ReturnCode copies.
 *
 * A ReturnCodePlatDataRef object is not thread safe, multiple threads must not
 * use the same ReturnCodePlatDataRef object concurrently.
 */
class ReturnCodePlatDataRef : public ReturnCodeDataRef
{
public:

    /**
     * @brief Constructor
     *
     * @param[in] i_pData Pointer to PlatData to associate
     */
    explicit ReturnCodePlatDataRef(void * i_pData);

    /**
     * @brief Destructor
     */
    virtual ~ReturnCodePlatDataRef();

    /**
     * @brief Get a pointer to any PlatData. ReturnCodePlatDataRef is still
     *        responsible for deletion of the data. The caller must not delete
     *
     * The pointer is only meaningful to platform code.
     *
     * @return void *. Pointer to PlatData. If NULL then no data (must have been
     *                 released)
     */
    void * getData() const;

    /**
     * @brief Get a pointer to any PlatData and release ownership from
     *        ReturnCodeDataRef. The caller is responsible for deletion.
     *
     * The pointer is only meaningful to platform code.
     *
     * @return void *. Pointer to PlatData. If NULL then no data (must have been
     *                 released)
     */
    void * releaseData();

private:

    // Copy constructor and assignment operator disabled
    ReturnCodePlatDataRef(const ReturnCodePlatDataRef & i_right);
    ReturnCodePlatDataRef & operator=(const ReturnCodePlatDataRef & i_right);

    /**
     * @brief Deletes the PlatData
     *
     * @note Implemented by platform code because only platform code knows the
     *       type of the data and how to delete it.
     */
    void deleteData();

    // Pointer to PlatData
    void * iv_pData;
};

/**
 * @class ReturnCodeHwpFfdcRef
 *
 * This class contains HwpFfdc and inherits from ReturnCodeDataRef for a
 * reference count recording how many ReturnCodes have a pointer to it.
 *
 * It is used exclusively by the ReturnCode class. Multiple copies of a
 * ReturnCode will all point to the same ReturnCodeHwpFfdcRef. The ReturnCodes
 * maintain the reference count, the last ReturnCode to remove its reference
 * will delete the ReturnCodeHwpFfdcRef which in turn deletes the contained
 * HwpFfdc.
 *
 * A ReturnCodeHwpFfdcRef object is not thread safe, multiple threads must not
 * use the same ReturnCodeHwpFfdcRef object concurrently.
 */
class ReturnCodeHwpFfdcRef : public ReturnCodeDataRef
{
public:

    /**
     * @brief Constructor
     *
     * @param[in] i_pFfdc Pointer to the FFDC to copy
     * @param[in] i_size  Size of the FFDC to copy
     */
    ReturnCodeHwpFfdcRef(const void * i_pFfdc,
                         const uint32_t i_size);

    /**
     * @brief Destructor
     */
    virtual ~ReturnCodeHwpFfdcRef();

    /**
     * @brief Get a pointer to the HwpFfdc.
     *
     * @param[out] o_size Size of the FFDC data in bytes.
     *
     * @return void *. Pointer to HwpFfdc.
     */
    const void * getData(uint32_t & o_size) const;

private:

    // Copy constructor and assignment operator disabled
    ReturnCodeHwpFfdcRef(const ReturnCodeHwpFfdcRef & i_right);
    ReturnCodeHwpFfdcRef & operator=(const ReturnCodeHwpFfdcRef & i_right);

    // Pointer to HwpFfdc
    uint8_t * iv_pFfdc;

    // Size of HwpFfdc
    uint32_t iv_size;
};

}

#endif // FAPIRETURNCODEDATAREF_H_
OpenPOWER on IntegriCloud