sci_base_state_machine_logger.c revision 230843
16Sdg/*-
26Sdg * This file is provided under a dual BSD/GPLv2 license.  When using or
343Sdg * redistributing this file, you may do so under either license.
4808Sdg *
5498Sdg * GPL LICENSE SUMMARY
6498Sdg *
7498Sdg * Copyright(c) 2008 - 2011 Intel Corporation. All rights reserved.
8808Sdg *
9808Sdg * This program is free software; you can redistribute it and/or modify
10808Sdg * it under the terms of version 2 of the GNU General Public License as
11808Sdg * published by the Free Software Foundation.
12791Sdg *
13791Sdg * This program is distributed in the hope that it will be useful, but
14791Sdg * WITHOUT ANY WARRANTY; without even the implied warranty of
15791Sdg * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
16520Sdg * General Public License for more details.
17520Sdg *
18520Sdg * You should have received a copy of the GNU General Public License
19520Sdg * along with this program; if not, write to the Free Software
20520Sdg * Foundation, Inc., 51 Franklin St - Fifth Floor, Boston, MA 02110-1301 USA.
2143Sdg * The full GNU General Public License is included in this distribution
2243Sdg * in the file called LICENSE.GPL.
2343Sdg *
246Sdg * BSD LICENSE
256Sdg *
266Sdg * Copyright(c) 2008 - 2011 Intel Corporation. All rights reserved.
276Sdg * All rights reserved.
286Sdg *
296Sdg * Redistribution and use in source and binary forms, with or without
306Sdg * modification, are permitted provided that the following conditions
316Sdg * are met:
326Sdg *
336Sdg *   * Redistributions of source code must retain the above copyright
346Sdg *     notice, this list of conditions and the following disclaimer.
356Sdg *   * Redistributions in binary form must reproduce the above copyright
366Sdg *     notice, this list of conditions and the following disclaimer in
376Sdg *     the documentation and/or other materials provided with the
386Sdg *     distribution.
396Sdg *
406Sdg * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
416Sdg * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
426Sdg * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
436Sdg * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
446Sdg * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
456Sdg * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
466Sdg * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
476Sdg * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
486Sdg * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
496Sdg * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
506Sdg * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
516Sdg */
526Sdg
536Sdg#include <sys/cdefs.h>
546Sdg__FBSDID("$FreeBSD$");
556Sdg
566Sdg/**
576Sdg * @file
586Sdg *
596Sdg * @brief This file provides the public and protected implementations for the
606Sdg *        state machine logger.  The state machine logger will provide debug
616Sdg *        log information on a state machine for each state transition.
626Sdg */
636Sdg
646Sdg#include <dev/isci/scil/sci_base_state_machine_logger.h>
656Sdg
666Sdg#if defined(SCI_LOGGING)
676Sdg
686Sdg//******************************************************************************
696Sdg//* P R O T E C T E D    M E T H O D S
706Sdg//******************************************************************************
716Sdg
726Sdg/**
736Sdg * This is the function that is called when the state machine wants to notify
746Sdg * this observer that there has been a state change.
756Sdg *
766Sdg * @param[in] observer The state machine logger that is observing the state
776Sdg *       machine.
786Sdg * @param[in] subject The state machine that is being observed.
796Sdg */
806Sdgstatic
816Sdgvoid sci_base_state_machine_logger_update(
826Sdg   SCI_BASE_OBSERVER_T *observer,
836Sdg   SCI_BASE_SUBJECT_T  *subject
846Sdg)
856Sdg{
866Sdg   SCI_BASE_STATE_MACHINE_LOGGER_T *this_observer;
876Sdg   this_observer = (SCI_BASE_STATE_MACHINE_LOGGER_T *)observer;
886Sdg
896Sdg   this_observer->log_function(
906Sdg      sci_base_object_get_logger(this_observer->log_object),
916Sdg      this_observer->log_mask,
926Sdg      "%s 0x%08x %s has transitioned from %d to %d\n",
936Sdg      this_observer->log_object_name,
946Sdg      this_observer->log_object,
956Sdg      this_observer->log_state_machine_name,
966Sdg      this_observer->parent.subject_state,
976Sdg      sci_base_state_machine_get_state((SCI_BASE_STATE_MACHINE_T *)subject)
986Sdg   );
996Sdg
1006Sdg   sci_base_state_machine_observer_default_update(
1016Sdg      &this_observer->parent.parent, subject
1026Sdg   );
1036Sdg}
1046Sdg
1056Sdg//******************************************************************************
1066Sdg//* P U B L I C   M E T H O D S
1076Sdg//******************************************************************************
1086Sdg
1096Sdg/**
1106Sdg * This function will construct the state machine logger and attach it to the
1116Sdg * state machine that is to be observed.
1126Sdg *
1136Sdg * @param[in] this_observer This is the state machine logger object that is
1146Sdg *       going to observe the subject state machine.
1156Sdg * @param[in] the_object This is the object that contains the state machine
1166Sdg *       being observed it is used to report the address of the object for
1176Sdg *       which a state transition has occurred.
1186Sdg * @param[in] the_log_function This is the logging function to be used when a
1196Sdg *       state machine transition occurs.  Since this is a base object type it
1206Sdg *       does not actually know if the logging function is for the core or
1216Sdg *       framework.
1226Sdg * @param[in] the_object_name This is the name of the object that contains the
1236Sdg *       state machine being observed.
1246Sdg * @param[in] the_state_machine_name This is the name that will be displayed
1256Sdg *       in the log string for the state machine being observed.
1266Sdg * @param[in] the_object_mask This is the log object mask used when calling
1276Sdg *       the logging function.
1286Sdg *
1296Sdg * @return Nothing
1306Sdg */
1316Sdgvoid sci_base_state_machine_logger_construct(
1326Sdg   SCI_BASE_STATE_MACHINE_LOGGER_T             * this_observer,
1336Sdg   SCI_BASE_OBJECT_T                           * the_object,
1346Sdg   SCI_BASE_STATE_MACHINE_LOGGER_LOG_HANDLER_T   the_log_function,
1356Sdg   char                                        * log_object_name,
1366Sdg   char                                        * log_state_machine_name,
1376Sdg   U32                                           log_object_mask
1386Sdg)
1396Sdg{
1406Sdg   sci_base_state_machine_observer_construct(&this_observer->parent);
1416Sdg
1426Sdg   this_observer->log_object             = the_object;
1436Sdg   this_observer->log_function           = the_log_function;
1446Sdg   this_observer->log_object_name        = log_object_name;
1456Sdg   this_observer->log_state_machine_name = log_state_machine_name;
1466Sdg   this_observer->log_mask               = log_object_mask;
1476Sdg
1486Sdg   this_observer->parent.parent.update = sci_base_state_machine_logger_update;
1496Sdg}
1506Sdg
1516Sdg/**
1526Sdg * This is a helper function that will construct the state machine logger and
1536Sdg * attach it to the state machine that is to be observed.
1546Sdg *
1556Sdg * @param[in] this_observer This is the state machine logger object that is
1566Sdg *       going to observe the subject state machine.
1576Sdg * @param[in] the_state_machine This is the state machine that is under
1586Sdg *       observation.
1596Sdg * @param[in] the_object This is the object that contains the state machine
1606Sdg *       being observed it is used to report the address of the object for
1616Sdg *       which a state transition has occurred.
1626Sdg * @param[in] the_log_function This is the logging function to be used when a
1636Sdg *       state machine transition occurs.  Since this is a base object type it
1646Sdg *       does not actually know if the logging function is for the core or
1656Sdg *       framework.
1666Sdg * @param[in] the_object_name This is the name of the object that contains the
1676Sdg *       state machine being observed.
1686Sdg * @param[in] the_state_machine_name This is the name that will be displayed
1696Sdg *       in the log string for the state machine being observed.
1706Sdg * @param[in] the_object_mask This is the log object mask used when calling
1716Sdg *       the logging function.
1726Sdg *
1736Sdg * @return Nothing
1746Sdg */
1756Sdgvoid sci_base_state_machine_logger_initialize(
1766Sdg   SCI_BASE_STATE_MACHINE_LOGGER_T             * this_observer,
1776Sdg   SCI_BASE_STATE_MACHINE_T                    * the_state_machine,
1786Sdg   SCI_BASE_OBJECT_T                           * the_object,
1796Sdg   SCI_BASE_STATE_MACHINE_LOGGER_LOG_HANDLER_T   the_log_function,
1806Sdg   char                                        * log_object_name,
1816Sdg   char                                        * log_state_machine_name,
1826Sdg   U32                                           log_object_mask
1836Sdg)
1846Sdg{
1856Sdg   sci_base_state_machine_logger_construct(
1866Sdg      this_observer, the_object,
1876Sdg      the_log_function, log_object_name, log_state_machine_name, log_object_mask
1886Sdg   );
1896Sdg
1906Sdg   sci_base_subject_attach_observer(
1916Sdg      &the_state_machine->parent, &this_observer->parent.parent
1926Sdg   );
1936Sdg}
1946Sdg
1956Sdg/**
1966Sdg * This is a helper function that will detach this observer from the state
1976Sdg * machine that is being observerd.
1986Sdg *
1996Sdg * @param[in] this_observer This is the observer to detach from the state
2006Sdg *       machine.
2016Sdg * @parame[in] the_state_machine This is the state machine that is no longer
2026Sdg *       going to be observed.
2036Sdg *
2046Sdg * @return Nothing
2056Sdg */
2066Sdgvoid sci_base_state_machine_logger_deinitialize(
2076Sdg   SCI_BASE_STATE_MACHINE_LOGGER_T * this_observer,
2086Sdg   SCI_BASE_STATE_MACHINE_T        * the_state_machine
2096Sdg)
2106Sdg{
2116Sdg   sci_base_subject_detach_observer(
2126Sdg      &the_state_machine->parent, &this_observer->parent.parent
2136Sdg   );
2146Sdg}
2156Sdg
2166Sdg#endif // defined(SCI_LOGGING)
2176Sdg
2186Sdg