| 1 | #ifndef FACT_LocalControl
|
|---|
| 2 | #define FACT_LocalControl
|
|---|
| 3 |
|
|---|
| 4 | #include <ostream>
|
|---|
| 5 |
|
|---|
| 6 | class StateMachineImp;
|
|---|
| 7 |
|
|---|
| 8 | // **************************************************************************
|
|---|
| 9 | /** @class LocalControl
|
|---|
| 10 |
|
|---|
| 11 | @brief Implements a local control for a StateMachine based on a Readline class
|
|---|
| 12 |
|
|---|
| 13 | This template implements all functions which overwrite any function from the
|
|---|
| 14 | Readline class needed for a local control of a state machien. Since
|
|---|
| 15 | several derivatives of the Readline class implement different kind of
|
|---|
| 16 | Readline access, this class can be derived by any of them due to its
|
|---|
| 17 | template argument. However, the normal case will be deriving it from
|
|---|
| 18 | either Console or Shell.
|
|---|
| 19 |
|
|---|
| 20 | @tparam T
|
|---|
| 21 | The base class for RemoteControl. Either Readlien or a class
|
|---|
| 22 | deriving from it. This is usually either Console or Shell.
|
|---|
| 23 |
|
|---|
| 24 | **/
|
|---|
| 25 | // **************************************************************************
|
|---|
| 26 | #include <boost/filesystem.hpp>
|
|---|
| 27 |
|
|---|
| 28 | #include "WindowLog.h"
|
|---|
| 29 | #include "StateMachineImp.h"
|
|---|
| 30 |
|
|---|
| 31 | using namespace std;
|
|---|
| 32 |
|
|---|
| 33 | template <class T>
|
|---|
| 34 | class LocalControl : public T
|
|---|
| 35 | {
|
|---|
| 36 | private:
|
|---|
| 37 | char **Completion(const char *text, int pos, int)
|
|---|
| 38 | {
|
|---|
| 39 | return pos>0 ? 0 : T::Complete(fStateMachine->GetEventNames(), text);
|
|---|
| 40 | }
|
|---|
| 41 |
|
|---|
| 42 | protected:
|
|---|
| 43 | StateMachineImp *fStateMachine;
|
|---|
| 44 |
|
|---|
| 45 | std::ostream &lout;
|
|---|
| 46 |
|
|---|
| 47 | std::string fName;
|
|---|
| 48 |
|
|---|
| 49 | LocalControl(const char *name) : T(name),
|
|---|
| 50 | fStateMachine(0), lout(T::GetStreamIn()),
|
|---|
| 51 | fName(boost::filesystem::path(name).filename())
|
|---|
| 52 | { }
|
|---|
| 53 |
|
|---|
| 54 | //bool PrintGeneralHelp()
|
|---|
| 55 | //bool PrintKeyBindings()
|
|---|
| 56 | bool PrintCommands()
|
|---|
| 57 | {
|
|---|
| 58 | lout << endl << kBold << "List of commands:" << endl;
|
|---|
| 59 | fStateMachine->PrintListOfEvents(lout);
|
|---|
| 60 | //lout << endl;
|
|---|
| 61 |
|
|---|
| 62 | return true;
|
|---|
| 63 | }
|
|---|
| 64 |
|
|---|
| 65 | bool Process(const std::string &str)
|
|---|
| 66 | {
|
|---|
| 67 | if (T::Process(str))
|
|---|
| 68 | return true;
|
|---|
| 69 |
|
|---|
| 70 | return !fStateMachine->PostEvent(lout, str);
|
|---|
| 71 | }
|
|---|
| 72 |
|
|---|
| 73 | public:
|
|---|
| 74 |
|
|---|
| 75 | void SetReceiver(StateMachineImp &imp) { fStateMachine = &imp; }
|
|---|
| 76 |
|
|---|
| 77 | void Run(const char * = 0)
|
|---|
| 78 | {
|
|---|
| 79 | lout << endl;
|
|---|
| 80 | lout << kBlue << kBold << "You are on the " << fName << " terminal of the MCP -" << endl;
|
|---|
| 81 | lout << kBlue << kBold << "the Master Control Program." << endl;
|
|---|
| 82 | lout << endl;
|
|---|
| 83 | lout << kBlue << kBold << "Hello Flynn..." << endl;
|
|---|
| 84 | lout << endl;
|
|---|
| 85 |
|
|---|
| 86 | T::Run();
|
|---|
| 87 | }
|
|---|
| 88 | };
|
|---|
| 89 |
|
|---|
| 90 | // **************************************************************************
|
|---|
| 91 | /** @class LocalConsole
|
|---|
| 92 |
|
|---|
| 93 | @brief Derives the LocalControl from Control and adds prompt
|
|---|
| 94 |
|
|---|
| 95 | This is basically a LocalControl, which derives through the template
|
|---|
| 96 | argument from the Console class. It enhances the functionality of
|
|---|
| 97 | the local control with a proper updated prompt.
|
|---|
| 98 |
|
|---|
| 99 | */
|
|---|
| 100 | // **************************************************************************
|
|---|
| 101 | #include "Console.h"
|
|---|
| 102 | #include "tools.h"
|
|---|
| 103 |
|
|---|
| 104 | class LocalConsole : public LocalControl<Console>
|
|---|
| 105 | {
|
|---|
| 106 | public:
|
|---|
| 107 | LocalConsole(const char *name, bool continous=false)
|
|---|
| 108 | : LocalControl<Console>(name)
|
|---|
| 109 | {
|
|---|
| 110 | SetContinous(continous);
|
|---|
| 111 | }
|
|---|
| 112 |
|
|---|
| 113 | string GetUpdatePrompt() const;
|
|---|
| 114 | };
|
|---|
| 115 |
|
|---|
| 116 | // **************************************************************************
|
|---|
| 117 | /** @class LocalShell
|
|---|
| 118 |
|
|---|
| 119 | @brief Derives the LocalControl from Shell and adds a colored prompt
|
|---|
| 120 |
|
|---|
| 121 | This is basically a LocalControl, which derives through the template
|
|---|
| 122 | argument from the Shell class. It enhances the functionality of
|
|---|
| 123 | the local control with a proper updated prompt.
|
|---|
| 124 |
|
|---|
| 125 | */
|
|---|
| 126 | // **************************************************************************
|
|---|
| 127 | #include "Shell.h"
|
|---|
| 128 |
|
|---|
| 129 | class LocalShell : public LocalControl<Shell>
|
|---|
| 130 | {
|
|---|
| 131 | public:
|
|---|
| 132 | LocalShell(const char *name, bool = false)
|
|---|
| 133 | : LocalControl<Shell>(name) { }
|
|---|
| 134 |
|
|---|
| 135 | string GetUpdatePrompt() const;
|
|---|
| 136 | };
|
|---|
| 137 |
|
|---|
| 138 | #endif
|
|---|