- Timestamp:
- May 28, 2008 5:50:02 PM (17 years ago)
- Location:
- trunk/src/VBox/Debugger
- Files:
-
- 4 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/src/VBox/Debugger/VBoxDbgBase.cpp
r8155 r9206 30 30 31 31 32 VBoxDbgBase::VBoxDbgBase(PVM pVM) : m_pVM(pVM) 32 VBoxDbgBase::VBoxDbgBase(PVM pVM) : m_pVM(pVM), m_hGUIThread(RTThreadNativeSelf()) 33 33 { 34 34 /* -
trunk/src/VBox/Debugger/VBoxDbgBase.h
r8155 r9206 28 28 #include <VBox/vmapi.h> 29 29 #include <VBox/dbg.h> 30 #include <iprt/thread.h> 30 31 31 32 … … 61 62 { 62 63 return m_pVM != NULL; 64 } 65 66 /** 67 * Checks if the current thread is the GUI thread or not. 68 * @return true/false accordingly. 69 */ 70 bool isGUIThread() const 71 { 72 return m_hGUIThread == RTThreadNativeSelf(); 63 73 } 64 74 … … 107 117 /** The VM handle. */ 108 118 PVM m_pVM; 119 /** The handle of the GUI thread. */ 120 RTNATIVETHREAD m_hGUIThread; 109 121 }; 110 122 -
trunk/src/VBox/Debugger/VBoxDbgConsole.cpp
r8155 r9206 58 58 59 59 VBoxDbgConsoleOutput::VBoxDbgConsoleOutput(QWidget *pParent/* = NULL*/, const char *pszName/* = NULL*/) 60 : QTextEdit(pParent, pszName), m_uCurLine(0), m_uCurPos(0) 60 : QTextEdit(pParent, pszName), m_uCurLine(0), m_uCurPos(0), m_hGUIThread(RTThreadNativeSelf()) 61 61 { 62 62 setReadOnly(true); … … 69 69 Font.setFamily("Courier [Monotype]"); 70 70 setFont(Font); 71 72 /* green on black */ 73 setPaper(QBrush(Qt::black)); 74 //setColor(Qt::green); 75 setColor(QColor(qRgb(0, 0xe0, 0))); 71 76 } 72 77 73 78 VBoxDbgConsoleOutput::~VBoxDbgConsoleOutput() 74 79 { 80 Assert(m_hGUIThread == RTThreadNativeSelf()); 75 81 } 76 82 77 83 void VBoxDbgConsoleOutput::appendText(const QString &rStr) 78 84 { 85 Assert(m_hGUIThread == RTThreadNativeSelf()); 86 79 87 if (rStr.isEmpty() || rStr.isNull() || !rStr.length()) 80 88 return; … … 128 136 129 137 VBoxDbgConsoleInput::VBoxDbgConsoleInput(QWidget *pParent/* = NULL*/, const char *pszName/* = NULL*/) 130 : QComboBox(true, pParent, pszName), m_iBlankItem(0) 138 : QComboBox(true, pParent, pszName), m_iBlankItem(0), m_hGUIThread(RTThreadNativeSelf()) 131 139 { 132 140 insertItem("", m_iBlankItem); … … 141 149 VBoxDbgConsoleInput::~VBoxDbgConsoleInput() 142 150 { 151 Assert(m_hGUIThread == RTThreadNativeSelf()); 143 152 } 144 153 145 154 void VBoxDbgConsoleInput::setLineEdit(QLineEdit *pEdit) 146 155 { 156 Assert(m_hGUIThread == RTThreadNativeSelf()); 147 157 QComboBox::setLineEdit(pEdit); 148 158 if (lineEdit() == pEdit && pEdit) … … 152 162 void VBoxDbgConsoleInput::returnPressed() 153 163 { 164 Assert(m_hGUIThread == RTThreadNativeSelf()); 154 165 /* deal with the current command. */ 155 166 QString Str = currentText(); … … 187 198 m_pszInputBuf(NULL), m_cbInputBuf(0), m_cbInputBufAlloc(0), 188 199 m_pszOutputBuf(NULL), m_cbOutputBuf(0), m_cbOutputBufAlloc(0), 189 m_ Timer(), m_fUpdatePending(false), m_Thread(NIL_RTTHREAD), m_EventSem(NIL_RTSEMEVENT), m_fTerminate(false)200 m_pTimer(NULL), m_fUpdatePending(false), m_Thread(NIL_RTTHREAD), m_EventSem(NIL_RTSEMEVENT), m_fTerminate(false) 190 201 { 191 202 setCaption("VBoxDbg - Console"); … … 227 238 228 239 /* 240 * Setup the timer. 241 */ 242 m_pTimer = new QTimer(this); 243 connect(m_pTimer, SIGNAL(timeout()), SLOT(updateOutput())); 244 245 /* 229 246 * Init the backend structure. 230 247 */ … … 251 268 VBoxDbgConsole::~VBoxDbgConsole() 252 269 { 270 Assert(isGUIThread()); 271 253 272 /* 254 273 * Wait for the thread. … … 266 285 * Free resources. 267 286 */ 287 delete m_pTimer; 288 m_pTimer = NULL; 268 289 RTCritSectDelete(&m_Lock); 269 290 RTSemEventDestroy(m_EventSem); … … 282 303 void VBoxDbgConsole::commandSubmitted(const QString &rCommand) 283 304 { 305 Assert(isGUIThread()); 306 284 307 lock(); 285 308 RTSemEventSignal(m_EventSem); … … 322 345 void VBoxDbgConsole::updateOutput() 323 346 { 347 Assert(isGUIThread()); 348 324 349 lock(); 325 350 m_fUpdatePending = false; … … 368 393 /* dirty focus hack: */ 369 394 if (pThis->m_fInputRestoreFocus) 370 { 371 pThis->m_fInputRestoreFocus = false; 372 if (!pThis->m_pInput->hasFocus()) 373 pThis->m_pInput->setFocus(); 374 } 395 QApplication::postEvent(pThis, new VBoxDbgConsoleEvent(VBoxDbgConsoleEvent::kInputRestoreFocus)); 375 396 376 397 bool fRc = true; … … 476 497 */ 477 498 if (!pThis->m_fUpdatePending) 478 QApplication::postEvent(pThis, new QCustomEvent(QEvent::User, NULL));499 QApplication::postEvent(pThis, new VBoxDbgConsoleEvent(VBoxDbgConsoleEvent::kUpdate)); 479 500 480 501 pThis->unlock(); … … 503 524 LogFlow(("backThread: returns %Vrc\n", rc)); 504 525 if (!pThis->m_fTerminate) 505 QApplication::postEvent(pThis, new QCustomEvent(QEvent::User, (void *)1));526 QApplication::postEvent(pThis, new VBoxDbgConsoleEvent(VBoxDbgConsoleEvent::kTerminated)); 506 527 return rc; 507 528 } 508 529 509 void VBoxDbgConsole::customEvent(QCustomEvent *pEvent) 510 { 511 if (pEvent->type() == QEvent::User) 512 { 513 uintptr_t u = (uintptr_t)pEvent->data(); /** @todo enum! */ 514 switch (u) 530 bool VBoxDbgConsole::event(QEvent *pGenEvent) 531 { 532 Assert(isGUIThread()); 533 if (pGenEvent->type() == (QEvent::Type)VBoxDbgConsoleEvent::kEventNumber) 534 { 535 VBoxDbgConsoleEvent *pEvent = (VBoxDbgConsoleEvent *)pGenEvent; 536 537 switch (pEvent->command()) 515 538 { 516 539 /* make update pending. */ 517 case 0:540 case VBoxDbgConsoleEvent::kUpdate: 518 541 if (!m_fUpdatePending) 519 542 { 520 543 m_fUpdatePending = true; 521 m_ Timer.singleShot(10, this, SLOT(updateOutput()));544 m_pTimer->start(10, true /* single shot */); 522 545 } 523 546 break; 524 547 548 /* dirty hack: restores the focus */ 549 case VBoxDbgConsoleEvent::kInputRestoreFocus: 550 if (m_fInputRestoreFocus) 551 { 552 m_fInputRestoreFocus = false; 553 if (!m_pInput->hasFocus()) 554 m_pInput->setFocus(); 555 } 556 break; 557 525 558 /* the thread terminated */ 526 case 1:559 case VBoxDbgConsoleEvent::kTerminated: 527 560 m_pInput->setEnabled(false); 528 561 break; … … 530 563 /* paranoia */ 531 564 default: 532 AssertMsgFailed((" u=%d\n", u));565 AssertMsgFailed(("command=%d\n", pEvent->command())); 533 566 break; 534 567 } 535 } 536 } 537 568 return true; 569 } 570 571 return QVBox::event(pGenEvent); 572 } 573 -
trunk/src/VBox/Debugger/VBoxDbgConsole.h
r8155 r9206 32 32 #include <iprt/critsect.h> 33 33 #include <iprt/semaphore.h> 34 #include <iprt/thread.h> 34 35 35 36 … … 66 67 /** The position in the current line. */ 67 68 unsigned m_uCurPos; 69 /** The handle to the GUI thread. */ 70 RTNATIVETHREAD m_hGUIThread; 68 71 }; 69 72 … … 118 121 /** The current blank entry. */ 119 122 int m_iBlankItem; 123 /** The handle to the GUI thread. */ 124 RTNATIVETHREAD m_hGUIThread; 120 125 }; 121 126 … … 224 229 protected: 225 230 /** 226 * Use to get the GUI thread to insert the output data. 227 */ 228 void customEvent(QCustomEvent *pEvent); 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); 229 238 230 239 protected: … … 249 258 size_t m_cbOutputBufAlloc; 250 259 /** The timer object used to process output in a delayed fashion. */ 251 QTimer m_Timer;260 QTimer *m_pTimer; 252 261 /** Set when an output update is pending. */ 253 262 bool volatile m_fUpdatePending; … … 278 287 279 288 289 /** 290 * Simple event class for push certain operations over 291 * onto the GUI thread. 292 */ 293 class VBoxDbgConsoleEvent : public QEvent 294 { 295 public: 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 309 private: 310 VBoxDbgConsoleEventType m_enmCommand; 311 }; 312 313 280 314 #endif 315
Note:
See TracChangeset
for help on using the changeset viewer.