* Add a preference to automatically reconnect. Fixes bug #165.
authorRobert Sesek <rsesek@bluestatic.org>
Wed, 22 Jul 2009 04:34:20 +0000 (00:34 -0400)
committerRobert Sesek <rsesek@bluestatic.org>
Wed, 22 Jul 2009 04:37:07 +0000 (00:37 -0400)
* Create a GDBpConnectionDelegate formal protocol.
  * No longer use notifications to pass errors from GDBpConnection to DebuggerController.
  * Add delegate methods for |-debuggerConnected| and |-debuggerDisconnected|.
* Move GDBpConnection's |-socketDidAccept| implementation into a helper so it can be run on the main thread.

CHANGES
English.lproj/Preferences.xib
Source/AppDelegate.m
Source/DebuggerController.h
Source/DebuggerController.m
Source/GDBpConnection.h
Source/GDBpConnection.m

diff --git a/CHANGES b/CHANGES
index 9f4a9c70e0af9bf9599aa0bab8d75997aca7b30b..2c2b4db5d7164f012418eeb7eda85428fcf4719a 100644 (file)
--- a/CHANGES
+++ b/CHANGES
@@ -1,6 +1,11 @@
 MacGDBp                                                               CHANGE LOG
 ================================================================================
 
+1.4
+#####################
+- New: #165  Added a preference to automatically reconnect after debugging
+
+
 1.3
 #####################
 - New: #155  Add a variable inspector to display the full, untruncated value
index e2176f712bd52c6cd9b8ce462823d8d7fb8501c8..0b28fa12f3296f73f3043356a14dcebf3d75f0a1 100644 (file)
                                <string key="NSFrameAutosaveName">Preferences</string>
                        </object>
                        <object class="NSUserDefaultsController" id="811642706">
+                               <object class="NSMutableArray" key="NSDeclaredKeys">
+                                       <bool key="EncodedWithXMLCoder">YES</bool>
+                                       <string>AutoReconnect</string>
+                               </object>
                                <bool key="NSSharedInstance">YES</bool>
                        </object>
                        <object class="NSCustomView" id="164161235">
                                        <object class="NSButton" id="708819028">
                                                <reference key="NSNextResponder" ref="164161235"/>
                                                <int key="NSvFlags">268</int>
-                                               <string key="NSFrame">{{164, 125}, {216, 18}}</string>
+                                               <string key="NSFrame">{{164, 147}, {216, 18}}</string>
                                                <reference key="NSSuperview" ref="164161235"/>
                                                <bool key="NSEnabled">YES</bool>
                                                <object class="NSButtonCell" key="NSCell" id="1053497655">
                                                        <reference key="NSControlView" ref="708819028"/>
                                                        <int key="NSButtonFlags">1211912703</int>
                                                        <int key="NSButtonFlags2">130</int>
-                                                       <object class="NSCustomResource" key="NSNormalImage">
+                                                       <object class="NSCustomResource" key="NSNormalImage" id="548552881">
                                                                <string key="NSClassName">NSImage</string>
                                                                <string key="NSResourceName">NSSwitch</string>
                                                        </object>
-                                                       <object class="NSButtonImageSource" key="NSAlternateImage">
+                                                       <object class="NSButtonImageSource" key="NSAlternateImage" id="471173519">
                                                                <string key="NSImageName">NSSwitch</string>
                                                        </object>
                                                        <string key="NSAlternateContents"/>
                                        <object class="NSTextField" id="421171423">
                                                <reference key="NSNextResponder" ref="164161235"/>
                                                <int key="NSvFlags">268</int>
-                                               <string key="NSFrame">{{15, 127}, {146, 17}}</string>
+                                               <string key="NSFrame">{{15, 149}, {146, 17}}</string>
                                                <reference key="NSSuperview" ref="164161235"/>
                                                <bool key="NSEnabled">YES</bool>
                                                <object class="NSTextFieldCell" key="NSCell" id="690767777">
                                                        <reference key="NSTextColor" ref="819706911"/>
                                                </object>
                                        </object>
