diff --git a/CMakeLists.txt b/CMakeLists.txt index df1e06e890f..6b88f9e010a 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -291,6 +291,8 @@ set(WPIUNITS_DEP_REPLACE_IMPL "find_dependency(wpiunits)") set(WPIUTIL_DEP_REPLACE "find_dependency(wpiutil)") add_subdirectory(wpiutil) +add_subdirectory(datalog) + if(WITH_NTCORE) set(NTCORE_DEP_REPLACE "find_dependency(ntcore)") set(WPINET_DEP_REPLACE "find_dependency(wpinet)") diff --git a/datalog/BUILD.bazel b/datalog/BUILD.bazel new file mode 100644 index 00000000000..1e3c34c1171 --- /dev/null +++ b/datalog/BUILD.bazel @@ -0,0 +1,106 @@ +load("@rules_cc//cc:defs.bzl", "cc_binary", "cc_library", "cc_test") +load("@rules_java//java:defs.bzl", "java_binary") +load("@rules_python//python:defs.bzl", "py_binary") +load("//shared/bazel/rules:java_rules.bzl", "wpilib_java_junit5_test") +load("//shared/bazel/rules:jni_rules.bzl", "wpilib_jni_cc_library", "wpilib_jni_java_library") + +cc_library( + name = "datalog.static", + srcs = glob( + ["src/main/native/cpp/**"], + exclude = ["src/main/native/cpp/jni/**"], + ), + hdrs = glob(["src/main/native/include/**"]), + includes = [ + "src/main/native/cpp", + "src/main/native/include", + ], + strip_include_prefix = "src/main/native/include", + visibility = ["//visibility:public"], + deps = [ + "//wpiutil:wpiutil.static", + ], +) + +wpilib_jni_cc_library( + name = "datalogjni", + srcs = glob(["src/main/native/cpp/jni/**"]), + java_dep = ":datalog-java", + visibility = ["//visibility:public"], + deps = [ + ":datalog.static", + ], +) + +wpilib_jni_java_library( + name = "datalog-java", + srcs = glob(["src/main/java/**/*.java"]), + native_libs = [":datalogjni"], + visibility = ["//visibility:public"], + deps = [ + "//wpiutil:wpiutil-java", + "@maven//:us_hebi_quickbuf_quickbuf_runtime", + ], +) + +py_binary( + name = "datalog", + srcs = ["examples/printlog/datalog.py"], + tags = ["manual"], +) + +cc_binary( + name = "printlog", + srcs = ["examples/printlog/printlog.cpp"], + deps = [ + ":datalog.static", + "//wpiutil:wpiutil.static", + ], +) + +cc_binary( + name = "writelog", + srcs = ["examples/writelog/writelog.cpp"], + deps = [ + ":datalog.static", + "//wpiutil:wpiutil.static", + ], +) + +java_binary( + name = "printlog-java", + srcs = ["src/printlog/java/printlog/PrintLog.java"], + main_class = "printlog.PrintLog", + deps = [ + ":datalog-java", + ], +) + +cc_test( + name = "datalog-cpp-test", + size = "small", + srcs = glob([ + "src/test/native/**/*.cpp", + "src/test/native/**/*.h", + ]), + tags = [ + "exclusive", + "no-asan", + "no-tsan", + ], + deps = [ + ":datalog.static", + "//thirdparty/googletest:googletest.static", + "//wpiutil:wpiutil-testlib", + ], +) + +wpilib_java_junit5_test( + name = "datalog-java-test", + srcs = glob(["src/test/java/**/*.java"]), + tags = ["exclusive"], + deps = [ + ":datalog-java", + "//wpiutil:wpiutil-java", + ], +) diff --git a/datalog/CMakeLists.txt b/datalog/CMakeLists.txt new file mode 100644 index 00000000000..2e31dc10c40 --- /dev/null +++ b/datalog/CMakeLists.txt @@ -0,0 +1,108 @@ +project(datalog) + +include(CompileWarnings) + +file(GLOB datalog_native_src src/main/native/cpp/*.cpp) + +file(GLOB datalog_jni_src src/main/native/cpp/jni/DataLogJNI.cpp) +list(REMOVE_ITEM datalog_native_src ${datalog_jni_src}) + +add_library(datalog ${datalog_native_src}) +set_target_properties(datalog PROPERTIES DEBUG_POSTFIX "d") + +target_compile_features(datalog PUBLIC cxx_std_20) +if(MSVC) + target_compile_options( + datalog + PUBLIC /permissive- /Zc:preprocessor /Zc:__cplusplus /Zc:throwingNew /MP /bigobj /utf-8 + ) + target_compile_definitions(datalog PRIVATE -D_CRT_SECURE_NO_WARNINGS) +endif() +wpilib_target_warnings(datalog) + +target_include_directories( + datalog + PUBLIC $ +) + +target_link_libraries(datalog PRIVATE wpiutil) + +subdir_list(datalog_examples "${CMAKE_CURRENT_SOURCE_DIR}/examples") +foreach(example ${datalog_examples}) + file(GLOB datalog_example_src examples/${example}/*.cpp) + if(datalog_example_src) + add_executable(datalog_${example} ${datalog_example_src}) + wpilib_target_warnings(datalog_${example}) + target_link_libraries(datalog_${example} datalog wpiutil) + set_property(TARGET datalog_${example} PROPERTY FOLDER "examples") + endif() +endforeach() + +# Java bindings +if(WITH_JAVA) + include(UseJava) + + set(CMAKE_JNI_TARGET true) + + file(GLOB_RECURSE JAVA_SOURCES src/main/java/*.java) + file(GLOB QUICKBUF_JAR ${WPILIB_BINARY_DIR}/wpiutil/thirdparty/quickbuf/*.jar) + + add_jar( + datalog_jar + ${JAVA_SOURCES} + # INCLUDE_JARS ${JACKSON_JARS} ${QUICKBUF_JAR} + INCLUDE_JARS wpiutil_jar ${QUICKBUF_JAR} + OUTPUT_NAME datalog + OUTPUT_DIR ${WPILIB_BINARY_DIR}/${java_lib_dest} + GENERATE_NATIVE_HEADERS datalog_jni_headers + ) + set_property(TARGET datalog_jar PROPERTY FOLDER "java") + + install_jar(datalog_jar DESTINATION ${java_lib_dest}) + install_jar_exports(TARGETS datalog_jar FILE datalog_jar.cmake DESTINATION share/datalog) + + add_library(datalogjni ${datalog_jni_src}) + wpilib_target_warnings(datalogjni) + target_link_libraries(datalogjni PUBLIC datalog wpiutil) + + set_property(TARGET datalogjni PROPERTY FOLDER "libraries") + + target_link_libraries(datalogjni PRIVATE datalog_jni_headers) + add_dependencies(datalogjni datalog_jar) + + install(TARGETS datalogjni EXPORT datalogjni) + export(TARGETS datalogjni FILE datalogjni.cmake NAMESPACE datalogjni::) +endif() + +if(WITH_JAVA_SOURCE) + include(UseJava) + include(CreateSourceJar) + add_source_jar( + datalog_src_jar + BASE_DIRECTORIES ${CMAKE_CURRENT_SOURCE_DIR}/src/main/java + OUTPUT_NAME datalog-sources + OUTPUT_DIR ${WPILIB_BINARY_DIR}/${java_lib_dest} + ) + set_property(TARGET datalog_src_jar PROPERTY FOLDER "java") + + install_jar(datalog_src_jar DESTINATION ${java_lib_dest}) +endif() + +install(TARGETS datalog EXPORT datalog) +export(TARGETS datalog FILE datalog.cmake NAMESPACE datalog::) + +configure_file(datalog-config.cmake.in ${WPILIB_BINARY_DIR}/datalog-config.cmake) +install(FILES ${WPILIB_BINARY_DIR}/datalog-config.cmake DESTINATION share/datalog) +install(EXPORT datalog DESTINATION share/datalog) + +if(WITH_TESTS) + file(GLOB_RECURSE datalog_testlib_src src/test/native/include/*.h) + add_library(datalog_testlib INTERFACE ${datalog_test_src}) + target_include_directories(datalog_testlib INTERFACE src/test/native/include) + + wpilib_add_test(datalog src/test/native/cpp) + target_link_libraries(datalog_test datalog googletest datalog_testlib wpiutil) + if(MSVC) + target_compile_options(datalog_test PRIVATE /utf-8) + endif() +endif() diff --git a/datalog/build.gradle b/datalog/build.gradle new file mode 100644 index 00000000000..211908a4d2b --- /dev/null +++ b/datalog/build.gradle @@ -0,0 +1,32 @@ +ext { + useJava = true + useCpp = true + baseId = 'datalog' + groupId = 'edu.wpi.first.datalog' + + nativeName = 'datalog' + devMain = 'edu.wpi.first.datalog.DevMain' +} + +apply from: "${rootDir}/shared/jni/setupBuild.gradle" + +nativeUtils.exportsConfigs { + datalog { + } +} + +model { + components { + all { + it.sources.each { + it.exportedHeaders { + srcDirs 'src/main/native/include' + } + } + } + } +} + +dependencies { + api project(":wpiutil") +} diff --git a/datalog/datalog-config.cmake.in b/datalog/datalog-config.cmake.in new file mode 100644 index 00000000000..eb26b9cb314 --- /dev/null +++ b/datalog/datalog-config.cmake.in @@ -0,0 +1,5 @@ +@FILENAME_DEP_REPLACE@ +include(${SELF_DIR}/wpiutil.cmake) +if(@WITH_JAVA@) + include(${SELF_DIR}/wpiutil_jar.cmake) +endif() diff --git a/wpiutil/examples/printlog/datalog.py b/datalog/examples/printlog/datalog.py similarity index 100% rename from wpiutil/examples/printlog/datalog.py rename to datalog/examples/printlog/datalog.py diff --git a/wpiutil/examples/printlog/printlog.cpp b/datalog/examples/printlog/printlog.cpp similarity index 97% rename from wpiutil/examples/printlog/printlog.cpp rename to datalog/examples/printlog/printlog.cpp index a17d30b3852..c4eea6484bc 100644 --- a/wpiutil/examples/printlog/printlog.cpp +++ b/datalog/examples/printlog/printlog.cpp @@ -9,11 +9,10 @@ #include #include #include - -#include "wpi/DataLogReader.h" -#include "wpi/DenseMap.h" -#include "wpi/MemoryBuffer.h" -#include "wpi/print.h" +#include +#include +#include +#include int main(int argc, const char** argv) { if (argc != 2) { diff --git a/wpiutil/examples/writelog/writelog.cpp b/datalog/examples/writelog/writelog.cpp similarity index 97% rename from wpiutil/examples/writelog/writelog.cpp rename to datalog/examples/writelog/writelog.cpp index dd9f8fa33da..d6a2949282d 100644 --- a/wpiutil/examples/writelog/writelog.cpp +++ b/datalog/examples/writelog/writelog.cpp @@ -8,8 +8,8 @@ #include #include -#include "wpi/DataLogBackgroundWriter.h" -#include "wpi/print.h" +#include +#include int main(int argc, char** argv) { using std::chrono::duration_cast; diff --git a/datalog/src/dev/java/edu/wpi/first/datalog/DevMain.java b/datalog/src/dev/java/edu/wpi/first/datalog/DevMain.java new file mode 100644 index 00000000000..2c424d6c84e --- /dev/null +++ b/datalog/src/dev/java/edu/wpi/first/datalog/DevMain.java @@ -0,0 +1,12 @@ +// Copyright (c) FIRST and other WPILib contributors. +// 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. + +package edu.wpi.first.datalog; + +public final class DevMain { + /** Main entry point. */ + public static void main(String[] args) {} + + private DevMain() {} +} diff --git a/datalog/src/dev/native/cpp/main.cpp b/datalog/src/dev/native/cpp/main.cpp new file mode 100644 index 00000000000..a3e363efca0 --- /dev/null +++ b/datalog/src/dev/native/cpp/main.cpp @@ -0,0 +1,5 @@ +// Copyright (c) FIRST and other WPILib contributors. +// 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. + +int main() {} diff --git a/wpiutil/src/main/java/edu/wpi/first/util/datalog/BooleanArrayLogEntry.java b/datalog/src/main/java/edu/wpi/first/datalog/BooleanArrayLogEntry.java similarity index 99% rename from wpiutil/src/main/java/edu/wpi/first/util/datalog/BooleanArrayLogEntry.java rename to datalog/src/main/java/edu/wpi/first/datalog/BooleanArrayLogEntry.java index 76b85f518c2..01a3fffce15 100644 --- a/wpiutil/src/main/java/edu/wpi/first/util/datalog/BooleanArrayLogEntry.java +++ b/datalog/src/main/java/edu/wpi/first/datalog/BooleanArrayLogEntry.java @@ -2,7 +2,7 @@ // 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. -package edu.wpi.first.util.datalog; +package edu.wpi.first.datalog; import java.util.Arrays; diff --git a/wpiutil/src/main/java/edu/wpi/first/util/datalog/BooleanLogEntry.java b/datalog/src/main/java/edu/wpi/first/datalog/BooleanLogEntry.java similarity index 98% rename from wpiutil/src/main/java/edu/wpi/first/util/datalog/BooleanLogEntry.java rename to datalog/src/main/java/edu/wpi/first/datalog/BooleanLogEntry.java index ba1783e1618..b037370fcc4 100644 --- a/wpiutil/src/main/java/edu/wpi/first/util/datalog/BooleanLogEntry.java +++ b/datalog/src/main/java/edu/wpi/first/datalog/BooleanLogEntry.java @@ -2,7 +2,7 @@ // 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. -package edu.wpi.first.util.datalog; +package edu.wpi.first.datalog; /** Log boolean values. */ public class BooleanLogEntry extends DataLogEntry { diff --git a/wpiutil/src/main/java/edu/wpi/first/util/datalog/DataLog.java b/datalog/src/main/java/edu/wpi/first/datalog/DataLog.java similarity index 99% rename from wpiutil/src/main/java/edu/wpi/first/util/datalog/DataLog.java rename to datalog/src/main/java/edu/wpi/first/datalog/DataLog.java index 4a89542cb75..fed02a0a49d 100644 --- a/wpiutil/src/main/java/edu/wpi/first/util/datalog/DataLog.java +++ b/datalog/src/main/java/edu/wpi/first/datalog/DataLog.java @@ -2,7 +2,7 @@ // 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. -package edu.wpi.first.util.datalog; +package edu.wpi.first.datalog; import edu.wpi.first.util.WPIUtilJNI; import edu.wpi.first.util.protobuf.Protobuf; diff --git a/wpiutil/src/main/java/edu/wpi/first/util/datalog/DataLogBackgroundWriter.java b/datalog/src/main/java/edu/wpi/first/datalog/DataLogBackgroundWriter.java similarity index 98% rename from wpiutil/src/main/java/edu/wpi/first/util/datalog/DataLogBackgroundWriter.java rename to datalog/src/main/java/edu/wpi/first/datalog/DataLogBackgroundWriter.java index 18a6e5e63c6..f9ac427e6a6 100644 --- a/wpiutil/src/main/java/edu/wpi/first/util/datalog/DataLogBackgroundWriter.java +++ b/datalog/src/main/java/edu/wpi/first/datalog/DataLogBackgroundWriter.java @@ -2,7 +2,7 @@ // 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. -package edu.wpi.first.util.datalog; +package edu.wpi.first.datalog; /** * A data log background writer that periodically flushes the data log on a background thread. The diff --git a/wpiutil/src/main/java/edu/wpi/first/util/datalog/DataLogEntry.java b/datalog/src/main/java/edu/wpi/first/datalog/DataLogEntry.java similarity index 98% rename from wpiutil/src/main/java/edu/wpi/first/util/datalog/DataLogEntry.java rename to datalog/src/main/java/edu/wpi/first/datalog/DataLogEntry.java index 8502428405e..9c58f94e970 100644 --- a/wpiutil/src/main/java/edu/wpi/first/util/datalog/DataLogEntry.java +++ b/datalog/src/main/java/edu/wpi/first/datalog/DataLogEntry.java @@ -2,7 +2,7 @@ // 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. -package edu.wpi.first.util.datalog; +package edu.wpi.first.datalog; /** Log entry base class. */ public class DataLogEntry { diff --git a/wpiutil/src/main/java/edu/wpi/first/util/datalog/DataLogIterator.java b/datalog/src/main/java/edu/wpi/first/datalog/DataLogIterator.java similarity index 97% rename from wpiutil/src/main/java/edu/wpi/first/util/datalog/DataLogIterator.java rename to datalog/src/main/java/edu/wpi/first/datalog/DataLogIterator.java index 3f1d66e72d8..f6579e54a48 100644 --- a/wpiutil/src/main/java/edu/wpi/first/util/datalog/DataLogIterator.java +++ b/datalog/src/main/java/edu/wpi/first/datalog/DataLogIterator.java @@ -2,7 +2,7 @@ // 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. -package edu.wpi.first.util.datalog; +package edu.wpi.first.datalog; import java.util.Iterator; import java.util.NoSuchElementException; diff --git a/wpiutil/src/main/java/edu/wpi/first/util/datalog/DataLogJNI.java b/datalog/src/main/java/edu/wpi/first/datalog/DataLogJNI.java similarity index 83% rename from wpiutil/src/main/java/edu/wpi/first/util/datalog/DataLogJNI.java rename to datalog/src/main/java/edu/wpi/first/datalog/DataLogJNI.java index 8b949e55ced..bffd6ab3c3a 100644 --- a/wpiutil/src/main/java/edu/wpi/first/util/datalog/DataLogJNI.java +++ b/datalog/src/main/java/edu/wpi/first/datalog/DataLogJNI.java @@ -2,18 +2,72 @@ // 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. -package edu.wpi.first.util.datalog; +package edu.wpi.first.datalog; -import edu.wpi.first.util.WPIUtilJNI; +import edu.wpi.first.util.RuntimeLoader; import java.io.IOException; import java.nio.ByteBuffer; +import java.util.concurrent.atomic.AtomicBoolean; /** - * DataLog wpiutil JNI Functions. + * DataLog JNI Functions. * - * @see "wpiutil/DataLog.h" + * @see "datalog/DataLog.h" */ -public class DataLogJNI extends WPIUtilJNI { +public class DataLogJNI { + static boolean libraryLoaded = false; + + /** Sets whether JNI should be loaded in the static block. */ + public static class Helper { + private static AtomicBoolean extractOnStaticLoad = new AtomicBoolean(true); + + /** + * Returns true if the JNI should be loaded in the static block. + * + * @return True if the JNI should be loaded in the static block. + */ + public static boolean getExtractOnStaticLoad() { + return extractOnStaticLoad.get(); + } + + /** + * Sets whether the JNI should be loaded in the static block. + * + * @param load Whether the JNI should be loaded in the static block. + */ + public static void setExtractOnStaticLoad(boolean load) { + extractOnStaticLoad.set(load); + } + + /** Utility class. */ + private Helper() {} + } + + static { + if (Helper.getExtractOnStaticLoad()) { + try { + RuntimeLoader.loadLibrary("datalogjni"); + } catch (Exception ex) { + ex.printStackTrace(); + System.exit(1); + } + libraryLoaded = true; + } + } + + /** + * Force load the library. + * + * @throws IOException if the library failed to load + */ + public static synchronized void forceLoad() throws IOException { + if (libraryLoaded) { + return; + } + RuntimeLoader.loadLibrary("datalogjni"); + libraryLoaded = true; + } + /** * Create a new Data Log background writer. The log will be initially created with a temporary * filename. @@ -298,6 +352,24 @@ private static native void appendRawBuffer( */ static native void appendStringArray(long impl, int entry, String[] value, long timestamp); + /** + * Create a native FileLogger. When the specified file is modified, appended data will be appended + * to the specified data log. + * + * @param file path to the file + * @param log data log implementation handle + * @param key log key to append data to + * @return The FileLogger handle. + */ + public static native long createFileLogger(String file, long log, String key); + + /** + * Free a native FileLogger. This causes the FileLogger to stop appending data to the log. + * + * @param fileTail The FileLogger handle. + */ + public static native void freeFileLogger(long fileTail); + /** Utility class. */ private DataLogJNI() {} } diff --git a/wpiutil/src/main/java/edu/wpi/first/util/datalog/DataLogReader.java b/datalog/src/main/java/edu/wpi/first/datalog/DataLogReader.java similarity index 99% rename from wpiutil/src/main/java/edu/wpi/first/util/datalog/DataLogReader.java rename to datalog/src/main/java/edu/wpi/first/datalog/DataLogReader.java index 55eabf3ad74..c58da2dc160 100644 --- a/wpiutil/src/main/java/edu/wpi/first/util/datalog/DataLogReader.java +++ b/datalog/src/main/java/edu/wpi/first/datalog/DataLogReader.java @@ -2,7 +2,7 @@ // 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. -package edu.wpi.first.util.datalog; +package edu.wpi.first.datalog; import java.io.IOException; import java.io.RandomAccessFile; diff --git a/wpiutil/src/main/java/edu/wpi/first/util/datalog/DataLogRecord.java b/datalog/src/main/java/edu/wpi/first/datalog/DataLogRecord.java similarity index 99% rename from wpiutil/src/main/java/edu/wpi/first/util/datalog/DataLogRecord.java rename to datalog/src/main/java/edu/wpi/first/datalog/DataLogRecord.java index 5e3965b5aae..cf7f2d2d526 100644 --- a/wpiutil/src/main/java/edu/wpi/first/util/datalog/DataLogRecord.java +++ b/datalog/src/main/java/edu/wpi/first/datalog/DataLogRecord.java @@ -2,7 +2,7 @@ // 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. -package edu.wpi.first.util.datalog; +package edu.wpi.first.datalog; import java.nio.BufferUnderflowException; import java.nio.ByteBuffer; diff --git a/wpiutil/src/main/java/edu/wpi/first/util/datalog/DataLogWriter.java b/datalog/src/main/java/edu/wpi/first/datalog/DataLogWriter.java similarity index 98% rename from wpiutil/src/main/java/edu/wpi/first/util/datalog/DataLogWriter.java rename to datalog/src/main/java/edu/wpi/first/datalog/DataLogWriter.java index 058d6dd8a46..ce751d77768 100644 --- a/wpiutil/src/main/java/edu/wpi/first/util/datalog/DataLogWriter.java +++ b/datalog/src/main/java/edu/wpi/first/datalog/DataLogWriter.java @@ -2,7 +2,7 @@ // 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. -package edu.wpi.first.util.datalog; +package edu.wpi.first.datalog; import java.io.IOException; import java.io.OutputStream; diff --git a/wpiutil/src/main/java/edu/wpi/first/util/datalog/DoubleArrayLogEntry.java b/datalog/src/main/java/edu/wpi/first/datalog/DoubleArrayLogEntry.java similarity index 99% rename from wpiutil/src/main/java/edu/wpi/first/util/datalog/DoubleArrayLogEntry.java rename to datalog/src/main/java/edu/wpi/first/datalog/DoubleArrayLogEntry.java index 2fe528f1bd3..7a9b4943524 100644 --- a/wpiutil/src/main/java/edu/wpi/first/util/datalog/DoubleArrayLogEntry.java +++ b/datalog/src/main/java/edu/wpi/first/datalog/DoubleArrayLogEntry.java @@ -2,7 +2,7 @@ // 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. -package edu.wpi.first.util.datalog; +package edu.wpi.first.datalog; import java.util.Arrays; diff --git a/wpiutil/src/main/java/edu/wpi/first/util/datalog/DoubleLogEntry.java b/datalog/src/main/java/edu/wpi/first/datalog/DoubleLogEntry.java similarity index 98% rename from wpiutil/src/main/java/edu/wpi/first/util/datalog/DoubleLogEntry.java rename to datalog/src/main/java/edu/wpi/first/datalog/DoubleLogEntry.java index 2484063aba0..e4ec6909af6 100644 --- a/wpiutil/src/main/java/edu/wpi/first/util/datalog/DoubleLogEntry.java +++ b/datalog/src/main/java/edu/wpi/first/datalog/DoubleLogEntry.java @@ -2,7 +2,7 @@ // 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. -package edu.wpi.first.util.datalog; +package edu.wpi.first.datalog; /** Log double values. */ public class DoubleLogEntry extends DataLogEntry { diff --git a/wpiutil/src/main/java/edu/wpi/first/util/FileLogger.java b/datalog/src/main/java/edu/wpi/first/datalog/FileLogger.java similarity index 82% rename from wpiutil/src/main/java/edu/wpi/first/util/FileLogger.java rename to datalog/src/main/java/edu/wpi/first/datalog/FileLogger.java index 438861b53ee..afa98b2a6f9 100644 --- a/wpiutil/src/main/java/edu/wpi/first/util/FileLogger.java +++ b/datalog/src/main/java/edu/wpi/first/datalog/FileLogger.java @@ -2,9 +2,7 @@ // 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. -package edu.wpi.first.util; - -import edu.wpi.first.util.datalog.DataLog; +package edu.wpi.first.datalog; /** * A class version of `tail -f`, otherwise known as `tail -f` at home. Watches a file and puts the @@ -22,11 +20,11 @@ public class FileLogger implements AutoCloseable { * @param key The log key to append data to. */ public FileLogger(String file, DataLog log, String key) { - m_impl = WPIUtilJNI.createFileLogger(file, log.getImpl(), key); + m_impl = DataLogJNI.createFileLogger(file, log.getImpl(), key); } @Override public void close() { - WPIUtilJNI.freeFileLogger(m_impl); + DataLogJNI.freeFileLogger(m_impl); } } diff --git a/wpiutil/src/main/java/edu/wpi/first/util/datalog/FloatArrayLogEntry.java b/datalog/src/main/java/edu/wpi/first/datalog/FloatArrayLogEntry.java similarity index 99% rename from wpiutil/src/main/java/edu/wpi/first/util/datalog/FloatArrayLogEntry.java rename to datalog/src/main/java/edu/wpi/first/datalog/FloatArrayLogEntry.java index 136b7e5b420..8532e3ab1e0 100644 --- a/wpiutil/src/main/java/edu/wpi/first/util/datalog/FloatArrayLogEntry.java +++ b/datalog/src/main/java/edu/wpi/first/datalog/FloatArrayLogEntry.java @@ -2,7 +2,7 @@ // 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. -package edu.wpi.first.util.datalog; +package edu.wpi.first.datalog; import java.util.Arrays; diff --git a/wpiutil/src/main/java/edu/wpi/first/util/datalog/FloatLogEntry.java b/datalog/src/main/java/edu/wpi/first/datalog/FloatLogEntry.java similarity index 98% rename from wpiutil/src/main/java/edu/wpi/first/util/datalog/FloatLogEntry.java rename to datalog/src/main/java/edu/wpi/first/datalog/FloatLogEntry.java index 8cb02cfafdd..2286a7328c8 100644 --- a/wpiutil/src/main/java/edu/wpi/first/util/datalog/FloatLogEntry.java +++ b/datalog/src/main/java/edu/wpi/first/datalog/FloatLogEntry.java @@ -2,7 +2,7 @@ // 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. -package edu.wpi.first.util.datalog; +package edu.wpi.first.datalog; /** Log float values. */ public class FloatLogEntry extends DataLogEntry { diff --git a/wpiutil/src/main/java/edu/wpi/first/util/datalog/IntegerArrayLogEntry.java b/datalog/src/main/java/edu/wpi/first/datalog/IntegerArrayLogEntry.java similarity index 99% rename from wpiutil/src/main/java/edu/wpi/first/util/datalog/IntegerArrayLogEntry.java rename to datalog/src/main/java/edu/wpi/first/datalog/IntegerArrayLogEntry.java index 80e2be36d95..1f9c9ff64e3 100644 --- a/wpiutil/src/main/java/edu/wpi/first/util/datalog/IntegerArrayLogEntry.java +++ b/datalog/src/main/java/edu/wpi/first/datalog/IntegerArrayLogEntry.java @@ -2,7 +2,7 @@ // 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. -package edu.wpi.first.util.datalog; +package edu.wpi.first.datalog; import java.util.Arrays; diff --git a/wpiutil/src/main/java/edu/wpi/first/util/datalog/IntegerLogEntry.java b/datalog/src/main/java/edu/wpi/first/datalog/IntegerLogEntry.java similarity index 98% rename from wpiutil/src/main/java/edu/wpi/first/util/datalog/IntegerLogEntry.java rename to datalog/src/main/java/edu/wpi/first/datalog/IntegerLogEntry.java index 25f491cc035..0b807e70e97 100644 --- a/wpiutil/src/main/java/edu/wpi/first/util/datalog/IntegerLogEntry.java +++ b/datalog/src/main/java/edu/wpi/first/datalog/IntegerLogEntry.java @@ -2,7 +2,7 @@ // 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. -package edu.wpi.first.util.datalog; +package edu.wpi.first.datalog; /** Log integer values. */ public class IntegerLogEntry extends DataLogEntry { diff --git a/wpiutil/src/main/java/edu/wpi/first/util/datalog/ProtobufLogEntry.java b/datalog/src/main/java/edu/wpi/first/datalog/ProtobufLogEntry.java similarity index 99% rename from wpiutil/src/main/java/edu/wpi/first/util/datalog/ProtobufLogEntry.java rename to datalog/src/main/java/edu/wpi/first/datalog/ProtobufLogEntry.java index 9108e56bbf9..f91cc47bf4b 100644 --- a/wpiutil/src/main/java/edu/wpi/first/util/datalog/ProtobufLogEntry.java +++ b/datalog/src/main/java/edu/wpi/first/datalog/ProtobufLogEntry.java @@ -2,7 +2,7 @@ // 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. -package edu.wpi.first.util.datalog; +package edu.wpi.first.datalog; import edu.wpi.first.util.protobuf.Protobuf; import edu.wpi.first.util.protobuf.ProtobufBuffer; diff --git a/wpiutil/src/main/java/edu/wpi/first/util/datalog/RawLogEntry.java b/datalog/src/main/java/edu/wpi/first/datalog/RawLogEntry.java similarity index 99% rename from wpiutil/src/main/java/edu/wpi/first/util/datalog/RawLogEntry.java rename to datalog/src/main/java/edu/wpi/first/datalog/RawLogEntry.java index 9ab59e9659c..b2a29b9b270 100644 --- a/wpiutil/src/main/java/edu/wpi/first/util/datalog/RawLogEntry.java +++ b/datalog/src/main/java/edu/wpi/first/datalog/RawLogEntry.java @@ -2,7 +2,7 @@ // 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. -package edu.wpi.first.util.datalog; +package edu.wpi.first.datalog; import java.nio.ByteBuffer; import java.util.Arrays; diff --git a/wpiutil/src/main/java/edu/wpi/first/util/datalog/StringArrayLogEntry.java b/datalog/src/main/java/edu/wpi/first/datalog/StringArrayLogEntry.java similarity index 99% rename from wpiutil/src/main/java/edu/wpi/first/util/datalog/StringArrayLogEntry.java rename to datalog/src/main/java/edu/wpi/first/datalog/StringArrayLogEntry.java index 0218502fc04..f93603833c4 100644 --- a/wpiutil/src/main/java/edu/wpi/first/util/datalog/StringArrayLogEntry.java +++ b/datalog/src/main/java/edu/wpi/first/datalog/StringArrayLogEntry.java @@ -2,7 +2,7 @@ // 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. -package edu.wpi.first.util.datalog; +package edu.wpi.first.datalog; import java.util.Arrays; diff --git a/wpiutil/src/main/java/edu/wpi/first/util/datalog/StringLogEntry.java b/datalog/src/main/java/edu/wpi/first/datalog/StringLogEntry.java similarity index 99% rename from wpiutil/src/main/java/edu/wpi/first/util/datalog/StringLogEntry.java rename to datalog/src/main/java/edu/wpi/first/datalog/StringLogEntry.java index 523abd6646b..367c0c89861 100644 --- a/wpiutil/src/main/java/edu/wpi/first/util/datalog/StringLogEntry.java +++ b/datalog/src/main/java/edu/wpi/first/datalog/StringLogEntry.java @@ -2,7 +2,7 @@ // 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. -package edu.wpi.first.util.datalog; +package edu.wpi.first.datalog; /** Log string values. */ public class StringLogEntry extends DataLogEntry { diff --git a/wpiutil/src/main/java/edu/wpi/first/util/datalog/StructArrayLogEntry.java b/datalog/src/main/java/edu/wpi/first/datalog/StructArrayLogEntry.java similarity index 99% rename from wpiutil/src/main/java/edu/wpi/first/util/datalog/StructArrayLogEntry.java rename to datalog/src/main/java/edu/wpi/first/datalog/StructArrayLogEntry.java index 43d69b10f10..1fcd6f05d1d 100644 --- a/wpiutil/src/main/java/edu/wpi/first/util/datalog/StructArrayLogEntry.java +++ b/datalog/src/main/java/edu/wpi/first/datalog/StructArrayLogEntry.java @@ -2,7 +2,7 @@ // 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. -package edu.wpi.first.util.datalog; +package edu.wpi.first.datalog; import edu.wpi.first.util.struct.Struct; import edu.wpi.first.util.struct.StructBuffer; diff --git a/wpiutil/src/main/java/edu/wpi/first/util/datalog/StructLogEntry.java b/datalog/src/main/java/edu/wpi/first/datalog/StructLogEntry.java similarity index 99% rename from wpiutil/src/main/java/edu/wpi/first/util/datalog/StructLogEntry.java rename to datalog/src/main/java/edu/wpi/first/datalog/StructLogEntry.java index c7bdf0a8589..1d0351e7fcf 100644 --- a/wpiutil/src/main/java/edu/wpi/first/util/datalog/StructLogEntry.java +++ b/datalog/src/main/java/edu/wpi/first/datalog/StructLogEntry.java @@ -2,7 +2,7 @@ // 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. -package edu.wpi.first.util.datalog; +package edu.wpi.first.datalog; import edu.wpi.first.util.struct.Struct; import edu.wpi.first.util.struct.StructBuffer; diff --git a/wpiutil/src/main/native/cpp/DataLog.cpp b/datalog/src/main/native/cpp/DataLog.cpp similarity index 99% rename from wpiutil/src/main/native/cpp/DataLog.cpp rename to datalog/src/main/native/cpp/DataLog.cpp index 16e66187f80..2d568274e7c 100644 --- a/wpiutil/src/main/native/cpp/DataLog.cpp +++ b/datalog/src/main/native/cpp/DataLog.cpp @@ -2,8 +2,6 @@ // 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/DataLog.h" - #include #include #include @@ -13,11 +11,12 @@ #include #include -#include "wpi/Endian.h" -#include "wpi/Logger.h" -#include "wpi/SmallString.h" -#include "wpi/print.h" -#include "wpi/timestamp.h" +#include +#include +#include +#include +#include +#include using namespace wpi::log; diff --git a/wpiutil/src/main/native/cpp/DataLogBackgroundWriter.cpp b/datalog/src/main/native/cpp/DataLogBackgroundWriter.cpp similarity index 99% rename from wpiutil/src/main/native/cpp/DataLogBackgroundWriter.cpp rename to datalog/src/main/native/cpp/DataLogBackgroundWriter.cpp index c8028af1289..8ec2bf3b5c3 100644 --- a/wpiutil/src/main/native/cpp/DataLogBackgroundWriter.cpp +++ b/datalog/src/main/native/cpp/DataLogBackgroundWriter.cpp @@ -2,7 +2,7 @@ // 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/DataLogBackgroundWriter.h" +#include #ifndef _WIN32 #include diff --git a/wpiutil/src/main/native/cpp/DataLogReader.cpp b/datalog/src/main/native/cpp/DataLogReader.cpp similarity index 98% rename from wpiutil/src/main/native/cpp/DataLogReader.cpp rename to datalog/src/main/native/cpp/DataLogReader.cpp index 7eb88a6518b..df0a326e3b3 100644 --- a/wpiutil/src/main/native/cpp/DataLogReader.cpp +++ b/datalog/src/main/native/cpp/DataLogReader.cpp @@ -2,13 +2,12 @@ // 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/DataLogReader.h" - #include #include -#include "wpi/DataLog.h" -#include "wpi/Endian.h" +#include +#include +#include using namespace wpi::log; diff --git a/glass/src/lib/native/cpp/support/DataLogReaderThread.cpp b/datalog/src/main/native/cpp/DataLogReaderThread.cpp similarity index 98% rename from glass/src/lib/native/cpp/support/DataLogReaderThread.cpp rename to datalog/src/main/native/cpp/DataLogReaderThread.cpp index c4336f65567..d045a02e678 100644 --- a/glass/src/lib/native/cpp/support/DataLogReaderThread.cpp +++ b/datalog/src/main/native/cpp/DataLogReaderThread.cpp @@ -2,15 +2,14 @@ // 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 "glass/support/DataLogReaderThread.h" - #include #include #include +#include #include -using namespace glass; +using namespace wpi::log; DataLogReaderThread::~DataLogReaderThread() { if (m_thread.joinable()) { diff --git a/wpiutil/src/main/native/cpp/DataLogWriter.cpp b/datalog/src/main/native/cpp/DataLogWriter.cpp similarity index 97% rename from wpiutil/src/main/native/cpp/DataLogWriter.cpp rename to datalog/src/main/native/cpp/DataLogWriter.cpp index b33266f75b5..65301e6b8b0 100644 --- a/wpiutil/src/main/native/cpp/DataLogWriter.cpp +++ b/datalog/src/main/native/cpp/DataLogWriter.cpp @@ -2,13 +2,12 @@ // 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/DataLogWriter.h" - #include #include #include -#include "wpi/raw_ostream.h" +#include +#include using namespace wpi::log; diff --git a/wpiutil/src/main/native/cpp/FileLogger.cpp b/datalog/src/main/native/cpp/FileLogger.cpp similarity index 96% rename from wpiutil/src/main/native/cpp/FileLogger.cpp rename to datalog/src/main/native/cpp/FileLogger.cpp index 70ee9f95ec3..c535b857d9c 100644 --- a/wpiutil/src/main/native/cpp/FileLogger.cpp +++ b/datalog/src/main/native/cpp/FileLogger.cpp @@ -2,8 +2,6 @@ // 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/FileLogger.h" - #ifdef __linux__ #include #include @@ -18,10 +16,10 @@ #include #include +#include +#include -#include "wpi/StringExtras.h" - -namespace wpi { +namespace wpi::log { FileLogger::FileLogger(std::string_view file, std::function callback) #ifdef __linux__ @@ -101,4 +99,4 @@ std::function FileLogger::Buffer( buf.append(leftover.begin(), leftover.end()); }; } -} // namespace wpi +} // namespace wpi::log diff --git a/wpiutil/src/main/native/cpp/jni/DataLogJNI.cpp b/datalog/src/main/native/cpp/jni/DataLogJNI.cpp similarity index 70% rename from wpiutil/src/main/native/cpp/jni/DataLogJNI.cpp rename to datalog/src/main/native/cpp/jni/DataLogJNI.cpp index 782266874d0..272689302b8 100644 --- a/wpiutil/src/main/native/cpp/jni/DataLogJNI.cpp +++ b/datalog/src/main/native/cpp/jni/DataLogJNI.cpp @@ -2,6 +2,8 @@ // 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 "DataLogJNI.h" + #include #include @@ -9,17 +11,47 @@ #include #include +#include +#include +#include +#include +#include -#include "WPIUtilJNI.h" -#include "edu_wpi_first_util_datalog_DataLogJNI.h" -#include "wpi/DataLog.h" -#include "wpi/DataLogBackgroundWriter.h" -#include "wpi/DataLogWriter.h" -#include "wpi/jni_util.h" +#include "edu_wpi_first_datalog_DataLogJNI.h" using namespace wpi::java; using namespace wpi::log; +static bool mockTimeEnabled = false; +static uint64_t mockNow = 0; + +static JException illegalArgEx; +static JException indexOobEx; +static JException ioEx; +static JException nullPointerEx; + +static const JExceptionInit exceptions[] = { + {"java/lang/IllegalArgumentException", &illegalArgEx}, + {"java/lang/IndexOutOfBoundsException", &indexOobEx}, + {"java/io/IOException", &ioEx}, + {"java/lang/NullPointerException", &nullPointerEx}}; + +void wpi::ThrowIllegalArgumentException(JNIEnv* env, std::string_view msg) { + illegalArgEx.Throw(env, msg); +} + +void wpi::ThrowIndexOobException(JNIEnv* env, std::string_view msg) { + indexOobEx.Throw(env, msg); +} + +void wpi::ThrowIOException(JNIEnv* env, std::string_view msg) { + ioEx.Throw(env, msg); +} + +void wpi::ThrowNullPointerException(JNIEnv* env, std::string_view msg) { + nullPointerEx.Throw(env, msg); +} + namespace { class buf_ostream : public wpi::raw_uvector_ostream { private: @@ -34,13 +66,40 @@ class buf_ostream : public wpi::raw_uvector_ostream { extern "C" { +JNIEXPORT jint JNICALL JNI_OnLoad(JavaVM* vm, void* reserved) { + JNIEnv* env; + if (vm->GetEnv(reinterpret_cast(&env), JNI_VERSION_1_6) != JNI_OK) { + return JNI_ERR; + } + + for (auto& c : exceptions) { + *c.cls = JException(env, c.name); + if (!*c.cls) { + return JNI_ERR; + } + } + + return JNI_VERSION_1_6; +} + +JNIEXPORT void JNICALL JNI_OnUnload(JavaVM* vm, void* reserved) { + JNIEnv* env; + if (vm->GetEnv(reinterpret_cast(&env), JNI_VERSION_1_6) != JNI_OK) { + return; + } + + for (auto& c : exceptions) { + c.cls->free(env); + } +} + /* - * Class: edu_wpi_first_util_datalog_DataLogJNI + * Class: edu_wpi_first_datalog_DataLogJNI * Method: bgCreate * Signature: (Ljava/lang/String;Ljava/lang/String;DLjava/lang/String;)J */ JNIEXPORT jlong JNICALL -Java_edu_wpi_first_util_datalog_DataLogJNI_bgCreate +Java_edu_wpi_first_datalog_DataLogJNI_bgCreate (JNIEnv* env, jclass, jstring dir, jstring filename, jdouble period, jstring extraHeader) { @@ -62,12 +121,12 @@ Java_edu_wpi_first_util_datalog_DataLogJNI_bgCreate } /* - * Class: edu_wpi_first_util_datalog_DataLogJNI + * Class: edu_wpi_first_datalog_DataLogJNI * Method: bgSetFilename * Signature: (JLjava/lang/String;)V */ JNIEXPORT void JNICALL -Java_edu_wpi_first_util_datalog_DataLogJNI_bgSetFilename +Java_edu_wpi_first_datalog_DataLogJNI_bgSetFilename (JNIEnv* env, jclass, jlong impl, jstring filename) { if (impl == 0) { @@ -83,12 +142,12 @@ Java_edu_wpi_first_util_datalog_DataLogJNI_bgSetFilename } /* - * Class: edu_wpi_first_util_datalog_DataLogJNI + * Class: edu_wpi_first_datalog_DataLogJNI * Method: fgCreate * Signature: (Ljava/lang/String;Ljava/lang/String;)J */ JNIEXPORT jlong JNICALL -Java_edu_wpi_first_util_datalog_DataLogJNI_fgCreate +Java_edu_wpi_first_datalog_DataLogJNI_fgCreate (JNIEnv* env, jclass, jstring filename, jstring extraHeader) { if (!filename) { @@ -111,12 +170,28 @@ Java_edu_wpi_first_util_datalog_DataLogJNI_fgCreate } /* - * Class: edu_wpi_first_util_datalog_DataLogJNI + * Class: edu_wpi_first_util_WPIUtilJNI + * Method: now + * Signature: ()J + */ +JNIEXPORT jlong JNICALL +Java_edu_wpi_first_util_WPIUtilJNI_now + (JNIEnv*, jclass) +{ + if (mockTimeEnabled) { + return mockNow; + } else { + return wpi::Now(); + } +} + +/* + * Class: edu_wpi_first_datalog_DataLogJNI * Method: fgCreateMemory * Signature: (Ljava/lang/String;)J */ JNIEXPORT jlong JNICALL -Java_edu_wpi_first_util_datalog_DataLogJNI_fgCreateMemory +Java_edu_wpi_first_datalog_DataLogJNI_fgCreateMemory (JNIEnv* env, jclass, jstring extraHeader) { if (!extraHeader) { @@ -129,12 +204,12 @@ Java_edu_wpi_first_util_datalog_DataLogJNI_fgCreateMemory } /* - * Class: edu_wpi_first_util_datalog_DataLogJNI + * Class: edu_wpi_first_datalog_DataLogJNI * Method: flush * Signature: (J)V */ JNIEXPORT void JNICALL -Java_edu_wpi_first_util_datalog_DataLogJNI_flush +Java_edu_wpi_first_datalog_DataLogJNI_flush (JNIEnv* env, jclass, jlong impl) { if (impl == 0) { @@ -145,12 +220,12 @@ Java_edu_wpi_first_util_datalog_DataLogJNI_flush } /* - * Class: edu_wpi_first_util_datalog_DataLogJNI + * Class: edu_wpi_first_datalog_DataLogJNI * Method: copyWriteBuffer * Signature: (J[BI)I */ JNIEXPORT jint JNICALL -Java_edu_wpi_first_util_datalog_DataLogJNI_copyWriteBuffer +Java_edu_wpi_first_datalog_DataLogJNI_copyWriteBuffer (JNIEnv* env, jclass, jlong impl, jbyteArray buf, jint start) { if (impl == 0) { @@ -172,12 +247,12 @@ Java_edu_wpi_first_util_datalog_DataLogJNI_copyWriteBuffer } /* - * Class: edu_wpi_first_util_datalog_DataLogJNI + * Class: edu_wpi_first_datalog_DataLogJNI * Method: pause * Signature: (J)V */ JNIEXPORT void JNICALL -Java_edu_wpi_first_util_datalog_DataLogJNI_pause +Java_edu_wpi_first_datalog_DataLogJNI_pause (JNIEnv* env, jclass, jlong impl) { if (impl == 0) { @@ -188,12 +263,12 @@ Java_edu_wpi_first_util_datalog_DataLogJNI_pause } /* - * Class: edu_wpi_first_util_datalog_DataLogJNI + * Class: edu_wpi_first_datalog_DataLogJNI * Method: resume * Signature: (J)V */ JNIEXPORT void JNICALL -Java_edu_wpi_first_util_datalog_DataLogJNI_resume +Java_edu_wpi_first_datalog_DataLogJNI_resume (JNIEnv* env, jclass, jlong impl) { if (impl == 0) { @@ -204,12 +279,12 @@ Java_edu_wpi_first_util_datalog_DataLogJNI_resume } /* - * Class: edu_wpi_first_util_datalog_DataLogJNI + * Class: edu_wpi_first_datalog_DataLogJNI * Method: stop * Signature: (J)V */ JNIEXPORT void JNICALL -Java_edu_wpi_first_util_datalog_DataLogJNI_stop +Java_edu_wpi_first_datalog_DataLogJNI_stop (JNIEnv* env, jclass, jlong impl) { if (impl == 0) { @@ -220,12 +295,12 @@ Java_edu_wpi_first_util_datalog_DataLogJNI_stop } /* - * Class: edu_wpi_first_util_datalog_DataLogJNI + * Class: edu_wpi_first_datalog_DataLogJNI * Method: addSchema * Signature: (JLjava/lang/String;Ljava/lang/String;[BJ)V */ JNIEXPORT void JNICALL -Java_edu_wpi_first_util_datalog_DataLogJNI_addSchema +Java_edu_wpi_first_datalog_DataLogJNI_addSchema (JNIEnv* env, jclass, jlong impl, jstring name, jstring type, jbyteArray schema, jlong timestamp) { @@ -239,12 +314,12 @@ Java_edu_wpi_first_util_datalog_DataLogJNI_addSchema } /* - * Class: edu_wpi_first_util_datalog_DataLogJNI + * Class: edu_wpi_first_datalog_DataLogJNI * Method: addSchemaString * Signature: (JLjava/lang/String;Ljava/lang/String;Ljava/lang/String;J)V */ JNIEXPORT void JNICALL -Java_edu_wpi_first_util_datalog_DataLogJNI_addSchemaString +Java_edu_wpi_first_datalog_DataLogJNI_addSchemaString (JNIEnv* env, jclass, jlong impl, jstring name, jstring type, jstring schema, jlong timestamp) { @@ -261,12 +336,12 @@ Java_edu_wpi_first_util_datalog_DataLogJNI_addSchemaString } /* - * Class: edu_wpi_first_util_datalog_DataLogJNI + * Class: edu_wpi_first_datalog_DataLogJNI * Method: start * Signature: (JLjava/lang/String;Ljava/lang/String;Ljava/lang/String;J)I */ JNIEXPORT jint JNICALL -Java_edu_wpi_first_util_datalog_DataLogJNI_start +Java_edu_wpi_first_datalog_DataLogJNI_start (JNIEnv* env, jclass, jlong impl, jstring name, jstring type, jstring metadata, jlong timestamp) { @@ -280,12 +355,12 @@ Java_edu_wpi_first_util_datalog_DataLogJNI_start } /* - * Class: edu_wpi_first_util_datalog_DataLogJNI + * Class: edu_wpi_first_datalog_DataLogJNI * Method: finish * Signature: (JIJ)V */ JNIEXPORT void JNICALL -Java_edu_wpi_first_util_datalog_DataLogJNI_finish +Java_edu_wpi_first_datalog_DataLogJNI_finish (JNIEnv* env, jclass, jlong impl, jint entry, jlong timestamp) { if (impl == 0) { @@ -296,12 +371,12 @@ Java_edu_wpi_first_util_datalog_DataLogJNI_finish } /* - * Class: edu_wpi_first_util_datalog_DataLogJNI + * Class: edu_wpi_first_datalog_DataLogJNI * Method: setMetadata * Signature: (JILjava/lang/String;J)V */ JNIEXPORT void JNICALL -Java_edu_wpi_first_util_datalog_DataLogJNI_setMetadata +Java_edu_wpi_first_datalog_DataLogJNI_setMetadata (JNIEnv* env, jclass, jlong impl, jint entry, jstring metadata, jlong timestamp) { @@ -314,24 +389,24 @@ Java_edu_wpi_first_util_datalog_DataLogJNI_setMetadata } /* - * Class: edu_wpi_first_util_datalog_DataLogJNI + * Class: edu_wpi_first_datalog_DataLogJNI * Method: close * Signature: (J)V */ JNIEXPORT void JNICALL -Java_edu_wpi_first_util_datalog_DataLogJNI_close +Java_edu_wpi_first_datalog_DataLogJNI_close (JNIEnv*, jclass, jlong impl) { delete reinterpret_cast(impl); } /* - * Class: edu_wpi_first_util_datalog_DataLogJNI + * Class: edu_wpi_first_datalog_DataLogJNI * Method: appendRaw * Signature: (JI[BIIJ)V */ JNIEXPORT void JNICALL -Java_edu_wpi_first_util_datalog_DataLogJNI_appendRaw +Java_edu_wpi_first_datalog_DataLogJNI_appendRaw (JNIEnv* env, jclass, jlong impl, jint entry, jbyteArray value, jint start, jint length, jlong timestamp) { @@ -362,12 +437,12 @@ Java_edu_wpi_first_util_datalog_DataLogJNI_appendRaw } /* - * Class: edu_wpi_first_util_datalog_DataLogJNI + * Class: edu_wpi_first_datalog_DataLogJNI * Method: appendRawBuffer * Signature: (JILjava/lang/Object;IIJ)V */ JNIEXPORT void JNICALL -Java_edu_wpi_first_util_datalog_DataLogJNI_appendRawBuffer +Java_edu_wpi_first_datalog_DataLogJNI_appendRawBuffer (JNIEnv* env, jclass, jlong impl, jint entry, jobject value, jint start, jint length, jlong timestamp) { @@ -398,12 +473,12 @@ Java_edu_wpi_first_util_datalog_DataLogJNI_appendRawBuffer } /* - * Class: edu_wpi_first_util_datalog_DataLogJNI + * Class: edu_wpi_first_datalog_DataLogJNI * Method: appendBoolean * Signature: (JIZJ)V */ JNIEXPORT void JNICALL -Java_edu_wpi_first_util_datalog_DataLogJNI_appendBoolean +Java_edu_wpi_first_datalog_DataLogJNI_appendBoolean (JNIEnv* env, jclass, jlong impl, jint entry, jboolean value, jlong timestamp) { if (impl == 0) { @@ -414,12 +489,12 @@ Java_edu_wpi_first_util_datalog_DataLogJNI_appendBoolean } /* - * Class: edu_wpi_first_util_datalog_DataLogJNI + * Class: edu_wpi_first_datalog_DataLogJNI * Method: appendInteger * Signature: (JIJJ)V */ JNIEXPORT void JNICALL -Java_edu_wpi_first_util_datalog_DataLogJNI_appendInteger +Java_edu_wpi_first_datalog_DataLogJNI_appendInteger (JNIEnv* env, jclass, jlong impl, jint entry, jlong value, jlong timestamp) { if (impl == 0) { @@ -430,12 +505,12 @@ Java_edu_wpi_first_util_datalog_DataLogJNI_appendInteger } /* - * Class: edu_wpi_first_util_datalog_DataLogJNI + * Class: edu_wpi_first_datalog_DataLogJNI * Method: appendFloat * Signature: (JIFJ)V */ JNIEXPORT void JNICALL -Java_edu_wpi_first_util_datalog_DataLogJNI_appendFloat +Java_edu_wpi_first_datalog_DataLogJNI_appendFloat (JNIEnv* env, jclass, jlong impl, jint entry, jfloat value, jlong timestamp) { if (impl == 0) { @@ -446,12 +521,12 @@ Java_edu_wpi_first_util_datalog_DataLogJNI_appendFloat } /* - * Class: edu_wpi_first_util_datalog_DataLogJNI + * Class: edu_wpi_first_datalog_DataLogJNI * Method: appendDouble * Signature: (JIDJ)V */ JNIEXPORT void JNICALL -Java_edu_wpi_first_util_datalog_DataLogJNI_appendDouble +Java_edu_wpi_first_datalog_DataLogJNI_appendDouble (JNIEnv* env, jclass, jlong impl, jint entry, jdouble value, jlong timestamp) { if (impl == 0) { @@ -462,12 +537,12 @@ Java_edu_wpi_first_util_datalog_DataLogJNI_appendDouble } /* - * Class: edu_wpi_first_util_datalog_DataLogJNI + * Class: edu_wpi_first_datalog_DataLogJNI * Method: appendString * Signature: (JILjava/lang/String;J)V */ JNIEXPORT void JNICALL -Java_edu_wpi_first_util_datalog_DataLogJNI_appendString +Java_edu_wpi_first_datalog_DataLogJNI_appendString (JNIEnv* env, jclass, jlong impl, jint entry, jstring value, jlong timestamp) { if (impl == 0) { @@ -479,12 +554,12 @@ Java_edu_wpi_first_util_datalog_DataLogJNI_appendString } /* - * Class: edu_wpi_first_util_datalog_DataLogJNI + * Class: edu_wpi_first_datalog_DataLogJNI * Method: appendBooleanArray * Signature: (JI[ZJ)V */ JNIEXPORT void JNICALL -Java_edu_wpi_first_util_datalog_DataLogJNI_appendBooleanArray +Java_edu_wpi_first_datalog_DataLogJNI_appendBooleanArray (JNIEnv* env, jclass, jlong impl, jint entry, jbooleanArray value, jlong timestamp) { @@ -501,12 +576,12 @@ Java_edu_wpi_first_util_datalog_DataLogJNI_appendBooleanArray } /* - * Class: edu_wpi_first_util_datalog_DataLogJNI + * Class: edu_wpi_first_datalog_DataLogJNI * Method: appendIntegerArray * Signature: (JI[JJ)V */ JNIEXPORT void JNICALL -Java_edu_wpi_first_util_datalog_DataLogJNI_appendIntegerArray +Java_edu_wpi_first_datalog_DataLogJNI_appendIntegerArray (JNIEnv* env, jclass, jlong impl, jint entry, jlongArray value, jlong timestamp) { @@ -534,12 +609,12 @@ Java_edu_wpi_first_util_datalog_DataLogJNI_appendIntegerArray } /* - * Class: edu_wpi_first_util_datalog_DataLogJNI + * Class: edu_wpi_first_datalog_DataLogJNI * Method: appendFloatArray * Signature: (JI[FJ)V */ JNIEXPORT void JNICALL -Java_edu_wpi_first_util_datalog_DataLogJNI_appendFloatArray +Java_edu_wpi_first_datalog_DataLogJNI_appendFloatArray (JNIEnv* env, jclass, jlong impl, jint entry, jfloatArray value, jlong timestamp) { @@ -556,12 +631,12 @@ Java_edu_wpi_first_util_datalog_DataLogJNI_appendFloatArray } /* - * Class: edu_wpi_first_util_datalog_DataLogJNI + * Class: edu_wpi_first_datalog_DataLogJNI * Method: appendDoubleArray * Signature: (JI[DJ)V */ JNIEXPORT void JNICALL -Java_edu_wpi_first_util_datalog_DataLogJNI_appendDoubleArray +Java_edu_wpi_first_datalog_DataLogJNI_appendDoubleArray (JNIEnv* env, jclass, jlong impl, jint entry, jdoubleArray value, jlong timestamp) { @@ -578,12 +653,12 @@ Java_edu_wpi_first_util_datalog_DataLogJNI_appendDoubleArray } /* - * Class: edu_wpi_first_util_datalog_DataLogJNI + * Class: edu_wpi_first_datalog_DataLogJNI * Method: appendStringArray * Signature: (JI[Ljava/lang/Object;J)V */ JNIEXPORT void JNICALL -Java_edu_wpi_first_util_datalog_DataLogJNI_appendStringArray +Java_edu_wpi_first_datalog_DataLogJNI_appendStringArray (JNIEnv* env, jclass, jlong impl, jint entry, jobjectArray value, jlong timestamp) { @@ -610,5 +685,41 @@ Java_edu_wpi_first_util_datalog_DataLogJNI_appendStringArray } reinterpret_cast(impl)->AppendStringArray(entry, arr, timestamp); } +/* + * Class: edu_wpi_first_datalog_DataLogJNI + * Method: createFileLogger + * Signature: (Ljava/lang/String;JLjava/lang/String;)J + */ +JNIEXPORT jlong JNICALL +Java_edu_wpi_first_datalog_DataLogJNI_createFileLogger + (JNIEnv* env, jclass, jstring file, jlong log, jstring key) +{ + if (!file) { + wpi::ThrowNullPointerException(env, "file is null"); + return 0; + } + auto* f = reinterpret_cast(log); + if (!f) { + wpi::ThrowNullPointerException(env, "log is null"); + return 0; + } + if (!key) { + wpi::ThrowNullPointerException(env, "key is null"); + return 0; + } + return reinterpret_cast(new wpi::log::FileLogger{ + JStringRef{env, file}, *f, JStringRef{env, key}}); +} +/* + * Class: edu_wpi_first_datalog_DataLogJNI + * Method: freeFileLogger + * Signature: (J)V + */ +JNIEXPORT void JNICALL +Java_edu_wpi_first_datalog_DataLogJNI_freeFileLogger + (JNIEnv* env, jclass, jlong fileTail) +{ + delete reinterpret_cast(fileTail); +} } // extern "C" diff --git a/datalog/src/main/native/cpp/jni/DataLogJNI.h b/datalog/src/main/native/cpp/jni/DataLogJNI.h new file mode 100644 index 00000000000..4d08fdbf8bf --- /dev/null +++ b/datalog/src/main/native/cpp/jni/DataLogJNI.h @@ -0,0 +1,18 @@ +// Copyright (c) FIRST and other WPILib contributors. +// 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. + +#pragma once + +#include + +#include + +namespace wpi { + +void ThrowIllegalArgumentException(JNIEnv* env, std::string_view msg); +void ThrowIndexOobException(JNIEnv* env, std::string_view msg); +void ThrowIOException(JNIEnv* env, std::string_view msg); +void ThrowNullPointerException(JNIEnv* env, std::string_view msg); + +} // namespace wpi diff --git a/wpiutil/src/main/native/include/wpi/DataLog.h b/datalog/src/main/native/include/wpi/datalog/DataLog.h similarity index 99% rename from wpiutil/src/main/native/include/wpi/DataLog.h rename to datalog/src/main/native/include/wpi/datalog/DataLog.h index 50c3aed8f13..86db41d7e2a 100644 --- a/wpiutil/src/main/native/include/wpi/DataLog.h +++ b/datalog/src/main/native/include/wpi/datalog/DataLog.h @@ -19,15 +19,15 @@ #include #include -#include "wpi/DataLog_c.h" -#include "wpi/DenseMap.h" -#include "wpi/SmallVector.h" -#include "wpi/StringMap.h" -#include "wpi/mutex.h" -#include "wpi/protobuf/Protobuf.h" -#include "wpi/string.h" -#include "wpi/struct/Struct.h" -#include "wpi/timestamp.h" +#include +#include +#include +#include +#include +#include +#include +#include +#include namespace wpi { class Logger; diff --git a/wpiutil/src/main/native/include/wpi/DataLogBackgroundWriter.h b/datalog/src/main/native/include/wpi/datalog/DataLogBackgroundWriter.h similarity index 98% rename from wpiutil/src/main/native/include/wpi/DataLogBackgroundWriter.h rename to datalog/src/main/native/include/wpi/datalog/DataLogBackgroundWriter.h index 7926299ca13..c1662bf9fde 100644 --- a/wpiutil/src/main/native/include/wpi/DataLogBackgroundWriter.h +++ b/datalog/src/main/native/include/wpi/datalog/DataLogBackgroundWriter.h @@ -12,9 +12,9 @@ #include #include -#include "wpi/DataLog.h" -#include "wpi/condition_variable.h" -#include "wpi/mutex.h" +#include +#include +#include namespace wpi { class Logger; diff --git a/wpiutil/src/main/native/include/wpi/DataLogReader.h b/datalog/src/main/native/include/wpi/datalog/DataLogReader.h similarity index 99% rename from wpiutil/src/main/native/include/wpi/DataLogReader.h rename to datalog/src/main/native/include/wpi/datalog/DataLogReader.h index cb9a8cb8ffb..2a22725c7c4 100644 --- a/wpiutil/src/main/native/include/wpi/DataLogReader.h +++ b/datalog/src/main/native/include/wpi/datalog/DataLogReader.h @@ -12,7 +12,7 @@ #include #include -#include "wpi/MemoryBuffer.h" +#include namespace wpi::log { diff --git a/glass/src/lib/native/include/glass/support/DataLogReaderThread.h b/datalog/src/main/native/include/wpi/datalog/DataLogReaderThread.h similarity index 97% rename from glass/src/lib/native/include/glass/support/DataLogReaderThread.h rename to datalog/src/main/native/include/wpi/datalog/DataLogReaderThread.h index 2cfb89e39be..51eb837302e 100644 --- a/glass/src/lib/native/include/glass/support/DataLogReaderThread.h +++ b/datalog/src/main/native/include/wpi/datalog/DataLogReaderThread.h @@ -13,9 +13,9 @@ #include #include -#include #include #include +#include #include #include @@ -23,7 +23,7 @@ #include #endif -namespace glass { +namespace wpi::log { class DataLogReaderRange { public: @@ -105,4 +105,4 @@ class DataLogReaderThread { std::thread m_thread; }; -} // namespace glass +} // namespace wpi::log diff --git a/wpiutil/src/main/native/include/wpi/DataLogWriter.h b/datalog/src/main/native/include/wpi/datalog/DataLogWriter.h similarity index 98% rename from wpiutil/src/main/native/include/wpi/DataLogWriter.h rename to datalog/src/main/native/include/wpi/datalog/DataLogWriter.h index f69c7b5b259..189584c6cac 100644 --- a/wpiutil/src/main/native/include/wpi/DataLogWriter.h +++ b/datalog/src/main/native/include/wpi/datalog/DataLogWriter.h @@ -8,7 +8,7 @@ #include #include -#include "wpi/DataLog.h" +#include namespace wpi { class raw_ostream; diff --git a/wpiutil/src/main/native/include/wpi/DataLog_c.h b/datalog/src/main/native/include/wpi/datalog/DataLog_c.h similarity index 99% rename from wpiutil/src/main/native/include/wpi/DataLog_c.h rename to datalog/src/main/native/include/wpi/datalog/DataLog_c.h index 654181a843a..21e66c6c43f 100644 --- a/wpiutil/src/main/native/include/wpi/DataLog_c.h +++ b/datalog/src/main/native/include/wpi/datalog/DataLog_c.h @@ -7,6 +7,7 @@ #include // NOLINT #include + #include #ifdef __cplusplus diff --git a/wpiutil/src/main/native/include/wpi/FileLogger.h b/datalog/src/main/native/include/wpi/datalog/FileLogger.h similarity index 95% rename from wpiutil/src/main/native/include/wpi/FileLogger.h rename to datalog/src/main/native/include/wpi/datalog/FileLogger.h index c04cf5b7edc..38dbab4c99e 100644 --- a/wpiutil/src/main/native/include/wpi/FileLogger.h +++ b/datalog/src/main/native/include/wpi/datalog/FileLogger.h @@ -8,9 +8,9 @@ #include #include -#include "wpi/DataLog.h" +#include -namespace wpi { +namespace wpi::log { /** * A class version of `tail -f`, otherwise known as `tail -f` at home. Watches * a file and puts the data somewhere else. Only works on Linux-based platforms. @@ -58,4 +58,4 @@ class FileLogger { std::thread m_thread; #endif }; -} // namespace wpi +} // namespace wpi::log diff --git a/wpiutil/src/printlog/java/printlog/PrintLog.java b/datalog/src/printlog/java/printlog/PrintLog.java similarity index 98% rename from wpiutil/src/printlog/java/printlog/PrintLog.java rename to datalog/src/printlog/java/printlog/PrintLog.java index c0074df0b7c..739e5ec187b 100644 --- a/wpiutil/src/printlog/java/printlog/PrintLog.java +++ b/datalog/src/printlog/java/printlog/PrintLog.java @@ -4,8 +4,8 @@ package printlog; -import edu.wpi.first.util.datalog.DataLogReader; -import edu.wpi.first.util.datalog.DataLogRecord; +import edu.wpi.first.datalog.DataLogReader; +import edu.wpi.first.datalog.DataLogRecord; import java.io.IOException; import java.time.LocalDateTime; import java.time.ZoneOffset; diff --git a/wpiutil/src/test/java/edu/wpi/first/util/datalog/DataLogTest.java b/datalog/src/test/java/edu/wpi/first/datalog/DataLogTest.java similarity index 99% rename from wpiutil/src/test/java/edu/wpi/first/util/datalog/DataLogTest.java rename to datalog/src/test/java/edu/wpi/first/datalog/DataLogTest.java index b6d140bfbd7..217bb7d4094 100644 --- a/wpiutil/src/test/java/edu/wpi/first/util/datalog/DataLogTest.java +++ b/datalog/src/test/java/edu/wpi/first/datalog/DataLogTest.java @@ -2,7 +2,7 @@ // 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. -package edu.wpi.first.util.datalog; +package edu.wpi.first.datalog; import static org.junit.jupiter.api.Assertions.assertArrayEquals; import static org.junit.jupiter.api.Assertions.assertEquals; diff --git a/wpiutil/src/test/native/cpp/DataLogTest.cpp b/datalog/src/test/native/cpp/DataLogTest.cpp similarity index 99% rename from wpiutil/src/test/native/cpp/DataLogTest.cpp rename to datalog/src/test/native/cpp/DataLogTest.cpp index 149d3a36b78..8c2aecc10f7 100644 --- a/wpiutil/src/test/native/cpp/DataLogTest.cpp +++ b/datalog/src/test/native/cpp/DataLogTest.cpp @@ -8,10 +8,9 @@ #include #include - -#include "wpi/DataLogWriter.h" -#include "wpi/Logger.h" -#include "wpi/raw_ostream.h" +#include +#include +#include namespace { struct ThingA { diff --git a/wpiutil/src/test/native/cpp/FileLoggerTest.cpp b/datalog/src/test/native/cpp/FileLoggerTest.cpp similarity index 85% rename from wpiutil/src/test/native/cpp/FileLoggerTest.cpp rename to datalog/src/test/native/cpp/FileLoggerTest.cpp index f402ef583dc..b0db3a9c4af 100644 --- a/wpiutil/src/test/native/cpp/FileLoggerTest.cpp +++ b/datalog/src/test/native/cpp/FileLoggerTest.cpp @@ -7,12 +7,11 @@ #include #include - -#include "wpi/FileLogger.h" +#include TEST(FileLoggerTest, BufferSingleLine) { std::vector buf; - auto func = wpi::FileLogger::Buffer( + auto func = wpi::log::FileLogger::Buffer( [&buf](std::string_view line) { buf.emplace_back(line); }); func("qwertyuiop\n"); EXPECT_EQ("qwertyuiop", buf[0]); @@ -20,7 +19,7 @@ TEST(FileLoggerTest, BufferSingleLine) { TEST(FileLoggerTest, BufferMultiLine) { std::vector buf; - auto func = wpi::FileLogger::Buffer( + auto func = wpi::log::FileLogger::Buffer( [&buf](std::string_view line) { buf.emplace_back(line); }); func("line 1\nline 2\nline 3\n"); EXPECT_EQ("line 1\nline 2\nline 3", buf[0]); @@ -28,7 +27,7 @@ TEST(FileLoggerTest, BufferMultiLine) { TEST(FileLoggerTest, BufferPartials) { std::vector buf; - auto func = wpi::FileLogger::Buffer( + auto func = wpi::log::FileLogger::Buffer( [&buf](std::string_view line) { buf.emplace_back(line); }); func("part 1"); func("part 2\npart 3"); @@ -39,7 +38,7 @@ TEST(FileLoggerTest, BufferPartials) { TEST(FileLoggerTest, BufferMultiplePartials) { std::vector buf; - auto func = wpi::FileLogger::Buffer( + auto func = wpi::log::FileLogger::Buffer( [&buf](std::string_view line) { buf.emplace_back(line); }); func("part 1"); func("part 2"); @@ -49,7 +48,7 @@ TEST(FileLoggerTest, BufferMultiplePartials) { } TEST(FileLoggerTest, BufferMultipleMultiLinePartials) { std::vector buf; - auto func = wpi::FileLogger::Buffer( + auto func = wpi::log::FileLogger::Buffer( [&buf](std::string_view line) { buf.emplace_back(line); }); func("part 1"); func("part 2\npart 3"); diff --git a/datalog/src/test/native/cpp/main.cpp b/datalog/src/test/native/cpp/main.cpp new file mode 100644 index 00000000000..e993c1f14ef --- /dev/null +++ b/datalog/src/test/native/cpp/main.cpp @@ -0,0 +1,11 @@ +// Copyright (c) FIRST and other WPILib contributors. +// 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 + +int main(int argc, char** argv) { + ::testing::InitGoogleTest(&argc, argv); + int ret = RUN_ALL_TESTS(); + return ret; +} diff --git a/datalogtool/CMakeLists.txt b/datalogtool/CMakeLists.txt index ba9475d2eb7..0c74557c57a 100644 --- a/datalogtool/CMakeLists.txt +++ b/datalogtool/CMakeLists.txt @@ -25,7 +25,7 @@ add_executable( ${APP_ICON_MACOSX} ) wpilib_link_macos_gui(datalogtool) -target_link_libraries(datalogtool libglass ssh) +target_link_libraries(datalogtool libglass ssh datalog wpiutil) if(WIN32) set_target_properties(datalogtool PROPERTIES WIN32_EXECUTABLE YES) diff --git a/datalogtool/build.gradle b/datalogtool/build.gradle index 418dd60294a..1cea1ef5ea7 100644 --- a/datalogtool/build.gradle +++ b/datalogtool/build.gradle @@ -99,9 +99,10 @@ model { } it.cppCompiler.define("LIBSSH_STATIC") lib project: ':glass', library: 'glass', linkage: 'static' - lib project: ':wpiutil', library: 'wpiutil', linkage: 'static' lib project: ':wpigui', library: 'wpigui', linkage: 'static' + lib project: ':datalog', library: 'datalog', linkage: 'static' lib project: ':thirdparty:imgui_suite', library: 'imguiSuite', linkage: 'static' + lib project: ':wpiutil', library: 'wpiutil', linkage: 'static' nativeUtils.useRequiredLibrary(it, 'libssh') if (it.targetPlatform.operatingSystem.isWindows()) { it.linker.args << 'Gdi32.lib' << 'Shell32.lib' << 'd3d11.lib' << 'd3dcompiler.lib' diff --git a/datalogtool/src/main/native/cpp/Exporter.cpp b/datalogtool/src/main/native/cpp/Exporter.cpp index 149b6718309..2cf399b71c2 100644 --- a/datalogtool/src/main/native/cpp/Exporter.cpp +++ b/datalogtool/src/main/native/cpp/Exporter.cpp @@ -20,7 +20,6 @@ #include #include #include -#include #include #include #include @@ -30,6 +29,7 @@ #include #include #include +#include #include #include #include @@ -40,7 +40,7 @@ namespace { struct InputFile { - explicit InputFile(std::unique_ptr datalog); + explicit InputFile(std::unique_ptr datalog); InputFile(std::string_view filename, std::string_view status) : filename{filename}, @@ -51,7 +51,7 @@ struct InputFile { std::string filename; std::string stem; - std::unique_ptr datalog; + std::unique_ptr datalog; std::string status; bool highlight = false; }; @@ -140,7 +140,7 @@ static void RebuildEntryTree() { } } -InputFile::InputFile(std::unique_ptr datalog_) +InputFile::InputFile(std::unique_ptr datalog_) : filename{datalog_->GetBufferIdentifier()}, stem{fs::path{filename}.stem().string()}, datalog{std::move(datalog_)} { @@ -196,7 +196,7 @@ static std::unique_ptr LoadDataLog(std::string_view filename) { } return std::make_unique( - std::make_unique(std::move(reader))); + std::make_unique(std::move(reader))); } void DisplayInputFiles() { diff --git a/epilogue-runtime/BUILD.bazel b/epilogue-runtime/BUILD.bazel index 6e02a5dfcb8..0fe3a4f6dff 100644 --- a/epilogue-runtime/BUILD.bazel +++ b/epilogue-runtime/BUILD.bazel @@ -6,6 +6,7 @@ java_library( srcs = glob(["src/main/java/**/*.java"]), visibility = ["//visibility:public"], deps = [ + "//datalog:datalog-java", "//ntcore:networktables-java", "//wpiunits", "//wpiutil:wpiutil-java", diff --git a/epilogue-runtime/build.gradle b/epilogue-runtime/build.gradle index fb96095a0a5..ffcf6c096ff 100644 --- a/epilogue-runtime/build.gradle +++ b/epilogue-runtime/build.gradle @@ -13,4 +13,5 @@ dependencies { api(project(':ntcore')) api(project(':wpiutil')) api(project(':wpiunits')) + api(project(':datalog')) } diff --git a/epilogue-runtime/src/main/java/edu/wpi/first/epilogue/logging/FileBackend.java b/epilogue-runtime/src/main/java/edu/wpi/first/epilogue/logging/FileBackend.java index 2b5b6b2071b..b9fbbb95dcb 100644 --- a/epilogue-runtime/src/main/java/edu/wpi/first/epilogue/logging/FileBackend.java +++ b/epilogue-runtime/src/main/java/edu/wpi/first/epilogue/logging/FileBackend.java @@ -6,21 +6,21 @@ import static edu.wpi.first.util.ErrorMessages.requireNonNullParam; -import edu.wpi.first.util.datalog.BooleanArrayLogEntry; -import edu.wpi.first.util.datalog.BooleanLogEntry; -import edu.wpi.first.util.datalog.DataLog; -import edu.wpi.first.util.datalog.DataLogEntry; -import edu.wpi.first.util.datalog.DoubleArrayLogEntry; -import edu.wpi.first.util.datalog.DoubleLogEntry; -import edu.wpi.first.util.datalog.FloatArrayLogEntry; -import edu.wpi.first.util.datalog.FloatLogEntry; -import edu.wpi.first.util.datalog.IntegerArrayLogEntry; -import edu.wpi.first.util.datalog.IntegerLogEntry; -import edu.wpi.first.util.datalog.RawLogEntry; -import edu.wpi.first.util.datalog.StringArrayLogEntry; -import edu.wpi.first.util.datalog.StringLogEntry; -import edu.wpi.first.util.datalog.StructArrayLogEntry; -import edu.wpi.first.util.datalog.StructLogEntry; +import edu.wpi.first.datalog.BooleanArrayLogEntry; +import edu.wpi.first.datalog.BooleanLogEntry; +import edu.wpi.first.datalog.DataLog; +import edu.wpi.first.datalog.DataLogEntry; +import edu.wpi.first.datalog.DoubleArrayLogEntry; +import edu.wpi.first.datalog.DoubleLogEntry; +import edu.wpi.first.datalog.FloatArrayLogEntry; +import edu.wpi.first.datalog.FloatLogEntry; +import edu.wpi.first.datalog.IntegerArrayLogEntry; +import edu.wpi.first.datalog.IntegerLogEntry; +import edu.wpi.first.datalog.RawLogEntry; +import edu.wpi.first.datalog.StringArrayLogEntry; +import edu.wpi.first.datalog.StringLogEntry; +import edu.wpi.first.datalog.StructArrayLogEntry; +import edu.wpi.first.datalog.StructLogEntry; import edu.wpi.first.util.struct.Struct; import java.util.HashMap; import java.util.Map; diff --git a/glass/build.gradle b/glass/build.gradle index 354036dec75..4ef5686b495 100644 --- a/glass/build.gradle +++ b/glass/build.gradle @@ -93,11 +93,12 @@ model { it.buildable = false return } - lib project: ':wpiutil', library: 'wpiutil', linkage: 'shared' + lib project: ':wpimath', library: 'wpimath', linkage: 'shared' lib project: ':wpigui', library: 'wpigui', linkage: 'static' lib project: ':fieldImages', library: 'fieldImages', linkage: 'shared' lib project: ':thirdparty:imgui_suite', library: 'imguiSuite', linkage: 'static' + lib project: ':wpiutil', library: 'wpiutil', linkage: 'shared' } appendDebugPathToBinaries(binaries) } @@ -123,11 +124,11 @@ model { lib library: nativeName, linkage: 'static' project(':ntcore').addNtcoreDependency(it, 'shared') lib project: ':wpinet', library: 'wpinet', linkage: 'shared' - lib project: ':wpiutil', library: 'wpiutil', linkage: 'shared' lib project: ':wpimath', library: 'wpimath', linkage: 'shared' lib project: ':wpigui', library: 'wpigui', linkage: 'static' lib project: ':fieldImages', library: 'fieldImages', linkage: 'shared' lib project: ':thirdparty:imgui_suite', library: 'imguiSuite', linkage: 'static' + lib project: ':wpiutil', library: 'wpiutil', linkage: 'shared' } appendDebugPathToBinaries(binaries) } @@ -162,12 +163,12 @@ model { lib library: nativeName, linkage: 'static' project(':ntcore').addNtcoreDependency(it, 'static') lib project: ':wpinet', library: 'wpinet', linkage: 'static' - lib project: ':wpiutil', library: 'wpiutil', linkage: 'static' lib project: ':wpimath', library: 'wpimath', linkage: 'static' lib project: ':wpigui', library: 'wpigui', linkage: 'static' lib project: ':fieldImages', library: 'fieldImages', linkage: 'static' nativeUtils.useRequiredLibrary(it, 'opencv_static') lib project: ':thirdparty:imgui_suite', library: 'imguiSuite', linkage: 'static' + lib project: ':wpiutil', library: 'wpiutil', linkage: 'static' if (it.targetPlatform.operatingSystem.isWindows()) { it.linker.args << 'Gdi32.lib' << 'Shell32.lib' << 'd3d11.lib' << 'd3dcompiler.lib' it.linker.args << '/DELAYLOAD:MF.dll' << '/DELAYLOAD:MFReadWrite.dll' << '/DELAYLOAD:MFPlat.dll' << '/delay:nobind' diff --git a/ntcore/BUILD.bazel b/ntcore/BUILD.bazel index 9b020297c59..4147b8ef816 100644 --- a/ntcore/BUILD.bazel +++ b/ntcore/BUILD.bazel @@ -47,6 +47,7 @@ cc_library( visibility = ["//visibility:public"], deps = [ ":generated_cc_headers", + "//datalog:datalog.static", "//wpinet:wpinet.static", "//wpiutil:wpiutil.static", ], @@ -68,6 +69,7 @@ wpilib_jni_java_library( native_libs = [":ntcorejni"], visibility = ["//visibility:public"], deps = [ + "//datalog:datalog-java", "//wpiutil:wpiutil-java", "@maven//:us_hebi_quickbuf_quickbuf_runtime", ], diff --git a/ntcore/CMakeLists.txt b/ntcore/CMakeLists.txt index f108a9133d2..c248d532aaf 100644 --- a/ntcore/CMakeLists.txt +++ b/ntcore/CMakeLists.txt @@ -26,7 +26,7 @@ target_include_directories( ) wpilib_target_warnings(ntcore) target_compile_features(ntcore PUBLIC cxx_std_20) -target_link_libraries(ntcore PUBLIC wpinet wpiutil) +target_link_libraries(ntcore PUBLIC wpinet wpiutil datalog) set_property(TARGET ntcore PROPERTY FOLDER "libraries") @@ -53,7 +53,7 @@ if(WITH_JAVA) add_jar( ntcore_jar ${JAVA_SOURCES} - INCLUDE_JARS wpiutil_jar ${QUICKBUF_JAR} + INCLUDE_JARS wpiutil_jar ${QUICKBUF_JAR} datalog_jar OUTPUT_NAME ntcore OUTPUT_DIR ${WPILIB_BINARY_DIR}/${java_lib_dest} GENERATE_NATIVE_HEADERS ntcore_jni_headers diff --git a/ntcore/build.gradle b/ntcore/build.gradle index 937c2d11b81..e4c3da5673d 100644 --- a/ntcore/build.gradle +++ b/ntcore/build.gradle @@ -1,10 +1,12 @@ ext { addNtcoreDependency = { binary, shared-> binary.lib project: ':ntcore', library: 'ntcore', linkage: shared + binary.lib project: ':datalog', library: 'datalog', linkage: shared } addNtcoreJniDependency = { binary-> binary.lib project: ':ntcore', library: 'ntcoreJNIShared', linkage: 'shared' + binary.lib project: ':datalog', library: 'datalogJNIShared', linkage: 'shared' } nativeName = 'ntcore' @@ -34,9 +36,11 @@ model { if (it.component.name == "${nativeName}JNI") { lib project: ':wpinet', library: 'wpinet', linkage: 'static' lib project: ':wpiutil', library: 'wpiutil', linkage: 'static' + lib project: ':datalog', library: 'datalog', linkage: 'static' } else { lib project: ':wpinet', library: 'wpinet', linkage: 'shared' lib project: ':wpiutil', library: 'wpiutil', linkage: 'shared' + lib project: ':datalog', library: 'datalog', linkage: 'shared' } } } @@ -61,3 +65,7 @@ nativeUtils.exportsConfigs { x64SymbolFilter = symbolFilter } } + +dependencies { + api project(":datalog") +} diff --git a/ntcore/src/generate/main/java/NetworkTableInstance.java.jinja b/ntcore/src/generate/main/java/NetworkTableInstance.java.jinja index 50883074a3d..28f8687cb95 100644 --- a/ntcore/src/generate/main/java/NetworkTableInstance.java.jinja +++ b/ntcore/src/generate/main/java/NetworkTableInstance.java.jinja @@ -6,9 +6,9 @@ package edu.wpi.first.networktables; +import edu.wpi.first.datalog.DataLog; import edu.wpi.first.util.WPIUtilJNI; import edu.wpi.first.util.concurrent.Event; -import edu.wpi.first.util.datalog.DataLog; import edu.wpi.first.util.protobuf.Protobuf; import edu.wpi.first.util.struct.Struct; import java.nio.charset.StandardCharsets; diff --git a/ntcore/src/generate/main/java/NetworkTablesJNI.java.jinja b/ntcore/src/generate/main/java/NetworkTablesJNI.java.jinja index c63515d3e0d..06f69e292fe 100644 --- a/ntcore/src/generate/main/java/NetworkTablesJNI.java.jinja +++ b/ntcore/src/generate/main/java/NetworkTablesJNI.java.jinja @@ -6,8 +6,8 @@ package edu.wpi.first.networktables; +import edu.wpi.first.datalog.DataLog; import edu.wpi.first.util.RuntimeLoader; -import edu.wpi.first.util.datalog.DataLog; import java.io.IOException; import java.nio.ByteBuffer; import java.util.EnumSet; diff --git a/ntcore/src/generated/main/java/edu/wpi/first/networktables/NetworkTableInstance.java b/ntcore/src/generated/main/java/edu/wpi/first/networktables/NetworkTableInstance.java index 5b116148f77..8f31e5d993e 100644 --- a/ntcore/src/generated/main/java/edu/wpi/first/networktables/NetworkTableInstance.java +++ b/ntcore/src/generated/main/java/edu/wpi/first/networktables/NetworkTableInstance.java @@ -6,9 +6,9 @@ package edu.wpi.first.networktables; +import edu.wpi.first.datalog.DataLog; import edu.wpi.first.util.WPIUtilJNI; import edu.wpi.first.util.concurrent.Event; -import edu.wpi.first.util.datalog.DataLog; import edu.wpi.first.util.protobuf.Protobuf; import edu.wpi.first.util.struct.Struct; import java.nio.charset.StandardCharsets; diff --git a/ntcore/src/generated/main/java/edu/wpi/first/networktables/NetworkTablesJNI.java b/ntcore/src/generated/main/java/edu/wpi/first/networktables/NetworkTablesJNI.java index 4fddd9f51f3..4cbcb895c44 100644 --- a/ntcore/src/generated/main/java/edu/wpi/first/networktables/NetworkTablesJNI.java +++ b/ntcore/src/generated/main/java/edu/wpi/first/networktables/NetworkTablesJNI.java @@ -6,8 +6,8 @@ package edu.wpi.first.networktables; +import edu.wpi.first.datalog.DataLog; import edu.wpi.first.util.RuntimeLoader; -import edu.wpi.first.util.datalog.DataLog; import java.io.IOException; import java.nio.ByteBuffer; import java.util.EnumSet; diff --git a/ntcore/src/main/native/cpp/ConnectionList.h b/ntcore/src/main/native/cpp/ConnectionList.h index c46266d5c18..6551ee468c5 100644 --- a/ntcore/src/main/native/cpp/ConnectionList.h +++ b/ntcore/src/main/native/cpp/ConnectionList.h @@ -13,8 +13,8 @@ #include #include -#include #include +#include #include #include "Handle.h" diff --git a/ntcore/src/main/native/cpp/local/LocalDataLogger.cpp b/ntcore/src/main/native/cpp/local/LocalDataLogger.cpp index 121c99ab39b..3ae62f60b18 100644 --- a/ntcore/src/main/native/cpp/local/LocalDataLogger.cpp +++ b/ntcore/src/main/native/cpp/local/LocalDataLogger.cpp @@ -5,8 +5,8 @@ #include "LocalDataLogger.h" #include -#include #include +#include using namespace nt::local; diff --git a/ntcore/src/main/native/cpp/local/LocalDataLoggerEntry.h b/ntcore/src/main/native/cpp/local/LocalDataLoggerEntry.h index 53ff480b19b..0d86ea893c3 100644 --- a/ntcore/src/main/native/cpp/local/LocalDataLoggerEntry.h +++ b/ntcore/src/main/native/cpp/local/LocalDataLoggerEntry.h @@ -9,7 +9,7 @@ #include #include -#include +#include #include "ntcore_c.h" diff --git a/ntcore/src/main/native/cpp/local/LocalStorageImpl.cpp b/ntcore/src/main/native/cpp/local/LocalStorageImpl.cpp index 60a03c1c77c..fd00bc9aa68 100644 --- a/ntcore/src/main/native/cpp/local/LocalStorageImpl.cpp +++ b/ntcore/src/main/native/cpp/local/LocalStorageImpl.cpp @@ -11,9 +11,9 @@ #include #include -#include #include #include +#include #include "IListenerStorage.h" #include "Log.h" diff --git a/ntcoreffi/src/main/native/cpp/DataLogManager.cpp b/ntcoreffi/src/main/native/cpp/DataLogManager.cpp index d758c02a2ac..96377feef2c 100644 --- a/ntcoreffi/src/main/native/cpp/DataLogManager.cpp +++ b/ntcoreffi/src/main/native/cpp/DataLogManager.cpp @@ -13,10 +13,10 @@ #include #include #include -#include -#include #include #include +#include +#include #include #include @@ -202,7 +202,7 @@ struct Thread final : public wpi::SafeThread { NT_DataLogger m_ntEntryLogger = 0; NT_ConnectionDataLogger m_ntConnLogger = 0; bool m_consoleLoggerEnabled = false; - wpi::FileLogger m_consoleLogger; + wpi::log::FileLogger m_consoleLogger; wpi::log::StringLogEntry m_messageLog; }; diff --git a/settings.gradle b/settings.gradle index 45ef87e77d8..8f55ab798e1 100644 --- a/settings.gradle +++ b/settings.gradle @@ -59,6 +59,7 @@ include 'epilogue-runtime' include 'thirdparty:googletest' include 'thirdparty:imgui_suite' include 'wpical' +include 'datalog' buildCache { def cred = { diff --git a/sysid/CMakeLists.txt b/sysid/CMakeLists.txt index 8bcb224d4dc..389f8d06143 100644 --- a/sysid/CMakeLists.txt +++ b/sysid/CMakeLists.txt @@ -25,7 +25,7 @@ endif() wpilib_link_macos_gui(sysid) wpilib_target_warnings(sysid) target_include_directories(sysid PRIVATE src/main/native/include) -target_link_libraries(sysid wpimath libglass) +target_link_libraries(sysid wpimath libglass datalog) if(WIN32) set_target_properties(sysid PROPERTIES WIN32_EXECUTABLE YES) @@ -42,5 +42,5 @@ if(WITH_TESTS) target_compile_options(sysid_test PRIVATE /utf-8) endif() target_include_directories(sysid_test PRIVATE src/main/native/cpp src/main/native/include) - target_link_libraries(sysid_test wpimath libglass googletest) + target_link_libraries(sysid_test wpimath libglass datalog googletest) endif() diff --git a/sysid/build.gradle b/sysid/build.gradle index d5e927b2845..cb0964bfd3d 100644 --- a/sysid/build.gradle +++ b/sysid/build.gradle @@ -98,9 +98,10 @@ model { } lib project: ':glass', library: 'glass', linkage: 'static' lib project: ':wpimath', library: 'wpimath', linkage: 'static' - lib project: ':wpiutil', library: 'wpiutil', linkage: 'static' lib project: ':wpigui', library: 'wpigui', linkage: 'static' + lib project: ':datalog', library: 'datalog', linkage: 'static' lib project: ':thirdparty:imgui_suite', library: 'imguiSuite', linkage: 'static' + lib project: ':wpiutil', library: 'wpiutil', linkage: 'static' if (it.targetPlatform.operatingSystem.isWindows()) { it.linker.args << 'Gdi32.lib' << 'Shell32.lib' << 'd3d11.lib' << 'd3dcompiler.lib' it.linker.args << '/DELAYLOAD:MF.dll' << '/DELAYLOAD:MFReadWrite.dll' << '/DELAYLOAD:MFPlat.dll' << '/delay:nobind' @@ -137,9 +138,10 @@ model { } lib project: ':glass', library: 'glass', linkage: 'static' lib project: ':wpimath', library: 'wpimath', linkage: 'static' - lib project: ':wpiutil', library: 'wpiutil', linkage: 'static' + lib project: ':datalog', library: 'datalog', linkage: 'static' lib project: ':wpigui', library: 'wpigui', linkage: 'static' lib project: ':thirdparty:imgui_suite', library: 'imguiSuite', linkage: 'static' + lib project: ':wpiutil', library: 'wpiutil', linkage: 'static' if (it.targetPlatform.operatingSystem.isWindows()) { it.linker.args << 'Gdi32.lib' << 'Shell32.lib' << 'd3d11.lib' << 'd3dcompiler.lib' it.linker.args << '/DELAYLOAD:MF.dll' << '/DELAYLOAD:MFReadWrite.dll' << '/DELAYLOAD:MFPlat.dll' << '/delay:nobind' diff --git a/sysid/src/main/native/cpp/view/DataSelector.cpp b/sysid/src/main/native/cpp/view/DataSelector.cpp index 3409bf6ee37..17b2ab27e2e 100644 --- a/sysid/src/main/native/cpp/view/DataSelector.cpp +++ b/sysid/src/main/native/cpp/view/DataSelector.cpp @@ -10,11 +10,11 @@ #include #include -#include #include -#include #include #include +#include +#include #include "sysid/Util.h" #include "sysid/analysis/AnalysisType.h" @@ -25,7 +25,7 @@ using namespace sysid; static constexpr const char* kAnalysisTypes[] = {"Elevator", "Arm", "Simple"}; static bool EmitEntryTarget(const char* name, bool isString, - const glass::DataLogReaderEntry** entry) { + const wpi::log::DataLogReaderEntry** entry) { if (*entry) { auto text = fmt::format("{}: {} ({})", name, (*entry)->name, (*entry)->type); @@ -38,8 +38,9 @@ static bool EmitEntryTarget(const char* name, bool isString, if (ImGui::BeginDragDropTarget()) { if (const ImGuiPayload* payload = ImGui::AcceptDragDropPayload( isString ? "DataLogEntryString" : "DataLogEntry")) { - assert(payload->DataSize == sizeof(const glass::DataLogReaderEntry*)); - *entry = *static_cast(payload->Data); + assert(payload->DataSize == sizeof(const wpi::log::DataLogReaderEntry*)); + *entry = + *static_cast(payload->Data); rv = true; } ImGui::EndDragDropTarget(); @@ -179,7 +180,7 @@ void DataSelector::Reset() { } DataSelector::Tests DataSelector::LoadTests( - const glass::DataLogReaderEntry& testStateEntry) { + const wpi::log::DataLogReaderEntry& testStateEntry) { Tests tests; for (auto&& range : testStateEntry.ranges) { std::string_view prevState; @@ -245,7 +246,7 @@ static void AddSamples(std::vector>& samples, } static std::vector> GetData( - const glass::DataLogReaderEntry& entry, double scale) { + const wpi::log::DataLogReaderEntry& entry, double scale) { std::vector> rv; bool isDouble = entry.type == "double"; for (auto&& range : entry.ranges) { diff --git a/sysid/src/main/native/cpp/view/LogLoader.cpp b/sysid/src/main/native/cpp/view/LogLoader.cpp index 8e0fe429b2e..b21bea46158 100644 --- a/sysid/src/main/native/cpp/view/LogLoader.cpp +++ b/sysid/src/main/native/cpp/view/LogLoader.cpp @@ -12,13 +12,13 @@ #include #include -#include #include #include #include #include #include #include +#include #include using namespace sysid; @@ -55,7 +55,7 @@ void LogLoader::Display() { } unload(); m_reader = - std::make_unique(std::move(reader)); + std::make_unique(std::move(reader)); m_entryTree.clear(); } m_opener.reset(); @@ -108,7 +108,7 @@ void LogLoader::Display() { void LogLoader::RebuildEntryTree() { m_entryTree.clear(); wpi::SmallVector parts; - m_reader->ForEachEntryName([&](const glass::DataLogReaderEntry& entry) { + m_reader->ForEachEntryName([&](const wpi::log::DataLogReaderEntry& entry) { // only show double/float/string entries (TODO: support struct/protobuf) if (entry.type != "double" && entry.type != "float" && entry.type != "string") { @@ -167,7 +167,7 @@ void LogLoader::RebuildEntryTree() { } static void EmitEntry(const std::string& name, - const glass::DataLogReaderEntry& entry) { + const wpi::log::DataLogReaderEntry& entry) { ImGui::TableNextColumn(); ImGui::Selectable(name.c_str()); if (ImGui::BeginDragDropSource()) { diff --git a/sysid/src/main/native/include/sysid/view/DataSelector.h b/sysid/src/main/native/include/sysid/view/DataSelector.h index 71732a7ed74..1020bc563a4 100644 --- a/sysid/src/main/native/include/sysid/view/DataSelector.h +++ b/sysid/src/main/native/include/sysid/view/DataSelector.h @@ -12,17 +12,19 @@ #include #include -#include #include +#include #include "sysid/analysis/Storage.h" namespace glass { -class DataLogReaderEntry; class Storage; } // namespace glass namespace wpi { +namespace log { +class DataLogReaderEntry; +} // namespace log class Logger; } // namespace wpi @@ -64,10 +66,10 @@ class DataSelector : public glass::View { std::future m_testsFuture; Tests m_tests; std::string m_selectedTest; - const glass::DataLogReaderEntry* m_testStateEntry = nullptr; - const glass::DataLogReaderEntry* m_velocityEntry = nullptr; - const glass::DataLogReaderEntry* m_positionEntry = nullptr; - const glass::DataLogReaderEntry* m_voltageEntry = nullptr; + const wpi::log::DataLogReaderEntry* m_testStateEntry = nullptr; + const wpi::log::DataLogReaderEntry* m_velocityEntry = nullptr; + const wpi::log::DataLogReaderEntry* m_positionEntry = nullptr; + const wpi::log::DataLogReaderEntry* m_voltageEntry = nullptr; double m_velocityScale = 1.0; double m_positionScale = 1.0; int m_selectedUnit = 0; @@ -75,7 +77,7 @@ class DataSelector : public glass::View { std::future m_testdataFuture; std::vector m_testdataStats; - static Tests LoadTests(const glass::DataLogReaderEntry& testStateEntry); + static Tests LoadTests(const wpi::log::DataLogReaderEntry& testStateEntry); TestData BuildTestData(); }; } // namespace sysid diff --git a/sysid/src/main/native/include/sysid/view/LogLoader.h b/sysid/src/main/native/include/sysid/view/LogLoader.h index 04ddd84dab3..70931bc8cab 100644 --- a/sysid/src/main/native/include/sysid/view/LogLoader.h +++ b/sysid/src/main/native/include/sysid/view/LogLoader.h @@ -13,8 +13,6 @@ #include namespace glass { -class DataLogReaderEntry; -class DataLogReaderThread; class Storage; } // namespace glass @@ -23,6 +21,10 @@ class open_file; } // namespace pfd namespace wpi { +namespace log { +class DataLogReaderEntry; +class DataLogReaderThread; +} // namespace log class Logger; } // namespace wpi @@ -57,7 +59,7 @@ class LogLoader : public glass::View { std::string m_filename; std::unique_ptr m_opener; - std::unique_ptr m_reader; + std::unique_ptr m_reader; std::string m_error; @@ -67,7 +69,7 @@ class LogLoader : public glass::View { explicit EntryTreeNode(std::string_view name) : name{name} {} std::string name; // name of just this node std::string path; // full path if entry is nullptr - const glass::DataLogReaderEntry* entry = nullptr; + const wpi::log::DataLogReaderEntry* entry = nullptr; std::vector children; // children, sorted by name }; std::vector m_entryTree; diff --git a/wpilibNewCommands/CMakeLists.txt b/wpilibNewCommands/CMakeLists.txt index f7c664802e6..d4107abb679 100644 --- a/wpilibNewCommands/CMakeLists.txt +++ b/wpilibNewCommands/CMakeLists.txt @@ -22,6 +22,7 @@ if(WITH_JAVA) wpiunits_jar wpiutil_jar wpilibj_jar + datalog_jar OUTPUT_NAME wpilibNewCommands OUTPUT_DIR ${WPILIB_BINARY_DIR}/${java_lib_dest} ) diff --git a/wpilibNewCommands/build.gradle b/wpilibNewCommands/build.gradle index 588c3113b36..dd5930e3eca 100644 --- a/wpilibNewCommands/build.gradle +++ b/wpilibNewCommands/build.gradle @@ -21,6 +21,7 @@ dependencies { implementation project(':hal') implementation project(':wpimath') implementation project(':wpilibj') + api project(':datalog') testImplementation 'org.mockito:mockito-core:4.1.0' } diff --git a/wpilibc/BUILD.bazel b/wpilibc/BUILD.bazel index c11298d3d57..62e871af19c 100644 --- a/wpilibc/BUILD.bazel +++ b/wpilibc/BUILD.bazel @@ -40,6 +40,7 @@ cc_library( ":generated_cc_headers", "//cameraserver:cameraserver.static", "//cscore:cscore.static", + "//datalog:datalog.static", "//hal:wpiHal.static", "//ntcore:ntcore.static", "//wpimath:wpimath.static", diff --git a/wpilibc/CMakeLists.txt b/wpilibc/CMakeLists.txt index ec1016244d4..7f4907b2961 100644 --- a/wpilibc/CMakeLists.txt +++ b/wpilibc/CMakeLists.txt @@ -35,7 +35,7 @@ else() ) endif() -target_link_libraries(wpilibc PUBLIC hal ntcore wpimath wpiutil) +target_link_libraries(wpilibc PUBLIC hal ntcore wpimath datalog) set_property(TARGET wpilibc PROPERTY FOLDER "libraries") diff --git a/wpilibc/build.gradle b/wpilibc/build.gradle index 4fa684ccfc5..1bc014ee513 100644 --- a/wpilibc/build.gradle +++ b/wpilibc/build.gradle @@ -112,6 +112,7 @@ model { lib project: ':wpinet', library: 'wpinet', linkage: 'shared' lib project: ':wpiutil', library: 'wpiutil', linkage: 'shared' lib project: ':wpimath', library: 'wpimath', linkage: 'shared' + lib project: ':datalog', library: 'datalog', linkage: 'shared' } } "${nativeName}"(NativeLibrarySpec) { diff --git a/wpilibc/src/main/native/cpp/DataLogManager.cpp b/wpilibc/src/main/native/cpp/DataLogManager.cpp index 92035eb74b8..2a671366902 100644 --- a/wpilibc/src/main/native/cpp/DataLogManager.cpp +++ b/wpilibc/src/main/native/cpp/DataLogManager.cpp @@ -15,11 +15,11 @@ #include #include #include -#include -#include -#include #include #include +#include +#include +#include #include #include #include @@ -51,7 +51,7 @@ struct Thread final : public wpi::SafeThread { NT_DataLogger m_ntEntryLogger = 0; NT_ConnectionDataLogger m_ntConnLogger = 0; bool m_consoleLoggerEnabled = false; - wpi::FileLogger m_consoleLogger; + wpi::log::FileLogger m_consoleLogger; wpi::log::StringLogEntry m_messageLog; }; diff --git a/wpilibc/src/main/native/cpp/DriverStation.cpp b/wpilibc/src/main/native/cpp/DriverStation.cpp index 6318c8899e8..001f6ff81f1 100644 --- a/wpilibc/src/main/native/cpp/DriverStation.cpp +++ b/wpilibc/src/main/native/cpp/DriverStation.cpp @@ -23,9 +23,9 @@ #include #include #include -#include #include #include +#include #include #include #include diff --git a/wpilibc/src/main/native/include/frc/sysid/SysIdRoutineLog.h b/wpilibc/src/main/native/include/frc/sysid/SysIdRoutineLog.h index 5e727169068..9d53847e6b9 100644 --- a/wpilibc/src/main/native/include/frc/sysid/SysIdRoutineLog.h +++ b/wpilibc/src/main/native/include/frc/sysid/SysIdRoutineLog.h @@ -15,7 +15,7 @@ #include #include #include -#include +#include namespace frc::sysid { diff --git a/wpilibj/BUILD.bazel b/wpilibj/BUILD.bazel index e5b8b0dd993..b5f193f2c43 100644 --- a/wpilibj/BUILD.bazel +++ b/wpilibj/BUILD.bazel @@ -26,6 +26,7 @@ java_library( deps = [ "//cameraserver:cameraserver-java", "//cscore:cscore-java", + "//datalog:datalog-java", "//hal:hal-java", "//ntcore:networktables-java", "//wpimath:wpimath-java", diff --git a/wpilibj/CMakeLists.txt b/wpilibj/CMakeLists.txt index 5ea91bdee0f..e27bbbb21f9 100644 --- a/wpilibj/CMakeLists.txt +++ b/wpilibj/CMakeLists.txt @@ -41,6 +41,7 @@ if(WITH_JAVA) wpimath_jar wpiunits_jar wpiutil_jar + datalog_jar OUTPUT_NAME wpilibj OUTPUT_DIR ${WPILIB_BINARY_DIR}/${java_lib_dest} ) diff --git a/wpilibj/build.gradle b/wpilibj/build.gradle index 81642b195ee..07f5df67dad 100644 --- a/wpilibj/build.gradle +++ b/wpilibj/build.gradle @@ -69,6 +69,7 @@ dependencies { implementation project(':wpimath') implementation project(':ntcore') implementation project(':cscore') + api project(':datalog') implementation project(':cameraserver') testImplementation 'org.mockito:mockito-core:4.1.0' devImplementation sourceSets.main.output diff --git a/wpilibj/src/main/java/edu/wpi/first/wpilibj/DataLogManager.java b/wpilibj/src/main/java/edu/wpi/first/wpilibj/DataLogManager.java index 53e8b84c2d2..33fd32e0bfa 100644 --- a/wpilibj/src/main/java/edu/wpi/first/wpilibj/DataLogManager.java +++ b/wpilibj/src/main/java/edu/wpi/first/wpilibj/DataLogManager.java @@ -4,17 +4,17 @@ package edu.wpi.first.wpilibj; +import edu.wpi.first.datalog.DataLog; +import edu.wpi.first.datalog.DataLogBackgroundWriter; +import edu.wpi.first.datalog.FileLogger; +import edu.wpi.first.datalog.IntegerLogEntry; +import edu.wpi.first.datalog.StringLogEntry; import edu.wpi.first.hal.FRCNetComm.tInstances; import edu.wpi.first.hal.FRCNetComm.tResourceType; import edu.wpi.first.hal.HAL; import edu.wpi.first.networktables.NetworkTableInstance; -import edu.wpi.first.util.FileLogger; import edu.wpi.first.util.WPIUtilJNI; import edu.wpi.first.util.concurrent.Event; -import edu.wpi.first.util.datalog.DataLog; -import edu.wpi.first.util.datalog.DataLogBackgroundWriter; -import edu.wpi.first.util.datalog.IntegerLogEntry; -import edu.wpi.first.util.datalog.StringLogEntry; import java.io.File; import java.io.IOException; import java.nio.file.Files; diff --git a/wpilibj/src/main/java/edu/wpi/first/wpilibj/DriverStation.java b/wpilibj/src/main/java/edu/wpi/first/wpilibj/DriverStation.java index 36721e355aa..eed127ce555 100644 --- a/wpilibj/src/main/java/edu/wpi/first/wpilibj/DriverStation.java +++ b/wpilibj/src/main/java/edu/wpi/first/wpilibj/DriverStation.java @@ -4,6 +4,11 @@ package edu.wpi.first.wpilibj; +import edu.wpi.first.datalog.BooleanArrayLogEntry; +import edu.wpi.first.datalog.BooleanLogEntry; +import edu.wpi.first.datalog.DataLog; +import edu.wpi.first.datalog.FloatArrayLogEntry; +import edu.wpi.first.datalog.IntegerArrayLogEntry; import edu.wpi.first.hal.AllianceStationID; import edu.wpi.first.hal.ControlWord; import edu.wpi.first.hal.DriverStationJNI; @@ -16,11 +21,6 @@ import edu.wpi.first.networktables.StringTopic; import edu.wpi.first.util.EventVector; import edu.wpi.first.util.WPIUtilJNI; -import edu.wpi.first.util.datalog.BooleanArrayLogEntry; -import edu.wpi.first.util.datalog.BooleanLogEntry; -import edu.wpi.first.util.datalog.DataLog; -import edu.wpi.first.util.datalog.FloatArrayLogEntry; -import edu.wpi.first.util.datalog.IntegerArrayLogEntry; import java.nio.ByteBuffer; import java.util.Map; import java.util.Optional; diff --git a/wpilibj/src/main/java/edu/wpi/first/wpilibj/sysid/SysIdRoutineLog.java b/wpilibj/src/main/java/edu/wpi/first/wpilibj/sysid/SysIdRoutineLog.java index 82c9ed9b05f..f80332a26be 100644 --- a/wpilibj/src/main/java/edu/wpi/first/wpilibj/sysid/SysIdRoutineLog.java +++ b/wpilibj/src/main/java/edu/wpi/first/wpilibj/sysid/SysIdRoutineLog.java @@ -12,6 +12,8 @@ import static edu.wpi.first.units.Units.Second; import static edu.wpi.first.units.Units.Volts; +import edu.wpi.first.datalog.DoubleLogEntry; +import edu.wpi.first.datalog.StringLogEntry; import edu.wpi.first.units.measure.Angle; import edu.wpi.first.units.measure.AngularAcceleration; import edu.wpi.first.units.measure.AngularVelocity; @@ -20,8 +22,6 @@ import edu.wpi.first.units.measure.LinearAcceleration; import edu.wpi.first.units.measure.LinearVelocity; import edu.wpi.first.units.measure.Voltage; -import edu.wpi.first.util.datalog.DoubleLogEntry; -import edu.wpi.first.util.datalog.StringLogEntry; import edu.wpi.first.wpilibj.DataLogManager; import java.util.HashMap; import java.util.Map; diff --git a/wpiutil/BUILD.bazel b/wpiutil/BUILD.bazel index 646858441c5..3fcfaecc2b4 100644 --- a/wpiutil/BUILD.bazel +++ b/wpiutil/BUILD.bazel @@ -1,6 +1,5 @@ load("@rules_cc//cc:defs.bzl", "cc_binary", "cc_library", "cc_test") load("@rules_java//java:defs.bzl", "java_binary") -load("@rules_python//python:defs.bzl", "py_binary") load("//shared/bazel/rules:java_rules.bzl", "wpilib_java_junit5_test") load("//shared/bazel/rules:jni_rules.bzl", "wpilib_jni_cc_library", "wpilib_jni_java_library") load("//shared/bazel/rules/gen:gen-resources.bzl", "generate_resources") @@ -305,34 +304,3 @@ java_binary( ":wpiutil-java", ], ) - -py_binary( - name = "datalog", - srcs = ["examples/printlog/datalog.py"], - tags = ["manual"], -) - -cc_binary( - name = "printlog", - srcs = ["examples/printlog/printlog.cpp"], - deps = [ - ":wpiutil.static", - ], -) - -cc_binary( - name = "writelog", - srcs = ["examples/writelog/writelog.cpp"], - deps = [ - ":wpiutil.static", - ], -) - -java_binary( - name = "printlog-java", - srcs = ["src/printlog/java/printlog/PrintLog.java"], - main_class = "printlog.PrintLog", - deps = [ - ":wpiutil-java", - ], -) diff --git a/wpiutil/CMakeLists.txt b/wpiutil/CMakeLists.txt index 9d98b7fc984..e0af46d8df3 100644 --- a/wpiutil/CMakeLists.txt +++ b/wpiutil/CMakeLists.txt @@ -6,11 +6,7 @@ include(CompileWarnings) include(AddTest) include(DownloadAndCheck) -file( - GLOB wpiutil_jni_src - src/main/native/cpp/jni/WPIUtilJNI.cpp - src/main/native/cpp/jni/DataLogJNI.cpp -) +file(GLOB wpiutil_jni_src src/main/native/cpp/jni/WPIUtilJNI.cpp) # Java bindings if(WITH_JAVA) diff --git a/wpiutil/src/main/java/edu/wpi/first/util/WPIUtilJNI.java b/wpiutil/src/main/java/edu/wpi/first/util/WPIUtilJNI.java index 2818489c59d..acd93408e64 100644 --- a/wpiutil/src/main/java/edu/wpi/first/util/WPIUtilJNI.java +++ b/wpiutil/src/main/java/edu/wpi/first/util/WPIUtilJNI.java @@ -222,24 +222,6 @@ public static native boolean waitForObjectTimeout(int handle, double timeout) public static native int[] waitForObjectsTimeout(int[] handles, double timeout) throws InterruptedException; - /** - * Create a native FileLogger. When the specified file is modified, appended data will be appended - * to the specified data log. - * - * @param file path to the file - * @param log data log implementation handle - * @param key log key to append data to - * @return The FileLogger handle. - */ - public static native long createFileLogger(String file, long log, String key); - - /** - * Free a native FileLogger. This causes the FileLogger to stop appending data to the log. - * - * @param fileTail The FileLogger handle. - */ - public static native void freeFileLogger(long fileTail); - /** Utility class. */ protected WPIUtilJNI() {} } diff --git a/wpiutil/src/main/native/cpp/fs.cpp b/wpiutil/src/main/native/cpp/fs.cpp index 82bd3857eed..6ea69bfc195 100644 --- a/wpiutil/src/main/native/cpp/fs.cpp +++ b/wpiutil/src/main/native/cpp/fs.cpp @@ -21,6 +21,7 @@ #define _WIN32_WINNT 0x0601 #define _WIN32_IE 0x0800 // MinGW at it again. FIXME: verify if still needed. #define WIN32_LEAN_AND_MEAN +#define kInvalidFile reinterpret_cast(-1) #ifndef NOMINMAX #define NOMINMAX #endif diff --git a/wpiutil/src/main/native/cpp/jni/WPIUtilJNI.cpp b/wpiutil/src/main/native/cpp/jni/WPIUtilJNI.cpp index b55100de0ed..55764642a46 100644 --- a/wpiutil/src/main/native/cpp/jni/WPIUtilJNI.cpp +++ b/wpiutil/src/main/native/cpp/jni/WPIUtilJNI.cpp @@ -7,8 +7,6 @@ #include #include "edu_wpi_first_util_WPIUtilJNI.h" -#include "wpi/DataLog.h" -#include "wpi/FileLogger.h" #include "wpi/RawFrame.h" #include "wpi/RuntimeCheck.h" #include "wpi/Synchronization.h" @@ -464,42 +462,4 @@ Java_edu_wpi_first_util_WPIUtilJNI_setRawFrameInfo f->stride = stride; 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(log); - if (!f) { - wpi::ThrowNullPointerException(env, "log is null"); - return 0; - } - if (!key) { - wpi::ThrowNullPointerException(env, "key is null"); - return 0; - } - return reinterpret_cast( - 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(fileTail); -} } // extern "C"