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

#include <Macho.h>

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

◆ _MachineBase()

inet::_MachineBase::_MachineBase ( )
protected
220 {
221 }

◆ ~_MachineBase()

inet::_MachineBase::~_MachineBase ( )
protected
224 {
225  assert(!myPendingInit);
226 
227  delete[] myInstances;
228  delete myPendingEvent;
229 }

Member Function Documentation

◆ allocate()

void inet::_MachineBase::allocate ( unsigned int  count)
protected
281 {
283  for (unsigned int i = 0; i < count; ++i)
284  myInstances[i] = nullptr;
285 }

◆ clearHistoryDeep()

void inet::_MachineBase::clearHistoryDeep ( unsigned int  count,
const _StateInstance instance 
)
protected
300 {
301  for (unsigned int i = 0; i < count; ++i) {
303  if (s && s->isChild(instance))
304  s->setHistory(nullptr);
305  }
306 }

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

◆ currentState()

Alias inet::_MachineBase::currentState ( ) const

◆ free()

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 }

◆ getInstance() [1/2]

◆ getInstance() [2/2]

const _StateInstance* inet::Macho::_MachineBase::getInstance ( ID  id) const
inlineprotected
1547  {
1548  return myInstances[id];
1549  }

◆ rattleOn()

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 #ifndef NDEBUG
389  // Clear dummy event if need be
390  if (myPendingEvent == (_IEventBase *)&myPendingEvent)
391  myPendingEvent = nullptr;
392 #endif // ifndef NDEBUG
393  } // while (myPendingState)
394 
395  if (myPendingEvent) {
396  _IEventBase *event = myPendingEvent;
397  myPendingEvent = nullptr;
398  event->dispatch(*myCurrentState);
399  delete event;
400  }
401  } // while (myPendingState || myPendingEvent)
402 } // rattleOn

Referenced by setState().

◆ setPendingEvent()

void inet::Macho::_MachineBase::setPendingEvent ( _IEventBase event)
inlineprotected
1529  {
1530  assert(event);
1531  assert(!myPendingEvent && "There is already an event pending!");
1532 
1533  myPendingEvent = event;
1534  }

◆ setPendingState()

void inet::Macho::_MachineBase::setPendingState ( _StateInstance instance,
_Initializer init 
)
inlineprotected
1519  {
1520  assert((!myPendingState || (myPendingState == &instance && myPendingInit == init)) &&
1521  "There is already a state transition pending!");
1522 
1523  myPendingState = &instance;
1524  myPendingInit = init;
1525  }

Referenced by inet::Macho::_StateInstance::init(), setState(), and inet::Macho::Alias::setState().

◆ setState() [1/2]

void inet::_MachineBase::setState ( _StateInstance instance,
_Initializer init 
)
protected
237 {
238  setPendingState(instance, init);
239  rattleOn();
240 }

Referenced by shutdown(), and start().

◆ setState() [2/2]

void inet::_MachineBase::setState ( const Alias state)
protected
243 {
244  state.setState(*this);
245  rattleOn();
246 }

◆ shutdown()

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 }

Referenced by inet::Macho::_StateSpecification::_shutdown().

◆ start() [1/2]

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 }

◆ start() [2/2]

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 }

Friends And Related Function Documentation

◆ ::inet::TestAccess

friend class ::inet::TestAccess
friend

◆ _AdaptingInitializer

friend class _AdaptingInitializer
friend

◆ _StateInstance

friend class _StateInstance
friend

◆ _StateSpecification

friend class _StateSpecification
friend

◆ Alias

friend class Alias
friend

Referenced by currentState().

◆ MachoLink

template<class C , class P >
friend class MachoLink
friend

◆ TopBase

template<class T >
friend class TopBase
friend

Member Data Documentation

◆ myCurrentState

_StateInstance* inet::Macho::_MachineBase::myCurrentState = nullptr
protected

◆ myInstances

_StateInstance** inet::Macho::_MachineBase::myInstances = nullptr
protected

◆ myPendingBox

void* inet::Macho::_MachineBase::myPendingBox = nullptr
protected

Referenced by rattleOn().

◆ myPendingEvent

_IEventBase* inet::Macho::_MachineBase::myPendingEvent = nullptr
protected

◆ myPendingInit

_Initializer* inet::Macho::_MachineBase::myPendingInit = nullptr
protected

◆ myPendingState

_StateInstance* inet::Macho::_MachineBase::myPendingState = nullptr
protected

Referenced by rattleOn(), setPendingState(), and shutdown().


The documentation for this class was generated from the following files:
inet::Macho::_IEventBase::dispatch
virtual void dispatch(_StateInstance &)=0
inet::Macho::_StateInstance::setBox
void setBox(void *box)
Definition: Macho.h:775
inet::Macho::_StateInstance::name
virtual const char * name()=0
inet::count
int count(const std::vector< T > &v, const Tk &a)
Definition: stlutils.h:54
inet::Macho::_StateInstance::exit
void exit(_StateInstance &next)
Definition: Macho.cc:156
inet::Macho::_Initializer::execute
virtual void execute(_StateInstance &instance)=0
inet::Macho::_MachineBase::rattleOn
void rattleOn()
Definition: Macho.cc:339
inet::Macho::_StateInstance::isChild
bool isChild(const _StateInstance &instance)
Definition: Macho.h:789
inet::Macho::_StateInstance::entry
void entry(_StateInstance &previous, bool first=true)
Definition: Macho.cc:139
inet::Macho::_MachineBase::myInstances
_StateInstance ** myInstances
Definition: Macho.h:1614
inet::Macho::_MachineBase::myCurrentState
_StateInstance * myCurrentState
Definition: Macho.h:1602
inet::Macho::_StateInstance::setHistorySuper
void setHistorySuper(_StateInstance &deep)
Definition: Macho.h:734
inet::units::values::s
value< double, units::s > s
Definition: Units.h:1235
inet::Macho::_MachineBase::setState
void setState(_StateInstance &instance, _Initializer *init)
Definition: Macho.cc:236
inet::Macho::_MachineBase::setPendingState
void setPendingState(_StateInstance &instance, _Initializer *init)
Definition: Macho.h:1518
inet::Macho::_MachineBase::myPendingState
_StateInstance * myPendingState
Definition: Macho.h:1605
inet::Macho::_MachineBase::Alias
friend class Alias
Definition: Macho.h:1590
inet::Macho::_StateInstance::key
virtual Key key()=0
inet::Macho::_MachineBase::myPendingBox
void * myPendingBox
Definition: Macho.h:1609
MACHO_TRC3
#define MACHO_TRC3(STATE, MSG1, MSG2)
Definition: Macho.cc:47
inet::Macho::_StateSpecification::_getInstance
static _StateInstance & _getInstance(_MachineBase &machine)
Definition: Macho.cc:86
inet::Macho::_MachineBase::myPendingEvent
_IEventBase * myPendingEvent
Definition: Macho.h:1611
inet::Macho::_MachineBase::_StateInstance
friend class _StateInstance
Definition: Macho.h:1596
MACHO_TRC1
#define MACHO_TRC1(MSG)
Definition: Macho.cc:45
inet::Macho::_MachineBase::myPendingInit
_Initializer * myPendingInit
Definition: Macho.h:1606