23 #include "precompiled.h"
33 #include <CoreFoundation/CoreFoundation.h>
34 #include <CoreServices/CoreServices.h>
60 if ((major == 10 && minor >= 7) || major >= 11)
66 #if MAC_OS_X_VERSION_MIN_REQUIRED >= 1070
68 #define kFSEventStreamCreateFlagFileEvents 0x00000010
69 #define kFSEventStreamEventFlagItemIsFile 0x00010000
70 #define kFSEventStreamEventFlagItemRemoved 0x00000200
71 #define kFSEventStreamEventFlagItemRenamed 0x00000800
72 #define kFSEventStreamEventFlagItemCreated 0x00000100
73 #define kFSEventStreamEventFlagItemModified 0x00001000
77 ConstFSEventStreamRef
UNUSED(streamRef),
78 void *
UNUSED(clientCallBackInfo),
81 const FSEventStreamEventFlags eventFlags[],
82 const FSEventStreamEventId
UNUSED(eventIds)[] )
85 char **paths = (
char **)eventPaths;
87 for (i=0; i<numEvents; i++)
89 bool isWatched =
false;
91 unsigned long eventType = eventFlags[i];
95 for ( DirWatchMap::iterator it =
g_Paths.begin() ; it !=
g_Paths.end(); ++it)
124 CFStringRef* pathLists = (CFStringRef*)malloc(
sizeof(CFStringRef*) * path.size() );
126 for ( DirWatchMap::iterator it = path.begin() ; it != path.end(); ++it)
128 pathLists[index] = CFStringCreateWithFileSystemRepresentation( NULL,
OsString(it->path).c_str());
131 CFArrayRef pathsToWatch = CFArrayCreate(NULL, (
const void **)pathLists, index, NULL);
133 FSEventStreamContext *callbackInfo = NULL;
135 FSEventStreamRef stream = FSEventStreamCreate(NULL, &
fsevent_callback, callbackInfo, pathsToWatch,
138 CFRelease( pathsToWatch );
141 FSEventStreamScheduleWithRunLoop(stream, CFRunLoopGetCurrent(), kCFRunLoopDefaultMode);
142 if (!FSEventStreamStart(stream))
143 debug_warn(L
"event_loop FSEventStreamStart failed!");
166 dirWatch.swap(tmpDirWatch);
167 dirWatch->path = path;
168 dirWatch->reqnum = 0;
169 g_Paths.push_back( *dirWatch );
171 bool alreadyInsideRootPath =
false;
175 alreadyInsideRootPath =
true;
178 if ( !alreadyInsideRootPath )
static DirWatchMap g_Paths
std::vector< DirWatchNotification > DirWatchNotifications
void GetSystemVersion(int &major, int &minor, int &bugfix)
#define UNUSED(param)
mark a function parameter as unused and avoid the corresponding compiler warning. ...
#define kFSEventStreamEventFlagItemRenamed
#define kFSEventStreamEventFlagItemModified
bool CanRunNotifications()
std::map< int, PDirWatch > DirWatchMap
LIB_API Status dir_watch_Add(const OsPath &path, PDirWatch &dirWatch)
start watching a single directory for changes.
FSEventStreamRef CreateEventStream(DirWatchMap path)
#define kFSEventStreamCreateFlagFileEvents
static DirWatchNotifications g_QueuedDirs
#define kFSEventStreamEventFlagItemIsFile
shared_ptr< DirWatch > PDirWatch
static DirWatchMap g_RootPaths
#define kFSEventStreamEventFlagItemRemoved
const String & string() const
LIB_API Status dir_watch_Poll(DirWatchNotifications ¬ifications)
return all pending directory watch notifications.
i64 Status
Error handling system.
bool path_is_subpath(const wchar_t *s1, const wchar_t *s2)
is s2 a subpath of s1, or vice versa? (equal counts as subpath)
FSEventStreamRef g_Stream
static void fsevent_callback(ConstFSEventStreamRef streamRef, void *clientCallBackInfo, size_t numEvents, void *eventPaths, const FSEventStreamEventFlags eventFlags[], const FSEventStreamEventId eventIds[])
#define debug_warn(expr)
display the error dialog with the given text.
#define kFSEventStreamEventFlagItemCreated
static std::string OsString(const OsPath &path)