summaryrefslogtreecommitdiffstats
path: root/src/include/usr/errl/parser/errlparserbase.H
blob: b5074f2d5d8f5656e64ccbc78df6158f4c9d457b (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
//  IBM_PROLOG_BEGIN_TAG
//  This is an automatically generated prolog.
//
//  $Source: src/include/usr/errl/parser/errlparserbase.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
#ifndef ERRL_ERRLPARSERBASE_H
#define ERRL_ERRLPARSERBASE_H

/**
 *  @file errlparserbase.H
 *
 *  @brief Base class for parser routines
 *
 *  pulled from fips740/ .. /src/errl/fsp/errlparser.H
 *
 * @note
 *  There are many more routines in fips code to print out specialty
 *  fields and such, these are not used presently and IMHO should be in
 *  their own file.
 *  Leave out for now.
 *
 */


/*****************************************************************************/
// I n c l u d e s
/*****************************************************************************/
#include <stdint.h>
#include <stdlib.h>
#include <stdio.h>
#include <netinet/in.h>             // network byte-swapping routines.
// Unavoidable include for va_list
#include <cstdarg>

#include <errl/hberrltypes.H>

/*****************************************************************************/
//  Typedefs
/*****************************************************************************/
/**
 * @struct  BCD_time8_t
 *
 * pulled from fips740/ .. /src/rtim/fsp/rtim.H
 */
struct BCD_time8_t
{
  uint16_t year;
  uint8_t  month;
  uint8_t  day;
  uint8_t  hours;
  uint8_t  minutes;
  uint8_t  seconds;
  uint8_t  hundredths;
}  __attribute__ ((packed));



/*****************************************************************************/
// User Types
/*****************************************************************************/
class ErrlParser
{
public:


    /**
     *  @brief Build an associated parser object
     *
     *  Builds an associated parser object which is tied to the
     *  given stream.  The net effect is the addition of some
     *  simple methods to standardize log output
     *
     *  @param	i_output
     *	    Stream to be used for output, defaults to stdout
     *
     */
    ErrlParser(
            FILE *		    i_output = stdout
    );


    /**
     *  @brief Cleanup handler
     *
     *  Currently no-op
     *
     */
    virtual ~ErrlParser();


    /**
     *  @brief Set Stream pointer
     *
     *  Changes the output stream pointer which ultimately
     *  determines what OS device receives the data
     *
     *  @param	i_val
     *	    Output stream
     *
     *	@note	The stream handle is not owned by this object
     *	        and will therefore not be released automatically
     *
     */
    void setStream( FILE * i_val )
    {
        iv_Stream = i_val;
    }


    /**
     *  @brief Display a standard parser message
     *
     *  Displays the a message in the error log parser
     *  format of "Label: Desc"
     *
     *  @param	i_label
     *	    Label for the message
     *
     *  @param	i_string
     *	    Description string
     *
     */
    virtual void PrintString(
            const char * i_label,
            const char * i_string
    ) = 0;


    /**
     *  @brief Output a standard message for numeric data
     *
     *  A message consisting of the label and a hex formatted
     *  number is forwarded to the PrintString interface
     *
     *  @param	i_label
     *	    Left-hand label for the data
     *
     *  @param	i_fmt
     *	    Numeric format used to parse the data value
     *
     *  @param	i_value
     *	    Numberic value
     *
     *  @note Current implementation templates the output
     *        to PrintString after generating a string
     *        of the proper type.
     */
    virtual void PrintNumber(
            const char * i_label,
            const char * i_fmt,
            uint32_t     i_value
    );


    /**
     *  @brief Classical Hex dump of data
     *
     *  A 5 column output consisting of an offset, 4 hex words,
     *  and an ascii equivalent will be dumped in big endian
     *  mode
     *
     *  @param	i_data
     *	    Pointer to data buffer
     *
     *  @param	i_len
     *	    Length of data in bytes
     *
     */
    virtual void PrintHexDump(
            const void * i_data,
            uint32_t     i_len
    ) = 0;


protected:
    /**
     *  @brief Load a message string.
     *
     *  FSP allows this to reference a message file.  This is pulled out
     *  here, perhaps can be added later if needed.
     *
     *  @param  i_MsgId
     *      Message Identifier ( see errllang.H )
     *
     *  @return Constant pointer to the message string
     *
     *  @note The message is static and should not be modified by
     *        the caller.
     *
     */
    const char * LoadMsg( const char * i_MsgId )    const
    {
    return i_MsgId;
    }


    /**
     * @brief endian switch a uint64
     *
     * @param[in]   i_value
     *      uint64_t value to be byteswapped
     *
     *  @return byte-swapped uint64_t value
     *
     */
    uint64_t ntohll( uint64_t i )   const
    {
        uint64_t hi;
        uint64_t lo;
        uint32_t * pword = reinterpret_cast<uint32_t*>(&i);

        hi = ntohl( *pword );
        lo = ntohl( *(pword+1) );

        return (hi<<32)|lo;
    }


    // Data
    FILE *	iv_Stream;	    ///< Associated stream


};




#endif //ERRLPARSER_H
OpenPOWER on IntegriCloud