sci_base_state_machine.h revision 230557
110015Speter/*- 212496Speter * This file is provided under a dual BSD/GPLv2 license. When using or 310015Speter * redistributing this file, you may do so under either license. 410015Speter * 510015Speter * GPL LICENSE SUMMARY 610015Speter * 710015Speter * Copyright(c) 2008 - 2011 Intel Corporation. All rights reserved. 810015Speter * 910015Speter * This program is free software; you can redistribute it and/or modify 1010015Speter * it under the terms of version 2 of the GNU General Public License as 1110015Speter * published by the Free Software Foundation. 1210015Speter * 1310015Speter * This program is distributed in the hope that it will be useful, but 1410015Speter * WITHOUT ANY WARRANTY; without even the implied warranty of 1510015Speter * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 1610015Speter * General Public License for more details. 1710015Speter * 1810015Speter * You should have received a copy of the GNU General Public License 1910015Speter * along with this program; if not, write to the Free Software 2010015Speter * Foundation, Inc., 51 Franklin St - Fifth Floor, Boston, MA 02110-1301 USA. 2110015Speter * The full GNU General Public License is included in this distribution 2210015Speter * in the file called LICENSE.GPL. 2310015Speter * 2410015Speter * BSD LICENSE 2510015Speter * 2610015Speter * Copyright(c) 2008 - 2011 Intel Corporation. All rights reserved. 2710015Speter * All rights reserved. 2810015Speter * 2910015Speter * Redistribution and use in source and binary forms, with or without 3010015Speter * modification, are permitted provided that the following conditions 3110015Speter * are met: 3210015Speter * 3316444Speter * * Redistributions of source code must retain the above copyright 3410015Speter * notice, this list of conditions and the following disclaimer. 3510015Speter * * Redistributions in binary form must reproduce the above copyright 3610015Speter * notice, this list of conditions and the following disclaimer in 3716322Sgpalmer * the documentation and/or other materials provided with the 3816322Sgpalmer * distribution. 3916322Sgpalmer * 4010015Speter * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS 4110015Speter * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT 4210015Speter * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR 4310015Speter * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT 4410015Speter * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, 4510015Speter * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT 4610015Speter * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, 4710015Speter * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY 4810015Speter * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 4910015Speter * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE 5010015Speter * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 5110015Speter * 5210015Speter * $FreeBSD$ 5310015Speter */ 5410015Speter#ifndef _SCI_BASE_STATE_MACHINE_H_ 5515683Speter#define _SCI_BASE_STATE_MACHINE_H_ 5610015Speter 5712675Sjulian/** 5812675Sjulian * @file 5912675Sjulian * 6010015Speter * @brief This file contains all structures, constants, or method declarations 6110015Speter * common to all state machines defined in SCI. 6210015Speter */ 6312659Sbde 6412662Sdg#ifdef __cplusplus 6512662Sdgextern "C" { 6612659Sbde#endif // __cplusplus 6710015Speter 6810015Speter#include <dev/isci/scil/sci_base_subject.h> 6910015Speter#include <dev/isci/scil/sci_base_state.h> 7010015Speter 7110015Speter 7210015Speter/** 7313353Speter * This macro simply provides simplified retrieval of an objects state 7410015Speter * handler. 7510015Speter */ 7610015Speter#define SET_STATE_HANDLER(object, table, state) \ 7710015Speter (object)->state_handlers = &(table)[(state)] 7810015Speter 7912496Speter/** 8010015Speter * @struct SCI_BASE_STATE_MACHINE 8110015Speter * 8210015Speter * @brief This structure defines the fields common to all state machines. 8310015Speter */ 8410015Spetertypedef struct SCI_BASE_STATE_MACHINE 8510015Speter{ 8610047Speter#if defined(SCI_LOGGING) 8712496Speter /** 8815639Speter * The state machine object participates in the observer design pattern. 8915639Speter * Thus, the SCI_BASE_SUBJECT is the parent object, which allows a 9010015Speter * state machine to be easily monitored by a user. 9110015Speter */ 9210015Speter SCI_BASE_SUBJECT_T parent; 9310015Speter#endif // defined(SCI_LOGGING) 9410015Speter 9510015Speter /** 9610015Speter * This field points to the start of the state machine's state table. 9710015Speter */ 9810015Speter SCI_BASE_STATE_T * state_table; 9910015Speter 10010015Speter /** 10110015Speter * This field points to the object to which this state machine is 10210015Speter * associated. It serves as a cookie to be provided to the state 10310015Speter * enter/exit methods. 10412724Sphk */ 10510015Speter SCI_BASE_OBJECT_T * state_machine_owner; 10612724Sphk 10712724Sphk /** 10812724Sphk * This field simply indicates the state value for the state machine's 10910708Speter * initial state. 11010708Speter */ 11112675Sjulian U32 initial_state_id; 11212675Sjulian 11312675Sjulian /** 11412675Sjulian * This field indicates the current state of the state machine. 11512675Sjulian */ 11612675Sjulian U32 current_state_id; 11712675Sjulian 11812675Sjulian /** 11912675Sjulian * This field indicates the previous state of the state machine. 12012675Sjulian */ 12112731Sbde U32 previous_state_id; 12212675Sjulian 12312675Sjulian} SCI_BASE_STATE_MACHINE_T; 12412678Sphk 12512675Sjulian//****************************************************************************** 12612743Sbde//* P R O T E C T E D M E T H O D S 12712742Sbde//****************************************************************************** 12812675Sjulian 12912675Sjulianvoid sci_base_state_machine_construct( 13012174Speter SCI_BASE_STATE_MACHINE_T *this_state_machine, 13113353Speter SCI_BASE_OBJECT_T *state_machine_owner, 13213353Speter SCI_BASE_STATE_T *state_table, 13313353Speter U32 initial_state 13410708Speter); 13513353Speter 13610708Spetervoid sci_base_state_machine_start( 13713353Speter SCI_BASE_STATE_MACHINE_T *this_state_machine 13810708Speter); 13910708Speter 14010708Spetervoid sci_base_state_machine_stop( 14110708Speter SCI_BASE_STATE_MACHINE_T *this_state_machine 14210962Speter); 14310962Speter 14410962Spetervoid sci_base_state_machine_change_state( 14510015Speter SCI_BASE_STATE_MACHINE_T *this_state_machine, 14610962Speter U32 next_state 14710962Speter); 14812174Speter 14910015SpeterU32 sci_base_state_machine_get_state( 15010015Speter SCI_BASE_STATE_MACHINE_T *this_state_machine 15110015Speter); 15210044Speter 15310044Speter#ifdef __cplusplus 15410044Speter} 15510044Speter#endif // __cplusplus 15610044Speter 15710044Speter#endif // _SCI_BASE_STATE_MACHINE_H_ 15810044Speter