1230557Sjimharris/*- 2230557Sjimharris * This file is provided under a dual BSD/GPLv2 license. When using or 3230557Sjimharris * redistributing this file, you may do so under either license. 4230557Sjimharris * 5230557Sjimharris * GPL LICENSE SUMMARY 6230557Sjimharris * 7230557Sjimharris * Copyright(c) 2008 - 2011 Intel Corporation. All rights reserved. 8230557Sjimharris * 9230557Sjimharris * This program is free software; you can redistribute it and/or modify 10230557Sjimharris * it under the terms of version 2 of the GNU General Public License as 11230557Sjimharris * published by the Free Software Foundation. 12230557Sjimharris * 13230557Sjimharris * This program is distributed in the hope that it will be useful, but 14230557Sjimharris * WITHOUT ANY WARRANTY; without even the implied warranty of 15230557Sjimharris * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 16230557Sjimharris * General Public License for more details. 17230557Sjimharris * 18230557Sjimharris * You should have received a copy of the GNU General Public License 19230557Sjimharris * along with this program; if not, write to the Free Software 20230557Sjimharris * Foundation, Inc., 51 Franklin St - Fifth Floor, Boston, MA 02110-1301 USA. 21230557Sjimharris * The full GNU General Public License is included in this distribution 22230557Sjimharris * in the file called LICENSE.GPL. 23230557Sjimharris * 24230557Sjimharris * BSD LICENSE 25230557Sjimharris * 26230557Sjimharris * Copyright(c) 2008 - 2011 Intel Corporation. All rights reserved. 27230557Sjimharris * All rights reserved. 28230557Sjimharris * 29230557Sjimharris * Redistribution and use in source and binary forms, with or without 30230557Sjimharris * modification, are permitted provided that the following conditions 31230557Sjimharris * are met: 32230557Sjimharris * 33230557Sjimharris * * Redistributions of source code must retain the above copyright 34230557Sjimharris * notice, this list of conditions and the following disclaimer. 35230557Sjimharris * * Redistributions in binary form must reproduce the above copyright 36230557Sjimharris * notice, this list of conditions and the following disclaimer in 37230557Sjimharris * the documentation and/or other materials provided with the 38230557Sjimharris * distribution. 39230557Sjimharris * 40230557Sjimharris * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS 41230557Sjimharris * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT 42230557Sjimharris * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR 43230557Sjimharris * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT 44230557Sjimharris * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, 45230557Sjimharris * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT 46230557Sjimharris * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, 47230557Sjimharris * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY 48230557Sjimharris * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 49230557Sjimharris * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE 50230557Sjimharris * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 51230557Sjimharris */ 52230557Sjimharris 53230557Sjimharris#include <sys/cdefs.h> 54230557Sjimharris__FBSDID("$FreeBSD: releng/10.3/sys/dev/isci/scil/sci_base_logger.c 231136 2012-02-07 17:43:58Z jimharris $"); 55230557Sjimharris 56230557Sjimharris/** 57230557Sjimharris * @file 58230557Sjimharris * 59230557Sjimharris * @brief This file contains the implementation for the base logger object. 60230557Sjimharris * It provides the functionality necessary to enabling, disabling, 61230557Sjimharris * constructing, etc. logger objects. 62230557Sjimharris */ 63230557Sjimharris 64230557Sjimharris 65230557Sjimharris#include <dev/isci/scil/sci_base_logger.h> 66230557Sjimharris 67230557Sjimharris 68230557Sjimharris#ifdef SCI_LOGGING 69230557Sjimharris 70230557Sjimharris//****************************************************************************** 71230557Sjimharris//* P R I V A T E M E T H O D S 72230557Sjimharris//****************************************************************************** 73230557Sjimharris 74230557Sjimharris#define SCI_LOGGER_GET_OBJECT_MASK(logger, verbosity_level) \ 75230557Sjimharris (((SCI_BASE_LOGGER_T *)(logger))->object_mask[(verbosity_level)]) 76230557Sjimharris 77230557Sjimharris/** 78230557Sjimharris * @brief This method is private to this object. It attempts to enable the 79230557Sjimharris * supplied log objects for the supplied verbosity levels. 80230557Sjimharris * 81230557Sjimharris * @param[in] logger This parameter specifies the logger object for which 82230557Sjimharris * to attempt to enable log object and verbosity levels. 83230557Sjimharris * @param[in] log_object_mask This parameter specifies the log objects to 84230557Sjimharris * attempt to enable. 85230557Sjimharris * @param[in] verbosity_mask This parameter specifies the verbosity levels 86230557Sjimharris * that are allowed to be enabled. 87230557Sjimharris * @param[in] verbosity This parameter specifies the specific verbosity level 88230557Sjimharris * to attempt to enable. 89230557Sjimharris * 90230557Sjimharris * @return none 91230557Sjimharris */ 92230557Sjimharrisstatic 93230557Sjimharrisvoid sci_base_logger_enable_log_object( 94230557Sjimharris SCI_LOGGER_HANDLE_T logger, 95230557Sjimharris U32 log_object_mask, 96230557Sjimharris U8 verbosity_mask, 97230557Sjimharris U8 verbosity 98230557Sjimharris) 99230557Sjimharris{ 100230557Sjimharris // Enable the log objects for the error verbosity if errs are enabled. 101230557Sjimharris if ( (1<<verbosity) & verbosity_mask) 102230557Sjimharris { 103230557Sjimharris SCI_LOGGER_GET_OBJECT_MASK(logger, verbosity) |= log_object_mask; 104230557Sjimharris (((SCI_BASE_LOGGER_T *)(logger))->verbosity_mask |= (1<<verbosity) ); 105230557Sjimharris } 106230557Sjimharris} 107230557Sjimharris 108230557Sjimharris/** 109230557Sjimharris * @brief This method is private to this object. It attempts to disable the 110230557Sjimharris * supplied log objects for the supplied verbosity levels. 111230557Sjimharris * 112230557Sjimharris * @param[in] logger This parameter specifies the logger object for which 113230557Sjimharris * to attempt to disable log object and verbosity levels. 114230557Sjimharris * @param[in] log_object_mask This parameter specifies the log objects to 115230557Sjimharris * attempt to disable. 116230557Sjimharris * @param[in] verbosity_mask This parameter specifies the verbosity levels 117230557Sjimharris * that are allowed to be disabled. 118230557Sjimharris * @param[in] verbosity This parameter specifies the specific verbosity level 119230557Sjimharris * to attempt to disable. 120230557Sjimharris * 121230557Sjimharris * @return none 122230557Sjimharris */ 123230557Sjimharrisstatic 124230557Sjimharrisvoid sci_base_logger_disable_log_object( 125230557Sjimharris SCI_LOGGER_HANDLE_T logger, 126230557Sjimharris U32 log_object_mask, 127230557Sjimharris U8 verbosity_mask, 128230557Sjimharris U8 verbosity 129230557Sjimharris) 130230557Sjimharris{ 131230557Sjimharris if ( (1<<verbosity) & verbosity_mask) 132230557Sjimharris { 133230557Sjimharris SCI_LOGGER_GET_OBJECT_MASK(logger, verbosity) &= ~log_object_mask; 134230557Sjimharris 135230557Sjimharris // If all of the objects in the object mask are disabled for this 136230557Sjimharris // verbosity, then disable the verbosity as well. 137230557Sjimharris if (SCI_LOGGER_GET_OBJECT_MASK(logger, verbosity) == 0) 138230557Sjimharris (((SCI_BASE_LOGGER_T *)(logger))->verbosity_mask &= ~(1<<verbosity) ); 139230557Sjimharris } 140230557Sjimharris} 141230557Sjimharris 142230557Sjimharris//****************************************************************************** 143230557Sjimharris//* P U B L I C M E T H O D S 144230557Sjimharris//****************************************************************************** 145230557Sjimharris 146230557SjimharrisU8 sci_logger_get_verbosity_mask( 147230557Sjimharris SCI_LOGGER_HANDLE_T logger, 148230557Sjimharris U32 log_object 149230557Sjimharris) 150230557Sjimharris{ 151230557Sjimharris U8 verbosity_mask = 0; 152230557Sjimharris SCI_BASE_LOGGER_T * base_logger = (SCI_BASE_LOGGER_T *)logger; 153230557Sjimharris 154230557Sjimharris if ( base_logger->object_mask[SCI_LOG_VERBOSITY_ERROR] & log_object ) 155230557Sjimharris verbosity_mask |= 1<<SCI_LOG_VERBOSITY_ERROR; 156230557Sjimharris 157230557Sjimharris if ( base_logger->object_mask[SCI_LOG_VERBOSITY_WARNING] & log_object ) 158230557Sjimharris verbosity_mask |= 1<<SCI_LOG_VERBOSITY_WARNING; 159230557Sjimharris 160230557Sjimharris if ( base_logger->object_mask[SCI_LOG_VERBOSITY_INFO] & log_object ) 161230557Sjimharris verbosity_mask |= 1<<SCI_LOG_VERBOSITY_INFO; 162230557Sjimharris 163230557Sjimharris if ( base_logger->object_mask[SCI_LOG_VERBOSITY_TRACE] & log_object ) 164230557Sjimharris verbosity_mask |= 1<<SCI_LOG_VERBOSITY_TRACE; 165230557Sjimharris 166230557Sjimharris if ( base_logger->object_mask[SCI_LOG_VERBOSITY_STATES] & log_object ) 167230557Sjimharris verbosity_mask |= 1<<SCI_LOG_VERBOSITY_TRACE; 168230557Sjimharris 169230557Sjimharris return verbosity_mask; 170230557Sjimharris} 171230557Sjimharris 172230557Sjimharris// --------------------------------------------------------------------------- 173230557Sjimharris 174230557SjimharrisU32 sci_logger_get_object_mask( 175230557Sjimharris SCI_LOGGER_HANDLE_T logger, 176230557Sjimharris U8 verbosity 177230557Sjimharris) 178230557Sjimharris{ 179230557Sjimharris // Ensure that a supported verbosity level was supplied. 180230557Sjimharris if ( (SCI_LOG_VERBOSITY_ERROR == verbosity) 181230557Sjimharris || (SCI_LOG_VERBOSITY_WARNING == verbosity) 182230557Sjimharris || (SCI_LOG_VERBOSITY_INFO == verbosity) 183230557Sjimharris || (SCI_LOG_VERBOSITY_TRACE == verbosity) 184230557Sjimharris || (SCI_LOG_VERBOSITY_STATES == verbosity) ) 185230557Sjimharris { 186230557Sjimharris return SCI_LOGGER_GET_OBJECT_MASK(logger, verbosity); 187230557Sjimharris } 188230557Sjimharris 189230557Sjimharris // An unsupported verbosity level was supplied. Simply return an empty 190230557Sjimharris // log object mask. 191230557Sjimharris return 0; 192230557Sjimharris} 193230557Sjimharris 194230557Sjimharris// --------------------------------------------------------------------------- 195230557Sjimharris 196230557Sjimharrisvoid sci_logger_enable( 197230557Sjimharris SCI_LOGGER_HANDLE_T logger, 198230557Sjimharris U32 log_object_mask, 199230557Sjimharris U8 verbosity_mask 200230557Sjimharris) 201230557Sjimharris{ 202230557Sjimharris sci_base_logger_enable_log_object( 203230557Sjimharris logger, log_object_mask, verbosity_mask, SCI_LOG_VERBOSITY_ERROR 204230557Sjimharris ); 205230557Sjimharris 206230557Sjimharris sci_base_logger_enable_log_object( 207230557Sjimharris logger, log_object_mask, verbosity_mask, SCI_LOG_VERBOSITY_WARNING 208230557Sjimharris ); 209230557Sjimharris 210230557Sjimharris sci_base_logger_enable_log_object( 211230557Sjimharris logger, log_object_mask, verbosity_mask, SCI_LOG_VERBOSITY_INFO 212230557Sjimharris ); 213230557Sjimharris 214230557Sjimharris sci_base_logger_enable_log_object( 215230557Sjimharris logger, log_object_mask, verbosity_mask, SCI_LOG_VERBOSITY_TRACE 216230557Sjimharris ); 217230557Sjimharris 218230557Sjimharris sci_base_logger_enable_log_object( 219230557Sjimharris logger, log_object_mask, verbosity_mask, SCI_LOG_VERBOSITY_STATES 220230557Sjimharris ); 221230557Sjimharris} 222230557Sjimharris 223230557Sjimharris// --------------------------------------------------------------------------- 224230557Sjimharris 225230557Sjimharrisvoid sci_logger_disable( 226230557Sjimharris SCI_LOGGER_HANDLE_T logger, 227230557Sjimharris U32 log_object_mask, 228230557Sjimharris U8 verbosity_mask 229230557Sjimharris) 230230557Sjimharris{ 231230557Sjimharris sci_base_logger_disable_log_object( 232230557Sjimharris logger, log_object_mask, verbosity_mask, SCI_LOG_VERBOSITY_ERROR 233230557Sjimharris ); 234230557Sjimharris 235230557Sjimharris sci_base_logger_disable_log_object( 236230557Sjimharris logger, log_object_mask, verbosity_mask, SCI_LOG_VERBOSITY_WARNING 237230557Sjimharris ); 238230557Sjimharris 239230557Sjimharris sci_base_logger_disable_log_object( 240230557Sjimharris logger, log_object_mask, verbosity_mask, SCI_LOG_VERBOSITY_INFO 241230557Sjimharris ); 242230557Sjimharris 243230557Sjimharris sci_base_logger_disable_log_object( 244230557Sjimharris logger, log_object_mask, verbosity_mask, SCI_LOG_VERBOSITY_TRACE 245230557Sjimharris ); 246230557Sjimharris 247230557Sjimharris sci_base_logger_disable_log_object( 248230557Sjimharris logger, log_object_mask, verbosity_mask, SCI_LOG_VERBOSITY_STATES 249230557Sjimharris ); 250230557Sjimharris} 251230557Sjimharris 252230557Sjimharris// --------------------------------------------------------------------------- 253230557Sjimharris 254230557SjimharrisBOOL sci_logger_is_enabled( 255230557Sjimharris SCI_LOGGER_HANDLE_T logger, 256230557Sjimharris U32 log_object_mask, 257230557Sjimharris U8 verbosity_level 258230557Sjimharris) 259230557Sjimharris{ 260230557Sjimharris SCI_BASE_LOGGER_T * base_logger = (SCI_BASE_LOGGER_T*) logger; 261230557Sjimharris 262230557Sjimharris if ( (base_logger->verbosity_mask & (1<<verbosity_level)) 263230557Sjimharris && (base_logger->object_mask[verbosity_level] & log_object_mask) ) 264230557Sjimharris return TRUE; 265230557Sjimharris 266230557Sjimharris return FALSE; 267230557Sjimharris} 268230557Sjimharris 269230557Sjimharris//****************************************************************************** 270230557Sjimharris//* P R O T E C T E D M E T H O D S 271230557Sjimharris//****************************************************************************** 272230557Sjimharris 273230557Sjimharrisvoid sci_base_logger_construct( 274230557Sjimharris SCI_BASE_LOGGER_T *this_logger 275230557Sjimharris) 276230557Sjimharris{ 277230557Sjimharris int index; 278230557Sjimharris 279230557Sjimharris sci_base_object_construct( 280230557Sjimharris &this_logger->parent, this_logger 281230557Sjimharris ); 282230557Sjimharris 283230557Sjimharris this_logger->verbosity_mask = 0; 284230557Sjimharris 285230557Sjimharris for (index = 0; index < SCI_BASE_LOGGER_MAX_VERBOSITY_LEVELS; index++) 286230557Sjimharris { 287230557Sjimharris this_logger->object_mask[index] = 0; 288230557Sjimharris } 289230557Sjimharris} 290230557Sjimharris 291230557Sjimharris#endif // SCI_LOGGING 292