23 #import <Foundation/Foundation.h>
32 context.retain = NULL;
33 context.release = NULL;
34 context.copyDescription = NULL;
35 setObjectiveCObject([NSMutableArray arrayWithCapacity:10]);
44 static void FSEvents_Callback(
45 ConstFSEventStreamRef streamRef,
46 void *clientCallBackInfo,
49 const FSEventStreamEventFlags eventFlags[],
50 const FSEventStreamEventId eventIds[])
53 char** paths = (
char**)eventPaths;
55 for (
unsigned int i = 0; i < numEvents; i++)
57 NSString* dir = [NSString stringWithUTF8String:paths[i]];
58 NSArray* filesInDir = [[NSFileManager defaultManager] contentsOfDirectoryAtPath:dir error:NULL];
59 for (NSString* str in filesInDir)
61 NSString* fullPath = [dir stringByAppendingPathComponent:str];
62 NSDictionary* attribs = [[NSFileManager defaultManager] attributesOfItemAtPath:fullPath error:NULL];
63 NSDate* modified = [attribs fileModificationDate];
64 if (modified && -[modified timeIntervalSinceNow] <= 3.0)
70 void C4FileMonitor::StartStream()
72 eventStream = FSEventStreamCreate(kCFAllocatorDefault, &FSEvents_Callback, &context, (__bridge CFArrayRef)objectiveCObject<NSMutableArray>(), kFSEventStreamEventIdSinceNow, 0.3,
73 kFSEventStreamCreateFlagNone);
74 FSEventStreamScheduleWithRunLoop(eventStream, CFRunLoopGetCurrent(), kCFRunLoopDefaultMode);
75 FSEventStreamStart(eventStream);
78 void C4FileMonitor::StopStream()
83 FSEventStreamStop(eventStream);
84 FSEventStreamInvalidate(eventStream);
85 FSEventStreamRelease(eventStream);
97 NSString* path = [NSString stringWithUTF8String:szDir];
98 NSString* fullPath = [path characterAtIndex:0] ==
'/'
100 : [NSString stringWithFormat:
@"%@/%@", [[NSFileManager defaultManager] currentDirectoryPath], path];
101 [objectiveCObject<NSMutableArray>() addObject:fullPath];
107 pCallback((
const char *)pEventData, 0);
void GetFDs(std::vector< struct pollfd > &FDs) override
void OnThreadEvent(C4InteractiveEventType eEvent, void *pEventData) override
bool Execute(int iTimeout=-1, pollfd *=nullptr) override
~C4FileMonitor() override
void AddDirectory(const char *szDir)
C4FileMonitor(ChangeNotify pCallback)