WO2022140880A1 - Method and apparatus for controlling finite state machine, computer device, and storage medium - Google Patents

Method and apparatus for controlling finite state machine, computer device, and storage medium Download PDF

Info

Publication number
WO2022140880A1
WO2022140880A1 PCT/CN2020/139828 CN2020139828W WO2022140880A1 WO 2022140880 A1 WO2022140880 A1 WO 2022140880A1 CN 2020139828 W CN2020139828 W CN 2020139828W WO 2022140880 A1 WO2022140880 A1 WO 2022140880A1
Authority
WO
WIPO (PCT)
Prior art keywords
event
state
processing
class
function
Prior art date
Application number
PCT/CN2020/139828
Other languages
French (fr)
Chinese (zh)
Inventor
陈绍昆
Original Assignee
深圳元戎启行科技有限公司
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 深圳元戎启行科技有限公司 filed Critical 深圳元戎启行科技有限公司
Priority to PCT/CN2020/139828 priority Critical patent/WO2022140880A1/en
Priority to CN202080103184.8A priority patent/CN115885253A/en
Publication of WO2022140880A1 publication Critical patent/WO2022140880A1/en

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

Definitions

  • 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 includes a state machine class and state class; the state machine class is used to implement the logic of state jumping; the state class is used to complete the processing of specific business logic; when processing the event, if the state machine class according to the current state, If it is determined that the event is accepted to be processed, corresponding business logic processing is performed on the event, and a corresponding processing state is returned; and a processing mode corresponding to the next state is determined according to the processing state.
  • Step 206 call the event processing class to process the event; wherein, the event processing class includes a state machine class and a state class; the state machine class is used to implement the logic of state jumping, and the state class is used to complete the processing of specific business logic.
  • the conversion module 704 is configured to convert the control signal into an event according to the signaling information.
  • the calling module 706 is used to call the event processing class to process the event, wherein the event processing class includes a state machine class and a state class, the state machine class is used to implement the logic of state jumping, and the state class is used to complete the processing of specific business logic .
  • the calling module is further configured to call the GetStrategy function to obtain a processing strategy corresponding to the current state, and the processing strategy includes an ignore event, a replacement event, and a rollback event.
  • the processing module is also used to ignore the event when the processing strategy returned by the GetStrategy function is to ignore the event; when the processing strategy returned by the GetStrategy function is to replace the event, create a new state to replace the current state and process the event according to the event; When the processing strategy returned by the GetStrategy function is a rollback event, it returns to the previous state to process the event.

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 method for controlling a finite state machine comprises: receiving a control signal, the control signal carrying signalling information; on the basis of the signalling information, converting the control signal into an event; invoking an event handling class to handle the event, wherein the event handling class comprises a state machine class and a state class, the state machine class being used for implementing state jumping logic, and the state class being used for completing handling of a specific service logic; when handling the event, if on the basis of the current state the state machine class determines to accept handling of the event, then implementing corresponding service logic handling for the event, and returning the corresponding handling state; and, on the basis of the handling state, determining the handling means corresponding to the next state.

Description

