From fd6f727abde7de9335639ddf4915dee52cb152e7 Mon Sep 17 00:00:00 2001 From: Robert Sesek Date: Wed, 11 Sep 2019 00:55:07 -0400 Subject: [PATCH] Put the listening port information into the status display. --- Source/DebuggerBackEnd.h | 6 ++++-- Source/DebuggerBackEnd.m | 21 +++++++++++++++------ Source/DebuggerController.m | 4 ++-- Source/DebuggerModel.h | 3 +++ Source/DebuggerModel.m | 4 ++++ 5 files changed, 28 insertions(+), 10 deletions(-) diff --git a/Source/DebuggerBackEnd.h b/Source/DebuggerBackEnd.h index 0af8590..2ed62a7 100644 --- a/Source/DebuggerBackEnd.h +++ b/Source/DebuggerBackEnd.h @@ -34,11 +34,13 @@ @property(assign, nonatomic) BOOL autoAttach; // The model object to update in response to changes in the debugger. -@property(assign, nonatomic) DebuggerModel* model; +@property(readonly, nonatomic) DebuggerModel* model; // Designated initializer. Sets up a connection on |aPort| and will // initialize it if |autoAttach| is YES. -- (instancetype)initWithPort:(NSUInteger)aPort autoAttach:(BOOL)doAttach; +- (instancetype)initWithModel:(DebuggerModel*)model + port:(NSUInteger)aPort + autoAttach:(BOOL)doAttach; // getter - (uint16_t)port; diff --git a/Source/DebuggerBackEnd.m b/Source/DebuggerBackEnd.m index ba51977..778c04a 100644 --- a/Source/DebuggerBackEnd.m +++ b/Source/DebuggerBackEnd.m @@ -28,15 +28,16 @@ ProtocolClient* _client; } -- (instancetype)initWithPort:(NSUInteger)aPort autoAttach:(BOOL)doAttach +- (instancetype)initWithModel:(DebuggerModel*)model + port:(NSUInteger)aPort + autoAttach:(BOOL)doAttach { if (self = [super init]) { + _model = model; _port = aPort; _client = [[ProtocolClient alloc] initWithDelegate:self]; - _autoAttach = doAttach; - if (doAttach) - [_client connectOnPort:_port]; + [self setAutoAttach:doAttach]; } return self; } @@ -67,7 +68,7 @@ if (_autoAttach) [_client disconnect]; else - [_client connectOnPort:_port]; + [self doConnect]; _autoAttach = flag; } @@ -254,7 +255,7 @@ [_model onDisconnect]; if (self.autoAttach) - [_client connectOnPort:_port]; + [self doConnect]; } - (void)protocolClient:(ProtocolClient*)client receivedInitialMessage:(NSXMLDocument*)message { @@ -384,4 +385,12 @@ } } +// Private ///////////////////////////////////////////////////////////////////// +#pragma mark Private + +- (void)doConnect { + [_client connectOnPort:_port]; + [_model onListeningOnPort:_port]; +} + @end diff --git a/Source/DebuggerController.m b/Source/DebuggerController.m index 690737e..4cc6cfe 100644 --- a/Source/DebuggerController.m +++ b/Source/DebuggerController.m @@ -60,9 +60,9 @@ options:NSKeyValueObservingOptionNew context:nil]; - _connection = [[DebuggerBackEnd alloc] initWithPort:[defaults integerForKey:kPrefPort] + _connection = [[DebuggerBackEnd alloc] initWithModel:_model + port:[defaults integerForKey:kPrefPort] autoAttach:[defaults boolForKey:kPrefDebuggerAttached]]; - _connection.model = _model; _model.breakpointManager.connection = _connection; [_model addObserver:self diff --git a/Source/DebuggerModel.h b/Source/DebuggerModel.h index eeded0d..b2698bd 100644 --- a/Source/DebuggerModel.h +++ b/Source/DebuggerModel.h @@ -43,6 +43,9 @@ // Helper accessor for |stack.count|. @property(readonly, nonatomic) NSUInteger stackDepth; +// Informs the model that the debugger is listening for new connections. +- (void)onListeningOnPort:(uint16_t)port; + // Informs the model that a new connection was initiated. This clears any data // in the model. - (void)onNewConnection; diff --git a/Source/DebuggerModel.m b/Source/DebuggerModel.m index 3e588c1..442e81c 100644 --- a/Source/DebuggerModel.m +++ b/Source/DebuggerModel.m @@ -49,6 +49,10 @@ return self.stack.count; } +- (void)onListeningOnPort:(uint16_t)port { + self.status = [NSString stringWithFormat:@"Listening on Port %d", port]; +} + - (void)onNewConnection { self.status = nil; self.connected = YES; -- 2.43.5