2 * \file trc_component.cpp
5 * \copyright Copyright (c) 2015, ARM Limited. All Rights Reserved.
9 * Redistribution and use in source and binary forms, with or without modification,
10 * are permitted provided that the following conditions are met:
12 * 1. Redistributions of source code must retain the above copyright notice,
13 * this list of conditions and the following disclaimer.
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.
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.
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.
35 #include "common/trc_component.h"
37 class errLogAttachMonitor : public IComponentAttachNotifier
44 virtual ~ errLogAttachMonitor()
47 m_pComp->getErrorLogAttachPt()->set_notifier(0);
51 virtual void attachNotify(const int num_attached)
54 m_pComp->do_attach_notify(num_attached);
56 void Init(TraceComponent *pComp)
60 m_pComp->getErrorLogAttachPt()->set_notifier(this);
63 TraceComponent *m_pComp;
66 TraceComponent::TraceComponent(const std::string &name)
71 TraceComponent::TraceComponent(const std::string &name, int instIDNum)
73 std::string name_combined = name;
75 sprintf(num_buffer,"_%04d",instIDNum);
76 name_combined += (std::string)num_buffer;
80 TraceComponent::~TraceComponent()
83 delete m_pErrAttachMon;
86 void TraceComponent::Init(const std::string &name)
88 m_errLogHandle = OCSD_INVALID_HANDLE;
89 m_errVerbosity = OCSD_ERR_SEV_NONE;
92 m_supported_op_flags = 0;
96 m_pErrAttachMon = new (std::nothrow) errLogAttachMonitor();
98 m_pErrAttachMon->Init(this);
101 void TraceComponent::LogError(const ocsdError &Error)
103 if((m_errLogHandle != OCSD_INVALID_HANDLE) &&
104 isLoggingErrorLevel(Error.getErrorSeverity()))
106 // ensure we have not disabled the attachPt
107 if(m_error_logger.first())
108 m_error_logger.first()->LogError(m_errLogHandle,&Error);
112 void TraceComponent::LogMessage(const ocsd_err_severity_t filter_level, const std::string &msg)
114 if ((m_errLogHandle != OCSD_INVALID_HANDLE) &&
115 isLoggingErrorLevel(filter_level))
117 // ensure we have not disabled the attachPt
118 if (m_error_logger.first())
119 m_error_logger.first()->LogMessage(this->m_errLogHandle, filter_level, msg);
124 void TraceComponent::do_attach_notify(const int num_attached)
128 // ensure we have not disabled the attachPt
129 if(m_error_logger.first())
131 m_errLogHandle = m_error_logger.first()->RegisterErrorSource(m_name);
132 m_errVerbosity = m_error_logger.first()->GetErrorLogVerbosity();
137 m_errLogHandle = OCSD_INVALID_HANDLE;
141 void TraceComponent::updateErrorLogLevel()
143 if(m_error_logger.first())
145 m_errVerbosity = m_error_logger.first()->GetErrorLogVerbosity();
149 ocsd_err_t TraceComponent::setComponentOpMode(uint32_t op_flags)
151 m_op_flags = op_flags & m_supported_op_flags;
155 /* End of File trc_component.cpp */