Skip to content
Browse files

Delete UKKQueue

Can always add it back as a submodule if desperately needed, but GCD is
likely a better fit these days anyway
  • Loading branch information...
1 parent e36a074 commit b7dd189eaccd350bdfc41f2a9d6ba8c2287a1d63 @mikeabdullah mikeabdullah committed Mar 22, 2013
View
37 Connection.xcodeproj/project.pbxproj
@@ -78,13 +78,6 @@
791E83050B0EDAC90060E5FC /* error.png in Resources */ = {isa = PBXBuildFile; fileRef = 791E83030B0EDAC90060E5FC /* error.png */; };
791E83060B0EDAC90060E5FC /* finished.png in Resources */ = {isa = PBXBuildFile; fileRef = 791E83040B0EDAC90060E5FC /* finished.png */; };
792BC96C0ABF7EC10022415A /* NSString+Connection.h in Headers */ = {isa = PBXBuildFile; fileRef = 792BC8B00ABF6B2E0022415A /* NSString+Connection.h */; settings = {ATTRIBUTES = (Public, ); }; };
- 795AFEF50B115511006905FA /* UKFileWatcher.h in Headers */ = {isa = PBXBuildFile; fileRef = 795AFEEC0B115511006905FA /* UKFileWatcher.h */; };
- 795AFEF60B115511006905FA /* UKFileWatcher.m in Sources */ = {isa = PBXBuildFile; fileRef = 795AFEED0B115511006905FA /* UKFileWatcher.m */; };
- 795AFEF90B115511006905FA /* UKKQueue Readme.txt in Resources */ = {isa = PBXBuildFile; fileRef = 795AFEF00B115511006905FA /* UKKQueue Readme.txt */; };
- 795AFEFA0B115511006905FA /* UKKQueue.h in Headers */ = {isa = PBXBuildFile; fileRef = 795AFEF10B115511006905FA /* UKKQueue.h */; };
- 795AFEFB0B115511006905FA /* UKKQueue.m in Sources */ = {isa = PBXBuildFile; fileRef = 795AFEF20B115511006905FA /* UKKQueue.m */; };
- 795AFEFC0B115511006905FA /* UKMainThreadProxy.h in Headers */ = {isa = PBXBuildFile; fileRef = 795AFEF30B115511006905FA /* UKMainThreadProxy.h */; };
- 795AFEFD0B115511006905FA /* UKMainThreadProxy.m in Sources */ = {isa = PBXBuildFile; fileRef = 795AFEF40B115511006905FA /* UKMainThreadProxy.m */; };
795E44DF0AC5F748007912A2 /* NSString+Connection.m in Sources */ = {isa = PBXBuildFile; fileRef = 792BC8B10ABF6B2E0022415A /* NSString+Connection.m */; };
796DB30109F8BB1D0065897B /* SecurityInterface.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = 796DB2F609F8BB1D0065897B /* SecurityInterface.framework */; };
7978FC150B117D7C0048168B /* bookmark.tif in Resources */ = {isa = PBXBuildFile; fileRef = 7978FC140B117D7C0048168B /* bookmark.tif */; };
@@ -276,13 +269,6 @@
792BC8B10ABF6B2E0022415A /* NSString+Connection.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; name = "NSString+Connection.m"; path = "ConnectionKit/NSString+Connection.m"; sourceTree = "<group>"; };
7946B0FC0AC0F4A400CAE90F /* CKS3Connection.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = CKS3Connection.h; sourceTree = "<group>"; };
7946B0FD0AC0F4A400CAE90F /* CKS3Connection.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = CKS3Connection.m; sourceTree = "<group>"; };
- 795AFEEC0B115511006905FA /* UKFileWatcher.h */ = {isa = PBXFileReference; fileEncoding = 30; lastKnownFileType = sourcecode.c.h; path = UKFileWatcher.h; sourceTree = "<group>"; };
- 795AFEED0B115511006905FA /* UKFileWatcher.m */ = {isa = PBXFileReference; fileEncoding = 30; lastKnownFileType = sourcecode.c.objc; path = UKFileWatcher.m; sourceTree = "<group>"; };
- 795AFEF00B115511006905FA /* UKKQueue Readme.txt */ = {isa = PBXFileReference; fileEncoding = 30; lastKnownFileType = text; path = "UKKQueue Readme.txt"; sourceTree = "<group>"; };
- 795AFEF10B115511006905FA /* UKKQueue.h */ = {isa = PBXFileReference; fileEncoding = 30; lastKnownFileType = sourcecode.c.h; path = UKKQueue.h; sourceTree = "<group>"; };
- 795AFEF20B115511006905FA /* UKKQueue.m */ = {isa = PBXFileReference; fileEncoding = 30; lastKnownFileType = sourcecode.c.objc; path = UKKQueue.m; sourceTree = "<group>"; };
- 795AFEF30B115511006905FA /* UKMainThreadProxy.h */ = {isa = PBXFileReference; fileEncoding = 30; lastKnownFileType = sourcecode.c.h; path = UKMainThreadProxy.h; sourceTree = "<group>"; };
- 795AFEF40B115511006905FA /* UKMainThreadProxy.m */ = {isa = PBXFileReference; fileEncoding = 30; lastKnownFileType = sourcecode.c.objc; path = UKMainThreadProxy.m; sourceTree = "<group>"; };
796DB2F609F8BB1D0065897B /* SecurityInterface.framework */ = {isa = PBXFileReference; lastKnownFileType = wrapper.framework; name = SecurityInterface.framework; path = /System/Library/Frameworks/SecurityInterface.framework; sourceTree = "<absolute>"; };
7978FC140B117D7C0048168B /* bookmark.tif */ = {isa = PBXFileReference; lastKnownFileType = image.tiff; path = bookmark.tif; sourceTree = "<group>"; };
797CC8C609F861770063FF9B /* en */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = text.plist.strings; lineEnding = 0; name = en; path = en.lproj/Localizable.strings; sourceTree = "<group>"; };
@@ -620,21 +606,6 @@
name = Frameworks;
sourceTree = "<group>";
};
- 795AFEE50B1154E2006905FA /* UKKQueue */ = {
- isa = PBXGroup;
- children = (
- 795AFEEC0B115511006905FA /* UKFileWatcher.h */,
- 795AFEED0B115511006905FA /* UKFileWatcher.m */,
- 795AFEF00B115511006905FA /* UKKQueue Readme.txt */,
- 795AFEF10B115511006905FA /* UKKQueue.h */,
- 795AFEF20B115511006905FA /* UKKQueue.m */,
- 795AFEF30B115511006905FA /* UKMainThreadProxy.h */,
- 795AFEF40B115511006905FA /* UKMainThreadProxy.m */,
- );
- name = UKKQueue;
- path = ../UKQueue;
- sourceTree = "<group>";
- };
79CFD11A09F7022900172CDD /* Connections */ = {
isa = PBXGroup;
children = (
@@ -650,7 +621,6 @@
79CFD8A009F705B400172CDD /* Utility */ = {
isa = PBXGroup;
children = (
- 795AFEE50B1154E2006905FA /* UKKQueue */,
2790A8201626CA67000C9D9F /* CK2RemoteURL.h */,
2790A8211626CA67000C9D9F /* CK2RemoteURL.m */,
);
@@ -696,9 +666,6 @@
79CFD89509F704F400172CDD /* Connection.h in Headers */,
7983DF8E0B0C0FAC00F5078E /* CKTransferRecord.h in Headers */,
798313C90B0D67E000F5078E /* CKTransferProgressCell.h in Headers */,
- 795AFEF50B115511006905FA /* UKFileWatcher.h in Headers */,
- 795AFEFA0B115511006905FA /* UKKQueue.h in Headers */,
- 795AFEFC0B115511006905FA /* UKMainThreadProxy.h in Headers */,
27D03B421471787000FEA588 /* CKUploader.h in Headers */,
2702E3EF1459CB550085BBC4 /* CK2SFTPFileHandle.h in Headers */,
2702E3F11459CB550085BBC4 /* CK2SFTPSession.h in Headers */,
@@ -880,7 +847,6 @@
797CC8C709F861770063FF9B /* Localizable.strings in Resources */,
791E83050B0EDAC90060E5FC /* error.png in Resources */,
791E83060B0EDAC90060E5FC /* finished.png in Resources */,
- 795AFEF90B115511006905FA /* UKKQueue Readme.txt in Resources */,
7978FC150B117D7C0048168B /* bookmark.tif in Resources */,
227113BF168388FD00280005 /* http.json in Resources */,
);
@@ -983,9 +949,6 @@
795E44DF0AC5F748007912A2 /* NSString+Connection.m in Sources */,
7983DF8F0B0C0FAC00F5078E /* CKTransferRecord.m in Sources */,
798313CA0B0D67E000F5078E /* CKTransferProgressCell.m in Sources */,
- 795AFEF60B115511006905FA /* UKFileWatcher.m in Sources */,
- 795AFEFB0B115511006905FA /* UKKQueue.m in Sources */,
- 795AFEFD0B115511006905FA /* UKMainThreadProxy.m in Sources */,
2702E3F01459CB550085BBC4 /* CK2SFTPFileHandle.m in Sources */,
2702E3F21459CB550085BBC4 /* CK2SFTPSession.m in Sources */,
27D03B431471787000FEA588 /* CKUploader.m in Sources */,
View
62 UKQueue/UKFileWatcher.h
@@ -1,62 +0,0 @@
-/* =============================================================================
- FILE: UKFileWatcher.h
- PROJECT: Filie
-
- COPYRIGHT: (c) 2005 M. Uli Kusterer, all rights reserved.
-
- AUTHORS: M. Uli Kusterer - UK
-
- LICENSES: MIT License
-
- REVISIONS:
- 2006-03-13 UK Moved notification constants to .m file.
- 2005-02-25 UK Created.
- ========================================================================== */
-
-/*
- This is a protocol that file change notification classes should adopt.
- That way, no matter whether you use Carbon's FNNotify/FNSubscribe, BSD's
- kqueue or whatever, the object being notified can react to change
- notifications the same way, and you can easily swap one out for the other
- to cater to different OS versions, target volumes etc.
-*/
-
-// -----------------------------------------------------------------------------
-// Protocol:
-// -----------------------------------------------------------------------------
-
-@protocol UKFileWatcher
-
-// +(id) sharedFileWatcher; // Singleton accessor. Not officially part of the protocol, but use this name if you provide a singleton.
-
--(void) addPath: (NSString*)path;
--(void) removePath: (NSString*)path;
-
--(id) delegate;
--(void) setDelegate: (id)newDelegate;
-
-@end
-
-// -----------------------------------------------------------------------------
-// Methods delegates need to provide:
-// -----------------------------------------------------------------------------
-
-@interface NSObject (UKFileWatcherDelegate)
-
--(void) watcher: (id<UKFileWatcher>)kq receivedNotification: (NSString*)nm forPath: (NSString*)fpath;
-
-@end
-
-
-// Notifications this sends:
-/* object = the file watcher object
- userInfo.path = file path watched
- These notifications are sent via the NSWorkspace notification center */
-extern NSString* UKFileWatcherRenameNotification;
-extern NSString* UKFileWatcherWriteNotification;
-extern NSString* UKFileWatcherDeleteNotification;
-extern NSString* UKFileWatcherAttributeChangeNotification;
-extern NSString* UKFileWatcherSizeIncreaseNotification;
-extern NSString* UKFileWatcherLinkCountChangeNotification;
-extern NSString* UKFileWatcherAccessRevocationNotification;
-
View
38 UKQueue/UKFileWatcher.m
@@ -1,38 +0,0 @@
-/* =============================================================================
- FILE: UKKQueue.m
- PROJECT: Filie
-
- COPYRIGHT: (c) 2005-06 M. Uli Kusterer, all rights reserved.
-
- AUTHORS: M. Uli Kusterer - UK
-
- LICENSES: MIT License
-
- REVISIONS:
- 2006-03-13 UK Created, moved notification constants here as exportable
- symbols.
- ========================================================================== */
-
-// -----------------------------------------------------------------------------
-// Headers:
-// -----------------------------------------------------------------------------
-
-#import <Cocoa/Cocoa.h>
-#import "UKFileWatcher.h"
-
-
-// -----------------------------------------------------------------------------
-// Constants:
-// -----------------------------------------------------------------------------
-
-// Do not rely on the actual contents of these constants. They will eventually
-// be changed to be more generic and less KQueue-specific.
-
-NSString* UKFileWatcherRenameNotification = @"UKKQueueFileRenamedNotification";
-NSString* UKFileWatcherWriteNotification = @"UKKQueueFileWrittenToNotification";
-NSString* UKFileWatcherDeleteNotification = @"UKKQueueFileDeletedNotification";
-NSString* UKFileWatcherAttributeChangeNotification = @"UKKQueueFileAttributesChangedNotification";
-NSString* UKFileWatcherSizeIncreaseNotification = @"UKKQueueFileSizeIncreasedNotification";
-NSString* UKFileWatcherLinkCountChangeNotification = @"UKKQueueFileLinkCountChangedNotification";
-NSString* UKFileWatcherAccessRevocationNotification = @"UKKQueueFileAccessRevocationNotification";
-
View
32 UKQueue/UKKQueue Readme.txt
@@ -1,32 +0,0 @@
-UKKQUEUE
---------
-
-A wrapper class around the kqueue file change notification mechanism.
-
-Simply create a UKKQueue (or use the singleton), add a few paths to it and listen to the change notifications via NSWorkspace's notification center.
-
-LICENSE:
-
-(c) 2003-06 by M. Uli Kusterer. You may redistribute, modify, use in
-commercial products free of charge, however distributing modified copies
-requires that you clearly mark them as having been modified by you, while
-maintaining the original markings and copyrights. I don't like getting bug
-reports about code I wasn't involved in.
-
-I'd also appreciate if you gave credit in your app's about screen or a similar
-place. A simple "Thanks to M. Uli Kusterer" is quite sufficient.
-Also, I rarely turn down any postcards, gifts, complementary copies of
-applications etc.
-
-
-REVISION HISTORY:
-0.1 - Initial release.
-0.2 - Now calls delegate on main thread using UKMainThreadProxy, and checks retain count to make sure the object is released even when the thread is still holding on to it. Equivalent to SVN revision 79.
-0.3 - Now adopts UKFileWatcher protocol to allow swapping out a kqueue for another scheme easily. Uses O_EVONLY instead of O_RDONLY to open the file without preventing it from being deleted or its drive ejected.
-0.4 - Now includes UKFNSubscribeFileWatcher, and closes the kqueue file descriptor in a separate thread (thanks to Dominic Yu for the suggestion!) so you don't have to wait for close() to time out.
-0.5 - Turns off all deprecated features. Changes the notifications to make it possible to subscribe to them more selectively. Changes notification constants to be safer for apps that expose KQueue to their plugins. FNSubscribeFileWatcher now also sends notifications (sorry, "write" only).
-
-
-CONTACT:
-Get the newest version at http://www.zathras.de
-E-Mail me at witness (at) zathras (dot) de or witness (dot) of (dot) teachtext (at) gmx (dot) net
View
122 UKQueue/UKKQueue.h
@@ -1,122 +0,0 @@
-/* =============================================================================
- FILE: UKKQueue.h
- PROJECT: Filie
-
- COPYRIGHT: (c) 2003 M. Uli Kusterer, all rights reserved.
-
- AUTHORS: M. Uli Kusterer - UK
-
- LICENSES: MIT License
-
- REVISIONS:
- 2006-03-13 UK Clarified license, streamlined UKFileWatcher stuff,
- Changed notifications to be useful and turned off by
- default some deprecated stuff.
- 2003-12-21 UK Created.
- ========================================================================== */
-
-// -----------------------------------------------------------------------------
-// Headers:
-// -----------------------------------------------------------------------------
-
-#import <Foundation/Foundation.h>
-#include <sys/types.h>
-#include <sys/event.h>
-#import "UKFileWatcher.h"
-
-
-// -----------------------------------------------------------------------------
-// Constants:
-// -----------------------------------------------------------------------------
-
-// Backwards compatibility constants. Don't rely on code commented out with these constants, because it may be deleted in a future version.
-#ifndef UKKQUEUE_BACKWARDS_COMPATIBLE
-#define UKKQUEUE_BACKWARDS_COMPATIBLE 0 // 1 to send old-style kqueue:receivedNotification:forFile: messages to objects that accept them.
-#endif
-
-#ifndef UKKQUEUE_SEND_STUPID_NOTIFICATIONS
-#define UKKQUEUE_SEND_STUPID_NOTIFICATIONS 0 // 1 to send old-style notifications that have the path as the object and no userInfo dictionary.
-#endif
-
-#ifndef UKKQUEUE_OLD_SINGLETON_ACCESSOR_NAME
-#define UKKQUEUE_OLD_SINGLETON_ACCESSOR_NAME 0 // 1 to allow use of sharedQueue instead of sharedFileWatcher.
-#endif
-
-#ifndef UKKQUEUE_OLD_NOTIFICATION_NAMES
-#define UKKQUEUE_OLD_NOTIFICATION_NAMES 0 // 1 to allow use of old KQueue-style notification names instead of the new more generic ones in UKFileWatcher.
-#endif
-
-// Flags for notifyingAbout:
-#define UKKQueueNotifyAboutRename NOTE_RENAME // Item was renamed.
-#define UKKQueueNotifyAboutWrite NOTE_WRITE // Item contents changed (also folder contents changed).
-#define UKKQueueNotifyAboutDelete NOTE_DELETE // item was removed.
-#define UKKQueueNotifyAboutAttributeChange NOTE_ATTRIB // Item attributes changed.
-#define UKKQueueNotifyAboutSizeIncrease NOTE_EXTEND // Item size increased.
-#define UKKQueueNotifyAboutLinkCountChanged NOTE_LINK // Item's link count changed.
-#define UKKQueueNotifyAboutAccessRevocation NOTE_REVOKE // Access to item was revoked.
-
-// Notifications this sends:
-// (see UKFileWatcher)
-// Old names: *deprecated*
-#if UKKQUEUE_OLD_NOTIFICATION_NAMES
-#define UKKQueueFileRenamedNotification UKFileWatcherRenameNotification
-#define UKKQueueFileWrittenToNotification UKFileWatcherWriteNotification
-#define UKKQueueFileDeletedNotification UKFileWatcherDeleteNotification
-#define UKKQueueFileAttributesChangedNotification UKFileWatcherAttributeChangeNotification
-#define UKKQueueFileSizeIncreasedNotification UKFileWatcherSizeIncreaseNotification
-#define UKKQueueFileLinkCountChangedNotification UKFileWatcherLinkCountChangeNotification
-#define UKKQueueFileAccessRevocationNotification UKFileWatcherAccessRevocationNotification
-#endif
-
-
-// -----------------------------------------------------------------------------
-// UKKQueue:
-// -----------------------------------------------------------------------------
-
-@interface UKKQueue : NSObject <UKFileWatcher>
-{
- int queueFD; // The actual queue ID (Unix file descriptor).
- NSMutableArray* watchedPaths; // List of NSStrings containing the paths we're watching.
- NSMutableArray* watchedFDs; // List of NSNumbers containing the file descriptors we're watching.
- id delegate; // Gets messages about changes instead of notification center, if specified.
- id delegateProxy; // Proxy object to which we send messages so they reach delegate on the main thread.
- BOOL alwaysNotify; // Send notifications even if we have a delegate? Defaults to NO.
- BOOL keepThreadRunning; // Termination criterion of our thread.
-}
-
-+(id) sharedFileWatcher; // Returns a singleton, a shared kqueue object Handy if you're subscribing to the notifications. Use this, or just create separate objects using alloc/init. Whatever floats your boat.
-
--(int) queueFD; // I know you unix geeks want this...
-
-// High-level file watching: (use UKFileWatcher protocol methods instead, where possible!)
--(void) addPathToQueue: (NSString*)path;
--(void) addPathToQueue: (NSString*)path notifyingAbout: (u_int)fflags;
--(void) removePathFromQueue: (NSString*)path;
-
--(id) delegate;
--(void) setDelegate: (id)newDelegate;
-
--(BOOL) alwaysNotify;
--(void) setAlwaysNotify: (BOOL)n;
-
-#if UKKQUEUE_OLD_SINGLETON_ACCESSOR_NAME
-+(UKKQueue*) sharedQueue;
-#endif
-
-// private:
--(void) watcherThread: (id)sender;
--(void) postNotification: (NSString*)nm forFile: (NSString*)fp; // Message-posting bottleneck.
-
-@end
-
-
-// -----------------------------------------------------------------------------
-// Methods delegates need to provide:
-// * DEPRECATED * use UKFileWatcher delegate methods instead!
-// -----------------------------------------------------------------------------
-
-@interface NSObject (UKKQueueDelegate)
-
--(void) kqueue: (UKKQueue*)kq receivedNotification: (NSString*)nm forFile: (NSString*)fpath;
-
-@end
View
480 UKQueue/UKKQueue.m
@@ -1,480 +0,0 @@
-/* =============================================================================
- FILE: UKKQueue.m
- PROJECT: Filie
-
- COPYRIGHT: (c) 2003 M. Uli Kusterer, all rights reserved.
-
- AUTHORS: M. Uli Kusterer - UK
-
- LICENSES: MIT License
-
- REVISIONS:
- 2006-03-13 UK Clarified license, streamlined UKFileWatcher stuff,
- Changed notifications to be useful and turned off by
- default some deprecated stuff.
- 2004-12-28 UK Several threading fixes.
- 2003-12-21 UK Created.
- ========================================================================== */
-
-// -----------------------------------------------------------------------------
-// Headers:
-// -----------------------------------------------------------------------------
-
-#import "UKKQueue.h"
-#import "UKMainThreadProxy.h"
-#import <unistd.h>
-#import <fcntl.h>
-
-
-// -----------------------------------------------------------------------------
-// Macros:
-// -----------------------------------------------------------------------------
-
-// @synchronized isn't available prior to 10.3, so we use a typedef so
-// this class is thread-safe on Panther but still compiles on older OSs.
-
-#if MAC_OS_X_VERSION_MAX_ALLOWED >= MAC_OS_X_VERSION_10_3
-#define AT_SYNCHRONIZED(n) @synchronized(n)
-#else
-#define AT_SYNCHRONIZED(n)
-#endif
-
-
-// -----------------------------------------------------------------------------
-// Globals:
-// -----------------------------------------------------------------------------
-
-static UKKQueue * gUKKQueueSharedQueueSingleton = nil;
-
-
-@implementation UKKQueue
-
-// Deprecated:
-#if UKKQUEUE_OLD_SINGLETON_ACCESSOR_NAME
-+(UKKQueue*) sharedQueue
-{
- return [self sharedFileWatcher];
-}
-#endif
-
-// -----------------------------------------------------------------------------
-// sharedQueue:
-// Returns a singleton queue object. In many apps (especially those that
-// subscribe to the notifications) there will only be one kqueue instance,
-// and in that case you can use this.
-//
-// For all other cases, feel free to create additional instances to use
-// independently.
-//
-// REVISIONS:
-// 2006-03-13 UK Renamed from sharedQueue.
-// 2005-07-02 UK Created.
-// -----------------------------------------------------------------------------
-
-+(id) sharedFileWatcher
-{
- AT_SYNCHRONIZED( self )
- {
- if( !gUKKQueueSharedQueueSingleton )
- gUKKQueueSharedQueueSingleton = [[UKKQueue alloc] init]; // This is a singleton, and thus an intentional "leak".
- }
-
- return gUKKQueueSharedQueueSingleton;
-}
-
-
-// -----------------------------------------------------------------------------
-// * CONSTRUCTOR:
-// Creates a new KQueue and starts that thread we use for our
-// notifications.
-//
-// REVISIONS:
-// 2004-11-12 UK Doesn't pass self as parameter to watcherThread anymore,
-// because detachNewThreadSelector retains target and args,
-// which would cause us to never be released.
-// 2004-03-13 UK Documented.
-// -----------------------------------------------------------------------------
-
--(id) init
-{
- self = [super init];
- if( self )
- {
- queueFD = kqueue();
- if( queueFD == -1 )
- {
- [self release];
- return nil;
- }
-
- watchedPaths = [[NSMutableArray alloc] init];
- watchedFDs = [[NSMutableArray alloc] init];
-
- // Start new thread that fetches and processes our events:
- keepThreadRunning = YES;
- [NSThread detachNewThreadSelector:@selector(watcherThread:) toTarget:self withObject:nil];
- }
-
- return self;
-}
-
-
-// -----------------------------------------------------------------------------
-// release:
-// Since NSThread retains its target, we need this method to terminate the
-// thread when we reach a retain-count of two. The thread is terminated by
-// setting keepThreadRunning to NO.
-//
-// REVISIONS:
-// 2004-11-12 UK Created.
-// -----------------------------------------------------------------------------
-
--(oneway void) release
-{
- AT_SYNCHRONIZED(self)
- {
- //NSLog(@"%@ (%d)", self, [self retainCount]);
- if( [self retainCount] == 2 && keepThreadRunning )
- keepThreadRunning = NO;
- }
-
- [super release];
-}
-
-// -----------------------------------------------------------------------------
-// * DESTRUCTOR:
-// Releases the kqueue again.
-//
-// REVISIONS:
-// 2004-03-13 UK Documented.
-// -----------------------------------------------------------------------------
-
--(void) dealloc
-{
- delegate = nil;
- [delegateProxy release];
-
- if( keepThreadRunning )
- keepThreadRunning = NO;
-
- // Close all our file descriptors so the files can be deleted:
- NSEnumerator* enny = [watchedFDs objectEnumerator];
- NSNumber* fdNum;
- while( (fdNum = [enny nextObject]) )
- {
- if( close( [fdNum intValue] ) == -1 )
- NSLog(@"dealloc: Couldn't close file descriptor (%d)", errno);
- }
-
- [watchedPaths release];
- watchedPaths = nil;
- [watchedFDs release];
- watchedFDs = nil;
-
- [super dealloc];
-
- //NSLog(@"kqueue released.");
-}
-
-
-// -----------------------------------------------------------------------------
-// queueFD:
-// Returns a Unix file descriptor for the KQueue this uses. The descriptor
-// is owned by this object. Do not close it!
-//
-// REVISIONS:
-// 2004-03-13 UK Documented.
-// -----------------------------------------------------------------------------
-
--(int) queueFD
-{
- return queueFD;
-}
-
-
-// -----------------------------------------------------------------------------
-// addPathToQueue:
-// Tell this queue to listen for all interesting notifications sent for
-// the object at the specified path. If you want more control, use the
-// addPathToQueue:notifyingAbout: variant instead.
-//
-// REVISIONS:
-// 2004-03-13 UK Documented.
-// -----------------------------------------------------------------------------
-
--(void) addPathToQueue: (NSString*)path
-{
- [self addPath: path];
-}
-
-
--(void) addPath: (NSString*)path
-{
- [self addPathToQueue: path notifyingAbout: UKKQueueNotifyAboutRename
- | UKKQueueNotifyAboutWrite
- | UKKQueueNotifyAboutDelete
- | UKKQueueNotifyAboutAttributeChange];
-}
-
-
-// -----------------------------------------------------------------------------
-// addPathToQueue:notfyingAbout:
-// Tell this queue to listen for the specified notifications sent for
-// the object at the specified path.
-//
-// REVISIONS:
-// 2005-06-29 UK Files are now opened using O_EVTONLY instead of O_RDONLY
-// which allows ejecting or deleting watched files/folders.
-// Thanks to Phil Hargett for finding this flag in the docs.
-// 2004-03-13 UK Documented.
-// -----------------------------------------------------------------------------
-
--(void) addPathToQueue: (NSString*)path notifyingAbout: (u_int)fflags
-{
- struct timespec nullts = { 0, 0 };
- struct kevent ev;
- int fd = open( [path fileSystemRepresentation], O_EVTONLY, 0 );
-
- if( fd >= 0 )
- {
- EV_SET( &ev, fd, EVFILT_VNODE,
- EV_ADD | EV_ENABLE | EV_CLEAR,
- fflags, 0, (void*)path );
-
- AT_SYNCHRONIZED( self )
- {
- [watchedPaths addObject: path];
- [watchedFDs addObject: [NSNumber numberWithInt: fd]];
- kevent( queueFD, &ev, 1, NULL, 0, &nullts );
- }
- }
-}
-
-
--(void) removePath: (NSString*)path
-{
- [self removePathFromQueue: path];
-}
-
-
-// -----------------------------------------------------------------------------
-// removePathFromQueue:
-// Stop listening for changes to the specified path. This removes all
-// notifications. Use this to balance both addPathToQueue:notfyingAbout:
-// as well as addPathToQueue:.
-//
-// REVISIONS:
-// 2004-03-13 UK Documented.
-// -----------------------------------------------------------------------------
-
--(void) removePathFromQueue: (NSString*)path
-{
- int index = 0;
- int fd = -1;
-
- AT_SYNCHRONIZED( self )
- {
- index = [watchedPaths indexOfObject: path];
-
- if( index == NSNotFound )
- return;
-
- fd = [[watchedFDs objectAtIndex: index] intValue];
-
- [watchedFDs removeObjectAtIndex: index];
- [watchedPaths removeObjectAtIndex: index];
- }
-
- if( close( fd ) == -1 )
- NSLog(@"removePathFromQueue: Couldn't close file descriptor (%d)", errno);
-}
-
-
-// -----------------------------------------------------------------------------
-// removeAllPathsFromQueue:
-// Stop listening for changes to all paths. This removes all
-// notifications.
-//
-// REVISIONS:
-// 2004-12-28 UK Added as suggested by bbum.
-// -----------------------------------------------------------------------------
-
--(void) removeAllPathsFromQueue;
-{
- AT_SYNCHRONIZED( self )
- {
- NSEnumerator * fdEnumerator = [watchedFDs objectEnumerator];
- NSNumber * anFD;
-
- while( (anFD = [fdEnumerator nextObject]) != nil )
- close( [anFD intValue] );
-
- [watchedFDs removeAllObjects];
- [watchedPaths removeAllObjects];
- }
-}
-
-
-// -----------------------------------------------------------------------------
-// watcherThread:
-// This method is called by our NSThread to loop and poll for any file
-// changes that our kqueue wants to tell us about. This sends separate
-// notifications for the different kinds of changes that can happen.
-// All messages are sent via the postNotification:forFile: main bottleneck.
-//
-// This also calls sharedWorkspace's noteFileSystemChanged.
-//
-// To terminate this method (and its thread), set keepThreadRunning to NO.
-//
-// REVISIONS:
-// 2005-08-27 UK Changed to use keepThreadRunning instead of kqueueFD
-// being -1 as termination criterion, and to close the
-// queue in this thread so the main thread isn't blocked.
-// 2004-11-12 UK Fixed docs to include termination criterion, added
-// timeout to make sure the bugger gets disposed.
-// 2004-03-13 UK Documented.
-// -----------------------------------------------------------------------------
-
--(void) watcherThread: (id)sender
-{
- int n;
- struct kevent ev;
- struct timespec timeout = { 5, 0 }; // 5 seconds timeout.
- int theFD = queueFD; // So we don't have to risk accessing iVars when the thread is terminated.
-
- while( keepThreadRunning )
- {
- NSAutoreleasePool* pool = [[NSAutoreleasePool alloc] init];
-
- NS_DURING
- n = kevent( queueFD, NULL, 0, &ev, 1, &timeout );
- if( n > 0 )
- {
- if( ev.filter == EVFILT_VNODE )
- {
- if( ev.fflags )
- {
- NSString* fpath = [[(NSString *)ev.udata retain] autorelease]; // In case one of the notified folks removes the path.
- //NSLog(@"UKKQueue: Detected file change: %@", fpath);
- [[NSWorkspace sharedWorkspace] noteFileSystemChanged: fpath];
-
- //NSLog(@"ev.flags = %u",ev.fflags); // DEBUG ONLY!
-
- if( (ev.fflags & NOTE_RENAME) == NOTE_RENAME )
- [self postNotification: UKFileWatcherRenameNotification forFile: fpath];
- if( (ev.fflags & NOTE_WRITE) == NOTE_WRITE )
- [self postNotification: UKFileWatcherWriteNotification forFile: fpath];
- if( (ev.fflags & NOTE_DELETE) == NOTE_DELETE )
- [self postNotification: UKFileWatcherDeleteNotification forFile: fpath];
- if( (ev.fflags & NOTE_ATTRIB) == NOTE_ATTRIB )
- [self postNotification: UKFileWatcherAttributeChangeNotification forFile: fpath];
- if( (ev.fflags & NOTE_EXTEND) == NOTE_EXTEND )
- [self postNotification: UKFileWatcherSizeIncreaseNotification forFile: fpath];
- if( (ev.fflags & NOTE_LINK) == NOTE_LINK )
- [self postNotification: UKFileWatcherLinkCountChangeNotification forFile: fpath];
- if( (ev.fflags & NOTE_REVOKE) == NOTE_REVOKE )
- [self postNotification: UKFileWatcherAccessRevocationNotification forFile: fpath];
- }
- }
- }
- NS_HANDLER
- NSLog(@"Error in UKKQueue watcherThread: %@",localException);
- NS_ENDHANDLER
-
- [pool release];
- }
-
- // Close our kqueue's file descriptor:
- if( close( theFD ) == -1 )
- NSLog(@"release: Couldn't close main kqueue (%d)", errno);
-
- //NSLog(@"exiting kqueue watcher thread.");
-}
-
-
-// -----------------------------------------------------------------------------
-// postNotification:forFile:
-// This is the main bottleneck for posting notifications. If you don't want
-// the notifications to go through NSWorkspace, override this method and
-// send them elsewhere.
-//
-// REVISIONS:
-// 2004-02-27 UK Changed this to send new notification, and the old one
-// only to objects that respond to it. The old category on
-// NSObject could cause problems with the proxy itself.
-// 2004-10-31 UK Helloween fun: Make this use a mainThreadProxy and
-// allow sending the notification even if we have a
-// delegate.
-// 2004-03-13 UK Documented.
-// -----------------------------------------------------------------------------
-
--(void) postNotification: (NSString*)nm forFile: (NSString*)fp
-{
- if( delegateProxy )
- {
- #if UKKQUEUE_BACKWARDS_COMPATIBLE
- if( ![delegateProxy respondsToSelector: @selector(watcher:receivedNotification:forPath:)] )
- [delegateProxy kqueue: self receivedNotification: nm forFile: fp];
- else
- #endif
- [delegateProxy watcher: self receivedNotification: nm forPath: fp];
- }
-
- if( !delegateProxy || alwaysNotify )
- {
- #if UKKQUEUE_SEND_STUPID_NOTIFICATIONS
- [[[NSWorkspace sharedWorkspace] notificationCenter] postNotificationName: nm object: fp];
- #else
- [[[NSWorkspace sharedWorkspace] notificationCenter] postNotificationName: nm object: self
- userInfo: [NSDictionary dictionaryWithObjectsAndKeys: fp, @"path", nil]];
- #endif
- }
-}
-
--(id) delegate
-{
- return delegate;
-}
-
--(void) setDelegate: (id)newDelegate
-{
- id oldProxy = delegateProxy;
- delegate = newDelegate;
- delegateProxy = [delegate copyMainThreadProxy];
- [oldProxy release];
-}
-
-// -----------------------------------------------------------------------------
-// Flag to send a notification even if we have a delegate:
-// -----------------------------------------------------------------------------
-
--(BOOL) alwaysNotify
-{
- return alwaysNotify;
-}
-
-
--(void) setAlwaysNotify: (BOOL)n
-{
- alwaysNotify = n;
-}
-
-
-// -----------------------------------------------------------------------------
-// description:
-// This method can be used to help in debugging. It provides the value
-// used by NSLog & co. when you request to print this object using the
-// %@ format specifier.
-//
-// REVISIONS:
-// 2004-11-12 UK Created.
-// -----------------------------------------------------------------------------
-
--(NSString*) description
-{
- return [NSString stringWithFormat: @"%@ { watchedPaths = %@, alwaysNotify = %@ }", NSStringFromClass([self class]), watchedPaths, (alwaysNotify? @"YES" : @"NO") ];
-}
-
-@end
-
-
View
57 UKQueue/UKMainThreadProxy.h
@@ -1,57 +0,0 @@
-/* =============================================================================
- FILE: UKMainThreadProxy.h
- PROJECT: UKMainThreadProxy
-
- PURPOSE: Send a message to object theObject to [theObject mainThreadProxy]
- instead and the message will be received on the main thread by
- theObject.
-
- COPYRIGHT: (c) 2004 M. Uli Kusterer, all rights reserved.
-
- AUTHORS: M. Uli Kusterer - UK
-
- LICENSES: MIT License
-
- REVISIONS:
- 2006-03-13 UK Clarified license.
- 2004-10-14 UK Created.
- ========================================================================== */
-
-// -----------------------------------------------------------------------------
-// Headers:
-// -----------------------------------------------------------------------------
-
-#import <Cocoa/Cocoa.h>
-
-// -----------------------------------------------------------------------------
-// Categories:
-// -----------------------------------------------------------------------------
-
-@interface NSObject (UKMainThreadProxy)
-
--(id) mainThreadProxy; // You can't init or release this object.
--(id) copyMainThreadProxy; // Gives you a retained version.
-
-@end
-
-// -----------------------------------------------------------------------------
-// Classes:
-// -----------------------------------------------------------------------------
-
-/*
- This object is created as a proxy in a second thread for an existing object.
- All messages you send to this object will automatically be sent to the other
- object on the main thread, except NSObject methods like retain/release etc.
-*/
-
-@interface UKMainThreadProxy : NSObject
-{
- IBOutlet id target;
- BOOL waitForCompletion;
-}
-
--(id) initWithTarget: (id)targ;
-
--(void) setWaitForCompletion: (BOOL)state;
-
-@end
View
152 UKQueue/UKMainThreadProxy.m
@@ -1,152 +0,0 @@
-/* =============================================================================
- FILE: UKMainThreadProxy.h
- PROJECT: UKMainThreadProxy
-
- PURPOSE: Send a message to object theObject to [theObject mainThreadProxy]
- instead and the message will be received on the main thread by
- theObject.
-
- COPYRIGHT: (c) 2004 M. Uli Kusterer, all rights reserved.
-
- AUTHORS: M. Uli Kusterer - UK
-
- LICENSES: MIT License
-
- REVISIONS:
- 2006-03-13 UK Clarified license.
- 2004-10-14 UK Created.
- ========================================================================== */
-
-// -----------------------------------------------------------------------------
-// Headers:
-// -----------------------------------------------------------------------------
-
-#import "UKMainThreadProxy.h"
-
-@implementation UKMainThreadProxy
-
--(id) initWithTarget: (id)targ
-{
- self = [super init];
- if( self )
- {
- target = targ;
- waitForCompletion = YES;
- }
-
- return self;
-}
-
--(void) setWaitForCompletion: (BOOL)state
-{
- waitForCompletion = state;
-}
-
-// -----------------------------------------------------------------------------
-// Introspection overrides:
-// -----------------------------------------------------------------------------
-
--(BOOL) respondsToSelector: (SEL)itemAction
-{
- BOOL does = [super respondsToSelector: itemAction];
-
- return( does || [target respondsToSelector: itemAction] );
-}
-
--(id) performSelector: (SEL)itemAction
-{
- BOOL does = [super respondsToSelector: itemAction];
- if( does )
- return [super performSelector: itemAction];
-
- if( ![target respondsToSelector: itemAction] )
- [self doesNotRecognizeSelector: itemAction];
-
- [target retain];
- [target performSelectorOnMainThread: itemAction withObject: nil waitUntilDone: waitForCompletion];
- [target release];
-
- return nil;
-}
-
--(id) performSelector: (SEL)itemAction withObject: (id)obj
-{
- BOOL does = [super respondsToSelector: itemAction];
- if( does )
- return [super performSelector: itemAction withObject: obj];
-
- if( ![target respondsToSelector: itemAction] )
- [self doesNotRecognizeSelector: itemAction];
-
- [target retain];
- [obj retain];
- [target performSelectorOnMainThread: itemAction withObject: obj waitUntilDone: waitForCompletion];
- [obj release];
- [target release];
-
- return nil;
-}
-
-// -----------------------------------------------------------------------------
-// Forwarding unknown methods to the target:
-// -----------------------------------------------------------------------------
-
--(NSMethodSignature*) methodSignatureForSelector: (SEL)itemAction
-{
- NSMethodSignature* sig = [super methodSignatureForSelector: itemAction];
-
- if( sig )
- return sig;
-
- return [target methodSignatureForSelector: itemAction];
-}
-
--(void) forwardInvocation: (NSInvocation*)invocation
-{
- SEL itemAction = [invocation selector];
-
- if( [target respondsToSelector: itemAction] )
- {
- [invocation retainArguments];
- [target retain];
- [invocation performSelectorOnMainThread: @selector(invokeWithTarget:) withObject: target waitUntilDone: waitForCompletion];
- [target release];
- }
- else
- [self doesNotRecognizeSelector: itemAction];
-}
-
-// -----------------------------------------------------------------------------
-// Safety net:
-// -----------------------------------------------------------------------------
-
--(id) mainThreadProxy // Just in case someone accidentally sends this message to a main thread proxy.
-{
- return self;
-}
-
--(id) copyMainThreadProxy // Just in case someone accidentally sends this message to a main thread proxy.
-{
- return [self retain];
-}
-
-@end
-
-// -----------------------------------------------------------------------------
-// Shorthand notation for getting a main thread proxy:
-// -----------------------------------------------------------------------------
-
-@implementation NSObject (UKMainThreadProxy)
-
--(id) mainThreadProxy
-{
- return [[[UKMainThreadProxy alloc] initWithTarget: self] autorelease];
-}
-
--(id) copyMainThreadProxy
-{
- return [[UKMainThreadProxy alloc] initWithTarget: self];
-}
-
-@end
-

0 comments on commit b7dd189

Please sign in to comment.
Something went wrong with that request. Please try again.