-
-
Save alfonsotesauro/3662da78b230a8effbea6e2aa6b659b7 to your computer and use it in GitHub Desktop.
Minimum example of FSEvent (no thread creation)
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#include <CoreServices/CoreServices.h> | |
#include <iostream> | |
void callback( | |
ConstFSEventStreamRef stream, | |
void *callbackInfo, | |
size_t numEvents, | |
void *evPaths, | |
const FSEventStreamEventFlags evFlags[], | |
const FSEventStreamEventId evIds[]) | |
{ | |
char const **paths = (char const**)evPaths; | |
for(int i = 0; i < numEvents; ++i) { | |
std::cout << (unsigned long long)evIds[i] << "\t" << | |
evFlags[i] << "\t" << | |
paths[i] << "\n" | |
; | |
} | |
} | |
int main(int argc, char **argv) | |
{ | |
CFStringRef arg = CFStringCreateWithCString( | |
kCFAllocatorDefault, | |
argv[1], | |
kCFStringEncodingUTF8); | |
CFArrayRef paths = CFArrayCreate(NULL, (const void**)&arg, 1, NULL); | |
void *callbackInfo = NULL; | |
FSEventStreamRef stream; | |
CFAbsoluteTime latency = 3.0; | |
stream = FSEventStreamCreate( | |
NULL, | |
&callback, | |
NULL, | |
paths, | |
kFSEventStreamEventIdSinceNow, | |
latency, | |
kFSEventStreamCreateFlagNone); | |
FSEventStreamScheduleWithRunLoop(stream, CFRunLoopGetCurrent(), kCFRunLoopDefaultMode); | |
FSEventStreamStart(stream); | |
std::cout << "eventID\tFlag\tPath\n"; | |
CFRunLoopRun(); | |
FSEventStreamInvalidate(stream); | |
FSEventStreamRelease(stream); | |
return 0; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment