Created
July 19, 2013 06:28
-
-
Save yangacer/6037073 to your computer and use it in GitHub Desktop.
Minimum example of FSEvent (no thread creation)
This file contains 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