summaryrefslogtreecommitdiffstats
path: root/src/include/usr/hwpf/fapi/fapiReturnCodeDataRef.H
blob: 2bc468ba9d82638f20e0d82a346ce79e2086b2a2 (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
/* 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,2014              */
/*                                                                        */
/* 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 otherwise         */
/* divested of its trade secrets, irrespective of what has been           */
/* deposited with the U.S. Copyright Office.                              */
/*                                                                        */
/* Origin: 30                                                             */
/*                                                                        */
/* IBM_PROLOG_END_TAG                                                     */
// $Id: fapiReturnCodeDataRef.H,v 1.7 2013/10/15 13:13:38 dcrowell Exp $
// $Source: /afs/awd/projects/eclipz/KnowledgeBase/.cvsroot/eclipz/hwpf/working/fapi/fapiReturnCodeDataRef.H,v $

/**
 *  @file fapiReturnCodeDataRef.H
 *
 *  @brief Defines the ReturnCodeDataRef class that manages the data associated
 *         with a ReturnCode
 */

/*
 * 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
 *                          mjjones     09/22/2100  Added support for Error Info
 */

#ifndef FAPIRETURNCODEDATAREF_H_
#define FAPIRETURNCODEDATAREF_H_

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

namespace fapi
{

/**
 * @class ReturnCodeDataRef
 *
 * This class manages the data associated with a ReturnCode. A ReturnCode
 * contains a pointer to a ReturnCodeDataRef. When a ReturnCode is copied or
 * assigned, both ReturnCodes point to the same ReturnCodeDataRef (the data is
 * not copied) and the ReturnCodeDataRef reference count is incremented. When a
 * ReturnCode is destructed, the ReturnCodeDataRef reference count is
 * decremented and if zero, the ReturnCodeDataRef is deleted which deletes the
 * the data
 *
 * 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();

    /**
     * @brief Associate heap based PlatData (use-case is platform error log)
     *
     * Any existing PlatData is deleted
     *
     * @param[in] i_pPlatData Pointer to PlatData to associate
     */
    void setPlatData(void * i_pPlatData);

    /**
     * @brief Get a pointer to any PlatData. ReturnCodeDataRef 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
     */
    void * getPlatData() 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
     */
    void * releasePlatData();

    /**
     * @brief Get a pointer to any ErrorInfo
     *
     * @return ErrorInfo *. Pointer to ErrorInfo. If NULL then no info
     */
    ErrorInfo * getErrorInfo();

    /**
     * @brief Get a reference to the ErrorInfo. If there is no info then
     *        it is created (empty)
     *
     * @return ErrorInfo &. Reference to ErrorInfo.
     */
    ErrorInfo & getCreateErrorInfo();

#ifdef FAPI_CUSTOM_MALLOC
    /**
     * @brief Overload new operator to use platform-specific allocator
     *
     * @param[in] i_sz  Size of memory to allocate in bytes
     *
     * @return  Pointer to allocated memory
     */
    static void * operator new(size_t i_sz);

    /**
     * @brief Overload delete operator to use platform-specific deallocator
     *
     * @param[in] i_ptr Pointer to memory previously allocated with new
     */
    static void operator delete(void * i_ptr);
#endif

private:

    /**
     * @brief Delete any associated PlatData. Implemented by platform code
     *        because only platform code knows the type of the data.
     */
    void deletePlatData();

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

    // Pointer to associated PlatData
    void * iv_pPlatData;

    // Pointer to HWP Error Information 
    ErrorInfo * iv_pErrorInfo;
};

}

#endif // FAPIRETURNCODEDATAREF_H_
OpenPOWER on IntegriCloud