16#ifndef __OMNETPP_CFSM_H
17#define __OMNETPP_CFSM_H
19#include "cownedobject.h"
83#define FSM_Switch(fsm) \
84 for (int __i=1, __savedstate; \
85 (__i<3 || (__i&1)==0 || (fsm).isInTransientState()) && \
86 (__i<2*FSM_MAXT || (throw cRuntimeError(E_INFLOOP,(fsm).getStateName()),0)); \
87 ((__i&1)==0 && __savedstate!=(fsm).getState() && \
88 (throw cRuntimeError(E_STATECHG,(fsm).getStateName()),0)), \
89 __savedstate=(fsm).getState(),++__i) \
90 switch (FSM_Print(fsm,__i&1),(((fsm).getState()*2)|(__i&1)))
111#define FSM_Transient(state) (-(state))
121#define FSM_Steady(state) (state)
132#define FSM_Enter(state) (2*(state))
141#define FSM_Exit(state) (2*(state)|1)
153#define FSM_Goto(fsm,state) (fsm).setState(state,#state)
163#define FSM_Print(fsm,exiting) \
164 (EV << "FSM " << (fsm).getName() \
165 << ((exiting) ? ": leaving state " : ": entering state ") \
166 << (fsm).getStateName() << endl)
170#define FSM_Print(fsm,entering) ((void)0)
184class SIM_API
cFSM :
public cOwnedObject
194 const char *stateName =
"INIT";
197 void copy(
const cFSM& other);
208 explicit cFSM(
const char *name=
nullptr);
213 cFSM(
const cFSM& other) : cOwnedObject(other) {copy(other);}
235 virtual std::string
str()
const override;
266 void setState(
int state,
const char *stateName=
nullptr) {this->state=state;this->stateName=stateName;}
Buffer for the communications layer of parallel simulation.
Definition ccommbuffer.h:42
cFSM & operator=(const cFSM &vs)
void setState(int state, const char *stateName=nullptr)
Definition cfsm.h:266
cFSM(const char *name=nullptr)
int getState() const
Definition cfsm.h:244
virtual std::string str() const override
cFSM(const cFSM &other)
Definition cfsm.h:213
virtual cFSM * dup() const override
Definition cfsm.h:229
int isInTransientState() const
Definition cfsm.h:254
const char * getStateName() const
Definition cfsm.h:249
Thrown when the simulation kernel or other components detect a runtime error.
Definition cexception.h:343