]>
git.ipfire.org Git - people/ms/rstp.git/blob - rstplib/statmch.c
1 /************************************************************************
2 * RSTP library - Rapid Spanning Tree (802.1t, 802.1w)
3 * Copyright (C) 2001-2003 Optical Access
6 * This file is part of RSTP library.
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
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.
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
21 **********************************************************************/
23 /* Generic (abstract) state machine : 17.13, 17.14 */
33 STP_state_mach_create (void (*concreteEnterState
) (STATE_MACH_T
*),
34 Bool (*concreteCheckCondition
) (STATE_MACH_T
*),
35 char *(*concreteGetStatName
) (int),
36 void *owner
, char *name
)
40 STP_MALLOC(this, STATE_MACH_T
, "state machine");
43 this->name
= (char*) strdup (name
);
44 this->changeState
= False
;
47 this->ignoreHop2State
= BEGIN
;
49 this->concreteEnterState
= concreteEnterState
;
50 this->concreteCheckCondition
= concreteCheckCondition
;
51 this->concreteGetStatName
= concreteGetStatName
;
52 this->owner
.owner
= owner
;
58 STP_state_mach_delete (STATE_MACH_T
*this)
61 STP_FREE(this, "state machine");
65 STP_check_condition (STATE_MACH_T
* this)
69 bret
= (*(this->concreteCheckCondition
)) (this);
71 this->changeState
= True
;
78 STP_change_state (STATE_MACH_T
* this)
80 register int number_of_loops
;
82 for (number_of_loops
= 0; ; number_of_loops
++) {
83 if (! this->changeState
) return number_of_loops
;
84 (*(this->concreteEnterState
)) (this);
85 this->changeState
= False
;
86 STP_check_condition (this);
89 return number_of_loops
;
93 STP_hop_2_state (STATE_MACH_T
* this, unsigned int new_state
)
96 switch (this->debug
) {
99 if (new_state
== this->State
|| new_state
== this->ignoreHop2State
) break;
100 stp_trace ("%-8s(%s-%s): %s=>%s",
102 *this->owner
.port
->owner
->name
? this->owner
.port
->owner
->name
: "Glbl",
103 this->owner
.port
->port_name
,
104 (*(this->concreteGetStatName
)) (this->State
),
105 (*(this->concreteGetStatName
)) (new_state
));
108 if (new_state
== this->State
) break;
109 stp_trace ("%s(%s): %s=>%s",
111 *this->owner
.stpm
->name
? this->owner
.stpm
->name
: "Glbl",
112 (*(this->concreteGetStatName
)) (this->State
),
113 (*(this->concreteGetStatName
)) (new_state
));
118 this->State
= new_state
;
119 this->changeState
= True
;