OpenASIP
2.0
|
#include <ProximLineReader.hh>
Public Member Functions | |
ProximLineReader () | |
virtual | ~ProximLineReader () |
virtual void | initialize (std::string defPrompt="", FILE *in=stdin, FILE *out=stdout, FILE *err=stderr) |
virtual std::string | readLine (std::string prompt="") |
virtual char | charQuestion (std::string question, std::string allowedChars, bool caseSensitive=false, char defaultAnswer='\0') |
void | input (std::string command) |
virtual std::ostream & | outputStream () |
void | output (std::string text) |
virtual void | setInputHistoryLog (const std::string &historyFilename) |
std::string | inputHistoryFilename () const |
![]() | |
LineReader (std::istream &iStream=std::cin, std::ostream &oStream=std::cout) | |
virtual | ~LineReader () |
bool | confirmation (std::string question, char defaultAnswer='n', char yesChar='y', char noChar='n') |
virtual void | setSaveInputHistoryToFile (bool flag) |
virtual bool | saveInputHistoryToFile () const |
virtual void | setInputHistoryLength (std::size_t length) |
virtual size_t | inputHistoryMaxLength () const |
virtual std::size_t | inputsInHistory () const |
virtual std::string | inputHistoryEntry (std::size_t age) const |
Private Member Functions | |
ProximLineReader (const ProximLineReader &) | |
Copying not allowed. More... | |
ProximLineReader & | operator= (const ProximLineReader &) |
Assignment not allowed. More... | |
Private Attributes | |
wxMutex * | mutex_ |
wxCondition * | input_ |
Condition, which is signaled when user input is received from the GUI. More... | |
std::string | prompt_ |
Input prompt. More... | |
std::queue< std::string > | inputQueue_ |
Input queue. More... | |
wxEvtHandler * | gui_ |
GUI to send the events to. More... | |
std::ostream * | outputStream_ |
Output stream which converts the output to SimulatorEvents. More... | |
std::string | historyFile_ |
Name of the input history file. More... | |
Static Private Attributes | |
static const std::string | DEFAULT_LOG_FILE_NAME = ".proximHistory" |
Additional Inherited Members | |
![]() | |
void | setInitialized () |
bool | initialized () const |
void | putInInputHistory (const std::string &inputLine) |
Handles user input passing between the simulator and GUI threads in Proxim.
This class is designed to act as an interface between two threads: A GUI thread handling the user interface, and a worker thread running the simulator engine. The worker thread waits for the user input by listening to the 'input_' condition. When the line reader receives input from the GUI thread, the worker thread is signaled about the input by setting the input_ condition. If the worker thread is busy and not listening to the input_ condition signal when the GUI thread signals about user input, the signal is lost and the user input is ignored. Therefore the user input should be disabled in the GUI when the worker thread is busy. ProximLineReader requests user input and sends simulator engine output to the GUI thread using SimulatorEvents and the standard wxWidgets event handling system.
Definition at line 60 of file ProximLineReader.hh.
ProximLineReader::ProximLineReader | ( | ) |
The Constructor.
Definition at line 48 of file ProximLineReader.cc.
References DEFAULT_LOG_FILE_NAME, and setInputHistoryLog().
|
virtual |
|
private |
Copying not allowed.
|
virtual |
Requests answer to a char question from the GUI thread.
question | Question to ask from the user. |
allowedChars | Allowed answers. |
caseSensitive | True, if the answer characters are case sensitive. |
defaultAnswer | Default answer to the question. |
Implements LineReader.
Definition at line 148 of file ProximLineReader.cc.
References LineReader::initialized(), input_, inputQueue_, and output().
|
virtual |
Initializes the linereader.
The FILE* pointer parameters specified in the base class are not used.
defPrompt | Default prompt. |
Implements LineReader.
Definition at line 76 of file ProximLineReader.cc.
References gui_, outputStream(), prompt_, LineReader::setInitialized(), and OperationGlobals::setOutputStream().
Referenced by ProximSimulationThread::initialize().
void ProximLineReader::input | ( | std::string | input | ) |
This function is called by the GUI thread to set the user input.
The input_ condtion is signaled about the user input.
command | The user input. |
Definition at line 131 of file ProximLineReader.cc.
References input_, and inputQueue_.
Referenced by ProximExecuteFileCmd::Do(), ProximQuitCmd::Do(), ProximCmdHistoryWindow::onCommandDClick(), AddBreakpointDialog::onOK(), WatchPropertiesDialog::onOK(), AddWatchDialog::onOK(), BreakpointPropertiesDialog::onOK(), SimulatorSettingsDialog::onOK(), readLine(), and ConsoleWindow::textEntered().
std::string ProximLineReader::inputHistoryFilename | ( | ) | const |
Returns input history log file name.
Definition at line 310 of file ProximLineReader.cc.
References historyFile_.
Referenced by SimulatorSettingsDialog::onOK(), and SimulatorSettingsDialog::TransferDataToWindow().
|
private |
Assignment not allowed.
void ProximLineReader::output | ( | std::string | text | ) |
Definition at line 194 of file ProximLineReader.cc.
References SimulatorEvent::EVT_SIMULATOR_OUTPUT, and gui_.
Referenced by charQuestion(), ProximLROutputBuffer::flushBuffer(), ProximLROutputBuffer::overflow(), and readLine().
|
virtual |
Returns an outputstream, which the worker thread can use to write text to the GUI.
Reimplemented from LineReader.
Definition at line 185 of file ProximLineReader.cc.
References outputStream_.
Referenced by initialize().
|
virtual |
Waits for input from the GUI thread.
The input_ condition timeout is set as 100ms. After the timeout an empty input is returned. This is done because the worker thread needs to check its stop and delete requests at regular intervals.
prompt | Prompt used for requesting the user input. |
Implements LineReader.
Definition at line 98 of file ProximLineReader.cc.
References LineReader::initialized(), input(), input_, inputQueue_, mutex_, output(), prompt_, and LineReader::putInInputHistory().
Referenced by ProximSimulationThread::Entry().
|
virtual |
Sets the name of the input history log file.
hisoryFileName | Name of the input history log file. |
Reimplemented from LineReader.
Definition at line 299 of file ProximLineReader.cc.
References historyFile_, and LineReader::setInputHistoryLog().
Referenced by ProximLineReader().
|
staticprivate |
Definition at line 106 of file ProximLineReader.hh.
Referenced by ProximLineReader().
|
private |
GUI to send the events to.
Definition at line 99 of file ProximLineReader.hh.
Referenced by initialize(), and output().
|
private |
Name of the input history file.
Definition at line 104 of file ProximLineReader.hh.
Referenced by inputHistoryFilename(), and setInputHistoryLog().
|
private |
Condition, which is signaled when user input is received from the GUI.
Definition at line 93 of file ProximLineReader.hh.
Referenced by charQuestion(), input(), readLine(), and ~ProximLineReader().
|
private |
Input queue.
Definition at line 97 of file ProximLineReader.hh.
Referenced by charQuestion(), input(), and readLine().
|
private |
Definition at line 91 of file ProximLineReader.hh.
Referenced by readLine(), and ~ProximLineReader().
|
private |
Output stream which converts the output to SimulatorEvents.
Definition at line 101 of file ProximLineReader.hh.
Referenced by outputStream().
|
private |
Input prompt.
Definition at line 95 of file ProximLineReader.hh.
Referenced by initialize(), and readLine().