有限状态机的控制方法、装置、计算机设备和存储介质Control method, device, computer equipment and storage medium for finite state machine 技术领域technical field
本申请涉及计算机技术领域,特别是涉及一种有限状态机的控制方法、装置、计算机设备和存储介质。The present application relates to the field of computer technology, and in particular, to a control method, apparatus, computer device and storage medium for a finite state machine.
背景技术Background technique
随着计算机技术的发展,有限状态机(FSM)能够有效、方便地描述系统和组件的动态行为,其广泛应用于电信软件应用开发。FSM具有有限个状态,一般包括状态及状态之间的转移关系。目前,在软件编程工程中,目前普遍采用的实现FSM的方式是采用过程语言,例如C语言,采用这种方法实现的FSM实质上是由条件语句描述的。With the development of computer technology, finite state machine (FSM) can effectively and conveniently describe the dynamic behavior of systems and components, which is widely used in the development of telecommunication software applications. FSM has a limited number of states, generally including states and transition relationships between states. At present, in software programming engineering, the commonly used way to implement FSM is to use procedural language, such as C language, and the FSM implemented by this method is essentially described by conditional statements.
然而,目前的有限状态机的控制方式中,通常状态之间的切换关系需要提前注册好,且状态机不通用,不能灵活的动态添加状态,同时在运行时,也不支持根据当前状态进行状态回滚,即无法动态控制不同状态之间的跳转,容易导致控制效率较低。However, in the current control method of the finite state machine, the switching relationship between the states needs to be registered in advance, and the state machine is not universal, so the state cannot be dynamically added flexibly. Rollback, that is, the inability to dynamically control the jump between different states, easily leads to low control efficiency.
发明内容SUMMARY OF THE INVENTION
根据本申请公开的各种实施例,提供一种有限状态机的控制方法、装置、计算机设备和存储介质。According to various embodiments disclosed in the present application, a control method, apparatus, computer device and storage medium for a finite state machine are provided.
一种有限状态机的控制方法,包括:A control method for 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 includes a state machine class and state class; the state machine class is used to implement the logic of state jumping; the state class is used to complete the processing of specific business logic; when processing the event, if the state machine class according to the current state, If it is determined that the event is accepted to be processed, corresponding business logic processing is performed on the event, and a corresponding processing state is returned; and a processing mode corresponding to the next state is determined according to the processing state.
一种有限状态机的控制装置,包括:A control device for a finite state machine, comprising:
接收模块,用于接收控制信号;所述控制信号中携带信令信息;转换模块,用于根据所述信令信息,将所述控制信号转换为事件;调用模块,用于调用事件处理类对所述事件进行处理;其中,所述事件处理类包括状态机类和状态类;所述状态机类用于实现状态跳转的逻辑;所述状态类用于完成具体业务逻辑的处理;处理模块,用于在对所述事件进行处理时,若状态机类根据当前状态,判定接受处理所述事件,则对所述事件进行对应的业务逻辑处理,返回对应的处理状态;及确定模块,用于根据所述处理状态,确定下一个状态对应的处理方式。a receiving module for receiving a control signal; the control signal carries signaling information; a conversion module for converting the control signal into an event according to the signaling information; a calling module for calling an event processing class pair The event is processed; wherein, the event processing class includes a state machine class and a state class; the state machine class is used to implement the logic of state jumping; the state class is used to complete the processing of specific business logic; processing module , used to process the event, if the state machine class decides to accept and process the event according to the current state, perform corresponding business logic processing on the event, and return the corresponding processing state; and determine the module, use According to the processing state, the processing mode corresponding to the next state is determined.
一种计算机设备,包括存储器和一个或多个处理器,所述存储器中储存有计算机可读指令,所述计算机可读指令被所述处理器执行时,使得所述一个或多个处理器执行以下步骤:获取产品信息;A computer device comprising a memory and one or more processors, the memory having computer-readable instructions stored therein, the computer-readable instructions, when executed by the processor, cause the one or more processors to execute The following steps: get 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 includes a state machine class and state class; the state machine class is used to implement the logic of state jumping; the state class is used to complete the processing of specific business logic; when processing the event, if the state machine class according to the current state, If it is determined that the event is accepted to be processed, corresponding business logic processing is performed on the event, and a corresponding processing state is returned; and a processing mode corresponding to the next state is determined 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 following steps: obtain 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 includes a state machine class and state class; the state machine class is used to implement the logic of state jumping; the state class is used to complete the processing of specific business logic; when processing the event, if the state machine class according to the current state, If it is determined that the event is accepted to be processed, corresponding business logic processing is performed on the event, and a corresponding processing state is returned; and a processing mode corresponding to the next state is determined 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 present application will be apparent from the description, drawings, and claims.
附图说明Description of drawings
为了更清楚地说明本申请实施例中的技术方案,下面将对实施例中所需要使用的附图作简单地介绍,显而易见地,下面描述中的附图仅仅是本申请的一些实施例,对于本领域普通技术人员来讲,在不付出创造性劳动的前提下,还可以根据这些附图获得其它的附图。In order to illustrate the technical solutions in the embodiments of the present application more clearly, the following briefly introduces the drawings required in the embodiments. Obviously, the drawings in the following description are only some embodiments of the present application. For those of ordinary skill in the art, other drawings can also be obtained from these drawings without any creative effort.
图1为一个实施例中有限状态机的控制方法的应用环境图;Fig. 1 is the application environment diagram of the control method of finite state machine in one embodiment;
图2为一个实施例中有限状态机的控制方法的流程示意图;2 is a schematic flowchart of a control method for a finite state machine in one embodiment;
图3为一个实施例中根据处理状态,确定下一个状态对应的处理方式步骤的流程示意图;FIG. 3 is a schematic flowchart of steps of determining a processing mode corresponding to a next state according to a processing state in one embodiment;
图4为一个实施例中获取当前状态对应的处理策略步骤的流程示意图;FIG. 4 is a schematic flowchart of obtaining a processing strategy step corresponding to the current state in one embodiment;
图5为一个实施例中当GetStrategy函数返回的处理策略为替换事件时,则根据事件,创建一个新状态替换当前状态,对事件进行处理步骤的流程示意图;Fig. 5 is when the processing strategy that GetStrategy function returns is replacement event in one embodiment, then according to the event, create a new state to replace the current state, the schematic flow chart of the event processing step;
图6A为另一个实施例中有限状态机的控制方法的流程示意图;6A is a schematic flowchart of a control method for a finite state machine in another embodiment;
图6B为一个实施例中有限状态机对事件进行处理时的调用关系示意图;6B is a schematic diagram of a calling relationship when a finite state machine processes an event in one embodiment;
图7为一个实施例中有限状态机的控制装置的结构框图;7 is a structural block diagram of a control device of a finite state machine in one embodiment;
图8为一个实施例中计算机设备的内部结构图。FIG. 8 is a diagram of the internal structure of a computer device in one embodiment.
具体实施方式Detailed ways
为了使本申请的技术方案及优点更加清楚明白,以下结合附图及实施例,对本申请进行进一步详细说明。应当理解,此处描述的具体实施例仅仅用以解释本申请,并不用于限定本申请。In order to make the technical solutions and advantages of the present application clearer, the present application will be further described in detail below with reference to the accompanying drawings and embodiments. It should be understood that the specific embodiments described herein are only used to explain the present application, but not to limit the present application.
本申请实施例中所提供的有限状态机的控制方法,可以应用于如图1所示的应用环境中,终端102通过网络与终端104通过网络进行通信。终端102接收到终端104发送的控制信号,控制信号中携带信令信息。终端102根据信令信息,将控制信号转换为事件。终端102调用事件处理类对事件进行处理。事件处理类包括状态机类和状态类,状态机类用于实现状态跳转的逻辑,状态类用于完成具体业务逻辑的处理。在终端102对事件进行处理时,若状态机类根据当前状态,判定接受处理事件,则对事件进行对应的业务逻辑处理,返回对应的处理状态。终端102根据处理状态,确定下一个状态对应的处理方式。终端102可以但不限于是各种个人计算机、笔记本电脑、智能手机、平板电脑和便携式可穿戴设备。The control method of the finite state machine provided in the embodiment of the present application can be applied to the application environment shown in FIG. 1 , where the terminal 102 communicates with the terminal 104 through the network through the network. The terminal 102 receives the 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 invokes the event processing class to process the event. The event processing class includes a state machine class and a state class. The state machine class is used to implement the logic of state jumping, and the state class is used to complete the processing of specific business logic. When the terminal 102 processes the event, if the state machine class determines that the event is to be processed according to the current state, it performs corresponding business logic processing on the event, and returns the corresponding processing state. The terminal 102 determines the 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, notebook computers, smart phones, tablet computers, and portable wearable devices.
下述实施方式以有限状态机的控制方法应用于图1的终端为例进行说明,但需要说明的是,实际应用中该方法并不仅限应用于上述终端。The following embodiments illustrate that the control method of the finite state machine is applied to the terminal in FIG. 1 as an example, but it should be noted that in practical application, the method is not limited to the above-mentioned terminal.
如图2所示,在其中一个实施例中的有限状态机的控制方法的流程图,该方法具体包括以下步骤:As shown in FIG. 2 , in one embodiment, a flow chart of a control method for a finite state machine, the method specifically includes the following steps:
步骤202,接收控制信号,控制信号中携带信令信息。Step 202: Receive a control signal, where the control signal carries signaling information.
有限状态机是一种用来进行对象行为建模的工具,其作用主要是描述对象在它的生命周期内所经历的状态序列,以及如何响应来自外界的各种事件。在计算机科学中,有限状态机被广泛用于建模应用行为、硬件电路系统设计、软件工程,编译器、网络协议和计算与语言的研究。状态机由状态寄存器和组合逻辑电路构成,能够根据控制信号按照预先设定的状态进行状态转移,是协调相关信号动作、完成特定操作的控制中心。A finite state machine is a tool for modeling object behavior. Its role is to describe the sequence of states that an object experiences in its life cycle and how to respond to various events from the outside world. In computer science, finite state machines are widely used in modeling application behavior, hardware circuit system design, software engineering, compilers, network protocols, and research in computing and languages. The state machine is composed of a state register and a combinational logic circuit, which can perform state transition according to a preset state according to a control signal, and is a control center that coordinates the actions of related signals and completes specific operations.
有限状态机简写为FSM(Finite State Machine),有限状态机是表示有限个状态以及在这些状态之间的转移和动作等行为的数学模型。常见的计算机就是使用有限状态机作为计算模型的,对于内存的不同状态,中央处理器(CPU,Central Processing Unit)即CPU通过读取内存值进行计算,更新内存中的状态。CPU还通过消息总线接受外部输入设备(如键盘、鼠标)的指令,计算后更改内存中的状态,计算结果输出到外部显示设备(如显示器),以及持久化存储在 硬盘。游戏设计中也经常使用有限状态机模型。以水果忍者游戏为例,游戏中水果的状态是有限状态,其运行轨迹是由模拟物理运动规律的计算公式运算而成的,一个香蕉抛起来后会按照抛物线运行,其每一帧位置变化都是一个状态的改变,状态改变通过计算公式来决定。游戏还涉及复杂的人机交互事件,比如用手在屏幕上“切”了水果,水果感知到这个事件后,会按照程序逻辑进入爆炸状态。A finite state machine is abbreviated as FSM (Finite State Machine). A finite state machine is a mathematical model that represents a finite number of states and behaviors such as transitions and actions between these states. A common computer uses a finite state machine as a computing model. For different states of memory, the central processing unit (CPU, Central Processing Unit), that is, the CPU, performs calculations by reading the memory value and updates the state in the memory. The CPU also accepts instructions from external input devices (such as keyboard and mouse) through the message bus, changes the state in memory after calculation, outputs the calculation results to external display devices (such as monitors), and persists them on the hard disk. Finite state machine models are also frequently used in game design. Taking the fruit ninja game as an example, the state of the fruit in the game is a finite state, and its running trajectory is calculated by a calculation formula that simulates the laws of physical motion. After a banana is thrown, it will run in a parabola, and its position changes every frame. It is a state change, and the state change is determined by a calculation formula. The game also involves complex human-computer interaction events, such as "cutting" fruit on the screen with your hands. After the fruit perceives this event, it will enter an explosion state according to program logic.
具体的,终端可以接收控制信号,控制信号中携带信令信息。控制信号是一种用于控制的信号,依靠该控制信号为媒介来实施对计算机控制。控制信号可以是由不同设备发送至终端的,不同的设备可以包括第三方设备、终端设备、服务器以及物联网设备等。信令信息是指信令的具体内容,即控制信号携带的控制信息。信令是在无线通信系统中,除了传输用户信息之外,为使全网有轶序地工作,用来保证正常通信所需要的控制信号。即信令实际上是一种用于控制的信号。Specifically, the terminal may receive a control signal, and the control signal carries signaling information. A control signal is a signal used for control, and the computer is controlled by means of the control signal as a medium. The control signal may be sent to the terminal by different devices, and the different devices may include third-party devices, terminal devices, servers, and IoT devices. The signaling information refers to the specific content of the signaling, that is, the control information carried by the control signal. In a wireless communication system, signaling is a control signal required to ensure normal communication in order to make the entire network work in an orderly manner, in addition to transmitting user information. That is, signaling is actually a signal for control.
步骤204,根据信令信息,将控制信号转换为事件。Step 204: Convert the control signal into an event according to the signaling information.
终端接收到不同设备发送的控制信号之后,终端可以根据控制信号中携带信令信息,将该控制信号转换为事件。事件是指对象对于外部动作的响应,当对象发生了某个事件,就会执行与此对象的这个事件相应的代码,这段代码被称为“事件过程”。终端可以根据信令的具体内容,将接收到的信号转换为事件,即终端将接收到的信号抽象为事件,一个事件可以包含事件类型、事件标识(即事件id)和事件内容(msg)。具体的,终端可以根据信令的具体内容,将信号转化为内部定义的事件类型、事件标识和事件内容,并将这些值保存到事件Event这个结构体中。事件类型和事件标识可以是整形变量类型来保存的,事件内容是通过void指针保存的信令的内存地址,这样就可以把不同的信号转换为可以统一处理的事件Event。void指针是指一种特殊的指针,表示为“无类型指针”,在ANSIC中使用它来代替“char*”作为通用指针的类型。由于void指针没有特定的类型,因此它可以指向任何类型的数据。也就是说,任何类型的指针都可以直接赋值给void指针,而无需进行其他相关的强制类型转换。After the terminal receives the control signal sent by different devices, the terminal can convert the control signal into an event according to the signaling information carried in the control signal. An event refers to an object's response to an external action. When an event occurs in an object, the code corresponding to the event of the object will be executed. This code is called an "event procedure". The terminal can convert the received signal into an event according to the specific content of the signaling, that is, the terminal abstracts the received signal into an event, and an event can include event type, event identifier (ie event id) and event content (msg). Specifically, the terminal can convert the signal into an internally defined event type, event identifier and event content according to the specific content of the signaling, and save these values in the structure of the event Event. The event type and event identifier can be stored as an integer variable type, and the event content is the memory address of the signaling stored through the void pointer, so that different signals can be converted into events that can be handled uniformly. A void pointer refers to a special kind of pointer, denoted as an "untyped pointer", which is used in ANSIC to replace "char*" as the type of generic pointer. Since a void pointer has no specific type, it can point to any type of data. That is, a pointer of any type can be directly assigned to a void pointer without other related casts.
步骤206,调用事件处理类对事件进行处理;其中,事件处理类包括状态机 类和状态类;状态机类用于实现状态跳转的逻辑,状态类用于完成具体业务逻辑的处理。 Step 206, call the event processing class to process the event; wherein, the event processing class includes a state machine class and a state class; the state machine class is used to implement the logic of state jumping, and the state class is used to complete the processing of specific business logic.
终端根据信令信息,将控制信号转换为事件之后,终端可以调用事件处理类对抽象的事件进行处理。类(Class)是面向对象程序设计(OOP,Object-Oriented Programming)实现信息封装的基础。类是一种用户定义的引用数据类型,也称类类型。每个类包含数据说明和一组操作数据或传递消息的函数。类的实例称为对象。事件处理类是指一组可以复用的业务功能的集合,包含一些对象及其行为,通过调用的方式从而达到复用功能的目的。事件处理类可以包括状态机类和状态类,状态机类用于实现状态跳转的逻辑,状态类用于完成具体业务逻辑的处理。具体的,终端根据信令信息,将信号转换为事件之后,终端可以调用事件处理类对转换的事件进行处理。即终端中对事件的处理类都可以继承自一个类(Handler类),该Handler类包含HandEvent函数。状态机类即StateMachine类,状态类即State类,StateMachine类和State类本质都是对事件进行处理的类,因此,通过抽象出一个事件处理的Handler类,提供一个抽象的接口HandEvent事件处理函数,即可在子类实现HandEvent函数,具体来说就是在子类StateMachine中的HandEvent函数实现状态跳转的逻辑,在子类State中的HandEvent函数完成具体业务逻辑的处理。每个状态State包含Enter函数,用于进入状态的函数,HandEvent函数,用于处理当前状态能接受的事件的函数,Exit函数,用于退出状态的函数,GetStrategy函数,用于获取当前状态对于不能接受的事件的处理策略的函数。After the terminal converts the control signal into an event according to the signaling information, the terminal can call the event processing class to process the abstract event. Class is the basis for object-oriented programming (OOP, Object-Oriented Programming) to realize information encapsulation. A class is a user-defined reference data type, also known as a class type. Each class contains data descriptions and a set of functions that manipulate data or pass messages. An instance of a class is called an object. An event processing class refers to a set of reusable business functions, including some objects and their behaviors, which can be invoked to achieve the purpose of reusing functions. The event processing class can include a state machine class and a state class. The state machine class is used to implement the logic of state jumping, and the state class is used to complete the processing of specific business logic. Specifically, after the terminal converts the signal into an event according to the signaling information, the terminal can call the event processing class to process the converted event. That is, the event processing class in the terminal can inherit from a class (Handler class), and the Handler class contains the HandEvent function. The state machine class is the StateMachine class, and the state class is the State class. The StateMachine class and the State class are essentially classes that process events. Therefore, by abstracting an event processing Handler class, an abstract interface HandEvent event handler is provided. The HandEvent function can be implemented in the subclass. Specifically, the HandEvent function in the subclass StateMachine implements the logic of state jumping, and the HandEvent function in the subclass State completes the processing of specific business logic. Each state State contains the Enter function, the function used to enter the state, the HandEvent function, the function used to process the events that the current state can accept, the Exit function, the function used to exit the state, the GetStrategy function, used to get the current state A function of the processing strategy for the accepted event.
步骤208,在对事件进行处理时,若状态机类根据当前状态,判定接受处理事件,则对事件进行对应的业务逻辑处理,返回对应的处理状态。 Step 208 , when the event is processed, if the state machine class determines that the event is to be processed according to the current state, the event is processed by corresponding business logic, and the corresponding processing state is returned.
终端调用事件处理类对事件进行处理时,若状态机类根据当前状态,判定接受处理事件,则对事件进行对应的业务逻辑处理,返回对应的处理状态。具体的,终端调用Handler类对事件进行处理时,若StateMachine类根据当前状态,判定接受处理事件,则通过子类State中的HandEvent函数对事件进行对应的业务逻辑处理,并返回对应的处理状态。即终端调用当前状态的HandEvent函数,对事件进行对应的业务逻辑处理,并返回对应的处理状态。处理状态是每个状 态对事件进行处理后返回对应的状态码,状态码是HandEvent函数的返回值。即状态码指的是状态处理函数的返回值,StateMachine类可以根据这个返回值来决定接下来的动作。When the terminal invokes the event processing class to process the event, if the state machine class determines that the event is to be processed according to the current state, it will perform corresponding business logic processing on the event and return the corresponding processing state. Specifically, when the terminal calls the Handler class to process the event, if the StateMachine class decides to accept the processing event according to the current state, the HandEvent function in the subclass State will process the event corresponding to the business logic, and return the corresponding processing state. That is, the terminal calls the HandEvent function of the current state, performs corresponding business logic processing on the event, and returns the corresponding processing state. The processing status is that each status returns the corresponding status code after processing the event, and the status code is the return value of the HandEvent function. That is, the status code refers to the return value of the state processing function, and the StateMachine class can determine the next action based on this return value.
步骤210,根据处理状态,确定下一个状态对应的处理方式。Step 210: Determine the processing mode corresponding to the next state according to the processing state.
终端调用事件处理类对事件进行处理,返回对应的处理状态之后,终端可以继续调用事件处理类,根据返回的处理状态,确定下一个状态对应的处理方式。例如,终端通过子类State中的HandEvent函数对当前事件进行对应的业务逻辑处理,HandEvent函数根据对当前事件的处理情况,可以返回DONE_EVENT、CONTINUE_EVENT、和UNKOWN_EVENT三个处理状态。DONE_EVENT表示当前状态已经对事件处理完毕,可以跳转到下一个状态;CONTINUE_EVENT表示当前状态继续处理该事件,不进行状态跳转;UNKOWN_EVENT表示当前状态不能接受该事件,需要StateMachine类根据当前状态的GetStrategy函数,获取当前状态的策略,并根据获取到的策略,执行接下来的步骤。The terminal calls the event processing class to process the event, and after returning the corresponding processing state, the terminal can continue to call the event processing class, and determine the processing method corresponding to the next state according to the returned processing state. For example, the terminal performs corresponding business logic processing on the current event through the HandEvent function in the subclass State. The HandEvent function can return three processing states of DONE_EVENT, CONTINUE_EVENT, and UNKOWN_EVENT according to the processing of the current event. DONE_EVENT means that the current state has finished processing the event, and can jump to the next state; CONTINUE_EVENT means that the current state continues to process the event without state jumping; UNKOWN_EVENT means that the current state cannot accept the event, and the StateMachine class needs to be based on the GetStrategy of the current state function to get the strategy of the current state, and execute the next steps according to the obtained strategy.
传统的有限状态机的控制方式中,在状态跳转时,需要在状态机中指定下一个要跳转的状态,因而不方便添加新状态,每添加一个状态,就需要修改状态机对应的代码。而本实施例中,通过接收控制信号,控制信号中携带信令信息,根据信令信息,将控制信号转换为事件,调用事件处理类对事件进行处理。事件处理类包括状态机类和状态类,状态机类用于实现状态跳转的逻辑,状态类用于完成具体业务逻辑的处理。在对事件进行处理时,若状态机类根据当前状态,判定接受处理事件,则对事件进行对应的业务逻辑处理,返回对应的处理状态,并根据处理状态,确定下一个状态对应的处理方式。由此使得,通过把各种不同的信号的抽象为统一的参数Event来进行事件的处理和状态之间的跳转,状态机部分可以做得更通用,方便进行新状态的添加而不用修改状态机部分的代码,能够根据事件处理策略灵活的创建状态和进行状态跳转,从而有效的提高了控制效率。In the traditional control method of finite state machine, when the state jumps, it is necessary to specify the next state to be jumped in the state machine, so it is inconvenient to add a new state. Each time a state is added, the code corresponding to the state machine needs to be modified. . In this embodiment, however, by receiving a control signal, the control signal carries signaling information, and according to the signaling information, the control signal is converted into an event, and an event processing class is invoked to process the event. The event processing class includes a state machine class and a state class. The state machine class is used to implement the logic of state jumping, and the state class is used to complete the processing of specific business logic. When processing an event, if the state machine class decides to accept and process the event according to the current state, it will perform corresponding business logic processing on the event, return the corresponding processing state, and determine the processing method corresponding to the next state according to the processing state. As a result, by abstracting various signals into a unified parameter Event to process events and jump between states, the state machine part can be made more general, and it is convenient to add new states without modifying the state. The code of the machine part can flexibly create states and perform state jumps according to the event processing strategy, thereby effectively improving the control efficiency.
在其中一个实施例中,如图3所示,处理状态包括处理完毕、继续处理和不接受处理,根据处理状态,确定下一个状态对应的处理方式的步骤,包括:In one embodiment, as shown in FIG. 3 , the processing status includes processing completed, continuing processing and not accepting processing. According to the processing status, the steps of determining the processing mode corresponding to the next status include:
步骤302,当返回的处理状态为处理完毕时,则跳转至下一个状态对事件进行处理。 Step 302, when the returned processing state is that the processing is completed, jump to the next state to process the event.
步骤304,当返回的处理状态为继续处理时,则不进行状态跳转,调用当前状态的HandEvent函数,继续对事件进行处理。 Step 304, when the returned processing state is to continue processing, no state jump is performed, and the HandEvent function of the current state is called to continue processing the event.
步骤306,当返回的处理状态为不接受处理时,则获取当前状态对应的处理策略。 Step 306, when the returned processing status is not accepting processing, acquire the processing strategy corresponding to the current status.
终端调用事件处理类对事件进行处理,返回对应的处理状态之后,终端可以继续调用事件处理类,根据上一个步骤返回的处理状态,确定下一个状态对应的处理方式。处理状态包括处理完毕、继续处理和不接受处理。具体的,当HandEvent函数根据对当前事件的处理情况,返回的处理状态为处理完毕时,则StateMachine类可以跳转至下一个状态对事件进行处理。当返回的处理状态为继续处理时,则不进行状态跳转,StateMachine类调用当前状态的HandEvent函数,继续对该事件进行处理。当返回的处理状态为不接受处理时,则StateMachine类获取当前状态对应的处理策略。即只有当返回UNKOWN_EVENT(不接受处理)的状态时,StateMachine类才会调用当前状态的GetStrategy函数去获取对应的处理策略。The terminal calls the event processing class to process the event, and after returning the corresponding processing state, the terminal can continue to call the event processing class, and determine the processing method corresponding to the next state according to the processing state returned in the previous step. Processing status includes processing completed, continuing processing, and not accepting processing. Specifically, when the HandEvent function returns the processing status according to the processing of the current event, the StateMachine class can jump to the next status to process the event. When the returned processing state is to continue processing, no state jump is performed, and the StateMachine class calls the HandEvent function of the current state to continue processing the event. When the returned processing status is not accepting processing, the StateMachine class obtains the processing strategy corresponding to the current status. That is, only when the state of UNKOWN_EVENT (not accepting processing) is returned, the StateMachine class will call the GetStrategy function of the current state to obtain the corresponding processing strategy.
具体的,通过HandEvent函数对当前事件进行处理时,终端通过调用State类的HandEvent函数根据事件Event的事件类型和事件标识,判断该事件Event是否为在当前状态处理的事件,若是,则利用HandEvent函数对当前事件进行具体的业务逻辑的处理;若不是,则表明当前状态无法处理该事件,返回UNKOWN_EVENT的处理状态。每个状态对事件进行处理后返回对应的状态码,当返回CONTINUE_EVENT的处理状态时,表示当前状态可以连续处理该事件,则不需要进行状态跳转,由此可以减少状态的不必要跳转,无需从当前状态又跳转到当前状态,能够动态控制不同状态之间的跳转,从而有效提高了控制效率。Specifically, when processing the current event through the HandEvent function, the terminal judges whether the event Event is an event processed in the current state by calling the HandEvent function of the State class according to the event type and event identifier of the event Event, and if so, uses the HandEvent function. Perform specific business logic processing on the current event; if not, it indicates that the current state cannot process the event, and returns the processing state of UNKOWN_EVENT. Each state processes the event and returns the corresponding status code. When returning to the processing state of CONTINUE_EVENT, it means that the current state can process the event continuously, and there is no need to perform state jumps, which can reduce unnecessary state jumps. There is no need to jump from the current state to the current state, and the jump between different states can be dynamically controlled, thereby effectively improving the control efficiency.
在其中一个实施例中,如图4所示,获取当前状态对应的处理策略的步骤,包括:In one of the embodiments, as shown in FIG. 4 , the steps of acquiring the processing strategy corresponding to the current state include:
步骤402,调用GetStrategy函数获取当前状态对应的处理策略,处理策略 包括忽略事件、替换事件和回滚事件。 Step 402, calling the GetStrategy function to obtain the processing strategy corresponding to the current state, and the processing strategy includes an ignore event, a replacement event and a rollback event.
步骤404,当GetStrategy函数返回的处理策略为忽略事件时,则忽略事件。 Step 404, when the processing strategy returned by the GetStrategy function is to ignore the event, ignore the event.
步骤406,当GetStrategy函数返回的处理策略为替换事件时,则根据事件,创建一个新状态替换当前状态,对事件进行处理。 Step 406, when the processing strategy returned by the GetStrategy function is a replacement event, then according to the event, a new state is created to replace the current state, and the event is processed.
步骤408,当GetStrategy函数返回的处理策略为回滚事件时,则恢复至上一个状态来处理事件。 Step 408, when the processing strategy returned by the GetStrategy function is a rollback event, restore to the previous state to process the event.
终端调用事件处理类对事件进行处理,当返回的处理状态为不接受处理时,则StateMachine类可以获取当前状态对应的处理策略。具体的,StateMachine类可以通过调用GetStrategy函数获取当前状态对应的处理策略,处理策略包括忽略事件(IGNORE)、替换事件(REPLACE)和回滚事件(RECOVER)。即GetStrategy函数对于当前事件可以返回IGNORE、REPLACE以及RECOVER三种策略。IGNORE表示忽略当前事件,REPLACE表示根据当前事件创建一个新的状态来替换当前状态对该事件进行处理,RECOVER表示恢复上一个状态来处理当前事件。即当GetStrategy函数返回的处理策略为忽略事件时,则忽略该事件。当GetStrategy函数返回的处理策略为替换事件时,则根据事件,创建一个新状态替换当前状态,对该事件进行处理。当GetStrategy函数返回的处理策略为回滚事件时,则恢复至上一个状态来处理该事件。相较于传统有限状态机的控制方式中,由于没有保存上一个状态,也没有事件的动态处理策略,因而无法实现状态回滚,同时也无法解决何时可以进行状态回滚的问题。而本实施例中,状态的跳转策略是在具体的状态中实现的,这样就可以在运行时根据当前所处的状态,来决定下一个状态怎么跳转,或者回滚到上一个状态。因为在状态机StateMachine保存了上一个状态,如果当前状态对事件的处理策略是RECOVER时,则可以使得StateMachine回滚到上一个状态,能够实现根据事件处理策略灵活的创建状态和进行状态跳转。The terminal calls the event processing class to process the event. When the returned processing status is not accepting processing, the StateMachine class can obtain the processing strategy corresponding to the current status. Specifically, the StateMachine class can obtain the processing strategy corresponding to the current state by calling the GetStrategy function, and the processing strategy includes an ignore event (IGNORE), a replacement event (REPLACE), and a rollback event (RECOVER). That is, the GetStrategy function can return three strategies: IGNORE, REPLACE and RECOVER for the current event. IGNORE means to ignore the current event, REPLACE means to create a new state based on the current event to replace the current state to process the event, RECOVER means to restore the previous state to process the current event. That is, when the processing strategy returned by the GetStrategy function is to ignore the event, the event is ignored. 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 strategy returned by the GetStrategy function is a rollback event, it restores to the previous state to process the event. Compared with the control method of the traditional finite state machine, since the previous state is not saved and there is no dynamic processing strategy for events, the state rollback cannot be realized, and the problem of when the state can be rolled back cannot be solved. In this embodiment, the state jumping strategy is implemented in a specific state, so that it is possible to decide how to jump to the next state or roll back to the previous state according to the current state at runtime. Because the state machine StateMachine saves the previous state, if the current state's event processing strategy is RECOVER, the StateMachine can be rolled back to the previous state, enabling flexible state creation and state jumping according to the event processing strategy.
在其中一个实施例中,如图5所示,当GetStrategy函数返回的处理策略为替换事件时,则根据事件,创建一个新状态替换当前状态,对事件进行处理的步骤,包括:In one embodiment, as shown in Figure 5, when the processing strategy returned by the GetStrategy function is a replacement event, then according to the event, a new state is created to replace the current state, and the steps of processing the event include:
步骤502,当GetStrategy函数返回的处理策略为替换事件时,调用状态工 厂类,根据事件的事件类型和事件标识,利用CreateState函数创建对应的新状态。 Step 502, when the processing strategy returned by the GetStrategy function is the replacement event, the state factory class is called, and the CreateState function is used to create a corresponding new state according to the event type and event identifier of the event.
步骤504,将当前状态替换为新状态,利用新状态对事件进行处理。 Step 504 , replace the current state with a new state, and use the new state to process the event.
终端调用事件处理类对事件进行处理,当返回的处理状态为不接受处理时,则StateMachine类可以通过调用GetStrategy函数获取当前状态对应的处理策略。当GetStrategy函数返回的处理策略为替换事件时,则根据事件,创建一个新状态替换当前状态,对事件进行处理。StateMachine类即状态机类包含一个状态工厂类(即StateFactory类对象)和两个状态。两个状态分别为当前状态(cur_state)和上一个状态(last_state)。StateFactory是一个创建具体State类对象的类,负责具体状态的创建,即StateFactory类主要用于根据事件创建相应的状态。last_state表示StateMachine的上一个状态,是为了状态回滚时使用。cur_state表示StateMachine的当前状态,cur_state的作用是当StateMachine接收到事件Event时,StateMachine首先尝试调用cur_state的HandEvent函数来处理该事件Event,并根据cur_state的处理结果来决定接下来的流程。例如,接下来的流程可以包括创建新状态来处理事件、忽略当前事件以及进行状态回滚。The terminal calls the event processing class to process the event. When the returned processing status is not accepting processing, the StateMachine class can obtain the processing strategy corresponding to the current status by calling the GetStrategy function. 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. The StateMachine class, the state machine class, contains a state factory class (ie, a StateFactory class object) and two states. The two states are the current state (cur_state) and the previous state (last_state). StateFactory is a class that creates specific State class objects and is responsible for the creation of specific states, that is, the StateFactory class is mainly used to create corresponding states based on events. last_state represents the last state of StateMachine, which is used when the state is rolled back. cur_state represents the current state of StateMachine. The function of cur_state is that when StateMachine receives an event, StateMachine first tries to call the HandEvent function of cur_state to process the event, and decides the next process according to the processing result of cur_state. For example, the next flow can include creating a new state to handle events, ignoring current events, and doing state rollbacks.
具体的,当GetStrategy函数返回的处理策略为替换事件时,则StateMachine类可以调用StateFactory,StateFactory根据当前事件的事件类型和事件标识,利用CreateState函数创建对应的新状态。进一步的,StateMachine将当前状态替换为新状态,利用新状态对该事件进行处理。StateFactory提供了一个CreateState函数来创建具体的状态,函数参数为事件Event。由此使得,StateMachine不用关心具体状态如何创建,只需要使用状态工厂来创建下一个状态,从而可以实现对状态的灵活创建。此外,将状态创建的过程封装到状态工厂类中,可以方便的对状态进行扩展,当需要新增一个状态时,只需要修改状态工厂类中的部分代码,而对于状态的具体使用者StateMachine来说并不需要做任何改变,方便代码扩展,能够实现根据事件处理策略灵活定的建状态和进行状态跳转。Specifically, when the processing strategy returned by the GetStrategy function is a replacement event, the StateMachine class can call the StateFactory, and the StateFactory uses the CreateState function to create a corresponding new state according to the event type and event identifier of the current event. Further, StateMachine replaces the current state with a new state, and uses the new state to process the event. StateFactory provides a CreateState function to create a specific state, and the function parameter is the event Event. As a result, StateMachine does not need to care about how the specific state is created, and only needs to use the state factory to create the next state, so that the flexible creation of the state can be realized. In addition, encapsulating the process of state creation into the state factory class can easily extend the state. When a new state needs to be added, only part of the code in the state factory class needs to be modified, and the specific user of the state StateMachine It is said that there is no need to make any changes, which is convenient for code expansion, and can realize flexible state creation and state jumping according to the event processing strategy.
在其中一个实施例中,如图6A所示,提供了一种有限状态机的控制方法,以该方法应用于图1中的终端为例进行说明,包括以下步骤:In one of the embodiments, as shown in FIG. 6A , a method for controlling a finite state machine is provided, and the method is applied to the terminal in FIG. 1 as an example for description, including the following steps:
步骤602,接收控制信号,控制信号中携带信令信息。Step 602: Receive a control signal, where the control signal carries signaling information.
步骤604,根据信令信息,将控制信号转换为事件。 Step 604, according to the signaling information, convert the control signal into an event.
步骤606,调用事件处理类对事件进行处理。其中,事件处理类包括状态机类和状态类,状态机类用于实现状态跳转的逻辑,状态类用于完成具体业务逻辑的处理。 Step 606, call the event processing class to process the event. Among them, the event processing class includes a state machine class and a state class. The state machine class is used to implement the logic of state jumping, and the state class is used to complete the processing of specific business logic.
步骤608,在对事件进行处理时,若状态机类根据当前状态,判定接受处理事件,则调用当前状态的HandEvent函数,对事件进行对应的业务逻辑处理,并返回对应的处理状态。其中,处理状态是每个状态对事件进行处理后返回对应的状态码,状态码是HandEvent函数的返回值。 Step 608 , when processing the event, if the state machine class determines to accept the processing event according to the current state, it calls the HandEvent function of the current state, performs corresponding business logic processing on the event, and returns the corresponding processing state. Among them, the processing state is that each state returns the corresponding state code after processing the event, and the state code is the return value of the HandEvent function.
步骤610,在对事件进行处理时,若状态机类根据当前状态,判定不接受处理事件时,则返回状态为不接受处理;获取当前状态对应的处理策略,根据处理策略,对事件进行处理,返回对应的处理状态。Step 610, when the event is processed, if the state machine class determines that the event is not accepted for processing according to the current state, the return state is that the processing is not accepted; the processing strategy corresponding to the current state is obtained, and the event is processed according to the processing strategy, Returns the corresponding processing status.
步骤612,当返回的处理状态为处理完毕时,则跳转至下一个状态对事件进行处理;当返回的处理状态为继续处理时,则不进行状态跳转,调用当前状态的HandEvent函数,继续对事件进行处理;当返回的处理状态为不接受处理时,则获取当前状态对应的处理策略。 Step 612, when the returned processing state is that the processing is completed, then jump to the next state to process the event; when the returned processing state is to continue processing, then no state jump is performed, and the HandEvent function of the current state is called to continue. Process the event; when the returned processing status is not accepting processing, the processing strategy corresponding to the current status is obtained.
如图6B所示,为有限状态机对事件进行处理时的调用关系示意图。终端接收到不同设备发送的控制信号之后,终端可以根据控制信号中携带信令信息,将该信号转换为事件。不同的设备可以包括第三方设备、终端设备、服务器以及物联网设备等。进一步的,终端可以调用事件处理类对事件进行处理。事件处理类包括状态机类和状态类,状态机类用于实现状态跳转的逻辑,状态类用于完成具体业务逻辑的处理。在对事件进行处理时,若状态机类根据当前状态,判定接受处理事件,则调用当前状态的HandEvent函数,对事件进行对应的业务逻辑处理,并返回对应的处理状态。处理状态是每个状态对事件进行处理后返回对应的状态码,状态码是HandEvent函数的返回值。此外,在对事件进行处理时,若状态机类根据当前状态,判定不接受处理事件时,则返回状态为不接受处理。当返回状态为不接受处理时,则终端通过StateMachine获取当前状态对应的处理策略,并根据获取到的处理策略,对事件进行处理,返回对应的处理状态。进一步的,当返回的处理状态为处理完毕时,则StateMachine跳转 至下一个状态对事件进行处理;当返回的处理状态为继续处理时,则StateMachine不进行状态跳转,调用当前状态的HandEvent函数,继续对事件进行处理;当返回的处理状态为不接受处理时,则StateMachine继续获取当前状态对应的处理策略。一个事件可以包含事件类型、事件标识(即事件id)和事件内容(MSG是Windows程序中的结构体,在Windows程序中,消息是由MSG结构体来表示的)。事件类型(Event_type),表示一类事件。事件标识即事件id(Event_id),表示一个具体的事件,因此在每个事件的处理函数中可以灵活的根据事件类型和事件id进行相应的处理,例如在父状态可以只关心事件类型,具体事件的逻辑可以在子状态中处理。As shown in FIG. 6B , it is a schematic diagram of a calling relationship when a finite state machine processes an event. After the terminal receives the control signal sent by different devices, the terminal can convert the signal into an event according to the signaling information carried in the control signal. Different devices can include third-party devices, terminal devices, servers, and IoT devices. Further, the terminal can call the event processing class to process the event. The event processing class includes a state machine class and a state class. The state machine class is used to implement the logic of state jumping, and the state class is used to complete the processing of specific business logic. When processing an event, if the state machine class decides to accept the processing event according to the current state, it will call the HandEvent function of the current state, process the corresponding business logic of the event, and return the corresponding processing state. The processing status is that each status returns the corresponding status code after processing the event, and the status code is the return value of the HandEvent function. In addition, when the event is processed, if the state machine class determines that the event is not accepted according to the current state, the return state is that the processing is not accepted. When the return status is not accepting processing, the terminal obtains the processing strategy corresponding to the current status through StateMachine, processes the event according to the obtained processing strategy, and returns the corresponding processing status. Further, when the returned processing state is completed, StateMachine jumps to the next state to process the event; when the returned processing state is to continue processing, StateMachine does not perform state jump and calls the HandEvent function of the current state. , continue to process the event; when the returned processing status is not accepting processing, StateMachine continues to obtain the processing strategy corresponding to the current status. An event can include event type, event identifier (ie event id) and event content (MSG is a structure in Windows programs, and in Windows programs, messages are represented by the MSG structure). Event type (Event_type), which represents a type of event. The event identifier is the event id (Event_id), which represents a specific event. Therefore, the processing function of each event can be flexibly processed according to the event type and event id. For example, in the parent state, you can only care about the event type and the specific event. The logic can be handled in substates.
下面以无人驾驶车辆为例进行说明。在系统收到一个信号后,即当终端接收到物联网设备车辆A发送的信号时,终端可以根据该信号中携带的控制信息,将该信号转换为内部的一个事件A。进一步的,终端可以调用状态机处理该事件A,状态机根据当前状态,判定是否能接受处理当前事件A,若判定接受处理事件A,则调用当前状态的HandEvent函数对事件A进行对应的业务逻辑处理,并返回对应的处理状态。例如,车辆A的状态可以包括正常运行和故障。状态机可以根据当前状态,判定是否能接受处理当前事件A,即判断事件A对应的车辆A的状态为正常运行还是故障。当状态机根据当前状态,判定接受处理事件A,即表示事件A对应的车辆A的状态为正常运行,才会进入接下来的流程。若判定不接受处理事件A,则表示事件A对应的车辆A的状态为故障,则无法接受处理该事件A,进入获取处理策略的流程,并根据获取到的处理策略,对该事件A进行处理,返回对应的处理状态。例如,当状态机获取的处理策略为替换事件(REPLACE)时,则状态机可以调用状态工厂创建新的状态来处理该事件A,并返回对应的处理状态。如果上述步骤都不能有效处理该事件A,则忽略该事件A。当车辆A正常运行时,可以接收到指令任务,指令任务包括任务开始、任务暂停、任务取消以及任务结束。状态机可以实现该车辆A正常运行时状态的跳转,即控制车辆A执行指令任务开始、任务暂停、任务取消或者任务结束。即系统可以定义一个大的父状态,在父状态中保存一个状态机来完成子状态的跳转,实现状态机的嵌套,方便灵活的为父状态添加子状态,对 于状态机的使用者来说,表现都是一样的,因此内部可以进行复杂的嵌套而不用担心会对状态机的使用者有影响。The following is an example of an unmanned vehicle. After the system receives a signal, that is, when the terminal receives the signal sent by the IoT device vehicle A, the terminal can convert the signal into an internal event A according to the control information carried in the signal. Further, the terminal can call the state machine to process the event A, and the state machine determines whether the current event A can be accepted and processed according to the current state. process and return the corresponding processing status. For example, the status of vehicle A may include normal operation and failure. The state machine can determine whether the current event A can be accepted and processed according to the current state, that is, whether the state of the vehicle A corresponding to the event A is normal operation or failure. When the state machine determines to accept and process event A according to the current state, it means that the state of vehicle A corresponding to event A is normal operation, and then the next process is entered. If it is determined that the event A is not accepted for processing, it means that the state of the vehicle A corresponding to the event A is faulty, and the event A cannot be accepted and processed, and the process of acquiring the processing strategy is entered, and the event A is processed according to the acquired processing strategy. , returns the corresponding processing status. For example, when the processing strategy obtained by the state machine is a replacement event (REPLACE), the state machine can call the state factory to create a new state to process the event A, and return the corresponding processing state. If none of the above steps can effectively handle the event A, then ignore the event A. When the vehicle A is running normally, it can receive command tasks, and the command tasks include task start, task suspension, task cancellation, and task end. The state machine can realize the transition of the state of the vehicle A during normal operation, that is, control the vehicle A to execute the command task start, task suspension, task cancellation or task end. That is, the system can define a large parent state, save a state machine in the parent state to complete the jump of the child state, realize the nesting of the state machine, and add child states to the parent state conveniently and flexibly. That said, the performance is the same, so complex nesting can be done internally without worrying about affecting the users of the state machine.
本实施例中,将所有信号都抽象为事件,并通过事件处理类可以灵活的根据事件类型或事件标识做出相应的处理,例如在父状态中只关心事件类型,在子状态中处理具体事件,从而实现了根据事件处理策略灵活的创建状态和进行状态跳转,同时,在运行时也可以根据策略进行状态回滚,能够动态控制不同状态之间的跳转,有效提高了控制效率。In this embodiment, all signals are abstracted into events, and corresponding processing can be flexibly made according to the event type or event identifier through the event processing class. For example, only the event type is concerned in the parent state, and specific events are processed in the child state. , so that the state can be created flexibly and the state jump can be performed according to the event processing strategy. At the same time, the state can also be rolled back according to the strategy at runtime, which can dynamically control the jump between different states and effectively improve the control efficiency.
在其中一个实施例中,事件处理类为Handler类,Handler类,是计算机用语,是Java子类及继承接口。Handler类可以包括子类StateMachine类和State类,StateMachine类和State类都继承自Handler类。在State类中保存一个指向StateMachine类的Handler指针,Handler指针用于实现父子状态机的嵌套。由于StateMachine类和State类都继承自抽象的事件处理类即Handler类,因此可以在State类中注入一个StateMachine类,这样可以灵活的组合各个Handler类,支持状态机的嵌套。可以使用装饰模式在State中保存一个指向StateMachine类的Handler指针,这样就达到了状态里面嵌套了另一个状态机,即方便的使用装饰模式来实现父子状态机的无限嵌套。传统有限状态机的控制方式中,支持状态的嵌套却不支持状态机的嵌套,还需要在父状态维护子状态的切换,使得状态和状态机的边界不清晰,概念上有些混淆。而本实施例中,对外界来说可以只使用一个Handler类的指针,而不用关心具体的处理类,方便进行代码扩展,修改状态工厂类中的部分代码,并不会影响到Handler的使用者。由于StateMachine和State都继承自Hander,可以灵活的组合StateMachine和State的关系,来实现父子状态的组合和子状态的状态跳转。In one embodiment, the event processing class is a Handler class, which is a computer term, a Java subclass and an inherited interface. Handler class can include subclasses StateMachine class and State class, both StateMachine class and State class inherit from Handler class. A Handler pointer to the StateMachine class is saved in the State class, and the Handler pointer is used to implement the nesting of parent-child state machines. Since both the StateMachine class and the State class inherit from the abstract event processing class, that is, the Handler class, a StateMachine class can be injected into the State class, which can flexibly combine each Handler class and support the nesting of state machines. You can use the decoration mode to save a Handler pointer to the StateMachine class in the State, so that another state machine is nested in the state, that is, it is convenient to use the decoration mode to realize the infinite nesting of the parent-child state machine. In the traditional finite state machine control method, the nesting of states is supported but the nesting of state machines is not supported. It is also necessary to maintain the switching of child states in the parent state, which makes the boundary between the state and the state machine unclear, and the concept is somewhat confusing. In this embodiment, the outside world can only use a pointer of a Handler class without caring about the specific processing class, which is convenient for code expansion and modification of some codes in the state factory class, and will not affect the users of the Handler. . Since both StateMachine and State inherit from Hander, the relationship between StateMachine and State can be flexibly combined to realize the combination of parent-child state and the state jump of child state.
应该理解的是,虽然图1-6的流程图中的各个步骤按照箭头的指示依次显示,但是这些步骤并不是必然按照箭头指示的顺序依次执行。除非本文中有明确的说明,这些步骤的执行并没有严格的顺序限制,这些步骤可以以其它的顺序执行。而且,图1-6中的至少一部分步骤可以包括多个步骤或者多个阶段,这些步骤或者阶段并不必然是在同一时刻执行完成,而是可以在不同的时刻执行,这些步骤或者阶段的执行顺序也不必然是依次进行,而是可以与其它步骤或者 其它步骤中的步骤或者阶段的至少一部分轮流或者交替地执行。It should be understood that although the steps in the flowcharts of FIGS. 1-6 are shown in sequence according to the arrows, these steps are not necessarily executed in the sequence shown by the arrows. Unless explicitly stated herein, the execution of these steps is not strictly limited to the order, and these steps may be performed in other orders. Moreover, at least a part of the steps in FIGS. 1-6 may include multiple steps or multiple stages. These steps or stages are not necessarily executed at the same time, but may be executed at different times. The execution of these steps or stages The order is also not necessarily sequential, but may be performed alternately or alternately with other steps or at least a portion of the steps or phases within the other steps.
在其中一个实施例中,如图7所示,提供了一种有限状态机的控制装置,包括:接收模块702、转换模块704、调用模块706、处理模块708和确定模块710,其中:In one of the embodiments, as shown in FIG. 7, a control apparatus for a finite state machine is provided, including: a receiving module 702, a converting module 704, a calling module 706, a processing module 708 and a determining module 710, wherein:
接收模块702,用于接收控制信号,控制信号中携带信令信息。The receiving module 702 is configured to receive a control signal, where the control signal carries signaling information.
转换模块704,用于根据信令信息,将控制信号转换为事件。The conversion module 704 is configured to convert the control signal into an event according to the signaling information.
调用模块706,用于调用事件处理类对事件进行处理,其中,事件处理类包括状态机类和状态类,状态机类用于实现状态跳转的逻辑,状态类用于完成具体业务逻辑的处理。The calling module 706 is used to call the event processing class to process the event, wherein the event processing class includes a state machine class and a state class, the state machine class is used to implement the logic of state jumping, and the state class is used to complete the processing of specific business logic .
处理模块708,用于在对事件进行处理时,若状态机类根据当前状态,判定接受处理事件,则对事件进行对应的业务逻辑处理,返回对应的处理状态。The processing module 708 is configured to, when processing the event, if the state machine class determines to accept the processing event according to the current state, perform corresponding business logic processing on the event, and return the corresponding processing state.
确定模块710,用于根据处理状态,确定下一个状态对应的处理方式。The determining module 710 is configured to determine the processing mode corresponding to the next state according to the processing state.
在其中一个实施例中,调用模块还用于调用当前状态的HandEvent函数,对事件进行对应的业务逻辑处理,并返回对应的处理状态,其中,处理状态是每个状态对事件进行处理后返回对应的状态码,状态码是HandEvent函数的返回值。In one embodiment, the calling module is further configured to call the HandEvent function of the current state, perform corresponding business logic processing on the event, and return the corresponding processing state, wherein the processing state is that each state processes the event and returns the corresponding processing state. The status code, the status code is the return value of the HandEvent function.
在其中一个实施例中,该装置还包括:跳转模块和获取模块。In one of the embodiments, the apparatus further includes: a jumping module and an obtaining module.
跳转模块用于当返回的处理状态为处理完毕时,则跳转至下一个状态对事件进行处理。调用模块还用于当返回的处理状态为继续处理时,则不进行状态跳转,调用当前状态的HandEvent函数,继续对事件进行处理。获取模块用于当返回的处理状态为不接受处理时,则获取当前状态对应的处理策略。The jump module is used to jump to the next state to process the event when the returned processing state is completed. The calling module is also used to call the HandEvent function of the current state and continue to process the event when the returned processing state is to continue processing without performing state jump. The obtaining module is used to obtain the processing strategy corresponding to the current state when the returned processing status is not accepting processing.
在其中一个实施例中,调用模块还用于调用GetStrategy函数获取当前状态对应的处理策略,处理策略包括忽略事件、替换事件和回滚事件。处理模块还用于当GetStrategy函数返回的处理策略为忽略事件时,则忽略事件;当GetStrategy函数返回的处理策略为替换事件时,则根据事件,创建一个新状态替换当前状态,对事件进行处理;当GetStrategy函数返回的处理策略为回滚事件时,则恢复至上一个状态来处理事件。In one embodiment, the calling module is further configured to call the GetStrategy function to obtain a processing strategy corresponding to the current state, and the processing strategy includes an ignore event, a replacement event, and a rollback event. The processing module is also used to ignore the event when the processing strategy returned by the GetStrategy function is to ignore the event; when the processing strategy returned by the GetStrategy function is to replace the event, create a new state to replace the current state and process the event according to the event; When the processing strategy returned by the GetStrategy function is a rollback event, it returns to the previous state to process the event.
在其中一个实施例中,调用模块还用于当GetStrategy函数返回的处理策略为替换事件时,调用状态工厂类,根据事件的事件类型和事件标识,利用CreateState函数创建对应的新状态。处理模块还用于将当前状态替换为新状态,利用新状态对事件进行处理。In one embodiment, the calling module is further configured to call the state factory class when the processing strategy returned by the GetStrategy function is a replacement event, and use the CreateState function to create a corresponding new state according to the event type and event identifier of the event. The processing module is also used to replace the current state with a new state, and use the new state to process events.
在其中一个实施例中,处理模块还用于在对事件进行处理时,若状态机类根据当前状态,判定不接受处理事件时,则返回状态为不接受处理。获取模块还用于获取当前状态对应的处理策略,根据处理策略,对事件进行处理,返回对应的处理状态。In one embodiment, the processing module is further configured to, when processing the event, if the state machine class determines, according to the current state, that the event is not accepted for processing, the return state is that the processing is not accepted. The acquiring module is also used to acquire the processing strategy corresponding to the current state, process the event according to the processing strategy, and return the corresponding processing state.
在其中一个实施例中,该装置还包括:保存模块。In one of the embodiments, the apparatus further includes: a saving module.
保存模块用于在State类中保存一个指向StateMachine类的Handler指针,Handler指针用于实现父子状态机的嵌套。The saving module is used to save a Handler pointer to the StateMachine class in the State class, and the Handler pointer is used to implement the nesting of parent-child state machines.
关于有限状态机的控制装置的具体限定可以参见上文中对于有限状态机的控制方法的限定,在此不再赘述。上述有限状态机的控制装置中的各个模块可全部或部分通过软件、硬件及其组合来实现。上述各模块可以硬件形式内嵌于或独立于计算机设备中的处理器中,也可以以软件形式存储于计算机设备中的存储器中,以便于处理器调用执行以上各个模块对应的操作。For the specific limitation of the control device of the finite state machine, reference may be made to the limitation of the control method of the finite state machine above, which will not be repeated here. Each module in the control device of the above-mentioned finite state machine can be implemented in whole or in part by software, hardware and combinations thereof. The above modules can be embedded in or independent of the processor in the computer device in the form of hardware, or stored in the memory in the computer device in the form of software, so that the processor can call and execute the operations corresponding to the above modules.
在其中一个实施例中,提供了一种计算机设备,该计算机设备可以是终端,其内部结构图可以如图8所示。该计算机设备包括通过系统总线连接的处理器、存储器、通信接口、显示屏和输入装置。其中,该计算机设备的处理器用于提供计算和控制能力。该计算机设备的存储器包括非易失性存储介质、内存储器。该非易失性存储介质存储有操作系统和计算机程序。该内存储器为非易失性存储介质中的操作系统和计算机程序的运行提供环境。该计算机设备的通信接口用于与外部的终端进行有线或无线方式的通信,无线方式可通过WIFI、运营商网络、NFC(近场通信)或其他技术实现。该计算机程序被处理器执行时以实现一种有限状态机的控制方法。该计算机设备的显示屏可以是液晶显示屏或者电子墨水显示屏,该计算机设备的输入装置可以是显示屏上覆盖的触摸层,也可以是计算机设备外壳上设置的按键、轨迹球或触控板,还可以是外接的键盘、触控板或鼠标等。In one of the embodiments, a computer device is provided, and the computer device may be a terminal, and the internal structure diagram thereof may be as shown in FIG. 8 . The computer equipment includes a processor, memory, a communication interface, a display screen, and an input device connected by a system bus. Among them, the processor of the computer device is used to provide computing and control capabilities. The memory of the computer device includes a non-volatile storage medium, an internal memory. The nonvolatile storage medium stores an operating system and a computer program. The internal memory provides an environment for the execution of the operating system and computer programs in the non-volatile storage medium. The communication interface of the computer device is used for wired or wireless communication with an external terminal, and the wireless communication can be realized by WIFI, operator network, NFC (Near Field Communication) or other technologies. The computer program implements a control method of a finite state machine when executed by a processor. The display screen of the computer equipment may be a liquid crystal display screen or an electronic ink display screen, and the input device of the computer equipment may be a touch layer covered on the display screen, or a button, a trackball or a touchpad set on the shell of the computer equipment , or an external keyboard, trackpad, or mouse.
本领域技术人员可以理解,图8中示出的结构,仅仅是与本申请方案相关的部分结构的框图,并不构成对本申请方案所应用于其上的计算机设备的限定,具体的计算机设备可以包括比图中所示更多或更少的部件,或者组合某些部件,或者具有不同的部件布置。Those skilled in the art can understand that the structure shown in FIG. 8 is only a block diagram of a part of the structure related to the solution of the present application, and does not constitute a limitation on the computer equipment to which the solution of the present application is applied. Include more or fewer components than shown in the figures, or combine certain components, or have a different arrangement of components.
一种计算机设备,包括存储器和一个或多个处理器,存储器中储存有计算机可读指令,一个或多个存储有计算机可读指令的非易失性存储介质,计算机可读指令被一个或多个处理器执行时,使得一个或多个处理器实现本申请任意一个实施例中提供的有限状态机的控制方法的步骤。A computer device including a memory and one or more processors, the memory having computer-readable instructions stored in the memory, and one or more non-volatile storage media storing the computer-readable instructions, the computer-readable instructions being stored by one or more non-volatile storage media When executed by each processor, one or more processors are made to implement the steps of the finite state machine control method provided in any one of the embodiments of this application.
本领域普通技术人员可以理解实现上述实施例方法中的全部或部分流程,是可以通过计算机可读指令来指令相关的硬件来完成,所述的计算机可读指令可存储于一非易失性计算机可读取存储介质中,该计算机可读指令在执行时,可包括如上述各方法的实施例的流程。其中,本申请所提供的各实施例中所使用的对存储器、存储、数据库或其它介质的任何引用,均可包括非易失性和易失性存储器中的至少一种。非易失性存储器可包括只读存储器(Read-Only Memory,ROM)、磁带、软盘、闪存或光存储器等。易失性存储器可包括随机存取存储器(Random Access Memory,RAM)或外部高速缓冲存储器。作为说明而非局限,RAM可以是多种形式,比如静态随机存取存储器(Static Random Access Memory,SRAM)或动态随机存取存储器(Dynamic Random Access Memory,DRAM)等。Those of ordinary skill in the art can understand that all or part of the processes in the methods of the above embodiments can be implemented by instructing the relevant hardware through computer-readable instructions, and the computer-readable instructions can be stored in a non-volatile computer. In the readable storage medium, the computer-readable instructions, when executed, may include the processes of the foregoing method embodiments. Wherein, any reference to memory, storage, database or other media used in the various embodiments provided in this application may include at least one of non-volatile and volatile memory. Non-volatile memory may include read-only memory (Read-Only Memory, ROM), magnetic tape, floppy disk, flash memory, or optical memory, and the like. Volatile memory may include random access memory (RAM) or external cache memory. By way of illustration and not limitation, the RAM may be in various forms, such as Static Random Access Memory (SRAM) or Dynamic Random Access Memory (DRAM).
以上实施例的各技术特征可以进行任意的组合,为使描述简洁,未对上述实施例中的各个技术特征所有可能的组合都进行描述,然而,只要这些技术特征的组合不存在矛盾,都应当认为是本说明书记载的范围。The technical features of the above embodiments can be combined arbitrarily. For the sake of brevity, all possible combinations of the technical features in the above embodiments are not described. However, as long as there is no contradiction in the combination of these technical features, all It is considered to be the range described in this specification.
以上所述实施例仅表达了本申请的几种实施方式,其描述较为具体和详细,但并不能因此而理解为对发明专利范围的限制。应当指出的是,对于本领域的普通技术人员来说,在不脱离本申请构思的前提下,还可以做出若干变形和改进,这些都属于本申请的保护范围。因此,本申请专利的保护范围 应以所附权利要求为准。The above-mentioned embodiments only represent several embodiments of the present application, and the descriptions thereof are relatively specific and detailed, but should not be construed as a limitation on the scope of the invention patent. It should be pointed out that for those skilled in the art, without departing from the concept of the present application, several modifications and improvements can be made, which all belong to the protection scope of the present application. Therefore, the scope of protection of the patent of the present application should be determined by the appended claims.

