summaryrefslogtreecommitdiffstats
path: root/src/usr/diag/prdf/common/util/prdfErrlSmartPtr.H
blob: 3fad9672887dd80ec143e0acb8900ee4e4fa7cac (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
/* IBM_PROLOG_BEGIN_TAG                                                   */
/* This is an automatically generated prolog.                             */
/*                                                                        */
/* $Source: src/usr/diag/prdf/common/util/prdfErrlSmartPtr.H $            */
/*                                                                        */
/* IBM CONFIDENTIAL                                                       */
/*                                                                        */
/* COPYRIGHT International Business Machines Corp. 2003,2013              */
/*                                                                        */
/* 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                                                     */

#ifndef __PRDFERRLSMARTPTR_H
#define __PRDFERRLSMARTPTR_H

#include <errlentry.H>
#include <prdf_service_codes.H>

namespace PRDF
{
/**
 * @class ErrlSmartPtr
 *        This is a smart pointer class for errlHndl_t objects, especially for
 *        the g_prd_errl variable.  Currently, programmers can accidentially
 *        overwrite g_prd_errl and we leak a error log.  This class will keep
 *        track of the error logs and commit/delete it if it goes out of context.
 */
class ErrlSmartPtr
{
    public:

        class INVALID_TYPE_CONVERSION___SEE_COMMENTS_FOR_RELEASE_FUNCTION {};

        /* ctor - Initialize ptr to NULL */
        ErrlSmartPtr() : iv_errl(NULL) {};
        /* dtor - Commit remaining error log */
        ~ErrlSmartPtr() { commit_errl(); };

        /* operator =
         *        Someone attempted to overwrite the error log, commit if needed.
         */
        ErrlSmartPtr & operator=(errlHndl_t i_errl)
            {
                this->commit_errl();
                iv_errl = i_errl;

                return *this;
            };

        /* operator ->
         *        Used to do standard errlHndl_t->func() operations:
         *                errl->commit().
         */
        errlHndl_t operator->() const
            {
                return iv_errl;
            };

        /* operator*
         *        Used when dereferencing the errlHndl_t, for instance to get
         *        at the rc value:
         *                (uint32_t) *errl;
         */
        #ifdef __HOSTBOOT_MODULE
        ERRORLOG::ErrlEntry& operator*() const
        #else
        ErrlEntry& operator*() const
        #endif
            {
                return *iv_errl;
            };

        /* operator ==
         *        Compare with NULL or other ptr values:
         *                if (errl == NULL)...
         */
        bool operator==(const errlHndl_t i_errl) const
            {
                return iv_errl == i_errl;
            };

        /* operator !=
         *        Compare with NULL or other ptr values:
         *                if (errl != NULL)...
         */
        bool operator!=(const errlHndl_t i_errl) const
            {
                return iv_errl != i_errl;
            };

        /* friend operator ==
         *        Compare with NULL or other ptr values:
         *                if (NULL == errl)
         */
        friend bool operator==(const errlHndl_t i_errl,
                        const ErrlSmartPtr & i_smrtptr)
            {
                return i_smrtptr == i_errl;
            };

        /* friend operator =!
         *        Compare with NULL or other ptr values:
         *                if (NULL =! errl)
         */
        friend bool operator!=(const errlHndl_t i_errl,
                        const ErrlSmartPtr & i_smrtptr)
            {
                return i_smrtptr != i_errl;
            };

        /* operator errlHndl_t
         *        Cast to errlHndl_t object.  (needed?)
         */
        operator errlHndl_t()
            {
                return iv_errl;
            };

        operator INVALID_TYPE_CONVERSION___SEE_COMMENTS_FOR_RELEASE_FUNCTION *()
            {
                return NULL;
            };

        /* errlHndl_t release
         *        Used when error log is leaving PRD's context (returned to
         *        cecserver):
         *                return errl.release();
         *        instead of:
         *                return errl;
         *
         *        Or, to delete the error log:
         *                delete errl.release();
         *
         *        This prevent the error log from being deleted twice or commited
         *        by the wrong component.
         */
        errlHndl_t release()
            {
                errlHndl_t l_tmp = iv_errl;
                iv_errl = NULL;
                return l_tmp;
            };

    protected:
        errlHndl_t iv_errl;

        /* void add_src()
         *         Add special SRC to error log specifying commited from smart
         *         pointer.
         */
        void add_src();

        /* void commit_errl()
         *        Commit error log and delete.
         */
        void commit_errl();

};

} // end namespace PRDF

#endif
OpenPOWER on IntegriCloud