[wpiutil, wpilib] Add FileLogger and log console output (#6977)

This commit is contained in:
Gold856
2024-09-13 01:13:06 -04:00
committed by GitHub
parent 32252f7d6a
commit 3bbbf86632
12 changed files with 428 additions and 0 deletions

View File

@@ -7,6 +7,8 @@
#include <jni.h>
#include "edu_wpi_first_util_WPIUtilJNI.h"
#include "wpi/DataLog.h"
#include "wpi/FileLogger.h"
#include "wpi/RawFrame.h"
#include "wpi/Synchronization.h"
#include "wpi/jni_util.h"
@@ -414,4 +416,41 @@ Java_edu_wpi_first_util_WPIUtilJNI_setRawFrameInfo
f->pixelFormat = pixelFormat;
}
/*
* Class: edu_wpi_first_util_WPIUtilJNI
* Method: createFileLogger
* Signature: (Ljava/lang/String;JLjava/lang/String;)J
*/
JNIEXPORT jlong JNICALL
Java_edu_wpi_first_util_WPIUtilJNI_createFileLogger
(JNIEnv* env, jclass, jstring file, jlong log, jstring key)
{
if (!file) {
wpi::ThrowNullPointerException(env, "file is null");
return 0;
}
auto* f = reinterpret_cast<wpi::log::DataLog*>(log);
if (!f) {
wpi::ThrowNullPointerException(env, "log is null");
return 0;
}
if (!key) {
wpi::ThrowNullPointerException(env, "key is null");
return 0;
}
return reinterpret_cast<jlong>(
new wpi::FileLogger{JStringRef{env, file}, *f, JStringRef{env, key}});
}
/*
* Class: edu_wpi_first_util_WPIUtilJNI
* Method: freeFileLogger
* Signature: (J)V
*/
JNIEXPORT void JNICALL
Java_edu_wpi_first_util_WPIUtilJNI_freeFileLogger
(JNIEnv* env, jclass, jlong fileTail)
{
delete reinterpret_cast<wpi::FileLogger*>(fileTail);
}
} // extern "C"