Use java.util.function.Consumer for event listener.

This commit is contained in:
Peter Johnson
2016-11-13 17:02:38 -08:00
parent 0bcafedebf
commit 797d049f31
4 changed files with 7 additions and 17 deletions

View File

@@ -13,6 +13,7 @@ import java.io.OutputStream;
import java.io.FileOutputStream;
import java.io.IOException;
import java.nio.ByteBuffer;
import java.util.function.Consumer;
import org.opencv.core.Core;
public class CameraServerJNI {
@@ -164,7 +165,7 @@ public class CameraServerJNI {
//
// Listener Functions
//
public static native int addListener(VideoListenerFunction listener,
public static native int addListener(Consumer<VideoEvent> listener,
int eventMask, boolean immediateNotify);
public static native void removeListener(int handle);

View File

@@ -7,6 +7,8 @@
package edu.wpi.cscore;
import java.util.function.Consumer;
/// An event listener. This calls back to a desigated callback function when
/// an event matching the specified mask is generated by the library.
public class VideoListener {
@@ -15,7 +17,7 @@ public class VideoListener {
/// @param eventMask Bitmask of VideoEvent.Type values
/// @param immediateNotify Whether callback should be immediately called with
/// a representative set of events for the current library state.
public VideoListener(VideoListenerFunction listener, int eventMask,
public VideoListener(Consumer<VideoEvent> listener, int eventMask,
boolean immediateNotify) {
m_handle = CameraServerJNI.addListener(listener, eventMask, immediateNotify);
}

View File

@@ -1,12 +0,0 @@
/*----------------------------------------------------------------------------*/
/* Copyright (c) FIRST 2016. All Rights Reserved. */
/* Open Source Software - may be modified and shared by FRC teams. The code */
/* must be accompanied by the FIRST BSD license file in the root directory of */
/* the project. */
/*----------------------------------------------------------------------------*/
package edu.wpi.cscore;
public interface VideoListenerFunction {
void apply(VideoEvent event);
}