//////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// //////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// //////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// public void SendAsyncCommand(string command, OnAsyncOutputDelegate asyncDelegate = null) { LoggingUtils.Print(string.Format("[JdbClient] SendAsyncCommand: {0}", command)); if (string.IsNullOrWhiteSpace(command)) { throw new ArgumentNullException("command"); } if (m_jdbClientInstance == null) { return; } m_timeSinceLastOperation.Restart(); AsyncCommandData commandData = new AsyncCommandData(); commandData.Command = command; commandData.OutputDelegate = asyncDelegate; ++m_sessionCommandToken; lock (m_asyncCommandData) { m_asyncCommandData.Add(m_sessionCommandToken, commandData); } //command = m_sessionCommandToken + command; m_jdbClientInstance.SendCommand(command); m_timeSinceLastOperation.Restart(); }
//////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// //////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// //////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// public void ProcessStdout(object sendingProcess, DataReceivedEventArgs args) { if (!string.IsNullOrEmpty(args.Data)) { LoggingUtils.Print(string.Format("[JdbClient] ProcessStdout: {0}", args.Data)); try { m_timeSinceLastOperation.Restart(); if (args.Data.Equals("Initializing jdb ...")) { m_sessionStarted.Set(); } // // Distribute result records to registered delegate callbacks. // OnAsyncStdout(new string [] { args.Data }); // // Collate output for any ongoing async commands. // lock (m_asyncCommandData) { foreach (KeyValuePair <uint, AsyncCommandData> asyncCommand in m_asyncCommandData) { if (!asyncCommand.Value.Command.StartsWith("-")) { asyncCommand.Value.OutputLines.Add(args.Data); } } } // // Call the corresponding registered delegate for the token response. // uint token = m_sessionCommandToken; AsyncCommandData callbackCommandData = null; lock (m_asyncCommandData) { if (m_asyncCommandData.TryGetValue(token, out callbackCommandData)) { m_asyncCommandData.Remove(token); } } // // Spawn any registered callback handlers on a dedicated thread, as not to block JDB output. // if ((callbackCommandData != null) && (callbackCommandData.OutputDelegate != null)) { ThreadPool.QueueUserWorkItem(delegate(object state) { try { callbackCommandData.OutputDelegate(callbackCommandData.OutputLines.ToArray()); } catch (Exception e) { LoggingUtils.HandleException(e); } }); } } catch (Exception e) { LoggingUtils.HandleException(e); } } }
//////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// //////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// //////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// public void SendAsyncCommand (string command, OnAsyncOutputDelegate asyncDelegate = null) { LoggingUtils.Print (string.Format ("[JdbClient] SendAsyncCommand: {0}", command)); if (string.IsNullOrWhiteSpace (command)) { throw new ArgumentNullException ("command"); } if (m_jdbClientInstance == null) { return; } m_timeSinceLastOperation.Restart (); AsyncCommandData commandData = new AsyncCommandData (); commandData.Command = command; commandData.OutputDelegate = asyncDelegate; ++m_sessionCommandToken; lock (m_asyncCommandData) { m_asyncCommandData.Add (m_sessionCommandToken, commandData); } //command = m_sessionCommandToken + command; m_jdbClientInstance.SendCommand (command); m_timeSinceLastOperation.Restart (); }
//////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// //////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// //////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// public uint SendCommand (string command, int timeout, OnResultRecordDelegate asyncDelegate = null) { // // Keep track of this command, and associated token-id, so results can be tracked asynchronously. // LoggingUtils.Print (string.Format ("[GdbClient] SendAsyncCommand: {0}", command)); if (string.IsNullOrWhiteSpace (command)) { throw new ArgumentNullException ("command"); } if (m_gdbClientInstance == null) { throw new InvalidOperationException ("No GdbClient instance bound"); } m_timeSinceLastOperation.Restart (); AsyncCommandData commandData = new AsyncCommandData (); commandData.Command = command; commandData.ResultDelegate = asyncDelegate; ++m_sessionCommandToken; lock (m_asyncCommandData) { m_asyncCommandData.Add (m_sessionCommandToken, commandData); } // // Prepend (and increment) GDB/MI token. // command = m_sessionCommandToken + command; m_gdbClientInstance.SendCommand (command); m_timeSinceLastOperation.Restart (); return m_sessionCommandToken; }