Hierarchical_State_Machine Class Reference

 #include <Hierarchical_State_Machine.h>

Collaboration diagram for Hierarchical_State_Machine:

[legend]
List of all members.


Detailed Description

This is an example of state machine implementation using Hierarchical State Machines.

For details refer to the article on Hierarchical State Machines

In conventional state machine design, all states are considered at the same level. The design does not capture the commonality that exists among states. In real life, many states handle most messages in similar fashion and differ only in handling of few
key messages. Even when the actual handling differs, there is still some commonality. Hierarchical state machine design captures the commonality by organizing the states as a hierarchy. The states at the higher level in hierarchy perform the common message
handling, while the lower level states inherit the commonality from higher level ones and perform the state specific functions. This examples explores hierarchichal state machines using an example of a hardware unit that can be in the following states:

Definition at line 32 of file Hierarchical_State_Machine.h.

 

Public Member Functions

void  On_Message (const Message *p_Message)
  Receive methods and invoke the handler for the currently active state.


Private Member Functions

void  Next_State (Unit_State
&r_State)
  This private method changes the state for the state machine.


Private Attributes

Unit_State p_Current_State
  Pointer to the current state.

Static Private Attributes

Active  Active_State
  Static declaration of Active state. Static declarations share the same states across multiple instances.
Standby  Standby_State
  Static declaration of Standby state.
Suspect  Suspect_State
  Static declaration of Suspect state.
Failed  Failed_State
  Static declaration of Failed State.

Member Function Documentation

void Hierarchical_State_Machine::Next_State Unit_State r_State  )  [private]
 
This private method changes the state for the state machine.

The p_Current_State variable is updated with the new state

Parameters:
r_State  Reference to the desired next state

Definition at line 169 of file Hierarchical_State_Machine.h.

00170 {
00171     p_Current_State = &r_State;
00172 }

void Hierarchical_State_Machine::On_Message const Message *  p_Message  )   
 
Receive methods and invoke the handler for the currently active state.

Note that p_Current_State has already been set to the current state.

Parameters:
p_Message  Pointer to the message being processed.

Definition at line 17 of file Hierarchical_State_Machine.cpp.

00018 {
00019     switch (p_Message->GetType())
00020     {
00021     case Message::FAULT_TRIGGER:
00022         p_Current_State->On_Fault_Trigger(*this, p_Message);
00023         break;
00024
00025     case Message::SWITCHOVER:
00026         p_Current_State->On_Switchover(*this, p_Message);
00027         break;
00028
00029     case Message::DIAGNOSTICS_PASSED:
00030         p_Current_State->On_Diagnostics_Passed(*this, p_Message);
00031         break;
00032
00033     case Message::DIAGNOSTICS_FAILED:
00034         p_Current_State->On_Diagnostics_Failed(*this, p_Message);
00035         break;
00036
00037     case Message::OPERATOR_INSERVICE:
00038         p_Current_State->On_Operator_Inservice(*this, p_Message);
00039         break;
00040
00041     default:
00042         assert(false);
00043         break;
00044     }
00045 }

时间: 2024-08-04 06:48:24

Hierarchical_State_Machine Class Reference的相关文章

Custom tool error: Failed to generate code for the service reference &amp;#215;&amp;#215;&amp;#215;&amp;#215;&amp;#215;&amp;#215;. Please check other erro

开发工具:VS2010 问题描述: 在ProjectName.Web中创建的WebService服务,然后在项目中添加Add Service Reference,然后就报"Custom tool error: Failed togenerate code for the service reference ××××××. Please check other error andwarning messages for details. "这样的错误  新建.调用WebService 解

ios-传递作为reference的GLInt

问题描述 传递作为reference的GLInt 代码如下: glGenFramebuffers(1, &_defaultFramebuffer); 但是运行之后报警: Passing 'GLint *' (aka 'int *') to parameter of type 'GLuint *' (aka 'unsigned int *') converts between pointers to integer types with different sign 应该怎么解决?

reference counting:PHP源码分析-变量的引用计数、写时复制(Reference counting &amp;amp; Copy-on-Write)

PHP语法中有两种赋值方式:引用赋值.非引用赋值.<?php$a = 1;$b = $a; // 非引用赋值$c = &$b; // 引用赋值从表面看,通常会这样认为:"引用赋值就是两个变量对应同一个变量(在C中其实就是一个zval),非引用赋值则是直接产生的一个新的变量(zval),同时将值copy过来".这种认为在大部分情况下都是可以想通的.(#1)但有些情况下则会显得非常低效,例如:(#2)<?phpfunction print_arr($arr){//非引用

Common ASP.NET Code Techniques (DPC&amp;dwc Reference)

Figure 2.1Output of Listing 2.1.1 when viewed through a browser. Adding Elements to an ArrayListIn Listing 2.1.1 we create two ArrayList class instances, aTerritories and aStates, on lines 5 and 6, respectively. We then populate the aStates ArrayList

Common ASP.NET Code Techniques (DPC&amp;amp;DWC Reference)--6

asp.net Figure 2.5Output of Listing 2.1.5 when viewed through a browser. If you've worked with classic ASP, you are likely familiar with the concept of session-level variables. These variables are defined on a per-user basis and last for the duration

Common ASP.NET Code Techniques (DPC&amp;amp;dwc Reference)--2

asp.net Figure 2.1Output of Listing 2.1.1 when viewed through a browser. Adding Elements to an ArrayListIn Listing 2.1.1 we create two ArrayList class instances, aTerritories and aStates, on lines 5 and 6, respectively. We then populate the aStates A

Linux下C编程:undefined reference to ‘pthread_create&#039;问题解决

undefined reference to 'pthread_create' undefined reference to 'pthread_join' 问题原因: pthread 库不是 Linux 系统默认的库,连接时需要使用静态库 libpthread.a,所以在使用pthread_create()创建线程,以及调用 pthread_atfork()函数建立fork处理程序时,需要链接该库. 问题解决: 在编译中要加 -lpthread参数 gcc thread.c -o thread

Java内存管理之软引用(Soft Reference)

软引用(Soft  Reference)的主要特点是具有较强的引用功能.只有当内存不够的时候才回收这类内 存,因此在内存足够的时候,他们通常不被回收.另外,这些引用对象还能保证在Java  抛出 OutOfMemory异常之前,被设置为null.他可以用于实现一些常用资源的缓存,实现Cache的功能,保证最大限 度的使用内存而不引起OutOfMemory异常. 下面是软引用的实现代码: import java.lang.ref.SoftReference; public class softRe

Assigning the return value of new by reference is deprecated in

PHP显示Deprecated: Assigning the return value of new by reference is deprecated in解决办法 昨晚用Spreadsheet_Excel_Reader导入EXCEL内容到数据库的时候,出现了以下提示: Deprecated: Assigning the return value of new by reference is deprecated in 定位到出错的那一行: [php] view plaincopyprint