CN115885253A - Control method and device of finite state machine, computer equipment and storage medium - Google Patents

Control method and device of finite state machine, computer equipment and storage medium Download PDF

Info

Publication number
CN115885253A
CN115885253A CN202080103184.8A CN202080103184A CN115885253A CN 115885253 A CN115885253 A CN 115885253A CN 202080103184 A CN202080103184 A CN 202080103184A CN 115885253 A CN115885253 A CN 115885253A
Authority
CN
China
Prior art keywords
state
event
processing
class
returned
Prior art date
Legal status (The legal status is an assumption and is not a legal conclusion. Google has not performed a legal analysis and makes no representation as to the accuracy of the status listed.)
Pending
Application number
CN202080103184.8A
Other languages
Chinese (zh)
Inventor
陈绍昆
Current Assignee (The listed assignees may be inaccurate. Google has not performed a legal analysis and makes no representation or warranty as to the accuracy of the list.)
DeepRoute AI Ltd
Original Assignee
DeepRoute AI Ltd
Priority date (The priority date is an assumption and is not a legal conclusion. Google has not performed a legal analysis and makes no representation as to the accuracy of the date listed.)
Filing date
Publication date
Application filed by DeepRoute AI Ltd filed Critical DeepRoute AI Ltd
Publication of CN115885253A publication Critical patent/CN115885253A/en
Pending legal-status Critical Current

Links

Images

Classifications

    • GPHYSICS
    • G06COMPUTING; CALCULATING OR COUNTING
    • G06FELECTRIC DIGITAL DATA PROCESSING
    • G06F8/00Arrangements for software engineering
    • G06F8/30Creation or generation of source code
    • G06F8/38Creation or generation of source code for implementing user interfaces

Landscapes

  • Engineering & Computer Science (AREA)
  • Software Systems (AREA)
  • General Engineering & Computer Science (AREA)
  • Theoretical Computer Science (AREA)
  • Human Computer Interaction (AREA)
  • Physics & Mathematics (AREA)
  • General Physics & Mathematics (AREA)
  • Stored Programmes (AREA)

Abstract

A control method of a finite state machine comprises the following steps: receiving a control signal; the control signal carries signaling information; converting the control signal into an event according to the signaling information; calling an event processing class to process the event; the event processing class comprises a state machine class and a state class; the state machine class is used for realizing the logic of state jump; the state class is used for finishing the processing of specific service logic; when processing the event, if the state machine judges to receive the processing event according to the current state, performing corresponding service logic processing on the event, and returning to the corresponding processing state; and determining a processing mode corresponding to the next state according to the processing state.

Description

