1 #ifndef FACT_LocalControl 2 #define FACT_LocalControl 24 #include <boost/version.hpp> 25 #include <boost/filesystem.hpp> 40 return pos>0 ? 0 : T::Complete(fStateMachine->GetEventNames(), text);
51 fStateMachine(0), lout(T::GetStreamIn()),
52 #
if BOOST_VERSION < 104600
53 fName(
boost::filesystem::path(name).filename())
55 fName(
boost::filesystem::path(name).filename().string())
62 lout <<
" " <<
kUnderline <<
"Specific commands:" << endl;
63 lout <<
kBold <<
" ac,allowed " <<
kReset <<
"Display a list of all currently allowed commands." << endl;
64 lout <<
kBold <<
" st,states " <<
kReset <<
"Display a list of the available states with description." << endl;
65 lout <<
kBold <<
" > <text> " <<
kReset <<
"Echo <text> to the output stream" << endl;
66 lout <<
kBold <<
" .s " <<
kReset <<
"Wait for the state-machine to change to the given state.\n";
67 lout <<
" " " .s <server> [<state> [<timeout> [<label>]]]\n";
68 lout <<
" " "<server> The server for which state to wait (e.g. FTM_CONTROL)\n";
69 lout <<
" " "<state> The state id (see 'states') for which to wait (e.g. 3)\n";
70 lout <<
" " "<imeout> A timeout in millisenconds how long to wait (e.g. 500)\n";
71 lout <<
" " "<label> A label until which everything is skipped in case of timeout\n";
77 lout << endl <<
kBold <<
"List of commands:" << endl;
86 if (str.substr(0, 2)==
"h " || str.substr(0, 5)==
"help ")
94 if (str==
"states" || str==
"st")
99 if (str==
"allowed" || str==
"ac")
101 lout << endl <<
kBold <<
"List of commands allowed in current state:" << endl;
107 if (str.substr(0, 3)==
".s ")
109 istringstream in(str.substr(3));
111 int state=-100, ms=0;
116 lout <<
kRed <<
"Couldn't parse state id in '" << str.substr(3) <<
"'" << endl;
130 if (in.fail() && !in.eof())
132 lout <<
kRed <<
"Invalid label in '" << str.substr(3) <<
"'" << endl;
150 return !fStateMachine->
PostEvent(lout, str);
196 SetContinous(continous);
201 return GetLinePrompt()+
" " 202 "\033[34m\033[1m"+fName+
"\033[0m:" 203 "\033[32m\033[1m"+fStateMachine->GetStateName()+
"\033[0m> ";
228 return GetLinePrompt()+
' '+fName+
':'+fStateMachine->GetStateName()+
"> ";
int Comment(const std::string &str)
Derives the LocalControl from Control and adds prompt.
This is an extension to the Readline class provding a colored output.
void PrintListOfStates(std::ostream &out) const
string GetUpdatePrompt() const
bool PrintGeneralHelp(std::ostream &out, const std::string &name)
int GetCurrentState() const
return the current state of the machine
Base class for a state machine implementation.
bool PostEvent(std::ostream &lout, const std::string &str)
Post an event to the event queue.
This is an extension to the Readline class provding buffered output.
void SetReceiver(StateMachineImp &imp)
Adds some functionality to boost::posix_time::ptime for our needs.
char ** Completion(const char *text, int pos, int)
Derives the LocalControl from Shell and adds a colored prompt.
bool Process(const std::string &str)
LocalStream(const char *name, bool null=false)
StateMachineImp * fStateMachine
LocalShell(const char *name, bool=false)
LocalConsole(const char *name, bool continous=false)
LocalControl(const char *name)
bool Process(std::ostream &out, const std::string &str)
Implements a local control for a StateMachine based on a Readline class.
void PrintListOfEvents(std::ostream &out, const std::string &evt="")
string GetUpdatePrompt() const
void PrintListOfAllowedEvents(std::ostream &out)
Derives the LocalControl from ConsoleStream.
Do not initialize the time.
Implementation of a console based user shell with an input and output window.