1 /*- 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. 4 * 5 * GPL LICENSE SUMMARY 6 * 7 * Copyright(c) 2008 - 2011 Intel Corporation. All rights reserved. 8 * 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. 12 * 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. 17 * 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. 23 * 24 * BSD LICENSE 25 * 26 * Copyright(c) 2008 - 2011 Intel Corporation. All rights reserved. 27 * All rights reserved. 28 * 29 * Redistribution and use in source and binary forms, with or without 30 * modification, are permitted provided that the following conditions 31 * are met: 32 * 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 38 * distribution. 39 * 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. 51 */ 52 53 #include <sys/cdefs.h> 54 __FBSDID("$FreeBSD$"); 55 56 /** 57 * @file 58 * 59 * @brief This file provides the public and protected implementations for the 60 * state machine logger. The state machine logger will provide debug 61 * log information on a state machine for each state transition. 62 */ 63 64 #include <dev/isci/scil/sci_base_state_machine_logger.h> 65 66 #if defined(SCI_LOGGING) 67 68 //****************************************************************************** 69 //* P R O T E C T E D M E T H O D S 70 //****************************************************************************** 71 72 /** 73 * This is the function that is called when the state machine wants to notify 74 * this observer that there has been a state change. 75 * 76 * @param[in] observer The state machine logger that is observing the state 77 * machine. 78 * @param[in] subject The state machine that is being observed. 79 */ 80 static 81 void sci_base_state_machine_logger_update( 82 SCI_BASE_OBSERVER_T *observer, 83 SCI_BASE_SUBJECT_T *subject 84 ) 85 { 86 SCI_BASE_STATE_MACHINE_LOGGER_T *this_observer; 87 this_observer = (SCI_BASE_STATE_MACHINE_LOGGER_T *)observer; 88 89 this_observer->log_function( 90 sci_base_object_get_logger(this_observer->log_object), 91 this_observer->log_mask, 92 "%s 0x%08x %s has transitioned from %d to %d\n", 93 this_observer->log_object_name, 94 this_observer->log_object, 95 this_observer->log_state_machine_name, 96 this_observer->parent.subject_state, 97 sci_base_state_machine_get_state((SCI_BASE_STATE_MACHINE_T *)subject) 98 ); 99 100 sci_base_state_machine_observer_default_update( 101 &this_observer->parent.parent, subject 102 ); 103 } 104 105 //****************************************************************************** 106 //* P U B L I C M E T H O D S 107 //****************************************************************************** 108 109 /** 110 * This function will construct the state machine logger and attach it to the 111 * state machine that is to be observed. 112 * 113 * @param[in] this_observer This is the state machine logger object that is 114 * going to observe the subject state machine. 115 * @param[in] the_object This is the object that contains the state machine 116 * being observed it is used to report the address of the object for 117 * which a state transition has occurred. 118 * @param[in] the_log_function This is the logging function to be used when a 119 * state machine transition occurs. Since this is a base object type it 120 * does not actually know if the logging function is for the core or 121 * framework. 122 * @param[in] the_object_name This is the name of the object that contains the 123 * state machine being observed. 124 * @param[in] the_state_machine_name This is the name that will be displayed 125 * in the log string for the state machine being observed. 126 * @param[in] the_object_mask This is the log object mask used when calling 127 * the logging function. 128 * 129 * @return Nothing 130 */ 131 void sci_base_state_machine_logger_construct( 132 SCI_BASE_STATE_MACHINE_LOGGER_T * this_observer, 133 SCI_BASE_OBJECT_T * the_object, 134 SCI_BASE_STATE_MACHINE_LOGGER_LOG_HANDLER_T the_log_function, 135 char * log_object_name, 136 char * log_state_machine_name, 137 U32 log_object_mask 138 ) 139 { 140 sci_base_state_machine_observer_construct(&this_observer->parent); 141 142 this_observer->log_object = the_object; 143 this_observer->log_function = the_log_function; 144 this_observer->log_object_name = log_object_name; 145 this_observer->log_state_machine_name = log_state_machine_name; 146 this_observer->log_mask = log_object_mask; 147 148 this_observer->parent.parent.update = sci_base_state_machine_logger_update; 149 } 150 151 /** 152 * This is a helper function that will construct the state machine logger and 153 * attach it to the state machine that is to be observed. 154 * 155 * @param[in] this_observer This is the state machine logger object that is 156 * going to observe the subject state machine. 157 * @param[in] the_state_machine This is the state machine that is under 158 * observation. 159 * @param[in] the_object This is the object that contains the state machine 160 * being observed it is used to report the address of the object for 161 * which a state transition has occurred. 162 * @param[in] the_log_function This is the logging function to be used when a 163 * state machine transition occurs. Since this is a base object type it 164 * does not actually know if the logging function is for the core or 165 * framework. 166 * @param[in] the_object_name This is the name of the object that contains the 167 * state machine being observed. 168 * @param[in] the_state_machine_name This is the name that will be displayed 169 * in the log string for the state machine being observed. 170 * @param[in] the_object_mask This is the log object mask used when calling 171 * the logging function. 172 * 173 * @return Nothing 174 */ 175 void sci_base_state_machine_logger_initialize( 176 SCI_BASE_STATE_MACHINE_LOGGER_T * this_observer, 177 SCI_BASE_STATE_MACHINE_T * the_state_machine, 178 SCI_BASE_OBJECT_T * the_object, 179 SCI_BASE_STATE_MACHINE_LOGGER_LOG_HANDLER_T the_log_function, 180 char * log_object_name, 181 char * log_state_machine_name, 182 U32 log_object_mask 183 ) 184 { 185 sci_base_state_machine_logger_construct( 186 this_observer, the_object, 187 the_log_function, log_object_name, log_state_machine_name, log_object_mask 188 ); 189 190 sci_base_subject_attach_observer( 191 &the_state_machine->parent, &this_observer->parent.parent 192 ); 193 } 194 195 /** 196 * This is a helper function that will detach this observer from the state 197 * machine that is being observerd. 198 * 199 * @param[in] this_observer This is the observer to detach from the state 200 * machine. 201 * @parame[in] the_state_machine This is the state machine that is no longer 202 * going to be observed. 203 * 204 * @return Nothing 205 */ 206 void sci_base_state_machine_logger_deinitialize( 207 SCI_BASE_STATE_MACHINE_LOGGER_T * this_observer, 208 SCI_BASE_STATE_MACHINE_T * the_state_machine 209 ) 210 { 211 sci_base_subject_detach_observer( 212 &the_state_machine->parent, &this_observer->parent.parent 213 ); 214 } 215 216 #endif // defined(SCI_LOGGING) 217 218