Control method and device of finite state machine, computer equipment and storage medium Technical Field
The present application relates to the field of computer technologies, and in particular, to a method and an apparatus for controlling a finite state machine, a computer device, and a storage medium.
Background
With the development of computer technology, a Finite State Machine (FSM) can effectively and conveniently describe the dynamic behavior of a system and components, and is widely applied to telecommunication software application development. The FSM has a finite number of states, typically including states and transition relationships between states. At present, in software programming engineering, the currently widely adopted way for implementing FSM is to use a procedural language, for example, C language, and the FSM implemented by using this method is substantially described by conditional statements.
However, in the current control mode of the finite-state machine, the switching relationship between the common states needs to be registered in advance, and the state machine is not universal, and cannot flexibly and dynamically add a state, and at the same time, when the finite-state machine runs, the finite-state machine does not support state rollback according to the current state, that is, the jump between different states cannot be dynamically controlled, which easily results in low control efficiency.
Disclosure of Invention
According to various embodiments disclosed in the present application, a control method and apparatus of a finite state machine, a computer device, and a storage medium are provided.
A method of controlling a finite state machine, comprising:
receiving a control signal; the control signal carries signaling information; converting the control signal into an event according to the signaling information; calling an event processing class to process the event; wherein the event processing class comprises a state machine class and a state class; the state machine class is used for realizing logic of state jump; the state class is used for finishing the processing of specific service logic; when the event is processed, if the state machine judges to receive the processing of the event according to the current state, the corresponding business logic processing is carried out on the event, and the corresponding processing state is returned; and determining a processing mode corresponding to the next state according to the processing state.
A control apparatus of a finite state machine, comprising:
the receiving module is used for receiving a control signal; the control signal carries signaling information; the conversion module is used for converting the control signal into an event according to the signaling information; the calling module is used for calling an event processing class to process the event; wherein the event processing class comprises a state machine class and a state class; the state machine class is used for realizing the logic of state jump; the state class is used for finishing the processing of specific service logic; the processing module is used for judging whether to accept the event processing according to the current state by the state machine when processing the event, then carrying out corresponding business logic processing on the event and returning to the corresponding processing state; and the determining module is used for determining the processing mode corresponding to the next state according to the processing state.
A computer device comprising a memory and one or more processors, the memory having stored therein computer-readable instructions that, when executed by the processors, cause the one or more processors to perform the steps of: acquiring product information;
receiving a control signal; the control signal carries signaling information; converting the control signal into an event according to the signaling information; calling an event processing class to process the event; wherein the event processing class comprises a state machine class and a state class; the state machine class is used for realizing logic of state jump; the state class is used for finishing the processing of specific service logic; when the event is processed, if the state machine judges to receive the processing of the event according to the current state, the corresponding business logic processing is carried out on the event, and the corresponding processing state is returned; and determining a processing mode corresponding to the next state according to the processing state.
One or more computer storage media storing computer-readable instructions that, when executed by one or more processors, cause the one or more processors to perform the steps of: acquiring product information;
receiving a control signal; the control signal carries signaling information; converting the control signal into an event according to the signaling information; calling an event processing class to process the event; wherein the event processing class comprises a state machine class and a state class; the state machine class is used for realizing the logic of state jump; the state class is used for finishing the processing of specific service logic; when the event is processed, if the state machine judges to receive the processing of the event according to the current state, the corresponding business logic processing is carried out on the event, and the corresponding processing state is returned; and determining a processing mode corresponding to the next state according to the processing state.
The details of one or more embodiments of the application are set forth in the accompanying drawings and the description below. Other features and advantages of the application will be apparent from the description and drawings, and from the claims.
Drawings
In order to more clearly illustrate the technical solutions in the embodiments of the present application, the drawings needed to be used in the embodiments will be briefly described below, and it is obvious that the drawings in the following description are only some embodiments of the present application, and it is obvious for those skilled in the art to obtain other drawings without creative efforts.
FIG. 1 is a diagram illustrating an exemplary system for controlling a finite state machine;
FIG. 2 is a flow diagram illustrating a method for controlling a finite state machine according to one embodiment;
FIG. 3 is a flowchart illustrating a step of determining a processing mode corresponding to a next state according to a processing state in one embodiment;
FIG. 4 is a flowchart illustrating a process policy step corresponding to obtaining a current state in one embodiment;
FIG. 5 is a flowchart illustrating steps of creating a new state to replace a current state and processing an event according to the event when a processing policy returned by the GetStrategy function is a replacement event in one embodiment;
FIG. 6A is a flowchart illustrating a method for controlling a finite state machine according to another embodiment;
FIG. 6B is a diagram illustrating a call relationship when a finite state machine processes an event according to an embodiment;
FIG. 7 is a block diagram of a control apparatus of a finite state machine according to an embodiment;
FIG. 8 is a diagram illustrating an internal structure of a computer device according to an embodiment.
Detailed Description
In order to make the technical solutions and advantages of the present application more clearly understood, the present application is further described in detail below with reference to the accompanying drawings and embodiments. It should be understood that the specific embodiments described herein are merely illustrative of the present application and are not intended to limit the present application.
The control method of the finite-state machine provided in the embodiment of the present application may be applied to an application environment shown in fig. 1, where a terminal 102 communicates with a terminal 104 through a network. The terminal 102 receives a control signal sent by the terminal 104, and the control signal carries signaling information. The terminal 102 converts the control signal into an event according to the signaling information. The terminal 102 calls the event handling class to handle the event. The event processing class comprises a state machine class and a state class, wherein the state machine class is used for realizing the logic of state jump, and the state class is used for finishing the processing of specific service logic. When the terminal 102 processes the event, if the state machine determines to receive the processed event according to the current state, the corresponding service logic processing is performed on the event, and the corresponding processing state is returned. The terminal 102 determines a processing mode corresponding to the next state according to the processing state. The terminal 102 may be, but is not limited to, various personal computers, laptops, smartphones, tablets, and portable wearable devices.
The following embodiments will describe the case where the control method of the finite state machine is applied to the terminal in fig. 1, but it should be noted that the method is not limited to the above terminal in practical applications.
As shown in fig. 2, a flowchart of a method for controlling a finite state machine in one embodiment specifically includes the following steps:
step 202, receiving a control signal, where the control signal carries signaling information.
A finite state machine is a tool used to model the behavior of an object, and its role is mainly to describe the sequence of states that an object experiences during its lifecycle and how to respond to various events from the outside world. Finite state machines are widely used in computer science for modeling application behavior, hardware circuitry design, software engineering, compilers, network protocols, and computing and language research. The state machine is a control center which is composed of a state register and a combinational logic circuit, can carry out state transition according to a preset state according to a control signal, coordinates the action of the related signal and completes a specific operation.
A Finite State Machine is abbreviated as FSM (Finite State Machine), which is a mathematical model representing the behavior of a Finite number of states and transitions and actions between these states. A common computer uses a finite state machine as a calculation model, and for different states of a memory, a Central Processing Unit (CPU) performs calculation by reading a memory value, and updates the state in the memory. The CPU also receives the instruction of external input equipment (such as a keyboard and a mouse) through a message bus, changes the state in the memory after calculation, outputs the calculation result to external display equipment (such as a display) and stores the calculation result in a hard disk in a persistent mode. Finite state machine models are also often used in game design. Taking a fruit ninja game as an example, the state of the fruit in the game is a finite state, the running track of the fruit is calculated by a calculation formula simulating the law of physical motion, a banana runs according to a parabola after being thrown, the position change of each frame is a state change, and the state change is determined by the calculation formula. The game also involves complex human-computer interaction events, such as "cutting" fruit on the screen by hand, which, upon sensing this event, will enter an explosive state according to the programmed logic.
Specifically, the terminal may receive a control signal, where the control signal carries signaling information. The control signal is a signal for control, and the computer control is implemented by taking the control signal as a medium. The control signal may be sent to the terminal by different devices, and the different devices may include a third-party device, a terminal device, a server, an internet of things device, and the like. The signaling information refers to the specific content of the signaling, that is, the control information carried by the control signal. Signaling is the control signals required to ensure normal communications in a wireless communication system in order to operate network-wide anecdotally, in addition to transmitting user information. I.e. the signalling is actually a signal for control.
Step 204, converting the control signal into an event according to the signaling information.
After the terminal receives the control signals sent by different devices, the terminal can convert the control signals into events according to signaling information carried in the control signals. An event refers to a response of an object to an external action, and when an event occurs in the object, code corresponding to the event of the object is executed, and this code is called an "event process". The terminal may convert the received signal into an event according to the detailed content of the signaling, that is, the terminal abstracts the received signal into an event, and an event may include an event type, an event identifier (i.e., an event id), and an event content (msg). Specifically, the terminal may convert the signal into an internally defined Event type, an Event identifier, and an Event content according to the specific content of the signaling, and store these values in the structure of the Event. The Event type and the Event identifier can be stored by a shaping variable type, and the Event content is the memory address of the signaling stored by the void pointer, so that different signals can be converted into Event events which can be processed uniformly. The void pointer refers to a special pointer, denoted as "no type pointer", which is used in ANSIC instead of "char" as the type of the general pointer. Since the void pointer is not of a particular type, it can point to any type of data. That is, any type of pointer can be directly assigned to the void pointer without performing other related forced type transformations.
Step 206, calling an event processing class to process the event; the event processing class comprises a state machine class and a state class; the state machine class is used for realizing the logic of state jump, and the state class is used for finishing the processing of specific service logic.
After the terminal converts the control signal into the event according to the signaling information, the terminal can call an event processing class to process the abstract event. Class (Class) is the basis for Object-Oriented Programming (OOP) implementation information encapsulation. A class is a user-defined type of reference data, also called a class type. Each class contains a description of the data and a set of functions that operate on the data or pass messages. Instances of classes are referred to as objects. The event processing class is a set of reusable service functions, and comprises some objects and behaviors thereof, and the purpose of reusing the functions is achieved by calling. The event processing class may include a state machine class and a state class, the state machine class is used for implementing logic of state jump, and the state class is used for completing processing of specific service logic. Specifically, after the terminal converts the signal into the event according to the signaling information, the terminal may invoke an event handling class to handle the converted event. I.e. the handling class of events in the terminal can be inherited from a class (Handler class) containing the HandEvent function. The State machine class, namely the statemechine class, the State class, namely the State class, and the essence of the statemechine class and the State class are all classes for processing events, so that an abstract Handler class for processing events is abstracted, an abstract interface HandEvent event processing function is provided, a HandEvent function can be realized in subclasses, specifically, the logic of State jump is realized in the HandEvent function in the subclass statemechine, and the specific service logic processing is completed in the HandEvent function in the subclass State. Each State contains an Enter function, a function for entering a State, a HandEvent function, a function for processing events which can be accepted in the current State, an Exit function, a function for exiting a State, a GetStrategy function, and a function for acquiring a processing strategy of events which can not be accepted in the current State.
And step 208, when the event is processed, if the state machine judges to receive the processed event according to the current state, performing corresponding service logic processing on the event, and returning to the corresponding processing state.
When the terminal calls the event processing class to process the event, if the state machine class judges to receive the processing event according to the current state, the corresponding service logic processing is carried out on the event, and the corresponding processing state is returned. Specifically, when the terminal calls a Handler class to process the event, if the StateMachine class determines to receive the processed event according to the current State, the terminal performs corresponding service logic processing on the event through a HandEvent function in the subclass State and returns to the corresponding processing State. Namely, the terminal calls a HandEvent function in the current state, performs corresponding service logic processing on the event, and returns to the corresponding processing state. The processing state is that each state returns a corresponding state code after processing the event, and the state code is the return value of the HandEvent function. That is, the status code is a return value of the status handling function, and the statemechine class can determine the next action according to the return value.
And step 210, determining a processing mode corresponding to the next state according to the processing state.
The terminal calls the event processing class to process the event, after the corresponding processing state is returned, the terminal can continue to call the event processing class, and the processing mode corresponding to the next state is determined according to the returned processing state. For example, the terminal performs corresponding service logic processing on the current EVENT through a HandEvent function in the subclass State, and the HandEvent function can return three processing states of DONE _ EVENT, CONTINUE _ EVENT, and UNKOWN _ EVENT according to the processing condition of the current EVENT. The DONE _ EVENT indicates that the current state finishes the EVENT processing and can jump to the next state; the CONTINUE _ EVENT indicates that the current state CONTINUEs to process the EVENT and does not carry out state jump; the UNKOWN _ EVENT indicates that the current state cannot accept the EVENT, the StatemAChine class is required to acquire the strategy of the current state according to the GetStrategy function of the current state, and the next step is executed according to the acquired strategy.
In a conventional finite state machine control mode, when a state jumps, a state to be jumped next needs to be specified in the state machine, so that it is inconvenient to add a new state, and a code corresponding to the state machine needs to be modified every time a state is added. In this embodiment, the control signal is received, the control signal carries signaling information, the control signal is converted into an event according to the signaling information, and an event processing class is called to process the event. The event processing class comprises a state machine class and a state class, wherein the state machine class is used for realizing the logic of state jump, and the state class is used for finishing the processing of specific service logic. When processing the event, if the state machine judges to receive the processing event according to the current state, the corresponding business logic processing is carried out on the event, the corresponding processing state is returned, and the processing mode corresponding to the next state is determined according to the processing state. Therefore, the processing of events and the skipping between states are carried out by abstracting various different signals into a uniform parameter Event, the state machine part can be more universal, the addition of new states is convenient without modifying codes of the state machine part, the states can be flexibly established and the state skipping can be carried out according to an Event processing strategy, and therefore the control efficiency is effectively improved.
In one embodiment, as shown in fig. 3, the processing states include processing completion, continuing processing, and non-acceptance processing, and the step of determining a processing mode corresponding to a next state according to the processing states includes:
and step 302, when the returned processing state is that the processing is finished, jumping to the next state to process the event.
And step 304, when the returned processing state is the continuous processing, not performing state jump, calling a HandEvent function in the current state, and continuously processing the event.
And step 306, when the returned processing state is not to be processed, acquiring a processing strategy corresponding to the current state.
The terminal calls the event processing class to process the event, after the corresponding processing state is returned, the terminal can continue to call the event processing class, and the processing mode corresponding to the next state is determined according to the processing state returned in the previous step. The processing state includes completion of processing, continuation of processing, and non-acceptance of processing. Specifically, when the HandEvent function returns the processing state as processing completion according to the processing condition of the current event, the statemechine class may jump to the next state to process the event. And when the returned processing state is the continuous processing, the state jump is not carried out, and the StatemAcahine class calls the HandEvent function in the current state to continuously process the event. And when the returned processing state is not to be processed, the StatemAchine class acquires the processing strategy corresponding to the current state. That is, only when the state of UNKOWN _ EVENT is returned (not to be processed), the Statemachine class calls the GetStrategy function in the current state to obtain the corresponding processing policy.
Specifically, when a current Event is processed through a HandEvent function, the terminal judges whether the Event is an Event processed in the current State or not according to the Event type and the Event identifier of the Event by calling the HandEvent function of a State class, and if so, the HandEvent function is used for carrying out specific service logic processing on the current Event; if not, the current state is indicated to be incapable of processing the EVENT, and the processing state of UNKOWN _ EVENT is returned. And when the processing state of CONTINUE _ EVENT is returned, the current state can continuously process the EVENT, and state skipping is not needed, so that unnecessary skipping of the state can be reduced, skipping from the current state to the current state is not needed, skipping among different states can be dynamically controlled, and the control efficiency is effectively improved.
In one embodiment, as shown in fig. 4, the step of acquiring the processing policy corresponding to the current state includes:
step 402, calling a GetStrategy function to obtain a processing strategy corresponding to the current state, wherein the processing strategy comprises an ignoring event, a replacing event and a rollback event.
In step 404, when the processing policy returned by the GetStrategy function is an ignore event, the event is ignored.
In step 406, when the processing policy returned by the GetStrategy function is a replacement event, a new state is created to replace the current state according to the event, and the event is processed.
In step 408, when the processing policy returned by the GetStrategy function is a rollback event, the state is restored to the previous state to process the event.
The terminal calls the event processing class to process the event, and when the returned processing state is not accepted, the stateMAC class can acquire the processing strategy corresponding to the current state. Specifically, the StateMachine class may obtain a processing policy corresponding to the current state by calling a GetStrategy function, where the processing policy includes an IGNORE event (IGNORE), a REPLACE event (REPLACE) and a rollback event (RECOVER). Namely, the GetStrategy function can return three strategies of IGNORE, REPLACE and RECOVER for the current event. IGNORE represents ignoring the current event, REPLACE represents creating a new state to REPLACE the current state according to the current event for processing the event, and RECOVER represents restoring the last state to process the current event. That is, when the processing policy returned by the GetStrategy function is to ignore the event, the event is ignored. And when the processing strategy returned by the GetStrategy function is a replacement event, creating a new state to replace the current state according to the event, and processing the event. When the processing policy returned by the GetStrategy function is a rollback event, the event is processed by restoring to the previous state. Compared with the conventional finite-state machine control mode, the last state is not saved, and the dynamic event processing strategy is not provided, so that the state rollback cannot be realized, and the problem of when the state rollback can be performed cannot be solved. In this embodiment, the jump policy of the state is implemented in a specific state, so that how to jump the next state or rollback to the previous state can be determined according to the current state during the operation. Because the last state is stored in the state machine StateMachine, if the processing strategy of the current state to the event is the RECOVER, the StateMachine can be rolled back to the last state, and the state can be flexibly established and the state jump can be realized according to the event processing strategy.
In one embodiment, as shown in fig. 5, when the processing policy returned by the GetStrategy function is a replacement event, a new state is created to replace the current state according to the event, and the step of processing the event includes:
step 502, when the processing policy returned by the GetStrategy function is a replacement event, a state factory class is called, and a corresponding new state is created by using a CreateState function according to the event type and the event identifier of the event.
And step 504, replacing the current state with a new state, and processing the event by using the new state.
The terminal calls the event processing class to process the event, and when the returned processing state is not accepted, the Statemmachine class can obtain the processing strategy corresponding to the current state by calling the GetStrategy function. And when the processing strategy returned by the GetStrategy function is a replacement event, creating a new state to replace the current state according to the event, and processing the event. The StateMachine class, state machine class, contains one state factory class (i.e., stateFactory class object) and two states. The two states are the current state (cur _ state) and the last state (last _ state), respectively. The stateFactory is a class for creating a specific State class object and is responsible for creating a specific State, namely the stateFactory class is mainly used for creating a corresponding State according to an event. last _ state indicates the last state of statecache for use when rolling back the state. The cur _ state represents the current state of StatemMechine, and the role of the cur _ state is that when the StatemMechine receives an Event, the StatemMechine first tries to call the HandEvent function of the cur _ state to process the Event, and decides the next flow according to the processing result of the cur _ state. For example, the next flow may include creating a new state to handle the event, ignoring the current event, and performing a state rollback.
Specifically, when the processing policy returned by the GetStrategy function is a replacement event, the StateFactory class may call StateFactory, and the StateFactory creates a corresponding new state by using the CreateState function according to the event type and the event identifier of the current event. Further, stateMachine replaces the current state with a new state, and processes the event by using the new state. StateFactory provides a CreateState function to create specific states, with the function parameter being an Event. Therefore, statemAchine does not need to care about how a specific state is created, and only needs to use a state factory to create the next state, so that flexible creation of the states can be achieved. In addition, the process of state creation is packaged into the state factory class, the state can be conveniently expanded, when a state needs to be newly added, only part of codes in the state factory class need to be modified, and any change is not needed for a specific user Statemmachine of the state, so that the code expansion is convenient, and the state creation and the state jump flexibly determined according to an event processing strategy can be realized.
In one embodiment, as shown in fig. 6A, a method for controlling a finite-state machine is provided, which is described by taking the method as an example applied to the terminal in fig. 1, and includes the following steps:
step 602, receiving a control signal, where the control signal carries signaling information.
Step 604, converting the control signal into an event according to the signaling information.
Step 606, call the event handling class to handle the event. The event processing class comprises a state machine class and a state class, wherein the state machine class is used for realizing the logic of state skipping, and the state class is used for finishing the processing of specific service logic.
Step 608, when processing the event, if the state machine determines to receive the processed event according to the current state, then call the handover event function of the current state, perform corresponding service logic processing on the event, and return to the corresponding processing state. The processing state is that each state returns a corresponding state code after processing the event, and the state code is a return value of the HandEvent function.
Step 610, when processing the event, if the state machine determines not to accept the event according to the current state, then returning to the state of not accepting the event; and acquiring a processing strategy corresponding to the current state, processing the event according to the processing strategy, and returning to the corresponding processing state.
Step 612, when the returned processing state is that the processing is finished, skipping to the next state to process the event; when the returned processing state is the continuous processing, the state jump is not carried out, the HandEvent function in the current state is called, and the event is continuously processed; and when the returned processing state is not accepted, acquiring a processing strategy corresponding to the current state.
Fig. 6B is a schematic diagram of a call relation when the finite state machine processes an event. After the terminal receives the control signals sent by different devices, the terminal can convert the signals into events according to signaling information carried in the control signals. The different devices may include third party devices, terminal devices, servers, internet of things devices, and the like. Further, the terminal may invoke an event handling class to handle the event. The event processing class comprises a state machine class and a state class, wherein the state machine class is used for realizing the logic of state skip, and the state class is used for finishing the processing of specific service logic. When processing the event, if the state machine judges to receive the processing event according to the current state, calling a HandEvent function of the current state, performing corresponding business logic processing on the event, and returning to the corresponding processing state. The processing state is a state code corresponding to each state returned after the event is processed, and the state code is a return value of a HandEvent function. In addition, when the event is processed, if the state machine judges that the event is not accepted according to the current state, the state is returned to be the non-acceptance processing. And when the returned state is not accepted, the terminal acquires a processing strategy corresponding to the current state through the StatemMAC, processes the event according to the acquired processing strategy and returns to the corresponding processing state. Further, when the returned processing state is that the processing is finished, the StatemAcahine jumps to the next state to process the event; when the returned processing state is the continuous processing, statemAcahine does not carry out state jump, calls a HandEvent function in the current state and continuously processes the event; and when the returned processing state is not to be processed, the StatemAcahine continues to acquire the processing strategy corresponding to the current state. An event may contain an event type, an event identification (i.e., an event id), and an event content (MSG is a structure in a Windows program in which a message is represented by an MSG structure). Event type (Event _ type), representing a type of Event. The Event identifier, i.e. Event id (Event _ id), represents a specific Event, so that the corresponding processing can be flexibly performed according to the Event type and the Event id in the processing function of each Event, for example, only the Event type can be concerned in the parent state, and the logic of the specific Event can be processed in the child state.
The following description will be given taking an unmanned vehicle as an example. After the system receives a signal, namely when the terminal receives a signal sent by the internet of things equipment vehicle A, the terminal can convert the signal into an internal event A according to control information carried in the signal. Further, the terminal may call a state machine to process the event a, the state machine determines whether the current event a can be accepted or not according to the current state, and if it is determined that the event a is accepted, calls a HandEvent function in the current state to perform corresponding service logic processing on the event a, and returns to the corresponding processing state. For example, the state of the vehicle a may include normal operation and malfunction. The state machine can judge whether the current event A can be processed or not according to the current state, namely, whether the state of the vehicle A corresponding to the event A is in normal operation or failure is judged. When the state machine judges that the event A is processed according to the current state, namely the state of the vehicle A corresponding to the event A is normal operation, the next flow is entered. And if the event A is judged not to be processed, the state of the vehicle A corresponding to the event A is judged to be a fault, the event A cannot be processed, the process of acquiring the processing strategy is entered, the event A is processed according to the acquired processing strategy, and the corresponding processing state is returned. For example, when the processing policy obtained by the state machine is a REPLACE event (REPLACE), the state machine may call the state factory to create a new state to process the event a and return to the corresponding processing state. If none of the above steps are effective in handling the event A, the event A is ignored. When the vehicle a is operating normally, an instruction task may be received, the instruction task including task start, task pause, task cancel, and task end. The state machine can realize the jump of the state when the vehicle A normally runs, namely, the vehicle A is controlled to execute instruction task start, task pause, task cancel or task end. The system can define a large father state, a state machine is stored in the father state to complete the jump of the child state, the nesting of the state machines is realized, the child state is conveniently and flexibly added to the father state, and the behavior is the same for users of the state machines, so that the interior can be nested in a complex way without worrying about the influence on the users of the state machines.
In the embodiment, all signals are abstracted into events, corresponding processing can be flexibly performed according to event types or event identifications through event processing classes, for example, only the event types are concerned in a parent state, and specific events are processed in a child state, so that state creation and state skipping flexibly according to event processing strategies are realized, meanwhile, state rollback can be performed according to the strategies during operation, skipping among different states can be dynamically controlled, and control efficiency is effectively improved.
In one embodiment, the event handling class is a Handler class, which is a computer term, a Java subclass, and an inheritance interface. The Handler class may include the subclasses StateMachine class and State class, both inherited from the Handler class. And saving a Handler pointer pointing to the StatemMechine class in the State class, wherein the Handler pointer is used for realizing nesting of the parent-child State machines. Because the StateMeachine class and the State class are both inherited from an abstract event processing class, namely the Handler class, a StateMeachine class can be injected into the State class, so that each Handler class can be flexibly combined, and nesting of State machines is supported. The decoration mode can be used for storing a Handler pointer pointing to the StatemMechine class in the State, so that another State machine is nested in the State, namely the decoration mode is conveniently used for realizing the infinite nesting of parent and child State machines. In a traditional finite state machine control mode, nesting of a support state does not support nesting of a state machine, and switching of a child state needs to be maintained in a parent state, so that the boundaries of the state and the state machine are not clear, and the concept is somewhat confused. In this embodiment, only one pointer of the Handler class can be used for the outside without paying attention to a specific processing class, so that code expansion is facilitated, part of codes in the state factory class are modified, and users of the Handler are not affected. Because StatemAchine and State are inherited from the Hander, the relation between StatemAchine and State can be flexibly combined to realize the combination of parent-child states and the State jump of child states.
It should be understood that although the various steps in the flow charts of fig. 1-6 are shown in order as indicated by the arrows, the steps are not necessarily performed in order as indicated by the arrows. The steps are not performed in the exact order shown and described, and may be performed in other orders, unless explicitly stated otherwise. Moreover, at least some of the steps in fig. 1-6 may include multiple steps or multiple stages, which are not necessarily performed at the same time, but may be performed at different times, which are not necessarily performed sequentially, but may be performed alternately or in alternation with other steps or at least some of the other steps or stages.
In one embodiment, as shown in fig. 7, there is provided a control apparatus of a finite state machine, including: a receiving module 702, a converting module 704, a calling module 706, a processing module 708, and a determining module 710, wherein:
a receiving module 702, configured to receive a control signal, where the control signal carries signaling information.
A conversion module 704, configured to convert the control signal into an event according to the signaling information.
The invoking module 706 is configured to invoke an event processing class to process an event, where the event processing class includes a state machine class and a state class, the state machine class is used to implement a logic of state jump, and the state class is used to complete processing of a specific service logic.
The processing module 708 is configured to, when processing an event, perform corresponding service logic processing on the event and return to a corresponding processing state if the state machine determines to receive the processed event according to the current state.
The determining module 710 is configured to determine, according to the processing state, a processing manner corresponding to a next state.
In one embodiment, the calling module is further configured to call a HandEvent function in the current state, perform corresponding service logic processing on the event, and return a corresponding processing state, where the processing state is that each state returns a corresponding state code after processing the event, and the state code is a return value of the HandEvent function.
In one embodiment, the apparatus further comprises: the device comprises a skipping module and an obtaining module.
And the skipping module is used for skipping to the next state to process the event when the returned processing state is that the processing is finished. The calling module is also used for calling the HandEvent function in the current state without state jump when the returned processing state is the continuous processing state, and continuously processing the event. The obtaining module is used for obtaining the processing strategy corresponding to the current state when the returned processing state is not accepted.
In one embodiment, the calling module is further configured to call the GetStrategy function to obtain a processing policy corresponding to the current state, where the processing policy includes an ignore event, a replace event, and a rollback event. The processing module is also used for ignoring the event when the processing strategy returned by the GetStrategy function is the ignoring event; when the processing strategy returned by the GetStrategy function is a replacement event, a new state is created to replace the current state according to the event, and the event is processed; when the processing policy returned by the GetStrategy function is a rollback event, the state is restored to the previous state to process the event.
In one embodiment, the calling module is further configured to call the state factory class when the processing policy returned by the GetStrategy function is a replacement event, and create a corresponding new state by using the CreateState function according to the event type and the event identifier of the event. The processing module is also used for replacing the current state with a new state and processing the event by using the new state.
In one embodiment, the processing module is further configured to, when processing an event, return to the state of not accepting processing if the state machine determines that the event is not accepted according to the current state. The acquisition module is further used for acquiring a processing strategy corresponding to the current state, processing the event according to the processing strategy and returning to the corresponding processing state.
In one embodiment, the apparatus further comprises: and a storage module.
The storage module is used for storing a Handler pointer pointing to a StatemMechine class in the State class, and the Handler pointer is used for nesting the parent-child State machines.
For specific limitations of the control apparatus of the finite state machine, reference may be made to the above limitations of the control method of the finite state machine, and details are not described herein again. The respective modules in the control device of the finite state machine described above may be wholly or partially implemented by software, hardware, and a combination thereof. The modules can be embedded in a hardware form or independent from a processor in the computer device, and can also be stored in a memory in the computer device in a software form, so that the processor can call and execute operations corresponding to the modules.
In one embodiment, a computer device is provided, which may be a terminal, and its internal structure diagram may be as shown in fig. 8. The computer device includes a processor, a memory, a communication interface, a display screen, and an input device connected by a system bus. Wherein the processor of the computer device is configured to provide computing and control capabilities. The memory of the computer device comprises a nonvolatile storage medium and an internal memory. The non-volatile storage medium stores an operating system and a computer program. The internal memory provides an environment for the operation of an operating system and computer programs in the non-volatile storage medium. The communication interface of the computer device is used for carrying out wired or wireless communication with an external terminal, and the wireless communication can be realized through WIFI, an operator network, NFC (near field communication) or other technologies. The computer program is executed by a processor to implement a control method of a finite state machine. The display screen of the computer equipment can be a liquid crystal display screen or an electronic ink display screen, and the input device of the computer equipment can be a touch layer covered on the display screen, a key, a track ball or a touch pad arranged on the shell of the computer equipment, an external keyboard, a touch pad or a mouse and the like.
It will be appreciated by those skilled in the art that the configuration shown in fig. 8 is a block diagram of only a portion of the configuration associated with the present application, and is not intended to limit the computing device to which the present application may be applied, and that a particular computing device may include more or less components than those shown, or may combine certain components, or have a different arrangement of components.
A computer device comprising a memory and one or more processors, the memory having stored therein computer-readable instructions, the one or more non-volatile storage media having stored thereon computer-readable instructions, which, when executed by the one or more processors, cause the one or more processors to carry out the steps of a method of controlling a finite state machine as provided in any one of the embodiments of the present application.
It will be understood by those of ordinary skill in the art that all or part of the processes of the methods of the embodiments described above can be implemented by hardware associated with computer readable instructions, which can be stored in a non-volatile computer readable storage medium, and when executed, can include processes of the embodiments of the methods described above. Any reference to memory, storage, database or other medium used in the embodiments provided herein can include at least one of non-volatile and volatile memory. Non-volatile Memory may include Read-Only Memory (ROM), magnetic tape, floppy disk, flash Memory, optical storage, or the like. Volatile Memory can include Random Access Memory (RAM) or external cache Memory. By way of illustration and not limitation, RAM can take many forms, such as Static Random Access Memory (SRAM) or Dynamic Random Access Memory (DRAM), among others.
The technical features of the above embodiments can be arbitrarily combined, and for the sake of brevity, all possible combinations of the technical features in the above embodiments are not described, but should be considered as the scope of the present specification as long as there is no contradiction between the combinations of the technical features.
The above-mentioned embodiments only express several embodiments of the present application, and the description thereof is more specific and detailed, but not construed as limiting the scope of the invention. It should be noted that, for a person skilled in the art, several variations and modifications can be made without departing from the concept of the present application, which falls within the scope of protection of the present application. Therefore, the protection scope of the present patent shall be subject to the appended claims.