Claims (16)

  1. 一种有限状态机的控制方法,包括:A control method for 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 includes a state machine class and state class; the state machine class is used to implement the logic of state jumping; the state class is used to complete the processing of specific business logic; when processing the event, if the state machine class according to the current state, If it is determined that the event is accepted to be processed, corresponding business logic processing is performed on the event, and a corresponding processing state is returned; and a processing mode corresponding to the next state is determined according to the processing state.
  2. 根据权利要求1所述的方法,其中,所述对所述事件进行对应的业务逻辑处理,返回对应的处理状态,包括:The method according to claim 1, wherein, performing corresponding business logic processing on the event and returning a corresponding processing status, comprising:
    调用所述当前状态的HandEvent函数,对所述事件进行对应的业务逻辑处理,并返回对应的处理状态;其中,所述处理状态是每个状态对所述事件进行处理后返回对应的状态码,所述状态码是所述HandEvent函数的返回值。Call the HandEvent function of the current state, perform corresponding business logic processing on the event, and return the corresponding processing status; wherein, the processing status is that each status returns the corresponding status code after processing the event, The status code is the return value of the HandEvent function.
  3. 根据权利要求1所述的方法,其中,所述处理状态包括处理完毕、继续处理和不接受处理,所述根据所述处理状态,确定下一个状态对应的处理方式,包括:The method according to claim 1, wherein the processing status includes processing completed, continuing processing and not accepting processing, and determining a processing mode corresponding to the next status according to the processing status, comprising:
    当返回的所述处理状态为处理完毕时,则跳转至下一个状态对所述事件进行处理;当返回的所述处理状态为继续处理时,则不进行状态跳转,调用所述当前状态的HandEvent函数,继续对所述事件进行处理;及当返回的所述处理状态为不接受处理时,则获取所述当前状态对应的处理策略。When the returned processing state is that the processing is completed, then jump to the next state to process the event; when the returned processing state is to continue processing, no state jump is performed, and the current state is called. The HandEvent function continues to process the event; and when the returned processing status is not accepting processing, the processing strategy corresponding to the current status is obtained.
  4. 根据权利要求3所述的方法,其中,所述获取所述当前状态对应的处理策略,包括:The method according to claim 3, wherein the acquiring the processing strategy corresponding to the current state comprises:
    调用GetStrategy函数获取所述当前状态对应的处理策略;所述处理策略包括忽略事件、替换事件和回滚事件;当所述GetStrategy函数返回的处理策略为忽略事件时,则忽略所述事件;当所述GetStrategy函数返回的处理策略为替换事件时,则根据所述事件,创建一个新状态替换所述当前状态,对所述事件进行处理;及当所述GetStrategy函数返回的处理策略为回滚事件时,则恢复至上 一个状态来处理所述事件。Call the GetStrategy function to obtain the processing strategy corresponding to the current state; the processing strategy includes an ignore event, a replacement event and a rollback event; when the processing strategy returned by the GetStrategy function is to ignore the event, then ignore the event; When the processing strategy returned by the GetStrategy function is a replacement event, then according to the event, a new state is created to replace the current state, and the event is processed; and when the processing strategy returned by the GetStrategy function is a rollback event , then revert to the previous state to process the event.
  5. 根据权利要求4所述的方法,其中,所述当所述GetStrategy函数返回的处理策略为替换事件时,则根据所述事件,创建一个新状态替换所述当前状态,对所述事件进行处理,包括:The method according to claim 4, wherein, 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, include:
    当所述GetStrategy函数返回的处理策略为替换事件时,调用状态工厂类,根据所述事件的事件类型和事件标识,利用CreateState函数创建对应的新状态;及将所述当前状态替换为所述新状态,利用所述新状态对所述事件进行处理。When the processing strategy returned by the GetStrategy function is a replacement event, call the state factory class, and use the CreateState function to create a corresponding new state according to the event type and event identifier of the event; and replace the current state with the new state state, the event is processed with the new state.
  6. 根据权利要求1所述的方法,其中,所述方法还包括:The method of claim 1, wherein the method further comprises:
    在对所述事件进行处理时,若状态机类根据当前状态,判定不接受处理所述事件时,则返回状态为不接受处理;获取所述当前状态对应的处理策略;及根据所述处理策略,对所述事件进行处理,返回对应的处理状态。When processing the event, if the state machine class determines not to accept the processing of the event according to the current state, the return state is not to accept the processing; obtain the processing strategy corresponding to the current state; and according to the processing strategy , process the event and return the corresponding processing status.
  7. 根据权利要求1所述的方法,其中,所述方法还包括:The method of claim 1, wherein the method further comprises:
    所述事件处理类为Handler类,所述Handler类包括子类StateMachine类和State类;所述StateMachine类和State类都继承自所述Handler类;及在State类中保存一个指向StateMachine类的Handler指针,所述Handler指针用于实现父子状态机的嵌套。Described event handling class is Handler class, described Handler class includes subclass StateMachine class and State class; Described StateMachine class and State class both inherit from described Handler class; And save a Handler pointer to StateMachine class in State class , the Handler pointer is used to implement the nesting of parent-child state machines.
  8. 一种有限状态机的控制装置,包括:A control device for a finite state machine, comprising:
    接收模块,用于接收控制信号;所述控制信号中携带信令信息;转换模块,用于根据所述信令信息,将所述控制信号转换为事件;调用模块,用于调用事件处理类对所述事件进行处理;其中,所述事件处理类包括状态机类和状态类;所述状态机类用于实现状态跳转的逻辑;所述状态类用于完成具体业务逻辑的处理;处理模块,用于在对所述事件进行处理时,若状态机类根据当前状态,判定接受处理所述事件,则对所述事件进行对应的业务逻辑处理,返回对应的处理状态;及确定模块,用于根据所述处理状态,确定下一个状态对应的处理方式。a receiving module for receiving a control signal; the control signal carries signaling information; a conversion module for converting the control signal into an event according to the signaling information; a calling module for calling an event processing class pair The event is processed; wherein, the event processing class includes a state machine class and a state class; the state machine class is used to implement the logic of state jumping; the state class is used to complete the processing of specific business logic; processing module , used to process the event, if the state machine class decides to accept and process the event according to the current state, perform corresponding business logic processing on the event, and return the corresponding processing state; and determine the module, use According to the processing state, the processing mode corresponding to the next state is determined.
  9. 根据权利要求8的有限状态机的控制装置,其中,所述装置还包括:The control device for a finite state machine according to claim 8, wherein the device further comprises:
    所述调用模块还用于调用所述当前状态的HandEvent函数,对所述事件进行对应的业务逻辑处理,并返回对应的处理状态;其中,所述处理状态是每个 状态对所述事件进行处理后返回对应的状态码,所述状态码是所述HandEvent函数的返回值。The calling module is also used to call the HandEvent function of the current state, perform corresponding business logic processing on the event, and return the corresponding processing state; wherein, the processing state is that each state processes the event Then, the corresponding status code is returned, and the status code is the return value of the HandEvent function.
  10. 根据权利要求8的有限状态机的控制装置,其中,所述装置还包括:The control device for a finite state machine according to claim 8, wherein the device further comprises:
    跳转模块,用于当返回的所述处理状态为处理完毕时,则跳转至下一个状态对所述事件进行处理;所述调用模块还用于当返回的所述处理状态为继续处理时,则不进行状态跳转,调用所述当前状态的HandEvent函数,继续对所述事件进行处理;及获取模块,用于当返回的所述处理状态为不接受处理时,则获取所述当前状态对应的处理策略。The jumping module is used to jump to the next state to process the event when the returned processing state is completed; the calling module is also used to continue processing when the returned processing state is , then no state jump is performed, the HandEvent function of the current state is called, and the event is continued to be processed; and an acquisition module is used to acquire the current state when the returned processing state is not to accept processing corresponding processing strategy.
  11. 根据权利要求10的有限状态机的控制装置,其中,所述装置还包括:The control apparatus for a finite state machine according to claim 10, wherein the apparatus further comprises:
    所述调用模块还用于调用GetStrategy函数获取所述当前状态对应的处理策略;所述处理策略包括忽略事件、替换事件和回滚事件;返回模块,用于当所述GetStrategy函数返回的处理策略为忽略事件时,则忽略所述事件;创建模块,用于当所述GetStrategy函数返回的处理策略为替换事件时,则根据所述事件,创建一个新状态替换所述当前状态,对所述事件进行处理;及恢复模块,用于当所述GetStrategy函数返回的处理策略为回滚事件时,则恢复至上一个状态来处理所述事件。The calling module is also used to call the GetStrategy function to obtain the processing strategy corresponding to the current state; the processing strategy includes an ignore event, a replacement event and a rollback event; a return module is used when the processing strategy returned by the GetStrategy function is: When the event is ignored, the event is ignored; the creation module is used to create a new state to replace the current state according to the event when the processing strategy returned by the GetStrategy function is a replacement event, and perform the operation on the event. processing; and a recovery module, configured to restore to the previous state to process the event when the processing strategy returned by the GetStrategy function is a rollback event.
  12. 根据权利要求11的有限状态机的控制装置,其中,所述装置还包括:The control apparatus for a finite state machine according to claim 11, wherein the apparatus further comprises:
    所述调用模块还用于当所述GetStrategy函数返回的处理策略为替换事件时,调用状态工厂类,根据所述事件的事件类型和事件标识,利用CreateState函数创建对应的新状态;及替换模块,用于将所述当前状态替换为所述新状态,利用所述新状态对所述事件进行处理。The calling module is also used to call the state factory class when the processing strategy returned by the GetStrategy function is a replacement event, and use the CreateState function to create a corresponding new state according to the event type and event identifier of the event; and the replacement module, It is used to replace the current state with the new state, and use the new state to process the event.
  13. 根据权利要求8的有限状态机的控制装置,其中,所述装置还包括:The control device for a finite state machine according to claim 8, wherein the device further comprises:
    判定模块,用于在对所述事件进行处理时,若状态机类根据当前状态,判定不接受处理所述事件时,则返回状态为不接受处理;所述获取模块还用于获取所述当前状态对应的处理策略;及所述处理模块还用于根据所述处理策略,对所述事件进行处理,返回对应的处理状态。The determining module is used to, when processing the event, if the state machine class determines that the event is not accepted for processing according to the current state, the return state is that the processing is not accepted; the obtaining module is further configured to obtain the current state processing strategy corresponding to the state; and the processing module is further configured to process the event according to the processing strategy, and return the corresponding processing state.
  14. 根据权利要求8的有限状态机的控制装置,其中,所述装置还包括:The control device for a finite state machine according to claim 8, wherein the device further comprises:
    保存模块,用于在State类中保存一个指向StateMachine类的Handler指针, 所述Handler指针用于实现父子状态机的嵌套。The saving module is used to save a Handler pointer to the StateMachine class in the State class, where the Handler pointer is used to implement the nesting of the parent-child state machine.
  15. 一种计算机设备,包括存储器及一个或多个处理器,所述存储器中储存有计算机可读指令,所述计算机可读指令被所述一个或多个处理器执行时,使得所述一个或多个处理器执行权利要求1至7中任一项所述方法的步骤。A computer device comprising a memory and one or more processors, the memory having computer-readable instructions stored in the memory that, when executed by the one or more processors, cause the one or more processors to A processor performs the steps of the method of any one of claims 1 to 7.
  16. 一个或多个存储有计算机可读指令的计算机存储介质,所述计算机可读指令被一个或多个处理器执行时,使得所述一个或多个处理器执行权利要求1至7中任一项所述方法的步骤。One or more computer storage media storing computer readable instructions which, when executed by one or more processors, cause the one or more processors to perform any one of claims 1 to 7 the steps of the method.
