INET Framework for OMNeT++/OMNEST
inet::Macho::_MachineBase Class Reference

#include <Macho.h>

Inheritance diagram for inet::Macho::_MachineBase:
inet::Macho::Machine< TOP > inet::Macho::Machine< fsm::TopState >

Public Member Functions

class Alias currentState () const
 

Protected Member Functions

 _MachineBase ()
 
 ~_MachineBase ()
 
void setState (_StateInstance &instance, _Initializer *init)
 
void setState (const Alias &state)
 
void setPendingState (_StateInstance &instance, _Initializer *init)
 
void setPendingEvent (_IEventBase *event)
 
void rattleOn ()
 
_StateInstance *& getInstance (ID id)
 
const _StateInstancegetInstance (ID id) const
 
void start (_StateInstance &instance)
 
void start (const Alias &state)
 
void shutdown ()
 
void allocate (unsigned int count)
 
void free (unsigned int count)
 
void clearHistoryDeep (unsigned int count, const _StateInstance &instance)
 

Protected Attributes

_StateInstancemyCurrentState = nullptr
 
_StateInstancemyPendingState = nullptr
 
_InitializermyPendingInit = nullptr
 
void * myPendingBox = nullptr
 
_IEventBasemyPendingEvent = nullptr
 
_StateInstance ** myInstances = nullptr
 

Friends

template<class C , class P >
class MachoLink
 
template<class T >
class TopBase
 
class _StateSpecification
 
class Alias
 
class _AdaptingInitializer
 
class _StateInstance
 
class ::inet::TestAccess
 

Constructor & Destructor Documentation

inet::_MachineBase::_MachineBase ( )
protected
220 {
221 }
inet::_MachineBase::~_MachineBase ( )
protected
224 {
225  assert(!myPendingInit);
226 
227  delete[] myInstances;
228  delete myPendingEvent;
229 }
_IEventBase * myPendingEvent
Definition: Macho.h:1609
_StateInstance ** myInstances
Definition: Macho.h:1612
_Initializer * myPendingInit
Definition: Macho.h:1604

Member Function Documentation

void inet::_MachineBase::allocate ( unsigned int  count)
protected
281 {
283  for (unsigned int i = 0; i < count; ++i)
284  myInstances[i] = nullptr;
285 }
int count(const std::vector< T > &v, const T &a)
Definition: stlutils.h:58
friend class _StateInstance
Definition: Macho.h:1594
_StateInstance ** myInstances
Definition: Macho.h:1612
void inet::_MachineBase::clearHistoryDeep ( unsigned int  count,
const _StateInstance instance 
)
protected

Referenced by inet::Macho::MachoLink< C, P >::clearHistoryDeep().

300 {
301  for (unsigned int i = 0; i < count; ++i) {
303  if (s && s->isChild(instance))
304  s->setHistory(nullptr);
305  }
306 }
void setHistory(_StateInstance *history) const
Definition: Macho.h:810
int count(const std::vector< T > &v, const T &a)
Definition: stlutils.h:58
friend class _StateInstance
Definition: Macho.h:1594
_StateInstance ** myInstances
Definition: Macho.h:1612
value< double, units::s > s
Definition: Units.h:1049
Alias inet::_MachineBase::currentState ( ) const

Referenced by inet::Macho::MachoLink< C, P >::isCurrent(), and inet::Macho::MachoLink< C, P >::isCurrentDirect().