Claims (16)

  1. A method of controlling a finite state machine, comprising:
    receiving a control signal; the control signal carries signaling information; converting the control signal into an event according to the signaling information; calling an event processing class to process the event; wherein the event processing class comprises a state machine class and a state class; the state machine class is used for realizing the logic of state jump; the state class is used for finishing the processing of specific service logic; when the event is processed, if the state machine judges to receive the processing of the event according to the current state, the corresponding business logic processing is carried out on the event, and the corresponding processing state is returned; and determining a processing mode corresponding to the next state according to the processing state.
  2. The method of claim 1, wherein the performing corresponding business logic processing on the event and returning a corresponding processing state comprises:
    calling a HandEvent function in the current state, performing corresponding business logic processing on the event, and returning to a corresponding processing state; and the processing state is a state code corresponding to the returned processed event by each state, and the state code is a returned value of the HandEvent function.
  3. The method according to claim 1, wherein the processing states include processing completion, continuing processing, and non-acceptance processing, and determining a processing mode corresponding to a next state according to the processing states includes:
    when the returned processing state is that the processing is finished, jumping to the next state to process the event; when the returned processing state is continued processing, state skipping is not carried out, a HandEvent function in the current state is called, and the event is continuously processed; and when the returned processing state is not accepted, acquiring a processing strategy corresponding to the current state.
  4. The method of claim 3, wherein the obtaining of the processing policy corresponding to the current state comprises:
    calling a GetStrategy function to acquire a processing strategy corresponding to the current state; the processing strategy comprises an ignoring event, a replacing event and a rollback event; when the processing strategy returned by the GetStrategy function is an event, ignoring the event; when the processing strategy returned by the GetStrategy function is a replacing event, a new state is created to replace the current state according to the event, and the event is processed; and when the processing strategy returned by the GetStrategy function is a rollback event, restoring to a previous state to process the event.
  5. The method according to claim 4, wherein, when the processing policy returned by the GetStrategy function is a replacement event, creating a new state to replace the current state according to the event, and processing the event, comprises:
    when the processing strategy returned by the GetStrategy function is a replacement event, calling a state factory class, and creating a corresponding new state by using a CreateState function according to the event type and the event identifier of the event; and replacing the current state with the new state, and processing the event by using the new state.
  6. The method of claim 1, wherein the method further comprises:
    when the event is processed, if the state machine judges that the event is not accepted to be processed according to the current state, returning the state to be not accepted to be processed; acquiring a processing strategy corresponding to the current state; and processing the event according to the processing strategy and returning to a corresponding processing state.
  7. The method of claim 1, wherein the method further comprises:
    the event processing class is a Handler class which comprises a subclass StatemAChine class and a subclass State class; the StatemAcahine class and the State class are both inherited from the Handler class; and storing a Handler pointer pointing to the StatemMeschine class in the State class, wherein the Handler pointer is used for realizing nesting of the parent-child State machines.
  8. A control apparatus of a finite state machine, comprising:
    the receiving module is used for receiving a control signal; the control signal carries signaling information; the conversion module is used for converting the control signal into an event according to the signaling information; the calling module is used for calling an event processing class to process the event; wherein the event processing class comprises a state machine class and a state class; the state machine class is used for realizing the logic of state jump; the state class is used for finishing the processing of specific service logic; the processing module is used for judging whether to accept the event processing according to the current state by the state machine when processing the event, then carrying out corresponding business logic processing on the event and returning to the corresponding processing state; and the determining module is used for determining the processing mode corresponding to the next state according to the processing state.
  9. The apparatus for controlling a finite state machine according to claim 8, wherein said apparatus further comprises:
    the calling module is also used for calling the HandEvent function in the current state, carrying out corresponding service logic processing on the event and returning to the corresponding processing state; and the processing state is a state code corresponding to the returned processed event by each state, and the state code is a returned value of the HandEvent function.
  10. The apparatus for controlling a finite state machine according to claim 8, wherein said apparatus further comprises:
    the skipping module is used for skipping to the next state to process the event when the returned processing state is that the processing is finished; the calling module is also used for calling the HandEvent function in the current state without state skip when the returned processing state is the continuous processing state, and continuously processing the event; and the acquisition module is used for acquiring the processing strategy corresponding to the current state when the returned processing state is not accepted.
  11. The finite state machine control apparatus according to claim 10, wherein said apparatus further comprises:
    the calling module is also used for calling a GetStrategy function to acquire the processing strategy corresponding to the current state; the processing strategy comprises an ignoring event, a replacing event and a rollback event; a returning module, configured to ignore the event when the processing policy returned by the GetStrategy function is an ignore event; a creating module, configured to create a new state to replace the current state according to the event when the processing policy returned by the GetStrategy function is a replacement event, and process the event; and the recovery module is used for recovering to the previous state to process the event when the processing strategy returned by the GetStrategy function is a rollback event.
  12. The finite state machine control apparatus according to claim 11, wherein said apparatus further comprises:
    the calling module is also used for calling a state factory class when the processing strategy returned by the GetStrategy function is a replacement event, and creating a corresponding new state by using a CreateState function according to the event type and the event identifier of the event; and the replacing module is used for replacing the current state with the new state and processing the event by using the new state.
  13. The apparatus for controlling a finite state machine according to claim 8, wherein said apparatus further comprises:
    the judging module is used for returning the state to be the non-acceptance processing state if the state machine judges that the event is not accepted according to the current state when the event is processed; the acquisition module is further used for acquiring the processing strategy corresponding to the current state; and the processing module is also used for processing the event according to the processing strategy and returning a corresponding processing state.
  14. The apparatus for controlling a finite state machine according to claim 8, wherein said apparatus further comprises:
    and the storage module is used for storing a Handler pointer pointing to the StatemMeschine class in the State class, wherein the Handler pointer is used for realizing nesting of the parent-child State machines.
  15. A computer device comprising a memory and one or more processors, the memory having stored therein computer-readable instructions that, when executed by the one or more processors, cause the one or more processors to perform the steps of the method of any one of claims 1 to 7.
  16. One or more computer storage media storing computer-readable instructions that, when executed by one or more processors, cause the one or more processors to perform the steps of the method of any one of claims 1-7.
