The .sm listing below is a skeleton with no states or transitions defined. It contains only the following features:
-
A verbatim code section which is copied verbatim
into the generated source code file. In this case the
verbatim code is the boilerplate copyright comments.
This section is delimited by the
%{ %}
pair. -
The
%class
keyword which specifies the application class to which this FSM is associated:Task
. -
The
%package
keyword which specifies to which class package this FSM belongs. This is the same package as theTask
class. -
The
%fsmclass
keyword specifies the generated finite state machine class name. If%fsmclass
is not specified, then the finite state machine class name would default toTaskContext
. This keyword is not required. -
The
%fsmfile
keyword specifies the generated finite state machine class file name. The appropriate suffix for the given programming language is appended to this file name to form the complete file name. This suffix may be changed from its default using the-suffix
and-hsuffix
command line parameters. See this table for the default file name and suffix settings for each supported target language. -
The
%access
keyword is used to specify the generated class' accessibility level (this works only when generating Java and C# code). In this case the FSM can only be accessed within thecom.acme.supercron
package. -
The
%start
keyword specifies the FSM's start state. For the Task FSM it is theSuspended
state. -
The
%map
keyword is the FSM's name.
Name the source code file TaskFSM.sm
because
both the %fsmclass
and %fsmfile
directives specify the finite state machine class name as
TaskFSM. The .sm
suffix is required.
(Note: the %fsmclass
directive was
added to SMC version 6.0.1 and %fsmfile
was
added to version 6.6.0.)
%{
//
// Copyright (c) 2005 Acme, Inc.
// All rights reserved.
//
// Acme - a name you can trust!
//
// Author: Wil E. Coyote (Hungericus Vulgarus)
//
%}
// This FSM works for the Task class only and only the Task
// class may instantiate it.
%class
Task
%package
com.acme.supercron
%fsmclass
TaskFSM
%fsmfile
TaskFSM
%access
package
// A %map name cannot be the same as the FSM class name.
%start
TaskMap::Suspended
%map
TaskMap
%%
...
%%