func startScanner(dir string) { lock.Lock() chans[dir] = make(chan string) lock.Unlock() cpaths := C.fswatch_make_mutable_array() defer C.free(unsafe.Pointer(cpaths)) path := C.CString(dir) str := C.CFStringCreateWithCString(nil, path, C.kCFStringEncodingUTF8) defer C.free(unsafe.Pointer(path)) defer C.free(unsafe.Pointer(str)) C.CFArrayAppendValue(cpaths, unsafe.Pointer(str)) ctx := C.FSEventStreamContext{info: unsafe.Pointer(C.CString(dir))} stream := C.fswatch_create(&ctx, cpaths, now, C.CFTimeInterval(interval/time.Second), cflags) go func() { C.FSEventStreamScheduleWithRunLoop(stream, C.CFRunLoopGetCurrent(), C.kCFRunLoopCommonModes) C.FSEventStreamStart(stream) C.CFRunLoopRun() }() }
func New(dev Device, since EventID, interval time.Duration, flags CreateFlags, paths ...string) *Stream { cpaths := C.fswatch_make_mutable_array() defer C.free(unsafe.Pointer(cpaths)) for _, dir := range paths { path := C.CString(dir) defer C.free(unsafe.Pointer(path)) str := C.CFStringCreateWithCString(nil, path, C.kCFStringEncodingUTF8) defer C.free(unsafe.Pointer(str)) C.CFArrayAppendValue(cpaths, unsafe.Pointer(str)) } csince := C.FSEventStreamEventId(since) cinterval := C.CFTimeInterval(interval / time.Second) cflags := C.FSEventStreamCreateFlags(flags &^ CF_USECFTYPES) s := new(Stream) s.Chan = make(chan []Event) ctx := C.FSEventStreamContext{info: unsafe.Pointer(&s.Chan)} var cstream C.FSEventStreamRef if dev == 0 { cstream = C.fswatch_create(&ctx, cpaths, csince, cinterval, cflags) } else { cdev := C.dev_t(dev) cstream = C.fswatch_create_relative_to_device( cdev, &ctx, cpaths, csince, cinterval, cflags) } s.cstream = cstream return s }