CN202080103184.8A 2020-12-28 2020-12-28 Control method and device of finite state machine, computer equipment and storage medium Pending CN115885253A (en)

Applications Claiming Priority (1)

Application Number Priority Date Filing Date Title
PCT/CN2020/139828 WO2022140880A1 (en) 2020-12-28 2020-12-28 Method and apparatus for controlling finite state machine, computer device, and storage medium

Publications (1)

Publication Number Publication Date
CN115885253A true CN115885253A (en) 2023-03-31

Family

ID=82258620

Family Applications (1)

Application Number Title Priority Date Filing Date
CN202080103184.8A Pending CN115885253A (en) 2020-12-28 2020-12-28 Control method and device of finite state machine, computer equipment and storage medium

Country Status (2)

Country Link
CN (1) CN115885253A (en)
WO (1) WO2022140880A1 (en)

Family Cites Families (4)

* Cited by examiner, † Cited by third party
Publication number Priority date Publication date Assignee Title
CN101957751B (en) * 2010-06-04 2013-07-24 福建星网锐捷网络有限公司 Method and device for realizing state machine
CN105656688B (en) * 2016-03-03 2019-09-20 腾讯科技(深圳)有限公司 Condition control method and device
US20180113951A1 (en) * 2016-10-20 2018-04-26 Micron Technology, Inc. Graph traversal using automata processor
CN110502237A (en) * 2019-09-07 2019-11-26 创新奇智(广州)科技有限公司 A kind of software interface prototype method and tool based on state diagram

