From 24a5001ae6019036592006618924d207b42a5570 Mon Sep 17 00:00:00 2001 From: Robert Sesek Date: Sat, 5 Jan 2008 13:54:55 -0800 Subject: [PATCH] We no longer use DebuggerConnection to manage the DebuggerWindowController, but now it's vice versa Benefits: - There was a problem that when we quit we would crash, because on window closing, the WindowController would tell the connection to shutdown, but because AppDelegate cleaned up before the WindowController, it would crash when sending the message. - An array of connections no longer needs to be managed because the WindowController stores all the pointers, so when it closes things are deallocated properly --- Source/AppDelegate.h | 8 +------- Source/AppDelegate.m | 28 +--------------------------- Source/ConnectWindowController.m | 6 ++---- Source/DebuggerConnection.h | 2 +- Source/DebuggerConnection.m | 14 ++------------ Source/DebuggerWindowController.h | 2 +- Source/DebuggerWindowController.m | 4 ++-- 7 files changed, 10 insertions(+), 54 deletions(-) diff --git a/Source/AppDelegate.h b/Source/AppDelegate.h index 9e1b352..612b3bd 100644 --- a/Source/AppDelegate.h +++ b/Source/AppDelegate.h @@ -18,13 +18,7 @@ #import "DebuggerConnection.h" @interface AppDelegate : NSObject -{ - NSMutableArray *connections; -} - - -- (void)registerConnection:(DebuggerConnection *)cnx; -- (void)unregisterConnection:(DebuggerConnection *)cnx; +{} - (IBAction)showConnectionWindow:(id)sender; diff --git a/Source/AppDelegate.m b/Source/AppDelegate.m index 1d1ebf2..3a4fc67 100644 --- a/Source/AppDelegate.m +++ b/Source/AppDelegate.m @@ -25,20 +25,10 @@ - (id)init { if (self = [super init]) - { - connections = [[NSMutableArray alloc] init]; - } + {} return self; } -/** - * Called when the application is going to go away - */ -- (void)applicationWillTerminate:(NSNotification *)aNotification -{ - [connections release]; -} - /** * When the application has finished loading, show the connection dialog */ @@ -47,22 +37,6 @@ [self showConnectionWindow:self]; } -/** - * Adds an object to the connections array - */ -- (void)registerConnection:(DebuggerConnection *)cnx -{ - [connections addObject:cnx]; -} - -/** - * Removes a given connection from the connections array - */ -- (void)unregisterConnection:(DebuggerConnection *)cnx -{ - [connections removeObject:cnx]; -} - /** * Shows the connection window */ diff --git a/Source/ConnectWindowController.m b/Source/ConnectWindowController.m index 199e892..f9e7dff 100644 --- a/Source/ConnectWindowController.m +++ b/Source/ConnectWindowController.m @@ -15,7 +15,7 @@ */ #import "ConnectWindowController.h" -#import "DebuggerConnection.h" +#import "DebuggerWindowController.h" #import "AppDelegate.h" @implementation ConnectWindowController @@ -53,9 +53,7 @@ */ - (IBAction)connect:(id)sender { - DebuggerConnection *cnx = [[DebuggerConnection alloc] initWithPort:[port intValue] session:[session stringValue]]; - [[NSApp delegate] registerConnection:cnx]; - [cnx release]; + [[[DebuggerWindowController alloc] initWithPort:[port intValue] session:[session stringValue]] release]; [[self window] orderOut:self]; } diff --git a/Source/DebuggerConnection.h b/Source/DebuggerConnection.h index 4eb1a51..8efc2ff 100644 --- a/Source/DebuggerConnection.h +++ b/Source/DebuggerConnection.h @@ -32,7 +32,7 @@ } // initializer -- (id)initWithPort:(int)aPort session:(NSString *)aSession; +- (id)initWithWindowController:(DebuggerWindowController *)wc port:(int)aPort session:(NSString *)aSession; - (void)windowDidClose; diff --git a/Source/DebuggerConnection.m b/Source/DebuggerConnection.m index 8c19d38..99a0975 100644 --- a/Source/DebuggerConnection.m +++ b/Source/DebuggerConnection.m @@ -29,7 +29,7 @@ * Creates a new DebuggerConnection and initializes the socket from the given connection * paramters. */ -- (id)initWithPort:(int)aPort session:(NSString *)aSession +- (id)initWithWindowController:(DebuggerWindowController *)wc port:(int)aPort session:(NSString *)aSession; { if (self = [super init]) { @@ -37,8 +37,7 @@ session = [aSession retain]; connected = NO; - windowController = [[DebuggerWindowController alloc] initWithConnection:self]; - [[windowController window] makeKeyAndOrderFront:self]; + windowController = [wc retain]; // now that we have our host information, open the socket socket = [[SocketWrapper alloc] initWithPort:port]; @@ -49,15 +48,6 @@ return self; } -/** - * This is a forwarded message from DebuggerWindowController that tells the connection to prepare to - * close - */ -- (void)windowDidClose -{ - [[NSApp delegate] unregisterConnection:self]; -} - /** * Releases all of the object's data members and closes the streams */ diff --git a/Source/DebuggerWindowController.h b/Source/DebuggerWindowController.h index f8495af..5770f92 100644 --- a/Source/DebuggerWindowController.h +++ b/Source/DebuggerWindowController.h @@ -42,7 +42,7 @@ IBOutlet NSButton *reconnectButton; } -- (id)initWithConnection:(DebuggerConnection *)cnx; +- (id)initWithPort:(int)aPort session:(NSString *)aSession; - (void)setStatus:(NSString *)aStatus; - (void)setError:(NSString *)anError; diff --git a/Source/DebuggerWindowController.m b/Source/DebuggerWindowController.m index aa16692..d7bbb21 100644 --- a/Source/DebuggerWindowController.m +++ b/Source/DebuggerWindowController.m @@ -30,11 +30,11 @@ /** * Initializes the window controller and sets the connection */ -- (id)initWithConnection:(DebuggerConnection *)cnx +- (id)initWithPort:(int)aPort session:(NSString *)aSession { if (self = [super initWithWindowNibName:@"Debugger"]) { - connection = cnx; + connection = [[DebuggerConnection alloc] initWithWindowController:self port:aPort session:aSession]; expandedRegisters = [[NSMutableArray alloc] init]; } return self; -- 2.22.5