The SMC-generated code is designed to be loosely coupled with your application software. The only changes that you need to make to your code is to:
-
Include the SMC class definitions into your
application (stored in smc/lib by programming language
name):
- C: Have lib/C/statemap.h in the include path.
- C++: Have lib/C++/statemap.h in the include path.
- C#: Have lib/DotNet/statemap.dll included in the Visual Studio studio.
- Groovy: Have lib/Groovy/statemap.jar in the classpath.
- Java: Have lib/Java/statemap.jar in the classpath.
-
JavaScript: Have lib/JavaScript/statemap.js
accessible to
<script>
tag. -
Lua: Have the lib/Lua/statemap.lua module on
your Lua
package.path
(initialized by the environment variableLUA_PATH
). - Objective-C: Have lib/ObjC/statemap.h in the include path.
-
Perl: Have StateMachine::Statemap module on your Perl
library path
@INC
. -
PHP: Have StateMachine/statemap.php in your
PHP
include_path
. -
Python: Have the statemap module
on your import source path
sys.path
. -
Ruby: Have the statemap module on your
Ruby library path
$LOAD_PATH
. - Scala: Have lib/Scala/statemap.jar in the classpath.
- Tcl: Have the lib/Tcl/statemap1.0 package on your path.
- VB.net: Have lib/DotNet/statemap.dll included in the Visual Studio studio.
-
Include the state machine's source file:
- C: #include "AppClass_sm.h"
- C++: #include "AppClass_sm.h"
- C#: put the AppClass_sm.vb file in your Visual Studio solution.
- Groovy: If AppClassContext class is in the same package as AppClass, no importation is needed.
- Java: If AppClassContext class is in the same package as AppClass, no importation is needed.
-
JavaScript: Have AppClass_sm.js file
accessible to
<script>
tag. - Lua: require 'AppClass_sm'
- Objective-C: #import "AppClass_sm.h"
- Perl: use AppClass_sm;
- PHP: require_once 'AppClass_sm';
- Python: import AppClass_sm
- Ruby: require 'AppClass_sm'
- Scala: If AppClassContext class is in the same package as AppClass, no importation is needed.
- Tcl: source ./AppClass_sm.tcl
- VB.net: put the AppClass_sm.vb file in your Visual Studio solution.
- Instantiate the state machine's context object.
-
If you want to execute the start state's entry actions
call the state machine context's
enterStartState
method. This is not needed to set the start state as that is done when the state machine context is instantiated.enterStartState
only executes the start state's entry actions (if any exist).
That's all you need to do. Whenever you want to issue a transition, call the context's object transition method.
SMC does not change your code or require you to change your code's logic. SMC does not require that your class inherit or implement any SMC class. SMC does not use state transition arrays or switch statements. SMC state machines are easy to add with minimal impact to your existing code.
CAUTION: THIS BEARS REPEATING. Do NOT issue a transition from within an action - it will cause the state machine to throw an exception since actions are not allowed to issue a transitions.
For an explanation of why this is, see the SMC FAQ question: Why can't an action issue a transition?
If you do need to issue a transition from an action, see the section 7, "Queuing Up" explaining how to use a "transition queue".
C language is not Object Oriented. But this behavior could be emulated in order to follow the SMC State pattern.
Assumptions:
- Your application class is named NetworkIF.
- Your class is stored in NetworkIF.h and NetworkIF.c.
- The state machine is in NetworkIF.sm.
- You have successfully compiled NetworkIF.sm.
Changes to NetworkIF.h
-
As explained in
section 1
, you have added the lines
%class NetworkIF %header NetworkIF.h %start MainMap::Start
at the appropriate location in NetworkIF.sm.
-
Add the following #include to NetworkIF.h:
#include "NetworkIF_sm.h"
-
Add the member data to class NetworkIF:
struct NetworkIFContext _fsm;
(I used "_fsm" but you can use another name).
Changes to NetworkIF.c
-
In NetworkIF initializer NetworkIF_Init, add the line:
void NetworkIF_Init(struct NetworkIF *network) { NetworkIFContext_Init(&this->_fsm, network); }Again, the member data does not have to be named _fsm.
Add the following line, if Push transitions are used.FSM_STACK(&network->_fsm, AppStack);where AppStack is a memory location. -
If the start state has entry actions and these actions
need to be executed before transitions are issued,
then add the following code:
NetworkIFContext_EnterStartState(&network->_fsm);
-
Wherever you want to issue a state machine transition,
add the following line of code:
NetworkIFContext_<transition>(&network->_fsm, ...);Where "<transition>" is the name of the transition you want to take. If the transition takes arguments then pass them in the transition call:NetworkIFContext_Connect(&network->_fsm, "192.168.3.100", 80);
Changes to Makefile
Add NetworkIF_sm.c to the source file list and link NetworkIF_sm.o into your application.
#includes in NetworkIF.sm
If you need to include header files in your .sm file,
use the %include
keyword:
Cautions
The following class and file names are generated by SMC. Be careful not to use them yourself.
- <AppClass>Context
- <AppClass>State
- <MapName>
- <MapName>_Default
- <MapName>_<StateName>
- <smc file name stem>_sm.h
- <smc file name stem>_sm.<ext>
where:
- <AppClass> is the name of your application class using that FSM.
- <MapName> is a "%map <MapName>" in <smc file name stem>.sm.
- <StateName> is a state in <smc file name stem>.sm.
- <smc file name stem> is that part of the .sm file's name before the ".".
- <ext> is the source file extension (defaults to "c").
Assumptions:
- Your application class is named NetworkIF.
- Your class is stored in NetworkIF.h and NetworkIF.cpp.
- The state machine is in NetworkIF.sm.
-
As explained in
section 1
, you have added the lines
%class NetworkIF %header NetworkIF.h %start MainMap::Start
at the appropriate location in NetworkIF.sm.
- You have successfully compiled NetworkIF.sm.
Changes to NetworkIF.h
-
Add the following #include to NetworkIF.h:
#include "NetworkIF_sm.h"
-
Add the member data to class NetworkIF:
NetworkIFContext _fsm;
This member data can be either public, protected or private and can have any name (I used "_fsm" but you can use another name).
- All state machine actions must be implemented as NetworkIF public methods. For an explanation as to why these methods must be public, see the answer to the FAQ question: Why do actions have to be declared as public?
Changes to NetworkIF.cpp
-
In all NetworkIF constructors, add the following to
the initialization list:
_fsm(*this)Again, the member data does not have to be named _fsm.
-
If the start state has entry actions which must be
executed before any transitions are issued add the
following code:
_fsm.enterStartState();
-
Wherever you want to issue a state machine transition,
add the following line of code:
_fsm.<transition>();Where "<transition>" is the name of the transition you want to take. If the transition takes arguments then pass them in the transition call:_fsm.Connect("192.168.3.100", 80);
Changes to Makefile
Add NetworkIF_sm.cpp to the source file list and link NetworkIF_sm.o into your application.
"using namespace" in NetworkIF.sm
If you need to place the SMC-generated classes into a C++ namespace, then see Section 8.
#includes in NetworkIF.sm
If you need to include header files in your .sm file,
use the %include
keyword:
Cautions
The following class and file names are generated by SMC. Be careful not to use them yourself.
- <AppClass>Context
- <AppClass>State
- <MapName>
- <MapName>_Default
- <MapName>_<StateName>
- <smc file name stem>_sm.h
- <smc file name stem>_sm.<ext>
where:
- <AppClass> is the name of your application class using that FSM.
- <MapName> is a "%map <MapName>" in <smc file name stem>.sm.
- <StateName> is a state in <smc file name stem>.sm.
- <smc file name stem> is that part of the .sm file's name before the ".".
- <ext> is the source file extension (defaults to "cpp").
using -crtp (Curiously Recurring Template Pattern)
Assumptions:
Same as C++ assumptions.
Changes to NetworkIF.h
-
Add the following #include to NetworkIF.h:
#include "NetworkIF_sm.h"
-
Inherit the context template:
class NetworkIF : public NetworkIFContext<NetworkIF>
This must be a public inheritance otherwise the SMC-generated code will not compile.
- All state machine actions must be implemented as NetworkIF public methods. For an explanation as to why these methods must be public, see the answer to the FAQ question: Why do actions have to be declared as public?
Changes to NetworkIF.cpp
-
If the start state has entry actions which must be
executed before any transitions are issued add the
following code:
enterStartState();
-
Wherever you want to issue a state machine transition,
add the following line of code:
<transition>();Where "<transition>" is the name of the transition you want to take. If the transition takes arguments then pass them in the transition call:Connect("192.168.3.100", 80);
Changes to Makefile
Add NetworkIF_sm.cpp to the source file list and link NetworkIF_sm.o into your application.
Assumptions:
- Your application class is named NetworkIF.
- Your class is declared in NetworkIF.h and defined in NetworkIF.m.
- The state machine is in NetworkIF.sm.
-
As explained in
section 1
, you have added the lines
%class NetworkIF %include NetworkIF.h %start MainMap::Start
at the appropriate location in NetworkIF.sm.
- You have successfully compiled NetworkIF.sm.
Changes to NetworkIF.h
-
Forward declare the FSM class by adding this line to
NetworkIF.h:
@class NetworkIFContext;
-
Add the member data to the class NetworkIF:
NetworkIFContext *_fsm;
Changes to NetworkIF.m
-
Import the FSM header:
#import "NetworkIF_sm.h"
-
When allocating the FSM, pass in the NetworkIF instance
reference:
_fsm = [[NetworkIF alloc] initWithOwner:self];
-
If the start state has entry actions which must be
executed prior to issuing transitions add the following
code:
TODO PUT Objective-C code here.
-
When you want to issue a state machine transition,
add the following line of code:
[_fsm <transition>];Where "<transition>" is the transition name.
Assumptions
- You have a Java class named NetworkIF defined in the file NetworkIF.java
- The state machine is in NetworkIF.sm.
- You have successfully compiled NetworkIF.sm.
Adding the state machine to NetworkIF requires the following changes to NetworkIF.java:
-
Add the following member data to class NetworkIF:
private NetworkIFContext _fsm;The data member does not have to be private but may be public or protected. Also, the variable name does not have to be "_fsm".
-
In all NetworkIF constructors, add the line:
_fsm = new NetworkIFContext(this);
-
If the start state has entry actions which must be
executed prior to issuing transitions then add
the following code outside the
NetworkIF constructors:
_fsm.enterStartState();
-
Whenever you want to issue a transition, all you
need to do is:
_fsm.<transition>();Where "<transition>" is the name of the transition you want to take. If the transition takes arguments then pass them in the transition call:_fsm.Connect("192.168.3.100", 80);
- All state machine actions may be implemented in NetworkIF as either public or package methods so that the SMC generated code can access them.
package in NetworkIF.sm
If you need to place the SMC-generated classes into a Java package, then see Section 8.
import in NetworkIF.sm
If you need to use import
statements
in your .sm file, use the %import
keyword
at the top of the .sm file:
Cautions
The following classes are generated by SMC. Be careful not to use them yourself.
- <AppClass>Context
- <AppClass>State
- <MapName>
- <MapName>_Default
- <MapName>_<StateName>
- <smc file name stem>Context.java
where:
- <AppClass> is the name of your application class.
- <MapName> is "%map <MapName>" in <smc file name stem>.sm.
- <StateName> is a state in <smc file name stem>.sm.
- <smc file name stem> is that part of the .sm file's name before the ".".
Assumptions:
- You have an [incr Tcl] class named NetworkIF defined in the file NetworkIF.tcl
- The state machine is in NetworkIF.sm.
- You have successfully compiled NetworkIF.sm.
Adding the state machine to NetworkIF requires the following changes to NetworkIF.tcl:
-
At the top of the file, add
source NetworkIF_sm.tcl
-
Add the following data member declaration:
private variable _fsmThis data member may be either public, protected or private and can have any name (I used "_fsm" but you can use another name).
-
In the NetworkIF constructor, create the state machine
object and place the name into your previously
declared data member:
set _fsm [NetworkIFContext #auto $this];Again, you don't have to use "#auto" to name the object but you do have to pass in the NetworkIF object's name to the NetworkIFContext's constructor.
-
If the start state has entry actions which must be
exectued prior to issuing transitions add this code
outside the NetworkIF constructors:
$_fsm enterStartState
-
Whenever you want to issue a transition, all you
need to do is:
$_fsm <transition>Where "<transition>" is the name of the transition you want to take. If the transition takes arguments pass them in the transition call:$_fsm Connect "192.168.3.100" 80;
- All state ma actions must be implemented as NetworkIF public methods. For an explanation as to why these methods must be public, see the answer to the FAQ question: Why do actions have to be declared as public?
"namespace eval" in NetworkIF.sm
If you need to place the SMC-generated classes into a Tcl namespace, then see Section 8.
"package require" in NetworkIF.sm
If you need to use package require
or
source
statements in your .sm file, place
these statements inside the verbatim code section at
the top of the .sm file:
Cautions
The following class and file names are generated by SMC. Be careful not to use them yourself.
- <AppClass>Context
- <AppClass>State
- <MapName>
- <MapName>_Default
- <MapName>_<StateName>
- <smc file name stem>_sm.tcl
where:
- <AppClass> is the name of your application class.
- <MapName> is a "%map <MapName>" in <smc file name stem>.sm.
- <StateName> is a state in <smc file name stem>.sm.
- <smc file name stem> is that part of the .sm file's name before the ".".
Assumptions:
- You have an VB.net class named NetworkIF defined in the file NetworkIF.vb
- The state machine is in NetworkIF.sm.
- You have successfully compiled NetworkIF.sm.
Adding the state machine to NetworkIF requires the following changes to NetworkIF.vb:
-
Add the following data member to class NetworkIF:
Private _fsm As NetworkIFContextYou can use any variable name you want. I use
_fsm
. -
In the New() constructors add the line:
_fsm = New NetworkIFContext(Me)
-
If the start state has entry actions which must be
executed prior to issuing any transitions add the
following code outside the NetworkIF
constructors:
_fsm.EnterStartState()
-
Whenever you want to issue a transition all you
need to do is:
_fsm.<transition>()where <transition> is the name of the transition you want to take. If the transition takes arguments then pass them in the transition call:_fsm.Connect("192.168.3.100", 80)
- All state machine actions must be implemented in NetworkIF as Public methods so that the SMC generated code can access them.
Imports in NetworkIF.sm
If you need to use Imports
in your .sm
file, use the %import
keyword in the
top of your .sm file:
Cautions
The following classes are generated by SMC. Be careful not to use them yourself.
- <AppClass>Context
- <AppClass>State
- <MapName>
- <MapName>_Default
- <MapName>_<StateName>
- <smc file name stem>Context.vb
where:
- <AppClass> is the name of your application class.
- <MapName> is "%map <MapName>" in <smc file name stem>.sm.
- <StateName> is a state in <smc file name stem>.sm.
- <smc file name stem> is that part of the .sm file's name before the ".".
Assumptions:
- You have an C# class named NetworkIF defined in the file NetworkIF.cs
- The state machine is in NetworkIF.sm.
- You have successfully compiled NetworkIF.sm.
Adding the state machine to NetworkIF requires the following changes to NetworkIF.cs:
-
Add the following data member to class NetworkIF:
private NetworkIFContext _fsm;You can use any variable name you want. I use
_fsm
. -
In the NetworkIF constructors add the line:
_fsm = new NetworkIFContext(this)
-
If the start state has entry actions which must be
executed prior to issuing any transitions add the
following code outside the NetworkIF
constructors:
_fsm.enterStartState()
-
Whenever you want to issue a transition all you
need to do is:
_fsm.<transition>()where <transition> is the name of the transition you want to take. If the transition takes arguments then pass them in the transition call:_fsm.Connect("192.168.3.100", 80)
- All state machine actions must be implemented in NetworkIF as public- or package-level methods so that the SMC generated code can access them.
Imports in NetworkIF.sm
If you need to use import
in your .sm
file, use the %import
keyword in the
top of your .sm file:
Cautions
The following classes are generated by SMC. Be careful not to use them yourself.
- <AppClass>Context
- <AppClass>State
- <MapName>
- <MapName>_Default
- <MapName>_<StateName>
- <smc file name stem>_sm.cs
where:
- <AppClass> is the name of your application class.
- <MapName> is "%map <MapName>" in <smc file name stem>.sm.
- <StateName> is a state in <smc file name stem>.sm.
- <smc file name stem> is that part of the .sm file's name before the ".".
Assumptions
- You have a Groovy class named NetworkIF defined in the file NetworkIF.groovy
- The state machine is in NetworkIF.sm.
- You have successfully compiled NetworkIF.sm.
Adding the state machine to NetworkIF requires the following changes to NetworkIF.groovy:
-
Add the following member data to class NetworkIF:
private def _fsmThe data member does not have to be private but may be public or protected. Also, the variable name does not have to be "_fsm".
-
In all NetworkIF constructors, add the line:
_fsm = new NetworkIFContext(this)
-
If the start state has entry actions which must be
executed prior to issuing any transitions add the
following code outside the NetworkIF
constructors:
TODO Put Groovy example code here.
-
Whenever you want to issue a transition, all you
need to do is:
_fsm.<transition>()Where "<transition>" is the name of the transition you want to take. If the transition takes arguments then pass them in the transition call:_fsm.Connect('192.168.3.100', 80)
- All state machine actions may be implemented in NetworkIF as either public or package methods so that the SMC generated code can access them.
package in NetworkIF.sm
If you need to place the SMC-generated classes into a Groovy package, then see Section 8.
import in NetworkIF.sm
If you need to use import
statements
in your .sm file, use the %import
keyword
at the top of the .sm file:
Cautions
The following classes are generated by SMC. Be careful not to use them yourself.
- <AppClass>Context
- <AppClass>State
- <MapName>
- <MapName>_Default
- <MapName>_<StateName>
- <smc file name stem>Context.groovy
where:
- <AppClass> is the name of your application class.
- <MapName> is "%map <MapName>" in <smc file name stem>.sm.
- <StateName> is a state in <smc file name stem>.sm.
- <smc file name stem> is that part of the .sm file's name before the ".".
Assumptions:
- You have an Lua class named NetworkIF defined in the file NetworkIF.lua
- The state machine is in NetworkIF.sm.
- You have successfully compiled NetworkIF.sm.
Adding the state machine to NetworkIF requires the following changes to NetworkIF.lua:
-
In the NetworkIF
new
methods add the line:o._fsm = NetworkIF_sm.sm:new({_owner = o}) -
If the start state has entry actions which must be
executed prior to issuing any transitions add the
following code outside the NetworkIF
constructors:
TODO Put Lua example code here.
-
Whenever you want to issue a transition all you
need to do is:
self._fsm:<transition>()where <transition> is the name of the transition you want to take. If the transition takes arguments then pass them in the transition call:self._fsm:Connect("192.168.3.100", 80)
Imports in NetworkIF.sm
If you need to use require
in your .sm
file, use the %import
keyword in the
top of your .sm file:
Cautions
The following classes or objects are generated by SMC. Be careful not to use them yourself.
- <AppClass>Context
- <AppClass>State
- <MapName>
- <MapName>_Default
- <MapName>_<StateName>
- <smc file name stem>_sm.lua
where:
- <AppClass> is the name of your application class.
- <MapName> is "%map <MapName>" in <smc file name stem>.sm.
- <StateName> is a state in <smc file name stem>.sm.
- <smc file name stem> is that part of the .sm file's name before the ".".
Assumptions:
- You have an Python class named NetworkIF defined in the file NetworkIF.py
- The state machine is in NetworkIF.sm.
- You have successfully compiled NetworkIF.sm.
Adding the state machine to NetworkIF requires the following changes to NetworkIF.py:
-
In the NetworkIF
__init__
methods add the line:self._fsm = NetworkIF_sm.NetworkIF_sm(self) -
If the start state has entry actions which must be
executed prior to issuing any transitions add the
following code outside the NetworkIF
constructors:
TODO Put Python example code here.
-
Whenever you want to issue a transition all you
need to do is:
self._fsm.<transition>()where <transition> is the name of the transition you want to take. If the transition takes arguments then pass them in the transition call:self._fsm.Connect("192.168.3.100", 80)
Imports in NetworkIF.sm
If you need to use import
in your .sm
file, use the %import
keyword in the
top of your .sm file:
Cautions
The following classes are generated by SMC. Be careful not to use them yourself.
- <AppClass>_sm
- <AppClass>State
- <MapName>
- <MapName>_Default
- <MapName>_<StateName>
- <smc file name stem>_sm.py
where:
- <AppClass> is the name of your application class.
- <MapName> is "%map <MapName>" in <smc file name stem>.sm.
- <StateName> is a state in <smc file name stem>.sm.
- <smc file name stem> is that part of the .sm file's name before the ".".
Assumptions:
- You have an PHP class named NetworkIF defined in the file NetworkIF.php
- The state machine is in NetworkIF.sm.
- You have successfully compiled NetworkIF.sm.
Adding the state machine to NetworkIF requires the following changes to NetworkIF.php:
-
In the NetworkIF
__construct
methods add the line:$this->_fsm = new NetworkIF_sm($this); -
If the start state has entry actions which must be
executed prior to issuing any transitions add the
following code outside the NetworkIF
constructors:
TODO Put PHP example code here.
-
Whenever you want to issue a transition all you
need to do is:
$this->_fsm-><transition>();where <transition> is the name of the transition you want to take. If the transition takes arguments then pass them in the transition call:$this->_fsm->Connect("192.168.3.100", 80);
Imports in NetworkIF.sm
If you need to use require_once
in your .sm
file, use the %import
keyword in the
top of your .sm file:
Cautions
The following classes are generated by SMC. Be careful not to use them yourself.
- <AppClass>_sm
- <AppClass>State
- <MapName>
- <MapName>_Default
- <MapName>_<StateName>
- <smc file name stem>_sm.php
where:
- <AppClass> is the name of your application class.
- <MapName> is "%map <MapName>" in <smc file name stem>.sm.
- <StateName> is a state in <smc file name stem>.sm.
- <smc file name stem> is that part of the .sm file's name before the ".".
Assumptions:
- You have an Perl module named NetworkIF defined in the file NetworkIF.pm
- The state machine is in NetworkIF.sm.
- You have successfully compiled NetworkIF.sm.
Adding the state machine to NetworkIF requires the following changes to NetworkIF.pm:
-
In the NetworkIF
new
methods add the line:$self->{_fsm} = new NetworkIF_sm($self); -
If the start state has entry actions which must be
executed prior to issuing any transitions add the
following code outside the NetworkIF
constructors:
TODO Put Perl example code here.
-
Whenever you want to issue a transition all you
need to do is:
$self->{_fsm}-><transition>();where <transition> is the name of the transition you want to take. If the transition takes arguments then pass them in the transition call:$self->{_fsm}->Connect("192.168.3.100", 80);
Imports in NetworkIF.sm
If you need to use use
in your .sm
file, use the %import
keyword in the
top of your .sm file:
Cautions
The following classes are generated by SMC. Be careful not to use them yourself.
- <AppClass>_sm
- <AppClass>State
- <MapName>
- <MapName>_Default
- <MapName>_<StateName>
- <smc file name stem>_sm.pm
where:
- <AppClass> is the name of your application class.
- <MapName> is "%map <MapName>" in <smc file name stem>.sm.
- <StateName> is a state in <smc file name stem>.sm.
- <smc file name stem> is that part of the .sm file's name before the ".".
Assumptions:
- You have an Ruby class named NetworkIF defined in the file NetworkIF.rb
- The state machine is in NetworkIF.sm.
- You have successfully compiled NetworkIF.sm.
Adding the state machine to NetworkIF requires the following changes to NetworkIF.rb:
-
In the NetworkIF
initialize
methods add the line:@_fsm = NetworkIF_sm::new(self) -
If the start state has entry actions which must be
executed prior to issuing any transitions add the
following code outside the NetworkIF
constructors:
TODO Put Ruby example code here.
-
Whenever you want to issue a transition all you
need to do is:
@_fsm.<transition>()where <transition> is the name of the transition you want to take. If the transition takes arguments then pass them in the transition call:@_fsm.Connect("192.168.3.100", 80)
Imports in NetworkIF.sm
If you need to use require
in your .sm
file, use the %import
keyword in the
top of your .sm file:
Cautions
The following classes are generated by SMC. Be careful not to use them yourself.
- <AppClass>_sm
- <AppClass>State
- <MapName>
- <MapName>_Default
- <MapName>_<StateName>
- <smc file name stem>_sm.rb
where:
- <AppClass> is the name of your application class.
- <MapName> is "%map <MapName>" in <smc file name stem>.sm.
- <StateName> is a state in <smc file name stem>.sm.
- <smc file name stem> is that part of the .sm file's name before the ".".
Assumptions
- You have a Scala class named NetworkIF defined in the file NetworkIF.scala
- The state machine is in NetworkIF.sm.
- You have successfully compiled NetworkIF.sm.
Adding the state machine to NetworkIF requires the following changes to NetworkIF.scala:
-
Add the following member data to class NetworkIF:
private val _fsm = new NetworkIFContext(this)The data member does not have to be private but may be public or protected. Also, the variable name does not have to be "_fsm".
-
If the start state has entry actions which must be
executed prior to issuing any transitions add the
following code outside the NetworkIF
constructors:
TODO Put Scala example code here.
-
Whenever you want to issue a transition, all you
need to do is:
_fsm.<transition>()Where "<transition>" is the name of the transition you want to take. If the transition takes arguments then pass them in the transition call:_fsm.Connect("192.168.3.100", 80)
- All state machine actions may be implemented in NetworkIF as either public or package methods so that the SMC generated code can access them.
package in NetworkIF.sm
If you need to place the SMC-generated classes into a Scala a package, then see Section 8.
import in NetworkIF.sm
If you need to use import
statements
in your .sm file, use the %import
keyword
at the top of the .sm file:
Cautions
The following classes or objects are generated by SMC. Be careful not to use them yourself.
- <AppClass>Context
- <AppClass>State
- <MapName>
- <MapName>_Default
- <MapName>_<StateName>
- <smc file name stem>Context.scala
where:
- <AppClass> is the name of your application class.
- <MapName> is "%map <MapName>" in <smc file name stem>.sm.
- <StateName> is a state in <smc file name stem>.sm.
- <smc file name stem> is that part of the .sm file's name before the ".".
Assumptions:
- You have an JavaScript class named NetworkIF defined in the file NetworkIF.js
- The state machine is in NetworkIF.sm.
- You have successfully compiled NetworkIF.sm.
Adding the state machine to NetworkIF requires the following changes to NetworkIF.js:
-
In the NetworkIF constructor add the line:
this._fsm = new NetworkIF_sm(this);
-
If the start state has entry actions which must be
executed prior to issuing any transitions add the
following code outside the NetworkIF
constructors:
this._fsm.enterStartState();
-
Whenever you want to issue a transition all you
need to do is:
this._fsm.<transition>();where <transition> is the name of the transition you want to take. If the transition takes arguments then pass them in the transition call:this._fsm.Connect("192.168.3.100", 80);