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() {};
45 virtual void attachNotify(const int num_attached)
48 m_pComp->do_attach_notify(num_attached);
50 void Init(TraceComponent *pComp)
54 m_pComp->getErrorLogAttachPt()->set_notifier(this);
57 TraceComponent *m_pComp;
60 TraceComponent::TraceComponent(const std::string &name)
65 TraceComponent::TraceComponent(const std::string &name, int instIDNum)
67 std::string name_combined = name;
69 sprintf(num_buffer,"_%04d",instIDNum);
70 name_combined += (std::string)num_buffer;
74 TraceComponent::~TraceComponent()
78 void TraceComponent::Init(const std::string &name)
80 m_errLogHandle = OCSD_INVALID_HANDLE;
81 m_errVerbosity = OCSD_ERR_SEV_NONE;
84 m_supported_op_flags = 0;
88 m_pErrAttachMon = new (std::nothrow) errLogAttachMonitor();
90 m_pErrAttachMon->Init(this);
93 void TraceComponent::LogError(const ocsdError &Error)
95 if((m_errLogHandle != OCSD_INVALID_HANDLE) &&
96 isLoggingErrorLevel(Error.getErrorSeverity()))
98 // ensure we have not disabled the attachPt
99 if(m_error_logger.first())
100 m_error_logger.first()->LogError(m_errLogHandle,&Error);
104 void TraceComponent::LogMessage(const ocsd_err_severity_t filter_level, const std::string &msg)
106 if ((m_errLogHandle != OCSD_INVALID_HANDLE) &&
107 isLoggingErrorLevel(filter_level))
109 // ensure we have not disabled the attachPt
110 if (m_error_logger.first())
111 m_error_logger.first()->LogMessage(this->m_errLogHandle, filter_level, msg);
116 void TraceComponent::do_attach_notify(const int num_attached)
120 // ensure we have not disabled the attachPt
121 if(m_error_logger.first())
123 m_errLogHandle = m_error_logger.first()->RegisterErrorSource(m_name);
124 m_errVerbosity = m_error_logger.first()->GetErrorLogVerbosity();
129 m_errLogHandle = OCSD_INVALID_HANDLE;
133 void TraceComponent::updateErrorLogLevel()
135 if(m_error_logger.first())
137 m_errVerbosity = m_error_logger.first()->GetErrorLogVerbosity();
141 ocsd_err_t TraceComponent::setComponentOpMode(uint32_t op_flags)
143 if( (~m_supported_op_flags & op_flags) != 0)
144 return OCSD_ERR_INVALID_PARAM_VAL;
145 m_op_flags = op_flags;
149 /* End of File trc_component.cpp */