summaryrefslogtreecommitdiffstats
path: root/src/usr/hwpf/fapi/fapiReturnCode.C
blob: 411177264089781a85f6ef8b06d28ed0350e8f4d (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
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
//  IBM_PROLOG_BEGIN_TAG
//  This is an automatically generated prolog.
//
//  $Source: src/usr/hwpf/fapi/fapiReturnCode.C $
//
//  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 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
 *                          camvanng    09/06/2011  Clear Plat Data, Hwp FFDC data,
 *                                                  and Error Target if
 *                                                  FAPI_RC_SUCCESS is assigned to
 *                                                  ReturnCode
 *                          mjjones     09/22/2011  Added ErrorInfo Support
 */

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

namespace fapi
{

//******************************************************************************
// Default Constructor
//******************************************************************************
ReturnCode::ReturnCode() :
    iv_rcValue(FAPI_RC_SUCCESS), iv_pDataRef(NULL)
{

}

//******************************************************************************
// Constructor
//******************************************************************************
ReturnCode::ReturnCode(const uint32_t i_rcValue) :
    iv_rcValue(i_rcValue), iv_pDataRef(NULL)
{

}

//******************************************************************************
// Copy Constructor
//******************************************************************************
ReturnCode::ReturnCode(const ReturnCode & i_right) :
    iv_rcValue(i_right.iv_rcValue), iv_pDataRef(i_right.iv_pDataRef)
{
    // Note shallow copy of data ref pointer. Both ReturnCodes now point to any
    // associated data. If there is data, increment the data ref count
    if (iv_pDataRef)
    {
        iv_pDataRef->incRefCount();
    }
}

//******************************************************************************
// Destructor
//******************************************************************************
ReturnCode::~ReturnCode()
{
    // Forget about any associated data
    forgetData();
}

//******************************************************************************
// Assignment Operator
//******************************************************************************
ReturnCode & ReturnCode::operator=(const ReturnCode & i_right)
{
    // Test for self assignment
    if (this != &i_right)
    {
        // Forget about any associated data
        forgetData();

        // Note shallow copy of data ref pointer. Both ReturnCodes now point to
        // any associated data. If there is data, increment the data ref count
        iv_rcValue = i_right.iv_rcValue;
        iv_pDataRef = i_right.iv_pDataRef;

        if (iv_pDataRef)
        {
            iv_pDataRef->incRefCount();
        }
    }

    return *this;
}

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

    if (iv_rcValue == FAPI_RC_SUCCESS)
    {
        // Forget about any associated data
        forgetData();
    }

    return *this;
}

//******************************************************************************
// resetError function
//******************************************************************************
void ReturnCode::resetError(const uint32_t i_rcValue)
{
    iv_rcValue = i_rcValue;

    // Forget about any associated data
    forgetData();
}

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

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

//******************************************************************************
// setPlatData function
//******************************************************************************
void ReturnCode::setPlatData(void * i_pData)
{
    ensureDataRefExists();
    iv_pDataRef->setPlatData(i_pData);
}

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

    if (iv_pDataRef)
    {
        l_pData = iv_pDataRef->getPlatData();
    }

    return l_pData;
}

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

    if (iv_pDataRef)
    {
        l_pData = iv_pDataRef->releasePlatData();
    }

    return l_pData;
}

