mirror of
https://github.com/wpilibsuite/allwpilib
synced 2026-06-26 01:51:41 +00:00
Use java.util.function.Consumer for event listener.
This commit is contained in:
@@ -889,7 +889,7 @@ JNIEXPORT void JNICALL Java_edu_wpi_cscore_CameraServerJNI_setSinkEnabled
|
||||
/*
|
||||
* Class: edu_wpi_cscore_CameraServerJNI
|
||||
* Method: addListener
|
||||
* Signature: (Ledu/wpi/cameraserver/CameraServerJNI/ConnectionListenerFunction;IZ)I
|
||||
* Signature: (Ljava/util/function/Consumer;IZ)I
|
||||
*/
|
||||
JNIEXPORT jint JNICALL Java_edu_wpi_cscore_CameraServerJNI_addListener
|
||||
(JNIEnv *envouter, jclass, jobject listener, jint eventMask, jboolean immediateNotify)
|
||||
@@ -904,8 +904,7 @@ JNIEXPORT jint JNICALL Java_edu_wpi_cscore_CameraServerJNI_addListener
|
||||
if (!cls) return 0;
|
||||
|
||||
// method ids, on the other hand, are safe to retain
|
||||
jmethodID mid = envouter->GetMethodID(cls, "apply",
|
||||
"(Ledu/wpi/cameraserver/VideoEvent;)V");
|
||||
jmethodID mid = envouter->GetMethodID(cls, "accept", "(Ljava/lang/Object;)V");
|
||||
if (!mid) return 0;
|
||||
|
||||
CS_Status status = 0;
|
||||
|
||||
@@ -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);
|
||||
|
||||
@@ -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);
|
||||
}
|
||||
|
||||
@@ -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);
|
||||
}
|
||||
Reference in New Issue
Block a user