1 /*- 2 * SPDX-License-Identifier: BSD-2-Clause OR GPL-2.0 3 * 4 * This file is provided under a dual BSD/GPLv2 license. When using or 5 * redistributing this file, you may do so under either license. 6 * 7 * GPL LICENSE SUMMARY 8 * 9 * Copyright(c) 2008 - 2011 Intel Corporation. All rights reserved. 10 * 11 * This program is free software; you can redistribute it and/or modify 12 * it under the terms of version 2 of the GNU General Public License as 13 * published by the Free Software Foundation. 14 * 15 * This program is distributed in the hope that it will be useful, but 16 * WITHOUT ANY WARRANTY; without even the implied warranty of 17 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 18 * General Public License for more details. 19 * 20 * You should have received a copy of the GNU General Public License 21 * along with this program; if not, write to the Free Software 22 * Foundation, Inc., 51 Franklin St - Fifth Floor, Boston, MA 02110-1301 USA. 23 * The full GNU General Public License is included in this distribution 24 * in the file called LICENSE.GPL. 25 * 26 * BSD LICENSE 27 * 28 * Copyright(c) 2008 - 2011 Intel Corporation. All rights reserved. 29 * All rights reserved. 30 * 31 * Redistribution and use in source and binary forms, with or without 32 * modification, are permitted provided that the following conditions 33 * are met: 34 * 35 * * Redistributions of source code must retain the above copyright 36 * notice, this list of conditions and the following disclaimer. 37 * * Redistributions in binary form must reproduce the above copyright 38 * notice, this list of conditions and the following disclaimer in 39 * the documentation and/or other materials provided with the 40 * distribution. 41 * 42 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS 43 * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT 44 * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR 45 * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT 46 * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, 47 * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT 48 * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, 49 * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY 50 * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 51 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE 52 * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 53 */ 54 55 #include <sys/cdefs.h> 56 /** 57 * @file 58 * 59 * @brief This file contains the implementation for the base logger object. 60 * It provides the functionality necessary to enabling, disabling, 61 * constructing, etc. logger objects. 62 */ 63 64 65 #include <dev/isci/scil/sci_base_logger.h> 66 67 68 #ifdef SCI_LOGGING 69 70 //****************************************************************************** 71 //* P R I V A T E M E T H O D S 72 //****************************************************************************** 73 74 #define SCI_LOGGER_GET_OBJECT_MASK(logger, verbosity_level) \ 75 (((SCI_BASE_LOGGER_T *)(logger))->object_mask[(verbosity_level)]) 76 77 /** 78 * @brief This method is private to this object. It attempts to enable the 79 * supplied log objects for the supplied verbosity levels. 80 * 81 * @param[in] logger This parameter specifies the logger object for which 82 * to attempt to enable log object and verbosity levels. 83 * @param[in] log_object_mask This parameter specifies the log objects to 84 * attempt to enable. 85 * @param[in] verbosity_mask This parameter specifies the verbosity levels 86 * that are allowed to be enabled. 87 * @param[in] verbosity This parameter specifies the specific verbosity level 88 * to attempt to enable. 89 * 90 * @return none 91 */ 92 static 93 void sci_base_logger_enable_log_object( 94 SCI_LOGGER_HANDLE_T logger, 95 U32 log_object_mask, 96 U8 verbosity_mask, 97 U8 verbosity 98 ) 99 { 100 // Enable the log objects for the error verbosity if errs are enabled. 101 if ( (1<<verbosity) & verbosity_mask) 102 { 103 SCI_LOGGER_GET_OBJECT_MASK(logger, verbosity) |= log_object_mask; 104 (((SCI_BASE_LOGGER_T *)(logger))->verbosity_mask |= (1<<verbosity) ); 105 } 106 } 107 108 /** 109 * @brief This method is private to this object. It attempts to disable the 110 * supplied log objects for the supplied verbosity levels. 111 * 112 * @param[in] logger This parameter specifies the logger object for which 113 * to attempt to disable log object and verbosity levels. 114 * @param[in] log_object_mask This parameter specifies the log objects to 115 * attempt to disable. 116 * @param[in] verbosity_mask This parameter specifies the verbosity levels 117 * that are allowed to be disabled. 118 * @param[in] verbosity This parameter specifies the specific verbosity level 119 * to attempt to disable. 120 * 121 * @return none 122 */ 123 static 124 void sci_base_logger_disable_log_object( 125 SCI_LOGGER_HANDLE_T logger, 126 U32 log_object_mask, 127 U8 verbosity_mask, 128 U8 verbosity 129 ) 130 { 131 if ( (1<<verbosity) & verbosity_mask) 132 { 133 SCI_LOGGER_GET_OBJECT_MASK(logger, verbosity) &= ~log_object_mask; 134 135 // If all of the objects in the object mask are disabled for this 136 // verbosity, then disable the verbosity as well. 137 if (SCI_LOGGER_GET_OBJECT_MASK(logger, verbosity) == 0) 138 (((SCI_BASE_LOGGER_T *)(logger))->verbosity_mask &= ~(1<<verbosity) ); 139 } 140 } 141 142 //****************************************************************************** 143 //* P U B L I C M E T H O D S 144 //****************************************************************************** 145 146 U8 sci_logger_get_verbosity_mask( 147 SCI_LOGGER_HANDLE_T logger, 148 U32 log_object 149 ) 150 { 151 U8 verbosity_mask = 0; 152 SCI_BASE_LOGGER_T * base_logger = (SCI_BASE_LOGGER_T *)logger; 153 154 if ( base_logger->object_mask[SCI_LOG_VERBOSITY_ERROR] & log_object ) 155 verbosity_mask |= 1<<SCI_LOG_VERBOSITY_ERROR; 156 157 if ( base_logger->object_mask[SCI_LOG_VERBOSITY_WARNING] & log_object ) 158 verbosity_mask |= 1<<SCI_LOG_VERBOSITY_WARNING; 159 160 if ( base_logger->object_mask[SCI_LOG_VERBOSITY_INFO] & log_object ) 161 verbosity_mask |= 1<<SCI_LOG_VERBOSITY_INFO; 162 163 if ( base_logger->object_mask[SCI_LOG_VERBOSITY_TRACE] & log_object ) 164 verbosity_mask |= 1<<SCI_LOG_VERBOSITY_TRACE; 165 166 if ( base_logger->object_mask[SCI_LOG_VERBOSITY_STATES] & log_object ) 167 verbosity_mask |= 1<<SCI_LOG_VERBOSITY_TRACE; 168 169 return verbosity_mask; 170 } 171 172 // --------------------------------------------------------------------------- 173 174 U32 sci_logger_get_object_mask( 175 SCI_LOGGER_HANDLE_T logger, 176 U8 verbosity 177 ) 178 { 179 // Ensure that a supported verbosity level was supplied. 180 if ( (SCI_LOG_VERBOSITY_ERROR == verbosity) 181 || (SCI_LOG_VERBOSITY_WARNING == verbosity) 182 || (SCI_LOG_VERBOSITY_INFO == verbosity) 183 || (SCI_LOG_VERBOSITY_TRACE == verbosity) 184 || (SCI_LOG_VERBOSITY_STATES == verbosity) ) 185 { 186 return SCI_LOGGER_GET_OBJECT_MASK(logger, verbosity); 187 } 188 189 // An unsupported verbosity level was supplied. Simply return an empty 190 // log object mask. 191 return 0; 192 } 193 194 // --------------------------------------------------------------------------- 195 196 void sci_logger_enable( 197 SCI_LOGGER_HANDLE_T logger, 198 U32 log_object_mask, 199 U8 verbosity_mask 200 ) 201 { 202 sci_base_logger_enable_log_object( 203 logger, log_object_mask, verbosity_mask, SCI_LOG_VERBOSITY_ERROR 204 ); 205 206 sci_base_logger_enable_log_object( 207 logger, log_object_mask, verbosity_mask, SCI_LOG_VERBOSITY_WARNING 208 ); 209 210 sci_base_logger_enable_log_object( 211 logger, log_object_mask, verbosity_mask, SCI_LOG_VERBOSITY_INFO 212 ); 213 214 sci_base_logger_enable_log_object( 215 logger, log_object_mask, verbosity_mask, SCI_LOG_VERBOSITY_TRACE 216 ); 217 218 sci_base_logger_enable_log_object( 219 logger, log_object_mask, verbosity_mask, SCI_LOG_VERBOSITY_STATES 220 ); 221 } 222 223 // --------------------------------------------------------------------------- 224 225 void sci_logger_disable( 226 SCI_LOGGER_HANDLE_T logger, 227 U32 log_object_mask, 228 U8 verbosity_mask 229 ) 230 { 231 sci_base_logger_disable_log_object( 232 logger, log_object_mask, verbosity_mask, SCI_LOG_VERBOSITY_ERROR 233 ); 234 235 sci_base_logger_disable_log_object( 236 logger, log_object_mask, verbosity_mask, SCI_LOG_VERBOSITY_WARNING 237 ); 238 239 sci_base_logger_disable_log_object( 240 logger, log_object_mask, verbosity_mask, SCI_LOG_VERBOSITY_INFO 241 ); 242 243 sci_base_logger_disable_log_object( 244 logger, log_object_mask, verbosity_mask, SCI_LOG_VERBOSITY_TRACE 245 ); 246 247 sci_base_logger_disable_log_object( 248 logger, log_object_mask, verbosity_mask, SCI_LOG_VERBOSITY_STATES 249 ); 250 } 251 252 // --------------------------------------------------------------------------- 253 254 BOOL sci_logger_is_enabled( 255 SCI_LOGGER_HANDLE_T logger, 256 U32 log_object_mask, 257 U8 verbosity_level 258 ) 259 { 260 SCI_BASE_LOGGER_T * base_logger = (SCI_BASE_LOGGER_T*) logger; 261 262 if ( (base_logger->verbosity_mask & (1<<verbosity_level)) 263 && (base_logger->object_mask[verbosity_level] & log_object_mask) ) 264 return TRUE; 265 266 return FALSE; 267 } 268 269 //****************************************************************************** 270 //* P R O T E C T E D M E T H O D S 271 //****************************************************************************** 272 273 void sci_base_logger_construct( 274 SCI_BASE_LOGGER_T *this_logger 275 ) 276 { 277 int index; 278 279 sci_base_object_construct( 280 &this_logger->parent, this_logger 281 ); 282 283 this_logger->verbosity_mask = 0; 284 285 for (index = 0; index < SCI_BASE_LOGGER_MAX_VERBOSITY_LEVELS; index++) 286 { 287 this_logger->object_mask[index] = 0; 288 } 289 } 290 291 #endif // SCI_LOGGING 292