summaryrefslogtreecommitdiffstats
path: root/src/usr/hwpf/fapi/fapiReturnCode.C
blob: 08cc048960263f63273d7b53334351d67bea51e0 (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
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
/**
 *  @file fapiReturnCode.C
 *
 *  @brief Implements the ReturnCode class.
 */

/*
 * 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 and
 *                                                  Error Target
 */

#include <fapiReturnCode.H>
#include <fapiReturnCodeDataRef.H>

namespace fapi
{

//******************************************************************************
// Default Constructor
//******************************************************************************
ReturnCode::ReturnCode() :
    iv_rcValue(FAPI_RC_SUCCESS), iv_pPlatDataRef(NULL), iv_pHwpFfdcRef(NULL),
    iv_pErrTarget(NULL)
{

}

//******************************************************************************
// Constructor
//******************************************************************************
ReturnCode::ReturnCode(const uint32_t i_rcValue) :
    iv_rcValue(i_rcValue), iv_pPlatDataRef(NULL), iv_pHwpFfdcRef(NULL),
    iv_pErrTarget(NULL)
{

}

//******************************************************************************
// Copy Constructor
//******************************************************************************
ReturnCode::ReturnCode(const ReturnCode & i_right) :
    iv_rcValue(i_right.iv_rcValue), iv_pPlatDataRef(i_right.iv_pPlatDataRef),
    iv_pHwpFfdcRef(i_right.iv_pHwpFfdcRef), iv_pErrTarget(NULL)
{
    // Note shallow copy of data ref pointers. Both ReturnCodes now point to the
    // same data

    // Increment the data ref counts and create a new copy of the error target
    if (iv_pPlatDataRef)
    {
        (void) iv_pPlatDataRef->incRefCount();
    }

    if (iv_pHwpFfdcRef)
    {
        (void) iv_pHwpFfdcRef->incRefCount();
    }

    if (i_right.iv_pErrTarget)
    {
        iv_pErrTarget = new Target(*i_right.iv_pErrTarget);
    }
}

//******************************************************************************
// Destructor
//******************************************************************************
ReturnCode::~ReturnCode()
{
    // Remove interest in any data references and delete any Error Target
    (void) removePlatData();
    (void) removeHwpFfdc();
    delete iv_pErrTarget;
}

//******************************************************************************
// Assignment Operator
//******************************************************************************
ReturnCode & ReturnCode::operator=(const ReturnCode & i_right)
{
    // Test for self assignment
    if (this != &i_right)
    {
        // Remove interest in any data references and delete any Error Target
        (void) removePlatData();
        (void) removeHwpFfdc();
        delete iv_pErrTarget;

        // Copy instance variables. Note shallow copy of data ref pointers. Both
        // ReturnCodes now point to the same data
        iv_rcValue = i_right.iv_rcValue;
        iv_pPlatDataRef = i_right.iv_pPlatDataRef;
        iv_pHwpFfdcRef = i_right.iv_pHwpFfdcRef;

        // Increment the data ref counts and create a new copy of the error tgt
        if (iv_pPlatDataRef)
        {
            (void) iv_pPlatDataRef->incRefCount();
        }

        if (iv_pHwpFfdcRef)
        {
            (void) iv_pHwpFfdcRef->incRefCount();
        }

        if (i_right.iv_pErrTarget)
        {
            iv_pErrTarget = new Target(*i_right.iv_pErrTarget);
        }
    }
    return *this;
}

//******************************************************************************
// Assignment Operator
//******************************************************************************
ReturnCode & ReturnCode::operator=(const uint32_t i_rcValue)
{
    iv_rcValue = i_rcValue;
    return *this;
}

//******************************************************************************
// ok function
//******************************************************************************
bool ReturnCode::ok() const
{
    return (iv_rcValue == FAPI_RC_SUCCESS);
}

//******************************************************************************
// returnCode_t cast
//******************************************************************************
ReturnCode::operator uint32_t() const
{
    return iv_rcValue;
}

//******************************************************************************
// getPlatData function
//******************************************************************************
void * ReturnCode::getPlatData() const
{
    void * l_pData = NULL;

    if (iv_pPlatDataRef)
    {
        // Get the data
        l_pData = iv_pPlatDataRef->getData();
    }

    return l_pData;
}

//******************************************************************************
// releasePlatData function
//******************************************************************************
void * ReturnCode::releasePlatData()
{
    void * l_pData = NULL;

    if (iv_pPlatDataRef)
    {
        // Release the data
        l_pData = iv_pPlatDataRef->releaseData();

        // Remove interest in ReturnCodePlatDataRef
        (void) removePlatData();
    }

    return l_pData;
}

//******************************************************************************
// setPlatData function
//******************************************************************************
void ReturnCode::setPlatData(void * i_pData)
{
    // Remove interest in ReturnCodePlatDataRef
    (void) removePlatData();

    // Create a new ReturnCodePlatDataRef which points to the data
    iv_pPlatDataRef = new ReturnCodePlatDataRef(i_pData);
}

//******************************************************************************
// getHwpFfdc function
//******************************************************************************
const void * ReturnCode::getHwpFfdc(uint32_t & o_size) const
{
    const void * l_pFfdc = NULL;

    if (iv_pHwpFfdcRef)
    {
        // Get the HwpFfdc
        l_pFfdc = iv_pHwpFfdcRef->getData(o_size);
    }

    return l_pFfdc;
}

//******************************************************************************
// setHwpFfdc function
//******************************************************************************
void ReturnCode::setHwpFfdc(const void * i_pFfdc, const uint32_t i_size)
{
    // Remove interest in ReturnCodeHwpFfdcRef
    (void) removeHwpFfdc();

    // Create a new ReturnCodeHwpFfdcRef which contains the HwpFfdc
    iv_pHwpFfdcRef = new ReturnCodeHwpFfdcRef(i_pFfdc, i_size);
}

//******************************************************************************
// getCreator function
//******************************************************************************
ReturnCode::returnCodeCreator ReturnCode::getCreator() const
{
    returnCodeCreator l_creator = CREATOR_HWP;

    if ((iv_rcValue & FAPI_RC_FAPI_MASK) || (iv_rcValue & FAPI_RC_ECMD_MASK))
    {
        l_creator = CREATOR_FAPI;
    }
    else if (iv_rcValue & FAPI_RC_PLAT_MASK)
    {
        l_creator = CREATOR_PLAT;
    }

    return l_creator;
}

//******************************************************************************
// setErrTarget function
//******************************************************************************
void ReturnCode::setErrTarget(const Target & i_target)
{
    if ((iv_rcValue != FAPI_RC_SUCCESS) && (iv_pErrTarget == NULL))
    {
        // Create a copy of the target
        iv_pErrTarget = new Target(i_target);
    }
}

//******************************************************************************
// getErrTarget function
//******************************************************************************
Target * ReturnCode::getErrTarget() const
{
    return iv_pErrTarget;
}

//******************************************************************************
// removePlatData function
//******************************************************************************
void ReturnCode::removePlatData()
{
    if (iv_pPlatDataRef)
    {
        // Decrement the ReturnCodePlatDataRef refcount
        if (iv_pPlatDataRef->decRefCountCheckZero())
        {
            // Refcount decremented to zero. No other ReturnCode points to the
            // ReturnCodePlatDataRef object, delete it
            delete iv_pPlatDataRef;
        }
        iv_pPlatDataRef = NULL;
    }
}

//******************************************************************************
// removeHwpFfdc function
//******************************************************************************
void ReturnCode::removeHwpFfdc()
{
    if (iv_pHwpFfdcRef)
    {
        // Decrement the ReturnCodeHwpFfdcRef refcount
        if (iv_pHwpFfdcRef->decRefCountCheckZero())
        {
            // Refcount decremented to zero. No other ReturnCode points to the
            // ReturnCodeHwpFfdcRef object, delete it
            delete iv_pHwpFfdcRef;
        }
        iv_pHwpFfdcRef = NULL;
    }
}

}
OpenPOWER on IntegriCloud