Docsity

Finite State Machine Code Generation: A Flexible UML-Based Tool, Papers of Computer Science

Toggle sidebar
bg1
FINITE STATE MACHINE AUTOMATIC CODE GENERATION
Ljubica Lazareviæ, Dragan Miliæev
University of Belgrade,
Faculty of Electrical Engineering
Abstract: This paper describes completion of software tool
for finite state machine code generation. The main feature
of the tool is great flexibility in adapting the way of code
generation in accordance with customer’s needs. Project of
the tool is based on principles of the UML (The Unified
Modeling Language) modeling. The tool was used for code
generation of Signaling System No7 TCAP’s (Transaction
Capabilities Application Part) finite state machines.
Keywords: Automatic code generation, Finite state
machine, CASE tool, meta modeling.
1. INTRODUCTION
A wide application of FSM in telecommunication systems
created a need for implementation a software tool that is
capable of direct code generation in given programming
language, on the basis of the FSM’s specification on high
abstraction level (as it is representation of the FSM given on
Fig.1). The way of code generation must not be fixed
because it depends on many aspects, such as whether the
environment is distributed or not, programming language, as
well as customer’s needs. Because of all these, the main
feature of the implemented tool is its flexibility in defining
the way of code generation.
Start State
Idle Running
End State
State State
s1
s2
s3
transitions
s4
Figure 1
2. BASIC PRINCIPLES
The tool’s flexibility is represented by its ability to redefine
the way of code generation in short time and minimal
changes.
The process of object oriented modeling is performed by
tools which provide visual modeling by using certain
notations, as well as code generating based on the given
model. Notation fixing also includes restriction of set of its
abstractions. The elements of modeling that are used in this
paper are set upon the UML notation.
In order to create the tool with mentioned characteristics
we need to:
- Define abstractions of the domain that concern us
(StateMachine, State,…), as well as their relations, i.e. to
define meta model for given domain.
- Define their semantics ;
- Define their graphic representation;
- Define the way of code generating.
The tool which is used for extension of abstractions’ set
of the existing CASE tools, as well as for designing the new
tools for domain that concerns us, is called meta CASE tool.
The software tool, which is described in this paper, is
implemented by using meta CASE tool.
3. IMPLEMENTATION
First, it was necessary to build up the meta model of FSM.
For this purpose we used UML meta model of the FSM, but
the implemented meta model actually represents just one
part of it. The adopted meta model contains the minimal set
of abstractions of UML meta model, which enables the
implementation of FSM. Figure 2 shows the implemented
meta model.
All the abstractions inherit the ModelElement class that
is contained by meta tool. It is necessary for the abstraction
to inherit this class in order to be able to run implemented
mechanisms of the tool, such as code generation,
persistence, etc.
The next step in creating the software tool is the meta
model insertion in meta tool, which is implemented as
dialogue application. The initial dialogue contains many
options whose choice provides defining new abstractions,
attributes, methods, and associations with other abstractions,
etc. For each defined abstraction meta tool automatically
generates a function for that abstraction code generation. In
the body of that function, the user can define his code that
defines the look of the final code for given model of state
machine. Some parts of the code generator are shown below:
#ifndef _FMSCodeGen1_h
#define _FMSCodeGen1_h
#include "CppGen.h"
#include "File.h"
#include "Package.h"
#include "Class.h"
class StateMachine;
class State;
class Transition;
class Event;
void generateStateMachineCode(const StateMachine*s,
File& file, StepOfCG step);
void generateStateCode(const State* s, File& file,
StepOfCG step, Package* p, Class* baseStateClass,
Class* sm, const StateMachine* stM);
void generateTransitionCode(const Transition* t,
File& file, StepOfCG step, Class* state,const
StateMachine* s, Package* p);
void generateEventCode(const Event* e, File& file,
StepOfCG step, Class* state, const Transition*
t,const StateMachine* s, Package* p);
#endif
void generateStateMachineCode(const StateMachine*
s, File& file, StepOfCG step)
{
Package* p=Package::create(0,NO);
Class* stateMachine=Class::create(p,NO);
stateMachine->setName(s-> getName());
Class* baseState=Class::create(p,NO);
BaseState->setName(s->getName()+”BaseState”);
pf3

Partial preview of the text

Download Finite State Machine Code Generation: A Flexible UML-Based Tool and more Papers Computer Science in PDF only on Docsity!

FINITE STATE MACHINE AUTOMATIC CODE GENERATION

Ljubica Lazareviæ, Dragan Miliæev

University of Belgrade,

Faculty of Electrical Engineering

Abstract : This paper describes completion of software tool

for finite state machine code generation. The main feature

of the tool is great flexibility in adapting the way of code

generation in accordance with customer’s needs. Project of

the tool is based on principles of the UML (The Unified

Modeling Language) modeling. The tool was used for code

generation of Signaling System No7 TCAP’s (Transaction

Capabilities Application Part) finite state machines.

Keywords: Automatic code generation, Finite state

machine, CASE tool, meta modeling.

1. INTRODUCTION

A wide application of FSM in telecommunication systems

created a need for implementation a software tool that is

capable of direct code generation in given programming

language, on the basis of the FSM’s specification on high

abstraction level (as it is representation of the FSM given on

Fig.1). The way of code generation must not be fixed

because it depends on many aspects, such as whether the

environment is distributed or not, programming language, as

well as customer’s needs. Because of all these, the main

feature of the implemented tool is its flexibility in defining

the way of code generation.

Start State

Idle Running

End State

State State

s

s

s

transitions

s

Figure 1

2. BASIC PRINCIPLES

The tool’s flexibility is represented by its ability to redefine

the way of code generation in short time and minimal

changes.

The process of object oriented modeling is performed by

tools which provide visual modeling by using certain

notations, as well as code generating based on the given

model. Notation fixing also includes restriction of set of its

abstractions. The elements of modeling that are used in this

paper are set upon the UML notation.

In order to create the tool with mentioned characteristics

we need to:

  • Define abstractions of the domain that concern us

(StateMachine, State,…), as well as their relations, i.e. to

define meta model for given domain.

  • Define their semantics ;
  • Define their graphic representation;
  • Define the way of code generating.

The tool which is used for extension of abstractions’ set

of the existing CASE tools, as well as for designing the new

tools for domain that concerns us, is called meta CASE tool.

The software tool, which is described in this paper, is

implemented by using meta CASE tool.

3. IMPLEMENTATION

First, it was necessary to build up the meta model of FSM.

For this purpose we used UML meta model of the FSM, but

the implemented meta model actually represents just one

part of it. The adopted meta model contains the minimal set

of abstractions of UML meta model, which enables the

implementation of FSM. Figure 2 shows the implemented

meta model.

All the abstractions inherit the ModelElement class that

is contained by meta tool. It is necessary for the abstraction

to inherit this class in order to be able to run implemented

mechanisms of the tool, such as code generation,

persistence, etc.

The next step in creating the software tool is the meta

model insertion in meta tool, which is implemented as

dialogue application. The initial dialogue contains many

options whose choice provides defining new abstractions,

attributes, methods, and associations with other abstractions,

etc. For each defined abstraction meta tool automatically

generates a function for that abstraction code generation. In

the body of that function, the user can define his code that

defines the look of the final code for given model of state

machine. Some parts of the code generator are shown below:

#ifndef _FMSCodeGen1_h #define _FMSCodeGen1_h #include "CppGen.h" #include "File.h" #include "Package.h" #include "Class.h" class StateMachine; class State; class Transition; class Event;

void generateStateMachineCode(const StateMachine*s, File& file, StepOfCG step);

void generateStateCode(const State* s, File& file, StepOfCG step, Package* p, Class* baseStateClass, Class* sm, const StateMachine* stM);

void generateTransitionCode(const Transition* t, File& file, StepOfCG step, Class* state,const StateMachine* s, Package* p);

void generateEventCode(const Event* e, File& file, StepOfCG step, Class* state, const Transition* t,const StateMachine* s, Package* p); #endif

void generateStateMachineCode(const StateMachine* s, File& file, StepOfCG step) { Package* p=Package::create(0,NO); Class* stateMachine=Class::create(p,NO); stateMachine->setName(s-> getName());

Class* baseState=Class::create(p,NO); BaseState->setName(s->getName()+”BaseState”);

ForEach(ev, Event, s->hEvents, B) ForEach(sm, StateMachine, ev->myEvents, A) Methodsignals=Method::create(stateMachine,NO); signals->setName("accept"); signals->setVisibilityInType(Public); signals->setPolymorfic(0); signals->setBody("currentState->exit();\n currentState=currentState->accept(e);\n currentState->entry();"); Parameter inPar1=Parameter::create(signals,NO); inPar1->setParameterName("e"); inPar1->setParameterType(ev->getName()+""); inPar1->setKind(In); Parameter retPar2=Parameter::create(signals,NO); retPar2->setParameterType("void"); retPar2->setKind(Return); ... EndForEach(sm)

EndForEach(ev) ... p->generateCode(file,step); deleteFromModel(p);

};

As an illustration of the tool’s flexibility we implemented

state machine code for distributed and concurrent

environment. The changes that had to be made were

minimal and introduced in a very short time, after the first

version of the code generator was implemented.

ModelElement

State (^) Transition

1..11..1 +mySources Source +hSource 0..0..

1..1 +myTargets Target +hTargets0..*

Event 1..* 0..

+myTrigger 0..

+hEvents

1..* Trigger

StateMachine

+myStates 0..*

+hStates

1..

States

1..1 +myTransitions 0..*

1..1+hTransitions

Transitions

0..*

1..1 +myEvents

1..1 +hEvents Events

Figure 2

Concurrency is one of the characteristics that

telecommunication software systems as real-time systems

often contain. This means that typically there are more

activities that have to be run at the same time. The main

problem of concurrent environment is the process

synchronization problem, which can be solved by using a

certain type of synchronization elements, such as

semaphore. So, if we want a FSM to run in concurrent

environment, we have to provide all its operations,

representing the events that trigger that FSM, exclusive.

Some parts of the code generator are shown below:

void generateStateMachineCode(const StateMachine* s, File& file, StepOfCG step) { Boolean sm=(Boolean)(s->isConcurrent); if(sm) { Attribute* a4=Attribute::create(stateMachine,NO); a4->setName("sem"); a4->setVisibilityInType(Private); a4->setAttributeType("Semaphore"); }; ... Each(ev, Event, s->hEvents, B) ForEach(sm, StateMachine, ev->myEvents, A) Method signals=Method::create(stateMachine,NO); signals->setName("accept"); signals->setVisibilityInType(Public); signals->setPolymorfic(0); if(sm->isConcurrent) signals->setBody("Mutex dummy(&sem);\ncurrentState->exit();\n currentState=currentState->accept(e);\n currentState->entry();"); else signals->setBody("currentState->exit();\n currentState=currentState->accept(e);\n currentState->entry();");

Parameter* inPar1=Parameter::create(signals,NO); inPar1->setParameterName("e"); inPar1->setParameterType(ev->getName()+""); inPar1->setKind(In); Parameter retPar2=Parameter::create(signals,NO); retPar2->setParameterType("void"); retPar2->setKind(Return); ... EndForEach(sm) EndForEach(ev) ... p->generateCode(file,step); deleteFromModel(p); };

Distribution is also very frequent characteristic of the

real-time systems. These systems are typically multi-

processors systems based on messages exchange

communication. In order to provide the transparency of

an FSM object to distributed environment, we represented

the abstraction with two separated classes. One of them

represents the interface of the FSM and it contains only

its public operations, which represent the events that

trigger FSM. These operations just transform events into

messages and then send them to the implementation part

of the FSM for processing. The other class contains the

implementation of the FSM abstraction. It defines all the

actions, transitions and states of the FSM. Some parts of

the code generator are shown below:

void generateStateMachineCode(const StateMachine* sm, File& file, StepOfCG step) { Package* p=Package::create(0,NO); Class* stateMachine=Class::create(p,NO); stateMachine->setName(sm->getName());