ProtocolClient is now responsible for dispatching blocks for response messages.
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;
@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;
- (id)initWithPort:(NSUInteger)aPort
{
if (self = [super init]) {
- callTable_ = [NSMutableDictionary new];
-
[[BreakpointManager sharedManager] setConnection:self];
port_ = aPort;
client_ = [[ProtocolClient alloc] initWithDelegate:self];
- (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
- (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
- (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
[_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)];
}
}