• R/O
  • HTTP
  • SSH
  • HTTPS

Commit

Tags
No Tags

Frequently used words (click to add to your profile)

javac++androidlinuxc#windowsobjective-ccocoa誰得qtpythonphprubygameguibathyscaphec計画中(planning stage)翻訳omegatframeworktwitterdomtestvb.netdirectxゲームエンジンbtronarduinopreviewer

An Objective-C wrapper for Mac OS X’s FSEvents C API.


Commit MetaInfo

Revisión4250cf9c51cbe44442907b7ceb5e81fc33bb2554 (tree)
Tiempo2011-08-31 03:07:00
AutorAron Cedercrantz <aron@cede...>
CommiterAron Cedercrantz

Log Message

Merge branch 'develop' into feature/arc

Conflicts:
CDEvents.xcodeproj/project.pbxproj

Cambiar Resumen

Diferencia incremental

--- a/CDEvent.h
+++ b/CDEvent.h
@@ -38,7 +38,6 @@
3838 #import <Foundation/Foundation.h>
3939 #import <CoreServices/CoreServices.h>
4040
41-
4241 #pragma mark -
4342 #pragma mark CDEvent types
4443 /**
@@ -116,6 +115,14 @@ typedef FSEventStreamEventFlags CDEventFlags;
116115 */
117116 @property (readonly) CDEventFlags flags;
118117
118+#pragma mark flag macros
119+
120+#define FLAG_CHECK(flags, flag) ((flags) & (flag))
121+
122+#define FLAG_PROPERTY(name, flag) \
123+- (BOOL)name \
124+{ return (FLAG_CHECK(_flags, flag) ? YES : NO); }
125+
119126 #pragma mark Specific flag properties
120127 /**
121128 * Wheter there was some change in the directory at the specific path supplied in this event.
@@ -348,6 +355,24 @@ typedef FSEventStreamEventFlags CDEventFlags;
348355 @property (readonly) BOOL didVolumeUnmount;
349356
350357
358+/**
359+ * The entirety of the documentation on file level events in lion is 3 sentences
360+ * long. Rename behavior is odd, making the combination of events and flags
361+ * somewhat confusing for atomic writes. It also appears possible to get a
362+ * singular event where a file has been created, modified, and removed.
363+ */
364+@property (readonly) BOOL isCreated;
365+@property (readonly) BOOL isRemoved;
366+@property (readonly) BOOL isInodeMetadataModified;
367+@property (readonly) BOOL isRenamed;
368+@property (readonly) BOOL isModified;
369+@property (readonly) BOOL isFinderInfoModified;
370+@property (readonly) BOOL didChangeOwner;
371+@property (readonly) BOOL isXattrModified;
372+@property (readonly) BOOL isFile;
373+@property (readonly) BOOL isDir;
374+@property (readonly) BOOL isSymlink;
375+
351376 #pragma mark Class object creators
352377 /** @name Creating CDEvent Objects */
353378 /**
--- a/CDEvent.m
+++ b/CDEvent.m
@@ -27,7 +27,7 @@
2727 */
2828
2929 #import "CDEvent.h"
30-
30+#import "compat.h"
3131
3232 @implementation CDEvent
3333
@@ -96,52 +96,33 @@
9696 return self;
9797 }
9898
99-
10099 #pragma mark Specific flag properties
101100 - (BOOL)isGenericChange
102101 {
103102 return (kFSEventStreamEventFlagNone == _flags);
104103 }
105104
106-- (BOOL)mustRescanSubDirectories
107-{
108- return (_flags & kFSEventStreamEventFlagMustScanSubDirs);
109-}
110-
111-- (BOOL)isUserDropped
112-{
113- return (_flags & kFSEventStreamEventFlagUserDropped);
114-}
115-
116-- (BOOL)isKernelDropped
117-{
118- return (_flags & kFSEventStreamEventFlagKernelDropped);
119-}
120-
121-- (BOOL)isEventIdentifiersWrapped
122-{
123- return (_flags & kFSEventStreamEventFlagEventIdsWrapped);
124-}
125-
126-- (BOOL)isHistoryDone
127-{
128- return (_flags & kFSEventStreamEventFlagHistoryDone);
129-}
130-
131-- (BOOL)isRootChanged
132-{
133- return (_flags & kFSEventStreamEventFlagRootChanged);
134-}
135-
136-- (BOOL)didVolumeMount
137-{
138- return (_flags & kFSEventStreamEventFlagMount);
139-}
140-
141-- (BOOL)didVolumeUnmount
142-{
143- return (_flags & kFSEventStreamEventFlagUnmount);
144-}
105+FLAG_PROPERTY(mustRescanSubDirectories, kFSEventStreamEventFlagMustScanSubDirs)
106+FLAG_PROPERTY(isUserDropped, kFSEventStreamEventFlagUserDropped)
107+FLAG_PROPERTY(isKernelDropped, kFSEventStreamEventFlagKernelDropped)
108+FLAG_PROPERTY(isEventIdentifiersWrapped, kFSEventStreamEventFlagEventIdsWrapped)
109+FLAG_PROPERTY(isHistoryDone, kFSEventStreamEventFlagHistoryDone)
110+FLAG_PROPERTY(isRootChanged, kFSEventStreamEventFlagRootChanged)
111+FLAG_PROPERTY(didVolumeMount, kFSEventStreamEventFlagMount)
112+FLAG_PROPERTY(didVolumeUnmount, kFSEventStreamEventFlagUnmount)
113+
114+// file-level events introduced in 10.7
115+FLAG_PROPERTY(isCreated, kFSEventStreamEventFlagItemCreated)
116+FLAG_PROPERTY(isRemoved, kFSEventStreamEventFlagItemRemoved)
117+FLAG_PROPERTY(isInodeMetadataModified, kFSEventStreamEventFlagItemInodeMetaMod)
118+FLAG_PROPERTY(isRenamed, kFSEventStreamEventFlagItemRenamed)
119+FLAG_PROPERTY(isModified, kFSEventStreamEventFlagItemModified)
120+FLAG_PROPERTY(isFinderInfoModified, kFSEventStreamEventFlagItemFinderInfoMod)
121+FLAG_PROPERTY(didChangeOwner, kFSEventStreamEventFlagItemChangeOwner)
122+FLAG_PROPERTY(isXattrModified, kFSEventStreamEventFlagItemXattrMod)
123+FLAG_PROPERTY(isFile, kFSEventStreamEventFlagItemIsFile)
124+FLAG_PROPERTY(isDir, kFSEventStreamEventFlagItemIsDir)
125+FLAG_PROPERTY(isSymlink, kFSEventStreamEventFlagItemIsSymlink)
145126
146127 #pragma mark Misc
147128 - (NSString *)description
--- a/CDEvents.xcodeproj/project.pbxproj
+++ b/CDEvents.xcodeproj/project.pbxproj
@@ -3,10 +3,11 @@
33 archiveVersion = 1;
44 classes = {
55 };
6- objectVersion = 45;
6+ objectVersion = 46;
77 objects = {
88
99 /* Begin PBXBuildFile section */
10+ 6A05775A1400F49900BF73C4 /* compat.h in Headers */ = {isa = PBXBuildFile; fileRef = 6A0577591400F49900BF73C4 /* compat.h */; };
1011 8DC2EF530486A6940098B216 /* InfoPlist.strings in Resources */ = {isa = PBXBuildFile; fileRef = 089C1666FE841158C02AAC07 /* InfoPlist.strings */; };
1112 9C6D03031166AFFA00343E46 /* CDEvent.h in Headers */ = {isa = PBXBuildFile; fileRef = 9C6D03011166AFFA00343E46 /* CDEvent.h */; settings = {ATTRIBUTES = (Public, ); }; };
1213 9C6D03041166AFFA00343E46 /* CDEvent.m in Sources */ = {isa = PBXBuildFile; fileRef = 9C6D03021166AFFA00343E46 /* CDEvent.m */; };
@@ -50,6 +51,7 @@
5051 089C1667FE841158C02AAC07 /* English */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = text.plist.strings; name = English; path = English.lproj/InfoPlist.strings; sourceTree = "<group>"; };
5152 1058C7B1FEA5585E11CA2CBB /* Cocoa.framework */ = {isa = PBXFileReference; lastKnownFileType = wrapper.framework; name = Cocoa.framework; path = /System/Library/Frameworks/Cocoa.framework; sourceTree = "<absolute>"; };
5253 32DBCF5E0370ADEE00C91783 /* CDEvents_Prefix.pch */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = CDEvents_Prefix.pch; sourceTree = "<group>"; };
54+ 6A0577591400F49900BF73C4 /* compat.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = compat.h; sourceTree = "<group>"; };
5355 8DC2EF5A0486A6940098B216 /* Info.plist */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = text.plist.xml; path = Info.plist; sourceTree = "<group>"; };
5456 8DC2EF5B0486A6940098B216 /* CDEvents.framework */ = {isa = PBXFileReference; explicitFileType = wrapper.framework; includeInIndex = 0; path = CDEvents.framework; sourceTree = BUILT_PRODUCTS_DIR; };
5557 9C6D03011166AFFA00343E46 /* CDEvent.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = CDEvent.h; sourceTree = "<group>"; };
@@ -163,6 +165,7 @@
163165 32C88DFF0371C24200C91783 /* Other Sources */ = {
164166 isa = PBXGroup;
165167 children = (
168+ 6A0577591400F49900BF73C4 /* compat.h */,
166169 32DBCF5E0370ADEE00C91783 /* CDEvents_Prefix.pch */,
167170 );
168171 name = "Other Sources";
@@ -188,6 +191,7 @@
188191 9C6D03031166AFFA00343E46 /* CDEvent.h in Headers */,
189192 9C6D051D1166BD5800343E46 /* CDEventsDelegate.h in Headers */,
190193 9C6D05241166BF5300343E46 /* CDEvents.h in Headers */,
194+ 6A05775A1400F49900BF73C4 /* compat.h in Headers */,
191195 );
192196 runOnlyForDeploymentPostprocessing = 0;
193197 };
@@ -237,8 +241,11 @@
237241 /* Begin PBXProject section */
238242 0867D690FE84028FC02AAC07 /* Project object */ = {
239243 isa = PBXProject;
244+ attributes = {
245+ LastUpgradeCheck = 0420;
246+ };
240247 buildConfigurationList = 1DEB91B108733DA50010E9CD /* Build configuration list for PBXProject "CDEvents" */;
241- compatibilityVersion = "Xcode 3.1";
248+ compatibilityVersion = "Xcode 3.2";
242249 developmentRegion = English;
243250 hasScannedForEncodings = 1;
244251 knownRegions = (
@@ -373,7 +380,6 @@
373380 GCC_WARN_UNUSED_VARIABLE = YES;
374381 MACOSX_DEPLOYMENT_TARGET = 10.7;
375382 ONLY_ACTIVE_ARCH = YES;
376- PREBINDING = NO;
377383 RUN_CLANG_STATIC_ANALYZER = YES;
378384 SDKROOT = macosx;
379385 };
@@ -400,7 +406,6 @@
400406 ALWAYS_SEARCH_USER_PATHS = NO;
401407 COPY_PHASE_STRIP = NO;
402408 GCC_DYNAMIC_NO_PIC = NO;
403- GCC_ENABLE_FIX_AND_CONTINUE = YES;
404409 GCC_ENABLE_OBJC_GC = unsupported;
405410 GCC_MODEL_TUNING = G5;
406411 GCC_OPTIMIZATION_LEVEL = 0;
@@ -416,7 +421,6 @@
416421 "-framework",
417422 AppKit,
418423 );
419- PREBINDING = NO;
420424 PRODUCT_NAME = CDEventsTestApp;
421425 };
422426 name = Debug;
@@ -427,7 +431,6 @@
427431 ALWAYS_SEARCH_USER_PATHS = NO;
428432 COPY_PHASE_STRIP = YES;
429433 DEBUG_INFORMATION_FORMAT = "dwarf-with-dsym";
430- GCC_ENABLE_FIX_AND_CONTINUE = NO;
431434 GCC_ENABLE_OBJC_GC = unsupported;
432435 GCC_MODEL_TUNING = G5;
433436 GCC_PRECOMPILE_PREFIX_HEADER = YES;
@@ -442,7 +445,6 @@
442445 "-framework",
443446 AppKit,
444447 );
445- PREBINDING = NO;
446448 PRODUCT_NAME = CDEventsTestApp;
447449 ZERO_LINK = NO;
448450 };
--- a/TestApp/CDEventsTestAppController.m
+++ b/TestApp/CDEventsTestAppController.m
@@ -31,6 +31,23 @@
3131 #import <CDEvents/CDEvents.h>
3232
3333
34+bool systemVersionIsAtLeast(SInt32 major, SInt32 minor)
35+{
36+ static SInt32 versionMajor = 0, versionMinor = 0;
37+
38+ if (versionMajor == 0) {
39+ Gestalt(gestaltSystemVersionMajor, &versionMajor);
40+ }
41+
42+ if (versionMinor == 0) {
43+ Gestalt(gestaltSystemVersionMinor, &versionMinor);
44+ }
45+
46+ return ((versionMajor > major) ||
47+ ((versionMajor == major) && (versionMinor >= minor)));
48+}
49+
50+
3451 @implementation CDEventsTestAppController
3552
3653 - (void)run
@@ -42,6 +59,16 @@
4259 [NSURL URLWithString:[[NSHomeDirectory() stringByAppendingPathComponent:@"Downloads"]
4360 stringByAddingPercentEscapesUsingEncoding:NSUTF8StringEncoding]]];
4461
62+ CDEventsEventStreamCreationFlags creationFlags = kCDEventsDefaultEventStreamFlags;
63+
64+ if (systemVersionIsAtLeast(10,6)) {
65+ creationFlags |= kFSEventStreamCreateFlagIgnoreSelf;
66+ }
67+
68+ if (systemVersionIsAtLeast(10,7)) {
69+ creationFlags |= kFSEventStreamCreateFlagFileEvents;
70+ }
71+
4572 _events = [[CDEvents alloc] initWithURLs:watchedURLs
4673 delegate:self
4774 onRunLoop:[NSRunLoop currentRunLoop]
@@ -49,7 +76,7 @@
4976 notificationLantency:CD_EVENTS_DEFAULT_NOTIFICATION_LATENCY
5077 ignoreEventsFromSubDirs:CD_EVENTS_DEFAULT_IGNORE_EVENT_FROM_SUB_DIRS
5178 excludeURLs:excludeURLs
52- streamCreationFlags:kCDEventsDefaultEventStreamFlags];
79+ streamCreationFlags:creationFlags];
5380 //[_events setIgnoreEventsFromSubDirectories:YES];
5481
5582 NSLog(@"-[CDEventsTestAppController run]:\n%@\n------\n%@",
--- /dev/null
+++ b/compat.h
@@ -0,0 +1,32 @@
1+/**
2+ * @headerfile compat.h
3+ * FSEventStream flag compatibility shim
4+ *
5+ * In order to compile a binary against an older SDK yet still support the
6+ * features present in later OS releases, we need to define any missing enum
7+ * constants not present in the older SDK. This allows us to safely defer
8+ * feature detection to runtime (and avoid recompilation).
9+ */
10+
11+#import <CoreServices/CoreServices.h>
12+
13+#if MAC_OS_X_VERSION_MAX_ALLOWED < 1060
14+// ignoring events originating from the current process introduced in 10.6
15+FSEventStreamCreateFlags kFSEventStreamCreateFlagIgnoreSelf = 0x00000008;
16+#endif
17+
18+#if MAC_OS_X_VERSION_MAX_ALLOWED < 1070
19+// file-level events introduced in 10.7
20+FSEventStreamCreateFlags kFSEventStreamCreateFlagFileEvents = 0x00000010;
21+FSEventStreamEventFlags kFSEventStreamEventFlagItemCreated = 0x00000100,
22+ kFSEventStreamEventFlagItemRemoved = 0x00000200,
23+ kFSEventStreamEventFlagItemInodeMetaMod = 0x00000400,
24+ kFSEventStreamEventFlagItemRenamed = 0x00000800,
25+ kFSEventStreamEventFlagItemModified = 0x00001000,
26+ kFSEventStreamEventFlagItemFinderInfoMod = 0x00002000,
27+ kFSEventStreamEventFlagItemChangeOwner = 0x00004000,
28+ kFSEventStreamEventFlagItemXattrMod = 0x00008000,
29+ kFSEventStreamEventFlagItemIsFile = 0x00010000,
30+ kFSEventStreamEventFlagItemIsDir = 0x00020000,
31+ kFSEventStreamEventFlagItemIsSymlink = 0x00040000;
32+#endif