···11-/*
22- This file is part of Darling.
33-44- Copyright (C) 2019 Lubos Dolezel
55-66- Darling is free software: you can redistribute it and/or modify
77- it under the terms of the GNU General Public License as published by
88- the Free Software Foundation, either version 3 of the License, or
99- (at your option) any later version.
1010-1111- Darling is distributed in the hope that it will be useful,
1212- but WITHOUT ANY WARRANTY; without even the implied warranty of
1313- MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
1414- GNU General Public License for more details.
1515-1616- You should have received a copy of the GNU General Public License
1717- along with Darling. If not, see <http://www.gnu.org/licenses/>.
1818-*/
1919-2020-#include <FSEvents/FSEvents.h>
2121-#include <stdio.h>
2222-#include <stdlib.h>
2323-2424-struct __FSEventStream {
2525- CFAllocatorRef allocator;
2626- CFArrayRef pathsToWatch;
2727-};
2828-2929-FSEventStreamRef FSEventStreamCreate(
3030- CFAllocatorRef allocator,
3131- FSEventStreamCallback callback,
3232- FSEventStreamContext *context,
3333- CFArrayRef pathsToWatch,
3434- FSEventStreamEventId sinceWhen,
3535- CFTimeInterval latency,
3636- FSEventStreamCreateFlags flags)
3737-{
3838- FSEventStreamRef stream = NULL;
3939- printf("STUB %s\n", __PRETTY_FUNCTION__);
4040- stream = CFAllocatorAllocate(allocator, sizeof(struct __FSEventStream), 0);
4141- stream->allocator = allocator;
4242- stream->pathsToWatch = CFArrayCreateCopy(allocator, pathsToWatch);
4343- return stream;
4444-}
4545-4646-CFArrayRef FSEventStreamCopyPathsBeingWatched(ConstFSEventStreamRef streamRef)
4747-{
4848- CFArrayRef copy;
4949- printf("STUB %s\n", __PRETTY_FUNCTION__);
5050- copy = CFArrayCreateCopy(streamRef->allocator, streamRef->pathsToWatch);
5151- copy = CFRetain(copy);
5252- return copy;
5353-}
···11+/*
22+ This file is part of Darling.
33+44+ Copyright (C) 2019-2020 Lubos Dolezel
55+66+ Darling is free software: you can redistribute it and/or modify
77+ it under the terms of the GNU General Public License as published by
88+ the Free Software Foundation, either version 3 of the License, or
99+ (at your option) any later version.
1010+1111+ Darling is distributed in the hope that it will be useful,
1212+ but WITHOUT ANY WARRANTY; without even the implied warranty of
1313+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
1414+ GNU General Public License for more details.
1515+1616+ You should have received a copy of the GNU General Public License
1717+ along with Darling. If not, see <http://www.gnu.org/licenses/>.
1818+*/
1919+2020+#include <FSEvents/FSEvents.h>
2121+#include <stdio.h>
2222+#include <stdlib.h>
2323+#import "FSEventsImpl.h"
2424+2525+FSEventStreamRef FSEventStreamCreate(
2626+ CFAllocatorRef allocator,
2727+ FSEventStreamCallback callback,
2828+ FSEventStreamContext *context,
2929+ CFArrayRef pathsToWatch,
3030+ FSEventStreamEventId sinceWhen,
3131+ CFTimeInterval latency,
3232+ FSEventStreamCreateFlags flags)
3333+{
3434+ return (FSEventStreamRef) [[FSEventsImpl alloc] initWithPaths: (NSArray*)pathsToWatch
3535+ flags: flags
3636+ context: context
3737+ callback: callback];
3838+}
3939+4040+CFArrayRef FSEventStreamCopyPathsBeingWatched(ConstFSEventStreamRef streamRef)
4141+{
4242+ FSEventsImpl* impl = (FSEventsImpl*) streamRef;
4343+ return (CFArrayRef) [impl copyPathsToWatch];
4444+}
4545+4646+FSEventStreamEventId FSEventStreamGetLatestEventId(ConstFSEventStreamRef streamRef)
4747+{
4848+ return [((FSEventsImpl*) streamRef) lastEventID];
4949+}
5050+5151+void FSEventStreamInvalidate(FSEventStreamRef streamRef)
5252+{
5353+ [((FSEventsImpl*) streamRef) invalidate];
5454+}
5555+5656+void FSEventStreamRelease(FSEventStreamRef streamRef)
5757+{
5858+ [((FSEventsImpl*) streamRef) release];
5959+}
6060+6161+void FSEventStreamRetain(FSEventStreamRef streamRef)
6262+{
6363+ [((FSEventsImpl*) streamRef) retain];
6464+}
6565+6666+void FSEventStreamScheduleWithRunLoop(FSEventStreamRef streamRef, CFRunLoopRef runLoop, CFStringRef runLoopMode)
6767+{
6868+ [((FSEventsImpl*) streamRef) scheduleWithRunLoop: runLoop
6969+ mode: runLoopMode];
7070+}
7171+7272+void FSEventStreamSetDispatchQueue(FSEventStreamRef streamRef, dispatch_queue_t q)
7373+{
7474+ [((FSEventsImpl*) streamRef) setDispatchQueue: q];
7575+}
7676+7777+Boolean FSEventStreamStart(FSEventStreamRef streamRef)
7878+{
7979+ [((FSEventsImpl*) streamRef) start];
8080+ return TRUE;
8181+}
8282+8383+void FSEventStreamStop(FSEventStreamRef streamRef)
8484+{
8585+ [((FSEventsImpl*) streamRef) stop];
8686+}
8787+8888+void FSEventStreamUnscheduleFromRunLoop(FSEventStreamRef streamRef, CFRunLoopRef runLoop, CFStringRef runLoopMode)
8989+{
9090+ [((FSEventsImpl*) streamRef) unscheduleWithRunLoop: runLoop
9191+ mode: runLoopMode];
9292+}
···11+/*
22+ This file is part of Darling.
33+44+ Copyright (C) 2020 Lubos Dolezel
55+66+ Darling is free software: you can redistribute it and/or modify
77+ it under the terms of the GNU General Public License as published by
88+ the Free Software Foundation, either version 3 of the License, or
99+ (at your option) any later version.
1010+1111+ Darling is distributed in the hope that it will be useful,
1212+ but WITHOUT ANY WARRANTY; without even the implied warranty of
1313+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
1414+ GNU General Public License for more details.
1515+1616+ You should have received a copy of the GNU General Public License
1717+ along with Darling. If not, see <http://www.gnu.org/licenses/>.
1818+*/
1919+2020+#import <Foundation/NSObject.h>
2121+#import <Foundation/NSArray.h>
2222+#import <Foundation/NSString.h>
2323+#import <Foundation/NSDictionary.h>
2424+#include <CoreFoundation/CFBag.h>
2525+#include <FSEvents/FSEvents.h>
2626+#include <dispatch/dispatch.h>
2727+2828+@interface FSEventsImpl : NSObject
2929+{
3030+ NSArray<NSString*>* _pathsToWatch;
3131+ NSDictionary<NSNumber*, NSString*>* _wdMap;
3232+3333+ FSEventStreamCreateFlags _flags;
3434+ FSEventStreamContext _context;
3535+ FSEventStreamCallback _callback;
3636+ dispatch_source_t _source;
3737+ dispatch_queue_t _queue;
3838+ CFMutableBagRef _runloops;
3939+ CFRunLoopSourceRef _rlSource;
4040+ int _fd;
4141+ FSEventStreamEventId _lastEventID;
4242+ bool _running;
4343+4444+ NSMutableArray* _pathArray;
4545+ FSEventStreamEventFlags* _flagArray;
4646+ FSEventStreamEventId* _idArray;
4747+}
4848+4949+-(instancetype)initWithPaths:(NSArray*)pathsToWatch
5050+ flags:(FSEventStreamCreateFlags)flags
5151+ context:(FSEventStreamContext*)context
5252+ callback:(FSEventStreamCallback)callback;
5353+-(NSArray*)copyPathsToWatch;
5454+5555+-(void)setDispatchQueue:(dispatch_queue_t)queue;
5656+-(void)scheduleWithRunLoop:(CFRunLoopRef)rl
5757+ mode:(CFStringRef)rlMode;
5858+-(void)unscheduleWithRunLoop:(CFRunLoopRef)rl
5959+ mode:(CFStringRef)rlMode;
6060+-(void)invalidate;
6161+-(void)start;
6262+-(void)stop;
6363+-(FSEventStreamEventId)lastEventID;
6464+6565+@end
6666+