mirror of
https://github.com/wpilibsuite/allwpilib
synced 2026-06-29 02:21:44 +00:00
[cscore] Change run loop functions to not be mac specific (#4854)
This commit is contained in:
@@ -391,9 +391,9 @@ public class CameraServerJNI {
|
||||
|
||||
public static native void freeRawFrame(long frame);
|
||||
|
||||
public static native void runOsxRunLoop();
|
||||
public static native void runMainRunLoop();
|
||||
|
||||
public static native int runOsxRunLoopTimeout(double timeoutSeconds);
|
||||
public static native int runMainRunLoopTimeout(double timeoutSeconds);
|
||||
|
||||
public static native void stopOsxMainRunLoop();
|
||||
public static native void stopMainRunLoop();
|
||||
}
|
||||
|
||||
@@ -2229,38 +2229,38 @@ Java_edu_wpi_first_cscore_CameraServerJNI_freeRawFrame
|
||||
|
||||
/*
|
||||
* Class: edu_wpi_first_cscore_CameraServerJNI
|
||||
* Method: runOsxRunLoop
|
||||
* Method: runMainRunLoop
|
||||
* Signature: ()V
|
||||
*/
|
||||
JNIEXPORT void JNICALL
|
||||
Java_edu_wpi_first_cscore_CameraServerJNI_runOsxRunLoop
|
||||
Java_edu_wpi_first_cscore_CameraServerJNI_runMainRunLoop
|
||||
(JNIEnv*, jclass)
|
||||
{
|
||||
cs::RunOsxRunLoop();
|
||||
cs::RunMainRunLoop();
|
||||
}
|
||||
|
||||
/*
|
||||
* Class: edu_wpi_first_cscore_CameraServerJNI
|
||||
* Method: runOsxRunLoopTimeout
|
||||
* Method: runMainRunLoopTimeout
|
||||
* Signature: (D)I
|
||||
*/
|
||||
JNIEXPORT jint JNICALL
|
||||
Java_edu_wpi_first_cscore_CameraServerJNI_runOsxRunLoopTimeout
|
||||
Java_edu_wpi_first_cscore_CameraServerJNI_runMainRunLoopTimeout
|
||||
(JNIEnv*, jclass, jdouble timeoutSeconds)
|
||||
{
|
||||
return cs::RunOsxRunLoopTimeout(timeoutSeconds);
|
||||
return cs::RunMainRunLoopTimeout(timeoutSeconds);
|
||||
}
|
||||
|
||||
/*
|
||||
* Class: edu_wpi_first_cscore_CameraServerJNI
|
||||
* Method: stopOsxMainRunLoop
|
||||
* Method: stopMainRunLoop
|
||||
* Signature: ()V
|
||||
*/
|
||||
JNIEXPORT void JNICALL
|
||||
Java_edu_wpi_first_cscore_CameraServerJNI_stopOsxMainRunLoop
|
||||
Java_edu_wpi_first_cscore_CameraServerJNI_stopMainRunLoop
|
||||
(JNIEnv*, jclass)
|
||||
{
|
||||
return cs::StopOsxMainRunLoop();
|
||||
return cs::StopMainRunLoop();
|
||||
}
|
||||
|
||||
} // extern "C"
|
||||
|
||||
@@ -5,7 +5,7 @@
|
||||
#pragma once
|
||||
|
||||
namespace cs {
|
||||
void RunOsxRunLoop();
|
||||
int RunOsxRunLoopTimeout(double timeoutSeconds);
|
||||
void StopOsxMainRunLoop();
|
||||
void RunMainRunLoop();
|
||||
int RunMainRunLoopTimeout(double timeoutSeconds);
|
||||
void StopMainRunLoop();
|
||||
} // namespace cs
|
||||
|
||||
@@ -2,12 +2,37 @@
|
||||
// Open Source Software; you can modify and/or share it under the terms of
|
||||
// the WPILib BSD license file in the root directory of this project.
|
||||
|
||||
#include <wpi/Synchronization.h>
|
||||
|
||||
#include "cscore_runloop.h"
|
||||
|
||||
namespace cs {
|
||||
void RunOsxRunLoop() {}
|
||||
int RunOsxRunLoopTimeout(double timeoutSeconds) {
|
||||
return 0;
|
||||
static wpi::Event& GetInstance() {
|
||||
static wpi::Event event;
|
||||
return event;
|
||||
}
|
||||
|
||||
namespace cs {
|
||||
void RunMainRunLoop() {
|
||||
wpi::Event& event = GetInstance();
|
||||
wpi::WaitForObject(event.GetHandle());
|
||||
}
|
||||
|
||||
int RunMainRunLoopTimeout(double timeoutSeconds) {
|
||||
wpi::Event& event = GetInstance();
|
||||
bool timedOut = false;
|
||||
bool signaled =
|
||||
wpi::WaitForObject(event.GetHandle(), timeoutSeconds, &timedOut);
|
||||
if (timedOut) {
|
||||
return 3;
|
||||
}
|
||||
if (signaled) {
|
||||
return 2;
|
||||
}
|
||||
return 1;
|
||||
}
|
||||
|
||||
void StopMainRunLoop() {
|
||||
wpi::Event& event = GetInstance();
|
||||
event.Set();
|
||||
}
|
||||
void StopOsxMainRunLoop() {}
|
||||
} // namespace cs
|
||||
|
||||
@@ -5,17 +5,26 @@
|
||||
#include "cscore_runloop.h"
|
||||
|
||||
#include <CoreFoundation/CFRunLoop.h>
|
||||
#import <Foundation/Foundation.h>
|
||||
|
||||
namespace cs {
|
||||
void RunOsxRunLoop() {
|
||||
void RunMainRunLoop() {
|
||||
if (CFRunLoopGetMain() != CFRunLoopGetCurrent()) {
|
||||
NSLog(@"This method can only be called from the main thread");
|
||||
return;
|
||||
}
|
||||
CFRunLoopRun();
|
||||
}
|
||||
|
||||
int RunOsxRunLoopTimeout(double timeoutSeconds) {
|
||||
int RunMainRunLoopTimeout(double timeoutSeconds) {
|
||||
if (CFRunLoopGetMain() != CFRunLoopGetCurrent()) {
|
||||
NSLog(@"This method can only be called from the main thread");
|
||||
return -1;
|
||||
}
|
||||
return CFRunLoopRunInMode(kCFRunLoopDefaultMode, timeoutSeconds, false);
|
||||
}
|
||||
|
||||
void StopOsxMainRunLoop() {
|
||||
void StopMainRunLoop() {
|
||||
CFRunLoopStop(CFRunLoopGetMain());
|
||||
}
|
||||
}
|
||||
|
||||
@@ -2,12 +2,37 @@
|
||||
// Open Source Software; you can modify and/or share it under the terms of
|
||||
// the WPILib BSD license file in the root directory of this project.
|
||||
|
||||
#include <wpi/Synchronization.h>
|
||||
|
||||
#include "cscore_runloop.h"
|
||||
|
||||
namespace cs {
|
||||
void RunOsxRunLoop() {}
|
||||
int RunOsxRunLoopTimeout(double timeoutSeconds) {
|
||||
return 0;
|
||||
static wpi::Event& GetInstance() {
|
||||
static wpi::Event event;
|
||||
return event;
|
||||
}
|
||||
|
||||
namespace cs {
|
||||
void RunMainRunLoop() {
|
||||
wpi::Event& event = GetInstance();
|
||||
wpi::WaitForObject(event.GetHandle());
|
||||
}
|
||||
|
||||
int RunMainRunLoopTimeout(double timeoutSeconds) {
|
||||
wpi::Event& event = GetInstance();
|
||||
bool timedOut = false;
|
||||
bool signaled =
|
||||
wpi::WaitForObject(event.GetHandle(), timeoutSeconds, &timedOut);
|
||||
if (timedOut) {
|
||||
return 3;
|
||||
}
|
||||
if (signaled) {
|
||||
return 2;
|
||||
}
|
||||
return 1;
|
||||
}
|
||||
|
||||
void StopMainRunLoop() {
|
||||
wpi::Event& event = GetInstance();
|
||||
event.Set();
|
||||
}
|
||||
void StopOsxMainRunLoop() {}
|
||||
} // namespace cs
|
||||
|
||||
Reference in New Issue
Block a user