Ejemplo n.º 1
0
  private Pointer[] createFSEventStream() throws IOException {
    final Pointer root = cf.CFStringCreateWithCString(Pointer.NULL, "/", ENC_MAC_ROMAN); // NOI18N
    if (root == Pointer.NULL) {
      throw new IOException("Path creation failed."); // NOI18N
    }
    final Pointer arr = cf.CFArrayCreateMutable(Pointer.NULL, new NativeLong(1), Pointer.NULL);
    if (arr == Pointer.NULL) {
      throw new IOException("Path list creation failed."); // NOI18N
    }
    cf.CFArrayAppendValue(arr, root);

    final Pointer eventStream =
        cs.FSEventStreamCreate(
            Pointer.NULL,
            callback,
            Pointer.NULL,
            arr,
            kFSEventStreamEventIdSinceNow,
            LATENCY,
            kFSEventStreamCreateFlagNoDefer);
    if (eventStream == Pointer.NULL) {
      throw new IOException("Creation of FSEventStream failed."); // NOI18N
    }
    final Pointer loop = cf.CFRunLoopGetCurrent();
    final Pointer kCFRunLoopDefaultMode = findDefaultMode(loop);
    if (kCFRunLoopDefaultMode == null) {
      throw new IOException("Caller has no defaul run loop mode."); // NOI18N
    }
    cs.FSEventStreamScheduleWithRunLoop(eventStream, loop, kCFRunLoopDefaultMode);
    if (LOG.isLoggable(DEBUG_LOG_LEVEL)) {
      LOG.log(DEBUG_LOG_LEVEL, getStreamDescription(eventStream));
    }
    cs.FSEventStreamStart(eventStream);
    return new Pointer[] {eventStream, loop};
  }
Ejemplo n.º 2
0
 public synchronized void stop() throws IOException {
   if (worker == null) {
     throw new IllegalStateException("FileSystemWatcher is not started."); // NOI18N
   }
   assert rtData != null;
   assert rtData.length == 2;
   assert rtData[0] != null;
   assert rtData[1] != null;
   cs.FSEventStreamStop(rtData[0]);
   cs.FSEventStreamInvalidate(rtData[0]);
   cs.FSEventStreamRelease(rtData[0]);
   cf.CFRunLoopStop(rtData[1]);
   worker.shutdown();
   worker = null;
   rtData = null;
 }
Ejemplo n.º 3
0
 private String getStreamDescription(final Pointer eventStream) {
   final Pointer desc = cs.FSEventStreamCopyDescription(eventStream);
   return desc == Pointer.NULL ? "" : cf.CFStringGetCStringPtr(desc, ENC_MAC_ROMAN); // NOI18N
 }