From d3c4fe0b14b4ab2af0e37a69f0fd4c1a5bdab180 Mon Sep 17 00:00:00 2001 From: Robert Sesek Date: Mon, 7 Dec 2015 01:00:28 -0500 Subject: [PATCH] Remove DebuggerBackEndDelegate. The connection state is now available via the DebuggerModel, and it will broadcast KVO to the Controller. --- Source/DebuggerBackEnd.h | 15 --------------- Source/DebuggerBackEnd.m | 11 ++--------- Source/DebuggerController.h | 5 +++-- Source/DebuggerController.m | 11 ++++++++++- Source/DebuggerModel.m | 8 ++++++-- 5 files changed, 21 insertions(+), 29 deletions(-) diff --git a/Source/DebuggerBackEnd.h b/Source/DebuggerBackEnd.h index 6fa17b2..4a7178a 100644 --- a/Source/DebuggerBackEnd.h +++ b/Source/DebuggerBackEnd.h @@ -43,8 +43,6 @@ // The model object to update in response to changes in the debugger. @property(assign, nonatomic) DebuggerModel* model; -@property(assign, nonatomic) id delegate; - // initializer - (id)initWithPort:(NSUInteger)aPort; @@ -76,16 +74,3 @@ forStackFrame:(StackFrame*)frame; @end - -// Delegate //////////////////////////////////////////////////////////////////// - -@protocol DebuggerBackEndDelegate - -// Called when the socket connects. Passed up from SocketWrapper. -- (void)debuggerConnected; - -// Called when we disconnect. -- (void)debuggerDisconnected; - -@end - diff --git a/Source/DebuggerBackEnd.m b/Source/DebuggerBackEnd.m index 1c5359c..ec9ba08 100644 --- a/Source/DebuggerBackEnd.m +++ b/Source/DebuggerBackEnd.m @@ -37,7 +37,6 @@ @synthesize status = _status; @synthesize autoAttach = _autoAttach; @synthesize model = _model; -@synthesize delegate = _delegate; - (id)initWithPort:(NSUInteger)aPort { @@ -273,9 +272,6 @@ - (void)debuggerEngineDisconnected:(ProtocolClient*)client { _active = NO; - if ([self.delegate respondsToSelector:@selector(debuggerDisconnected)]) - [self.delegate debuggerDisconnected]; - [_model onDisconnect]; if (self.autoAttach) @@ -313,9 +309,6 @@ for (Breakpoint* bp in [[BreakpointManager sharedManager] breakpoints]) [self addBreakpoint:bp]; - // Load the debugger to make it look active. - [self.delegate debuggerConnected]; - // TODO: update the status. } @@ -324,15 +317,15 @@ */ - (void)updateStatus:(NSXMLDocument*)response { self.status = [[[[response rootElement] attributeForName:@"status"] stringValue] capitalizedString]; + self.model.status = self.status; _active = YES; if (!_status || [_status isEqualToString:@"Stopped"]) { - [_delegate debuggerDisconnected]; + [_model onDisconnect]; _active = NO; } else if ([_status isEqualToString:@"Stopping"]) { [_client sendCommandWithFormat:@"stop"]; _active = NO; } - self.model.status = self.status; } /** diff --git a/Source/DebuggerController.h b/Source/DebuggerController.h index 352d548..b7cf03a 100644 --- a/Source/DebuggerController.h +++ b/Source/DebuggerController.h @@ -15,13 +15,14 @@ */ #import -#import "DebuggerBackEnd.h" + #include "VariableNode.h" @class BSSourceView; +@class DebuggerBackEnd; @class DebuggerModel; -@interface DebuggerController : NSWindowController +@interface DebuggerController : NSWindowController { DebuggerBackEnd* connection; diff --git a/Source/DebuggerController.m b/Source/DebuggerController.m index e47846a..a6a8d73 100644 --- a/Source/DebuggerController.m +++ b/Source/DebuggerController.m @@ -19,6 +19,7 @@ #import "AppDelegate.h" #import "BSSourceView.h" #import "BreakpointManager.h" +#import "DebuggerBackEnd.h" #import "DebuggerModel.h" #import "EvalController.h" #import "NSXMLElementAdditions.h" @@ -43,9 +44,12 @@ NSUserDefaults* defaults = [NSUserDefaults standardUserDefaults]; _model = [[DebuggerModel alloc] init]; + [_model addObserver:self + forKeyPath:@"connected" + options:NSKeyValueObservingOptionNew + context:nil]; connection = [[DebuggerBackEnd alloc] initWithPort:[defaults integerForKey:@"Port"]]; - connection.delegate = self; connection.model = _model; expandedVariables = [[NSMutableSet alloc] init]; [[self window] makeKeyAndOrderFront:nil]; @@ -100,6 +104,11 @@ [connection loadStackFrame:frame]; } else if (object == stackArrayController && [keyPath isEqualToString:@"selection.source"]) { [self updateSourceViewer]; + } else if (object == _model && [keyPath isEqualToString:@"connected"]) { + if ([change[NSKeyValueChangeNewKey] boolValue]) + [self debuggerConnected]; + else + [self debuggerDisconnected]; } else { [super observeValueForKeyPath:keyPath ofObject:object change:change context:context]; } diff --git a/Source/DebuggerModel.m b/Source/DebuggerModel.m index 89adb43..49738f6 100644 --- a/Source/DebuggerModel.m +++ b/Source/DebuggerModel.m @@ -18,6 +18,10 @@ #import "StackFrame.h" +@interface DebuggerModel () +@property(assign, nonatomic) BOOL connected; +@end + @implementation DebuggerModel { NSMutableArray* _stack; } @@ -41,12 +45,12 @@ - (void)onNewConnection { self.status = nil; - _connected = YES; + self.connected = YES; [_stack removeAllObjects]; } - (void)onDisconnect { - _connected = NO; + self.connected = NO; } - (void)updateStack:(NSArray*)newStack { -- 2.22.5