From 4da70cf6cfe75f03a61090ab26c572a502b7da43 Mon Sep 17 00:00:00 2001 From: Robert Sesek Date: Sat, 10 Oct 2015 12:59:50 -0400 Subject: [PATCH] Remove the old callTable_ system from DebuggerBackEnd. ProtocolClient is now responsible for dispatching blocks for response messages. --- Source/DebuggerBackEnd.h | 5 ----- Source/DebuggerBackEnd.m | 29 ----------------------------- Source/ProtocolClient.h | 6 ++---- Source/ProtocolClient.m | 18 ++++-------------- 4 files changed, 6 insertions(+), 52 deletions(-) diff --git a/Source/DebuggerBackEnd.h b/Source/DebuggerBackEnd.h index 081f025..588adec 100644 --- a/Source/DebuggerBackEnd.h +++ b/Source/DebuggerBackEnd.h @@ -53,11 +53,6 @@ NSInteger stackDepth_; // The earliest transaction ID for the current build of |stackFrames_|. NSInteger stackFirstTransactionID_; - - // Callback table. This maps transaction IDs to selectors. When the engine - // returns a response to the debugger, we will dispatch the response XML to - // the selector, based on transaction_id. - NSMutableDictionary* callTable_; } @property (readonly, copy) NSString* status; diff --git a/Source/DebuggerBackEnd.m b/Source/DebuggerBackEnd.m index 84225cd..05f0dce 100644 --- a/Source/DebuggerBackEnd.m +++ b/Source/DebuggerBackEnd.m @@ -25,8 +25,6 @@ @interface DebuggerBackEnd () @property (readwrite, copy) NSString* status; -- (void)recordCallback:(SEL)callback forTransaction:(NSNumber*)txn; - - (void)updateStatus:(NSXMLDocument*)response; - (void)debuggerStep:(NSXMLDocument*)response; - (void)rebuildStack:(NSXMLDocument*)response; @@ -48,8 +46,6 @@ - (id)initWithPort:(NSUInteger)aPort { if (self = [super init]) { - callTable_ = [NSMutableDictionary new]; - [[BreakpointManager sharedManager] setConnection:self]; port_ = aPort; client_ = [[ProtocolClient alloc] initWithDelegate:self]; @@ -68,7 +64,6 @@ - (void)dealloc { [client_ release]; - [callTable_ release]; [super dealloc]; } @@ -307,10 +302,6 @@ } } -- (void)debuggerEngine:(ProtocolClient*)client receivedMessage:(NSXMLDocument*)message { - [self handleResponse:message]; -} - // Specific Response Handlers ////////////////////////////////////////////////// #pragma mark Response Handlers @@ -341,19 +332,6 @@ // TODO: update the status. } -- (void)handleResponse:(NSXMLDocument*)response -{ - NSInteger transactionID = [client_ transactionIDFromResponse:response]; - NSNumber* key = [NSNumber numberWithInt:transactionID]; - NSString* callbackStr = [callTable_ objectForKey:key]; - if (callbackStr) - { - SEL callback = NSSelectorFromString(callbackStr); - [self performSelector:callback withObject:response]; - } - [callTable_ removeObjectForKey:key]; -} - /** * Receiver for status updates. This just freshens up the UI. */ @@ -468,11 +446,4 @@ } } -// Private ///////////////////////////////////////////////////////////////////// - -- (void)recordCallback:(SEL)callback forTransaction:(NSNumber*)txn -{ - [callTable_ setObject:NSStringFromSelector(callback) forKey:txn]; -} - @end diff --git a/Source/ProtocolClient.h b/Source/ProtocolClient.h index 9cfa539..37ea6e5 100644 --- a/Source/ProtocolClient.h +++ b/Source/ProtocolClient.h @@ -34,9 +34,8 @@ typedef void (^ProtocolClientMessageHandler)(NSXMLDocument*); - (void)connectOnPort:(NSUInteger)port; - (void)disconnect; -// This sends the given command format to the debugger. This method is thread -// safe and schedules the request on the |runLoop_|. -- (NSNumber*)sendCommandWithFormat:(NSString*)format, ...; +// Sends a one-way command to the debugger, when no response is required. +- (void)sendCommandWithFormat:(NSString*)format, ...; // Sends a command with the given |format| to the debugger. When a response is // received, |handler| is invoked. If an error occurs or the connection is @@ -70,5 +69,4 @@ typedef void (^ProtocolClientMessageHandler)(NSXMLDocument*); - (void)debuggerEngineDisconnected:(ProtocolClient*)client; - (void)protocolClient:(ProtocolClient*)client receivedInitialMessage:(NSXMLDocument*)message; - (void)protocolClient:(ProtocolClient*)client receivedErrorMessage:(NSXMLDocument*)message; -- (void)debuggerEngine:(ProtocolClient*)client receivedMessage:(NSXMLDocument*)message; @end diff --git a/Source/ProtocolClient.m b/Source/ProtocolClient.m index bb39ee3..7508817 100644 --- a/Source/ProtocolClient.m +++ b/Source/ProtocolClient.m @@ -66,19 +66,14 @@ [_messageQueue disconnect]; } -- (NSNumber*)sendCommandWithFormat:(NSString*)format, ... { +- (void)sendCommandWithFormat:(NSString*)format, ... { // Collect varargs and format command. va_list args; va_start(args, format); NSString* command = [[NSString alloc] initWithFormat:format arguments:args]; va_end(args); - NSNumber* callbackKey = [NSNumber numberWithInt:_nextID++]; - NSString* taggedCommand = [NSString stringWithFormat:@"%@ -i %@", [command autorelease], callbackKey]; - - assert(_messageQueue); - [_messageQueue sendMessage:taggedCommand]; - return callbackKey; + [self sendCommandWithFormat:command handler:^(NSXMLDocument* message){}]; } - (void)sendCommandWithFormat:(NSString*)format @@ -212,13 +207,8 @@ } else { // Dispatch the handler for the message. ProtocolClientMessageHandler handler = [_dispatchTable objectForKey:@(transactionID)]; - if (handler) { - handler(xml); - [_dispatchTable removeObjectForKey:@(transactionID)]; - } else { - // TODO(rsesek): Remove this path once the backend rewrite is complete. - [_delegate debuggerEngine:self receivedMessage:xml]; - } + handler(xml); + [_dispatchTable removeObjectForKey:@(transactionID)]; } } -- 2.43.5