⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 statmch.c

📁 rstp for switch in vxworks
💻 C
字号:

/************************************************************************ 
 * RSTP library - Rapid Spanning Tree (802.1t, 802.1w) 
 * Copyright (C) 2001-2003 Optical Access 
 * Author: Alex Rozin 
 * 
 * This file is part of RSTP library. 
 * 
 * RSTP library is free software; you can redistribute it and/or modify it 
 * under the terms of the GNU Lesser General Public License as published by the 
 * Free Software Foundation; version 2.1 
 * 
 * RSTP library is distributed in the hope that it will be useful, but 
 * WITHOUT ANY WARRANTY; without even the implied warranty of 
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU Lesser 
 * General Public License for more details. 
 * 
 * You should have received a copy of the GNU Lesser General Public License 
 * along with RSTP library; see the file COPYING.  If not, write to the Free 
 * Software Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 
 * 02111-1307, USA. 
 **********************************************************************/

/* Generic (abstract) state machine : 17.13, 17.14 */

/************************************************************************************
   此文件为各状态机跳转、进入状态的统一的函数集
************************************************************************************/

#include "base.h"
#include "statmch.h"

#if STP_DBG
#  include "stpm.h"
#endif

extern int cl_serv_console_fd;              



          
/************************************************************************************
  函数名称:
  输入参数:
  输出参数:
  功能描述: 创建状态机结构。给出状态机的EnterState函数和
                          CheckCondition函数
  返回值:
  备注           : 在宏STP_STATE_MACH_IN_LIST被调用,创建所有的状态机的结构
  作者           :
  日期           :
  ************************************************************************************/
STATE_MACH_T *
STP_state_mach_create (void (*concreteEnterState) (STATE_MACH_T*),/*函数参数1*/
                                                 Bool (*concreteCheckCondition) (STATE_MACH_T *), /*函数参数2*/
                                          	char *(*concreteGetStatName) (int), /*函数参数3*/
                                          	void *owner, 
                                          	char *name)
{
	STATE_MACH_T *this;

	STP_MALLOC (this, STATE_MACH_T, "state machine");

	this->State = BEGIN;
	this->name = (char *) strdup (name);
	this->changeState = False;

#if STP_DBG
	this->debug = False;
	this->ignoreHop2State = BEGIN;
#endif

	this->concreteEnterState = concreteEnterState;
	this->concreteCheckCondition = concreteCheckCondition;
	this->concreteGetStatName = concreteGetStatName;
	this->owner.owner = owner;

	return this;
}

/************************************************************************************
  函数名称:
  输入参数:
  输出参数:
  功能描述: 删除状态机
                          
  返回值:
  备注           : 
  作者           :
  日期           :
  ************************************************************************************/
void STP_state_mach_delete (STATE_MACH_T * this)
{
	free (this->name);
	STP_FREE (this, "state machine");
}

/************************************************************************************
  函数名称:
  输入参数:
  输出参数:  STATE_MACH_T->changeState
  功能描述:  调用具体的check_condition函数进行状态转移 
  返回值:       状态转移成功。True
                           未转移                      False
  备注           : 
  作者           :
  日期           :
  ************************************************************************************/
Bool STP_check_condition (STATE_MACH_T * this)
{
	Bool bret;

	bret = (*(this->concreteCheckCondition)) (this);

	if (bret)
	{
		this->changeState = True;
	}

	return bret;
}

/************************************************************************************
  函数名称:
  输入参数:
  输出参数:
  功能描述:   根据changeState的值,对状态机进行新的状态操作和状

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -