Last active
March 19, 2024 12:51
-
-
Save emarashliev/8786692 to your computer and use it in GitHub Desktop.
FileSystem Observing
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
#import <Foundation/Foundation.h> | |
#include <CoreServices/CoreServices.h> | |
void callbackFunction( ConstFSEventStreamRef streamRef, | |
void *clientCallBackInfo, | |
size_t numEvents, | |
void *eventPaths, | |
const FSEventStreamEventFlags eventFlags[], | |
const FSEventStreamEventId eventIds[] ) | |
{ | |
int i; | |
char **paths = eventPaths; | |
for (i=0; i<numEvents; i++) { | |
/* flags are unsigned long, IDs are uint64_t */ | |
printf("Change %llu in %s, flags %u\n", eventIds[i], paths[i], (unsigned int)eventFlags[i]); | |
} | |
} | |
int main(int argc, const char * argv[]) | |
{ | |
@autoreleasepool { | |
/* Define variables and create a CFArray object containing | |
CFString objects containing paths to watch. | |
*/ | |
CFStringRef mypaths[] = { CFSTR("/Users/marashliev/Desktop/test/") }; | |
CFArrayRef pathsToWatch = CFArrayCreate( NULL, (const void **)mypaths, sizeof(mypaths) / sizeof(CFStringRef), NULL ); | |
//NSArray *pathsToWatch = [NSArray arrayWithObject:@"/Users/marashliev/Desktop/test"]; | |
void *callbackInfo = NULL; // could put stream-specific data here. | |
FSEventStreamRef stream; | |
CFAbsoluteTime latency = 3.0; /* Latency in seconds */ | |
/* Create the stream, passing in a callback */ | |
stream = FSEventStreamCreate(NULL, | |
&callbackFunction, | |
callbackInfo, | |
pathsToWatch, | |
kFSEventStreamEventIdSinceNow, /* Or a previous event ID */ | |
latency, | |
kFSEventStreamCreateFlagNone /* Flags explained in reference */ ); | |
FSEventStreamScheduleWithRunLoop(stream, CFRunLoopGetCurrent(), kCFRunLoopDefaultMode); | |
FSEventStreamStart(stream); | |
CFRunLoopRun(); | |
} | |
return 0; | |
} | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment