Skip to content

Instantly share code, notes, and snippets.

@ga2arch
Forked from yangacer/fsevent.cpp
Last active August 29, 2015 14:07
Show Gist options
  • Save ga2arch/23f63d5200b1a9a0c167 to your computer and use it in GitHub Desktop.
Save ga2arch/23f63d5200b1a9a0c167 to your computer and use it in GitHub Desktop.
#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