statmch.h
上传用户:allwinjm
上传日期:2021-08-29
资源大小:99k
文件大小:3k
源码类别:

Internet/IE编程

开发平台:

Unix_Linux

  1. /************************************************************************ 
  2.  * RSTP library - Rapid Spanning Tree (802.1t, 802.1w) 
  3.  * Copyright (C) 2001-2003 Optical Access 
  4.  * Author: Alex Rozin 
  5.  * 
  6.  * This file is part of RSTP library. 
  7.  * 
  8.  * RSTP library is free software; you can redistribute it and/or modify it 
  9.  * under the terms of the GNU Lesser General Public License as published by the 
  10.  * Free Software Foundation; version 2.1 
  11.  * 
  12.  * RSTP library is distributed in the hope that it will be useful, but 
  13.  * WITHOUT ANY WARRANTY; without even the implied warranty of 
  14.  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU Lesser 
  15.  * General Public License for more details. 
  16.  * 
  17.  * You should have received a copy of the GNU Lesser General Public License 
  18.  * along with RSTP library; see the file COPYING.  If not, write to the Free 
  19.  * Software Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 
  20.  * 02111-1307, USA. 
  21.  **********************************************************************/
  22. /* Generic (abstract state machine) state machine : 17.13, 17.14 */
  23.  
  24. #ifndef _STP_STATER_H__
  25. #define _STP_STATER_H__
  26. #define BEGIN  9999 /* distinct from any valid state */
  27. typedef struct state_mach_t {
  28.   struct state_mach_t* next;
  29.   char*         name; /* for debugging */
  30. #ifdef STP_DBG
  31.   char          debug; /* 0- no dbg, 1 - port, 2 - stpm */
  32.   unsigned int  ignoreHop2State;
  33. #endif
  34.   Bool          changeState;
  35.   unsigned int  State;
  36.   void          (* concreteEnterState) (struct state_mach_t * );
  37.   Bool          (* concreteCheckCondition) (struct state_mach_t * );
  38.   char*         (* concreteGetStatName) (int);
  39.   union {
  40.     struct stpm_t* stpm;
  41.     struct port_t* port;
  42.     void         * owner;
  43.   } owner;
  44. } STATE_MACH_T;
  45. #define STP_STATE_MACH_IN_LIST(WHAT)                              
  46.   {                                                               
  47.     STATE_MACH_T* abstr;                                          
  48.                                                                   
  49.     abstr = STP_state_mach_create (STP_##WHAT##_enter_state,      
  50.                                   STP_##WHAT##_check_conditions,  
  51.                                   STP_##WHAT##_get_state_name,    
  52.                                   this,                           
  53.                                   #WHAT);                         
  54.     abstr->next = this->machines;                                 
  55.     this->machines = abstr;                                       
  56.     this->WHAT = abstr;                       
  57.   }
  58. STATE_MACH_T *
  59. STP_state_mach_create (void (* concreteEnterState) (STATE_MACH_T*),
  60.                        Bool (* concreteCheckCondition) (STATE_MACH_T*),
  61.                        char * (* concreteGetStatName) (int),
  62.                        void* owner, char* name);
  63.                      
  64. void
  65. STP_state_mach_delete (STATE_MACH_T* this);
  66. Bool
  67. STP_check_condition (STATE_MACH_T* this);
  68. Bool
  69. STP_change_state (STATE_MACH_T* this);
  70. Bool
  71. STP_hop_2_state (STATE_MACH_T* this, unsigned int new_state);
  72. #endif /* _STP_STATER_H__ */