PCT/CN2020/139828 2020-12-28 2020-12-28 Method and apparatus for controlling finite state machine, computer device, and storage medium WO2022140880A1 (en)

Priority Applications (2)

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
CN202080103184.8A CN115885253A (en) 2020-12-28 2020-12-28 Control method and device of finite state machine, computer equipment and storage medium

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
WO2022140880A1 true WO2022140880A1 (en) 2022-07-07

Family

ID=82258620

Family Applications (1)

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

Country Status (2)

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

Citations (4)

* Cited by examiner, † Cited by third party
Publication number Priority date Publication date Assignee Title
CN101957751A (en) * 2010-06-04 2011-01-26 福建星网锐捷网络有限公司 Method and device for realizing state machine
CN105656688A (en) * 2016-03-03 2016-06-08 腾讯科技(深圳)有限公司 State 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

Family Cites Families (3)

* Cited by examiner, † Cited by third party
Publication number Priority date Publication date Assignee Title
CN104239013B (en) * 2013-06-17 2018-11-30 上海联影医疗科技有限公司 Distributing state machine and its processing method based on commission
EP3671442A1 (en) * 2018-12-17 2020-06-24 Physik Instrumente (PI) GmbH & Co. Kg System and method for switching operating states of physical devices
CN113326083A (en) * 2021-05-28 2021-08-31 阿波罗智联(北京)科技有限公司 State machine processing method, state processing device, electronic equipment and storage medium

