Remove the old callTable_ system from DebuggerBackEnd.
authorRobert Sesek <rsesek@bluestatic.org>
Sat, 10 Oct 2015 16:59:50 +0000 (12:59 -0400)
committerRobert Sesek <rsesek@bluestatic.org>
Sat, 10 Oct 2015 17:17:17 +0000 (13:17 -0400)
ProtocolClient is now responsible for dispatching blocks for response messages.

Source/DebuggerBackEnd.h
Source/DebuggerBackEnd.m
Source/ProtocolClient.h
Source/ProtocolClient.m

index 081f025448c541a27f9f42de6a6b3918556d21a7..588adec02688a131394b9ec61e9fd4579b6f66d0 100644 (file)
   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;
index 84225cdaf8a8330eb8f0814bd25150ed08d0afb7..05f0dce7f7f52e292a74e0e7a52dfa28cd5e50cd 100644 (file)
@@ -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];
 }
 
   }
 }
 
-- (void)debuggerEngine:(ProtocolClient*)client receivedMessage:(NSXMLDocument*)message {
-  [self handleResponse:message];
-}
-
 // Specific Response Handlers //////////////////////////////////////////////////
 #pragma mark Response Handlers
 
   // 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.
  */
   }
 }
 
-// Private /////////////////////////////////////////////////////////////////////
-
-- (void)recordCallback:(SEL)callback forTransaction:(NSNumber*)txn
-{
-  [callTable_ setObject:NSStringFromSelector(callback) forKey:txn];
-}
-
 @end
index 9cfa539a454751db4caf9127f2b3c8366edcd288..37ea6e52c121bb09ebecc367e9918f1f5ddee7c7 100644 (file)
@@ -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
index bb39ee34a923974dee7d987beb1462a5abfdd76f..7508817584876fea012d0de702852bfb9dd92ec0 100644 (file)
   [_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
   } 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)];
   }
 }