+                                       <object class="NSButton" id="834917142">
+                                               <reference key="NSNextResponder" ref="164161235"/>
+                                               <int key="NSvFlags">268</int>
+                                               <string key="NSFrame">{{164, 125}, {216, 18}}</string>
+                                               <reference key="NSSuperview" ref="164161235"/>
+                                               <bool key="NSEnabled">YES</bool>
+                                               <object class="NSButtonCell" key="NSCell" id="971931499">
+                                                       <int key="NSCellFlags">67239424</int>
+                                                       <int key="NSCellFlags2">0</int>
+                                                       <string key="NSContents">Automatic reconnect</string>
+                                                       <reference key="NSSupport" ref="1004931791"/>
+                                                       <reference key="NSControlView" ref="834917142"/>
+                                                       <int key="NSButtonFlags">1211912703</int>
+                                                       <int key="NSButtonFlags2">130</int>
+                                                       <reference key="NSNormalImage" ref="548552881"/>
+                                                       <reference key="NSAlternateImage" ref="471173519"/>
+                                                       <string key="NSAlternateContents"/>
+                                                       <string key="NSKeyEquivalent"/>
+                                                       <int key="NSPeriodicDelay">200</int>
+                                                       <int key="NSPeriodicInterval">25</int>
+                                               </object>
+                                       </object>
                                </object>
-                               <string key="NSFrameSize">{421, 164}</string>
+                               <string key="NSFrameSize">{421, 186}</string>
                                <reference key="NSSuperview"/>
                                <string key="NSClassName">NSView</string>
                        </object>
                                        </object>
                                        <int key="connectionID">95</int>
                                </object>
+                               <object class="IBConnectionRecord">
+                                       <object class="IBBindingConnection" key="connection">
+                                               <string key="label">value: values.AutoReconnect</string>
+                                               <reference key="source" ref="834917142"/>
+                                               <reference key="destination" ref="811642706"/>
+                                               <object class="NSNibBindingConnector" key="connector">
+                                                       <reference key="NSSource" ref="834917142"/>
+                                                       <reference key="NSDestination" ref="811642706"/>
+                                                       <string key="NSLabel">value: values.AutoReconnect</string>
+                                                       <string key="NSBinding">value</string>
+                                                       <string key="NSKeyPath">values.AutoReconnect</string>
+                                                       <int key="NSNibBindingConnectorVersion">2</int>
+                                               </object>
+                                       </object>
+                                       <int key="connectionID">98</int>
+                               </object>
                        </object>
                        <object class="IBMutableOrderedSet" key="objectRecords">
                                <object class="NSArray" key="orderedObjects">
                                                        <bool key="EncodedWithXMLCoder">YES</bool>
                                                        <reference ref="708819028"/>
                                                        <reference ref="421171423"/>
+                                                       <reference ref="834917142"/>
                                                        <reference ref="190875294"/>
                                                        <reference ref="510392492"/>
                                                        <reference ref="249176901"/>
                                                <reference key="object" ref="690767777"/>
                                                <reference key="parent" ref="421171423"/>
                                        </object>
+                                       <object class="IBObjectRecord">
+                                               <int key="objectID">96</int>
+                                               <reference key="object" ref="834917142"/>
+                                               <object class="NSMutableArray" key="children">
+                                                       <bool key="EncodedWithXMLCoder">YES</bool>
+                                                       <reference ref="971931499"/>
+                                               </object>
+                                               <reference key="parent" ref="164161235"/>
+                                       </object>
+                                       <object class="IBObjectRecord">
+                                               <int key="objectID">97</int>
+                                               <reference key="object" ref="971931499"/>
+                                               <reference key="parent" ref="834917142"/>
+                                       </object>
                                </object>
                        </object>
                        <object class="NSMutableDictionary" key="flattenedProperties">
                                        <string>92.IBPluginDependency</string>
                                        <string>93.IBPluginDependency</string>
                                        <string>94.IBPluginDependency</string>
