xref: /freebsd/contrib/opencsd/decoder/include/common/ocsd_error_logger.h (revision 59c8e88e72633afbc47a4ace0d2170d00d51f7dc)
1 /*!
2  * \file       ocsd_error_logger.h
3  * \brief      OpenCSD : Library error logger.
4  *
5  * \copyright  Copyright (c) 2015, ARM Limited. All Rights Reserved.
6  */
7 
8 /*
9  * Redistribution and use in source and binary forms, with or without modification,
10  * are permitted provided that the following conditions are met:
11  *
12  * 1. Redistributions of source code must retain the above copyright notice,
13  * this list of conditions and the following disclaimer.
14  *
15  * 2. Redistributions in binary form must reproduce the above copyright notice,
16  * this list of conditions and the following disclaimer in the documentation
17  * and/or other materials provided with the distribution.
18  *
19  * 3. Neither the name of the copyright holder nor the names of its contributors
20  * may be used to endorse or promote products derived from this software without
21  * specific prior written permission.
22  *
23  * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS 'AS IS' AND
24  * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
25  * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
26  * IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT,
27  * INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
28  * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
29  * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
30  * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
31  * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
32  * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
33  */
34 
35 #ifndef ARM_OCSD_ERROR_LOGGER_H_INCLUDED
36 #define ARM_OCSD_ERROR_LOGGER_H_INCLUDED
37 
38 #include <string>
39 #include <vector>
40 //#include <fstream>
41 
42 #include "interfaces/trc_error_log_i.h"
43 #include "ocsd_error.h"
44 #include "ocsd_msg_logger.h"
45 
46 class ocsdDefaultErrorLogger : public ITraceErrorLog
47 {
48 public:
49     ocsdDefaultErrorLogger();
50     virtual ~ocsdDefaultErrorLogger();
51 
52     bool initErrorLogger(const ocsd_err_severity_t verbosity, bool bCreateOutputLogger = false); //!< Initialise the error logger with a severity filter, optionally create an output logger on stderr.
53 
54     virtual ocsdMsgLogger *getOutputLogger() { return m_output_logger; };
55     virtual void setOutputLogger(ocsdMsgLogger *pLogger);
56 
57     virtual const ocsd_hndl_err_log_t RegisterErrorSource(const std::string &component_name);
58 
59     virtual void LogError(const ocsd_hndl_err_log_t handle, const ocsdError *Error);
60     virtual void LogMessage(const ocsd_hndl_err_log_t handle, const ocsd_err_severity_t filter_level, const std::string &msg );
61 
62     virtual const ocsd_err_severity_t GetErrorLogVerbosity() const { return m_Verbosity; };
63 
64     virtual ocsdError *GetLastError() { return m_lastErr; };
65     virtual ocsdError *GetLastIDError(const uint8_t chan_id)
66     {
67         if(OCSD_IS_VALID_CS_SRC_ID(chan_id))
68             return m_lastErrID[chan_id];
69         return 0;
70     };
71 
72 private:
73     void CreateErrorObj(ocsdError **ppErr, const ocsdError *p_from);
74 
75     ocsdError *m_lastErr;
76     ocsdError *m_lastErrID[0x80];
77 
78     ocsd_err_severity_t m_Verbosity;
79 
80     ocsdMsgLogger *m_output_logger;   // pointer to a standard message output logger;
81     bool m_created_output_logger;      // true if this class created it's own logger;
82 
83     std::vector<std::string> m_error_sources;
84 };
85 
86 
87 #endif // ARM_OCSD_ERROR_LOGGER_H_INCLUDED
88 
89 /* End of File ocsd_error_logger.h */
90