Also Published As

Publication number Publication date
WO2022140880A1 (en) 2022-07-07

Similar Documents

Publication Publication Date Title
CN107832099B (en) Method and device for client version compatibility and storage medium
CN108763060A (en) Native layers of collapse source tracing method, device, storage medium and terminal in android system
CN105847446B (en) Method, device and system for acquiring network data
CN107908679B (en) Script statement conversion method and device and computer readable storage medium
CN103124947A (en) Method and apparatus for providing low cost programmable pattern recognition
CN102375759B (en) Utilize the method that finite state machine prevents code rewriting
CN106603125B (en) Method and device for data interaction with Bluetooth equipment
CN112882769B (en) Skill pack data processing method, skill pack data processing device, computer equipment and storage medium
CN110597552A (en) Configuration method, device and equipment of project continuous integration pipeline and storage medium
CN113094125B (en) Business process processing method, device, server and storage medium
CN105930190A (en) Program self-starting method and device based on operating system
CN115885253A (en) Control method and device of finite state machine, computer equipment and storage medium
CN110908644A (en) Configuration method and device of state node, computer equipment and storage medium
CN112069015B (en) Instruction execution method and device for instruction simulator, terminal equipment and storage medium
CN108874625B (en) Information processing method and device, electronic equipment and storage medium
CN113835680A (en) Application program generation method and device, electronic equipment and computer storage medium
CN113094052A (en) Application construction method and device, computer equipment and storage medium
JP2005092708A (en) Software update system and method, and computer program
CN112015570A (en) Message reminding processing method and device
US11968090B2 (en) Dynamic installation of mobile application modules
CN114879962B (en) Method and device for realizing batch system call
CN103927345A (en) JSP (java server page) tag nesting method and device
CN117539451B (en) Flow execution method, device, electronic equipment and storage medium
US20230359440A1 (en) Externally-initiated runtime type extension
US11487564B1 (en) Terminal shell switching

Legal Events

Date Code Title Description
PB01 Publication
PB01 Publication
SE01 Entry into force of request for substantive examination
SE01 Entry into force of request for substantive examination