• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*!
2  * \file       trc_component.h
3  * \brief      OpenCSD : Base trace decode component.
4  *
5  * \copyright  Copyright (c) 2015, ARM Limited. All Rights Reserved.
6  */
7 
8 
9 /*
10  * Redistribution and use in source and binary forms, with or without modification,
11  * are permitted provided that the following conditions are met:
12  *
13  * 1. Redistributions of source code must retain the above copyright notice,
14  * this list of conditions and the following disclaimer.
15  *
16  * 2. Redistributions in binary form must reproduce the above copyright notice,
17  * this list of conditions and the following disclaimer in the documentation
18  * and/or other materials provided with the distribution.
19  *
20  * 3. Neither the name of the copyright holder nor the names of its contributors
21  * may be used to endorse or promote products derived from this software without
22  * specific prior written permission.
23  *
24  * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS 'AS IS' AND
25  * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
26  * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
27  * IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT,
28  * INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
29  * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
30  * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
31  * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
32  * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
33  * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
34  */
35 
36 #ifndef ARM_TRC_COMPONENT_H_INCLUDED
37 #define ARM_TRC_COMPONENT_H_INCLUDED
38 
39 #include <string>
40 #include "comp_attach_pt_t.h"
41 #include "interfaces/trc_error_log_i.h"
42 #include "ocsd_error.h"
43 
44 class errLogAttachMonitor;
45 
46 /** @addtogroup ocsd_infrastructure
47 @{*/
48 
49 /*!
50  * @class TraceComponent
51  * @brief Base class for all decode components in the library.
52  *
53  * Provides error logging attachment point and component type and instance naming
54  * Interface for handling of component operational mode.
55  */
56 class TraceComponent
57 {
58 public:
59     TraceComponent(const std::string &name);
60     TraceComponent(const std::string &name, int instIDNum);
61     virtual ~TraceComponent(); /**< Default Destructor */
62 
getComponentName()63     const std::string &getComponentName() const { return m_name; };
setComponentName(const std::string & name)64     void setComponentName(const std::string &name)  { m_name = name; };
65 
66     /** Error logger attachment point.*/
getErrorLogAttachPt()67     componentAttachPt<ITraceErrorLog> *getErrorLogAttachPt() { return &m_error_logger; };
68 
69     /*!
70      * Set the operational mode for the component.
71      * This controls the way the component behaves under error conditions etc.
72      * These flags may also control output formats or data.
73      * Operation mode flags used are component specific and defined by derived classes.
74      *
75      * @param op_flags : Set of operation mode flags.
76      *
77      * @return ocsd_err_t  : OCSD_OK if flags supported by this component, error if unsuppored
78      */
79     ocsd_err_t setComponentOpMode(uint32_t op_flags);
80 
81     /*!
82      * Return the current operational mode flags values
83      *
84      * @return const uint32_t  : Op Mode flags.
85      */
getComponentOpMode()86     const uint32_t getComponentOpMode() const { return m_op_flags; };
87 
88     /*!
89      * Get the supported operational mode flags for this component.
90      * Base class will return nothing supported.
91      * Derived class must set the value correctly for the component.
92      *
93      * @return const uint32_t  : Supported flags values.
94      */
getSupportedOpModes()95     const uint32_t getSupportedOpModes() const { return m_supported_op_flags; };
96 
97     /*!
98      * Set associated trace component - used by generic code to track
99      * packet processor / packet decoder pairs.
100      *
101      * @param *assocComp : pointer to the associated component
102      */
setAssocComponent(TraceComponent * assocComp)103     void setAssocComponent(TraceComponent *assocComp) {  m_assocComp = assocComp; };
104 
105 
106     /*!
107      * get associated trace component pointer
108      *
109      * @return TraceComponent  *: associated component.
110      */
getAssocComponent()111     TraceComponent *getAssocComponent() { return m_assocComp; };
112 
113     /*!
114      * Log a message at the default severity on this component.
115      */
LogDefMessage(const std::string & msg)116     void LogDefMessage(const std::string &msg)
117     {
118         LogMessage(m_errVerbosity, msg);
119     }
120 
121 protected:
122     friend class errLogAttachMonitor;
123 
124     void LogError(const ocsdError &Error);
125     void LogMessage(const ocsd_err_severity_t filter_level, const std::string &msg);
getErrorLogLevel()126     const ocsd_err_severity_t getErrorLogLevel() const { return m_errVerbosity; };
isLoggingErrorLevel(const ocsd_err_severity_t level)127     const bool isLoggingErrorLevel(const ocsd_err_severity_t level) const { return level <= m_errVerbosity; };
128     void updateErrorLogLevel();
129 
130     void do_attach_notify(const int num_attached);
131     void Init(const std::string &name);
132 
133     uint32_t m_op_flags;                //!< current component operational mode flags.
134     uint32_t m_supported_op_flags;      //!< supported component operational mode flags - derived class to intialise.
135 
136 private:
137     componentAttachPt<ITraceErrorLog> m_error_logger;
138     ocsd_hndl_err_log_t m_errLogHandle;
139     ocsd_err_severity_t m_errVerbosity;
140     errLogAttachMonitor *m_pErrAttachMon;
141 
142     std::string m_name;
143 
144     TraceComponent *m_assocComp;    //!< associated component -> if this is a pkt decoder, associated pkt processor.
145 };
146 /** @}*/
147 #endif // ARM_TRC_COMPONENT_H_INCLUDED
148 
149 /* End of File trc_component.h */
150