1/* 2 * \file trc_component.cpp 3 * \brief OpenCSD : 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#include "common/trc_component.h" 36 37class errLogAttachMonitor : public IComponentAttachNotifier 38{ 39public: 40 errLogAttachMonitor() 41 { 42 m_pComp = 0; 43 }; 44 virtual ~ errLogAttachMonitor() 45 { 46 if (m_pComp) 47 m_pComp->getErrorLogAttachPt()->set_notifier(0); 48 m_pComp = 0; 49 50 }; 51 virtual void attachNotify(const int num_attached) 52 { 53 if(m_pComp) 54 m_pComp->do_attach_notify(num_attached); 55 } 56 void Init(TraceComponent *pComp) 57 { 58 m_pComp = pComp; 59 if(m_pComp) 60 m_pComp->getErrorLogAttachPt()->set_notifier(this); 61 } 62private: 63 TraceComponent *m_pComp; 64}; 65 66TraceComponent::TraceComponent(const std::string &name) 67{ 68 Init(name); 69} 70 71TraceComponent::TraceComponent(const std::string &name, int instIDNum) 72{ 73 std::string name_combined = name; 74 char num_buffer[32]; 75 sprintf(num_buffer,"_%04d",instIDNum); 76 name_combined += (std::string)num_buffer; 77 Init(name_combined); 78} 79 80TraceComponent::~TraceComponent() 81{ 82 if (m_pErrAttachMon) 83 delete m_pErrAttachMon; 84} 85 86void TraceComponent::Init(const std::string &name) 87{ 88 m_errLogHandle = OCSD_INVALID_HANDLE; 89 m_errVerbosity = OCSD_ERR_SEV_NONE; 90 m_name = name; 91 92 m_supported_op_flags = 0; 93 m_op_flags = 0; 94 m_assocComp = 0; 95 96 m_pErrAttachMon = new (std::nothrow) errLogAttachMonitor(); 97 if(m_pErrAttachMon) 98 m_pErrAttachMon->Init(this); 99} 100 101void TraceComponent::LogError(const ocsdError &Error) 102{ 103 if((m_errLogHandle != OCSD_INVALID_HANDLE) && 104 isLoggingErrorLevel(Error.getErrorSeverity())) 105 { 106 // ensure we have not disabled the attachPt 107 if(m_error_logger.first()) 108 m_error_logger.first()->LogError(m_errLogHandle,&Error); 109 } 110} 111 112void TraceComponent::LogMessage(const ocsd_err_severity_t filter_level, const std::string &msg) 113{ 114 if ((m_errLogHandle != OCSD_INVALID_HANDLE) && 115 isLoggingErrorLevel(filter_level)) 116 { 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); 120 } 121 122} 123 124void TraceComponent::do_attach_notify(const int num_attached) 125{ 126 if(num_attached) 127 { 128 // ensure we have not disabled the attachPt 129 if(m_error_logger.first()) 130 { 131 m_errLogHandle = m_error_logger.first()->RegisterErrorSource(m_name); 132 m_errVerbosity = m_error_logger.first()->GetErrorLogVerbosity(); 133 } 134 } 135 else 136 { 137 m_errLogHandle = OCSD_INVALID_HANDLE; 138 } 139} 140 141void TraceComponent::updateErrorLogLevel() 142{ 143 if(m_error_logger.first()) 144 { 145 m_errVerbosity = m_error_logger.first()->GetErrorLogVerbosity(); 146 } 147} 148 149ocsd_err_t TraceComponent::setComponentOpMode(uint32_t op_flags) 150{ 151 m_op_flags = op_flags & m_supported_op_flags; 152 return OCSD_OK; 153} 154 155/* End of File trc_component.cpp */ 156