1f11c7f63SJim Harris /*-
2*718cf2ccSPedro F. Giffuni * SPDX-License-Identifier: BSD-2-Clause OR GPL-2.0
3*718cf2ccSPedro F. Giffuni *
4f11c7f63SJim Harris * This file is provided under a dual BSD/GPLv2 license. When using or
5f11c7f63SJim Harris * redistributing this file, you may do so under either license.
6f11c7f63SJim Harris *
7f11c7f63SJim Harris * GPL LICENSE SUMMARY
8f11c7f63SJim Harris *
9f11c7f63SJim Harris * Copyright(c) 2008 - 2011 Intel Corporation. All rights reserved.
10f11c7f63SJim Harris *
11f11c7f63SJim Harris * This program is free software; you can redistribute it and/or modify
12f11c7f63SJim Harris * it under the terms of version 2 of the GNU General Public License as
13f11c7f63SJim Harris * published by the Free Software Foundation.
14f11c7f63SJim Harris *
15f11c7f63SJim Harris * This program is distributed in the hope that it will be useful, but
16f11c7f63SJim Harris * WITHOUT ANY WARRANTY; without even the implied warranty of
17f11c7f63SJim Harris * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
18f11c7f63SJim Harris * General Public License for more details.
19f11c7f63SJim Harris *
20f11c7f63SJim Harris * You should have received a copy of the GNU General Public License
21f11c7f63SJim Harris * along with this program; if not, write to the Free Software
22f11c7f63SJim Harris * Foundation, Inc., 51 Franklin St - Fifth Floor, Boston, MA 02110-1301 USA.
23f11c7f63SJim Harris * The full GNU General Public License is included in this distribution
24f11c7f63SJim Harris * in the file called LICENSE.GPL.
25f11c7f63SJim Harris *
26f11c7f63SJim Harris * BSD LICENSE
27f11c7f63SJim Harris *
28f11c7f63SJim Harris * Copyright(c) 2008 - 2011 Intel Corporation. All rights reserved.
29f11c7f63SJim Harris * All rights reserved.
30f11c7f63SJim Harris *
31f11c7f63SJim Harris * Redistribution and use in source and binary forms, with or without
32f11c7f63SJim Harris * modification, are permitted provided that the following conditions
33f11c7f63SJim Harris * are met:
34f11c7f63SJim Harris *
35f11c7f63SJim Harris * * Redistributions of source code must retain the above copyright
36f11c7f63SJim Harris * notice, this list of conditions and the following disclaimer.
37f11c7f63SJim Harris * * Redistributions in binary form must reproduce the above copyright
38f11c7f63SJim Harris * notice, this list of conditions and the following disclaimer in
39f11c7f63SJim Harris * the documentation and/or other materials provided with the
40f11c7f63SJim Harris * distribution.
41f11c7f63SJim Harris *
42f11c7f63SJim Harris * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
43f11c7f63SJim Harris * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
44f11c7f63SJim Harris * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
45f11c7f63SJim Harris * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
46f11c7f63SJim Harris * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
47f11c7f63SJim Harris * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
48f11c7f63SJim Harris * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
49f11c7f63SJim Harris * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
50f11c7f63SJim Harris * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
51f11c7f63SJim Harris * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
52f11c7f63SJim Harris * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
53f11c7f63SJim Harris */
54f11c7f63SJim Harris
55f11c7f63SJim Harris #include <sys/cdefs.h>
56f11c7f63SJim Harris /**
57f11c7f63SJim Harris * @file
58f11c7f63SJim Harris *
59f11c7f63SJim Harris * @brief This file provides the public and protected implementations for the
60f11c7f63SJim Harris * state machine logger. The state machine logger will provide debug
61f11c7f63SJim Harris * log information on a state machine for each state transition.
62f11c7f63SJim Harris */
63f11c7f63SJim Harris
64f11c7f63SJim Harris #include <dev/isci/scil/sci_base_state_machine_logger.h>
65f11c7f63SJim Harris
66f11c7f63SJim Harris #if defined(SCI_LOGGING)
67f11c7f63SJim Harris
68f11c7f63SJim Harris //******************************************************************************
69f11c7f63SJim Harris //* P R O T E C T E D M E T H O D S
70f11c7f63SJim Harris //******************************************************************************
71f11c7f63SJim Harris
72f11c7f63SJim Harris /**
73f11c7f63SJim Harris * This is the function that is called when the state machine wants to notify
74f11c7f63SJim Harris * this observer that there has been a state change.
75f11c7f63SJim Harris *
76f11c7f63SJim Harris * @param[in] observer The state machine logger that is observing the state
77f11c7f63SJim Harris * machine.
78f11c7f63SJim Harris * @param[in] subject The state machine that is being observed.
79f11c7f63SJim Harris */
80f11c7f63SJim Harris static
sci_base_state_machine_logger_update(SCI_BASE_OBSERVER_T * observer,SCI_BASE_SUBJECT_T * subject)81f11c7f63SJim Harris void sci_base_state_machine_logger_update(
82f11c7f63SJim Harris SCI_BASE_OBSERVER_T *observer,
83f11c7f63SJim Harris SCI_BASE_SUBJECT_T *subject
84f11c7f63SJim Harris )
85f11c7f63SJim Harris {
86f11c7f63SJim Harris SCI_BASE_STATE_MACHINE_LOGGER_T *this_observer;
87f11c7f63SJim Harris this_observer = (SCI_BASE_STATE_MACHINE_LOGGER_T *)observer;
88f11c7f63SJim Harris
89f11c7f63SJim Harris this_observer->log_function(
90f11c7f63SJim Harris sci_base_object_get_logger(this_observer->log_object),
91f11c7f63SJim Harris this_observer->log_mask,
92f11c7f63SJim Harris "%s 0x%08x %s has transitioned from %d to %d\n",
93f11c7f63SJim Harris this_observer->log_object_name,
94f11c7f63SJim Harris this_observer->log_object,
95f11c7f63SJim Harris this_observer->log_state_machine_name,
96f11c7f63SJim Harris this_observer->parent.subject_state,
97f11c7f63SJim Harris sci_base_state_machine_get_state((SCI_BASE_STATE_MACHINE_T *)subject)
98f11c7f63SJim Harris );
99f11c7f63SJim Harris
100f11c7f63SJim Harris sci_base_state_machine_observer_default_update(
101f11c7f63SJim Harris &this_observer->parent.parent, subject
102f11c7f63SJim Harris );
103f11c7f63SJim Harris }
104f11c7f63SJim Harris
105f11c7f63SJim Harris //******************************************************************************
106f11c7f63SJim Harris //* P U B L I C M E T H O D S
107f11c7f63SJim Harris //******************************************************************************
108f11c7f63SJim Harris
109f11c7f63SJim Harris /**
110f11c7f63SJim Harris * This function will construct the state machine logger and attach it to the
111f11c7f63SJim Harris * state machine that is to be observed.
112f11c7f63SJim Harris *
113f11c7f63SJim Harris * @param[in] this_observer This is the state machine logger object that is
114f11c7f63SJim Harris * going to observe the subject state machine.
115f11c7f63SJim Harris * @param[in] the_object This is the object that contains the state machine
116f11c7f63SJim Harris * being observed it is used to report the address of the object for
117f11c7f63SJim Harris * which a state transition has occurred.
118f11c7f63SJim Harris * @param[in] the_log_function This is the logging function to be used when a
119f11c7f63SJim Harris * state machine transition occurs. Since this is a base object type it
120f11c7f63SJim Harris * does not actually know if the logging function is for the core or
121f11c7f63SJim Harris * framework.
122f11c7f63SJim Harris * @param[in] the_object_name This is the name of the object that contains the
123f11c7f63SJim Harris * state machine being observed.
124f11c7f63SJim Harris * @param[in] the_state_machine_name This is the name that will be displayed
125f11c7f63SJim Harris * in the log string for the state machine being observed.
126f11c7f63SJim Harris * @param[in] the_object_mask This is the log object mask used when calling
127f11c7f63SJim Harris * the logging function.
128f11c7f63SJim Harris *
129f11c7f63SJim Harris * @return Nothing
130f11c7f63SJim Harris */
sci_base_state_machine_logger_construct(SCI_BASE_STATE_MACHINE_LOGGER_T * this_observer,SCI_BASE_OBJECT_T * the_object,SCI_BASE_STATE_MACHINE_LOGGER_LOG_HANDLER_T the_log_function,char * log_object_name,char * log_state_machine_name,U32 log_object_mask)131f11c7f63SJim Harris void sci_base_state_machine_logger_construct(
132f11c7f63SJim Harris SCI_BASE_STATE_MACHINE_LOGGER_T * this_observer,
133f11c7f63SJim Harris SCI_BASE_OBJECT_T * the_object,
134f11c7f63SJim Harris SCI_BASE_STATE_MACHINE_LOGGER_LOG_HANDLER_T the_log_function,
135f11c7f63SJim Harris char * log_object_name,
136f11c7f63SJim Harris char * log_state_machine_name,
137f11c7f63SJim Harris U32 log_object_mask
138f11c7f63SJim Harris )
139f11c7f63SJim Harris {
140f11c7f63SJim Harris sci_base_state_machine_observer_construct(&this_observer->parent);
141f11c7f63SJim Harris
142f11c7f63SJim Harris this_observer->log_object = the_object;
143f11c7f63SJim Harris this_observer->log_function = the_log_function;
144f11c7f63SJim Harris this_observer->log_object_name = log_object_name;
145f11c7f63SJim Harris this_observer->log_state_machine_name = log_state_machine_name;
146f11c7f63SJim Harris this_observer->log_mask = log_object_mask;
147f11c7f63SJim Harris
148f11c7f63SJim Harris this_observer->parent.parent.update = sci_base_state_machine_logger_update;
149f11c7f63SJim Harris }
150f11c7f63SJim Harris
151f11c7f63SJim Harris /**
152f11c7f63SJim Harris * This is a helper function that will construct the state machine logger and
153f11c7f63SJim Harris * attach it to the state machine that is to be observed.
154f11c7f63SJim Harris *
155f11c7f63SJim Harris * @param[in] this_observer This is the state machine logger object that is
156f11c7f63SJim Harris * going to observe the subject state machine.
157f11c7f63SJim Harris * @param[in] the_state_machine This is the state machine that is under
158f11c7f63SJim Harris * observation.
159f11c7f63SJim Harris * @param[in] the_object This is the object that contains the state machine
160f11c7f63SJim Harris * being observed it is used to report the address of the object for
161f11c7f63SJim Harris * which a state transition has occurred.
162f11c7f63SJim Harris * @param[in] the_log_function This is the logging function to be used when a
163f11c7f63SJim Harris * state machine transition occurs. Since this is a base object type it
164f11c7f63SJim Harris * does not actually know if the logging function is for the core or
165f11c7f63SJim Harris * framework.
166f11c7f63SJim Harris * @param[in] the_object_name This is the name of the object that contains the
167f11c7f63SJim Harris * state machine being observed.
168f11c7f63SJim Harris * @param[in] the_state_machine_name This is the name that will be displayed
169f11c7f63SJim Harris * in the log string for the state machine being observed.
170f11c7f63SJim Harris * @param[in] the_object_mask This is the log object mask used when calling
171f11c7f63SJim Harris * the logging function.
172f11c7f63SJim Harris *
173f11c7f63SJim Harris * @return Nothing
174f11c7f63SJim Harris */
sci_base_state_machine_logger_initialize(SCI_BASE_STATE_MACHINE_LOGGER_T * this_observer,SCI_BASE_STATE_MACHINE_T * the_state_machine,SCI_BASE_OBJECT_T * the_object,SCI_BASE_STATE_MACHINE_LOGGER_LOG_HANDLER_T the_log_function,char * log_object_name,char * log_state_machine_name,U32 log_object_mask)175f11c7f63SJim Harris void sci_base_state_machine_logger_initialize(
176f11c7f63SJim Harris SCI_BASE_STATE_MACHINE_LOGGER_T * this_observer,
177f11c7f63SJim Harris SCI_BASE_STATE_MACHINE_T * the_state_machine,
178f11c7f63SJim Harris SCI_BASE_OBJECT_T * the_object,
179f11c7f63SJim Harris SCI_BASE_STATE_MACHINE_LOGGER_LOG_HANDLER_T the_log_function,
180f11c7f63SJim Harris char * log_object_name,
181f11c7f63SJim Harris char * log_state_machine_name,
182f11c7f63SJim Harris U32 log_object_mask
183f11c7f63SJim Harris )
184f11c7f63SJim Harris {
185f11c7f63SJim Harris sci_base_state_machine_logger_construct(
186f11c7f63SJim Harris this_observer, the_object,
187f11c7f63SJim Harris the_log_function, log_object_name, log_state_machine_name, log_object_mask
188f11c7f63SJim Harris );
189f11c7f63SJim Harris
190f11c7f63SJim Harris sci_base_subject_attach_observer(
191f11c7f63SJim Harris &the_state_machine->parent, &this_observer->parent.parent
192f11c7f63SJim Harris );
193f11c7f63SJim Harris }
194f11c7f63SJim Harris
195f11c7f63SJim Harris /**
196f11c7f63SJim Harris * This is a helper function that will detach this observer from the state
197f11c7f63SJim Harris * machine that is being observerd.
198f11c7f63SJim Harris *
199f11c7f63SJim Harris * @param[in] this_observer This is the observer to detach from the state
200f11c7f63SJim Harris * machine.
201f11c7f63SJim Harris * @parame[in] the_state_machine This is the state machine that is no longer
202f11c7f63SJim Harris * going to be observed.
203f11c7f63SJim Harris *
204f11c7f63SJim Harris * @return Nothing
205f11c7f63SJim Harris */
sci_base_state_machine_logger_deinitialize(SCI_BASE_STATE_MACHINE_LOGGER_T * this_observer,SCI_BASE_STATE_MACHINE_T * the_state_machine)206f11c7f63SJim Harris void sci_base_state_machine_logger_deinitialize(
207f11c7f63SJim Harris SCI_BASE_STATE_MACHINE_LOGGER_T * this_observer,
208f11c7f63SJim Harris SCI_BASE_STATE_MACHINE_T * the_state_machine
209f11c7f63SJim Harris )
210f11c7f63SJim Harris {
211f11c7f63SJim Harris sci_base_subject_detach_observer(
212f11c7f63SJim Harris &the_state_machine->parent, &this_observer->parent.parent
213f11c7f63SJim Harris );
214f11c7f63SJim Harris }
215f11c7f63SJim Harris
216f11c7f63SJim Harris #endif // defined(SCI_LOGGING)
217f11c7f63SJim Harris
218