+                                       <string>96.IBAttributePlaceholdersKey</string>
+                                       <string>96.IBPluginDependency</string>
+                                       <string>97.IBPluginDependency</string>
                                </object>
                                <object class="NSMutableArray" key="dict.values">
                                        <bool key="EncodedWithXMLCoder">YES</bool>
                                        <string>com.apple.InterfaceBuilder.CocoaPlugin</string>
                                        <string>com.apple.InterfaceBuilder.CocoaPlugin</string>
                                        <string>com.apple.InterfaceBuilder.CocoaPlugin</string>
-                                       <string>{{483, 354}, {421, 164}}</string>
+                                       <string>{{483, 332}, {421, 186}}</string>
                                        <string>com.apple.InterfaceBuilder.CocoaPlugin</string>
                                        <string>com.apple.InterfaceBuilder.CocoaPlugin</string>
                                        <string>com.apple.InterfaceBuilder.CocoaPlugin</string>
                                        <string>com.apple.InterfaceBuilder.CocoaPlugin</string>
                                        <string>com.apple.InterfaceBuilder.CocoaPlugin</string>
                                        <string>com.apple.InterfaceBuilder.CocoaPlugin</string>
+                                       <object class="NSMutableDictionary">
+                                               <string key="NS.key.0">ToolTip</string>
+                                               <object class="IBToolTipAttribute" key="NS.object.0">
+                                                       <string key="name">ToolTip</string>
+                                                       <reference key="object" ref="834917142"/>
+                                                       <string key="toolTip">Automatically start listening for connections immediately after disconnecting. If disabled, you must use the reconnect toolbar button or menu command before debugging again.</string>
+                                               </object>
+                                       </object>
+                                       <string>com.apple.InterfaceBuilder.CocoaPlugin</string>
+                                       <string>com.apple.InterfaceBuilder.CocoaPlugin</string>
                                </object>
                        </object>
                        <object class="NSMutableDictionary" key="unlocalizedProperties">
                                </object>
                        </object>
                        <nil key="sourceID"/>
-                       <int key="maxID">95</int>
+                       <int key="maxID">98</int>
                </object>
                <object class="IBClassDescriber" key="IBDocument.Classes">
                        <object class="NSMutableArray" key="referencedPartialClassDescriptions">
index 70821612e1475eb16a6b75083aac1f96e678054d..b861bb239e9f7c33b7a3e49057ae3d894c4c217e 100644 (file)
        NSAutoreleasePool* pool = [NSAutoreleasePool new];
 
        NSDictionary* dict = [[NSDictionary alloc] initWithObjectsAndKeys:
-               [NSNumber numberWithInt:9000], @"Port",
-               @"macgdbp", @"IDEKey",
-               [NSNumber numberWithBool:YES], @"BreakpointsWindowVisible",
-               [NSNumber numberWithBool:YES], @"InspectorWindowVisible",
-               [NSMutableArray array], @"PathReplacements",
-               [NSNumber numberWithBool:YES], @"BreakOnFirstLine",
+               [NSNumber numberWithInt:9000],  @"Port",
+               @"macgdbp",                                             @"IDEKey",
+               [NSNumber numberWithBool:YES],  @"BreakpointsWindowVisible",
+               [NSNumber numberWithBool:YES],  @"InspectorWindowVisible",
+               [NSMutableArray array],                 @"PathReplacements",
+               [NSNumber numberWithBool:YES],  @"BreakOnFirstLine",
+               [NSNumber numberWithBool:NO],   @"AutoReconnect",
                nil
        ];
        
index 7000392e39dd60587f157aceee47f78acac98f29..22eed81f7df1f31fb3e2591a362dcde3a59a329f 100644 (file)
@@ -19,8 +19,9 @@
 #import "StackController.h"
 
 @class GDBpConnection;
+@protocol GDBpConnectionDelegate;
 
