Summary of the invention
In view of this, the invention provides a kind of execution system being easily maintained with Extended FSM and execution method.
The execution system of a kind of finite state machine, the execution system of described finite state machine includes: engine unit, is used for receiving incoming event, as the trigger event of finite state machine;Memory element, for storing current state and the state-transition table of finite state machine;Performance element, for obtaining the current state of finite state machine from memory element, and according to engine unit provide incoming event and memory element in storage state-transition table obtain the confidential transfer of current state NextState machine and according to obtain NextState machine update finite state machine current state;nullDescribed state-transition table includes N shell state machine,Upper strata state machine includes some underlying state machines repelled each other,Several underlying state machines belonging to same upper strata state machine are to obtain by inheriting this upper strata state machine,Underlying state machines is provided with the interface module entering its upper strata state machine inherited,Make underlying state machines can post messages to its upper strata state machine inherited,Each state machine only one of which example in N shell state machine,Only process the incoming event with this example direct correlation,State machine layer in N shell receive there is no, with it, the incoming event directly contacted time,By interface module, this incoming event is sent to the state machine process on upper strata,State machine and this incoming event also not direct correlation such as upper strata,Then this incoming event is sent to the state machine of more top by the state machine on upper strata by its interface module,Until being sent to process the state machine of this incoming event.
A kind of execution method of finite state machine, including step: receive incoming event, as the trigger event of finite state machine;nullObtain the current state of finite state machine,And according to engine unit provide incoming event and a state-transition table,Obtain the NextState machine of the confidential transfer of current state,Described state-transition table includes N shell state machine,Upper strata state machine includes some underlying state machines repelled each other,Several underlying state machines belonging to same upper strata state machine are to obtain by inheriting this upper strata state machine,Underlying state machines is provided with the interface module entering its upper strata state machine inherited,Make underlying state machines can post messages to its upper strata state machine inherited,Each state machine only one of which example in N shell state machine,Only process the incoming event with this example direct correlation,State machine layer in N shell receive there is no, with it, the incoming event directly contacted time,By interface module, this incoming event is sent to the state machine process on upper strata,State machine and this incoming event also not direct correlation such as upper strata,Then this incoming event is sent to the state machine of more top by the state machine on upper strata by its interface module,Until being sent to process the state machine of this incoming event;The current state of finite state machine is updated according to the NextState machine obtained.
Execution system and the execution method of above-mentioned finite state machine only need to delete this state machine when deleting certain state machine, have no effect on the setting of other state machines, and when setting up new state machine, only need to set up the inheritance between this new state machine and this new state machine and corresponding upper strata state machine, it is easy to maintenance and expansion.
Detailed description of the invention
Refer to Fig. 1 and Fig. 2, be the module map of the execution system 10 of finite state machine in an embodiment.The execution system 10 of finite state machine includes engine unit 20, memory element 30 and performance element 40.
Engine unit 20 is used for receiving incoming event, as the trigger event of finite state machine.
Memory element 30 is for storing current state and the state-transition table 50 of finite state machine.State-transition table 50 includes N shell state machine, N shell state machine includes 1 layer 1 state machine, this layer 1 state machine includes several layer 2 state machines repelled each other, several layer 3 state machines repelled each other are included under each layer 2 state machine, the like, until several layer N-1 state machines repelled each other, under each layer of N-1 state machine, include several layer N-state machines repelled each other.Wherein, several underlying state machines belonging to same upper strata state machine are to obtain by inheriting this upper strata state machine.Underlying state machines is provided with the interface module entering its upper strata state machine inherited so that underlying state machines can post messages to its upper strata state machine inherited.Each state machine in N shell state machine carries out reservation process for the incoming event received according to engine unit 20.Each layer of N-state machine only one of which example, only process the incoming event with this example direct correlation, layer N-state machine receive there is no, with it, the incoming event directly contacted time, by interface module, this incoming event is sent to the state machine process on upper strata, state machine and this incoming event also not direct correlation such as upper strata, then this incoming event is sent to the state machine of more top by the state machine on upper strata by its interface module, until being sent to process the state machine of this incoming event, i.e. with the state machine of this incoming event direct correlation.
Performance element 40 is for obtaining the current state of finite state machine from memory element 30, and in the incoming event that provides according to engine unit 20 and memory element 30, the state-transition table 50 of storage obtains the NextState machine of the confidential transfer of current state and updates the current state of finite state machine according to the NextState machine obtained.
Refer to Fig. 3, be the flow chart of the execution method of finite state machine in an embodiment, comprise the following steps:
Engine unit 20 receives incoming event, as the trigger event (S610) of finite state machine;
Performance element 40 obtains the current state of finite state machine, and the incoming event that provides according to engine unit 20 and a state-transition table, obtains the NextState machine (S620) of the confidential transfer of current state;
Above-mentioned state-transition table 50 includes N shell state machine, N shell state machine includes 1 layer 1 state machine, this layer 1 state machine includes several layer 2 state machines repelled each other, several layer 3 state machines repelled each other are included under each layer 2 state machine, the like, until several layer N-1 state machines repelled each other, under each layer of N-1 state machine, include several layer N-state machines repelled each other.Wherein, several underlying state machines belonging to same upper strata state machine are to obtain by inheriting this upper strata state machine.Underlying state machines is provided with the interface module entering its upper strata state machine inherited so that underlying state machines can post messages to its upper strata state machine inherited.Each state machine in N shell state machine carries out reservation process for the incoming event received according to engine unit 20.Each layer of N-state machine only one of which example, only process the incoming event with this example direct correlation, layer N-state machine receive there is no, with it, the incoming event directly contacted time, by interface module, this incoming event is sent to the state machine process on upper strata, state machine and this incoming event also not direct correlation such as upper strata, then this incoming event is sent to the state machine of more top by the state machine on upper strata by its interface module, until being sent to process the state machine of this incoming event, i.e. with the state machine of this incoming event direct correlation.
Performance element 40 updates the current state (S630) of finite state machine according to the NextState machine obtained.
It is inheritance between the underlying state machines in state-transition table and upper strata state machine in the execution system of above-mentioned finite state machine and execution method, each state machine only processes the event of direct correlation therewith, and underlying state machines sends the incoming event of the most non-immediate association received to upper strata state machine by interface module and processes.So, execution system and the execution method of above-mentioned finite state machine only need to delete this state machine when deleting certain state machine, have no effect on the setting of other state machines, and when setting up new state machine, only need to set up the inheritance between this new state machine and this new state machine and corresponding upper strata state machine, it is easy to maintenance and expansion.