VirtualBox

source: vbox/trunk/src/VBox/Debugger/VBoxDbgConsole.h@ 8911

Last change on this file since 8911 was 8155, checked in by vboxsync, 17 years ago

The Big Sun Rebranding Header Change

  • Property svn:eol-style set to native
  • Property svn:keywords set to Author Date Id Revision
File size: 7.4 KB
Line 
1/** @file
2 *
3 * VBox Debugger GUI - Console.
4 */
5
6/*
7 * Copyright (C) 2006-2007 Sun Microsystems, Inc.
8 *
9 * This file is part of VirtualBox Open Source Edition (OSE), as
10 * available from http://www.virtualbox.org. This file is free software;
11 * you can redistribute it and/or modify it under the terms of the GNU
12 * General Public License (GPL) as published by the Free Software
13 * Foundation, in version 2 as it comes in the "COPYING" file of the
14 * VirtualBox OSE distribution. VirtualBox OSE is distributed in the
15 * hope that it will be useful, but WITHOUT ANY WARRANTY of any kind.
16 *
17 * Please contact Sun Microsystems, Inc., 4150 Network Circle, Santa
18 * Clara, CA 95054 USA or visit http://www.sun.com if you need
19 * additional information or have any questions.
20 */
21
22#ifndef __VBoxDbgConsole_h__
23#define __VBoxDbgConsole_h__
24
25#include "VBoxDbgBase.h"
26
27#include <qtextedit.h>
28#include <qcombobox.h>
29#include <qvbox.h>
30#include <qtimer.h>
31
32#include <iprt/critsect.h>
33#include <iprt/semaphore.h>
34
35
36class VBoxDbgConsoleOutput : public QTextEdit
37{
38 Q_OBJECT
39
40public:
41 /**
42 * Constructor.
43 *
44 * @param pParent Parent Widget.
45 * @param pszName Widget name.
46 */
47 VBoxDbgConsoleOutput(QWidget *pParent = NULL, const char *pszName = NULL);
48
49 /**
50 * Destructor
51 */
52 virtual ~VBoxDbgConsoleOutput();
53
54 /**
55 * Appends text.
56 * This differs from QTextEdit::append() in that it won't start on a new paragraph
57 * unless the previous char was a newline ('\n').
58 *
59 * @param rStr The text string to append.
60 */
61 virtual void appendText(const QString &rStr);
62
63protected:
64 /** The current line (paragraph) number. */
65 unsigned m_uCurLine;
66 /** The position in the current line. */
67 unsigned m_uCurPos;
68};
69
70
71/**
72 * The Debugger Console Input widget.
73 *
74 * This is a combobox which only responds to <return>.
75 */
76class VBoxDbgConsoleInput : public QComboBox
77{
78 Q_OBJECT
79
80public:
81 /**
82 * Constructor.
83 *
84 * @param pParent Parent Widget.
85 * @param pszName Widget name.
86 */
87 VBoxDbgConsoleInput(QWidget *pParent = NULL, const char *pszName = NULL);
88
89 /**
90 * Destructor
91 */
92 virtual ~VBoxDbgConsoleInput();
93
94 /**
95 * We overload this method to get signaled upon returnPressed().
96 *
97 * See QComboBox::setLineEdit for full description.
98 * @param pEdit The new line edit widget.
99 * @remark This won't be called during the constructor.
100 */
101 virtual void setLineEdit(QLineEdit *pEdit);
102
103signals:
104 /**
105 * New command submitted.
106 */
107 void commandSubmitted(const QString &rCommand);
108
109private slots:
110 /**
111 * Returned was pressed.
112 *
113 * Will emit commandSubmitted().
114 */
115 void returnPressed();
116
117protected:
118 /** The current blank entry. */
119 int m_iBlankItem;
120};
121
122
123/**
124 * The Debugger Console.
125 */
126class VBoxDbgConsole : public QVBox, public VBoxDbgBase
127{
128 Q_OBJECT
129
130public:
131 /**
132 * Constructor.
133 *
134 * @param pVM VM handle.
135 * @param pParent Parent Widget.
136 * @param pszName Widget name.
137 */
138 VBoxDbgConsole(PVM pVM, QWidget *pParent = NULL, const char *pszName = NULL);
139
140 /**
141 * Destructor
142 */
143 virtual ~VBoxDbgConsole();
144
145protected slots:
146 /**
147 * Handler called when a command is submitted.
148 * (Enter or return pressed in the combo box.)
149 *
150 * @param rCommand The submitted command.
151 */
152 void commandSubmitted(const QString &rCommand);
153
154 /**
155 * Updates the output with what's currently in the output buffer.
156 * This is called by a timer or a User event posted by the debugger thread.
157 */
158 void updateOutput();
159
160
161protected:
162 /**
163 * Lock the object.
164 */
165 void lock();
166
167 /**
168 * Unlocks the object.
169 */
170 void unlock();
171
172protected:
173 /** @name Debug Console Backend.
174 * @{
175 */
176
177
178 /**
179 * Checks if there is input.
180 *
181 * @returns true if there is input ready.
182 * @returns false if there not input ready.
183 * @param pBack Pointer to VBoxDbgConsole::m_Back.
184 * @param cMillies Number of milliseconds to wait on input data.
185 */
186 static DECLCALLBACK(bool) backInput(PDBGCBACK pBack, uint32_t cMillies);
187
188 /**
189 * Read input.
190 *
191 * @returns VBox status code.
192 * @param pBack Pointer to VBoxDbgConsole::m_Back.
193 * @param pvBuf Where to put the bytes we read.
194 * @param cbBuf Maximum nymber of bytes to read.
195 * @param pcbRead Where to store the number of bytes actually read.
196 * If NULL the entire buffer must be filled for a
197 * successful return.
198 */
199 static DECLCALLBACK(int) backRead(PDBGCBACK pBack, void *pvBuf, size_t cbBuf, size_t *pcbRead);
200
201 /**
202 * Write (output).
203 *
204 * @returns VBox status code.
205 * @param pBack Pointer to VBoxDbgConsole::m_Back.
206 * @param pvBuf What to write.
207 * @param cbBuf Number of bytes to write.
208 * @param pcbWritten Where to store the number of bytes actually written.
209 * If NULL the entire buffer must be successfully written.
210 */
211 static DECLCALLBACK(int) backWrite(PDBGCBACK pBack, const void *pvBuf, size_t cbBuf, size_t *pcbWritten);
212
213 /**
214 * The Debugger Console Thread
215 *
216 * @returns VBox status code (ignored).
217 * @param Thread The thread handle.
218 * @param pvUser Pointer to the VBoxDbgConsole object.s
219 */
220 static DECLCALLBACK(int) backThread(RTTHREAD Thread, void *pvUser);
221
222 /** @} */
223
224protected:
225 /**
226 * Use to get the GUI thread to insert the output data.
227 */
228 void customEvent(QCustomEvent *pEvent);
229
230protected:
231 /** The output widget. */
232 VBoxDbgConsoleOutput *m_pOutput;
233 /** The input widget. */
234 VBoxDbgConsoleInput *m_pInput;
235 /** A hack to restore focus to the combobox after a command execution. */
236 bool m_fInputRestoreFocus;
237 /** The input buffer. */
238 char *m_pszInputBuf;
239 /** The amount of input in the buffer. */
240 size_t m_cbInputBuf;
241 /** The allocated size of the buffer. */
242 size_t m_cbInputBufAlloc;
243
244 /** The output buffer. */
245 char *m_pszOutputBuf;
246 /** The amount of output in the buffer. */
247 size_t m_cbOutputBuf;
248 /** The allocated size of the buffer. */
249 size_t m_cbOutputBufAlloc;
250 /** The timer object used to process output in a delayed fashion. */
251 QTimer m_Timer;
252 /** Set when an output update is pending. */
253 bool volatile m_fUpdatePending;
254
255 /** The debugger console thread. */
256 RTTHREAD m_Thread;
257 /** The event semaphore used to signal the debug console thread about input. */
258 RTSEMEVENT m_EventSem;
259 /** The critical section used to lock the object. */
260 RTCRITSECT m_Lock;
261 /** When set the thread will cause the debug console thread to terminate. */
262 bool volatile m_fTerminate;
263
264 /** The debug console backend structure.
265 * Use VBOXDBGCONSOLE_FROM_DBGCBACK to convert the DBGCBACK pointer to a object pointer. */
266 struct VBoxDbgConsoleBack
267 {
268 DBGCBACK Core;
269 VBoxDbgConsole *pSelf;
270 } m_Back;
271
272 /**
273 * Converts a pointer to VBoxDbgConsole::m_Back to VBoxDbgConsole pointer.
274 * @todo find a better way because offsetof is undefined on objects and g++ gets very noisy because of that.
275 */
276 #define VBOXDBGCONSOLE_FROM_DBGCBACK(pBack) ( ((struct VBoxDbgConsoleBack *)(pBack))->pSelf )
277};
278
279
280#endif
Note: See TracBrowser for help on using the repository browser.

© 2024 Oracle Support Privacy / Do Not Sell My Info Terms of Use Trademark Policy Automated Access Etiquette