From 89146844ce7c292d5531efa0a53ec619ee6f2bce Mon Sep 17 00:00:00 2001 From: Robert Sesek Date: Sat, 27 Mar 2010 16:26:09 -0400 Subject: [PATCH] Rewrite |-[DebuggerConnection getProperty:]| to be asynchronous. --- Source/DebuggerConnection.h | 8 +++++-- Source/DebuggerConnection.m | 44 ++++++++++++++++++++++--------------- Source/DebuggerController.m | 8 ------- 3 files changed, 32 insertions(+), 28 deletions(-) diff --git a/Source/DebuggerConnection.h b/Source/DebuggerConnection.h index 3d56b8a..1d270d3 100644 --- a/Source/DebuggerConnection.h +++ b/Source/DebuggerConnection.h @@ -116,8 +116,9 @@ - (void)addBreakpoint:(Breakpoint*)bp; - (void)removeBreakpoint:(Breakpoint*)bp; -// helpers -- (NSArray*)getProperty:(NSString*)property; +// Gets a property by name from the debugger engine. Returns a transaction ID +// which used in the delegate callback. +- (NSInteger)getProperty:(NSString*)property; @end @@ -144,5 +145,8 @@ // Tells the debugger that new source is available for the given frame. - (void)sourceUpdated:(StackFrame*)frame; +// Callback from |-getProperty:|. +- (void)receivedProperties:(NSArray*)properties forTransaction:(NSInteger)transaction; + @end diff --git a/Source/DebuggerConnection.m b/Source/DebuggerConnection.m index b0f4339..24eb78d 100644 --- a/Source/DebuggerConnection.m +++ b/Source/DebuggerConnection.m @@ -51,6 +51,7 @@ - (void)setSource:(NSXMLDocument*)response; - (void)contextsReceived:(NSXMLDocument*)response; - (void)variablesReceived:(NSXMLDocument*)response; +- (void)propertiesReceived:(NSXMLDocument*)response; - (NSNumber*)sendCommandWithCallback:(SEL)callback format:(NSString*)format, ...; @@ -327,25 +328,9 @@ void SocketAcceptCallback(CFSocketRef socket, * Tells the debugger engine to get a specifc property. This also takes in the NSXMLElement * that requested it so that the child can be attached. */ -- (NSArray*)getProperty:(NSString*)property +- (NSInteger)getProperty:(NSString*)property { - [socket send:[self createCommand:[NSString stringWithFormat:@"property_get -n \"%@\"", property]]]; - - NSXMLDocument* doc = [self processData:[socket receive]]; - - /* - - - - - - */ - - // we now have to detach all the children so we can insert them into another document - NSXMLElement* parent = (NSXMLElement*)[[doc rootElement] childAtIndex:0]; - NSArray* children = [parent children]; - [parent setChildren:nil]; - return children; + [self sendCommandWithCallback:@selector(propertiesReceived:) format:@"property_get -n \"%@\"", property]; } // Breakpoint Management /////////////////////////////////////////////////////// @@ -894,6 +879,29 @@ void SocketAcceptCallback(CFSocketRef socket, frame.variables = variables; } +/** + * Callback from a |-getProperty:| request. + */ +- (void)propertiesReceived:(NSXMLDocument*)response +{ + NSInteger transaction = [self transactionIDFromResponse:response]; + + /* + + + + + + */ + + // Detach all the children so we can insert them into another document. + NSXMLElement* parent = (NSXMLElement*)[[response rootElement] childAtIndex:0]; + NSArray* children = [parent children]; + [parent setChildren:nil]; + + [delegate receivedProperties:children forTransaction:transaction]; +} + /** * Callback for setting a breakpoint. */ diff --git a/Source/DebuggerController.m b/Source/DebuggerController.m index 62708cb..19a13e0 100644 --- a/Source/DebuggerController.m +++ b/Source/DebuggerController.m @@ -75,14 +75,6 @@ [stackArrayController setSortDescriptors:[NSArray arrayWithObject:[[[NSSortDescriptor alloc] initWithKey:@"index" ascending:YES] autorelease]]]; } -/** - * Called right before the window closes so that we can tell the socket to close down - */ -- (void)windowWillClose:(NSNotification*)notif -{ - [connection close]; -} - /** * Validates the menu items for the "Debugger" menu */ -- 2.22.5