Patent Citations (4)

* Cited by examiner, † Cited by third party
Publication number Priority date Publication date Assignee Title
CN101957751A (en) * 2010-06-04 2011-01-26 福建星网锐捷网络有限公司 Method and device for realizing state machine
CN105656688A (en) * 2016-03-03 2016-06-08 腾讯科技(深圳)有限公司 State 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
CN115885253A (en) 2023-03-31

Similar Documents

Publication Publication Date Title
KR101903805B1 (en) Method for checkpointing and restoring program state
US9600411B2 (en) System and method for determining an object's lifetime in an object oriented environment
CN108763060A (en) Native layers of collapse source tracing method, device, storage medium and terminal in android system
CN108958729B (en) Data processing method, device and storage medium
CN102236621A (en) Computer interface information configuration system and method
JP6379654B2 (en) Process execution program, process execution method, and information processing apparatus
CN110750315B (en) Class loading method, device, equipment and storage medium in Android system
CN102567097A (en) Method and terminal for downloading multiple tasks
CN110362363A (en) A method of model realization controls terminal applies when based on operation
CN112506854A (en) Method, device, equipment and medium for storing page template file and generating page
CN102375759B (en) Utilize the method that finite state machine prevents code rewriting
US11748108B2 (en) Instruction executing method and apparatus, electronic device, and computer-readable storage medium
WO2022140880A1 (en) Method and apparatus for controlling finite state machine, computer device, and storage medium
US20140250251A1 (en) Automatically and transparently preserving testing state across sessions
CN110018831B (en) Program processing method, program processing apparatus, and computer-readable storage medium
CN111858339A (en) Memory analysis method, device and system, computing device and computer-readable storage medium
CN111352644A (en) Applet updating method, device, server and storage medium
US9448818B2 (en) Defining classes as singleton classes or non-singleton classes
Dantas et al. Towards aspect-oriented programming for context-aware systems: A comparative study
CN110096315B (en) Component loading method and device
Hong et al. Senos: state-driven operating system architecture for dynamic sensor node reconfigurability
CN114879962B (en) Method and device for realizing batch system call
US11487564B1 (en) Terminal shell switching
CN102375740A (en) Handheld device and method for implementing interoperation of Java component and custom member by same
WO2023219692A1 (en) Externally-initiated runtime type extension

Legal Events

Date Code Title Description
121 Ep: the epo has been informed by wipo that ep was designated in this application

Ref document number: 20967233

Country of ref document: EP

Kind code of ref document: A1

NENP Non-entry into the national phase

Ref country code: DE

32PN Ep: public notification in the ep bulletin as address of the adressee cannot be established

Free format text: NOTING OF LOSS OF RIGHTS PURSUANT TO RULE 112(1) EPC (EPO FORM 1205A DATED 141123)