void IOChannel::Run () { SBListener listener("IOChannel::Run"); std::string new_line; SBBroadcaster interpreter_broadcaster (m_driver->GetDebugger().GetCommandInterpreter().GetBroadcaster()); listener.StartListeningForEvents (interpreter_broadcaster, SBCommandInterpreter::eBroadcastBitResetPrompt | SBCommandInterpreter::eBroadcastBitThreadShouldExit | SBCommandInterpreter::eBroadcastBitQuitCommandReceived); listener.StartListeningForEvents (*this, IOChannel::eBroadcastBitThreadShouldExit); listener.StartListeningForEvents (*m_driver, Driver::eBroadcastBitReadyForInput | Driver::eBroadcastBitThreadShouldExit); // Let anyone know that the IO channel is up and listening and ready for events BroadcastEventByType (eBroadcastBitThreadDidStart); bool done = false; while (!done) { SBEvent event; listener.WaitForEvent (UINT32_MAX, event); if (!event.IsValid()) continue; const uint32_t event_type = event.GetType(); if (event.GetBroadcaster().IsValid()) { if (event.BroadcasterMatchesPtr (m_driver)) { if (event_type & Driver::eBroadcastBitReadyForInput) { std::string line; if (CommandQueueIsEmpty()) { if (LibeditGetInput(line) == false) { // EOF or some other file error occurred done = true; continue; } } else { GetCommandFromQueue (line); } // TO BE DONE: FIGURE OUT WHICH COMMANDS SHOULD NOT BE REPEATED IF USER PRESSES PLAIN 'RETURN' // AND TAKE CARE OF THAT HERE. SBEvent line_event(IOChannel::eBroadcastBitHasUserInput, line.c_str(), line.size()); BroadcastEvent (line_event); } else if (event_type & Driver::eBroadcastBitThreadShouldExit) { done = true; break; } } else if (event.BroadcasterMatchesRef (interpreter_broadcaster)) { switch (event_type) { case SBCommandInterpreter::eBroadcastBitResetPrompt: { const char *new_prompt = SBEvent::GetCStringFromEvent (event); if (new_prompt) g_prompt_map[m_edit_line] = new_prompt; } break; case SBCommandInterpreter::eBroadcastBitThreadShouldExit: case SBCommandInterpreter::eBroadcastBitQuitCommandReceived: done = true; break; } } else if (event.BroadcasterMatchesPtr (this)) { if (event_type & IOChannel::eBroadcastBitThreadShouldExit) { done = true; break; } } } } BroadcastEventByType (IOChannel::eBroadcastBitThreadDidExit); m_driver = NULL; m_read_thread = NULL; }