From 14ffd9db160a389fd532233deec5dd46bbfd3833 Mon Sep 17 00:00:00 2001 From: Robert Sesek Date: Sun, 30 Nov 2008 22:40:18 -0500 Subject: [PATCH] Create an error system that follows MVC * Source/DebuggerController.m: (init): Register ourselves as an observer for the error notif type (handleConnectionError:): New method to handle the error notifs * Source/GDBpConnection.h: Forward-declare kErrorOccurred * Source/GDBpConnection.m: (errorEncountered:): Post the notification --- Source/DebuggerController.m | 15 +++++++++++++++ Source/GDBpConnection.h | 2 ++ Source/GDBpConnection.m | 11 ++++++++++- 3 files changed, 27 insertions(+), 1 deletion(-) diff --git a/Source/DebuggerController.m b/Source/DebuggerController.m index 60c695f..a8c5ded 100644 --- a/Source/DebuggerController.m +++ b/Source/DebuggerController.m @@ -46,6 +46,13 @@ expandedRegisters = [[NSMutableSet alloc] init]; [[self window] makeKeyAndOrderFront:nil]; [[self window] setDelegate:self]; + + [[NSNotificationCenter defaultCenter] + addObserver:self + selector:@selector(handleConnectionError:) + name:kErrorOccurredNotif + object:connection + ]; } return self; } @@ -143,6 +150,14 @@ [errormsg setHidden:NO]; } +/** + * Handles a GDBpConnection error + */ +- (void)handleConnectionError:(NSNotification *)notif +{ + [self setError:[[notif userInfo] valueForKey:@"NSString"]]; +} + /** * Sets the stack root element so that the NSOutlineView can display it */ diff --git a/Source/GDBpConnection.h b/Source/GDBpConnection.h index 36e4c01..e2ab984 100644 --- a/Source/GDBpConnection.h +++ b/Source/GDBpConnection.h @@ -20,6 +20,8 @@ #import "Breakpoint.h" #import "StackFrame.h" +extern NSString *kErrorOccurredNotif; + @interface GDBpConnection : NSObject { int port; diff --git a/Source/GDBpConnection.m b/Source/GDBpConnection.m index c68baca..d103a11 100644 --- a/Source/GDBpConnection.m +++ b/Source/GDBpConnection.m @@ -17,6 +17,8 @@ #import "GDBpConnection.h" #import "AppDelegate.h" +NSString *kErrorOccurredNotif = @"GDBpConnection_ErrorOccured_Notification"; + @interface GDBpConnection (Private) - (NSString *)createCommand:(NSString *)cmd; - (NSXMLDocument *)processData:(NSString *)data; @@ -121,7 +123,14 @@ */ - (void)errorEncountered:(NSString *)error { - [windowController setError:error]; + [[NSNotificationCenter defaultCenter] + postNotificationName:kErrorOccurredNotif + object:self + userInfo:[NSDictionary + dictionaryWithObject:error + forKey:@"NSString" + ] + ]; } /** -- 2.43.5