//******************************************************************************
// addErrorInfo function
//******************************************************************************
void ReturnCode::addErrorInfo(const void * const * i_pObjects,
                              const ErrorInfoEntry * i_pEntries,
                              const uint8_t i_count)
{
    for (uint32_t i = 0; i < i_count; i++)
    {
        // Figure out the object of this entry
        const void * l_pObject = i_pObjects[i_pEntries[i].iv_object];

        if (i_pEntries[i].iv_type == EI_TYPE_FFDC)
        {
            // Get the size of the object to add as FFDC
            int8_t l_size = i_pEntries[i].iv_data1;

            if (l_size > 0)
            {
                // This is a regular FFDC data object that can be directly
                // memcopied
                FAPI_ERR("addErrorInfo: Adding FFDC, size: %d", l_size);
                addEIFfdc(l_pObject, l_size);
            }
            else
            {
                // This is a special FFDC data object
                if (l_size == ReturnCodeFfdc::EI_FFDC_SIZE_ECMDDB)
                {
                    // The FFDC is a ecmdDataBufferBase
                    FAPI_ERR("addErrorInfo: Adding ecmdDB FFDC");
                    const ecmdDataBufferBase * l_pDb =
                        static_cast<const ecmdDataBufferBase *>(l_pObject);
                    ReturnCodeFfdc::addEIFfdc(*this, *l_pDb);
                }
                else
                {
                    FAPI_ERR("addErrorInfo: Unrecognized FFDC data: %d",
                             l_size);
                }
            }
        }
        else if (i_pEntries[i].iv_type == EI_TYPE_CALLOUT)
        {
            // Get a pointer to the Target to callout and the priority
            const Target * l_pTarget = static_cast<const Target *>(l_pObject);
            CalloutPriority l_pri =
                static_cast<CalloutPriority>(i_pEntries[i].iv_data1);

            // Add the ErrorInfo
            FAPI_ERR("addErrorInfo: Adding callout, pri: %d", l_pri);
            addEICallout(*l_pTarget, l_pri);
        }
        else if (i_pEntries[i].iv_type == EI_TYPE_DECONF)
        {
            // Get a pointer to the Target to deconfigure
            const Target * l_pTarget = static_cast<const Target *>(l_pObject);

            // Add the ErrorInfo
            FAPI_ERR("addErrorInfo: Adding deconfigure");
            addEIDeconfigure(*l_pTarget);
        }
        else if (i_pEntries[i].iv_type == EI_TYPE_GARD)
        {
            // Get a pointer to the Target to create a GARD record for
            const Target * l_pTarget = static_cast<const Target *>(l_pObject);

            // Add the ErrorInfo
            FAPI_ERR("addErrorInfo: Adding GARD");
            addEIGard(*l_pTarget);
        }
        else
        {
            FAPI_ERR("addErrorInfo: Unrecognized EI type: %d",
                     i_pEntries[i].iv_type);
        }
    }
}

//******************************************************************************
// addEIFfdc function
//******************************************************************************
void ReturnCode::addEIFfdc(const void * i_pFfdc,
                           const uint32_t i_size)
{
    // Create a ErrorInfoFfdc object and add it to the Error Information
    FAPI_ERR("addEIFfdc: Adding FFDC, size: %d", i_size);
    ensureDataRefExists();
    ErrorInfoFfdc * l_pFfdc = new ErrorInfoFfdc(i_pFfdc, i_size);
    iv_pDataRef->getCreateErrorInfo().iv_ffdcs.push_back(l_pFfdc);
}


//******************************************************************************
// getErrorInfo function
//******************************************************************************
const ErrorInfo * ReturnCode::getErrorInfo() const
{
    ErrorInfo * l_pErrorInfo = NULL;

    if (iv_pDataRef != NULL)
    {
        l_pErrorInfo = iv_pDataRef->getErrorInfo();
    }

    return l_pErrorInfo;
}

//******************************************************************************
// 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;
}

//******************************************************************************
// ensureDataRefExists function
//******************************************************************************
void ReturnCode::ensureDataRefExists()
{
    if (!iv_pDataRef)
    {
        iv_pDataRef = new ReturnCodeDataRef();
    }
}

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

//******************************************************************************
// addEICallout function
//******************************************************************************
void ReturnCode::addEICallout(const Target & i_target,
                              const CalloutPriority i_priority)
{
    // Create a ErrorInfoCallout object and add it to the Error Information
    ensureDataRefExists();
    ErrorInfoCallout * l_pCallout = new ErrorInfoCallout(i_target, i_priority);
    iv_pDataRef->getCreateErrorInfo().iv_callouts.push_back(l_pCallout);
}

//******************************************************************************
// addEIDeconfigure function
//******************************************************************************
void ReturnCode::addEIDeconfigure(const Target & i_target)
{
    // Create a ErrorInfoDeconfig object and add it to the Error Information
    ensureDataRefExists();
    ErrorInfoDeconfig * l_pDeconfig = new ErrorInfoDeconfig(i_target);
    iv_pDataRef->getCreateErrorInfo().iv_deconfigs.push_back(l_pDeconfig);
}

//******************************************************************************
// addEIGard function
//******************************************************************************
void ReturnCode::addEIGard(const Target & i_target)
{
    // Create a ErrorInfoGard object and add it to the Error Information
    ensureDataRefExists();
    ErrorInfoGard * l_pGard = new ErrorInfoGard(i_target);
    iv_pDataRef->getCreateErrorInfo().iv_gards.push_back(l_pGard);
}

}
OpenPOWER on IntegriCloud