2 * This file is provided under a dual BSD/GPLv2 license. When using or
3 * redistributing this file, you may do so under either license.
7 * Copyright(c) 2008 - 2011 Intel Corporation. All rights reserved.
9 * This program is free software; you can redistribute it and/or modify
10 * it under the terms of version 2 of the GNU General Public License as
11 * published by the Free Software Foundation.
13 * This program is distributed in the hope that it will be useful, but
14 * WITHOUT ANY WARRANTY; without even the implied warranty of
15 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
16 * General Public License for more details.
18 * You should have received a copy of the GNU General Public License
19 * along with this program; if not, write to the Free Software
20 * Foundation, Inc., 51 Franklin St - Fifth Floor, Boston, MA 02110-1301 USA.
21 * The full GNU General Public License is included in this distribution
22 * in the file called LICENSE.GPL.
26 * Copyright(c) 2008 - 2011 Intel Corporation. All rights reserved.
27 * All rights reserved.
29 * Redistribution and use in source and binary forms, with or without
30 * modification, are permitted provided that the following conditions
33 * * Redistributions of source code must retain the above copyright
34 * notice, this list of conditions and the following disclaimer.
35 * * Redistributions in binary form must reproduce the above copyright
36 * notice, this list of conditions and the following disclaimer in
37 * the documentation and/or other materials provided with the
40 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
41 * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
42 * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
43 * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
44 * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
45 * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
46 * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
47 * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
48 * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
49 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
50 * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
53 #include <sys/cdefs.h>
54 __FBSDID("$FreeBSD$");
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.
65 #include <dev/isci/scil/sci_base_logger.h>
70 //******************************************************************************
71 //* P R I V A T E M E T H O D S
72 //******************************************************************************
74 #define SCI_LOGGER_GET_OBJECT_MASK(logger, verbosity_level) \
75 (((SCI_BASE_LOGGER_T *)(logger))->object_mask[(verbosity_level)])
78 * @brief This method is private to this object. It attempts to enable the
79 * supplied log objects for the supplied verbosity levels.
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
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.
93 void sci_base_logger_enable_log_object(
94 SCI_LOGGER_HANDLE_T logger,
100 // Enable the log objects for the error verbosity if errs are enabled.
101 if ( (1<<verbosity) & verbosity_mask)
103 SCI_LOGGER_GET_OBJECT_MASK(logger, verbosity) |= log_object_mask;
104 (((SCI_BASE_LOGGER_T *)(logger))->verbosity_mask |= (1<<verbosity) );
109 * @brief This method is private to this object. It attempts to disable the
110 * supplied log objects for the supplied verbosity levels.
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.
124 void sci_base_logger_disable_log_object(
125 SCI_LOGGER_HANDLE_T logger,
131 if ( (1<<verbosity) & verbosity_mask)
133 SCI_LOGGER_GET_OBJECT_MASK(logger, verbosity) &= ~log_object_mask;
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) );
142 //******************************************************************************
143 //* P U B L I C M E T H O D S
144 //******************************************************************************
146 U8 sci_logger_get_verbosity_mask(
147 SCI_LOGGER_HANDLE_T logger,
151 U8 verbosity_mask = 0;
152 SCI_BASE_LOGGER_T * base_logger = (SCI_BASE_LOGGER_T *)logger;
154 if ( base_logger->object_mask[SCI_LOG_VERBOSITY_ERROR] & log_object )
155 verbosity_mask |= 1<<SCI_LOG_VERBOSITY_ERROR;
157 if ( base_logger->object_mask[SCI_LOG_VERBOSITY_WARNING] & log_object )
158 verbosity_mask |= 1<<SCI_LOG_VERBOSITY_WARNING;
160 if ( base_logger->object_mask[SCI_LOG_VERBOSITY_INFO] & log_object )
161 verbosity_mask |= 1<<SCI_LOG_VERBOSITY_INFO;
163 if ( base_logger->object_mask[SCI_LOG_VERBOSITY_TRACE] & log_object )
164 verbosity_mask |= 1<<SCI_LOG_VERBOSITY_TRACE;
166 if ( base_logger->object_mask[SCI_LOG_VERBOSITY_STATES] & log_object )
167 verbosity_mask |= 1<<SCI_LOG_VERBOSITY_TRACE;
169 return verbosity_mask;
172 // ---------------------------------------------------------------------------
174 U32 sci_logger_get_object_mask(
175 SCI_LOGGER_HANDLE_T logger,
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) )
186 return SCI_LOGGER_GET_OBJECT_MASK(logger, verbosity);
189 // An unsupported verbosity level was supplied. Simply return an empty
194 // ---------------------------------------------------------------------------
196 void sci_logger_enable(
197 SCI_LOGGER_HANDLE_T logger,
202 sci_base_logger_enable_log_object(
203 logger, log_object_mask, verbosity_mask, SCI_LOG_VERBOSITY_ERROR
206 sci_base_logger_enable_log_object(
207 logger, log_object_mask, verbosity_mask, SCI_LOG_VERBOSITY_WARNING
210 sci_base_logger_enable_log_object(
211 logger, log_object_mask, verbosity_mask, SCI_LOG_VERBOSITY_INFO
214 sci_base_logger_enable_log_object(
215 logger, log_object_mask, verbosity_mask, SCI_LOG_VERBOSITY_TRACE
218 sci_base_logger_enable_log_object(
219 logger, log_object_mask, verbosity_mask, SCI_LOG_VERBOSITY_STATES
223 // ---------------------------------------------------------------------------
225 void sci_logger_disable(
226 SCI_LOGGER_HANDLE_T logger,
231 sci_base_logger_disable_log_object(
232 logger, log_object_mask, verbosity_mask, SCI_LOG_VERBOSITY_ERROR
235 sci_base_logger_disable_log_object(
236 logger, log_object_mask, verbosity_mask, SCI_LOG_VERBOSITY_WARNING
239 sci_base_logger_disable_log_object(
240 logger, log_object_mask, verbosity_mask, SCI_LOG_VERBOSITY_INFO
243 sci_base_logger_disable_log_object(
244 logger, log_object_mask, verbosity_mask, SCI_LOG_VERBOSITY_TRACE
247 sci_base_logger_disable_log_object(
248 logger, log_object_mask, verbosity_mask, SCI_LOG_VERBOSITY_STATES
252 // ---------------------------------------------------------------------------
254 BOOL sci_logger_is_enabled(
255 SCI_LOGGER_HANDLE_T logger,
260 SCI_BASE_LOGGER_T * base_logger = (SCI_BASE_LOGGER_T*) logger;
262 if ( (base_logger->verbosity_mask & (1<<verbosity_level))
263 && (base_logger->object_mask[verbosity_level] & log_object_mask) )
269 //******************************************************************************
270 //* P R O T E C T E D M E T H O D S
271 //******************************************************************************
273 void sci_base_logger_construct(
274 SCI_BASE_LOGGER_T *this_logger
279 sci_base_object_construct(
280 &this_logger->parent, this_logger
283 this_logger->verbosity_mask = 0;
285 for (index = 0; index < SCI_BASE_LOGGER_MAX_VERBOSITY_LEVELS; index++)
287 this_logger->object_mask[index] = 0;
291 #endif // SCI_LOGGING