version.
- (void)rebuildStack:(NSXMLDocument*)response;
- (void)getStackFrame:(NSXMLDocument*)response;
- (void)propertiesReceived:(NSXMLDocument*)response;
-- (void)evalScriptReceived:(NSXMLDocument*)response;
@end
char* encodedString = malloc(modp_b64_encode_len([str length]));
modp_b64_encode(encodedString, [str UTF8String], [str length]);
- NSNumber* tx = [client_ sendCustomCommandWithFormat:@"eval -i {txn} -- %s", encodedString];
+ ProtocolClientMessageHandler handler = ^(NSXMLDocument* message) {
+ NSXMLElement* parent = (NSXMLElement*)[[message rootElement] childAtIndex:0];
+ NSString* value = [parent base64DecodedValue];
+ [self.delegate scriptWasEvaluatedWithResult:value];
+ };
+ [client_ sendCustomCommandWithFormat:@"eval -i {txn} -- %s" handler:handler, encodedString];
free(encodedString);
-
- [self recordCallback:@selector(evalScriptReceived:) forTransaction:tx];
}
// Protocol Client Delegate ////////////////////////////////////////////////////
[delegate receivedProperties:children forTransaction:transaction];
}
-/**
- * Callback from a |-evalScript:| request.
- */
-- (void)evalScriptReceived:(NSXMLDocument*)response
-{
- NSXMLElement* parent = (NSXMLElement*)[[response rootElement] childAtIndex:0];
- NSString* value = [parent base64DecodedValue];
- [delegate scriptWasEvaluatedWithResult:value];
-}
-
// Private /////////////////////////////////////////////////////////////////////
- (void)recordCallback:(SEL)callback forTransaction:(NSNumber*)txn
// Sends a command to the debugger. The command must have a substring |{txn}|
// within it, which will be replaced with the transaction ID. Use this if
// |-sendCommandWithFormat:|'s insertion of the transaction ID is incorrect.
-- (NSNumber*)sendCustomCommandWithFormat:(NSString*)format, ...;
+- (void)sendCustomCommandWithFormat:(NSString*)format
+ handler:(ProtocolClientMessageHandler)handler,
+ ...;
- (NSInteger)transactionIDFromResponse:(NSXMLDocument*)response;
- (NSInteger)transactionIDFromCommand:(NSString*)command;
[_messageQueue sendMessage:taggedCommand];
}
-- (NSNumber*)sendCustomCommandWithFormat:(NSString*)format, ... {
+- (void)sendCustomCommandWithFormat:(NSString*)format
+ handler:(ProtocolClientMessageHandler)handler, ... {
// Collect varargs and format command.
va_list args;
- va_start(args, format);
- NSString* command = [[[NSString alloc] initWithFormat:format arguments:args] autorelease];
+ va_start(args, handler);
+ NSString* command = [[NSString alloc] initWithFormat:format arguments:args];
va_end(args);
- NSNumber* callbackKey = [NSNumber numberWithInt:_nextID++];
- NSString* taggedCommand = [command stringByReplacingOccurrencesOfString:@"{txn}"
- withString:[callbackKey stringValue]];
+ int transaction = _nextID++;
+ NSString* taggedCommand =
+ [command stringByReplacingOccurrencesOfString:@"{txn}"
+ withString:[NSString stringWithFormat:@"%d", transaction]];
+ assert(_messageQueue);
+ [_dispatchTable setObject:[[handler copy] autorelease] forKey:@(transaction)];
[_messageQueue sendMessage:taggedCommand];
- return callbackKey;
}
+
- (NSInteger)transactionIDFromResponse:(NSXMLDocument*)response {
return [[[[response rootElement] attributeForName:@"transaction_id"] stringValue] intValue];
}