-@interface DebuggerController : NSWindowController
+@interface DebuggerController : NSWindowController <GDBpConnectionDelegate>
 {
        GDBpConnection* connection;
        
index 80aed82d0331ea3f359575d422432de54f243fa4..638173b9e853457ec8c88c6013ab368f7b3bb627 100644 (file)
@@ -14,8 +14,8 @@
  * write to the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA
  */
 
-#import "DebuggerController.h"
 #import "GDBpConnection.h"
+#import "DebuggerController.h"
 #import "NSXMLElementAdditions.h"
 #import "AppDelegate.h"
 #import "BreakpointManager.h"
                
                NSUserDefaults* defaults = [NSUserDefaults standardUserDefaults];
                connection = [[GDBpConnection alloc] initWithPort:[defaults integerForKey:@"Port"] session:[defaults stringForKey:@"IDEKey"]];
+               connection.delegate = self;
                expandedVariables = [[NSMutableSet alloc] init];
                [[self window] makeKeyAndOrderFront:nil];
                [[self window] setDelegate:self];
                
-               [[NSNotificationCenter defaultCenter]
-                       addObserver:self
-                       selector:@selector(handleConnectionError:)
-                       name:kErrorOccurredNotif
-                       object:connection
-               ];
-               
                if ([[NSUserDefaults standardUserDefaults] boolForKey:@"InspectorWindowVisible"])
                        [inspector orderFront:self];
        }
 /**
  * Handles a GDBpConnection error
  */
-- (void)handleConnectionError:(NSNotification*)notif
+- (void)errorEncountered:(NSString*)error
 {
-       [self setError:[[notif userInfo] valueForKey:@"NSString"]];
+       [self setError:error];
+}
+
+/**
+ * Delegate functioni for GDBpConnection for when the debugger connects.
+ */
+- (void)debuggerConnected
+{
+       [self startDebugger];
 }
 
 /**
                [self stepIn:self];
 }
 
+/**
+ * Called once the debugger disconnects.
+ */
+- (void)debuggerDisconnected
+{
+       if ([[NSUserDefaults standardUserDefaults] boolForKey:@"AutoReconnect"])
+               [self reconnect:self];
+}
+
 /**
  * Forwards the message to run script execution to the connection
  */
index 0a80c0146654e850571fe0a0f2c428d79c0e42f4..7c06b1f7969e99a85b574e5a4d3657577184ed1d 100644 (file)
@@ -19,7 +19,7 @@
 #import "Breakpoint.h"
 #import "StackFrame.h"
 
-extern NSString* kErrorOccurredNotif;
+@protocol GDBpConnectionDelegate;
 
 @interface GDBpConnection : NSObject <SocketWrapperDelegate>
 {
@@ -33,10 +33,13 @@ extern NSString* kErrorOccurredNotif;
        NSString* status;
        
        SocketWrapper* socket;
+       
+       id <GDBpConnectionDelegate> delegate;
 }
 
-@property(readonly, copy) NSString* status;
-@property(readonly) SocketWrapper* socket;
+@property (readonly, copy) NSString* status;
+@property (readonly) SocketWrapper* socket;
+@property (assign) id <GDBpConnectionDelegate> delegate;
 
 // initializer
 - (id)initWithPort:(int)aPort session:(NSString*)aSession;
@@ -61,3 +64,18 @@ extern NSString* kErrorOccurredNotif;
 - (NSArray*)getProperty:(NSString*)property;
 
 @end
+
+@protocol GDBpConnectionDelegate <NSObject>
+
+// Passes up errors from SocketWrapper and any other errors generated by the
+// GDBpConnection.
+- (void)errorEncountered:(NSString*)error;
+
+// Called when the socket connects. Passed up from SocketWrapper.
+- (void)debuggerConnected;
+
+// Called when we disconnect.
+- (void)debuggerDisconnected;
+
+@end
+
index 0386d88dd41224e061fb0e5e4accb030993d0b6c..96a170075c43b6a387303d736f9e0f2887b42b2b 100644 (file)
@@ -17,8 +17,6 @@
 #import "GDBpConnection.h"
 #import "AppDelegate.h"
 
