diff options
author | stuconnolly <stuart02@gmail.com> | 2010-10-20 20:08:08 +0000 |
---|---|---|
committer | stuconnolly <stuart02@gmail.com> | 2010-10-20 20:08:08 +0000 |
commit | c92776958cb5d5fca8f165e9bac043e5a91521dc (patch) | |
tree | 9146f7a5f62b799eadf8126f3b3708284e940fd8 /Frameworks/MCPKit | |
parent | 3b92b30ca625eff33df49b538e3c4f2da7a9cf09 (diff) | |
download | sequelpro-c92776958cb5d5fca8f165e9bac043e5a91521dc.tar.gz sequelpro-c92776958cb5d5fca8f165e9bac043e5a91521dc.tar.bz2 sequelpro-c92776958cb5d5fca8f165e9bac043e5a91521dc.zip |
Split MCPConnection's delegate methods into it's own protocol.
Diffstat (limited to 'Frameworks/MCPKit')
6 files changed, 152 insertions, 114 deletions
diff --git a/Frameworks/MCPKit/MCPFoundationKit/MCPConnection.h b/Frameworks/MCPKit/MCPFoundationKit/MCPConnection.h index 609830ce..ad30fa07 100644 --- a/Frameworks/MCPKit/MCPFoundationKit/MCPConnection.h +++ b/Frameworks/MCPKit/MCPFoundationKit/MCPConnection.h @@ -38,101 +38,21 @@ typedef struct { BOOL *lastPingSuccessPointer; } MCPConnectionPingDetails; -@protocol MCPConnectionProxy; - @class MCPResult, MCPStreamingResult; - -@interface NSObject (MCPConnectionDelegate) - -/** - * - */ -- (void)willQueryString:(NSString *)query connection:(id)connection; - -/** - * - */ -- (void)queryGaveError:(NSString *)error connection:(id)connection; - -/** - * - */ -- (void)showErrorWithTitle:(NSString *)error message:(NSString *)connection; - -/** - * - */ -- (NSString *)keychainPasswordForConnection:(id)connection; - -/** - * - */ -- (NSString *)onReconnectShouldSelectDatabase:(id)connection; - -/** - * - */ -- (void)noConnectionAvailable:(id)connection; - -/** - * - */ -- (MCPConnectionCheck)connectionLost:(id)connection; - -/** - * - */ -- (NSString *)connectionID; - -/** - * - */ -- (NSString *)database; - -/** - * - */ -- (BOOL)navigatorSchemaPathExistsForDatabase:(NSString*)dbname; - -/** - * - */ -- (NSArray*)allDatabaseNames; - -/** - * - */ -- (NSArray*)allSystemDatabaseNames; - -/** - * - */ -- (NSArray*)allTableNames; - -/** - * - */ -- (NSArray*)allViewNames; - -/** - * - */ -- (NSArray*)allSchemaKeys; - -@end +@protocol MCPConnectionProxy, MCPConnectionDelegate; @interface MCPConnection : NSObject { - MYSQL *mConnection; /* The inited MySQL connection. */ - BOOL mConnected; /* Reflect the fact that the connection is already in place or not. */ - NSStringEncoding mEncoding; /* The encoding used by MySQL server, to ISO-1 default. */ - NSTimeZone *mTimeZone; /* The time zone of the session. */ - NSUInteger mConnectionFlags; /* The flags to be used for the connection to the database. */ + MYSQL *mConnection; + BOOL mConnected; + NSStringEncoding mEncoding; + NSTimeZone *mTimeZone; + NSUInteger mConnectionFlags; - id delegate; /* Connection delegate */ + id <MCPConnectionDelegate> delegate; - /* Anything that performs a mysql_net_read is not thread-safe: mysql queries, pings */ - /* Always lock the connection first. Don't use this lock directly, use the lockConnection method! */ + // Anything that performs a mysql_net_read is not thread-safe: mysql queries, pings + // Always lock the connection first. Don't use this lock directly, use the lockConnection method! NSConditionLock *connectionLock; BOOL useKeepAlive; diff --git a/Frameworks/MCPKit/MCPFoundationKit/MCPConnection.m b/Frameworks/MCPKit/MCPFoundationKit/MCPConnection.m index 15eaae82..f503db55 100644 --- a/Frameworks/MCPKit/MCPFoundationKit/MCPConnection.m +++ b/Frameworks/MCPKit/MCPFoundationKit/MCPConnection.m @@ -60,6 +60,25 @@ static BOOL sTruncateLongFieldInLogs = YES; @end +/** + * Note that these aren't actually delegate methods, but are defined because queryDbStructureWithUserInfo needs + * them. We define them here to supress compiler warnings. + * + * TODO: Remove along with queryDbStructureWithUserInfo + */ +@interface MCPConnection (MCPConnectionDelegate) + +- (NSString *)database; +- (NSString *)connectionID; + +- (NSArray *)allDatabaseNames; +- (NSArray *)allSystemDatabaseNames; +- (NSArray *)allTableNames; +- (NSArray *)allViewNames; +- (NSArray *)allSchemaKeys; + +@end + @implementation MCPConnection // Synthesize ivars @@ -2222,6 +2241,8 @@ void pingThreadCleanup(MCPConnectionPingDetails *pingDetails) /** * Updates the dict containing the structure of all available databases (mainly for completion/navigator) * executed on a new connection. + * + * TODO: Split this entire method out of MCPKit if possible */ - (void)queryDbStructureWithUserInfo:(NSDictionary*)userInfo { @@ -2331,7 +2352,7 @@ void pingThreadCleanup(MCPConnectionPingDetails *pingDetails) return; } - // Retrieve the tables and views for this database from SPTablesList (TODO: split out of MCPKit) + // Retrieve the tables and views for this database from SPTablesList NSMutableArray *tablesAndViews = [NSMutableArray array]; for (id aTable in [[[self delegate] valueForKeyPath:@"tablesListInstance"] allTableNames]) { NSDictionary *aTableDict = [NSDictionary dictionaryWithObjectsAndKeys: diff --git a/Frameworks/MCPKit/MCPFoundationKit/MCPConnectionDelegate.h b/Frameworks/MCPKit/MCPFoundationKit/MCPConnectionDelegate.h new file mode 100644 index 00000000..3cbba325 --- /dev/null +++ b/Frameworks/MCPKit/MCPFoundationKit/MCPConnectionDelegate.h @@ -0,0 +1,81 @@ +// +// $Id$ +// +// MCPConnectionDelegate.h +// MCPKit +// +// Created by Stuart Connolly (stuconnolly.com) on October 20, 2010. +// Copyright (c) 2010 Stuart Connolly. All rights reserved. +// +// Forked by the Sequel Pro team (sequelpro.com), April 2009 +// +// This program is free software; you can redistribute it and/or modify +// it under the terms of the GNU General Public License as published by +// the Free Software Foundation; either version 2 of the License, or +// (at your option) any later version. +// +// This program is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU General Public License for more details. +// +// You should have received a copy of the GNU General Public License +// along with this program; if not, write to the Free Software +// Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA +// +// More info at <http://mysql-cocoa.sourceforge.net/> +// More info at <http://code.google.com/p/sequel-pro/> + +@protocol MCPConnectionDelegate + +/** + * + * @param query + * @param connection + */ +- (void)willQueryString:(NSString *)query connection:(id)connection; + +/** + * + * @param error + * @param connection + */ +- (void)queryGaveError:(NSString *)error connection:(id)connection; + +/** + * + * + * @param error + * @param message + */ +- (void)showErrorWithTitle:(NSString *)error message:(NSString *)message; + +/** + * + * + * @param connection + */ +- (NSString *)keychainPasswordForConnection:(id)connection; + +/** + * + * + * @param connection + */ +- (NSString *)onReconnectShouldSelectDatabase:(id)connection; + +/** + * + * + * @param connection + */ +- (void)noConnectionAvailable:(id)connection; + +/** + * + * + * @param connection + */ +- (MCPConnectionCheck)connectionLost:(id)connection; + +@end diff --git a/Frameworks/MCPKit/MCPFoundationKit/MCPKit.h b/Frameworks/MCPKit/MCPFoundationKit/MCPKit.h index b83ebb69..57e6d62d 100644 --- a/Frameworks/MCPKit/MCPFoundationKit/MCPKit.h +++ b/Frameworks/MCPKit/MCPFoundationKit/MCPKit.h @@ -36,7 +36,9 @@ #import <MCPKit/MCPNumber.h> #import <MCPKit/MCPResultPlus.h> #import <MCPKit/MCPFastQueries.h> -#import <MCPKit/MCPConnectionProxy.h> #import <MCPKit/MCPGeometryData.h> +#import <MCPKit/MCPConnectionProxy.h> +#import <MCPKit/MCPConnectionDelegate.h> + #import "mysql.h" diff --git a/Frameworks/MCPKit/Support files/NSNotificationAdditions.h b/Frameworks/MCPKit/Support files/NSNotificationAdditions.h index 33c8ec10..7d0d6f9a 100644 --- a/Frameworks/MCPKit/Support files/NSNotificationAdditions.h +++ b/Frameworks/MCPKit/Support files/NSNotificationAdditions.h @@ -25,11 +25,11 @@ @interface NSNotificationCenter (NSNotificationCenterAdditions) -- (void) postNotificationOnMainThread:(NSNotification *) notification; -- (void) postNotificationOnMainThread:(NSNotification *) notification waitUntilDone:(BOOL) wait; +- (void)postNotificationOnMainThread:(NSNotification *)notification; +- (void)postNotificationOnMainThread:(NSNotification *)notification waitUntilDone:(BOOL)wait; -- (void) postNotificationOnMainThreadWithName:(NSString *) name object:(id) object; -- (void) postNotificationOnMainThreadWithName:(NSString *) name object:(id) object userInfo:(NSDictionary *) userInfo; -- (void) postNotificationOnMainThreadWithName:(NSString *) name object:(id) object userInfo:(NSDictionary *) userInfo waitUntilDone:(BOOL) wait; +- (void)postNotificationOnMainThreadWithName:(NSString *)name object:(id)object; +- (void)postNotificationOnMainThreadWithName:(NSString *)name object:(id)object userInfo:(NSDictionary *)userInfo; +- (void)postNotificationOnMainThreadWithName:(NSString *)name object:(id)object userInfo:(NSDictionary *)userInfo waitUntilDone:(BOOL)wait; @end diff --git a/Frameworks/MCPKit/Support files/NSNotificationAdditions.m b/Frameworks/MCPKit/Support files/NSNotificationAdditions.m index f27a4d5c..d615231e 100644 --- a/Frameworks/MCPKit/Support files/NSNotificationAdditions.m +++ b/Frameworks/MCPKit/Support files/NSNotificationAdditions.m @@ -24,50 +24,64 @@ // More info at <http://code.google.com/p/sequel-pro/> #import "NSNotificationAdditions.h" -#import <pthread.h> +#import "pthread.h" @implementation NSNotificationCenter (NSNotificationCenterAdditions) -- (void) postNotificationOnMainThread:(NSNotification *) notification { - if( pthread_main_np() ) return [self postNotification:notification]; +- (void)postNotificationOnMainThread:(NSNotification *)notification +{ + if (pthread_main_np()) return [self postNotification:notification]; + [self postNotificationOnMainThread:notification waitUntilDone:NO]; } -- (void) postNotificationOnMainThread:(NSNotification *) notification waitUntilDone:(BOOL) wait { - if( pthread_main_np() ) return [self postNotification:notification]; - [[self class] performSelectorOnMainThread:@selector( _postNotification: ) withObject:notification waitUntilDone:wait]; +- (void)postNotificationOnMainThread:(NSNotification *)notification waitUntilDone:(BOOL)wait +{ + if (pthread_main_np()) return [self postNotification:notification]; + + [[self class] performSelectorOnMainThread:@selector(_postNotification:) withObject:notification waitUntilDone:wait]; } -+ (void) _postNotification:(NSNotification *) notification { ++ (void)_postNotification:(NSNotification *)notification +{ [[self defaultCenter] postNotification:notification]; } -- (void) postNotificationOnMainThreadWithName:(NSString *) name object:(id) object { - if( pthread_main_np() ) return [self postNotificationName:name object:object userInfo:nil]; +- (void)postNotificationOnMainThreadWithName:(NSString *)name object:(id)object +{ + if (pthread_main_np()) return [self postNotificationName:name object:object userInfo:nil]; + [self postNotificationOnMainThreadWithName:name object:object userInfo:nil waitUntilDone:NO]; } -- (void) postNotificationOnMainThreadWithName:(NSString *) name object:(id) object userInfo:(NSDictionary *) userInfo { - if( pthread_main_np() ) return [self postNotificationName:name object:object userInfo:userInfo]; +- (void)postNotificationOnMainThreadWithName:(NSString *)name object:(id)object userInfo:(NSDictionary *)userInfo +{ + if(pthread_main_np()) return [self postNotificationName:name object:object userInfo:userInfo]; + [self postNotificationOnMainThreadWithName:name object:object userInfo:userInfo waitUntilDone:NO]; } -- (void) postNotificationOnMainThreadWithName:(NSString *) name object:(id) object userInfo:(NSDictionary *) userInfo waitUntilDone:(BOOL) wait { - if( pthread_main_np() ) return [self postNotificationName:name object:object userInfo:userInfo]; +- (void)postNotificationOnMainThreadWithName:(NSString *)name object:(id)object userInfo:(NSDictionary *)userInfo waitUntilDone:(BOOL)wait +{ + if (pthread_main_np()) return [self postNotificationName:name object:object userInfo:userInfo]; NSMutableDictionary *info = [[NSMutableDictionary allocWithZone:nil] initWithCapacity:3]; - if( name ) [info setObject:name forKey:@"name"]; - if( object ) [info setObject:object forKey:@"object"]; - if( userInfo ) [info setObject:userInfo forKey:@"userInfo"]; + + if (name) [info setObject:name forKey:@"name"]; + if (object) [info setObject:object forKey:@"object"]; + if (userInfo) [info setObject:userInfo forKey:@"userInfo"]; - [[self class] performSelectorOnMainThread:@selector( _postNotificationName: ) withObject:info waitUntilDone:wait]; + [[self class] performSelectorOnMainThread:@selector(_postNotificationName:) withObject:info waitUntilDone:wait]; [info release]; } -+ (void) _postNotificationName:(NSDictionary *) info { ++ (void)_postNotificationName:(NSDictionary *)info +{ NSString *name = [info objectForKey:@"name"]; + id object = [info objectForKey:@"object"]; + NSDictionary *userInfo = [info objectForKey:@"userInfo"]; [[self defaultCenter] postNotificationName:name object:object userInfo:userInfo]; |