FACT++  1.0
bool StateMachineImp::PostEvent ( const EventImp evt,
const char *  ptr,
size_t  siz 
)

With this function commands are posted to the event queue. If the event loop has not yet been started with Run() the command is directly handled by HandleEvent.

Events posted when the state machine is in a negative state or kSM_FatalError are ignored.

A new event is created and its data contents initialized with the specified memory.

Parameters
evtThe event to be posted. The precise contents depend on what the event should be for.
ptrpointer to the memory which should be attached to the event
sizsize of the memory which should be attached to the event
Returns
false if the event is ignored, true otherwise.
Todo:
  • Shell we check for the validity of a command at the current state, too?
  • should we also get the output stream as an argument here?

Definition at line 295 of file StateMachineImp.cc.

References fBufferEvents, GetCurrentState(), HandleEvent(), IsRunning(), kSM_FatalError, kYellow, Lock(), MessageImp::Out(), PushEvent(), and UnLock().

296 {
297  if (/*GetCurrentState()<0 ||*/ GetCurrentState()==kSM_FatalError)
298  {
299  Out() << kYellow << "State<0 or FatalError: Event ignored." << endl;
300  return false;
301  }
302 
303  if (IsRunning() || fBufferEvents)
304  {
305  Event *event = new Event(evt, ptr, siz);
306  //Debug("Posted: "+event->GetName());
307  PushEvent(event);
308  }
309  else
310  {
311  // FIXME: Is this thread safe? (Yes, because the data is copied)
312  // But two handlers could be called at the same time. Do we
313  // need to lock the handlers? (Dim + console)
314  // FIXME: Is copying of the data necessary?
315  const Event event(evt, ptr, siz);
316  Lock();
317  HandleEvent(event);
318  UnLock();
319  }
320  return true;
321 }
int GetCurrentState() const
return the current state of the machine
Fatal error: stop program.
Set color Yellow.
Definition: WindowLog.h:19
bool HandleEvent(const EventImp &evt)
virtual void UnLock()
std::ostream & Out() const
Definition: MessageImp.h:73
virtual void PushEvent(Event *cmd)
This is a flag which is set true if the main loop should stop.
Concerete implementation of an EventImp stroring name, format, data and time.
Definition: Event.h:6
virtual void Lock()
bool IsRunning() const
Used to check if the main loop is already running or still running.
bool fBufferEvents
Conditional to signal run the an event is waiting.

+ Here is the call graph for this function: