0

I am developing a C++ library where we have a module for file system handling and specifically callbacks for file changes. I have implemented the fsevent callback (as described in https://developer.apple.com/library/mac/documentation/Darwin/Reference/FSEvents_Ref/Reference/reference.html and FSEvents C++ Example).

The problem is that I don't get any callbacks unless i call CFRunLoopRun() after FSEventStreamStart(stream) which blocks the main thread. If I use the same code in a GLFW context without CFRunLoopRun() I get the callbacks and everything works fine (non-blocking).

I have gone through a lot of GLFW code and implemented an Objective-C NSEvent polling that GLFW does in its glfwPollEvents() function, unfortunately the event is nil every time it is called and no callbacks gets called.

GLFW snippet from cocoa_window.m:

for (;;)
{
    NSEvent* event = [NSApp nextEventMatchingMask:NSAnyEventMask
                                        untilDate:[NSDate distantPast]
                                           inMode:NSDefaultRunLoopMode
                                          dequeue:YES];
    if (event == nil)
        break;

    [NSApp sendEvent:event];
}

Any ideas on how to get the callbacks (even if I have to poll for them) without having to run a GLFW context?

Update:

I would have like to get the callbacks asynchronously but I found FSEventStreamFlushSync that forces the callback (if there is one) to get called (and it works!). I had tried the Async version first which didn't work.

Community
  • 1
  • 1
  • well you *need* some runloop for this to work. why cant you attach it to the main run loop? use `FSEventStreamScheduleWithRunLoop` to schedule on `CFRunLoopGetCurrent`. all of this is in the thread you linked. – Brad Allred Oct 16 '14 at 01:20
  • sorry, I meant `CFRunLoopGetMain`. – Brad Allred Oct 16 '14 at 01:26
  • I am using FSEventStreamScheduleWithRunLoop and tried both CFRunLoopGetCurrent and CFRunLoopGetMain. None of them seem to work without the GLFW context or the CFRunLoopRun. – Jonas Strandstedt Oct 16 '14 at 09:40

1 Answers1

2

The solution was to use FSEventStreamFlushSync which forces callbacks without the GLFW context.