-NSString* kErrorOccurredNotif = @"GDBpConnection_ErrorOccured_Notification";
-
 @interface GDBpConnection()
 @property(readwrite, copy) NSString* status;
 
@@ -28,11 +26,13 @@ NSString* kErrorOccurredNotif = @"GDBpConnection_ErrorOccured_Notification";
 - (StackFrame*)createCurrentStackFrame;
 - (void)updateStatus;
 - (NSString*)escapedURIPath:(NSString*)path;
+- (void)doSocketAccept:_nil;
 @end
 
 @implementation GDBpConnection
-
-@synthesize socket, status;
+@synthesize socket;
+@synthesize status;
+@synthesize delegate;
 
 /**
  * Creates a new DebuggerConnection and initializes the socket from the given connection
@@ -111,18 +111,7 @@ NSString* kErrorOccurredNotif = @"GDBpConnection_ErrorOccured_Notification";
  */
 - (void)socketDidAccept
 {
-       connected = YES;
-       [socket receive];
-       [self updateStatus];
-       
-       // register any breakpoints that exist offline
-       for (Breakpoint* bp in [[BreakpointManager sharedManager] breakpoints])
-       {
-               [self addBreakpoint:bp];
-       }
-       
-       // Load the debugger to make it look active.
-       [[[NSApp delegate] debugger] performSelectorOnMainThread:@selector(startDebugger) withObject:nil waitUntilDone:YES];
+       [self performSelectorOnMainThread:@selector(doSocketAccept:) withObject:nil waitUntilDone:YES];
 }
 
 /**
@@ -130,14 +119,7 @@ NSString* kErrorOccurredNotif = @"GDBpConnection_ErrorOccured_Notification";
  */
 - (void)errorEncountered:(NSString*)error
 {
-       [[NSNotificationCenter defaultCenter]
-               postNotificationName:kErrorOccurredNotif
-               object:self
-               userInfo:[NSDictionary
-                       dictionaryWithObject:error
-                       forKey:@"NSString"
-               ]
-       ];
+       [delegate errorEncountered:error];
 }
 
 /**
@@ -192,7 +174,6 @@ NSString* kErrorOccurredNotif = @"GDBpConnection_ErrorOccured_Notification";
        [socket receive];
        
        [self updateStatus];
-
 }
 
 /**
@@ -317,7 +298,7 @@ NSString* kErrorOccurredNotif = @"GDBpConnection_ErrorOccured_Notification";
        if ([error count] > 0)
        {
                NSLog(@"Xdebug error: %@", error);
-               [self errorEncountered:[[[[error objectAtIndex:0] children] objectAtIndex:0] stringValue]];
+               [delegate errorEncountered:[[[[error objectAtIndex:0] children] objectAtIndex:0] stringValue]];
                return nil;
        }
        
@@ -397,6 +378,9 @@ NSString* kErrorOccurredNotif = @"GDBpConnection_ErrorOccured_Notification";
        {
                connected = NO;
                [socket close];
+               
+               [delegate debuggerDisconnected];
+               
                self.status = @"Stopped";
        }
 }
@@ -423,4 +407,23 @@ NSString* kErrorOccurredNotif = @"GDBpConnection_ErrorOccured_Notification";
        return urlString;
 }
 
+/**
+ * Helper method for |-socketDidAccept| to be called on the main thread.
+ */
+- (void)doSocketAccept:_nil
+{
+       connected = YES;
+       [socket receive];
+       [self updateStatus];
+       
+       // register any breakpoints that exist offline
+       for (Breakpoint* bp in [[BreakpointManager sharedManager] breakpoints])
+       {
+               [self addBreakpoint:bp];
+       }
+       
+       // Load the debugger to make it look active.
+       [delegate debuggerConnected];
+}
+
 @end