コード例 #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};
  }
コード例 #2
0
 private Pointer findDefaultMode(final Pointer runLoop) {
   final Pointer modes = cf.CFRunLoopCopyAllModes(runLoop);
   if (modes != Pointer.NULL) {
     final int modesCount = cf.CFArrayGetCount(modes).intValue();
     for (int i = 0; i < modesCount; i++) {
       final Pointer mode = cf.CFArrayGetValueAtIndex(modes, new NativeLong(i));
       if (mode != Pointer.NULL
           && DEFAULT_RUN_LOOP_MODE.equals(cf.CFStringGetCStringPtr(mode, ENC_MAC_ROMAN))) {
         return mode;
       }
     }
   }
   return null;
 }
コード例 #3
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;
 }
コード例 #4
0
ファイル: CGGradient.java プロジェクト: h87kg/robovm
 private static CGGradient create(CGColorSpace space, CGColor[] colors, Object locations) {
   if (colors == null) {
     throw new NullPointerException("colors");
   }
   try (CFMutableArray colorsArray =
       CFMutableArray.createMutable(null, colors.length, CoreFoundation.TypeArrayCallBacks())) {
     for (CGColor c : colors) {
       colorsArray.appendValue(Struct.toStruct(VoidPtr.class, c.getHandle()));
     }
     return create(
         space,
         colorsArray,
         locations != null
             ? VM.getArrayValuesAddress(CoreGraphics.toMachineSizedFloatArray(locations))
             : 0);
   }
 }
コード例 #5
0
 private String getStreamDescription(final Pointer eventStream) {
   final Pointer desc = cs.FSEventStreamCopyDescription(eventStream);
   return desc == Pointer.NULL ? "" : cf.CFStringGetCStringPtr(desc, ENC_MAC_ROMAN); // NOI18N
 }