232 {
233  return Alias(myCurrentState->key());
234 }
_StateInstance * myCurrentState
Definition: Macho.h:1600
friend class Alias
Definition: Macho.h:1588
void inet::_MachineBase::free ( unsigned int  count)
protected
288 {
289  // Free from end of list, so that child states are freed first
290  unsigned int i = count;
291  while (i > 0) {
292  --i;
293  delete myInstances[i];
294  myInstances[i] = nullptr;
295  }
296 }
int count(const std::vector< T > &v, const T &a)
Definition: stlutils.h:58
_StateInstance ** myInstances
Definition: Macho.h:1612
const _StateInstance* inet::Macho::_MachineBase::getInstance ( ID  id) const
inlineprotected
1545  {
1546  return myInstances[id];
1547  }
_StateInstance ** myInstances
Definition: Macho.h:1612
uint16_t id
Definition: TCP_NSC.cc:85
void inet::_MachineBase::rattleOn ( )
protected
340 {
341  assert(myCurrentState);
342 
343  while (myPendingState || myPendingEvent) {
344  // Loop here because init actions might change state again.
345  while (myPendingState) {
346  MACHO_TRC3(myCurrentState->name(), "Transition to", myPendingState->name());
347 
348 #ifndef NDEBUG
349  // Entry/Exit actions may not dispatch events: set dummy event.
350  if (!myPendingEvent)
351  myPendingEvent = (_IEventBase *)&myPendingEvent;
352 #endif // ifndef NDEBUG
353 
354  // Perform exit actions (which exactly depends on new state).
356 
357  // Store history information for previous state now.
358  // Previous state will be used for deep history.
360 
361  _StateInstance *previous = myCurrentState;
363 
364  // Deprecated!
365  if (myPendingBox) {
367  myPendingBox = nullptr;
368  }
369 
370  // Perform entry actions on next state's parents (which exactly depends on previous state).
371  myCurrentState->entry(*previous);
372 
373  // State transition complete.
374  // Clear 'pending' information just now so that setState would assert in exits and entries, but not in init.
375  myPendingState = nullptr;
376 
377  // Use initializer to call proper "init" action.
378  _Initializer *init = myPendingInit;
379  myPendingInit = nullptr;
380 
381  init->execute(*myCurrentState);
382  init->destroy();
383 
384  assert("Init may only transition to proper substates" &&
385  (!myPendingState ||
387  );
388 
389 #ifndef NDEBUG
390  // Clear dummy event if need be
391  if (myPendingEvent == (_IEventBase *)&myPendingEvent)
392  myPendingEvent = nullptr;
393 #endif // ifndef NDEBUG
394  } // while (myPendingState)
395 
396  if (myPendingEvent) {
397  _IEventBase *event = myPendingEvent;
398  myPendingEvent = nullptr;
399  event->dispatch(*myCurrentState);
400  delete event;
401  }
402  } // while (myPendingState || myPendingEvent)
403 } // rattleOn
void setBox(void *box)
Definition: Macho.h:773
bool isChild(const _StateInstance &instance)
Definition: Macho.h:787
_IEventBase * myPendingEvent
Definition: Macho.h:1609
friend class _StateInstance
Definition: Macho.h:1594
void entry(_StateInstance &previous, bool first=true)
Definition: Macho.cc:139
virtual const char * name()=0
virtual void execute(_StateInstance &instance)=0
void exit(_StateInstance &next)
Definition: Macho.cc:156
void setHistorySuper(_StateInstance &deep)
Definition: Macho.h:732
virtual void dispatch(_StateInstance &)=0
_Initializer * myPendingInit
Definition: Macho.h:1604
_StateInstance * myPendingState
Definition: Macho.h:1603
_StateInstance * myCurrentState
Definition: Macho.h:1600
void * myPendingBox
Definition: Macho.h:1607
#define MACHO_TRC3(STATE, MSG1, MSG2)
Definition: Macho.cc:47
void inet::Macho::_MachineBase::setPendingEvent ( _IEventBase event)
inlineprotected
1527  {
1528  assert(event);
1529  assert(!myPendingEvent && "There is already an event pending!");
1530 
1531  myPendingEvent = event;
1532  }
_IEventBase * myPendingEvent
Definition: Macho.h:1609
void inet::Macho::_MachineBase::setPendingState ( _StateInstance instance,
_Initializer init 
)
inlineprotected

Referenced by inet::Macho::_StateInstance::init(), inet::Macho::_StateSpecification::setState(), inet::Macho::Alias::setState(), inet::Macho::_StateSpecification::setStateBox(), inet::Macho::_StateSpecification::setStateDirect(), and inet::Macho::_StateSpecification::setStateHistory().

1517  {
1518  assert((!myPendingState || (myPendingState == &instance && myPendingInit == init)) &&
1519  "There is already a state transition pending!");
1520 
1521  myPendingState = &instance;
1522  myPendingInit = init;
1523  }
_Initializer * myPendingInit
Definition: Macho.h:1604
_StateInstance * myPendingState
Definition: Macho.h:1603
void inet::_MachineBase::setState ( _StateInstance instance,
_Initializer init 
)
protected
237 {
238  setPendingState(instance, init);
239  rattleOn();
240 }
void rattleOn()
Definition: Macho.cc:339
void setPendingState(_StateInstance &instance, _Initializer *init)
Definition: Macho.h:1516
void inet::_MachineBase::setState ( const Alias state)
protected
243 {
244  state.setState(*this);
245  rattleOn();
246 }
void rattleOn()
Definition: Macho.cc:339
void inet::_MachineBase::shutdown ( )
protected
269 {
270  assert(!myPendingState);
271 
272  MACHO_TRC1("Shutting down Machine");
273 
274  // Performs exit actions by going to Root (=StateSpecification) state.
275  setState(_StateSpecification::_getInstance(*this), &_theDefaultInitializer);
276 
277  myCurrentState = nullptr;
278 }
static _StateInstance & _getInstance(_MachineBase &machine)
Definition: Macho.cc:86
_StateInstance * myPendingState
Definition: Macho.h:1603
_StateInstance * myCurrentState
Definition: Macho.h:1600
void setState(_StateInstance &instance, _Initializer *init)
Definition: Macho.cc:236
#define MACHO_TRC1(MSG)
Definition: Macho.cc:45
void inet::_MachineBase::start ( _StateInstance instance)
protected
249 {
250  MACHO_TRC1("Starting Machine");
251 
252  // Start with Root state
254  // Then go to state
255  setState(instance, &_theDefaultInitializer);
256 }
static _StateInstance & _getInstance(_MachineBase &machine)
Definition: Macho.cc:86
_StateInstance * myCurrentState
Definition: Macho.h:1600
void setState(_StateInstance &instance, _Initializer *init)
Definition: Macho.cc:236
#define MACHO_TRC1(MSG)
Definition: Macho.cc:45
void inet::_MachineBase::start ( const Alias state)
protected
259 {
260  MACHO_TRC1("Starting Machine");
261 
262  // Start with Root state
264  // Then go to state
265  setState(state);
266 }
static _StateInstance & _getInstance(_MachineBase &machine)
Definition: Macho.cc:86
_StateInstance * myCurrentState
Definition: Macho.h:1600
void setState(_StateInstance &instance, _Initializer *init)
Definition: Macho.cc:236
#define MACHO_TRC1(MSG)
Definition: Macho.cc:45

Friends And Related Function Documentation

friend class ::inet::TestAccess
friend
friend class _AdaptingInitializer
friend
friend class _StateInstance
friend
friend class _StateSpecification
friend
friend class Alias
friend
template<class C , class P >
friend class MachoLink
friend
template<class T >
friend class TopBase
friend

Member Data Documentation

_StateInstance* inet::Macho::_MachineBase::myCurrentState = nullptr
protected
_StateInstance** inet::Macho::_MachineBase::myInstances = nullptr
protected
void* inet::Macho::_MachineBase::myPendingBox = nullptr
protected
_IEventBase* inet::Macho::_MachineBase::myPendingEvent = nullptr
protected
_Initializer* inet::Macho::_MachineBase::myPendingInit = nullptr
protected
_StateInstance* inet::Macho::_MachineBase::myPendingState = nullptr
protected

The documentation for this class was generated from the following files: