VirtualBox

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

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

Fixed the file headers.

  • Property svn:eol-style set to native
  • Property svn:keywords set to Author Date Id Revision
File size: 8.4 KB
Line 
1/* $Id: VBoxDbgConsole.h 9269 2008-05-31 14:53:24Z vboxsync $ */
2/** @file
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#include <iprt/thread.h>
35
36
37class VBoxDbgConsoleOutput : public QTextEdit
38{
39 Q_OBJECT
40
41public:
42 /**
43 * Constructor.
44 *
45 * @param pParent Parent Widget.
46 * @param pszName Widget name.
47 */
48 VBoxDbgConsoleOutput(QWidget *pParent = NULL, const char *pszName = NULL);
49
50 /**
51 * Destructor
52 */
53 virtual ~VBoxDbgConsoleOutput();
54
55 /**
56 * Appends text.
57 * This differs from QTextEdit::append() in that it won't start on a new paragraph
58 * unless the previous char was a newline ('\n').
59 *
60 * @param rStr The text string to append.
61 */
62 virtual void appendText(const QString &rStr);
63
64protected:
65 /** The current line (paragraph) number. */
66 unsigned m_uCurLine;
67 /** The position in the current line. */
68 unsigned m_uCurPos;
69 /** The handle to the GUI thread. */
70 RTNATIVETHREAD m_hGUIThread;
71};
72
73
74/**
75 * The Debugger Console Input widget.
76 *
77 * This is a combobox which only responds to <return>.
78 */
79class VBoxDbgConsoleInput : public QComboBox
80{
81 Q_OBJECT
82
83public:
84 /**
85 * Constructor.
86 *
87 * @param pParent Parent Widget.
88 * @param pszName Widget name.
89 */
90 VBoxDbgConsoleInput(QWidget *pParent = NULL, const char *pszName = NULL);
91
92 /**
93 * Destructor
94 */
95 virtual ~VBoxDbgConsoleInput();
96
97 /**
98 * We overload this method to get signaled upon returnPressed().
99 *
100 * See QComboBox::setLineEdit for full description.
101 * @param pEdit The new line edit widget.
102 * @remark This won't be called during the constructor.
103 */
104 virtual void setLineEdit(QLineEdit *pEdit);
105
106signals:
107 /**
108 * New command submitted.
109 */
110 void commandSubmitted(const QString &rCommand);
111
112private slots:
113 /**
114 * Returned was pressed.
115 *
116 * Will emit commandSubmitted().
117 */
118 void returnPressed();
119
120protected:
121 /** The current blank entry. */
122 int m_iBlankItem;
123 /** The handle to the GUI thread. */
124 RTNATIVETHREAD m_hGUIThread;
125};
126
127
128/**
129 * The Debugger Console.
130 */
131class VBoxDbgConsole : public QVBox, public VBoxDbgBase
132{
133 Q_OBJECT
134
135public:
136 /**
137 * Constructor.
138 *
139 * @param pVM VM handle.
140 * @param pParent Parent Widget.
141 * @param pszName Widget name.
142 */
143 VBoxDbgConsole(PVM pVM, QWidget *pParent = NULL, const char *pszName = NULL);
144
145 /**
146 * Destructor
147 */
148 virtual ~VBoxDbgConsole();
149
150protected slots:
151 /**
152 * Handler called when a command is submitted.
153 * (Enter or return pressed in the combo box.)
154 *
155 * @param rCommand The submitted command.
156 */
157 void commandSubmitted(const QString &rCommand);
158
159 /**
160 * Updates the output with what's currently in the output buffer.
161 * This is called by a timer or a User event posted by the debugger thread.
162 */
163 void updateOutput();
164
165
166protected:
167 /**
168 * Lock the object.
169 */
170 void lock();
171
172 /**
173 * Unlocks the object.
174 */
175 void unlock();
176
177protected:
178 /** @name Debug Console Backend.
179 * @{
180 */
181
182
183 /**
184 * Checks if there is input.
185 *
186 * @returns true if there is input ready.
187 * @returns false if there not input ready.
188 * @param pBack Pointer to VBoxDbgConsole::m_Back.
189 * @param cMillies Number of milliseconds to wait on input data.
190 */
191 static DECLCALLBACK(bool) backInput(PDBGCBACK pBack, uint32_t cMillies);
192
193 /**
194 * Read input.
195 *
196 * @returns VBox status code.
197 * @param pBack Pointer to VBoxDbgConsole::m_Back.
198 * @param pvBuf Where to put the bytes we read.
199 * @param cbBuf Maximum nymber of bytes to read.
200 * @param pcbRead Where to store the number of bytes actually read.
201 * If NULL the entire buffer must be filled for a
202 * successful return.
203 */
204 static DECLCALLBACK(int) backRead(PDBGCBACK pBack, void *pvBuf, size_t cbBuf, size_t *pcbRead);
205
206 /**
207 * Write (output).
208 *
209 * @returns VBox status code.
210 * @param pBack Pointer to VBoxDbgConsole::m_Back.
211 * @param pvBuf What to write.
212 * @param cbBuf Number of bytes to write.
213 * @param pcbWritten Where to store the number of bytes actually written.
214 * If NULL the entire buffer must be successfully written.
215 */
216 static DECLCALLBACK(int) backWrite(PDBGCBACK pBack, const void *pvBuf, size_t cbBuf, size_t *pcbWritten);
217
218 /**
219 * The Debugger Console Thread
220 *
221 * @returns VBox status code (ignored).
222 * @param Thread The thread handle.
223 * @param pvUser Pointer to the VBoxDbgConsole object.s
224 */
225 static DECLCALLBACK(int) backThread(RTTHREAD Thread, void *pvUser);
226
227 /** @} */
228
229protected:
230 /**
231 * Processes GUI command posted by the console thread.
232 *
233 * Qt3 isn't thread safe on any platform, meaning there is no locking, so, as
234 * a result we have to be very careful. All operations on objects which we share
235 * with the main thread has to be posted to it so it can perform it.
236 */
237 bool event(QEvent *pEvent);
238
239protected:
240 /** The output widget. */
241 VBoxDbgConsoleOutput *m_pOutput;
242 /** The input widget. */
243 VBoxDbgConsoleInput *m_pInput;
244 /** A hack to restore focus to the combobox after a command execution. */
245 bool m_fInputRestoreFocus;
246 /** The input buffer. */
247 char *m_pszInputBuf;
248 /** The amount of input in the buffer. */
249 size_t m_cbInputBuf;
250 /** The allocated size of the buffer. */
251 size_t m_cbInputBufAlloc;
252
253 /** The output buffer. */
254 char *m_pszOutputBuf;
255 /** The amount of output in the buffer. */
256 size_t m_cbOutputBuf;
257 /** The allocated size of the buffer. */
258 size_t m_cbOutputBufAlloc;
259 /** The timer object used to process output in a delayed fashion. */
260 QTimer *m_pTimer;
261 /** Set when an output update is pending. */
262 bool volatile m_fUpdatePending;
263
264 /** The debugger console thread. */
265 RTTHREAD m_Thread;
266 /** The event semaphore used to signal the debug console thread about input. */
267 RTSEMEVENT m_EventSem;
268 /** The critical section used to lock the object. */
269 RTCRITSECT m_Lock;
270 /** When set the thread will cause the debug console thread to terminate. */
271 bool volatile m_fTerminate;
272
273 /** The debug console backend structure.
274 * Use VBOXDBGCONSOLE_FROM_DBGCBACK to convert the DBGCBACK pointer to a object pointer. */
275 struct VBoxDbgConsoleBack
276 {
277 DBGCBACK Core;
278 VBoxDbgConsole *pSelf;
279 } m_Back;
280
281 /**
282 * Converts a pointer to VBoxDbgConsole::m_Back to VBoxDbgConsole pointer.
283 * @todo find a better way because offsetof is undefined on objects and g++ gets very noisy because of that.
284 */
285 #define VBOXDBGCONSOLE_FROM_DBGCBACK(pBack) ( ((struct VBoxDbgConsoleBack *)(pBack))->pSelf )
286};
287
288
289/**
290 * Simple event class for push certain operations over
291 * onto the GUI thread.
292 */
293class VBoxDbgConsoleEvent : public QEvent
294{
295public:
296 typedef enum { kUpdate, kInputRestoreFocus, kTerminated } VBoxDbgConsoleEventType;
297 enum { kEventNumber = QEvent::User + 42 };
298
299 VBoxDbgConsoleEvent(VBoxDbgConsoleEventType enmCommand)
300 : QEvent((QEvent::Type)kEventNumber), m_enmCommand(enmCommand)
301 {
302 }
303
304 VBoxDbgConsoleEventType command() const
305 {
306 return m_enmCommand;
307 }
308
309private:
310 VBoxDbgConsoleEventType m_enmCommand;
311};
312
313
314#endif
315
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