OpenASIP 2.2
Loading...
Searching...
No Matches
ProximLineReader.hh
Go to the documentation of this file.
1/*
2 Copyright (c) 2002-2009 Tampere University.
3
4 This file is part of TTA-Based Codesign Environment (TCE).
5
6 Permission is hereby granted, free of charge, to any person obtaining a
7 copy of this software and associated documentation files (the "Software"),
8 to deal in the Software without restriction, including without limitation
9 the rights to use, copy, modify, merge, publish, distribute, sublicense,
10 and/or sell copies of the Software, and to permit persons to whom the
11 Software is furnished to do so, subject to the following conditions:
12
13 The above copyright notice and this permission notice shall be included in
14 all copies or substantial portions of the Software.
15
16 THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
17 IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
18 FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
19 THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
20 LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
21 FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
22 DEALINGS IN THE SOFTWARE.
23 */
24/**
25 * @file ProximLineReader.hh
26 *
27 * Declaration of ProximLineReader class.
28 *
29 * @author Veli-Pekka Jääskeläinen 2005 (vjaaskel-no.spam-cs.tut.fi)
30 * @note rating: red
31 */
32
33#ifndef TTA_PROXIM_LINE_READER_HH
34#define TTA_PROXIM_LINE_READER_HH
35
36#include <iostream>
37#include <wx/wx.h>
38#include <string>
39#include <queue>
40#include "LineReader.hh"
41#include "Application.hh"
42#include "Exception.hh"
43
44/**
45 * Handles user input passing between the simulator and GUI threads in Proxim.
46 *
47 * This class is designed to act as an interface between two threads:
48 * A GUI thread handling the user interface, and a worker thread running the
49 * simulator engine. The worker thread waits for the user input
50 * by listening to the 'input_' condition. When the line reader receives
51 * input from the GUI thread, the worker thread is signaled about the input
52 * by setting the input_ condition. If the worker thread is busy and not
53 * listening to the input_ condition signal when the GUI thread signals
54 * about user input, the signal is lost and the user input is ignored.
55 * Therefore the user input should be disabled in the GUI when the worker
56 * thread is busy. ProximLineReader requests user input and sends simulator
57 * engine output to the GUI thread using SimulatorEvents and the standard
58 * wxWidgets event handling system.
59 */
61public:
63 virtual ~ProximLineReader();
64
65 virtual void initialize(
66 std::string defPrompt = "",
67 FILE* in = stdin,
68 FILE* out = stdout,
69 FILE* err = stderr);
70
71 virtual std::string readLine(std::string prompt = "");
72
73 virtual char charQuestion(
74 std::string question, std::string allowedChars,
75 bool caseSensitive = false, char defaultAnswer = '\0');
76
77 void input(std::string command);
78
79 virtual std::ostream& outputStream();
80 void output(std::string text);
81
82 virtual void setInputHistoryLog(const std::string& historyFilename);
83
84 std::string inputHistoryFilename() const;
85
86private:
87 /// Copying not allowed.
89 /// Assignment not allowed.
91 wxMutex* mutex_;
92 /// Condition, which is signaled when user input is received from the GUI.
93 wxCondition* input_;
94 /// Input prompt.
95 std::string prompt_;
96 /// Input queue.
97 std::queue<std::string> inputQueue_;
98 /// GUI to send the events to.
99 wxEvtHandler* gui_;
100 /// Output stream which converts the output to SimulatorEvents.
101 std::ostream* outputStream_;
102
103 /// Name of the input history file.
104 std::string historyFile_;
105
106 static const std::string DEFAULT_LOG_FILE_NAME;
107};
108
109
110/**
111 * Stream buffer for the ProximLROutputStream.
112 *
113 * This streambuffer converts the stream output to SimulatorEvents when
114 * the buffer cotnetnts is flushed.
115 */
116class ProximLROutputBuffer : public std::streambuf {
117public:
119 virtual ~ProximLROutputBuffer();
120protected:
121 int overflow(int);
122 int sync();
123private:
124 void flushBuffer();
126 const unsigned int BUFFER_SIZE;
127
128};
129
130
131/**
132 * An output stream which converts stream output to SimulatorEvents.
133 */
134class ProximLROutputStream : public std::ostream {
135public:
137 virtual ~ProximLROutputStream();
138};
139
140#endif
const unsigned int BUFFER_SIZE
ProximLineReader * lineReader_
wxCondition * input_
Condition, which is signaled when user input is received from the GUI.
virtual std::ostream & outputStream()
std::string prompt_
Input prompt.
ProximLineReader & operator=(const ProximLineReader &)
Assignment not allowed.
virtual void initialize(std::string defPrompt="", FILE *in=stdin, FILE *out=stdout, FILE *err=stderr)
std::ostream * outputStream_
Output stream which converts the output to SimulatorEvents.
ProximLineReader(const ProximLineReader &)
Copying not allowed.
void input(std::string command)
wxEvtHandler * gui_
GUI to send the events to.
virtual void setInputHistoryLog(const std::string &historyFilename)
virtual std::string readLine(std::string prompt="")
std::queue< std::string > inputQueue_
Input queue.
void output(std::string text)
std::string historyFile_
Name of the input history file.
std::string inputHistoryFilename() const
virtual char charQuestion(std::string question, std::string allowedChars, bool caseSensitive=false, char defaultAnswer='\0')
static const std::string DEFAULT_LOG_FILE_NAME
virtual ~ProximLineReader()