/// <summary> /// Checks if gdb is ready and sends the next command /// </summary> private void ProcessQueue() { lock (_commands) { if (_commands.Count == 0 || _gdbReadyForInput == false) return; _gdbReadyForInput = false; WriteLine (_commands.Peek ().Command); _currentCommand = _commands.Dequeue (); //If no response handler is specified, we don't need the command anymore if (_currentCommand.ResponseHandler == null) { _currentCommand.CommandFinished (); _currentCommand = null; } } }
/// <summary> /// Processes responses received from GDB. /// There may be direct responses to commands or async responses /// </summary> /// <param name="lines"></param> private void ReceivedNewLine(List<string> lines) { lock (_commands) { if (_currentCommand != null && _currentCommand.ResponseHandler == null) _currentCommand = null; if (_currentCommand != null && _currentCommand.ResponseHandler != null) { try { GDBResponseHandler.HandleResponseEnum responseEnum = (GDBResponseHandler.HandleResponseEnum) _currentCommand.ResponseHandler.HandleResponse (this, lines.ToArray (), !_gdbReadyForInput); if (responseEnum == GDBResponseHandler.HandleResponseEnum.NotHandled) { //TODO: Forward to permanent handlers } else if (responseEnum == GDBResponseHandler.HandleResponseEnum.Handled) { //Last command and response processed _currentCommand.CommandFinished(); _currentCommand = null; lines.Clear(); } else if(responseEnum == GDBResponseHandler.HandleResponseEnum.RequestLine && _gdbReadyForInput) { //Wrong behaviour throw new ArgumentException("Cannot request another response line if gdb is ready for input"); } } catch(Exception e) { GdbLogLine(string.Format("Error Handling response for handler '{0}': {1}", _currentCommand.ResponseHandler.LogIdentifier, e)); } } else { foreach(GDBResponseHandler permanentResponseHandler in _permanentResponseHandlers) { GDBResponseHandler.HandleResponseEnum responseEnum = permanentResponseHandler.HandleResponse(this, lines.ToArray(), !_gdbReadyForInput); if(responseEnum == GDBResponseHandler.HandleResponseEnum.Handled) { lines.Clear(); break; } else if(responseEnum == GDBResponseHandler.HandleResponseEnum.RequestLine && _gdbReadyForInput) { //Wrong behaviour throw new ArgumentException("Cannot request another response line if gdb is ready for input"); } else if(responseEnum == GDBResponseHandler.HandleResponseEnum.RequestLine) break; } } } }
/// <summary> /// Queues the command, it gets sent as soon as gdb is ready for input /// </summary> /// <param name="cmd"> /// A <see cref="GDBCommand"/> /// </param> public void QueueCommand(GDBCommand cmd) { lock(_commands) { _commands.Enqueue(cmd); } ProcessQueue(); }