source: trunk/FACT++/src/StateMachine.cc@ 20115

Last change on this file since 20115 was 14002, checked in by tbretz, 13 years ago
Replaced some 'const char*' with a const-refernce to a std::string
File size: 2.3 KB
Line 
1// **************************************************************************
2/** @class StateMachine
3
4 @brief Class for a state machine implementation just on the console
5
6This class implements a StateMachine which is to be controlled from the
7console. It redirects all output posted via MessageImp to the console
8and, if the stream is a WindowLog, adds colors.
9
10When constructing the Dim network is started and while dstruction it is
11stopped.
12
13@todo
14 Do we really need to create Event-objects? Shouldn't we add a
15 ProcessEvent function which takes an event as argument instead?
16 Or something else which easily allows to add data to the events?
17
18*/
19// **************************************************************************
20#include "StateMachine.h"
21
22#include "WindowLog.h"
23
24#include "Event.h"
25#include "Time.h"
26#include "Shell.h"
27
28#include "tools.h"
29
30using namespace std;
31
32// --------------------------------------------------------------------------
33//
34//! Overwrite StateMachineImp::AddTransition to create an Event object
35//! instead of an EventImp object. The event name propagated is name.
36//!
37//! For parameter description see StateMachineImp.
38//!
39EventImp *StateMachine::CreateEvent(const string &name, const string &fmt)
40{
41 return new Event(GetName()+'/'+name, fmt);
42}
43
44// --------------------------------------------------------------------------
45//
46//! This is (analog to StateMachineDim::commandHandler()) the function which
47//! is called if an event from the console is received. It then is
48//! supposed to send the event to the messge queue or handle it directly
49//! if the machine was not yet started.
50//!
51//! If fCurrentState is smaller than 0 or we are in kSM_FatalError state,
52//! all incoming commands are ignored.
53//!
54//! The commandHandler will go through the list of available commands
55//! (fListOfEventss). If the received command was recognized, it is added
56//! via PostCommand into the fifo.
57//!
58//! @todo
59//! - Fix the exit when cmd is not of type EventImp
60//! - Do we need a possibility to suppress a call to "HandleEvent"
61//! or is a state<0 enough?
62//
63bool StateMachine::ProcessCommand(const std::string &str, const char *ptr, size_t siz)
64{
65 EventImp *evt = FindEvent(str);
66 if (!evt)
67 return false;
68
69 PostEvent(*evt, ptr, siz);
70 return true;
71}
72
Note: See TracBrowser for help on using the repository browser.