sci_base_state_machine_observer.c revision 230557
1314125Sdelphij/*-
2110010Smarkm * This file is provided under a dual BSD/GPLv2 license.  When using or
3110010Smarkm * redistributing this file, you may do so under either license.
4142429Snectar *
5110010Smarkm * GPL LICENSE SUMMARY
6110010Smarkm *
7110010Smarkm * Copyright(c) 2008 - 2011 Intel Corporation. All rights reserved.
8110010Smarkm *
9110010Smarkm * This program is free software; you can redistribute it and/or modify
10110010Smarkm * it under the terms of version 2 of the GNU General Public License as
11110010Smarkm * published by the Free Software Foundation.
12110010Smarkm *
13110010Smarkm * This program is distributed in the hope that it will be useful, but
14110010Smarkm * WITHOUT ANY WARRANTY; without even the implied warranty of
15110010Smarkm * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
16110010Smarkm * General Public License for more details.
17110010Smarkm *
18110010Smarkm * You should have received a copy of the GNU General Public License
19110010Smarkm * along with this program; if not, write to the Free Software
20215698Ssimon * Foundation, Inc., 51 Franklin St - Fifth Floor, Boston, MA 02110-1301 USA.
21215698Ssimon * The full GNU General Public License is included in this distribution
22215698Ssimon * in the file called LICENSE.GPL.
23215698Ssimon *
24215698Ssimon * BSD LICENSE
25110010Smarkm *
26110010Smarkm * Copyright(c) 2008 - 2011 Intel Corporation. All rights reserved.
27110010Smarkm * All rights reserved.
28110010Smarkm *
29110010Smarkm * Redistribution and use in source and binary forms, with or without
30110010Smarkm * modification, are permitted provided that the following conditions
31110010Smarkm * are met:
32110010Smarkm *
33110010Smarkm *   * Redistributions of source code must retain the above copyright
34110010Smarkm *     notice, this list of conditions and the following disclaimer.
35110010Smarkm *   * Redistributions in binary form must reproduce the above copyright
36110010Smarkm *     notice, this list of conditions and the following disclaimer in
37110010Smarkm *     the documentation and/or other materials provided with the
38110010Smarkm *     distribution.
39110010Smarkm *
40110010Smarkm * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
41276861Sjkim * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
42276861Sjkim * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
43110010Smarkm * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
44110010Smarkm * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
45215698Ssimon * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
46215698Ssimon * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
47215698Ssimon * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
48215698Ssimon * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
49314125Sdelphij * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
50215698Ssimon * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
51142429Snectar */
52142429Snectar
53276861Sjkim#include <sys/cdefs.h>
54276861Sjkim__FBSDID("$FreeBSD$");
55276861Sjkim
56110010Smarkm/**
57314125Sdelphij * @file
58314125Sdelphij *
59314125Sdelphij * @brief This file provides the implementation for the observer role
60314125Sdelphij *        for a state machine.  A state machine observer is notified when
61215698Ssimon *        the state machine changes states.
62314125Sdelphij */
63314125Sdelphij
64314125Sdelphij#include <dev/isci/scil/sci_base_state_machine.h>
65276861Sjkim#include <dev/isci/scil/sci_base_state_machine_observer.h>
66215698Ssimon
67110010Smarkm#if defined(SCI_LOGGING)
68110010Smarkm
69110010Smarkm#define SCI_BASE_INVALID_SUBJECT_STATE 0xFFFF
70110010Smarkm
71110010Smarkm//******************************************************************************
72110010Smarkm//* P R O T E C T E D    M E T H O D S
73110010Smarkm//******************************************************************************
74110010Smarkm
75110010Smarkmvoid sci_base_state_machine_observer_default_update(
76110010Smarkm   SCI_BASE_OBSERVER_T *this_observer,
77110010Smarkm   SCI_BASE_SUBJECT_T  *the_subject
78110010Smarkm)
79110010Smarkm{
80110010Smarkm   SCI_BASE_STATE_MACHINE_OBSERVER_T *state_machine_observer;
81110010Smarkm
82110010Smarkm   state_machine_observer = (SCI_BASE_STATE_MACHINE_OBSERVER_T *)this_observer;
83110010Smarkm
84110010Smarkm   state_machine_observer->subject_state =
85110010Smarkm      sci_base_state_machine_get_state((SCI_BASE_STATE_MACHINE_T *)the_subject);
86110010Smarkm}
87110010Smarkm
88110010Smarkm// ---------------------------------------------------------------------------
89110010Smarkm
90110010Smarkmvoid sci_base_state_machine_observer_construct(
91110010Smarkm   SCI_BASE_STATE_MACHINE_OBSERVER_T *this_observer
92110010Smarkm)
93110010Smarkm{
94110010Smarkm   this_observer->parent.update = sci_base_state_machine_observer_default_update;
95110010Smarkm
96110010Smarkm   this_observer->subject_state = SCI_BASE_INVALID_SUBJECT_STATE;
97110010Smarkm}
98110010Smarkm
99110010Smarkm#endif // defined(SCI_LOGGING)
100110010Smarkm