Construct the finite state machine method for Linux operating system applications-general Linux technology-Linux programming and kernel information. The following is a detailed description. Finite Automation Machine is an important cornerstone of computer science. It is usually called a Finite State Machine (Finite State Machine) in the field of software development ), it is a Design Pattern that is widely used ). This article describes how to build a software system based on the state machine and how to use tools in Linux to automatically generate a practical state machine framework.
1. What is a state machine?
A finite state machine is a tool used to model object behavior. Its role is to describe the sequence of states that an object has experienced during its lifecycle, and how to respond to various events from outside. In an object-oriented software system, no matter how simple or complex an object is, it will inevitably go through a complete process from initial creation to final extinction, this is usually called the lifecycle of an object. Generally, an object cannot be completely isolated during its life cycle. It must affect other objects by sending messages, or change itself by accepting messages. In most cases, these messages are just simple and synchronous method calls. For example, in the bank Customer management system, when an instance of the Customer class is required, the getBalance () method defined in the Account class may be called. In this simple case, the Class Customer does not need a finite state machine to describe its own behavior, mainly because its current behavior does not depend on a previous state.
Unfortunately, not all cases will be so simple. In fact, many practical software systems must maintain one or two very critical objects, which usually have very complex state conversion relationships, in addition, it is necessary to respond to various asynchronous events from external sources. For example, in a VoIP Phone System, Telephone instances must be able to respond to random calls from the other party, key events from the user, and signaling from the network. When processing these messages, Telephone-like behaviors depend entirely on the current status. Therefore, using a state machine is a good choice.
The game engine is one of the most successful applications of finite state machines. Because a well-designed state machine can be used to replace some artificial intelligence algorithms, therefore, each role or device in the game may be embedded with a state machine. Consider a simple object such as the gate in RPG games. It has four states: open, Closed, Locked, and Unlocked, as shown in 1. When a player reaches a Locked door, if he has found the key to open the door, he can use it to change the current status of the door to Unlocked, you can also switch the door knob to Opened to successfully enter the city.
(400) {this. resized = true; this. width = 400; this. alt = 'click here to open new window';} "onmouseover =" if (this. resized) this. style. cursor = 'hand'; "onclick =" window. open ('HTTP: // linux.ccidnet.com/col/attachment/2006/12/956953.jpg'); ">
State machine controlling the city gate