From 54ab65a63a92199b116e0ed6dddff3ae8bd5173a Mon Sep 17 00:00:00 2001 From: PJ Reiniger Date: Fri, 1 Dec 2023 18:31:06 -0500 Subject: [PATCH] [ntcore] Commit generated files (#5962) --- .github/workflows/pregenerate.yml | 43 + docs/build.gradle | 1 - ntcore/.styleguide | 2 + ntcore/CMakeLists.txt | 38 +- ntcore/build.gradle | 276 +-- ntcore/generate_topics.py | 50 +- .../generate/{ => main}/java/Entry.java.jinja | 3 + .../{ => main}/java/EntryImpl.java.jinja | 3 + .../java/GenericEntryImpl.java.jinja | 3 + .../java/GenericPublisher.java.jinja | 3 + .../java/GenericSubscriber.java.jinja | 3 + .../java/NetworkTableEntry.java.jinja | 3 + .../java/NetworkTableInstance.java.jinja | 3 + .../java/NetworkTableValue.java.jinja | 3 + .../java/NetworkTablesJNI.java.jinja | 3 + .../{ => main}/java/Publisher.java.jinja | 3 + .../{ => main}/java/Subscriber.java.jinja | 3 + .../{ => main}/java/Timestamped.java.jinja | 3 + .../generate/{ => main}/java/Topic.java.jinja | 3 + .../native}/cpp/jni/types_jni.cpp.jinja | 3 + .../native}/cpp/ntcore_c_types.cpp.jinja | 3 + .../native}/cpp/ntcore_cpp_types.cpp.jinja | 3 + .../include/networktables/Topic.h.jinja | 3 + .../include/networktables/Topic.inc.jinja | 5 + .../native}/include/ntcore_c_types.h.jinja | 3 + .../native}/include/ntcore_cpp_types.h.jinja | 3 + .../networktables/BooleanArrayEntry.java | 17 + .../networktables/BooleanArrayEntryImpl.java | 77 + .../networktables/BooleanArrayPublisher.java | 52 + .../networktables/BooleanArraySubscriber.java | 80 + .../networktables/BooleanArrayTopic.java | 206 +++ .../wpi/first/networktables/BooleanEntry.java | 17 + .../first/networktables/BooleanEntryImpl.java | 77 + .../first/networktables/BooleanPublisher.java | 52 + .../networktables/BooleanSubscriber.java | 85 + .../wpi/first/networktables/BooleanTopic.java | 206 +++ .../first/networktables/DoubleArrayEntry.java | 17 + .../networktables/DoubleArrayEntryImpl.java | 77 + .../networktables/DoubleArrayPublisher.java | 52 + .../networktables/DoubleArraySubscriber.java | 80 + .../first/networktables/DoubleArrayTopic.java | 206 +++ .../wpi/first/networktables/DoubleEntry.java | 17 + .../first/networktables/DoubleEntryImpl.java | 77 + .../first/networktables/DoublePublisher.java | 52 + .../first/networktables/DoubleSubscriber.java | 85 + .../wpi/first/networktables/DoubleTopic.java | 206 +++ .../first/networktables/FloatArrayEntry.java | 17 + .../networktables/FloatArrayEntryImpl.java | 77 + .../networktables/FloatArrayPublisher.java | 52 + .../networktables/FloatArraySubscriber.java | 80 + .../first/networktables/FloatArrayTopic.java | 206 +++ .../wpi/first/networktables/FloatEntry.java | 17 + .../first/networktables/FloatEntryImpl.java | 77 + .../first/networktables/FloatPublisher.java | 52 + .../first/networktables/FloatSubscriber.java | 85 + .../wpi/first/networktables/FloatTopic.java | 206 +++ .../first/networktables/GenericEntryImpl.java | 815 +++++++++ .../first/networktables/GenericPublisher.java | 568 ++++++ .../networktables/GenericSubscriber.java | 176 ++ .../networktables/IntegerArrayEntry.java | 17 + .../networktables/IntegerArrayEntryImpl.java | 77 + .../networktables/IntegerArrayPublisher.java | 52 + .../networktables/IntegerArraySubscriber.java | 80 + .../networktables/IntegerArrayTopic.java | 206 +++ .../wpi/first/networktables/IntegerEntry.java | 17 + .../first/networktables/IntegerEntryImpl.java | 77 + .../first/networktables/IntegerPublisher.java | 52 + .../networktables/IntegerSubscriber.java | 85 + .../wpi/first/networktables/IntegerTopic.java | 206 +++ .../networktables/NetworkTableEntry.java | 1013 +++++++++++ .../networktables/NetworkTableInstance.java | 1553 +++++++++++++++++ .../networktables/NetworkTableValue.java | 742 ++++++++ .../first/networktables/NetworkTablesJNI.java | 493 ++++++ .../edu/wpi/first/networktables/RawEntry.java | 17 + .../wpi/first/networktables/RawEntryImpl.java | 89 + .../wpi/first/networktables/RawPublisher.java | 154 ++ .../first/networktables/RawSubscriber.java | 80 + .../edu/wpi/first/networktables/RawTopic.java | 154 ++ .../first/networktables/StringArrayEntry.java | 17 + .../networktables/StringArrayEntryImpl.java | 77 + .../networktables/StringArrayPublisher.java | 52 + .../networktables/StringArraySubscriber.java | 80 + .../first/networktables/StringArrayTopic.java | 206 +++ .../wpi/first/networktables/StringEntry.java | 17 + .../first/networktables/StringEntryImpl.java | 77 + .../first/networktables/StringPublisher.java | 52 + .../first/networktables/StringSubscriber.java | 80 + .../wpi/first/networktables/StringTopic.java | 206 +++ .../networktables/TimestampedBoolean.java | 42 + .../TimestampedBooleanArray.java | 42 + .../networktables/TimestampedDouble.java | 42 + .../networktables/TimestampedDoubleArray.java | 42 + .../first/networktables/TimestampedFloat.java | 42 + .../networktables/TimestampedFloatArray.java | 42 + .../networktables/TimestampedInteger.java | 42 + .../TimestampedIntegerArray.java | 42 + .../first/networktables/TimestampedRaw.java | 42 + .../networktables/TimestampedString.java | 42 + .../networktables/TimestampedStringArray.java | 42 + .../main/native/cpp/jni/types_jni.cpp | 1436 +++++++++++++++ .../main/native/cpp/ntcore_c_types.cpp | 495 ++++++ .../main/native/cpp/ntcore_cpp_types.cpp | 463 +++++ .../include/networktables/BooleanArrayTopic.h | 426 +++++ .../networktables/BooleanArrayTopic.inc | 137 ++ .../include/networktables/BooleanTopic.h | 373 ++++ .../include/networktables/BooleanTopic.inc | 121 ++ .../include/networktables/DoubleArrayTopic.h | 426 +++++ .../networktables/DoubleArrayTopic.inc | 137 ++ .../include/networktables/DoubleTopic.h | 373 ++++ .../include/networktables/DoubleTopic.inc | 121 ++ .../include/networktables/FloatArrayTopic.h | 426 +++++ .../include/networktables/FloatArrayTopic.inc | 137 ++ .../native/include/networktables/FloatTopic.h | 373 ++++ .../include/networktables/FloatTopic.inc | 121 ++ .../include/networktables/IntegerArrayTopic.h | 426 +++++ .../networktables/IntegerArrayTopic.inc | 137 ++ .../include/networktables/IntegerTopic.h | 373 ++++ .../include/networktables/IntegerTopic.inc | 121 ++ .../native/include/networktables/RawTopic.h | 384 ++++ .../native/include/networktables/RawTopic.inc | 121 ++ .../include/networktables/StringArrayTopic.h | 373 ++++ .../networktables/StringArrayTopic.inc | 121 ++ .../include/networktables/StringTopic.h | 428 +++++ .../include/networktables/StringTopic.inc | 137 ++ .../main/native/include/ntcore_c_types.h | 1245 +++++++++++++ .../main/native/include/ntcore_cpp_types.h | 998 +++++++++++ shared/java/javastyle.gradle | 2 +- 127 files changed, 21230 insertions(+), 329 deletions(-) create mode 100644 .github/workflows/pregenerate.yml mode change 100644 => 100755 ntcore/generate_topics.py rename ntcore/src/generate/{ => main}/java/Entry.java.jinja (87%) rename ntcore/src/generate/{ => main}/java/EntryImpl.java.jinja (97%) rename ntcore/src/generate/{ => main}/java/GenericEntryImpl.java.jinja (99%) rename ntcore/src/generate/{ => main}/java/GenericPublisher.java.jinja (98%) rename ntcore/src/generate/{ => main}/java/GenericSubscriber.java.jinja (96%) rename ntcore/src/generate/{ => main}/java/NetworkTableEntry.java.jinja (99%) rename ntcore/src/generate/{ => main}/java/NetworkTableInstance.java.jinja (99%) rename ntcore/src/generate/{ => main}/java/NetworkTableValue.java.jinja (98%) rename ntcore/src/generate/{ => main}/java/NetworkTablesJNI.java.jinja (99%) rename ntcore/src/generate/{ => main}/java/Publisher.java.jinja (98%) rename ntcore/src/generate/{ => main}/java/Subscriber.java.jinja (97%) rename ntcore/src/generate/{ => main}/java/Timestamped.java.jinja (93%) rename ntcore/src/generate/{ => main}/java/Topic.java.jinja (99%) rename ntcore/src/generate/{ => main/native}/cpp/jni/types_jni.cpp.jinja (99%) rename ntcore/src/generate/{ => main/native}/cpp/ntcore_c_types.cpp.jinja (97%) rename ntcore/src/generate/{ => main/native}/cpp/ntcore_cpp_types.cpp.jinja (98%) rename ntcore/src/generate/{ => main/native}/include/networktables/Topic.h.jinja (99%) rename ntcore/src/generate/{ => main/native}/include/networktables/Topic.inc.jinja (98%) rename ntcore/src/generate/{ => main/native}/include/ntcore_c_types.h.jinja (98%) rename ntcore/src/generate/{ => main/native}/include/ntcore_cpp_types.h.jinja (98%) create mode 100644 ntcore/src/generated/main/java/edu/wpi/first/networktables/BooleanArrayEntry.java create mode 100644 ntcore/src/generated/main/java/edu/wpi/first/networktables/BooleanArrayEntryImpl.java create mode 100644 ntcore/src/generated/main/java/edu/wpi/first/networktables/BooleanArrayPublisher.java create mode 100644 ntcore/src/generated/main/java/edu/wpi/first/networktables/BooleanArraySubscriber.java create mode 100644 ntcore/src/generated/main/java/edu/wpi/first/networktables/BooleanArrayTopic.java create mode 100644 ntcore/src/generated/main/java/edu/wpi/first/networktables/BooleanEntry.java create mode 100644 ntcore/src/generated/main/java/edu/wpi/first/networktables/BooleanEntryImpl.java create mode 100644 ntcore/src/generated/main/java/edu/wpi/first/networktables/BooleanPublisher.java create mode 100644 ntcore/src/generated/main/java/edu/wpi/first/networktables/BooleanSubscriber.java create mode 100644 ntcore/src/generated/main/java/edu/wpi/first/networktables/BooleanTopic.java create mode 100644 ntcore/src/generated/main/java/edu/wpi/first/networktables/DoubleArrayEntry.java create mode 100644 ntcore/src/generated/main/java/edu/wpi/first/networktables/DoubleArrayEntryImpl.java create mode 100644 ntcore/src/generated/main/java/edu/wpi/first/networktables/DoubleArrayPublisher.java create mode 100644 ntcore/src/generated/main/java/edu/wpi/first/networktables/DoubleArraySubscriber.java create mode 100644 ntcore/src/generated/main/java/edu/wpi/first/networktables/DoubleArrayTopic.java create mode 100644 ntcore/src/generated/main/java/edu/wpi/first/networktables/DoubleEntry.java create mode 100644 ntcore/src/generated/main/java/edu/wpi/first/networktables/DoubleEntryImpl.java create mode 100644 ntcore/src/generated/main/java/edu/wpi/first/networktables/DoublePublisher.java create mode 100644 ntcore/src/generated/main/java/edu/wpi/first/networktables/DoubleSubscriber.java create mode 100644 ntcore/src/generated/main/java/edu/wpi/first/networktables/DoubleTopic.java create mode 100644 ntcore/src/generated/main/java/edu/wpi/first/networktables/FloatArrayEntry.java create mode 100644 ntcore/src/generated/main/java/edu/wpi/first/networktables/FloatArrayEntryImpl.java create mode 100644 ntcore/src/generated/main/java/edu/wpi/first/networktables/FloatArrayPublisher.java create mode 100644 ntcore/src/generated/main/java/edu/wpi/first/networktables/FloatArraySubscriber.java create mode 100644 ntcore/src/generated/main/java/edu/wpi/first/networktables/FloatArrayTopic.java create mode 100644 ntcore/src/generated/main/java/edu/wpi/first/networktables/FloatEntry.java create mode 100644 ntcore/src/generated/main/java/edu/wpi/first/networktables/FloatEntryImpl.java create mode 100644 ntcore/src/generated/main/java/edu/wpi/first/networktables/FloatPublisher.java create mode 100644 ntcore/src/generated/main/java/edu/wpi/first/networktables/FloatSubscriber.java create mode 100644 ntcore/src/generated/main/java/edu/wpi/first/networktables/FloatTopic.java create mode 100644 ntcore/src/generated/main/java/edu/wpi/first/networktables/GenericEntryImpl.java create mode 100644 ntcore/src/generated/main/java/edu/wpi/first/networktables/GenericPublisher.java create mode 100644 ntcore/src/generated/main/java/edu/wpi/first/networktables/GenericSubscriber.java create mode 100644 ntcore/src/generated/main/java/edu/wpi/first/networktables/IntegerArrayEntry.java create mode 100644 ntcore/src/generated/main/java/edu/wpi/first/networktables/IntegerArrayEntryImpl.java create mode 100644 ntcore/src/generated/main/java/edu/wpi/first/networktables/IntegerArrayPublisher.java create mode 100644 ntcore/src/generated/main/java/edu/wpi/first/networktables/IntegerArraySubscriber.java create mode 100644 ntcore/src/generated/main/java/edu/wpi/first/networktables/IntegerArrayTopic.java create mode 100644 ntcore/src/generated/main/java/edu/wpi/first/networktables/IntegerEntry.java create mode 100644 ntcore/src/generated/main/java/edu/wpi/first/networktables/IntegerEntryImpl.java create mode 100644 ntcore/src/generated/main/java/edu/wpi/first/networktables/IntegerPublisher.java create mode 100644 ntcore/src/generated/main/java/edu/wpi/first/networktables/IntegerSubscriber.java create mode 100644 ntcore/src/generated/main/java/edu/wpi/first/networktables/IntegerTopic.java create mode 100644 ntcore/src/generated/main/java/edu/wpi/first/networktables/NetworkTableEntry.java create mode 100644 ntcore/src/generated/main/java/edu/wpi/first/networktables/NetworkTableInstance.java create mode 100644 ntcore/src/generated/main/java/edu/wpi/first/networktables/NetworkTableValue.java create mode 100644 ntcore/src/generated/main/java/edu/wpi/first/networktables/NetworkTablesJNI.java create mode 100644 ntcore/src/generated/main/java/edu/wpi/first/networktables/RawEntry.java create mode 100644 ntcore/src/generated/main/java/edu/wpi/first/networktables/RawEntryImpl.java create mode 100644 ntcore/src/generated/main/java/edu/wpi/first/networktables/RawPublisher.java create mode 100644 ntcore/src/generated/main/java/edu/wpi/first/networktables/RawSubscriber.java create mode 100644 ntcore/src/generated/main/java/edu/wpi/first/networktables/RawTopic.java create mode 100644 ntcore/src/generated/main/java/edu/wpi/first/networktables/StringArrayEntry.java create mode 100644 ntcore/src/generated/main/java/edu/wpi/first/networktables/StringArrayEntryImpl.java create mode 100644 ntcore/src/generated/main/java/edu/wpi/first/networktables/StringArrayPublisher.java create mode 100644 ntcore/src/generated/main/java/edu/wpi/first/networktables/StringArraySubscriber.java create mode 100644 ntcore/src/generated/main/java/edu/wpi/first/networktables/StringArrayTopic.java create mode 100644 ntcore/src/generated/main/java/edu/wpi/first/networktables/StringEntry.java create mode 100644 ntcore/src/generated/main/java/edu/wpi/first/networktables/StringEntryImpl.java create mode 100644 ntcore/src/generated/main/java/edu/wpi/first/networktables/StringPublisher.java create mode 100644 ntcore/src/generated/main/java/edu/wpi/first/networktables/StringSubscriber.java create mode 100644 ntcore/src/generated/main/java/edu/wpi/first/networktables/StringTopic.java create mode 100644 ntcore/src/generated/main/java/edu/wpi/first/networktables/TimestampedBoolean.java create mode 100644 ntcore/src/generated/main/java/edu/wpi/first/networktables/TimestampedBooleanArray.java create mode 100644 ntcore/src/generated/main/java/edu/wpi/first/networktables/TimestampedDouble.java create mode 100644 ntcore/src/generated/main/java/edu/wpi/first/networktables/TimestampedDoubleArray.java create mode 100644 ntcore/src/generated/main/java/edu/wpi/first/networktables/TimestampedFloat.java create mode 100644 ntcore/src/generated/main/java/edu/wpi/first/networktables/TimestampedFloatArray.java create mode 100644 ntcore/src/generated/main/java/edu/wpi/first/networktables/TimestampedInteger.java create mode 100644 ntcore/src/generated/main/java/edu/wpi/first/networktables/TimestampedIntegerArray.java create mode 100644 ntcore/src/generated/main/java/edu/wpi/first/networktables/TimestampedRaw.java create mode 100644 ntcore/src/generated/main/java/edu/wpi/first/networktables/TimestampedString.java create mode 100644 ntcore/src/generated/main/java/edu/wpi/first/networktables/TimestampedStringArray.java create mode 100644 ntcore/src/generated/main/native/cpp/jni/types_jni.cpp create mode 100644 ntcore/src/generated/main/native/cpp/ntcore_c_types.cpp create mode 100644 ntcore/src/generated/main/native/cpp/ntcore_cpp_types.cpp create mode 100644 ntcore/src/generated/main/native/include/networktables/BooleanArrayTopic.h create mode 100644 ntcore/src/generated/main/native/include/networktables/BooleanArrayTopic.inc create mode 100644 ntcore/src/generated/main/native/include/networktables/BooleanTopic.h create mode 100644 ntcore/src/generated/main/native/include/networktables/BooleanTopic.inc create mode 100644 ntcore/src/generated/main/native/include/networktables/DoubleArrayTopic.h create mode 100644 ntcore/src/generated/main/native/include/networktables/DoubleArrayTopic.inc create mode 100644 ntcore/src/generated/main/native/include/networktables/DoubleTopic.h create mode 100644 ntcore/src/generated/main/native/include/networktables/DoubleTopic.inc create mode 100644 ntcore/src/generated/main/native/include/networktables/FloatArrayTopic.h create mode 100644 ntcore/src/generated/main/native/include/networktables/FloatArrayTopic.inc create mode 100644 ntcore/src/generated/main/native/include/networktables/FloatTopic.h create mode 100644 ntcore/src/generated/main/native/include/networktables/FloatTopic.inc create mode 100644 ntcore/src/generated/main/native/include/networktables/IntegerArrayTopic.h create mode 100644 ntcore/src/generated/main/native/include/networktables/IntegerArrayTopic.inc create mode 100644 ntcore/src/generated/main/native/include/networktables/IntegerTopic.h create mode 100644 ntcore/src/generated/main/native/include/networktables/IntegerTopic.inc create mode 100644 ntcore/src/generated/main/native/include/networktables/RawTopic.h create mode 100644 ntcore/src/generated/main/native/include/networktables/RawTopic.inc create mode 100644 ntcore/src/generated/main/native/include/networktables/StringArrayTopic.h create mode 100644 ntcore/src/generated/main/native/include/networktables/StringArrayTopic.inc create mode 100644 ntcore/src/generated/main/native/include/networktables/StringTopic.h create mode 100644 ntcore/src/generated/main/native/include/networktables/StringTopic.inc create mode 100644 ntcore/src/generated/main/native/include/ntcore_c_types.h create mode 100644 ntcore/src/generated/main/native/include/ntcore_cpp_types.h diff --git a/.github/workflows/pregenerate.yml b/.github/workflows/pregenerate.yml new file mode 100644 index 0000000000..7f715eafee --- /dev/null +++ b/.github/workflows/pregenerate.yml @@ -0,0 +1,43 @@ +name: Check Pregenerated Files + +on: + pull_request: + push: + branches-ignore: + - main + +concurrency: + group: ${{ github.workflow }}-${{ github.head_ref || github.ref }} + cancel-in-progress: true + +jobs: + update: + name: "Update" + runs-on: ubuntu-22.04 + steps: + - uses: actions/checkout@v3 + - name: Fetch all history and metadata + run: | + git fetch --prune --unshallow + git checkout -b pr + git branch -f main origin/main + - name: Set up Python 3.9 + uses: actions/setup-python@v4 + with: + python-version: 3.9 + - name: Install jinja + run: python -m pip install jinja2 + - name: Run ntcore + run: ./ntcore/generate_topics.py + - name: Add untracked files to index so they count as changes + run: git add -A + - name: Check output + run: git --no-pager diff --exit-code HEAD + - name: Generate diff + run: git diff HEAD > pregenerated-files-fixes.patch + if: ${{ failure() }} + - uses: actions/upload-artifact@v3 + with: + name: pregenerated-files-fixes + path: pregenerated-files-fixes.patch + if: ${{ failure() }} diff --git a/docs/build.gradle b/docs/build.gradle index d17057242d..4a6dbd2686 100644 --- a/docs/build.gradle +++ b/docs/build.gradle @@ -227,7 +227,6 @@ task generateJavaDocs(type: Javadoc) { options.addBooleanOption('html5', true) options.linkSource(true) dependsOn project(':hal').generateUsageReporting - dependsOn project(':ntcore').ntcoreGenerateJavaTypes dependsOn project(':wpilibj').generateJavaVersion dependsOn project(':wpimath').generateNat source project(':apriltag').sourceSets.main.java diff --git a/ntcore/.styleguide b/ntcore/.styleguide index 1808bb50ce..13634e44df 100644 --- a/ntcore/.styleguide +++ b/ntcore/.styleguide @@ -14,6 +14,8 @@ cppSrcFileInclude { generatedFileExclude { ntcore/doc/ + ntcore/src/generated + .*\.jinja } repoRootNameOverride { diff --git a/ntcore/CMakeLists.txt b/ntcore/CMakeLists.txt index ded26b54ee..b56b3d8557 100644 --- a/ntcore/CMakeLists.txt +++ b/ntcore/CMakeLists.txt @@ -3,25 +3,10 @@ project(ntcore) include(CompileWarnings) include(AddTest) -execute_process( - COMMAND python3 ${CMAKE_CURRENT_SOURCE_DIR}/generate_topics.py ${WPILIB_BINARY_DIR}/ntcore - RESULT_VARIABLE generateResult -) -if(NOT (generateResult EQUAL "0")) - # Try python - execute_process( - COMMAND python ${CMAKE_CURRENT_SOURCE_DIR}/generate_topics.py ${WPILIB_BINARY_DIR}/ntcore - RESULT_VARIABLE generateResult - ) - if(NOT (generateResult EQUAL "0")) - message(FATAL_ERROR "python and python3 generate_topics.py failed") - endif() -endif() - file( GLOB ntcore_native_src src/main/native/cpp/*.cpp - ${WPILIB_BINARY_DIR}/ntcore/generated/main/native/cpp/*.cpp + src/generated/main/native/cpp/*.cpp src/main/native/cpp/net/*.cpp src/main/native/cpp/net3/*.cpp src/main/native/cpp/networktables/*.cpp @@ -34,7 +19,7 @@ target_include_directories( PRIVATE ${CMAKE_CURRENT_SOURCE_DIR}/src/main/native/cpp PUBLIC $ - $ + $ $ ) wpilib_target_warnings(ntcore) @@ -45,10 +30,7 @@ set_property(TARGET ntcore PROPERTY FOLDER "libraries") install(TARGETS ntcore EXPORT ntcore) install(DIRECTORY src/main/native/include/ DESTINATION "${include_dest}/ntcore") -install( - DIRECTORY ${WPILIB_BINARY_DIR}/ntcore/generated/main/native/include/ - DESTINATION "${include_dest}/ntcore" -) +install(DIRECTORY src/generated/main/native/include DESTINATION "${include_dest}/ntcore") configure_file(ntcore-config.cmake.in ${WPILIB_BINARY_DIR}/ntcore-config.cmake) install(FILES ${WPILIB_BINARY_DIR}/ntcore-config.cmake DESTINATION share/ntcore) @@ -65,17 +47,9 @@ if(WITH_JAVA) set(CMAKE_JAVA_INCLUDE_PATH wpimath.jar ${QUICKBUF_JAR}) - file( - GLOB ntcore_jni_src - src/main/native/cpp/jni/*.cpp - ${WPILIB_BINARY_DIR}/ntcore/generated/main/native/cpp/jni/*.cpp - ) + file(GLOB ntcore_jni_src src/main/native/cpp/jni/*.cpp src/generated/main/native/cpp/jni/*.cpp) - file( - GLOB_RECURSE JAVA_SOURCES - src/main/java/*.java - ${WPILIB_BINARY_DIR}/ntcore/generated/*.java - ) + file(GLOB_RECURSE JAVA_SOURCES src/main/java/*.java src/generated/main/java/*.java) set(CMAKE_JNI_TARGET true) add_jar( @@ -113,7 +87,7 @@ if(WITH_JAVA_SOURCE) file( GLOB NTCORE_SOURCES src/main/java/edu/wpi/first/networktables/*.java - ${WPILIB_BINARY_DIR}/ntcore/generated/*.java + src/generated/main/java/*.java ) add_jar( ntcore_src_jar diff --git a/ntcore/build.gradle b/ntcore/build.gradle index c5464cc5f4..510e5c183f 100644 --- a/ntcore/build.gradle +++ b/ntcore/build.gradle @@ -1,290 +1,24 @@ -import groovy.json.JsonSlurper; -import com.hubspot.jinjava.Jinjava; -import com.hubspot.jinjava.JinjavaConfig; - -def ntcoreTypesInputFile = file("src/generate/types.json") -def ntcoreJavaTypesInputDir = file("src/generate/java") -def ntcoreJavaTypesOutputDir = file("$buildDir/generated/main/java/edu/wpi/first/networktables") - -task ntcoreGenerateJavaTypes() { - description = "Generates ntcore Java type classes" - group = "WPILib" - - inputs.file ntcoreTypesInputFile - inputs.dir ntcoreJavaTypesInputDir - outputs.dir ntcoreJavaTypesOutputDir - - doLast { - def jsonSlurper = new JsonSlurper() - def jsonTypes = jsonSlurper.parse(ntcoreTypesInputFile) - - ntcoreJavaTypesOutputDir.deleteDir() - ntcoreJavaTypesOutputDir.mkdirs() - - def config = new JinjavaConfig() - def jinjava = new Jinjava(config) - - ntcoreJavaTypesInputDir.listFiles().each { File file -> - def template = file.text - def outfn = file.name.substring(0, file.name.length() - 6) - if (file.name.startsWith("NetworkTable") || file.name.startsWith("Generic")) { - def replacements = new HashMap() - replacements.put("types", jsonTypes) - def output = jinjava.render(template, replacements) - new File(ntcoreJavaTypesOutputDir, outfn).write(output) - } else { - jsonTypes.each { Map replacements -> - def output = jinjava.render(template, replacements) - def typename = replacements.get("TypeName") - File outfile - if (outfn == "Timestamped.java") { - outfile = new File(ntcoreJavaTypesOutputDir, "Timestamped${typename}.java") - } else { - outfile = new File(ntcoreJavaTypesOutputDir, "${typename}${outfn}") - } - outfile.write(output) - } - } - } - } -} - -def ntcoreCppTypesInputDir = file("src/generate/include/networktables") -def ntcoreCppTypesOutputDir = file("$buildDir/generated/main/native/include/networktables") - -task ntcoreGenerateCppTypes() { - description = "Generates ntcore C++ type classes" - group = "WPILib" - - inputs.file ntcoreTypesInputFile - inputs.dir ntcoreCppTypesInputDir - outputs.dir ntcoreCppTypesOutputDir - - doLast { - def jsonSlurper = new JsonSlurper() - def jsonTypes = jsonSlurper.parse(ntcoreTypesInputFile) - - ntcoreCppTypesOutputDir.deleteDir() - ntcoreCppTypesOutputDir.mkdirs() - - def config = new JinjavaConfig() - def jinjava = new Jinjava(config) - - ntcoreCppTypesInputDir.listFiles().each { File file -> - def template = file.text - def outfn = file.name.substring(0, file.name.length() - 6) - jsonTypes.each { Map replacements -> - def output = jinjava.render(template, replacements) - def typename = replacements.get("TypeName") - def outfile = new File(ntcoreCppTypesOutputDir, "${typename}${outfn}") - outfile.write(output) - } - } - } -} - -def ntcoreCppHandleSourceInputFile = file("src/generate/cpp/ntcore_cpp_types.cpp.jinja") -def ntcoreCppHandleSourceOutputFile = file("$buildDir/generated/main/native/cpp/ntcore_cpp_types.cpp") - -task ntcoreGenerateCppHandleSource() { - description = "Generates ntcore C++ handle source" - group = "WPILib" - - inputs.files([ - ntcoreTypesInputFile, - ntcoreCppHandleSourceInputFile - ]) - outputs.file ntcoreCppHandleSourceOutputFile - - doLast { - def jsonSlurper = new JsonSlurper() - def jsonTypes = jsonSlurper.parse(ntcoreTypesInputFile) - - ntcoreCppHandleSourceOutputFile.delete() - - def config = new JinjavaConfig() - def jinjava = new Jinjava(config) - - def template = ntcoreCppHandleSourceInputFile.text - def replacements = new HashMap() - replacements.put("types", jsonTypes) - def output = jinjava.render(template, replacements) - ntcoreCppHandleSourceOutputFile.write(output) - } -} - -def ntcoreCppHandleHeaderInputFile = file("src/generate/include/ntcore_cpp_types.h.jinja") -def ntcoreCppHandleHeaderOutputFile = file("$buildDir/generated/main/native/include/ntcore_cpp_types.h") - -task ntcoreGenerateCppHandleHeader() { - description = "Generates ntcore C++ handle header" - group = "WPILib" - - inputs.files([ - ntcoreTypesInputFile, - ntcoreCppHandleHeaderInputFile - ]) - outputs.file ntcoreCppHandleHeaderOutputFile - - doLast { - def jsonSlurper = new JsonSlurper() - def jsonTypes = jsonSlurper.parse(ntcoreTypesInputFile) - - ntcoreCppHandleHeaderOutputFile.delete() - - def config = new JinjavaConfig() - def jinjava = new Jinjava(config) - - def template = ntcoreCppHandleHeaderInputFile.text - def replacements = new HashMap() - replacements.put("types", jsonTypes) - def output = jinjava.render(template, replacements) - ntcoreCppHandleHeaderOutputFile.write(output) - } -} - -def ntcoreCHandleSourceInputFile = file("src/generate/cpp/ntcore_c_types.cpp.jinja") -def ntcoreCHandleSourceOutputFile = file("$buildDir/generated/main/native/cpp/ntcore_c_types.cpp") - -task ntcoreGenerateCHandleSource() { - description = "Generates ntcore C handle source" - group = "WPILib" - - inputs.files([ - ntcoreTypesInputFile, - ntcoreCHandleSourceInputFile - ]) - outputs.file ntcoreCHandleSourceOutputFile - - doLast { - def jsonSlurper = new JsonSlurper() - def jsonTypes = jsonSlurper.parse(ntcoreTypesInputFile) - - ntcoreCHandleSourceOutputFile.delete() - - def config = new JinjavaConfig() - def jinjava = new Jinjava(config) - - def template = ntcoreCHandleSourceInputFile.text - def replacements = new HashMap() - replacements.put("types", jsonTypes) - def output = jinjava.render(template, replacements) - ntcoreCHandleSourceOutputFile.write(output) - } -} - -def ntcoreCHandleHeaderInputFile = file("src/generate/include/ntcore_c_types.h.jinja") -def ntcoreCHandleHeaderOutputFile = file("$buildDir/generated/main/native/include/ntcore_c_types.h") - -task ntcoreGenerateCHandleHeader() { - description = "Generates ntcore C handle header" - group = "WPILib" - - inputs.files([ - ntcoreTypesInputFile, - ntcoreCHandleHeaderInputFile - ]) - outputs.file ntcoreCHandleHeaderOutputFile - - doLast { - def jsonSlurper = new JsonSlurper() - def jsonTypes = jsonSlurper.parse(ntcoreTypesInputFile) - - ntcoreCHandleHeaderOutputFile.delete() - - def config = new JinjavaConfig() - def jinjava = new Jinjava(config) - - def template = ntcoreCHandleHeaderInputFile.text - def replacements = new HashMap() - replacements.put("types", jsonTypes) - def output = jinjava.render(template, replacements) - ntcoreCHandleHeaderOutputFile.write(output) - } -} - -def ntcoreJniSourceInputFile = file("src/generate/cpp/jni/types_jni.cpp.jinja") -def ntcoreJniSourceOutputFile = file("$buildDir/generated/main/native/cpp/jni/types_jni.cpp") - -task ntcoreGenerateJniSource() { - description = "Generates ntcore JNI types source" - group = "WPILib" - - inputs.files([ - ntcoreTypesInputFile, - ntcoreJniSourceInputFile - ]) - outputs.file ntcoreJniSourceOutputFile - - doLast { - def jsonSlurper = new JsonSlurper() - def jsonTypes = jsonSlurper.parse(ntcoreTypesInputFile) - - ntcoreJniSourceOutputFile.delete() - - def config = new JinjavaConfig() - def jinjava = new Jinjava(config) - - def template = ntcoreJniSourceInputFile.text - def replacements = new HashMap() - replacements.put("types", jsonTypes) - def output = jinjava.render(template, replacements) - ntcoreJniSourceOutputFile.write(output) - } -} - ext { addNtcoreDependency = { binary, shared-> - binary.tasks.withType(AbstractNativeSourceCompileTask) { - it.dependsOn ntcoreGenerateCppTypes - it.dependsOn ntcoreGenerateCppHandleHeader - it.dependsOn ntcoreGenerateCHandleHeader - } binary.lib project: ':ntcore', library: 'ntcore', linkage: shared } addNtcoreJniDependency = { binary-> - binary.tasks.withType(AbstractNativeSourceCompileTask) { - it.dependsOn ntcoreGenerateCppTypes - it.dependsOn ntcoreGenerateCppHandleHeader - it.dependsOn ntcoreGenerateCHandleHeader - } binary.lib project: ':ntcore', library: 'ntcoreJNIShared', linkage: 'shared' } nativeName = 'ntcore' devMain = 'edu.wpi.first.ntcore.DevMain' - generatedSources = "$buildDir/generated/main/native/cpp" - generatedHeaders = "$buildDir/generated/main/native/include" + generatedSources = "$projectDir/src/generated/main/native/cpp" + generatedHeaders = "$projectDir/src/generated/main/native/include" jniSplitSetup = { - it.tasks.withType(CppCompile) { - it.dependsOn ntcoreGenerateCppTypes - it.dependsOn ntcoreGenerateCppHandleSource - it.dependsOn ntcoreGenerateCppHandleHeader - it.dependsOn ntcoreGenerateCHandleSource - it.dependsOn ntcoreGenerateCHandleHeader - it.dependsOn ntcoreGenerateJniSource - } } splitSetup = { it.tasks.withType(CppCompile) { - it.dependsOn ntcoreGenerateCppTypes - it.dependsOn ntcoreGenerateCppHandleSource - it.dependsOn ntcoreGenerateCppHandleHeader - it.dependsOn ntcoreGenerateCHandleSource - it.dependsOn ntcoreGenerateCHandleHeader - it.dependsOn ntcoreGenerateJniSource it.includes 'src/main/native/cpp' } } exeSplitSetup = { - it.tasks.withType(CppCompile) { - it.dependsOn ntcoreGenerateCppTypes - it.dependsOn ntcoreGenerateCppHandleSource - it.dependsOn ntcoreGenerateCppHandleHeader - it.dependsOn ntcoreGenerateCHandleSource - it.dependsOn ntcoreGenerateCHandleHeader - } } } @@ -308,13 +42,9 @@ model { } } -sourceSets.main.java.srcDir "${buildDir}/generated/main/java" -compileJava.dependsOn ntcoreGenerateJavaTypes +sourceSets.main.java.srcDir "${projectDir}/src/generated/main/java" cppHeadersZip { - dependsOn ntcoreGenerateCppTypes - dependsOn ntcoreGenerateCppHandleHeader - dependsOn ntcoreGenerateCHandleHeader from(generatedHeaders) { into '/' } diff --git a/ntcore/generate_topics.py b/ntcore/generate_topics.py old mode 100644 new mode 100755 index ece7df2988..5afd61a722 --- a/ntcore/generate_topics.py +++ b/ntcore/generate_topics.py @@ -1,3 +1,5 @@ +#!/usr/bin/env python3 + import glob import os import sys @@ -17,23 +19,22 @@ def Output(outPath, outfn, contents): return # File either doesn't exist or has different contents - with open(outpathname, "w") as f: + with open(outpathname, "w", newline="\n") as f: f.write(contents) def main(): dirname, _ = os.path.split(os.path.abspath(__file__)) - cmake_binary_dir = sys.argv[1] with open(f"{dirname}/src/generate/types.json") as f: types = json.load(f) # Java files env = Environment( - loader=FileSystemLoader(f"{dirname}/src/generate/java"), autoescape=False + loader=FileSystemLoader(f"{dirname}/src/generate/main/java"), autoescape=False ) - rootPath = f"{cmake_binary_dir}/generated/main/java/edu/wpi/first/networktables" - for fn in glob.glob(f"{dirname}/src/generate/java/*.jinja"): + rootPath = f"{dirname}/src/generated/main/java/edu/wpi/first/networktables" + for fn in glob.glob(f"{dirname}/src/generate/main/java/*.jinja"): template = env.get_template(os.path.basename(fn)) outfn = os.path.basename(fn)[:-6] # drop ".jinja" if os.path.basename(fn).startswith("NetworkTable") or os.path.basename( @@ -52,11 +53,15 @@ def main(): # C++ classes env = Environment( - loader=FileSystemLoader(f"{dirname}/src/generate/include/networktables"), + loader=FileSystemLoader( + f"{dirname}/src/generate/main/native/include/networktables" + ), autoescape=False, ) - rootPath = f"{cmake_binary_dir}/generated/main/native/include/networktables" - for fn in glob.glob(f"{dirname}/src/generate/include/networktables/*.jinja"): + rootPath = f"{dirname}/src/generated/main/native/include/networktables" + for fn in glob.glob( + f"{dirname}/src/generate/main/native/include/networktables/*.jinja" + ): template = env.get_template(os.path.basename(fn)) outfn = os.path.basename(fn)[:-6] # drop ".jinja" for replacements in types: @@ -66,55 +71,56 @@ def main(): # C++ handle API (header) env = Environment( - loader=FileSystemLoader(f"{dirname}/src/generate/include"), autoescape=False + loader=FileSystemLoader(f"{dirname}/src/generate/main/native/include"), + autoescape=False, ) template = env.get_template("ntcore_cpp_types.h.jinja") output = template.render(types=types) Output( - f"{cmake_binary_dir}/generated/main/native/include", + f"{dirname}/src/generated/main/native/include", "ntcore_cpp_types.h", output, ) # C++ handle API (source) env = Environment( - loader=FileSystemLoader(f"{dirname}/src/generate/cpp"), autoescape=False + loader=FileSystemLoader(f"{dirname}/src/generate/main/native/cpp"), + autoescape=False, ) template = env.get_template("ntcore_cpp_types.cpp.jinja") output = template.render(types=types) - Output( - f"{cmake_binary_dir}/generated/main/native/cpp", "ntcore_cpp_types.cpp", output - ) + Output(f"{dirname}/src/generated/main/native/cpp", "ntcore_cpp_types.cpp", output) # C handle API (header) env = Environment( - loader=FileSystemLoader(f"{dirname}/src/generate/include"), autoescape=False + loader=FileSystemLoader(f"{dirname}/src/generate/main/native/include"), + autoescape=False, ) template = env.get_template("ntcore_c_types.h.jinja") output = template.render(types=types) Output( - f"{cmake_binary_dir}/generated/main/native/include", + f"{dirname}/src/generated/main/native/include", "ntcore_c_types.h", output, ) # C handle API (source) env = Environment( - loader=FileSystemLoader(f"{dirname}/src/generate/cpp"), autoescape=False + loader=FileSystemLoader(f"{dirname}/src/generate/main/native/cpp"), + autoescape=False, ) template = env.get_template("ntcore_c_types.cpp.jinja") output = template.render(types=types) - Output( - f"{cmake_binary_dir}/generated/main/native/cpp", "ntcore_c_types.cpp", output - ) + Output(f"{dirname}/src/generated/main/native/cpp", "ntcore_c_types.cpp", output) # JNI env = Environment( - loader=FileSystemLoader(f"{dirname}/src/generate/cpp/jni"), autoescape=False + loader=FileSystemLoader(f"{dirname}/src/generate/main/native/cpp/jni"), + autoescape=False, ) template = env.get_template("types_jni.cpp.jinja") output = template.render(types=types) - Output(f"{cmake_binary_dir}/generated/main/native/cpp/jni", "types_jni.cpp", output) + Output(f"{dirname}/src/generated/main/native/cpp/jni", "types_jni.cpp", output) if __name__ == "__main__": diff --git a/ntcore/src/generate/java/Entry.java.jinja b/ntcore/src/generate/main/java/Entry.java.jinja similarity index 87% rename from ntcore/src/generate/java/Entry.java.jinja rename to ntcore/src/generate/main/java/Entry.java.jinja index cbaa782c20..43c424f713 100644 --- a/ntcore/src/generate/java/Entry.java.jinja +++ b/ntcore/src/generate/main/java/Entry.java.jinja @@ -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. +// THIS FILE WAS AUTO-GENERATED BY ./ntcore/generate_topics.py. DO NOT MODIFY + package edu.wpi.first.networktables; /** @@ -13,3 +15,4 @@ public interface {{ TypeName }}Entry extends {{ TypeName }}Subscriber, {{ TypeNa /** Stops publishing the entry if it's published. */ void unpublish(); } + diff --git a/ntcore/src/generate/java/EntryImpl.java.jinja b/ntcore/src/generate/main/java/EntryImpl.java.jinja similarity index 97% rename from ntcore/src/generate/java/EntryImpl.java.jinja rename to ntcore/src/generate/main/java/EntryImpl.java.jinja index b7432a7e31..5053e10cdb 100644 --- a/ntcore/src/generate/java/EntryImpl.java.jinja +++ b/ntcore/src/generate/main/java/EntryImpl.java.jinja @@ -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. +// THIS FILE WAS AUTO-GENERATED BY ./ntcore/generate_topics.py. DO NOT MODIFY + package edu.wpi.first.networktables; {% if TypeName == "Raw" %} import java.nio.ByteBuffer; @@ -95,3 +97,4 @@ final class {{ TypeName }}EntryImpl extends EntryBase implements {{ TypeName }}E private final {{ TypeName }}Topic m_topic; private final {{ java.ValueType }} m_defaultValue; } + diff --git a/ntcore/src/generate/java/GenericEntryImpl.java.jinja b/ntcore/src/generate/main/java/GenericEntryImpl.java.jinja similarity index 99% rename from ntcore/src/generate/java/GenericEntryImpl.java.jinja rename to ntcore/src/generate/main/java/GenericEntryImpl.java.jinja index 29666bb79e..0bc4fed246 100644 --- a/ntcore/src/generate/java/GenericEntryImpl.java.jinja +++ b/ntcore/src/generate/main/java/GenericEntryImpl.java.jinja @@ -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. +// THIS FILE WAS AUTO-GENERATED BY ./ntcore/generate_topics.py. DO NOT MODIFY + package edu.wpi.first.networktables; import java.nio.ByteBuffer; @@ -373,3 +375,4 @@ final class GenericEntryImpl extends EntryBase implements GenericEntry { private final Topic m_topic; } + diff --git a/ntcore/src/generate/java/GenericPublisher.java.jinja b/ntcore/src/generate/main/java/GenericPublisher.java.jinja similarity index 98% rename from ntcore/src/generate/java/GenericPublisher.java.jinja rename to ntcore/src/generate/main/java/GenericPublisher.java.jinja index 881aba63d5..f6d7001733 100644 --- a/ntcore/src/generate/java/GenericPublisher.java.jinja +++ b/ntcore/src/generate/main/java/GenericPublisher.java.jinja @@ -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. +// THIS FILE WAS AUTO-GENERATED BY ./ntcore/generate_topics.py. DO NOT MODIFY + package edu.wpi.first.networktables; import java.nio.ByteBuffer; @@ -242,3 +244,4 @@ public interface GenericPublisher extends Publisher, Consumer set(value); } } + diff --git a/ntcore/src/generate/java/GenericSubscriber.java.jinja b/ntcore/src/generate/main/java/GenericSubscriber.java.jinja similarity index 96% rename from ntcore/src/generate/java/GenericSubscriber.java.jinja rename to ntcore/src/generate/main/java/GenericSubscriber.java.jinja index 63ecebcf20..c0ed6611a9 100644 --- a/ntcore/src/generate/java/GenericSubscriber.java.jinja +++ b/ntcore/src/generate/main/java/GenericSubscriber.java.jinja @@ -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. +// THIS FILE WAS AUTO-GENERATED BY ./ntcore/generate_topics.py. DO NOT MODIFY + package edu.wpi.first.networktables; import java.util.function.Supplier; @@ -56,3 +58,4 @@ public interface GenericSubscriber extends Subscriber, Supplier m_schemas = new ConcurrentHashMap<>(); } + diff --git a/ntcore/src/generate/java/NetworkTableValue.java.jinja b/ntcore/src/generate/main/java/NetworkTableValue.java.jinja similarity index 98% rename from ntcore/src/generate/java/NetworkTableValue.java.jinja rename to ntcore/src/generate/main/java/NetworkTableValue.java.jinja index d2c8d11fe2..cb97570a82 100644 --- a/ntcore/src/generate/java/NetworkTableValue.java.jinja +++ b/ntcore/src/generate/main/java/NetworkTableValue.java.jinja @@ -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. +// THIS FILE WAS AUTO-GENERATED BY ./ntcore/generate_topics.py. DO NOT MODIFY + package edu.wpi.first.networktables; import java.util.Objects; @@ -246,3 +248,4 @@ public final class NetworkTableValue { private long m_time; private long m_serverTime; } + diff --git a/ntcore/src/generate/java/NetworkTablesJNI.java.jinja b/ntcore/src/generate/main/java/NetworkTablesJNI.java.jinja similarity index 99% rename from ntcore/src/generate/java/NetworkTablesJNI.java.jinja rename to ntcore/src/generate/main/java/NetworkTablesJNI.java.jinja index 6ff9c1627b..00c2c30ef4 100644 --- a/ntcore/src/generate/java/NetworkTablesJNI.java.jinja +++ b/ntcore/src/generate/main/java/NetworkTablesJNI.java.jinja @@ -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. +// THIS FILE WAS AUTO-GENERATED BY ./ntcore/generate_topics.py. DO NOT MODIFY + package edu.wpi.first.networktables; import edu.wpi.first.util.RuntimeLoader; @@ -353,3 +355,4 @@ public final class NetworkTablesJNI { public static native int addLogger(int poller, int minLevel, int maxLevel); } + diff --git a/ntcore/src/generate/java/Publisher.java.jinja b/ntcore/src/generate/main/java/Publisher.java.jinja similarity index 98% rename from ntcore/src/generate/java/Publisher.java.jinja rename to ntcore/src/generate/main/java/Publisher.java.jinja index a403d910fc..d35c941311 100644 --- a/ntcore/src/generate/java/Publisher.java.jinja +++ b/ntcore/src/generate/main/java/Publisher.java.jinja @@ -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. +// THIS FILE WAS AUTO-GENERATED BY ./ntcore/generate_topics.py. DO NOT MODIFY + package edu.wpi.first.networktables; {% if TypeName == "Raw" %} @@ -168,3 +170,4 @@ public interface {{ TypeName }}Publisher extends Publisher, {{ java.FunctionType set(value); } } + diff --git a/ntcore/src/generate/java/Subscriber.java.jinja b/ntcore/src/generate/main/java/Subscriber.java.jinja similarity index 97% rename from ntcore/src/generate/java/Subscriber.java.jinja rename to ntcore/src/generate/main/java/Subscriber.java.jinja index 0ea09a36e6..73e6190379 100644 --- a/ntcore/src/generate/java/Subscriber.java.jinja +++ b/ntcore/src/generate/main/java/Subscriber.java.jinja @@ -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. +// THIS FILE WAS AUTO-GENERATED BY ./ntcore/generate_topics.py. DO NOT MODIFY + package edu.wpi.first.networktables; import {{ java.SupplierFunctionPackage|default('java.util.function') }}.{{ java.FunctionTypePrefix }}Supplier; @@ -81,3 +83,4 @@ public interface {{ TypeName }}Subscriber extends Subscriber, {{ java.FunctionTy */ {{ java.ValueType }}[] readQueueValues(); } + diff --git a/ntcore/src/generate/java/Timestamped.java.jinja b/ntcore/src/generate/main/java/Timestamped.java.jinja similarity index 93% rename from ntcore/src/generate/java/Timestamped.java.jinja rename to ntcore/src/generate/main/java/Timestamped.java.jinja index 288af81b79..21e50e244f 100644 --- a/ntcore/src/generate/java/Timestamped.java.jinja +++ b/ntcore/src/generate/main/java/Timestamped.java.jinja @@ -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. +// THIS FILE WAS AUTO-GENERATED BY ./ntcore/generate_topics.py. DO NOT MODIFY + package edu.wpi.first.networktables; /** NetworkTables timestamped {{ TypeName }}. */ @@ -38,3 +40,4 @@ public final class Timestamped{{ TypeName }} { @SuppressWarnings("MemberName") public final {{ java.ValueType }} value; } + diff --git a/ntcore/src/generate/java/Topic.java.jinja b/ntcore/src/generate/main/java/Topic.java.jinja similarity index 99% rename from ntcore/src/generate/java/Topic.java.jinja rename to ntcore/src/generate/main/java/Topic.java.jinja index e22fa3baf8..6407a4b18e 100644 --- a/ntcore/src/generate/java/Topic.java.jinja +++ b/ntcore/src/generate/main/java/Topic.java.jinja @@ -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. +// THIS FILE WAS AUTO-GENERATED BY ./ntcore/generate_topics.py. DO NOT MODIFY + package edu.wpi.first.networktables; /** NetworkTables {{ TypeName }} topic. */ @@ -221,3 +223,4 @@ public final class {{ TypeName }}Topic extends Topic { } {% endif %} } + diff --git a/ntcore/src/generate/cpp/jni/types_jni.cpp.jinja b/ntcore/src/generate/main/native/cpp/jni/types_jni.cpp.jinja similarity index 99% rename from ntcore/src/generate/cpp/jni/types_jni.cpp.jinja rename to ntcore/src/generate/main/native/cpp/jni/types_jni.cpp.jinja index 29cf570377..fc811f54cd 100644 --- a/ntcore/src/generate/cpp/jni/types_jni.cpp.jinja +++ b/ntcore/src/generate/main/native/cpp/jni/types_jni.cpp.jinja @@ -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. +// THIS FILE WAS AUTO-GENERATED BY ./ntcore/generate_topics.py. DO NOT MODIFY + #include #include @@ -367,3 +369,4 @@ Java_edu_wpi_first_networktables_NetworkTablesJNI_setDefault{{ t.TypeName }} {% endif %} {% endfor %} } // extern "C" + diff --git a/ntcore/src/generate/cpp/ntcore_c_types.cpp.jinja b/ntcore/src/generate/main/native/cpp/ntcore_c_types.cpp.jinja similarity index 97% rename from ntcore/src/generate/cpp/ntcore_c_types.cpp.jinja rename to ntcore/src/generate/main/native/cpp/ntcore_c_types.cpp.jinja index e74e5cf776..a22563464c 100644 --- a/ntcore/src/generate/cpp/ntcore_c_types.cpp.jinja +++ b/ntcore/src/generate/main/native/cpp/ntcore_c_types.cpp.jinja @@ -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. +// THIS FILE WAS AUTO-GENERATED BY ./ntcore/generate_topics.py. DO NOT MODIFY + #include "ntcore_c_types.h" #include "Value_internal.h" @@ -104,3 +106,4 @@ void NT_FreeQueue{{ t.TypeName }}(struct NT_Timestamped{{ t.TypeName }}* arr, si {% endfor %} } // extern "C" + diff --git a/ntcore/src/generate/cpp/ntcore_cpp_types.cpp.jinja b/ntcore/src/generate/main/native/cpp/ntcore_cpp_types.cpp.jinja similarity index 98% rename from ntcore/src/generate/cpp/ntcore_cpp_types.cpp.jinja rename to ntcore/src/generate/main/native/cpp/ntcore_cpp_types.cpp.jinja index cdaf27fb6e..d9501f899a 100644 --- a/ntcore/src/generate/cpp/ntcore_cpp_types.cpp.jinja +++ b/ntcore/src/generate/main/native/cpp/ntcore_cpp_types.cpp.jinja @@ -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. +// THIS FILE WAS AUTO-GENERATED BY ./ntcore/generate_topics.py. DO NOT MODIFY + #include "ntcore_cpp_types.h" #include "Handle.h" @@ -129,3 +131,4 @@ Timestamped{{ t.TypeName }}View GetAtomic{{ t.TypeName }}( {% endif %} {% endfor %} } // namespace nt + diff --git a/ntcore/src/generate/include/networktables/Topic.h.jinja b/ntcore/src/generate/main/native/include/networktables/Topic.h.jinja similarity index 99% rename from ntcore/src/generate/include/networktables/Topic.h.jinja rename to ntcore/src/generate/main/native/include/networktables/Topic.h.jinja index ec2a915ee6..93abc49871 100644 --- a/ntcore/src/generate/include/networktables/Topic.h.jinja +++ b/ntcore/src/generate/main/native/include/networktables/Topic.h.jinja @@ -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. +// THIS FILE WAS AUTO-GENERATED BY ./ntcore/generate_topics.py. DO NOT MODIFY + #pragma once #include @@ -435,3 +437,4 @@ class {{ TypeName }}Topic final : public Topic { } // namespace nt #include "networktables/{{ TypeName }}Topic.inc" + diff --git a/ntcore/src/generate/include/networktables/Topic.inc.jinja b/ntcore/src/generate/main/native/include/networktables/Topic.inc.jinja similarity index 98% rename from ntcore/src/generate/include/networktables/Topic.inc.jinja rename to ntcore/src/generate/main/native/include/networktables/Topic.inc.jinja index 4e7a167d67..ce343d99fe 100644 --- a/ntcore/src/generate/include/networktables/Topic.inc.jinja +++ b/ntcore/src/generate/main/native/include/networktables/Topic.inc.jinja @@ -2,8 +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. +// THIS FILE WAS AUTO-GENERATED BY ./ntcore/generate_topics.py. DO NOT MODIFY + #pragma once +#include + #include "networktables/{{ TypeName }}Topic.h" #include "networktables/NetworkTableType.h" #include "ntcore_cpp.h" @@ -133,3 +137,4 @@ inline {{ TypeName }}Entry {{ TypeName }}Topic::GetEntryEx( } {% endif %} } // namespace nt + diff --git a/ntcore/src/generate/include/ntcore_c_types.h.jinja b/ntcore/src/generate/main/native/include/ntcore_c_types.h.jinja similarity index 98% rename from ntcore/src/generate/include/ntcore_c_types.h.jinja rename to ntcore/src/generate/main/native/include/ntcore_c_types.h.jinja index 83cc807353..22866fbe6e 100644 --- a/ntcore/src/generate/include/ntcore_c_types.h.jinja +++ b/ntcore/src/generate/main/native/include/ntcore_c_types.h.jinja @@ -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. +// THIS FILE WAS AUTO-GENERATED BY ./ntcore/generate_topics.py. DO NOT MODIFY + #pragma once #include @@ -149,3 +151,4 @@ void NT_FreeQueue{{ t.TypeName }}(struct NT_Timestamped{{ t.TypeName }}* arr, si #ifdef __cplusplus } // extern "C" #endif + diff --git a/ntcore/src/generate/include/ntcore_cpp_types.h.jinja b/ntcore/src/generate/main/native/include/ntcore_cpp_types.h.jinja similarity index 98% rename from ntcore/src/generate/include/ntcore_cpp_types.h.jinja rename to ntcore/src/generate/main/native/include/ntcore_cpp_types.h.jinja index df919de05a..941414d671 100644 --- a/ntcore/src/generate/include/ntcore_cpp_types.h.jinja +++ b/ntcore/src/generate/main/native/include/ntcore_cpp_types.h.jinja @@ -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. +// THIS FILE WAS AUTO-GENERATED BY ./ntcore/generate_topics.py. DO NOT MODIFY + #pragma once #include @@ -139,3 +141,4 @@ Timestamped{{ t.TypeName }}View GetAtomic{{ t.TypeName }}( /** @} */ {% endfor %} } // namespace nt + diff --git a/ntcore/src/generated/main/java/edu/wpi/first/networktables/BooleanArrayEntry.java b/ntcore/src/generated/main/java/edu/wpi/first/networktables/BooleanArrayEntry.java new file mode 100644 index 0000000000..bcc72e06c3 --- /dev/null +++ b/ntcore/src/generated/main/java/edu/wpi/first/networktables/BooleanArrayEntry.java @@ -0,0 +1,17 @@ +// 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. + +// THIS FILE WAS AUTO-GENERATED BY ./ntcore/generate_topics.py. DO NOT MODIFY + +package edu.wpi.first.networktables; + +/** + * NetworkTables BooleanArray entry. + * + *

Unlike NetworkTableEntry, the entry goes away when close() is called. + */ +public interface BooleanArrayEntry extends BooleanArraySubscriber, BooleanArrayPublisher { + /** Stops publishing the entry if it's published. */ + void unpublish(); +} diff --git a/ntcore/src/generated/main/java/edu/wpi/first/networktables/BooleanArrayEntryImpl.java b/ntcore/src/generated/main/java/edu/wpi/first/networktables/BooleanArrayEntryImpl.java new file mode 100644 index 0000000000..40e455ccac --- /dev/null +++ b/ntcore/src/generated/main/java/edu/wpi/first/networktables/BooleanArrayEntryImpl.java @@ -0,0 +1,77 @@ +// 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. + +// THIS FILE WAS AUTO-GENERATED BY ./ntcore/generate_topics.py. DO NOT MODIFY + +package edu.wpi.first.networktables; + +/** NetworkTables BooleanArray implementation. */ +@SuppressWarnings("PMD.ArrayIsStoredDirectly") +final class BooleanArrayEntryImpl extends EntryBase implements BooleanArrayEntry { + /** + * Constructor. + * + * @param topic Topic + * @param handle Native handle + * @param defaultValue Default value for get() + */ + BooleanArrayEntryImpl(BooleanArrayTopic topic, int handle, boolean[] defaultValue) { + super(handle); + m_topic = topic; + m_defaultValue = defaultValue; + } + + @Override + public BooleanArrayTopic getTopic() { + return m_topic; + } + + @Override + public boolean[] get() { + return NetworkTablesJNI.getBooleanArray(m_handle, m_defaultValue); + } + + @Override + public boolean[] get(boolean[] defaultValue) { + return NetworkTablesJNI.getBooleanArray(m_handle, defaultValue); + } + + @Override + public TimestampedBooleanArray getAtomic() { + return NetworkTablesJNI.getAtomicBooleanArray(m_handle, m_defaultValue); + } + + @Override + public TimestampedBooleanArray getAtomic(boolean[] defaultValue) { + return NetworkTablesJNI.getAtomicBooleanArray(m_handle, defaultValue); + } + + @Override + public TimestampedBooleanArray[] readQueue() { + return NetworkTablesJNI.readQueueBooleanArray(m_handle); + } + + @Override + public boolean[][] readQueueValues() { + return NetworkTablesJNI.readQueueValuesBooleanArray(m_handle); + } + + @Override + public void set(boolean[] value, long time) { + NetworkTablesJNI.setBooleanArray(m_handle, time, value); + } + + @Override + public void setDefault(boolean[] value) { + NetworkTablesJNI.setDefaultBooleanArray(m_handle, 0, value); + } + + @Override + public void unpublish() { + NetworkTablesJNI.unpublish(m_handle); + } + + private final BooleanArrayTopic m_topic; + private final boolean[] m_defaultValue; +} diff --git a/ntcore/src/generated/main/java/edu/wpi/first/networktables/BooleanArrayPublisher.java b/ntcore/src/generated/main/java/edu/wpi/first/networktables/BooleanArrayPublisher.java new file mode 100644 index 0000000000..3e40bdbb92 --- /dev/null +++ b/ntcore/src/generated/main/java/edu/wpi/first/networktables/BooleanArrayPublisher.java @@ -0,0 +1,52 @@ +// 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. + +// THIS FILE WAS AUTO-GENERATED BY ./ntcore/generate_topics.py. DO NOT MODIFY + +package edu.wpi.first.networktables; + +import java.util.function.Consumer; + +/** NetworkTables BooleanArray publisher. */ +public interface BooleanArrayPublisher extends Publisher, Consumer { + /** + * Get the corresponding topic. + * + * @return Topic + */ + @Override + BooleanArrayTopic getTopic(); + + /** + * Publish a new value using current NT time. + * + * @param value value to publish + */ + default void set(boolean[] value) { + set(value, 0); + } + + + /** + * Publish a new value. + * + * @param value value to publish + * @param time timestamp; 0 indicates current NT time should be used + */ + void set(boolean[] value, long time); + + /** + * Publish a default value. + * On reconnect, a default value will never be used in preference to a + * published value. + * + * @param value value + */ + void setDefault(boolean[] value); + + @Override + default void accept(boolean[] value) { + set(value); + } +} diff --git a/ntcore/src/generated/main/java/edu/wpi/first/networktables/BooleanArraySubscriber.java b/ntcore/src/generated/main/java/edu/wpi/first/networktables/BooleanArraySubscriber.java new file mode 100644 index 0000000000..ff07119840 --- /dev/null +++ b/ntcore/src/generated/main/java/edu/wpi/first/networktables/BooleanArraySubscriber.java @@ -0,0 +1,80 @@ +// 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. + +// THIS FILE WAS AUTO-GENERATED BY ./ntcore/generate_topics.py. DO NOT MODIFY + +package edu.wpi.first.networktables; + +import java.util.function.Supplier; + +/** NetworkTables BooleanArray subscriber. */ +@SuppressWarnings("PMD.MissingOverride") +public interface BooleanArraySubscriber extends Subscriber, Supplier { + /** + * Get the corresponding topic. + * + * @return Topic + */ + @Override + BooleanArrayTopic getTopic(); + + /** + * Get the last published value. + * If no value has been published, returns the stored default value. + * + * @return value + */ + boolean[] get(); + + /** + * Get the last published value. + * If no value has been published, returns the passed defaultValue. + * + * @param defaultValue default value to return if no value has been published + * @return value + */ + boolean[] get(boolean[] defaultValue); + + /** + * Get the last published value along with its timestamp + * If no value has been published, returns the stored default value and a + * timestamp of 0. + * + * @return timestamped value + */ + TimestampedBooleanArray getAtomic(); + + /** + * Get the last published value along with its timestamp + * If no value has been published, returns the passed defaultValue and a + * timestamp of 0. + * + * @param defaultValue default value to return if no value has been published + * @return timestamped value + */ + TimestampedBooleanArray getAtomic(boolean[] defaultValue); + + /** + * Get an array of all value changes since the last call to readQueue. + * Also provides a timestamp for each value. + * + *

The "poll storage" subscribe option can be used to set the queue + * depth. + * + * @return Array of timestamped values; empty array if no new changes have + * been published since the previous call. + */ + TimestampedBooleanArray[] readQueue(); + + /** + * Get an array of all value changes since the last call to readQueue. + * + *

The "poll storage" subscribe option can be used to set the queue + * depth. + * + * @return Array of values; empty array if no new changes have been + * published since the previous call. + */ + boolean[][] readQueueValues(); +} diff --git a/ntcore/src/generated/main/java/edu/wpi/first/networktables/BooleanArrayTopic.java b/ntcore/src/generated/main/java/edu/wpi/first/networktables/BooleanArrayTopic.java new file mode 100644 index 0000000000..7d18f31287 --- /dev/null +++ b/ntcore/src/generated/main/java/edu/wpi/first/networktables/BooleanArrayTopic.java @@ -0,0 +1,206 @@ +// 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. + +// THIS FILE WAS AUTO-GENERATED BY ./ntcore/generate_topics.py. DO NOT MODIFY + +package edu.wpi.first.networktables; + +/** NetworkTables BooleanArray topic. */ +public final class BooleanArrayTopic extends Topic { + /** The default type string for this topic type. */ + public static final String kTypeString = "boolean[]"; + + /** + * Construct from a generic topic. + * + * @param topic Topic + */ + public BooleanArrayTopic(Topic topic) { + super(topic.m_inst, topic.m_handle); + } + + /** + * Constructor; use NetworkTableInstance.getBooleanArrayTopic() instead. + * + * @param inst Instance + * @param handle Native handle + */ + public BooleanArrayTopic(NetworkTableInstance inst, int handle) { + super(inst, handle); + } + + /** + * Create a new subscriber to the topic. + * + *

The subscriber is only active as long as the returned object + * is not closed. + * + *

Subscribers that do not match the published data type do not return + * any values. To determine if the data type matches, use the appropriate + * Topic functions. + * + * @param defaultValue default value used when a default is not provided to a + * getter function + * @param options subscribe options + * @return subscriber + */ + public BooleanArraySubscriber subscribe( + boolean[] defaultValue, + PubSubOption... options) { + return new BooleanArrayEntryImpl( + this, + NetworkTablesJNI.subscribe( + m_handle, NetworkTableType.kBooleanArray.getValue(), + "boolean[]", options), + defaultValue); + } + + /** + * Create a new subscriber to the topic, with specified type string. + * + *

The subscriber is only active as long as the returned object + * is not closed. + * + *

Subscribers that do not match the published data type do not return + * any values. To determine if the data type matches, use the appropriate + * Topic functions. + * + * @param typeString type string + * @param defaultValue default value used when a default is not provided to a + * getter function + * @param options subscribe options + * @return subscriber + */ + public BooleanArraySubscriber subscribeEx( + String typeString, + boolean[] defaultValue, + PubSubOption... options) { + return new BooleanArrayEntryImpl( + this, + NetworkTablesJNI.subscribe( + m_handle, NetworkTableType.kBooleanArray.getValue(), + typeString, options), + defaultValue); + } + + /** + * Create a new publisher to the topic. + * + *

The publisher is only active as long as the returned object + * is not closed. + * + *

It is not possible to publish two different data types to the same + * topic. Conflicts between publishers are typically resolved by the server on + * a first-come, first-served basis. Any published values that do not match + * the topic's data type are dropped (ignored). To determine if the data type + * matches, use the appropriate Topic functions. + * + * @param options publish options + * @return publisher + */ + public BooleanArrayPublisher publish( + PubSubOption... options) { + return new BooleanArrayEntryImpl( + this, + NetworkTablesJNI.publish( + m_handle, NetworkTableType.kBooleanArray.getValue(), + "boolean[]", options), + new boolean[] {}); + } + + /** + * Create a new publisher to the topic, with type string and initial properties. + * + *

The publisher is only active as long as the returned object + * is not closed. + * + *

It is not possible to publish two different data types to the same + * topic. Conflicts between publishers are typically resolved by the server on + * a first-come, first-served basis. Any published values that do not match + * the topic's data type are dropped (ignored). To determine if the data type + * matches, use the appropriate Topic functions. + * + * @param typeString type string + * @param properties JSON properties + * @param options publish options + * @return publisher + * @throws IllegalArgumentException if properties is not a JSON object + */ + public BooleanArrayPublisher publishEx( + String typeString, + String properties, + PubSubOption... options) { + return new BooleanArrayEntryImpl( + this, + NetworkTablesJNI.publishEx( + m_handle, NetworkTableType.kBooleanArray.getValue(), + typeString, properties, options), + new boolean[] {}); + } + + /** + * Create a new entry for the topic. + * + *

Entries act as a combination of a subscriber and a weak publisher. The + * subscriber is active as long as the entry is not closed. The publisher is + * created when the entry is first written to, and remains active until either + * unpublish() is called or the entry is closed. + * + *

It is not possible to use two different data types with the same + * topic. Conflicts between publishers are typically resolved by the server on + * a first-come, first-served basis. Any published values that do not match + * the topic's data type are dropped (ignored), and the entry will show no new + * values if the data type does not match. To determine if the data type + * matches, use the appropriate Topic functions. + * + * @param defaultValue default value used when a default is not provided to a + * getter function + * @param options publish and/or subscribe options + * @return entry + */ + public BooleanArrayEntry getEntry( + boolean[] defaultValue, + PubSubOption... options) { + return new BooleanArrayEntryImpl( + this, + NetworkTablesJNI.getEntry( + m_handle, NetworkTableType.kBooleanArray.getValue(), + "boolean[]", options), + defaultValue); + } + + /** + * Create a new entry for the topic, with specified type string. + * + *

Entries act as a combination of a subscriber and a weak publisher. The + * subscriber is active as long as the entry is not closed. The publisher is + * created when the entry is first written to, and remains active until either + * unpublish() is called or the entry is closed. + * + *

It is not possible to use two different data types with the same + * topic. Conflicts between publishers are typically resolved by the server on + * a first-come, first-served basis. Any published values that do not match + * the topic's data type are dropped (ignored), and the entry will show no new + * values if the data type does not match. To determine if the data type + * matches, use the appropriate Topic functions. + * + * @param typeString type string + * @param defaultValue default value used when a default is not provided to a + * getter function + * @param options publish and/or subscribe options + * @return entry + */ + public BooleanArrayEntry getEntryEx( + String typeString, + boolean[] defaultValue, + PubSubOption... options) { + return new BooleanArrayEntryImpl( + this, + NetworkTablesJNI.getEntry( + m_handle, NetworkTableType.kBooleanArray.getValue(), + typeString, options), + defaultValue); + } + +} diff --git a/ntcore/src/generated/main/java/edu/wpi/first/networktables/BooleanEntry.java b/ntcore/src/generated/main/java/edu/wpi/first/networktables/BooleanEntry.java new file mode 100644 index 0000000000..1821c06a38 --- /dev/null +++ b/ntcore/src/generated/main/java/edu/wpi/first/networktables/BooleanEntry.java @@ -0,0 +1,17 @@ +// 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. + +// THIS FILE WAS AUTO-GENERATED BY ./ntcore/generate_topics.py. DO NOT MODIFY + +package edu.wpi.first.networktables; + +/** + * NetworkTables Boolean entry. + * + *

Unlike NetworkTableEntry, the entry goes away when close() is called. + */ +public interface BooleanEntry extends BooleanSubscriber, BooleanPublisher { + /** Stops publishing the entry if it's published. */ + void unpublish(); +} diff --git a/ntcore/src/generated/main/java/edu/wpi/first/networktables/BooleanEntryImpl.java b/ntcore/src/generated/main/java/edu/wpi/first/networktables/BooleanEntryImpl.java new file mode 100644 index 0000000000..f099afc0da --- /dev/null +++ b/ntcore/src/generated/main/java/edu/wpi/first/networktables/BooleanEntryImpl.java @@ -0,0 +1,77 @@ +// 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. + +// THIS FILE WAS AUTO-GENERATED BY ./ntcore/generate_topics.py. DO NOT MODIFY + +package edu.wpi.first.networktables; + +/** NetworkTables Boolean implementation. */ +@SuppressWarnings("PMD.ArrayIsStoredDirectly") +final class BooleanEntryImpl extends EntryBase implements BooleanEntry { + /** + * Constructor. + * + * @param topic Topic + * @param handle Native handle + * @param defaultValue Default value for get() + */ + BooleanEntryImpl(BooleanTopic topic, int handle, boolean defaultValue) { + super(handle); + m_topic = topic; + m_defaultValue = defaultValue; + } + + @Override + public BooleanTopic getTopic() { + return m_topic; + } + + @Override + public boolean get() { + return NetworkTablesJNI.getBoolean(m_handle, m_defaultValue); + } + + @Override + public boolean get(boolean defaultValue) { + return NetworkTablesJNI.getBoolean(m_handle, defaultValue); + } + + @Override + public TimestampedBoolean getAtomic() { + return NetworkTablesJNI.getAtomicBoolean(m_handle, m_defaultValue); + } + + @Override + public TimestampedBoolean getAtomic(boolean defaultValue) { + return NetworkTablesJNI.getAtomicBoolean(m_handle, defaultValue); + } + + @Override + public TimestampedBoolean[] readQueue() { + return NetworkTablesJNI.readQueueBoolean(m_handle); + } + + @Override + public boolean[] readQueueValues() { + return NetworkTablesJNI.readQueueValuesBoolean(m_handle); + } + + @Override + public void set(boolean value, long time) { + NetworkTablesJNI.setBoolean(m_handle, time, value); + } + + @Override + public void setDefault(boolean value) { + NetworkTablesJNI.setDefaultBoolean(m_handle, 0, value); + } + + @Override + public void unpublish() { + NetworkTablesJNI.unpublish(m_handle); + } + + private final BooleanTopic m_topic; + private final boolean m_defaultValue; +} diff --git a/ntcore/src/generated/main/java/edu/wpi/first/networktables/BooleanPublisher.java b/ntcore/src/generated/main/java/edu/wpi/first/networktables/BooleanPublisher.java new file mode 100644 index 0000000000..1254ff333d --- /dev/null +++ b/ntcore/src/generated/main/java/edu/wpi/first/networktables/BooleanPublisher.java @@ -0,0 +1,52 @@ +// 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. + +// THIS FILE WAS AUTO-GENERATED BY ./ntcore/generate_topics.py. DO NOT MODIFY + +package edu.wpi.first.networktables; + +import edu.wpi.first.util.function.BooleanConsumer; + +/** NetworkTables Boolean publisher. */ +public interface BooleanPublisher extends Publisher, BooleanConsumer { + /** + * Get the corresponding topic. + * + * @return Topic + */ + @Override + BooleanTopic getTopic(); + + /** + * Publish a new value using current NT time. + * + * @param value value to publish + */ + default void set(boolean value) { + set(value, 0); + } + + + /** + * Publish a new value. + * + * @param value value to publish + * @param time timestamp; 0 indicates current NT time should be used + */ + void set(boolean value, long time); + + /** + * Publish a default value. + * On reconnect, a default value will never be used in preference to a + * published value. + * + * @param value value + */ + void setDefault(boolean value); + + @Override + default void accept(boolean value) { + set(value); + } +} diff --git a/ntcore/src/generated/main/java/edu/wpi/first/networktables/BooleanSubscriber.java b/ntcore/src/generated/main/java/edu/wpi/first/networktables/BooleanSubscriber.java new file mode 100644 index 0000000000..7f54f4b3fd --- /dev/null +++ b/ntcore/src/generated/main/java/edu/wpi/first/networktables/BooleanSubscriber.java @@ -0,0 +1,85 @@ +// 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. + +// THIS FILE WAS AUTO-GENERATED BY ./ntcore/generate_topics.py. DO NOT MODIFY + +package edu.wpi.first.networktables; + +import java.util.function.BooleanSupplier; + +/** NetworkTables Boolean subscriber. */ +@SuppressWarnings("PMD.MissingOverride") +public interface BooleanSubscriber extends Subscriber, BooleanSupplier { + /** + * Get the corresponding topic. + * + * @return Topic + */ + @Override + BooleanTopic getTopic(); + + /** + * Get the last published value. + * If no value has been published, returns the stored default value. + * + * @return value + */ + boolean get(); + + /** + * Get the last published value. + * If no value has been published, returns the passed defaultValue. + * + * @param defaultValue default value to return if no value has been published + * @return value + */ + boolean get(boolean defaultValue); + + @Override + default boolean getAsBoolean() { + return get(); + } + + /** + * Get the last published value along with its timestamp + * If no value has been published, returns the stored default value and a + * timestamp of 0. + * + * @return timestamped value + */ + TimestampedBoolean getAtomic(); + + /** + * Get the last published value along with its timestamp + * If no value has been published, returns the passed defaultValue and a + * timestamp of 0. + * + * @param defaultValue default value to return if no value has been published + * @return timestamped value + */ + TimestampedBoolean getAtomic(boolean defaultValue); + + /** + * Get an array of all value changes since the last call to readQueue. + * Also provides a timestamp for each value. + * + *

The "poll storage" subscribe option can be used to set the queue + * depth. + * + * @return Array of timestamped values; empty array if no new changes have + * been published since the previous call. + */ + TimestampedBoolean[] readQueue(); + + /** + * Get an array of all value changes since the last call to readQueue. + * + *

The "poll storage" subscribe option can be used to set the queue + * depth. + * + * @return Array of values; empty array if no new changes have been + * published since the previous call. + */ + boolean[] readQueueValues(); +} diff --git a/ntcore/src/generated/main/java/edu/wpi/first/networktables/BooleanTopic.java b/ntcore/src/generated/main/java/edu/wpi/first/networktables/BooleanTopic.java new file mode 100644 index 0000000000..8ac03473e7 --- /dev/null +++ b/ntcore/src/generated/main/java/edu/wpi/first/networktables/BooleanTopic.java @@ -0,0 +1,206 @@ +// 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. + +// THIS FILE WAS AUTO-GENERATED BY ./ntcore/generate_topics.py. DO NOT MODIFY + +package edu.wpi.first.networktables; + +/** NetworkTables Boolean topic. */ +public final class BooleanTopic extends Topic { + /** The default type string for this topic type. */ + public static final String kTypeString = "boolean"; + + /** + * Construct from a generic topic. + * + * @param topic Topic + */ + public BooleanTopic(Topic topic) { + super(topic.m_inst, topic.m_handle); + } + + /** + * Constructor; use NetworkTableInstance.getBooleanTopic() instead. + * + * @param inst Instance + * @param handle Native handle + */ + public BooleanTopic(NetworkTableInstance inst, int handle) { + super(inst, handle); + } + + /** + * Create a new subscriber to the topic. + * + *

The subscriber is only active as long as the returned object + * is not closed. + * + *

Subscribers that do not match the published data type do not return + * any values. To determine if the data type matches, use the appropriate + * Topic functions. + * + * @param defaultValue default value used when a default is not provided to a + * getter function + * @param options subscribe options + * @return subscriber + */ + public BooleanSubscriber subscribe( + boolean defaultValue, + PubSubOption... options) { + return new BooleanEntryImpl( + this, + NetworkTablesJNI.subscribe( + m_handle, NetworkTableType.kBoolean.getValue(), + "boolean", options), + defaultValue); + } + + /** + * Create a new subscriber to the topic, with specified type string. + * + *

The subscriber is only active as long as the returned object + * is not closed. + * + *

Subscribers that do not match the published data type do not return + * any values. To determine if the data type matches, use the appropriate + * Topic functions. + * + * @param typeString type string + * @param defaultValue default value used when a default is not provided to a + * getter function + * @param options subscribe options + * @return subscriber + */ + public BooleanSubscriber subscribeEx( + String typeString, + boolean defaultValue, + PubSubOption... options) { + return new BooleanEntryImpl( + this, + NetworkTablesJNI.subscribe( + m_handle, NetworkTableType.kBoolean.getValue(), + typeString, options), + defaultValue); + } + + /** + * Create a new publisher to the topic. + * + *

The publisher is only active as long as the returned object + * is not closed. + * + *

It is not possible to publish two different data types to the same + * topic. Conflicts between publishers are typically resolved by the server on + * a first-come, first-served basis. Any published values that do not match + * the topic's data type are dropped (ignored). To determine if the data type + * matches, use the appropriate Topic functions. + * + * @param options publish options + * @return publisher + */ + public BooleanPublisher publish( + PubSubOption... options) { + return new BooleanEntryImpl( + this, + NetworkTablesJNI.publish( + m_handle, NetworkTableType.kBoolean.getValue(), + "boolean", options), + false); + } + + /** + * Create a new publisher to the topic, with type string and initial properties. + * + *

The publisher is only active as long as the returned object + * is not closed. + * + *

It is not possible to publish two different data types to the same + * topic. Conflicts between publishers are typically resolved by the server on + * a first-come, first-served basis. Any published values that do not match + * the topic's data type are dropped (ignored). To determine if the data type + * matches, use the appropriate Topic functions. + * + * @param typeString type string + * @param properties JSON properties + * @param options publish options + * @return publisher + * @throws IllegalArgumentException if properties is not a JSON object + */ + public BooleanPublisher publishEx( + String typeString, + String properties, + PubSubOption... options) { + return new BooleanEntryImpl( + this, + NetworkTablesJNI.publishEx( + m_handle, NetworkTableType.kBoolean.getValue(), + typeString, properties, options), + false); + } + + /** + * Create a new entry for the topic. + * + *

Entries act as a combination of a subscriber and a weak publisher. The + * subscriber is active as long as the entry is not closed. The publisher is + * created when the entry is first written to, and remains active until either + * unpublish() is called or the entry is closed. + * + *

It is not possible to use two different data types with the same + * topic. Conflicts between publishers are typically resolved by the server on + * a first-come, first-served basis. Any published values that do not match + * the topic's data type are dropped (ignored), and the entry will show no new + * values if the data type does not match. To determine if the data type + * matches, use the appropriate Topic functions. + * + * @param defaultValue default value used when a default is not provided to a + * getter function + * @param options publish and/or subscribe options + * @return entry + */ + public BooleanEntry getEntry( + boolean defaultValue, + PubSubOption... options) { + return new BooleanEntryImpl( + this, + NetworkTablesJNI.getEntry( + m_handle, NetworkTableType.kBoolean.getValue(), + "boolean", options), + defaultValue); + } + + /** + * Create a new entry for the topic, with specified type string. + * + *

Entries act as a combination of a subscriber and a weak publisher. The + * subscriber is active as long as the entry is not closed. The publisher is + * created when the entry is first written to, and remains active until either + * unpublish() is called or the entry is closed. + * + *

It is not possible to use two different data types with the same + * topic. Conflicts between publishers are typically resolved by the server on + * a first-come, first-served basis. Any published values that do not match + * the topic's data type are dropped (ignored), and the entry will show no new + * values if the data type does not match. To determine if the data type + * matches, use the appropriate Topic functions. + * + * @param typeString type string + * @param defaultValue default value used when a default is not provided to a + * getter function + * @param options publish and/or subscribe options + * @return entry + */ + public BooleanEntry getEntryEx( + String typeString, + boolean defaultValue, + PubSubOption... options) { + return new BooleanEntryImpl( + this, + NetworkTablesJNI.getEntry( + m_handle, NetworkTableType.kBoolean.getValue(), + typeString, options), + defaultValue); + } + +} diff --git a/ntcore/src/generated/main/java/edu/wpi/first/networktables/DoubleArrayEntry.java b/ntcore/src/generated/main/java/edu/wpi/first/networktables/DoubleArrayEntry.java new file mode 100644 index 0000000000..8a40d8bd32 --- /dev/null +++ b/ntcore/src/generated/main/java/edu/wpi/first/networktables/DoubleArrayEntry.java @@ -0,0 +1,17 @@ +// 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. + +// THIS FILE WAS AUTO-GENERATED BY ./ntcore/generate_topics.py. DO NOT MODIFY + +package edu.wpi.first.networktables; + +/** + * NetworkTables DoubleArray entry. + * + *

Unlike NetworkTableEntry, the entry goes away when close() is called. + */ +public interface DoubleArrayEntry extends DoubleArraySubscriber, DoubleArrayPublisher { + /** Stops publishing the entry if it's published. */ + void unpublish(); +} diff --git a/ntcore/src/generated/main/java/edu/wpi/first/networktables/DoubleArrayEntryImpl.java b/ntcore/src/generated/main/java/edu/wpi/first/networktables/DoubleArrayEntryImpl.java new file mode 100644 index 0000000000..7bb270ac37 --- /dev/null +++ b/ntcore/src/generated/main/java/edu/wpi/first/networktables/DoubleArrayEntryImpl.java @@ -0,0 +1,77 @@ +// 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. + +// THIS FILE WAS AUTO-GENERATED BY ./ntcore/generate_topics.py. DO NOT MODIFY + +package edu.wpi.first.networktables; + +/** NetworkTables DoubleArray implementation. */ +@SuppressWarnings("PMD.ArrayIsStoredDirectly") +final class DoubleArrayEntryImpl extends EntryBase implements DoubleArrayEntry { + /** + * Constructor. + * + * @param topic Topic + * @param handle Native handle + * @param defaultValue Default value for get() + */ + DoubleArrayEntryImpl(DoubleArrayTopic topic, int handle, double[] defaultValue) { + super(handle); + m_topic = topic; + m_defaultValue = defaultValue; + } + + @Override + public DoubleArrayTopic getTopic() { + return m_topic; + } + + @Override + public double[] get() { + return NetworkTablesJNI.getDoubleArray(m_handle, m_defaultValue); + } + + @Override + public double[] get(double[] defaultValue) { + return NetworkTablesJNI.getDoubleArray(m_handle, defaultValue); + } + + @Override + public TimestampedDoubleArray getAtomic() { + return NetworkTablesJNI.getAtomicDoubleArray(m_handle, m_defaultValue); + } + + @Override + public TimestampedDoubleArray getAtomic(double[] defaultValue) { + return NetworkTablesJNI.getAtomicDoubleArray(m_handle, defaultValue); + } + + @Override + public TimestampedDoubleArray[] readQueue() { + return NetworkTablesJNI.readQueueDoubleArray(m_handle); + } + + @Override + public double[][] readQueueValues() { + return NetworkTablesJNI.readQueueValuesDoubleArray(m_handle); + } + + @Override + public void set(double[] value, long time) { + NetworkTablesJNI.setDoubleArray(m_handle, time, value); + } + + @Override + public void setDefault(double[] value) { + NetworkTablesJNI.setDefaultDoubleArray(m_handle, 0, value); + } + + @Override + public void unpublish() { + NetworkTablesJNI.unpublish(m_handle); + } + + private final DoubleArrayTopic m_topic; + private final double[] m_defaultValue; +} diff --git a/ntcore/src/generated/main/java/edu/wpi/first/networktables/DoubleArrayPublisher.java b/ntcore/src/generated/main/java/edu/wpi/first/networktables/DoubleArrayPublisher.java new file mode 100644 index 0000000000..39b367a88d --- /dev/null +++ b/ntcore/src/generated/main/java/edu/wpi/first/networktables/DoubleArrayPublisher.java @@ -0,0 +1,52 @@ +// 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. + +// THIS FILE WAS AUTO-GENERATED BY ./ntcore/generate_topics.py. DO NOT MODIFY + +package edu.wpi.first.networktables; + +import java.util.function.Consumer; + +/** NetworkTables DoubleArray publisher. */ +public interface DoubleArrayPublisher extends Publisher, Consumer { + /** + * Get the corresponding topic. + * + * @return Topic + */ + @Override + DoubleArrayTopic getTopic(); + + /** + * Publish a new value using current NT time. + * + * @param value value to publish + */ + default void set(double[] value) { + set(value, 0); + } + + + /** + * Publish a new value. + * + * @param value value to publish + * @param time timestamp; 0 indicates current NT time should be used + */ + void set(double[] value, long time); + + /** + * Publish a default value. + * On reconnect, a default value will never be used in preference to a + * published value. + * + * @param value value + */ + void setDefault(double[] value); + + @Override + default void accept(double[] value) { + set(value); + } +} diff --git a/ntcore/src/generated/main/java/edu/wpi/first/networktables/DoubleArraySubscriber.java b/ntcore/src/generated/main/java/edu/wpi/first/networktables/DoubleArraySubscriber.java new file mode 100644 index 0000000000..a807d66efc --- /dev/null +++ b/ntcore/src/generated/main/java/edu/wpi/first/networktables/DoubleArraySubscriber.java @@ -0,0 +1,80 @@ +// 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. + +// THIS FILE WAS AUTO-GENERATED BY ./ntcore/generate_topics.py. DO NOT MODIFY + +package edu.wpi.first.networktables; + +import java.util.function.Supplier; + +/** NetworkTables DoubleArray subscriber. */ +@SuppressWarnings("PMD.MissingOverride") +public interface DoubleArraySubscriber extends Subscriber, Supplier { + /** + * Get the corresponding topic. + * + * @return Topic + */ + @Override + DoubleArrayTopic getTopic(); + + /** + * Get the last published value. + * If no value has been published, returns the stored default value. + * + * @return value + */ + double[] get(); + + /** + * Get the last published value. + * If no value has been published, returns the passed defaultValue. + * + * @param defaultValue default value to return if no value has been published + * @return value + */ + double[] get(double[] defaultValue); + + /** + * Get the last published value along with its timestamp + * If no value has been published, returns the stored default value and a + * timestamp of 0. + * + * @return timestamped value + */ + TimestampedDoubleArray getAtomic(); + + /** + * Get the last published value along with its timestamp + * If no value has been published, returns the passed defaultValue and a + * timestamp of 0. + * + * @param defaultValue default value to return if no value has been published + * @return timestamped value + */ + TimestampedDoubleArray getAtomic(double[] defaultValue); + + /** + * Get an array of all value changes since the last call to readQueue. + * Also provides a timestamp for each value. + * + *

The "poll storage" subscribe option can be used to set the queue + * depth. + * + * @return Array of timestamped values; empty array if no new changes have + * been published since the previous call. + */ + TimestampedDoubleArray[] readQueue(); + + /** + * Get an array of all value changes since the last call to readQueue. + * + *

The "poll storage" subscribe option can be used to set the queue + * depth. + * + * @return Array of values; empty array if no new changes have been + * published since the previous call. + */ + double[][] readQueueValues(); +} diff --git a/ntcore/src/generated/main/java/edu/wpi/first/networktables/DoubleArrayTopic.java b/ntcore/src/generated/main/java/edu/wpi/first/networktables/DoubleArrayTopic.java new file mode 100644 index 0000000000..f0128697e0 --- /dev/null +++ b/ntcore/src/generated/main/java/edu/wpi/first/networktables/DoubleArrayTopic.java @@ -0,0 +1,206 @@ +// 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. + +// THIS FILE WAS AUTO-GENERATED BY ./ntcore/generate_topics.py. DO NOT MODIFY + +package edu.wpi.first.networktables; + +/** NetworkTables DoubleArray topic. */ +public final class DoubleArrayTopic extends Topic { + /** The default type string for this topic type. */ + public static final String kTypeString = "double[]"; + + /** + * Construct from a generic topic. + * + * @param topic Topic + */ + public DoubleArrayTopic(Topic topic) { + super(topic.m_inst, topic.m_handle); + } + + /** + * Constructor; use NetworkTableInstance.getDoubleArrayTopic() instead. + * + * @param inst Instance + * @param handle Native handle + */ + public DoubleArrayTopic(NetworkTableInstance inst, int handle) { + super(inst, handle); + } + + /** + * Create a new subscriber to the topic. + * + *

The subscriber is only active as long as the returned object + * is not closed. + * + *

Subscribers that do not match the published data type do not return + * any values. To determine if the data type matches, use the appropriate + * Topic functions. + * + * @param defaultValue default value used when a default is not provided to a + * getter function + * @param options subscribe options + * @return subscriber + */ + public DoubleArraySubscriber subscribe( + double[] defaultValue, + PubSubOption... options) { + return new DoubleArrayEntryImpl( + this, + NetworkTablesJNI.subscribe( + m_handle, NetworkTableType.kDoubleArray.getValue(), + "double[]", options), + defaultValue); + } + + /** + * Create a new subscriber to the topic, with specified type string. + * + *

The subscriber is only active as long as the returned object + * is not closed. + * + *

Subscribers that do not match the published data type do not return + * any values. To determine if the data type matches, use the appropriate + * Topic functions. + * + * @param typeString type string + * @param defaultValue default value used when a default is not provided to a + * getter function + * @param options subscribe options + * @return subscriber + */ + public DoubleArraySubscriber subscribeEx( + String typeString, + double[] defaultValue, + PubSubOption... options) { + return new DoubleArrayEntryImpl( + this, + NetworkTablesJNI.subscribe( + m_handle, NetworkTableType.kDoubleArray.getValue(), + typeString, options), + defaultValue); + } + + /** + * Create a new publisher to the topic. + * + *

The publisher is only active as long as the returned object + * is not closed. + * + *

It is not possible to publish two different data types to the same + * topic. Conflicts between publishers are typically resolved by the server on + * a first-come, first-served basis. Any published values that do not match + * the topic's data type are dropped (ignored). To determine if the data type + * matches, use the appropriate Topic functions. + * + * @param options publish options + * @return publisher + */ + public DoubleArrayPublisher publish( + PubSubOption... options) { + return new DoubleArrayEntryImpl( + this, + NetworkTablesJNI.publish( + m_handle, NetworkTableType.kDoubleArray.getValue(), + "double[]", options), + new double[] {}); + } + + /** + * Create a new publisher to the topic, with type string and initial properties. + * + *

The publisher is only active as long as the returned object + * is not closed. + * + *

It is not possible to publish two different data types to the same + * topic. Conflicts between publishers are typically resolved by the server on + * a first-come, first-served basis. Any published values that do not match + * the topic's data type are dropped (ignored). To determine if the data type + * matches, use the appropriate Topic functions. + * + * @param typeString type string + * @param properties JSON properties + * @param options publish options + * @return publisher + * @throws IllegalArgumentException if properties is not a JSON object + */ + public DoubleArrayPublisher publishEx( + String typeString, + String properties, + PubSubOption... options) { + return new DoubleArrayEntryImpl( + this, + NetworkTablesJNI.publishEx( + m_handle, NetworkTableType.kDoubleArray.getValue(), + typeString, properties, options), + new double[] {}); + } + + /** + * Create a new entry for the topic. + * + *

Entries act as a combination of a subscriber and a weak publisher. The + * subscriber is active as long as the entry is not closed. The publisher is + * created when the entry is first written to, and remains active until either + * unpublish() is called or the entry is closed. + * + *

It is not possible to use two different data types with the same + * topic. Conflicts between publishers are typically resolved by the server on + * a first-come, first-served basis. Any published values that do not match + * the topic's data type are dropped (ignored), and the entry will show no new + * values if the data type does not match. To determine if the data type + * matches, use the appropriate Topic functions. + * + * @param defaultValue default value used when a default is not provided to a + * getter function + * @param options publish and/or subscribe options + * @return entry + */ + public DoubleArrayEntry getEntry( + double[] defaultValue, + PubSubOption... options) { + return new DoubleArrayEntryImpl( + this, + NetworkTablesJNI.getEntry( + m_handle, NetworkTableType.kDoubleArray.getValue(), + "double[]", options), + defaultValue); + } + + /** + * Create a new entry for the topic, with specified type string. + * + *

Entries act as a combination of a subscriber and a weak publisher. The + * subscriber is active as long as the entry is not closed. The publisher is + * created when the entry is first written to, and remains active until either + * unpublish() is called or the entry is closed. + * + *

It is not possible to use two different data types with the same + * topic. Conflicts between publishers are typically resolved by the server on + * a first-come, first-served basis. Any published values that do not match + * the topic's data type are dropped (ignored), and the entry will show no new + * values if the data type does not match. To determine if the data type + * matches, use the appropriate Topic functions. + * + * @param typeString type string + * @param defaultValue default value used when a default is not provided to a + * getter function + * @param options publish and/or subscribe options + * @return entry + */ + public DoubleArrayEntry getEntryEx( + String typeString, + double[] defaultValue, + PubSubOption... options) { + return new DoubleArrayEntryImpl( + this, + NetworkTablesJNI.getEntry( + m_handle, NetworkTableType.kDoubleArray.getValue(), + typeString, options), + defaultValue); + } + +} diff --git a/ntcore/src/generated/main/java/edu/wpi/first/networktables/DoubleEntry.java b/ntcore/src/generated/main/java/edu/wpi/first/networktables/DoubleEntry.java new file mode 100644 index 0000000000..b91e3243d3 --- /dev/null +++ b/ntcore/src/generated/main/java/edu/wpi/first/networktables/DoubleEntry.java @@ -0,0 +1,17 @@ +// 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. + +// THIS FILE WAS AUTO-GENERATED BY ./ntcore/generate_topics.py. DO NOT MODIFY + +package edu.wpi.first.networktables; + +/** + * NetworkTables Double entry. + * + *

Unlike NetworkTableEntry, the entry goes away when close() is called. + */ +public interface DoubleEntry extends DoubleSubscriber, DoublePublisher { + /** Stops publishing the entry if it's published. */ + void unpublish(); +} diff --git a/ntcore/src/generated/main/java/edu/wpi/first/networktables/DoubleEntryImpl.java b/ntcore/src/generated/main/java/edu/wpi/first/networktables/DoubleEntryImpl.java new file mode 100644 index 0000000000..968686d502 --- /dev/null +++ b/ntcore/src/generated/main/java/edu/wpi/first/networktables/DoubleEntryImpl.java @@ -0,0 +1,77 @@ +// 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. + +// THIS FILE WAS AUTO-GENERATED BY ./ntcore/generate_topics.py. DO NOT MODIFY + +package edu.wpi.first.networktables; + +/** NetworkTables Double implementation. */ +@SuppressWarnings("PMD.ArrayIsStoredDirectly") +final class DoubleEntryImpl extends EntryBase implements DoubleEntry { + /** + * Constructor. + * + * @param topic Topic + * @param handle Native handle + * @param defaultValue Default value for get() + */ + DoubleEntryImpl(DoubleTopic topic, int handle, double defaultValue) { + super(handle); + m_topic = topic; + m_defaultValue = defaultValue; + } + + @Override + public DoubleTopic getTopic() { + return m_topic; + } + + @Override + public double get() { + return NetworkTablesJNI.getDouble(m_handle, m_defaultValue); + } + + @Override + public double get(double defaultValue) { + return NetworkTablesJNI.getDouble(m_handle, defaultValue); + } + + @Override + public TimestampedDouble getAtomic() { + return NetworkTablesJNI.getAtomicDouble(m_handle, m_defaultValue); + } + + @Override + public TimestampedDouble getAtomic(double defaultValue) { + return NetworkTablesJNI.getAtomicDouble(m_handle, defaultValue); + } + + @Override + public TimestampedDouble[] readQueue() { + return NetworkTablesJNI.readQueueDouble(m_handle); + } + + @Override + public double[] readQueueValues() { + return NetworkTablesJNI.readQueueValuesDouble(m_handle); + } + + @Override + public void set(double value, long time) { + NetworkTablesJNI.setDouble(m_handle, time, value); + } + + @Override + public void setDefault(double value) { + NetworkTablesJNI.setDefaultDouble(m_handle, 0, value); + } + + @Override + public void unpublish() { + NetworkTablesJNI.unpublish(m_handle); + } + + private final DoubleTopic m_topic; + private final double m_defaultValue; +} diff --git a/ntcore/src/generated/main/java/edu/wpi/first/networktables/DoublePublisher.java b/ntcore/src/generated/main/java/edu/wpi/first/networktables/DoublePublisher.java new file mode 100644 index 0000000000..d47792118d --- /dev/null +++ b/ntcore/src/generated/main/java/edu/wpi/first/networktables/DoublePublisher.java @@ -0,0 +1,52 @@ +// 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. + +// THIS FILE WAS AUTO-GENERATED BY ./ntcore/generate_topics.py. DO NOT MODIFY + +package edu.wpi.first.networktables; + +import java.util.function.DoubleConsumer; + +/** NetworkTables Double publisher. */ +public interface DoublePublisher extends Publisher, DoubleConsumer { + /** + * Get the corresponding topic. + * + * @return Topic + */ + @Override + DoubleTopic getTopic(); + + /** + * Publish a new value using current NT time. + * + * @param value value to publish + */ + default void set(double value) { + set(value, 0); + } + + + /** + * Publish a new value. + * + * @param value value to publish + * @param time timestamp; 0 indicates current NT time should be used + */ + void set(double value, long time); + + /** + * Publish a default value. + * On reconnect, a default value will never be used in preference to a + * published value. + * + * @param value value + */ + void setDefault(double value); + + @Override + default void accept(double value) { + set(value); + } +} diff --git a/ntcore/src/generated/main/java/edu/wpi/first/networktables/DoubleSubscriber.java b/ntcore/src/generated/main/java/edu/wpi/first/networktables/DoubleSubscriber.java new file mode 100644 index 0000000000..688f6eaed7 --- /dev/null +++ b/ntcore/src/generated/main/java/edu/wpi/first/networktables/DoubleSubscriber.java @@ -0,0 +1,85 @@ +// 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. + +// THIS FILE WAS AUTO-GENERATED BY ./ntcore/generate_topics.py. DO NOT MODIFY + +package edu.wpi.first.networktables; + +import java.util.function.DoubleSupplier; + +/** NetworkTables Double subscriber. */ +@SuppressWarnings("PMD.MissingOverride") +public interface DoubleSubscriber extends Subscriber, DoubleSupplier { + /** + * Get the corresponding topic. + * + * @return Topic + */ + @Override + DoubleTopic getTopic(); + + /** + * Get the last published value. + * If no value has been published, returns the stored default value. + * + * @return value + */ + double get(); + + /** + * Get the last published value. + * If no value has been published, returns the passed defaultValue. + * + * @param defaultValue default value to return if no value has been published + * @return value + */ + double get(double defaultValue); + + @Override + default double getAsDouble() { + return get(); + } + + /** + * Get the last published value along with its timestamp + * If no value has been published, returns the stored default value and a + * timestamp of 0. + * + * @return timestamped value + */ + TimestampedDouble getAtomic(); + + /** + * Get the last published value along with its timestamp + * If no value has been published, returns the passed defaultValue and a + * timestamp of 0. + * + * @param defaultValue default value to return if no value has been published + * @return timestamped value + */ + TimestampedDouble getAtomic(double defaultValue); + + /** + * Get an array of all value changes since the last call to readQueue. + * Also provides a timestamp for each value. + * + *

The "poll storage" subscribe option can be used to set the queue + * depth. + * + * @return Array of timestamped values; empty array if no new changes have + * been published since the previous call. + */ + TimestampedDouble[] readQueue(); + + /** + * Get an array of all value changes since the last call to readQueue. + * + *

The "poll storage" subscribe option can be used to set the queue + * depth. + * + * @return Array of values; empty array if no new changes have been + * published since the previous call. + */ + double[] readQueueValues(); +} diff --git a/ntcore/src/generated/main/java/edu/wpi/first/networktables/DoubleTopic.java b/ntcore/src/generated/main/java/edu/wpi/first/networktables/DoubleTopic.java new file mode 100644 index 0000000000..2456841eaa --- /dev/null +++ b/ntcore/src/generated/main/java/edu/wpi/first/networktables/DoubleTopic.java @@ -0,0 +1,206 @@ +// 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. + +// THIS FILE WAS AUTO-GENERATED BY ./ntcore/generate_topics.py. DO NOT MODIFY + +package edu.wpi.first.networktables; + +/** NetworkTables Double topic. */ +public final class DoubleTopic extends Topic { + /** The default type string for this topic type. */ + public static final String kTypeString = "double"; + + /** + * Construct from a generic topic. + * + * @param topic Topic + */ + public DoubleTopic(Topic topic) { + super(topic.m_inst, topic.m_handle); + } + + /** + * Constructor; use NetworkTableInstance.getDoubleTopic() instead. + * + * @param inst Instance + * @param handle Native handle + */ + public DoubleTopic(NetworkTableInstance inst, int handle) { + super(inst, handle); + } + + /** + * Create a new subscriber to the topic. + * + *

The subscriber is only active as long as the returned object + * is not closed. + * + *

Subscribers that do not match the published data type do not return + * any values. To determine if the data type matches, use the appropriate + * Topic functions. + * + * @param defaultValue default value used when a default is not provided to a + * getter function + * @param options subscribe options + * @return subscriber + */ + public DoubleSubscriber subscribe( + double defaultValue, + PubSubOption... options) { + return new DoubleEntryImpl( + this, + NetworkTablesJNI.subscribe( + m_handle, NetworkTableType.kDouble.getValue(), + "double", options), + defaultValue); + } + + /** + * Create a new subscriber to the topic, with specified type string. + * + *

The subscriber is only active as long as the returned object + * is not closed. + * + *

Subscribers that do not match the published data type do not return + * any values. To determine if the data type matches, use the appropriate + * Topic functions. + * + * @param typeString type string + * @param defaultValue default value used when a default is not provided to a + * getter function + * @param options subscribe options + * @return subscriber + */ + public DoubleSubscriber subscribeEx( + String typeString, + double defaultValue, + PubSubOption... options) { + return new DoubleEntryImpl( + this, + NetworkTablesJNI.subscribe( + m_handle, NetworkTableType.kDouble.getValue(), + typeString, options), + defaultValue); + } + + /** + * Create a new publisher to the topic. + * + *

The publisher is only active as long as the returned object + * is not closed. + * + *

It is not possible to publish two different data types to the same + * topic. Conflicts between publishers are typically resolved by the server on + * a first-come, first-served basis. Any published values that do not match + * the topic's data type are dropped (ignored). To determine if the data type + * matches, use the appropriate Topic functions. + * + * @param options publish options + * @return publisher + */ + public DoublePublisher publish( + PubSubOption... options) { + return new DoubleEntryImpl( + this, + NetworkTablesJNI.publish( + m_handle, NetworkTableType.kDouble.getValue(), + "double", options), + 0); + } + + /** + * Create a new publisher to the topic, with type string and initial properties. + * + *

The publisher is only active as long as the returned object + * is not closed. + * + *

It is not possible to publish two different data types to the same + * topic. Conflicts between publishers are typically resolved by the server on + * a first-come, first-served basis. Any published values that do not match + * the topic's data type are dropped (ignored). To determine if the data type + * matches, use the appropriate Topic functions. + * + * @param typeString type string + * @param properties JSON properties + * @param options publish options + * @return publisher + * @throws IllegalArgumentException if properties is not a JSON object + */ + public DoublePublisher publishEx( + String typeString, + String properties, + PubSubOption... options) { + return new DoubleEntryImpl( + this, + NetworkTablesJNI.publishEx( + m_handle, NetworkTableType.kDouble.getValue(), + typeString, properties, options), + 0); + } + + /** + * Create a new entry for the topic. + * + *

Entries act as a combination of a subscriber and a weak publisher. The + * subscriber is active as long as the entry is not closed. The publisher is + * created when the entry is first written to, and remains active until either + * unpublish() is called or the entry is closed. + * + *

It is not possible to use two different data types with the same + * topic. Conflicts between publishers are typically resolved by the server on + * a first-come, first-served basis. Any published values that do not match + * the topic's data type are dropped (ignored), and the entry will show no new + * values if the data type does not match. To determine if the data type + * matches, use the appropriate Topic functions. + * + * @param defaultValue default value used when a default is not provided to a + * getter function + * @param options publish and/or subscribe options + * @return entry + */ + public DoubleEntry getEntry( + double defaultValue, + PubSubOption... options) { + return new DoubleEntryImpl( + this, + NetworkTablesJNI.getEntry( + m_handle, NetworkTableType.kDouble.getValue(), + "double", options), + defaultValue); + } + + /** + * Create a new entry for the topic, with specified type string. + * + *

Entries act as a combination of a subscriber and a weak publisher. The + * subscriber is active as long as the entry is not closed. The publisher is + * created when the entry is first written to, and remains active until either + * unpublish() is called or the entry is closed. + * + *

It is not possible to use two different data types with the same + * topic. Conflicts between publishers are typically resolved by the server on + * a first-come, first-served basis. Any published values that do not match + * the topic's data type are dropped (ignored), and the entry will show no new + * values if the data type does not match. To determine if the data type + * matches, use the appropriate Topic functions. + * + * @param typeString type string + * @param defaultValue default value used when a default is not provided to a + * getter function + * @param options publish and/or subscribe options + * @return entry + */ + public DoubleEntry getEntryEx( + String typeString, + double defaultValue, + PubSubOption... options) { + return new DoubleEntryImpl( + this, + NetworkTablesJNI.getEntry( + m_handle, NetworkTableType.kDouble.getValue(), + typeString, options), + defaultValue); + } + +} diff --git a/ntcore/src/generated/main/java/edu/wpi/first/networktables/FloatArrayEntry.java b/ntcore/src/generated/main/java/edu/wpi/first/networktables/FloatArrayEntry.java new file mode 100644 index 0000000000..b4cd353fea --- /dev/null +++ b/ntcore/src/generated/main/java/edu/wpi/first/networktables/FloatArrayEntry.java @@ -0,0 +1,17 @@ +// 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. + +// THIS FILE WAS AUTO-GENERATED BY ./ntcore/generate_topics.py. DO NOT MODIFY + +package edu.wpi.first.networktables; + +/** + * NetworkTables FloatArray entry. + * + *

Unlike NetworkTableEntry, the entry goes away when close() is called. + */ +public interface FloatArrayEntry extends FloatArraySubscriber, FloatArrayPublisher { + /** Stops publishing the entry if it's published. */ + void unpublish(); +} diff --git a/ntcore/src/generated/main/java/edu/wpi/first/networktables/FloatArrayEntryImpl.java b/ntcore/src/generated/main/java/edu/wpi/first/networktables/FloatArrayEntryImpl.java new file mode 100644 index 0000000000..1afe83728b --- /dev/null +++ b/ntcore/src/generated/main/java/edu/wpi/first/networktables/FloatArrayEntryImpl.java @@ -0,0 +1,77 @@ +// 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. + +// THIS FILE WAS AUTO-GENERATED BY ./ntcore/generate_topics.py. DO NOT MODIFY + +package edu.wpi.first.networktables; + +/** NetworkTables FloatArray implementation. */ +@SuppressWarnings("PMD.ArrayIsStoredDirectly") +final class FloatArrayEntryImpl extends EntryBase implements FloatArrayEntry { + /** + * Constructor. + * + * @param topic Topic + * @param handle Native handle + * @param defaultValue Default value for get() + */ + FloatArrayEntryImpl(FloatArrayTopic topic, int handle, float[] defaultValue) { + super(handle); + m_topic = topic; + m_defaultValue = defaultValue; + } + + @Override + public FloatArrayTopic getTopic() { + return m_topic; + } + + @Override + public float[] get() { + return NetworkTablesJNI.getFloatArray(m_handle, m_defaultValue); + } + + @Override + public float[] get(float[] defaultValue) { + return NetworkTablesJNI.getFloatArray(m_handle, defaultValue); + } + + @Override + public TimestampedFloatArray getAtomic() { + return NetworkTablesJNI.getAtomicFloatArray(m_handle, m_defaultValue); + } + + @Override + public TimestampedFloatArray getAtomic(float[] defaultValue) { + return NetworkTablesJNI.getAtomicFloatArray(m_handle, defaultValue); + } + + @Override + public TimestampedFloatArray[] readQueue() { + return NetworkTablesJNI.readQueueFloatArray(m_handle); + } + + @Override + public float[][] readQueueValues() { + return NetworkTablesJNI.readQueueValuesFloatArray(m_handle); + } + + @Override + public void set(float[] value, long time) { + NetworkTablesJNI.setFloatArray(m_handle, time, value); + } + + @Override + public void setDefault(float[] value) { + NetworkTablesJNI.setDefaultFloatArray(m_handle, 0, value); + } + + @Override + public void unpublish() { + NetworkTablesJNI.unpublish(m_handle); + } + + private final FloatArrayTopic m_topic; + private final float[] m_defaultValue; +} diff --git a/ntcore/src/generated/main/java/edu/wpi/first/networktables/FloatArrayPublisher.java b/ntcore/src/generated/main/java/edu/wpi/first/networktables/FloatArrayPublisher.java new file mode 100644 index 0000000000..afaf9f2721 --- /dev/null +++ b/ntcore/src/generated/main/java/edu/wpi/first/networktables/FloatArrayPublisher.java @@ -0,0 +1,52 @@ +// 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. + +// THIS FILE WAS AUTO-GENERATED BY ./ntcore/generate_topics.py. DO NOT MODIFY + +package edu.wpi.first.networktables; + +import java.util.function.Consumer; + +/** NetworkTables FloatArray publisher. */ +public interface FloatArrayPublisher extends Publisher, Consumer { + /** + * Get the corresponding topic. + * + * @return Topic + */ + @Override + FloatArrayTopic getTopic(); + + /** + * Publish a new value using current NT time. + * + * @param value value to publish + */ + default void set(float[] value) { + set(value, 0); + } + + + /** + * Publish a new value. + * + * @param value value to publish + * @param time timestamp; 0 indicates current NT time should be used + */ + void set(float[] value, long time); + + /** + * Publish a default value. + * On reconnect, a default value will never be used in preference to a + * published value. + * + * @param value value + */ + void setDefault(float[] value); + + @Override + default void accept(float[] value) { + set(value); + } +} diff --git a/ntcore/src/generated/main/java/edu/wpi/first/networktables/FloatArraySubscriber.java b/ntcore/src/generated/main/java/edu/wpi/first/networktables/FloatArraySubscriber.java new file mode 100644 index 0000000000..b70bece391 --- /dev/null +++ b/ntcore/src/generated/main/java/edu/wpi/first/networktables/FloatArraySubscriber.java @@ -0,0 +1,80 @@ +// 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. + +// THIS FILE WAS AUTO-GENERATED BY ./ntcore/generate_topics.py. DO NOT MODIFY + +package edu.wpi.first.networktables; + +import java.util.function.Supplier; + +/** NetworkTables FloatArray subscriber. */ +@SuppressWarnings("PMD.MissingOverride") +public interface FloatArraySubscriber extends Subscriber, Supplier { + /** + * Get the corresponding topic. + * + * @return Topic + */ + @Override + FloatArrayTopic getTopic(); + + /** + * Get the last published value. + * If no value has been published, returns the stored default value. + * + * @return value + */ + float[] get(); + + /** + * Get the last published value. + * If no value has been published, returns the passed defaultValue. + * + * @param defaultValue default value to return if no value has been published + * @return value + */ + float[] get(float[] defaultValue); + + /** + * Get the last published value along with its timestamp + * If no value has been published, returns the stored default value and a + * timestamp of 0. + * + * @return timestamped value + */ + TimestampedFloatArray getAtomic(); + + /** + * Get the last published value along with its timestamp + * If no value has been published, returns the passed defaultValue and a + * timestamp of 0. + * + * @param defaultValue default value to return if no value has been published + * @return timestamped value + */ + TimestampedFloatArray getAtomic(float[] defaultValue); + + /** + * Get an array of all value changes since the last call to readQueue. + * Also provides a timestamp for each value. + * + *

The "poll storage" subscribe option can be used to set the queue + * depth. + * + * @return Array of timestamped values; empty array if no new changes have + * been published since the previous call. + */ + TimestampedFloatArray[] readQueue(); + + /** + * Get an array of all value changes since the last call to readQueue. + * + *

The "poll storage" subscribe option can be used to set the queue + * depth. + * + * @return Array of values; empty array if no new changes have been + * published since the previous call. + */ + float[][] readQueueValues(); +} diff --git a/ntcore/src/generated/main/java/edu/wpi/first/networktables/FloatArrayTopic.java b/ntcore/src/generated/main/java/edu/wpi/first/networktables/FloatArrayTopic.java new file mode 100644 index 0000000000..e20ea7ffd2 --- /dev/null +++ b/ntcore/src/generated/main/java/edu/wpi/first/networktables/FloatArrayTopic.java @@ -0,0 +1,206 @@ +// 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. + +// THIS FILE WAS AUTO-GENERATED BY ./ntcore/generate_topics.py. DO NOT MODIFY + +package edu.wpi.first.networktables; + +/** NetworkTables FloatArray topic. */ +public final class FloatArrayTopic extends Topic { + /** The default type string for this topic type. */ + public static final String kTypeString = "float[]"; + + /** + * Construct from a generic topic. + * + * @param topic Topic + */ + public FloatArrayTopic(Topic topic) { + super(topic.m_inst, topic.m_handle); + } + + /** + * Constructor; use NetworkTableInstance.getFloatArrayTopic() instead. + * + * @param inst Instance + * @param handle Native handle + */ + public FloatArrayTopic(NetworkTableInstance inst, int handle) { + super(inst, handle); + } + + /** + * Create a new subscriber to the topic. + * + *

The subscriber is only active as long as the returned object + * is not closed. + * + *

Subscribers that do not match the published data type do not return + * any values. To determine if the data type matches, use the appropriate + * Topic functions. + * + * @param defaultValue default value used when a default is not provided to a + * getter function + * @param options subscribe options + * @return subscriber + */ + public FloatArraySubscriber subscribe( + float[] defaultValue, + PubSubOption... options) { + return new FloatArrayEntryImpl( + this, + NetworkTablesJNI.subscribe( + m_handle, NetworkTableType.kFloatArray.getValue(), + "float[]", options), + defaultValue); + } + + /** + * Create a new subscriber to the topic, with specified type string. + * + *

The subscriber is only active as long as the returned object + * is not closed. + * + *

Subscribers that do not match the published data type do not return + * any values. To determine if the data type matches, use the appropriate + * Topic functions. + * + * @param typeString type string + * @param defaultValue default value used when a default is not provided to a + * getter function + * @param options subscribe options + * @return subscriber + */ + public FloatArraySubscriber subscribeEx( + String typeString, + float[] defaultValue, + PubSubOption... options) { + return new FloatArrayEntryImpl( + this, + NetworkTablesJNI.subscribe( + m_handle, NetworkTableType.kFloatArray.getValue(), + typeString, options), + defaultValue); + } + + /** + * Create a new publisher to the topic. + * + *

The publisher is only active as long as the returned object + * is not closed. + * + *

It is not possible to publish two different data types to the same + * topic. Conflicts between publishers are typically resolved by the server on + * a first-come, first-served basis. Any published values that do not match + * the topic's data type are dropped (ignored). To determine if the data type + * matches, use the appropriate Topic functions. + * + * @param options publish options + * @return publisher + */ + public FloatArrayPublisher publish( + PubSubOption... options) { + return new FloatArrayEntryImpl( + this, + NetworkTablesJNI.publish( + m_handle, NetworkTableType.kFloatArray.getValue(), + "float[]", options), + new float[] {}); + } + + /** + * Create a new publisher to the topic, with type string and initial properties. + * + *

The publisher is only active as long as the returned object + * is not closed. + * + *

It is not possible to publish two different data types to the same + * topic. Conflicts between publishers are typically resolved by the server on + * a first-come, first-served basis. Any published values that do not match + * the topic's data type are dropped (ignored). To determine if the data type + * matches, use the appropriate Topic functions. + * + * @param typeString type string + * @param properties JSON properties + * @param options publish options + * @return publisher + * @throws IllegalArgumentException if properties is not a JSON object + */ + public FloatArrayPublisher publishEx( + String typeString, + String properties, + PubSubOption... options) { + return new FloatArrayEntryImpl( + this, + NetworkTablesJNI.publishEx( + m_handle, NetworkTableType.kFloatArray.getValue(), + typeString, properties, options), + new float[] {}); + } + + /** + * Create a new entry for the topic. + * + *

Entries act as a combination of a subscriber and a weak publisher. The + * subscriber is active as long as the entry is not closed. The publisher is + * created when the entry is first written to, and remains active until either + * unpublish() is called or the entry is closed. + * + *

It is not possible to use two different data types with the same + * topic. Conflicts between publishers are typically resolved by the server on + * a first-come, first-served basis. Any published values that do not match + * the topic's data type are dropped (ignored), and the entry will show no new + * values if the data type does not match. To determine if the data type + * matches, use the appropriate Topic functions. + * + * @param defaultValue default value used when a default is not provided to a + * getter function + * @param options publish and/or subscribe options + * @return entry + */ + public FloatArrayEntry getEntry( + float[] defaultValue, + PubSubOption... options) { + return new FloatArrayEntryImpl( + this, + NetworkTablesJNI.getEntry( + m_handle, NetworkTableType.kFloatArray.getValue(), + "float[]", options), + defaultValue); + } + + /** + * Create a new entry for the topic, with specified type string. + * + *

Entries act as a combination of a subscriber and a weak publisher. The + * subscriber is active as long as the entry is not closed. The publisher is + * created when the entry is first written to, and remains active until either + * unpublish() is called or the entry is closed. + * + *

It is not possible to use two different data types with the same + * topic. Conflicts between publishers are typically resolved by the server on + * a first-come, first-served basis. Any published values that do not match + * the topic's data type are dropped (ignored), and the entry will show no new + * values if the data type does not match. To determine if the data type + * matches, use the appropriate Topic functions. + * + * @param typeString type string + * @param defaultValue default value used when a default is not provided to a + * getter function + * @param options publish and/or subscribe options + * @return entry + */ + public FloatArrayEntry getEntryEx( + String typeString, + float[] defaultValue, + PubSubOption... options) { + return new FloatArrayEntryImpl( + this, + NetworkTablesJNI.getEntry( + m_handle, NetworkTableType.kFloatArray.getValue(), + typeString, options), + defaultValue); + } + +} diff --git a/ntcore/src/generated/main/java/edu/wpi/first/networktables/FloatEntry.java b/ntcore/src/generated/main/java/edu/wpi/first/networktables/FloatEntry.java new file mode 100644 index 0000000000..9830123fd5 --- /dev/null +++ b/ntcore/src/generated/main/java/edu/wpi/first/networktables/FloatEntry.java @@ -0,0 +1,17 @@ +// 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. + +// THIS FILE WAS AUTO-GENERATED BY ./ntcore/generate_topics.py. DO NOT MODIFY + +package edu.wpi.first.networktables; + +/** + * NetworkTables Float entry. + * + *

Unlike NetworkTableEntry, the entry goes away when close() is called. + */ +public interface FloatEntry extends FloatSubscriber, FloatPublisher { + /** Stops publishing the entry if it's published. */ + void unpublish(); +} diff --git a/ntcore/src/generated/main/java/edu/wpi/first/networktables/FloatEntryImpl.java b/ntcore/src/generated/main/java/edu/wpi/first/networktables/FloatEntryImpl.java new file mode 100644 index 0000000000..f7efebfce4 --- /dev/null +++ b/ntcore/src/generated/main/java/edu/wpi/first/networktables/FloatEntryImpl.java @@ -0,0 +1,77 @@ +// 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. + +// THIS FILE WAS AUTO-GENERATED BY ./ntcore/generate_topics.py. DO NOT MODIFY + +package edu.wpi.first.networktables; + +/** NetworkTables Float implementation. */ +@SuppressWarnings("PMD.ArrayIsStoredDirectly") +final class FloatEntryImpl extends EntryBase implements FloatEntry { + /** + * Constructor. + * + * @param topic Topic + * @param handle Native handle + * @param defaultValue Default value for get() + */ + FloatEntryImpl(FloatTopic topic, int handle, float defaultValue) { + super(handle); + m_topic = topic; + m_defaultValue = defaultValue; + } + + @Override + public FloatTopic getTopic() { + return m_topic; + } + + @Override + public float get() { + return NetworkTablesJNI.getFloat(m_handle, m_defaultValue); + } + + @Override + public float get(float defaultValue) { + return NetworkTablesJNI.getFloat(m_handle, defaultValue); + } + + @Override + public TimestampedFloat getAtomic() { + return NetworkTablesJNI.getAtomicFloat(m_handle, m_defaultValue); + } + + @Override + public TimestampedFloat getAtomic(float defaultValue) { + return NetworkTablesJNI.getAtomicFloat(m_handle, defaultValue); + } + + @Override + public TimestampedFloat[] readQueue() { + return NetworkTablesJNI.readQueueFloat(m_handle); + } + + @Override + public float[] readQueueValues() { + return NetworkTablesJNI.readQueueValuesFloat(m_handle); + } + + @Override + public void set(float value, long time) { + NetworkTablesJNI.setFloat(m_handle, time, value); + } + + @Override + public void setDefault(float value) { + NetworkTablesJNI.setDefaultFloat(m_handle, 0, value); + } + + @Override + public void unpublish() { + NetworkTablesJNI.unpublish(m_handle); + } + + private final FloatTopic m_topic; + private final float m_defaultValue; +} diff --git a/ntcore/src/generated/main/java/edu/wpi/first/networktables/FloatPublisher.java b/ntcore/src/generated/main/java/edu/wpi/first/networktables/FloatPublisher.java new file mode 100644 index 0000000000..3f4b320fca --- /dev/null +++ b/ntcore/src/generated/main/java/edu/wpi/first/networktables/FloatPublisher.java @@ -0,0 +1,52 @@ +// 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. + +// THIS FILE WAS AUTO-GENERATED BY ./ntcore/generate_topics.py. DO NOT MODIFY + +package edu.wpi.first.networktables; + +import edu.wpi.first.util.function.FloatConsumer; + +/** NetworkTables Float publisher. */ +public interface FloatPublisher extends Publisher, FloatConsumer { + /** + * Get the corresponding topic. + * + * @return Topic + */ + @Override + FloatTopic getTopic(); + + /** + * Publish a new value using current NT time. + * + * @param value value to publish + */ + default void set(float value) { + set(value, 0); + } + + + /** + * Publish a new value. + * + * @param value value to publish + * @param time timestamp; 0 indicates current NT time should be used + */ + void set(float value, long time); + + /** + * Publish a default value. + * On reconnect, a default value will never be used in preference to a + * published value. + * + * @param value value + */ + void setDefault(float value); + + @Override + default void accept(float value) { + set(value); + } +} diff --git a/ntcore/src/generated/main/java/edu/wpi/first/networktables/FloatSubscriber.java b/ntcore/src/generated/main/java/edu/wpi/first/networktables/FloatSubscriber.java new file mode 100644 index 0000000000..758463b89e --- /dev/null +++ b/ntcore/src/generated/main/java/edu/wpi/first/networktables/FloatSubscriber.java @@ -0,0 +1,85 @@ +// 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. + +// THIS FILE WAS AUTO-GENERATED BY ./ntcore/generate_topics.py. DO NOT MODIFY + +package edu.wpi.first.networktables; + +import edu.wpi.first.util.function.FloatSupplier; + +/** NetworkTables Float subscriber. */ +@SuppressWarnings("PMD.MissingOverride") +public interface FloatSubscriber extends Subscriber, FloatSupplier { + /** + * Get the corresponding topic. + * + * @return Topic + */ + @Override + FloatTopic getTopic(); + + /** + * Get the last published value. + * If no value has been published, returns the stored default value. + * + * @return value + */ + float get(); + + /** + * Get the last published value. + * If no value has been published, returns the passed defaultValue. + * + * @param defaultValue default value to return if no value has been published + * @return value + */ + float get(float defaultValue); + + @Override + default float getAsFloat() { + return get(); + } + + /** + * Get the last published value along with its timestamp + * If no value has been published, returns the stored default value and a + * timestamp of 0. + * + * @return timestamped value + */ + TimestampedFloat getAtomic(); + + /** + * Get the last published value along with its timestamp + * If no value has been published, returns the passed defaultValue and a + * timestamp of 0. + * + * @param defaultValue default value to return if no value has been published + * @return timestamped value + */ + TimestampedFloat getAtomic(float defaultValue); + + /** + * Get an array of all value changes since the last call to readQueue. + * Also provides a timestamp for each value. + * + *

The "poll storage" subscribe option can be used to set the queue + * depth. + * + * @return Array of timestamped values; empty array if no new changes have + * been published since the previous call. + */ + TimestampedFloat[] readQueue(); + + /** + * Get an array of all value changes since the last call to readQueue. + * + *

The "poll storage" subscribe option can be used to set the queue + * depth. + * + * @return Array of values; empty array if no new changes have been + * published since the previous call. + */ + float[] readQueueValues(); +} diff --git a/ntcore/src/generated/main/java/edu/wpi/first/networktables/FloatTopic.java b/ntcore/src/generated/main/java/edu/wpi/first/networktables/FloatTopic.java new file mode 100644 index 0000000000..2ac7c7ca2c --- /dev/null +++ b/ntcore/src/generated/main/java/edu/wpi/first/networktables/FloatTopic.java @@ -0,0 +1,206 @@ +// 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. + +// THIS FILE WAS AUTO-GENERATED BY ./ntcore/generate_topics.py. DO NOT MODIFY + +package edu.wpi.first.networktables; + +/** NetworkTables Float topic. */ +public final class FloatTopic extends Topic { + /** The default type string for this topic type. */ + public static final String kTypeString = "float"; + + /** + * Construct from a generic topic. + * + * @param topic Topic + */ + public FloatTopic(Topic topic) { + super(topic.m_inst, topic.m_handle); + } + + /** + * Constructor; use NetworkTableInstance.getFloatTopic() instead. + * + * @param inst Instance + * @param handle Native handle + */ + public FloatTopic(NetworkTableInstance inst, int handle) { + super(inst, handle); + } + + /** + * Create a new subscriber to the topic. + * + *

The subscriber is only active as long as the returned object + * is not closed. + * + *

Subscribers that do not match the published data type do not return + * any values. To determine if the data type matches, use the appropriate + * Topic functions. + * + * @param defaultValue default value used when a default is not provided to a + * getter function + * @param options subscribe options + * @return subscriber + */ + public FloatSubscriber subscribe( + float defaultValue, + PubSubOption... options) { + return new FloatEntryImpl( + this, + NetworkTablesJNI.subscribe( + m_handle, NetworkTableType.kFloat.getValue(), + "float", options), + defaultValue); + } + + /** + * Create a new subscriber to the topic, with specified type string. + * + *

The subscriber is only active as long as the returned object + * is not closed. + * + *

Subscribers that do not match the published data type do not return + * any values. To determine if the data type matches, use the appropriate + * Topic functions. + * + * @param typeString type string + * @param defaultValue default value used when a default is not provided to a + * getter function + * @param options subscribe options + * @return subscriber + */ + public FloatSubscriber subscribeEx( + String typeString, + float defaultValue, + PubSubOption... options) { + return new FloatEntryImpl( + this, + NetworkTablesJNI.subscribe( + m_handle, NetworkTableType.kFloat.getValue(), + typeString, options), + defaultValue); + } + + /** + * Create a new publisher to the topic. + * + *

The publisher is only active as long as the returned object + * is not closed. + * + *

It is not possible to publish two different data types to the same + * topic. Conflicts between publishers are typically resolved by the server on + * a first-come, first-served basis. Any published values that do not match + * the topic's data type are dropped (ignored). To determine if the data type + * matches, use the appropriate Topic functions. + * + * @param options publish options + * @return publisher + */ + public FloatPublisher publish( + PubSubOption... options) { + return new FloatEntryImpl( + this, + NetworkTablesJNI.publish( + m_handle, NetworkTableType.kFloat.getValue(), + "float", options), + 0); + } + + /** + * Create a new publisher to the topic, with type string and initial properties. + * + *

The publisher is only active as long as the returned object + * is not closed. + * + *

It is not possible to publish two different data types to the same + * topic. Conflicts between publishers are typically resolved by the server on + * a first-come, first-served basis. Any published values that do not match + * the topic's data type are dropped (ignored). To determine if the data type + * matches, use the appropriate Topic functions. + * + * @param typeString type string + * @param properties JSON properties + * @param options publish options + * @return publisher + * @throws IllegalArgumentException if properties is not a JSON object + */ + public FloatPublisher publishEx( + String typeString, + String properties, + PubSubOption... options) { + return new FloatEntryImpl( + this, + NetworkTablesJNI.publishEx( + m_handle, NetworkTableType.kFloat.getValue(), + typeString, properties, options), + 0); + } + + /** + * Create a new entry for the topic. + * + *

Entries act as a combination of a subscriber and a weak publisher. The + * subscriber is active as long as the entry is not closed. The publisher is + * created when the entry is first written to, and remains active until either + * unpublish() is called or the entry is closed. + * + *

It is not possible to use two different data types with the same + * topic. Conflicts between publishers are typically resolved by the server on + * a first-come, first-served basis. Any published values that do not match + * the topic's data type are dropped (ignored), and the entry will show no new + * values if the data type does not match. To determine if the data type + * matches, use the appropriate Topic functions. + * + * @param defaultValue default value used when a default is not provided to a + * getter function + * @param options publish and/or subscribe options + * @return entry + */ + public FloatEntry getEntry( + float defaultValue, + PubSubOption... options) { + return new FloatEntryImpl( + this, + NetworkTablesJNI.getEntry( + m_handle, NetworkTableType.kFloat.getValue(), + "float", options), + defaultValue); + } + + /** + * Create a new entry for the topic, with specified type string. + * + *

Entries act as a combination of a subscriber and a weak publisher. The + * subscriber is active as long as the entry is not closed. The publisher is + * created when the entry is first written to, and remains active until either + * unpublish() is called or the entry is closed. + * + *

It is not possible to use two different data types with the same + * topic. Conflicts between publishers are typically resolved by the server on + * a first-come, first-served basis. Any published values that do not match + * the topic's data type are dropped (ignored), and the entry will show no new + * values if the data type does not match. To determine if the data type + * matches, use the appropriate Topic functions. + * + * @param typeString type string + * @param defaultValue default value used when a default is not provided to a + * getter function + * @param options publish and/or subscribe options + * @return entry + */ + public FloatEntry getEntryEx( + String typeString, + float defaultValue, + PubSubOption... options) { + return new FloatEntryImpl( + this, + NetworkTablesJNI.getEntry( + m_handle, NetworkTableType.kFloat.getValue(), + typeString, options), + defaultValue); + } + +} diff --git a/ntcore/src/generated/main/java/edu/wpi/first/networktables/GenericEntryImpl.java b/ntcore/src/generated/main/java/edu/wpi/first/networktables/GenericEntryImpl.java new file mode 100644 index 0000000000..b467c83f02 --- /dev/null +++ b/ntcore/src/generated/main/java/edu/wpi/first/networktables/GenericEntryImpl.java @@ -0,0 +1,815 @@ +// 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. + +// THIS FILE WAS AUTO-GENERATED BY ./ntcore/generate_topics.py. DO NOT MODIFY + +package edu.wpi.first.networktables; + +import java.nio.ByteBuffer; + +/** NetworkTables generic implementation. */ +final class GenericEntryImpl extends EntryBase implements GenericEntry { + /** + * Constructor. + * + * @param topic Topic + * @param handle Native handle + */ + GenericEntryImpl(Topic topic, int handle) { + super(handle); + m_topic = topic; + } + + @Override + public Topic getTopic() { + return m_topic; + } + + @Override + public NetworkTableValue get() { + return NetworkTablesJNI.getValue(m_handle); + } + + /** + * Gets the entry's value as a boolean. If the entry does not exist or is of different type, it + * will return the default value. + * + * @param defaultValue the value to be returned if no value is found + * @return the entry's value or the given default value + */ + @Override + public boolean getBoolean(boolean defaultValue) { + return NetworkTablesJNI.getBoolean(m_handle, defaultValue); + } + + /** + * Gets the entry's value as a long. If the entry does not exist or is of different type, it + * will return the default value. + * + * @param defaultValue the value to be returned if no value is found + * @return the entry's value or the given default value + */ + @Override + public long getInteger(long defaultValue) { + return NetworkTablesJNI.getInteger(m_handle, defaultValue); + } + + /** + * Gets the entry's value as a float. If the entry does not exist or is of different type, it + * will return the default value. + * + * @param defaultValue the value to be returned if no value is found + * @return the entry's value or the given default value + */ + @Override + public float getFloat(float defaultValue) { + return NetworkTablesJNI.getFloat(m_handle, defaultValue); + } + + /** + * Gets the entry's value as a double. If the entry does not exist or is of different type, it + * will return the default value. + * + * @param defaultValue the value to be returned if no value is found + * @return the entry's value or the given default value + */ + @Override + public double getDouble(double defaultValue) { + return NetworkTablesJNI.getDouble(m_handle, defaultValue); + } + + /** + * Gets the entry's value as a String. If the entry does not exist or is of different type, it + * will return the default value. + * + * @param defaultValue the value to be returned if no value is found + * @return the entry's value or the given default value + */ + @Override + public String getString(String defaultValue) { + return NetworkTablesJNI.getString(m_handle, defaultValue); + } + + /** + * Gets the entry's value as a byte[]. If the entry does not exist or is of different type, it + * will return the default value. + * + * @param defaultValue the value to be returned if no value is found + * @return the entry's value or the given default value + */ + @Override + public byte[] getRaw(byte[] defaultValue) { + return NetworkTablesJNI.getRaw(m_handle, defaultValue); + } + + /** + * Gets the entry's value as a boolean[]. If the entry does not exist or is of different type, it + * will return the default value. + * + * @param defaultValue the value to be returned if no value is found + * @return the entry's value or the given default value + */ + @Override + public boolean[] getBooleanArray(boolean[] defaultValue) { + return NetworkTablesJNI.getBooleanArray(m_handle, defaultValue); + } + + /** + * Gets the entry's value as a boolean array. If the entry does not exist or is of different type, + * it will return the default value. + * + * @param defaultValue the value to be returned if no value is found + * @return the entry's value or the given default value + */ + @Override + public Boolean[] getBooleanArray(Boolean[] defaultValue) { + return NetworkTableValue.fromNativeBooleanArray( + getBooleanArray(NetworkTableValue.toNativeBooleanArray(defaultValue))); + } + + /** + * Gets the entry's value as a long[]. If the entry does not exist or is of different type, it + * will return the default value. + * + * @param defaultValue the value to be returned if no value is found + * @return the entry's value or the given default value + */ + @Override + public long[] getIntegerArray(long[] defaultValue) { + return NetworkTablesJNI.getIntegerArray(m_handle, defaultValue); + } + + /** + * Gets the entry's value as a boolean array. If the entry does not exist or is of different type, + * it will return the default value. + * + * @param defaultValue the value to be returned if no value is found + * @return the entry's value or the given default value + */ + @Override + public Long[] getIntegerArray(Long[] defaultValue) { + return NetworkTableValue.fromNativeIntegerArray( + getIntegerArray(NetworkTableValue.toNativeIntegerArray(defaultValue))); + } + + /** + * Gets the entry's value as a float[]. If the entry does not exist or is of different type, it + * will return the default value. + * + * @param defaultValue the value to be returned if no value is found + * @return the entry's value or the given default value + */ + @Override + public float[] getFloatArray(float[] defaultValue) { + return NetworkTablesJNI.getFloatArray(m_handle, defaultValue); + } + + /** + * Gets the entry's value as a boolean array. If the entry does not exist or is of different type, + * it will return the default value. + * + * @param defaultValue the value to be returned if no value is found + * @return the entry's value or the given default value + */ + @Override + public Float[] getFloatArray(Float[] defaultValue) { + return NetworkTableValue.fromNativeFloatArray( + getFloatArray(NetworkTableValue.toNativeFloatArray(defaultValue))); + } + + /** + * Gets the entry's value as a double[]. If the entry does not exist or is of different type, it + * will return the default value. + * + * @param defaultValue the value to be returned if no value is found + * @return the entry's value or the given default value + */ + @Override + public double[] getDoubleArray(double[] defaultValue) { + return NetworkTablesJNI.getDoubleArray(m_handle, defaultValue); + } + + /** + * Gets the entry's value as a boolean array. If the entry does not exist or is of different type, + * it will return the default value. + * + * @param defaultValue the value to be returned if no value is found + * @return the entry's value or the given default value + */ + @Override + public Double[] getDoubleArray(Double[] defaultValue) { + return NetworkTableValue.fromNativeDoubleArray( + getDoubleArray(NetworkTableValue.toNativeDoubleArray(defaultValue))); + } + + /** + * Gets the entry's value as a String[]. If the entry does not exist or is of different type, it + * will return the default value. + * + * @param defaultValue the value to be returned if no value is found + * @return the entry's value or the given default value + */ + @Override + public String[] getStringArray(String[] defaultValue) { + return NetworkTablesJNI.getStringArray(m_handle, defaultValue); + } + + @Override + public NetworkTableValue[] readQueue() { + return NetworkTablesJNI.readQueueValue(m_handle); + } + + @Override + public boolean set(NetworkTableValue value) { + long time = value.getTime(); + Object otherValue = value.getValue(); + switch (value.getType()) { + case kBoolean: + return NetworkTablesJNI.setBoolean(m_handle, time, (Boolean) otherValue); + case kInteger: + return NetworkTablesJNI.setInteger( + m_handle, time, ((Number) otherValue).longValue()); + case kFloat: + return NetworkTablesJNI.setFloat( + m_handle, time, ((Number) otherValue).floatValue()); + case kDouble: + return NetworkTablesJNI.setDouble( + m_handle, time, ((Number) otherValue).doubleValue()); + case kString: + return NetworkTablesJNI.setString(m_handle, time, (String) otherValue); + case kRaw: + return NetworkTablesJNI.setRaw(m_handle, time, (byte[]) otherValue); + case kBooleanArray: + return NetworkTablesJNI.setBooleanArray(m_handle, time, (boolean[]) otherValue); + case kIntegerArray: + return NetworkTablesJNI.setIntegerArray(m_handle, time, (long[]) otherValue); + case kFloatArray: + return NetworkTablesJNI.setFloatArray(m_handle, time, (float[]) otherValue); + case kDoubleArray: + return NetworkTablesJNI.setDoubleArray(m_handle, time, (double[]) otherValue); + case kStringArray: + return NetworkTablesJNI.setStringArray(m_handle, time, (String[]) otherValue); + default: + return true; + } + } + + /** + * Sets the entry's value. + * + * @param value the value that will be assigned + * @return False if the table key already exists with a different type + * @throws IllegalArgumentException if the value is not a known type + */ + @Override + public boolean setValue(Object value, long time) { + if (value instanceof NetworkTableValue) { + return set((NetworkTableValue) value); + } else if (value instanceof Boolean) { + return setBoolean((Boolean) value, time); + } else if (value instanceof Long) { + return setInteger((Long) value, time); + } else if (value instanceof Float) { + return setFloat((Float) value, time); + } else if (value instanceof Number) { + return setNumber((Number) value, time); + } else if (value instanceof String) { + return setString((String) value, time); + } else if (value instanceof byte[]) { + return setRaw((byte[]) value, time); + } else if (value instanceof boolean[]) { + return setBooleanArray((boolean[]) value, time); + } else if (value instanceof long[]) { + return setIntegerArray((long[]) value, time); + } else if (value instanceof float[]) { + return setFloatArray((float[]) value, time); + } else if (value instanceof double[]) { + return setDoubleArray((double[]) value, time); + } else if (value instanceof Boolean[]) { + return setBooleanArray((Boolean[]) value, time); + } else if (value instanceof Long[]) { + return setIntegerArray((Long[]) value, time); + } else if (value instanceof Float[]) { + return setFloatArray((Float[]) value, time); + } else if (value instanceof Number[]) { + return setNumberArray((Number[]) value, time); + } else if (value instanceof String[]) { + return setStringArray((String[]) value, time); + } else { + throw new IllegalArgumentException( + "Value of type " + value.getClass().getName() + " cannot be put into a table"); + } + } + + + /** + * Sets the entry's value. + * + * @param value the value to set + * @return False if the entry exists with a different type + */ + @Override + public boolean setBoolean(boolean value, long time) { + return NetworkTablesJNI.setBoolean(m_handle, time, value); + } + + + /** + * Sets the entry's value. + * + * @param value the value to set + * @return False if the entry exists with a different type + */ + @Override + public boolean setInteger(long value, long time) { + return NetworkTablesJNI.setInteger(m_handle, time, value); + } + + + /** + * Sets the entry's value. + * + * @param value the value to set + * @return False if the entry exists with a different type + */ + @Override + public boolean setFloat(float value, long time) { + return NetworkTablesJNI.setFloat(m_handle, time, value); + } + + + /** + * Sets the entry's value. + * + * @param value the value to set + * @return False if the entry exists with a different type + */ + @Override + public boolean setDouble(double value, long time) { + return NetworkTablesJNI.setDouble(m_handle, time, value); + } + + + /** + * Sets the entry's value. + * + * @param value the value to set + * @return False if the entry exists with a different type + */ + @Override + public boolean setString(String value, long time) { + return NetworkTablesJNI.setString(m_handle, time, value); + } + + + /** + * Sets the entry's value. + * + * @param value the value to set + * @param start Start position of data (in buffer) + * @param len Length of data (must be less than or equal to value.length - start) + * @return False if the entry exists with a different type + */ + @Override + public boolean setRaw(byte[] value, int start, int len, long time) { + return NetworkTablesJNI.setRaw(m_handle, time, value, start, len); + } + + /** + * Sets the entry's value. + * + * @param value the value to set + * @param start Start position of data (in buffer) + * @param len Length of data (must be less than or equal to value.capacity() - start) + * @return False if the entry exists with a different type + */ + @Override + public boolean setRaw(ByteBuffer value, int start, int len, long time) { + return NetworkTablesJNI.setRaw(m_handle, time, value, start, len); + } + + + /** + * Sets the entry's value. + * + * @param value the value to set + * @return False if the entry exists with a different type + */ + @Override + public boolean setBooleanArray(boolean[] value, long time) { + return NetworkTablesJNI.setBooleanArray(m_handle, time, value); + } + + /** + * Sets the entry's value. + * + * @param value the value to set + * @return False if the entry exists with a different type + */ + @Override + public boolean setBooleanArray(Boolean[] value, long time) { + return setBooleanArray(NetworkTableValue.toNativeBooleanArray(value), time); + } + + + /** + * Sets the entry's value. + * + * @param value the value to set + * @return False if the entry exists with a different type + */ + @Override + public boolean setIntegerArray(long[] value, long time) { + return NetworkTablesJNI.setIntegerArray(m_handle, time, value); + } + + /** + * Sets the entry's value. + * + * @param value the value to set + * @return False if the entry exists with a different type + */ + @Override + public boolean setIntegerArray(Long[] value, long time) { + return setIntegerArray(NetworkTableValue.toNativeIntegerArray(value), time); + } + + + /** + * Sets the entry's value. + * + * @param value the value to set + * @return False if the entry exists with a different type + */ + @Override + public boolean setFloatArray(float[] value, long time) { + return NetworkTablesJNI.setFloatArray(m_handle, time, value); + } + + /** + * Sets the entry's value. + * + * @param value the value to set + * @return False if the entry exists with a different type + */ + @Override + public boolean setFloatArray(Float[] value, long time) { + return setFloatArray(NetworkTableValue.toNativeFloatArray(value), time); + } + + + /** + * Sets the entry's value. + * + * @param value the value to set + * @return False if the entry exists with a different type + */ + @Override + public boolean setDoubleArray(double[] value, long time) { + return NetworkTablesJNI.setDoubleArray(m_handle, time, value); + } + + /** + * Sets the entry's value. + * + * @param value the value to set + * @return False if the entry exists with a different type + */ + @Override + public boolean setDoubleArray(Double[] value, long time) { + return setDoubleArray(NetworkTableValue.toNativeDoubleArray(value), time); + } + + + /** + * Sets the entry's value. + * + * @param value the value to set + * @return False if the entry exists with a different type + */ + @Override + public boolean setStringArray(String[] value, long time) { + return NetworkTablesJNI.setStringArray(m_handle, time, value); + } + + /** + * Sets the entry's value. + * + * @param value the value to set + * @return False if the entry exists with a different type + */ + public boolean setNumber(Number value, long time) { + return setDouble(value.doubleValue(), time); + } + + /** + * Sets the entry's value. + * + * @param value the value to set + * @return False if the entry exists with a different type + */ + public boolean setNumberArray(Number[] value, long time) { + return setDoubleArray(NetworkTableValue.toNativeDoubleArray(value), time); + } + + @Override + public boolean setDefault(NetworkTableValue defaultValue) { + long time = defaultValue.getTime(); + Object otherValue = defaultValue.getValue(); + switch (defaultValue.getType()) { + case kBoolean: + return NetworkTablesJNI.setDefaultBoolean(m_handle, time, (Boolean) otherValue); + case kInteger: + return NetworkTablesJNI.setDefaultInteger( + m_handle, time, ((Number) otherValue).longValue()); + case kFloat: + return NetworkTablesJNI.setDefaultFloat( + m_handle, time, ((Number) otherValue).floatValue()); + case kDouble: + return NetworkTablesJNI.setDefaultDouble( + m_handle, time, ((Number) otherValue).doubleValue()); + case kString: + return NetworkTablesJNI.setDefaultString(m_handle, time, (String) otherValue); + case kRaw: + return NetworkTablesJNI.setDefaultRaw(m_handle, time, (byte[]) otherValue); + case kBooleanArray: + return NetworkTablesJNI.setDefaultBooleanArray(m_handle, time, (boolean[]) otherValue); + case kIntegerArray: + return NetworkTablesJNI.setDefaultIntegerArray(m_handle, time, (long[]) otherValue); + case kFloatArray: + return NetworkTablesJNI.setDefaultFloatArray(m_handle, time, (float[]) otherValue); + case kDoubleArray: + return NetworkTablesJNI.setDefaultDoubleArray(m_handle, time, (double[]) otherValue); + case kStringArray: + return NetworkTablesJNI.setDefaultStringArray(m_handle, time, (String[]) otherValue); + default: + return true; + } + } + + /** + * Sets the entry's value if it does not exist. + * + * @param defaultValue the default value to set + * @return False if the entry exists with a different type + * @throws IllegalArgumentException if the value is not a known type + */ + @Override + public boolean setDefaultValue(Object defaultValue) { + if (defaultValue instanceof NetworkTableValue) { + return setDefault((NetworkTableValue) defaultValue); + } else if (defaultValue instanceof Boolean) { + return setDefaultBoolean((Boolean) defaultValue); + } else if (defaultValue instanceof Integer) { + return setDefaultInteger((Integer) defaultValue); + } else if (defaultValue instanceof Float) { + return setDefaultFloat((Float) defaultValue); + } else if (defaultValue instanceof Number) { + return setDefaultNumber((Number) defaultValue); + } else if (defaultValue instanceof String) { + return setDefaultString((String) defaultValue); + } else if (defaultValue instanceof byte[]) { + return setDefaultRaw((byte[]) defaultValue); + } else if (defaultValue instanceof boolean[]) { + return setDefaultBooleanArray((boolean[]) defaultValue); + } else if (defaultValue instanceof long[]) { + return setDefaultIntegerArray((long[]) defaultValue); + } else if (defaultValue instanceof float[]) { + return setDefaultFloatArray((float[]) defaultValue); + } else if (defaultValue instanceof double[]) { + return setDefaultDoubleArray((double[]) defaultValue); + } else if (defaultValue instanceof Boolean[]) { + return setDefaultBooleanArray((Boolean[]) defaultValue); + } else if (defaultValue instanceof Long[]) { + return setDefaultIntegerArray((Long[]) defaultValue); + } else if (defaultValue instanceof Float[]) { + return setDefaultFloatArray((Float[]) defaultValue); + } else if (defaultValue instanceof Number[]) { + return setDefaultNumberArray((Number[]) defaultValue); + } else if (defaultValue instanceof String[]) { + return setDefaultStringArray((String[]) defaultValue); + } else { + throw new IllegalArgumentException( + "Value of type " + defaultValue.getClass().getName() + " cannot be put into a table"); + } + } + + + /** + * Sets the entry's value if it does not exist. + * + * @param defaultValue the default value to set + * @return False if the entry exists with a different type + */ + @Override + public boolean setDefaultBoolean(boolean defaultValue) { + return NetworkTablesJNI.setDefaultBoolean(m_handle, 0, defaultValue); + } + + + /** + * Sets the entry's value if it does not exist. + * + * @param defaultValue the default value to set + * @return False if the entry exists with a different type + */ + @Override + public boolean setDefaultInteger(long defaultValue) { + return NetworkTablesJNI.setDefaultInteger(m_handle, 0, defaultValue); + } + + + /** + * Sets the entry's value if it does not exist. + * + * @param defaultValue the default value to set + * @return False if the entry exists with a different type + */ + @Override + public boolean setDefaultFloat(float defaultValue) { + return NetworkTablesJNI.setDefaultFloat(m_handle, 0, defaultValue); + } + + + /** + * Sets the entry's value if it does not exist. + * + * @param defaultValue the default value to set + * @return False if the entry exists with a different type + */ + @Override + public boolean setDefaultDouble(double defaultValue) { + return NetworkTablesJNI.setDefaultDouble(m_handle, 0, defaultValue); + } + + + /** + * Sets the entry's value if it does not exist. + * + * @param defaultValue the default value to set + * @return False if the entry exists with a different type + */ + @Override + public boolean setDefaultString(String defaultValue) { + return NetworkTablesJNI.setDefaultString(m_handle, 0, defaultValue); + } + + + /** + * Sets the entry's value if it does not exist. + * + * @param defaultValue the default value to set + * @param start Start position of data (in buffer) + * @param len Length of data (must be less than or equal to value.length - start) + * @return False if the entry exists with a different type + */ + @Override + public boolean setDefaultRaw(byte[] defaultValue, int start, int len) { + return NetworkTablesJNI.setDefaultRaw(m_handle, 0, defaultValue, start, len); + } + + /** + * Sets the entry's value if it does not exist. + * + * @param defaultValue the default value to set + * @param start Start position of data (in buffer) + * @param len Length of data (must be less than or equal to value.capacity() - start) + * @return False if the entry exists with a different type + */ + @Override + public boolean setDefaultRaw(ByteBuffer defaultValue, int start, int len) { + return NetworkTablesJNI.setDefaultRaw(m_handle, 0, defaultValue, start, len); + } + + + /** + * Sets the entry's value if it does not exist. + * + * @param defaultValue the default value to set + * @return False if the entry exists with a different type + */ + @Override + public boolean setDefaultBooleanArray(boolean[] defaultValue) { + return NetworkTablesJNI.setDefaultBooleanArray(m_handle, 0, defaultValue); + } + + /** + * Sets the entry's value if it does not exist. + * + * @param defaultValue the default value to set + * @return False if the entry exists with a different type + */ + @Override + public boolean setDefaultBooleanArray(Boolean[] defaultValue) { + return setDefaultBooleanArray(NetworkTableValue.toNativeBooleanArray(defaultValue)); + } + + + /** + * Sets the entry's value if it does not exist. + * + * @param defaultValue the default value to set + * @return False if the entry exists with a different type + */ + @Override + public boolean setDefaultIntegerArray(long[] defaultValue) { + return NetworkTablesJNI.setDefaultIntegerArray(m_handle, 0, defaultValue); + } + + /** + * Sets the entry's value if it does not exist. + * + * @param defaultValue the default value to set + * @return False if the entry exists with a different type + */ + @Override + public boolean setDefaultIntegerArray(Long[] defaultValue) { + return setDefaultIntegerArray(NetworkTableValue.toNativeIntegerArray(defaultValue)); + } + + + /** + * Sets the entry's value if it does not exist. + * + * @param defaultValue the default value to set + * @return False if the entry exists with a different type + */ + @Override + public boolean setDefaultFloatArray(float[] defaultValue) { + return NetworkTablesJNI.setDefaultFloatArray(m_handle, 0, defaultValue); + } + + /** + * Sets the entry's value if it does not exist. + * + * @param defaultValue the default value to set + * @return False if the entry exists with a different type + */ + @Override + public boolean setDefaultFloatArray(Float[] defaultValue) { + return setDefaultFloatArray(NetworkTableValue.toNativeFloatArray(defaultValue)); + } + + + /** + * Sets the entry's value if it does not exist. + * + * @param defaultValue the default value to set + * @return False if the entry exists with a different type + */ + @Override + public boolean setDefaultDoubleArray(double[] defaultValue) { + return NetworkTablesJNI.setDefaultDoubleArray(m_handle, 0, defaultValue); + } + + /** + * Sets the entry's value if it does not exist. + * + * @param defaultValue the default value to set + * @return False if the entry exists with a different type + */ + @Override + public boolean setDefaultDoubleArray(Double[] defaultValue) { + return setDefaultDoubleArray(NetworkTableValue.toNativeDoubleArray(defaultValue)); + } + + + /** + * Sets the entry's value if it does not exist. + * + * @param defaultValue the default value to set + * @return False if the entry exists with a different type + */ + @Override + public boolean setDefaultStringArray(String[] defaultValue) { + return NetworkTablesJNI.setDefaultStringArray(m_handle, 0, defaultValue); + } + + /** + * Sets the entry's value if it does not exist. + * + * @param defaultValue the default value to set + * @return False if the entry exists with a different type + */ + public boolean setDefaultNumber(Number defaultValue) { + return setDefaultDouble(defaultValue.doubleValue()); + } + + /** + * Sets the entry's value if it does not exist. + * + * @param defaultValue the default value to set + * @return False if the entry exists with a different type + */ + public boolean setDefaultNumberArray(Number[] defaultValue) { + return setDefaultDoubleArray(NetworkTableValue.toNativeDoubleArray(defaultValue)); + } + + @Override + public void unpublish() { + NetworkTablesJNI.unpublish(m_handle); + } + + private final Topic m_topic; +} diff --git a/ntcore/src/generated/main/java/edu/wpi/first/networktables/GenericPublisher.java b/ntcore/src/generated/main/java/edu/wpi/first/networktables/GenericPublisher.java new file mode 100644 index 0000000000..8fd03ec330 --- /dev/null +++ b/ntcore/src/generated/main/java/edu/wpi/first/networktables/GenericPublisher.java @@ -0,0 +1,568 @@ +// 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. + +// THIS FILE WAS AUTO-GENERATED BY ./ntcore/generate_topics.py. DO NOT MODIFY + +package edu.wpi.first.networktables; + +import java.nio.ByteBuffer; +import java.util.function.Consumer; + +/** NetworkTables generic publisher. */ +public interface GenericPublisher extends Publisher, Consumer { + /** + * Get the corresponding topic. + * + * @return Topic + */ + @Override + Topic getTopic(); + + /** + * Publish a new value. + * + * @param value value to publish + * @return False if the topic already exists with a different type + */ + boolean set(NetworkTableValue value); + + /** + * Publish a new value. + * + * @param value value to publish + * @return False if the topic already exists with a different type + * @throws IllegalArgumentException if the value is not a known type + */ + default boolean setValue(Object value) { + return setValue(value, 0); + } + + /** + * Publish a new value. + * + * @param value value to publish + * @param time timestamp; 0 indicates current NT time should be used + * @return False if the topic already exists with a different type + * @throws IllegalArgumentException if the value is not a known type + */ + boolean setValue(Object value, long time); + + /** + * Publish a new value. + * + * @param value value to publish + * @return False if the topic already exists with a different type + */ + default boolean setBoolean(boolean value) { + return setBoolean(value, 0); + } + + /** + * Publish a new value. + * + * @param value value to publish + * @param time timestamp; 0 indicates current NT time should be used + * @return False if the topic already exists with a different type + */ + boolean setBoolean(boolean value, long time); + + /** + * Publish a new value. + * + * @param value value to publish + * @return False if the topic already exists with a different type + */ + default boolean setInteger(long value) { + return setInteger(value, 0); + } + + /** + * Publish a new value. + * + * @param value value to publish + * @param time timestamp; 0 indicates current NT time should be used + * @return False if the topic already exists with a different type + */ + boolean setInteger(long value, long time); + + /** + * Publish a new value. + * + * @param value value to publish + * @return False if the topic already exists with a different type + */ + default boolean setFloat(float value) { + return setFloat(value, 0); + } + + /** + * Publish a new value. + * + * @param value value to publish + * @param time timestamp; 0 indicates current NT time should be used + * @return False if the topic already exists with a different type + */ + boolean setFloat(float value, long time); + + /** + * Publish a new value. + * + * @param value value to publish + * @return False if the topic already exists with a different type + */ + default boolean setDouble(double value) { + return setDouble(value, 0); + } + + /** + * Publish a new value. + * + * @param value value to publish + * @param time timestamp; 0 indicates current NT time should be used + * @return False if the topic already exists with a different type + */ + boolean setDouble(double value, long time); + + /** + * Publish a new value. + * + * @param value value to publish + * @return False if the topic already exists with a different type + */ + default boolean setString(String value) { + return setString(value, 0); + } + + /** + * Publish a new value. + * + * @param value value to publish + * @param time timestamp; 0 indicates current NT time should be used + * @return False if the topic already exists with a different type + */ + boolean setString(String value, long time); + + /** + * Publish a new value. + * + * @param value value to publish + * @return False if the topic already exists with a different type + */ + default boolean setRaw(byte[] value) { + return setRaw(value, 0); + } + + /** + * Publish a new value. + * + * @param value value to publish + * @return False if the topic already exists with a different type + */ + default boolean setRaw(ByteBuffer value) { + return setRaw(value, 0); + } + + /** + * Publish a new value. + * + * @param value value to publish + * @param time timestamp; 0 indicates current NT time should be used + * @return False if the topic already exists with a different type + */ + default boolean setRaw(byte[] value, long time) { + return setRaw(value, 0, value.length, time); + } + + /** + * Publish a new value. + * + * @param value value to publish; will send from value.position() to value.limit() + * @param time timestamp; 0 indicates current NT time should be used + * @return False if the topic already exists with a different type + */ + default boolean setRaw(ByteBuffer value, long time) { + int pos = value.position(); + return setRaw(value, pos, value.limit() - pos, time); + } + + /** + * Publish a new value. + * + * @param value value to publish + * @param start Start position of data (in buffer) + * @param len Length of data (must be less than or equal to value.length - start) + * @return False if the topic already exists with a different type + */ + default boolean setRaw(byte[] value, int start, int len) { + return setRaw(value, start, len, 0); + } + + /** + * Publish a new value. + * + * @param value value to publish + * @param start Start position of data (in buffer) + * @param len Length of data (must be less than or equal to value.length - start) + * @param time timestamp; 0 indicates current NT time should be used + * @return False if the topic already exists with a different type + */ + boolean setRaw(byte[] value, int start, int len, long time); + + /** + * Publish a new value. + * + * @param value value to publish + * @param start Start position of data (in buffer) + * @param len Length of data (must be less than or equal to value.capacity() - start) + * @return False if the topic already exists with a different type + */ + default boolean setRaw(ByteBuffer value, int start, int len) { + return setRaw(value, start, len, 0); + } + + /** + * Publish a new value. + * + * @param value value to publish + * @param start Start position of data (in buffer) + * @param len Length of data (must be less than or equal to value.capacity() - start) + * @param time timestamp; 0 indicates current NT time should be used + * @return False if the topic already exists with a different type + */ + boolean setRaw(ByteBuffer value, int start, int len, long time); + + /** + * Publish a new value. + * + * @param value value to publish + * @return False if the topic already exists with a different type + */ + default boolean setBooleanArray(boolean[] value) { + return setBooleanArray(value, 0); + } + + /** + * Publish a new value. + * + * @param value value to publish + * @param time timestamp; 0 indicates current NT time should be used + * @return False if the topic already exists with a different type + */ + boolean setBooleanArray(boolean[] value, long time); + + /** + * Publish a new value. + * + * @param value value to publish + * @return False if the topic already exists with a different type + */ + default boolean setBooleanArray(Boolean[] value) { + return setBooleanArray(value, 0); + } + + /** + * Publish a new value. + * + * @param value value to publish + * @param time timestamp; 0 indicates current NT time should be used + * @return False if the topic already exists with a different type + */ + boolean setBooleanArray(Boolean[] value, long time); + + /** + * Publish a new value. + * + * @param value value to publish + * @return False if the topic already exists with a different type + */ + default boolean setIntegerArray(long[] value) { + return setIntegerArray(value, 0); + } + + /** + * Publish a new value. + * + * @param value value to publish + * @param time timestamp; 0 indicates current NT time should be used + * @return False if the topic already exists with a different type + */ + boolean setIntegerArray(long[] value, long time); + + /** + * Publish a new value. + * + * @param value value to publish + * @return False if the topic already exists with a different type + */ + default boolean setIntegerArray(Long[] value) { + return setIntegerArray(value, 0); + } + + /** + * Publish a new value. + * + * @param value value to publish + * @param time timestamp; 0 indicates current NT time should be used + * @return False if the topic already exists with a different type + */ + boolean setIntegerArray(Long[] value, long time); + + /** + * Publish a new value. + * + * @param value value to publish + * @return False if the topic already exists with a different type + */ + default boolean setFloatArray(float[] value) { + return setFloatArray(value, 0); + } + + /** + * Publish a new value. + * + * @param value value to publish + * @param time timestamp; 0 indicates current NT time should be used + * @return False if the topic already exists with a different type + */ + boolean setFloatArray(float[] value, long time); + + /** + * Publish a new value. + * + * @param value value to publish + * @return False if the topic already exists with a different type + */ + default boolean setFloatArray(Float[] value) { + return setFloatArray(value, 0); + } + + /** + * Publish a new value. + * + * @param value value to publish + * @param time timestamp; 0 indicates current NT time should be used + * @return False if the topic already exists with a different type + */ + boolean setFloatArray(Float[] value, long time); + + /** + * Publish a new value. + * + * @param value value to publish + * @return False if the topic already exists with a different type + */ + default boolean setDoubleArray(double[] value) { + return setDoubleArray(value, 0); + } + + /** + * Publish a new value. + * + * @param value value to publish + * @param time timestamp; 0 indicates current NT time should be used + * @return False if the topic already exists with a different type + */ + boolean setDoubleArray(double[] value, long time); + + /** + * Publish a new value. + * + * @param value value to publish + * @return False if the topic already exists with a different type + */ + default boolean setDoubleArray(Double[] value) { + return setDoubleArray(value, 0); + } + + /** + * Publish a new value. + * + * @param value value to publish + * @param time timestamp; 0 indicates current NT time should be used + * @return False if the topic already exists with a different type + */ + boolean setDoubleArray(Double[] value, long time); + + /** + * Publish a new value. + * + * @param value value to publish + * @return False if the topic already exists with a different type + */ + default boolean setStringArray(String[] value) { + return setStringArray(value, 0); + } + + /** + * Publish a new value. + * + * @param value value to publish + * @param time timestamp; 0 indicates current NT time should be used + * @return False if the topic already exists with a different type + */ + boolean setStringArray(String[] value, long time); + + /** + * Sets the entry's value if it does not exist. + * + * @param defaultValue the default value to set + * @return False if the entry exists with a different type + */ + boolean setDefault(NetworkTableValue defaultValue); + + /** + * Sets the entry's value if it does not exist. + * + * @param defaultValue the default value to set + * @return False if the entry exists with a different type + * @throws IllegalArgumentException if the value is not a known type + */ + boolean setDefaultValue(Object defaultValue); + + + /** + * Sets the entry's value if it does not exist. + * + * @param defaultValue the default value to set + * @return False if the entry exists with a different type + */ + boolean setDefaultBoolean(boolean defaultValue); + + + /** + * Sets the entry's value if it does not exist. + * + * @param defaultValue the default value to set + * @return False if the entry exists with a different type + */ + boolean setDefaultInteger(long defaultValue); + + + /** + * Sets the entry's value if it does not exist. + * + * @param defaultValue the default value to set + * @return False if the entry exists with a different type + */ + boolean setDefaultFloat(float defaultValue); + + + /** + * Sets the entry's value if it does not exist. + * + * @param defaultValue the default value to set + * @return False if the entry exists with a different type + */ + boolean setDefaultDouble(double defaultValue); + + + /** + * Sets the entry's value if it does not exist. + * + * @param defaultValue the default value to set + * @return False if the entry exists with a different type + */ + boolean setDefaultString(String defaultValue); + + + /** + * Sets the entry's value if it does not exist. + * + * @param defaultValue the default value to set + * @return False if the entry exists with a different type + */ + default boolean setDefaultRaw(byte[] defaultValue) { + return setDefaultRaw(defaultValue, 0, defaultValue.length); + } + + /** + * Sets the entry's value if it does not exist. + * + * @param defaultValue the default value to set; will send from defaultValue.position() to + * defaultValue.limit() + * @return False if the entry exists with a different type + */ + default boolean setDefaultRaw(ByteBuffer defaultValue) { + int pos = defaultValue.position(); + return setDefaultRaw(defaultValue, pos, defaultValue.limit() - pos); + } + + /** + * Sets the entry's value if it does not exist. + * + * @param defaultValue the default value to set + * @param start Start position of data (in buffer) + * @param len Length of data (must be less than or equal to value.length - start) + * @return False if the entry exists with a different type + */ + boolean setDefaultRaw(byte[] defaultValue, int start, int len); + + /** + * Sets the entry's value if it does not exist. + * + * @param defaultValue the default value to set + * @param start Start position of data (in buffer) + * @param len Length of data (must be less than or equal to value.capacity() - start) + * @return False if the entry exists with a different type + */ + boolean setDefaultRaw(ByteBuffer defaultValue, int start, int len); + + + /** + * Sets the entry's value if it does not exist. + * + * @param defaultValue the default value to set + * @return False if the entry exists with a different type + */ + boolean setDefaultBooleanArray(boolean[] defaultValue); + + boolean setDefaultBooleanArray(Boolean[] defaultValue); + + + /** + * Sets the entry's value if it does not exist. + * + * @param defaultValue the default value to set + * @return False if the entry exists with a different type + */ + boolean setDefaultIntegerArray(long[] defaultValue); + + boolean setDefaultIntegerArray(Long[] defaultValue); + + + /** + * Sets the entry's value if it does not exist. + * + * @param defaultValue the default value to set + * @return False if the entry exists with a different type + */ + boolean setDefaultFloatArray(float[] defaultValue); + + boolean setDefaultFloatArray(Float[] defaultValue); + + + /** + * Sets the entry's value if it does not exist. + * + * @param defaultValue the default value to set + * @return False if the entry exists with a different type + */ + boolean setDefaultDoubleArray(double[] defaultValue); + + boolean setDefaultDoubleArray(Double[] defaultValue); + + + /** + * Sets the entry's value if it does not exist. + * + * @param defaultValue the default value to set + * @return False if the entry exists with a different type + */ + boolean setDefaultStringArray(String[] defaultValue); + + @Override + default void accept(NetworkTableValue value) { + set(value); + } +} diff --git a/ntcore/src/generated/main/java/edu/wpi/first/networktables/GenericSubscriber.java b/ntcore/src/generated/main/java/edu/wpi/first/networktables/GenericSubscriber.java new file mode 100644 index 0000000000..7d7ca9639b --- /dev/null +++ b/ntcore/src/generated/main/java/edu/wpi/first/networktables/GenericSubscriber.java @@ -0,0 +1,176 @@ +// 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. + +// THIS FILE WAS AUTO-GENERATED BY ./ntcore/generate_topics.py. DO NOT MODIFY + +package edu.wpi.first.networktables; + +import java.util.function.Supplier; + +/** NetworkTables generic subscriber. */ +@SuppressWarnings("PMD.MissingOverride") +public interface GenericSubscriber extends Subscriber, Supplier { + /** + * Get the corresponding topic. + * + * @return Topic + */ + @Override + Topic getTopic(); + + /** + * Get the last published value. + * If no value has been published, returns a value with type NetworkTableType.kUnassigned. + * + * @return value + */ + NetworkTableValue get(); + + /** + * Gets the entry's value as a boolean. If the entry does not exist or is of different type, it + * will return the default value. + * + * @param defaultValue the value to be returned if no value is found + * @return the entry's value or the given default value + */ + boolean getBoolean(boolean defaultValue); + + /** + * Gets the entry's value as a long. If the entry does not exist or is of different type, it + * will return the default value. + * + * @param defaultValue the value to be returned if no value is found + * @return the entry's value or the given default value + */ + long getInteger(long defaultValue); + + /** + * Gets the entry's value as a float. If the entry does not exist or is of different type, it + * will return the default value. + * + * @param defaultValue the value to be returned if no value is found + * @return the entry's value or the given default value + */ + float getFloat(float defaultValue); + + /** + * Gets the entry's value as a double. If the entry does not exist or is of different type, it + * will return the default value. + * + * @param defaultValue the value to be returned if no value is found + * @return the entry's value or the given default value + */ + double getDouble(double defaultValue); + + /** + * Gets the entry's value as a String. If the entry does not exist or is of different type, it + * will return the default value. + * + * @param defaultValue the value to be returned if no value is found + * @return the entry's value or the given default value + */ + String getString(String defaultValue); + + /** + * Gets the entry's value as a byte[]. If the entry does not exist or is of different type, it + * will return the default value. + * + * @param defaultValue the value to be returned if no value is found + * @return the entry's value or the given default value + */ + byte[] getRaw(byte[] defaultValue); + + /** + * Gets the entry's value as a boolean[]. If the entry does not exist or is of different type, it + * will return the default value. + * + * @param defaultValue the value to be returned if no value is found + * @return the entry's value or the given default value + */ + boolean[] getBooleanArray(boolean[] defaultValue); + + /** + * Gets the entry's value as a boolean array. If the entry does not exist or is of different type, + * it will return the default value. + * + * @param defaultValue the value to be returned if no value is found + * @return the entry's value or the given default value + */ + Boolean[] getBooleanArray(Boolean[] defaultValue); + + /** + * Gets the entry's value as a long[]. If the entry does not exist or is of different type, it + * will return the default value. + * + * @param defaultValue the value to be returned if no value is found + * @return the entry's value or the given default value + */ + long[] getIntegerArray(long[] defaultValue); + + /** + * Gets the entry's value as a boolean array. If the entry does not exist or is of different type, + * it will return the default value. + * + * @param defaultValue the value to be returned if no value is found + * @return the entry's value or the given default value + */ + Long[] getIntegerArray(Long[] defaultValue); + + /** + * Gets the entry's value as a float[]. If the entry does not exist or is of different type, it + * will return the default value. + * + * @param defaultValue the value to be returned if no value is found + * @return the entry's value or the given default value + */ + float[] getFloatArray(float[] defaultValue); + + /** + * Gets the entry's value as a boolean array. If the entry does not exist or is of different type, + * it will return the default value. + * + * @param defaultValue the value to be returned if no value is found + * @return the entry's value or the given default value + */ + Float[] getFloatArray(Float[] defaultValue); + + /** + * Gets the entry's value as a double[]. If the entry does not exist or is of different type, it + * will return the default value. + * + * @param defaultValue the value to be returned if no value is found + * @return the entry's value or the given default value + */ + double[] getDoubleArray(double[] defaultValue); + + /** + * Gets the entry's value as a boolean array. If the entry does not exist or is of different type, + * it will return the default value. + * + * @param defaultValue the value to be returned if no value is found + * @return the entry's value or the given default value + */ + Double[] getDoubleArray(Double[] defaultValue); + + /** + * Gets the entry's value as a String[]. If the entry does not exist or is of different type, it + * will return the default value. + * + * @param defaultValue the value to be returned if no value is found + * @return the entry's value or the given default value + */ + String[] getStringArray(String[] defaultValue); + + /** + * Get an array of all value changes since the last call to readQueue. + * Also provides a timestamp for each value. + * + *

The "poll storage" subscribe option can be used to set the queue + * depth. + * + * @return Array of timestamped values; empty array if no new changes have + * been published since the previous call. + */ + NetworkTableValue[] readQueue(); +} diff --git a/ntcore/src/generated/main/java/edu/wpi/first/networktables/IntegerArrayEntry.java b/ntcore/src/generated/main/java/edu/wpi/first/networktables/IntegerArrayEntry.java new file mode 100644 index 0000000000..fd8f9c2cec --- /dev/null +++ b/ntcore/src/generated/main/java/edu/wpi/first/networktables/IntegerArrayEntry.java @@ -0,0 +1,17 @@ +// 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. + +// THIS FILE WAS AUTO-GENERATED BY ./ntcore/generate_topics.py. DO NOT MODIFY + +package edu.wpi.first.networktables; + +/** + * NetworkTables IntegerArray entry. + * + *

Unlike NetworkTableEntry, the entry goes away when close() is called. + */ +public interface IntegerArrayEntry extends IntegerArraySubscriber, IntegerArrayPublisher { + /** Stops publishing the entry if it's published. */ + void unpublish(); +} diff --git a/ntcore/src/generated/main/java/edu/wpi/first/networktables/IntegerArrayEntryImpl.java b/ntcore/src/generated/main/java/edu/wpi/first/networktables/IntegerArrayEntryImpl.java new file mode 100644 index 0000000000..e74f4893b9 --- /dev/null +++ b/ntcore/src/generated/main/java/edu/wpi/first/networktables/IntegerArrayEntryImpl.java @@ -0,0 +1,77 @@ +// 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. + +// THIS FILE WAS AUTO-GENERATED BY ./ntcore/generate_topics.py. DO NOT MODIFY + +package edu.wpi.first.networktables; + +/** NetworkTables IntegerArray implementation. */ +@SuppressWarnings("PMD.ArrayIsStoredDirectly") +final class IntegerArrayEntryImpl extends EntryBase implements IntegerArrayEntry { + /** + * Constructor. + * + * @param topic Topic + * @param handle Native handle + * @param defaultValue Default value for get() + */ + IntegerArrayEntryImpl(IntegerArrayTopic topic, int handle, long[] defaultValue) { + super(handle); + m_topic = topic; + m_defaultValue = defaultValue; + } + + @Override + public IntegerArrayTopic getTopic() { + return m_topic; + } + + @Override + public long[] get() { + return NetworkTablesJNI.getIntegerArray(m_handle, m_defaultValue); + } + + @Override + public long[] get(long[] defaultValue) { + return NetworkTablesJNI.getIntegerArray(m_handle, defaultValue); + } + + @Override + public TimestampedIntegerArray getAtomic() { + return NetworkTablesJNI.getAtomicIntegerArray(m_handle, m_defaultValue); + } + + @Override + public TimestampedIntegerArray getAtomic(long[] defaultValue) { + return NetworkTablesJNI.getAtomicIntegerArray(m_handle, defaultValue); + } + + @Override + public TimestampedIntegerArray[] readQueue() { + return NetworkTablesJNI.readQueueIntegerArray(m_handle); + } + + @Override + public long[][] readQueueValues() { + return NetworkTablesJNI.readQueueValuesIntegerArray(m_handle); + } + + @Override + public void set(long[] value, long time) { + NetworkTablesJNI.setIntegerArray(m_handle, time, value); + } + + @Override + public void setDefault(long[] value) { + NetworkTablesJNI.setDefaultIntegerArray(m_handle, 0, value); + } + + @Override + public void unpublish() { + NetworkTablesJNI.unpublish(m_handle); + } + + private final IntegerArrayTopic m_topic; + private final long[] m_defaultValue; +} diff --git a/ntcore/src/generated/main/java/edu/wpi/first/networktables/IntegerArrayPublisher.java b/ntcore/src/generated/main/java/edu/wpi/first/networktables/IntegerArrayPublisher.java new file mode 100644 index 0000000000..b864ba1e6b --- /dev/null +++ b/ntcore/src/generated/main/java/edu/wpi/first/networktables/IntegerArrayPublisher.java @@ -0,0 +1,52 @@ +// 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. + +// THIS FILE WAS AUTO-GENERATED BY ./ntcore/generate_topics.py. DO NOT MODIFY + +package edu.wpi.first.networktables; + +import java.util.function.Consumer; + +/** NetworkTables IntegerArray publisher. */ +public interface IntegerArrayPublisher extends Publisher, Consumer { + /** + * Get the corresponding topic. + * + * @return Topic + */ + @Override + IntegerArrayTopic getTopic(); + + /** + * Publish a new value using current NT time. + * + * @param value value to publish + */ + default void set(long[] value) { + set(value, 0); + } + + + /** + * Publish a new value. + * + * @param value value to publish + * @param time timestamp; 0 indicates current NT time should be used + */ + void set(long[] value, long time); + + /** + * Publish a default value. + * On reconnect, a default value will never be used in preference to a + * published value. + * + * @param value value + */ + void setDefault(long[] value); + + @Override + default void accept(long[] value) { + set(value); + } +} diff --git a/ntcore/src/generated/main/java/edu/wpi/first/networktables/IntegerArraySubscriber.java b/ntcore/src/generated/main/java/edu/wpi/first/networktables/IntegerArraySubscriber.java new file mode 100644 index 0000000000..cbb2e6fe81 --- /dev/null +++ b/ntcore/src/generated/main/java/edu/wpi/first/networktables/IntegerArraySubscriber.java @@ -0,0 +1,80 @@ +// 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. + +// THIS FILE WAS AUTO-GENERATED BY ./ntcore/generate_topics.py. DO NOT MODIFY + +package edu.wpi.first.networktables; + +import java.util.function.Supplier; + +/** NetworkTables IntegerArray subscriber. */ +@SuppressWarnings("PMD.MissingOverride") +public interface IntegerArraySubscriber extends Subscriber, Supplier { + /** + * Get the corresponding topic. + * + * @return Topic + */ + @Override + IntegerArrayTopic getTopic(); + + /** + * Get the last published value. + * If no value has been published, returns the stored default value. + * + * @return value + */ + long[] get(); + + /** + * Get the last published value. + * If no value has been published, returns the passed defaultValue. + * + * @param defaultValue default value to return if no value has been published + * @return value + */ + long[] get(long[] defaultValue); + + /** + * Get the last published value along with its timestamp + * If no value has been published, returns the stored default value and a + * timestamp of 0. + * + * @return timestamped value + */ + TimestampedIntegerArray getAtomic(); + + /** + * Get the last published value along with its timestamp + * If no value has been published, returns the passed defaultValue and a + * timestamp of 0. + * + * @param defaultValue default value to return if no value has been published + * @return timestamped value + */ + TimestampedIntegerArray getAtomic(long[] defaultValue); + + /** + * Get an array of all value changes since the last call to readQueue. + * Also provides a timestamp for each value. + * + *

The "poll storage" subscribe option can be used to set the queue + * depth. + * + * @return Array of timestamped values; empty array if no new changes have + * been published since the previous call. + */ + TimestampedIntegerArray[] readQueue(); + + /** + * Get an array of all value changes since the last call to readQueue. + * + *

The "poll storage" subscribe option can be used to set the queue + * depth. + * + * @return Array of values; empty array if no new changes have been + * published since the previous call. + */ + long[][] readQueueValues(); +} diff --git a/ntcore/src/generated/main/java/edu/wpi/first/networktables/IntegerArrayTopic.java b/ntcore/src/generated/main/java/edu/wpi/first/networktables/IntegerArrayTopic.java new file mode 100644 index 0000000000..d020e8a62c --- /dev/null +++ b/ntcore/src/generated/main/java/edu/wpi/first/networktables/IntegerArrayTopic.java @@ -0,0 +1,206 @@ +// 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. + +// THIS FILE WAS AUTO-GENERATED BY ./ntcore/generate_topics.py. DO NOT MODIFY + +package edu.wpi.first.networktables; + +/** NetworkTables IntegerArray topic. */ +public final class IntegerArrayTopic extends Topic { + /** The default type string for this topic type. */ + public static final String kTypeString = "int[]"; + + /** + * Construct from a generic topic. + * + * @param topic Topic + */ + public IntegerArrayTopic(Topic topic) { + super(topic.m_inst, topic.m_handle); + } + + /** + * Constructor; use NetworkTableInstance.getIntegerArrayTopic() instead. + * + * @param inst Instance + * @param handle Native handle + */ + public IntegerArrayTopic(NetworkTableInstance inst, int handle) { + super(inst, handle); + } + + /** + * Create a new subscriber to the topic. + * + *

The subscriber is only active as long as the returned object + * is not closed. + * + *

Subscribers that do not match the published data type do not return + * any values. To determine if the data type matches, use the appropriate + * Topic functions. + * + * @param defaultValue default value used when a default is not provided to a + * getter function + * @param options subscribe options + * @return subscriber + */ + public IntegerArraySubscriber subscribe( + long[] defaultValue, + PubSubOption... options) { + return new IntegerArrayEntryImpl( + this, + NetworkTablesJNI.subscribe( + m_handle, NetworkTableType.kIntegerArray.getValue(), + "int[]", options), + defaultValue); + } + + /** + * Create a new subscriber to the topic, with specified type string. + * + *

The subscriber is only active as long as the returned object + * is not closed. + * + *

Subscribers that do not match the published data type do not return + * any values. To determine if the data type matches, use the appropriate + * Topic functions. + * + * @param typeString type string + * @param defaultValue default value used when a default is not provided to a + * getter function + * @param options subscribe options + * @return subscriber + */ + public IntegerArraySubscriber subscribeEx( + String typeString, + long[] defaultValue, + PubSubOption... options) { + return new IntegerArrayEntryImpl( + this, + NetworkTablesJNI.subscribe( + m_handle, NetworkTableType.kIntegerArray.getValue(), + typeString, options), + defaultValue); + } + + /** + * Create a new publisher to the topic. + * + *

The publisher is only active as long as the returned object + * is not closed. + * + *

It is not possible to publish two different data types to the same + * topic. Conflicts between publishers are typically resolved by the server on + * a first-come, first-served basis. Any published values that do not match + * the topic's data type are dropped (ignored). To determine if the data type + * matches, use the appropriate Topic functions. + * + * @param options publish options + * @return publisher + */ + public IntegerArrayPublisher publish( + PubSubOption... options) { + return new IntegerArrayEntryImpl( + this, + NetworkTablesJNI.publish( + m_handle, NetworkTableType.kIntegerArray.getValue(), + "int[]", options), + new long[] {}); + } + + /** + * Create a new publisher to the topic, with type string and initial properties. + * + *

The publisher is only active as long as the returned object + * is not closed. + * + *

It is not possible to publish two different data types to the same + * topic. Conflicts between publishers are typically resolved by the server on + * a first-come, first-served basis. Any published values that do not match + * the topic's data type are dropped (ignored). To determine if the data type + * matches, use the appropriate Topic functions. + * + * @param typeString type string + * @param properties JSON properties + * @param options publish options + * @return publisher + * @throws IllegalArgumentException if properties is not a JSON object + */ + public IntegerArrayPublisher publishEx( + String typeString, + String properties, + PubSubOption... options) { + return new IntegerArrayEntryImpl( + this, + NetworkTablesJNI.publishEx( + m_handle, NetworkTableType.kIntegerArray.getValue(), + typeString, properties, options), + new long[] {}); + } + + /** + * Create a new entry for the topic. + * + *

Entries act as a combination of a subscriber and a weak publisher. The + * subscriber is active as long as the entry is not closed. The publisher is + * created when the entry is first written to, and remains active until either + * unpublish() is called or the entry is closed. + * + *

It is not possible to use two different data types with the same + * topic. Conflicts between publishers are typically resolved by the server on + * a first-come, first-served basis. Any published values that do not match + * the topic's data type are dropped (ignored), and the entry will show no new + * values if the data type does not match. To determine if the data type + * matches, use the appropriate Topic functions. + * + * @param defaultValue default value used when a default is not provided to a + * getter function + * @param options publish and/or subscribe options + * @return entry + */ + public IntegerArrayEntry getEntry( + long[] defaultValue, + PubSubOption... options) { + return new IntegerArrayEntryImpl( + this, + NetworkTablesJNI.getEntry( + m_handle, NetworkTableType.kIntegerArray.getValue(), + "int[]", options), + defaultValue); + } + + /** + * Create a new entry for the topic, with specified type string. + * + *

Entries act as a combination of a subscriber and a weak publisher. The + * subscriber is active as long as the entry is not closed. The publisher is + * created when the entry is first written to, and remains active until either + * unpublish() is called or the entry is closed. + * + *

It is not possible to use two different data types with the same + * topic. Conflicts between publishers are typically resolved by the server on + * a first-come, first-served basis. Any published values that do not match + * the topic's data type are dropped (ignored), and the entry will show no new + * values if the data type does not match. To determine if the data type + * matches, use the appropriate Topic functions. + * + * @param typeString type string + * @param defaultValue default value used when a default is not provided to a + * getter function + * @param options publish and/or subscribe options + * @return entry + */ + public IntegerArrayEntry getEntryEx( + String typeString, + long[] defaultValue, + PubSubOption... options) { + return new IntegerArrayEntryImpl( + this, + NetworkTablesJNI.getEntry( + m_handle, NetworkTableType.kIntegerArray.getValue(), + typeString, options), + defaultValue); + } + +} diff --git a/ntcore/src/generated/main/java/edu/wpi/first/networktables/IntegerEntry.java b/ntcore/src/generated/main/java/edu/wpi/first/networktables/IntegerEntry.java new file mode 100644 index 0000000000..ccd614e312 --- /dev/null +++ b/ntcore/src/generated/main/java/edu/wpi/first/networktables/IntegerEntry.java @@ -0,0 +1,17 @@ +// 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. + +// THIS FILE WAS AUTO-GENERATED BY ./ntcore/generate_topics.py. DO NOT MODIFY + +package edu.wpi.first.networktables; + +/** + * NetworkTables Integer entry. + * + *

Unlike NetworkTableEntry, the entry goes away when close() is called. + */ +public interface IntegerEntry extends IntegerSubscriber, IntegerPublisher { + /** Stops publishing the entry if it's published. */ + void unpublish(); +} diff --git a/ntcore/src/generated/main/java/edu/wpi/first/networktables/IntegerEntryImpl.java b/ntcore/src/generated/main/java/edu/wpi/first/networktables/IntegerEntryImpl.java new file mode 100644 index 0000000000..a8db1bff9d --- /dev/null +++ b/ntcore/src/generated/main/java/edu/wpi/first/networktables/IntegerEntryImpl.java @@ -0,0 +1,77 @@ +// 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. + +// THIS FILE WAS AUTO-GENERATED BY ./ntcore/generate_topics.py. DO NOT MODIFY + +package edu.wpi.first.networktables; + +/** NetworkTables Integer implementation. */ +@SuppressWarnings("PMD.ArrayIsStoredDirectly") +final class IntegerEntryImpl extends EntryBase implements IntegerEntry { + /** + * Constructor. + * + * @param topic Topic + * @param handle Native handle + * @param defaultValue Default value for get() + */ + IntegerEntryImpl(IntegerTopic topic, int handle, long defaultValue) { + super(handle); + m_topic = topic; + m_defaultValue = defaultValue; + } + + @Override + public IntegerTopic getTopic() { + return m_topic; + } + + @Override + public long get() { + return NetworkTablesJNI.getInteger(m_handle, m_defaultValue); + } + + @Override + public long get(long defaultValue) { + return NetworkTablesJNI.getInteger(m_handle, defaultValue); + } + + @Override + public TimestampedInteger getAtomic() { + return NetworkTablesJNI.getAtomicInteger(m_handle, m_defaultValue); + } + + @Override + public TimestampedInteger getAtomic(long defaultValue) { + return NetworkTablesJNI.getAtomicInteger(m_handle, defaultValue); + } + + @Override + public TimestampedInteger[] readQueue() { + return NetworkTablesJNI.readQueueInteger(m_handle); + } + + @Override + public long[] readQueueValues() { + return NetworkTablesJNI.readQueueValuesInteger(m_handle); + } + + @Override + public void set(long value, long time) { + NetworkTablesJNI.setInteger(m_handle, time, value); + } + + @Override + public void setDefault(long value) { + NetworkTablesJNI.setDefaultInteger(m_handle, 0, value); + } + + @Override + public void unpublish() { + NetworkTablesJNI.unpublish(m_handle); + } + + private final IntegerTopic m_topic; + private final long m_defaultValue; +} diff --git a/ntcore/src/generated/main/java/edu/wpi/first/networktables/IntegerPublisher.java b/ntcore/src/generated/main/java/edu/wpi/first/networktables/IntegerPublisher.java new file mode 100644 index 0000000000..be734eddd1 --- /dev/null +++ b/ntcore/src/generated/main/java/edu/wpi/first/networktables/IntegerPublisher.java @@ -0,0 +1,52 @@ +// 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. + +// THIS FILE WAS AUTO-GENERATED BY ./ntcore/generate_topics.py. DO NOT MODIFY + +package edu.wpi.first.networktables; + +import java.util.function.LongConsumer; + +/** NetworkTables Integer publisher. */ +public interface IntegerPublisher extends Publisher, LongConsumer { + /** + * Get the corresponding topic. + * + * @return Topic + */ + @Override + IntegerTopic getTopic(); + + /** + * Publish a new value using current NT time. + * + * @param value value to publish + */ + default void set(long value) { + set(value, 0); + } + + + /** + * Publish a new value. + * + * @param value value to publish + * @param time timestamp; 0 indicates current NT time should be used + */ + void set(long value, long time); + + /** + * Publish a default value. + * On reconnect, a default value will never be used in preference to a + * published value. + * + * @param value value + */ + void setDefault(long value); + + @Override + default void accept(long value) { + set(value); + } +} diff --git a/ntcore/src/generated/main/java/edu/wpi/first/networktables/IntegerSubscriber.java b/ntcore/src/generated/main/java/edu/wpi/first/networktables/IntegerSubscriber.java new file mode 100644 index 0000000000..81a9740ef7 --- /dev/null +++ b/ntcore/src/generated/main/java/edu/wpi/first/networktables/IntegerSubscriber.java @@ -0,0 +1,85 @@ +// 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. + +// THIS FILE WAS AUTO-GENERATED BY ./ntcore/generate_topics.py. DO NOT MODIFY + +package edu.wpi.first.networktables; + +import java.util.function.LongSupplier; + +/** NetworkTables Integer subscriber. */ +@SuppressWarnings("PMD.MissingOverride") +public interface IntegerSubscriber extends Subscriber, LongSupplier { + /** + * Get the corresponding topic. + * + * @return Topic + */ + @Override + IntegerTopic getTopic(); + + /** + * Get the last published value. + * If no value has been published, returns the stored default value. + * + * @return value + */ + long get(); + + /** + * Get the last published value. + * If no value has been published, returns the passed defaultValue. + * + * @param defaultValue default value to return if no value has been published + * @return value + */ + long get(long defaultValue); + + @Override + default long getAsLong() { + return get(); + } + + /** + * Get the last published value along with its timestamp + * If no value has been published, returns the stored default value and a + * timestamp of 0. + * + * @return timestamped value + */ + TimestampedInteger getAtomic(); + + /** + * Get the last published value along with its timestamp + * If no value has been published, returns the passed defaultValue and a + * timestamp of 0. + * + * @param defaultValue default value to return if no value has been published + * @return timestamped value + */ + TimestampedInteger getAtomic(long defaultValue); + + /** + * Get an array of all value changes since the last call to readQueue. + * Also provides a timestamp for each value. + * + *

The "poll storage" subscribe option can be used to set the queue + * depth. + * + * @return Array of timestamped values; empty array if no new changes have + * been published since the previous call. + */ + TimestampedInteger[] readQueue(); + + /** + * Get an array of all value changes since the last call to readQueue. + * + *

The "poll storage" subscribe option can be used to set the queue + * depth. + * + * @return Array of values; empty array if no new changes have been + * published since the previous call. + */ + long[] readQueueValues(); +} diff --git a/ntcore/src/generated/main/java/edu/wpi/first/networktables/IntegerTopic.java b/ntcore/src/generated/main/java/edu/wpi/first/networktables/IntegerTopic.java new file mode 100644 index 0000000000..ebf87c4b0d --- /dev/null +++ b/ntcore/src/generated/main/java/edu/wpi/first/networktables/IntegerTopic.java @@ -0,0 +1,206 @@ +// 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. + +// THIS FILE WAS AUTO-GENERATED BY ./ntcore/generate_topics.py. DO NOT MODIFY + +package edu.wpi.first.networktables; + +/** NetworkTables Integer topic. */ +public final class IntegerTopic extends Topic { + /** The default type string for this topic type. */ + public static final String kTypeString = "int"; + + /** + * Construct from a generic topic. + * + * @param topic Topic + */ + public IntegerTopic(Topic topic) { + super(topic.m_inst, topic.m_handle); + } + + /** + * Constructor; use NetworkTableInstance.getIntegerTopic() instead. + * + * @param inst Instance + * @param handle Native handle + */ + public IntegerTopic(NetworkTableInstance inst, int handle) { + super(inst, handle); + } + + /** + * Create a new subscriber to the topic. + * + *

The subscriber is only active as long as the returned object + * is not closed. + * + *

Subscribers that do not match the published data type do not return + * any values. To determine if the data type matches, use the appropriate + * Topic functions. + * + * @param defaultValue default value used when a default is not provided to a + * getter function + * @param options subscribe options + * @return subscriber + */ + public IntegerSubscriber subscribe( + long defaultValue, + PubSubOption... options) { + return new IntegerEntryImpl( + this, + NetworkTablesJNI.subscribe( + m_handle, NetworkTableType.kInteger.getValue(), + "int", options), + defaultValue); + } + + /** + * Create a new subscriber to the topic, with specified type string. + * + *

The subscriber is only active as long as the returned object + * is not closed. + * + *

Subscribers that do not match the published data type do not return + * any values. To determine if the data type matches, use the appropriate + * Topic functions. + * + * @param typeString type string + * @param defaultValue default value used when a default is not provided to a + * getter function + * @param options subscribe options + * @return subscriber + */ + public IntegerSubscriber subscribeEx( + String typeString, + long defaultValue, + PubSubOption... options) { + return new IntegerEntryImpl( + this, + NetworkTablesJNI.subscribe( + m_handle, NetworkTableType.kInteger.getValue(), + typeString, options), + defaultValue); + } + + /** + * Create a new publisher to the topic. + * + *

The publisher is only active as long as the returned object + * is not closed. + * + *

It is not possible to publish two different data types to the same + * topic. Conflicts between publishers are typically resolved by the server on + * a first-come, first-served basis. Any published values that do not match + * the topic's data type are dropped (ignored). To determine if the data type + * matches, use the appropriate Topic functions. + * + * @param options publish options + * @return publisher + */ + public IntegerPublisher publish( + PubSubOption... options) { + return new IntegerEntryImpl( + this, + NetworkTablesJNI.publish( + m_handle, NetworkTableType.kInteger.getValue(), + "int", options), + 0); + } + + /** + * Create a new publisher to the topic, with type string and initial properties. + * + *

The publisher is only active as long as the returned object + * is not closed. + * + *

It is not possible to publish two different data types to the same + * topic. Conflicts between publishers are typically resolved by the server on + * a first-come, first-served basis. Any published values that do not match + * the topic's data type are dropped (ignored). To determine if the data type + * matches, use the appropriate Topic functions. + * + * @param typeString type string + * @param properties JSON properties + * @param options publish options + * @return publisher + * @throws IllegalArgumentException if properties is not a JSON object + */ + public IntegerPublisher publishEx( + String typeString, + String properties, + PubSubOption... options) { + return new IntegerEntryImpl( + this, + NetworkTablesJNI.publishEx( + m_handle, NetworkTableType.kInteger.getValue(), + typeString, properties, options), + 0); + } + + /** + * Create a new entry for the topic. + * + *

Entries act as a combination of a subscriber and a weak publisher. The + * subscriber is active as long as the entry is not closed. The publisher is + * created when the entry is first written to, and remains active until either + * unpublish() is called or the entry is closed. + * + *

It is not possible to use two different data types with the same + * topic. Conflicts between publishers are typically resolved by the server on + * a first-come, first-served basis. Any published values that do not match + * the topic's data type are dropped (ignored), and the entry will show no new + * values if the data type does not match. To determine if the data type + * matches, use the appropriate Topic functions. + * + * @param defaultValue default value used when a default is not provided to a + * getter function + * @param options publish and/or subscribe options + * @return entry + */ + public IntegerEntry getEntry( + long defaultValue, + PubSubOption... options) { + return new IntegerEntryImpl( + this, + NetworkTablesJNI.getEntry( + m_handle, NetworkTableType.kInteger.getValue(), + "int", options), + defaultValue); + } + + /** + * Create a new entry for the topic, with specified type string. + * + *

Entries act as a combination of a subscriber and a weak publisher. The + * subscriber is active as long as the entry is not closed. The publisher is + * created when the entry is first written to, and remains active until either + * unpublish() is called or the entry is closed. + * + *

It is not possible to use two different data types with the same + * topic. Conflicts between publishers are typically resolved by the server on + * a first-come, first-served basis. Any published values that do not match + * the topic's data type are dropped (ignored), and the entry will show no new + * values if the data type does not match. To determine if the data type + * matches, use the appropriate Topic functions. + * + * @param typeString type string + * @param defaultValue default value used when a default is not provided to a + * getter function + * @param options publish and/or subscribe options + * @return entry + */ + public IntegerEntry getEntryEx( + String typeString, + long defaultValue, + PubSubOption... options) { + return new IntegerEntryImpl( + this, + NetworkTablesJNI.getEntry( + m_handle, NetworkTableType.kInteger.getValue(), + typeString, options), + defaultValue); + } + +} diff --git a/ntcore/src/generated/main/java/edu/wpi/first/networktables/NetworkTableEntry.java b/ntcore/src/generated/main/java/edu/wpi/first/networktables/NetworkTableEntry.java new file mode 100644 index 0000000000..69d107753a --- /dev/null +++ b/ntcore/src/generated/main/java/edu/wpi/first/networktables/NetworkTableEntry.java @@ -0,0 +1,1013 @@ +// 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. + +// THIS FILE WAS AUTO-GENERATED BY ./ntcore/generate_topics.py. DO NOT MODIFY + +package edu.wpi.first.networktables; + +import java.nio.ByteBuffer; + +/** + * NetworkTables Entry. + * + *

For backwards compatibility, the NetworkTableEntry close() does not release the entry. + */ +@SuppressWarnings("UnnecessaryParentheses") +public final class NetworkTableEntry implements Publisher, Subscriber { + /** + * Flag values (as returned by {@link #getFlags()}). + * + * @deprecated Use isPersistent() instead. + */ + @Deprecated(since = "2022", forRemoval = true) + public static final int kPersistent = 0x01; + + /** + * Construct from native handle. + * + * @param inst Instance + * @param handle Native handle + */ + public NetworkTableEntry(NetworkTableInstance inst, int handle) { + this(new Topic(inst, NetworkTablesJNI.getTopicFromHandle(handle)), handle); + } + + /** + * Construct from native handle. + * + * @param topic Topic + * @param handle Native handle + */ + public NetworkTableEntry(Topic topic, int handle) { + m_topic = topic; + m_handle = handle; + } + + @Override + public void close() {} + + /** + * Determines if the native handle is valid. + * + * @return True if the native handle is valid, false otherwise. + */ + @Override + public boolean isValid() { + return m_handle != 0; + } + + /** + * Gets the native handle for the entry. + * + * @return Native handle + */ + @Override + public int getHandle() { + return m_handle; + } + + /** + * Gets the subscribed-to / published-to topic. + * + * @return Topic + */ + @Override + public Topic getTopic() { + return m_topic; + } + + /** + * Gets the instance for the entry. + * + * @return Instance + */ + public NetworkTableInstance getInstance() { + return m_topic.getInstance(); + } + + /** + * Determines if the entry currently exists. + * + * @return True if the entry exists, false otherwise. + */ + @Override + public boolean exists() { + return NetworkTablesJNI.getType(m_handle) != 0; + } + + /** + * Gets the name of the entry (the key). + * + * @return the entry's name + */ + public String getName() { + return NetworkTablesJNI.getEntryName(m_handle); + } + + /** + * Gets the type of the entry. + * + * @return the entry's type + */ + public NetworkTableType getType() { + return NetworkTableType.getFromInt(NetworkTablesJNI.getType(m_handle)); + } + + /** + * Returns the flags. + * + * @return the flags (bitmask) + * @deprecated Use isPersistent() or topic properties instead + */ + @Deprecated(since = "2022", forRemoval = true) + public int getFlags() { + return NetworkTablesJNI.getEntryFlags(m_handle); + } + + /** + * Gets the last time the entry's value was changed. + * + * @return Entry last change time + */ + @Override + public long getLastChange() { + return NetworkTablesJNI.getEntryLastChange(m_handle); + } + + /** + * Gets the entry's value. Returns a value with type NetworkTableType.kUnassigned if the value + * does not exist. + * + * @return the entry's value + */ + public NetworkTableValue getValue() { + return NetworkTablesJNI.getValue(m_handle); + } + + /** + * Gets the entry's value as a boolean. If the entry does not exist or is of different type, it + * will return the default value. + * + * @param defaultValue the value to be returned if no value is found + * @return the entry's value or the given default value + */ + public boolean getBoolean(boolean defaultValue) { + return NetworkTablesJNI.getBoolean(m_handle, defaultValue); + } + + /** + * Gets the entry's value as a long. If the entry does not exist or is of different type, it + * will return the default value. + * + * @param defaultValue the value to be returned if no value is found + * @return the entry's value or the given default value + */ + public long getInteger(long defaultValue) { + return NetworkTablesJNI.getInteger(m_handle, defaultValue); + } + + /** + * Gets the entry's value as a float. If the entry does not exist or is of different type, it + * will return the default value. + * + * @param defaultValue the value to be returned if no value is found + * @return the entry's value or the given default value + */ + public float getFloat(float defaultValue) { + return NetworkTablesJNI.getFloat(m_handle, defaultValue); + } + + /** + * Gets the entry's value as a double. If the entry does not exist or is of different type, it + * will return the default value. + * + * @param defaultValue the value to be returned if no value is found + * @return the entry's value or the given default value + */ + public double getDouble(double defaultValue) { + return NetworkTablesJNI.getDouble(m_handle, defaultValue); + } + + /** + * Gets the entry's value as a String. If the entry does not exist or is of different type, it + * will return the default value. + * + * @param defaultValue the value to be returned if no value is found + * @return the entry's value or the given default value + */ + public String getString(String defaultValue) { + return NetworkTablesJNI.getString(m_handle, defaultValue); + } + + /** + * Gets the entry's value as a byte[]. If the entry does not exist or is of different type, it + * will return the default value. + * + * @param defaultValue the value to be returned if no value is found + * @return the entry's value or the given default value + */ + public byte[] getRaw(byte[] defaultValue) { + return NetworkTablesJNI.getRaw(m_handle, defaultValue); + } + + /** + * Gets the entry's value as a boolean[]. If the entry does not exist or is of different type, it + * will return the default value. + * + * @param defaultValue the value to be returned if no value is found + * @return the entry's value or the given default value + */ + public boolean[] getBooleanArray(boolean[] defaultValue) { + return NetworkTablesJNI.getBooleanArray(m_handle, defaultValue); + } + + /** + * Gets the entry's value as a boolean array. If the entry does not exist or is of different type, + * it will return the default value. + * + * @param defaultValue the value to be returned if no value is found + * @return the entry's value or the given default value + */ + public Boolean[] getBooleanArray(Boolean[] defaultValue) { + return NetworkTableValue.fromNativeBooleanArray( + getBooleanArray(NetworkTableValue.toNativeBooleanArray(defaultValue))); + } + + /** + * Gets the entry's value as a long[]. If the entry does not exist or is of different type, it + * will return the default value. + * + * @param defaultValue the value to be returned if no value is found + * @return the entry's value or the given default value + */ + public long[] getIntegerArray(long[] defaultValue) { + return NetworkTablesJNI.getIntegerArray(m_handle, defaultValue); + } + + /** + * Gets the entry's value as a boolean array. If the entry does not exist or is of different type, + * it will return the default value. + * + * @param defaultValue the value to be returned if no value is found + * @return the entry's value or the given default value + */ + public Long[] getIntegerArray(Long[] defaultValue) { + return NetworkTableValue.fromNativeIntegerArray( + getIntegerArray(NetworkTableValue.toNativeIntegerArray(defaultValue))); + } + + /** + * Gets the entry's value as a float[]. If the entry does not exist or is of different type, it + * will return the default value. + * + * @param defaultValue the value to be returned if no value is found + * @return the entry's value or the given default value + */ + public float[] getFloatArray(float[] defaultValue) { + return NetworkTablesJNI.getFloatArray(m_handle, defaultValue); + } + + /** + * Gets the entry's value as a boolean array. If the entry does not exist or is of different type, + * it will return the default value. + * + * @param defaultValue the value to be returned if no value is found + * @return the entry's value or the given default value + */ + public Float[] getFloatArray(Float[] defaultValue) { + return NetworkTableValue.fromNativeFloatArray( + getFloatArray(NetworkTableValue.toNativeFloatArray(defaultValue))); + } + + /** + * Gets the entry's value as a double[]. If the entry does not exist or is of different type, it + * will return the default value. + * + * @param defaultValue the value to be returned if no value is found + * @return the entry's value or the given default value + */ + public double[] getDoubleArray(double[] defaultValue) { + return NetworkTablesJNI.getDoubleArray(m_handle, defaultValue); + } + + /** + * Gets the entry's value as a boolean array. If the entry does not exist or is of different type, + * it will return the default value. + * + * @param defaultValue the value to be returned if no value is found + * @return the entry's value or the given default value + */ + public Double[] getDoubleArray(Double[] defaultValue) { + return NetworkTableValue.fromNativeDoubleArray( + getDoubleArray(NetworkTableValue.toNativeDoubleArray(defaultValue))); + } + + /** + * Gets the entry's value as a String[]. If the entry does not exist or is of different type, it + * will return the default value. + * + * @param defaultValue the value to be returned if no value is found + * @return the entry's value or the given default value + */ + public String[] getStringArray(String[] defaultValue) { + return NetworkTablesJNI.getStringArray(m_handle, defaultValue); + } + + /** + * Gets the entry's value as a double. If the entry does not exist or is of different type, it + * will return the default value. + * + * @param defaultValue the value to be returned if no value is found + * @return the entry's value or the given default value + */ + public Number getNumber(Number defaultValue) { + return getDouble(defaultValue.doubleValue()); + } + + /** + * Gets the entry's value as a double array. If the entry does not exist or is of different type, + * it will return the default value. + * + * @param defaultValue the value to be returned if no value is found + * @return the entry's value or the given default value + */ + public Number[] getNumberArray(Number[] defaultValue) { + return NetworkTableValue.fromNativeDoubleArray( + getDoubleArray(NetworkTableValue.toNativeDoubleArray(defaultValue))); + } + + /** + * Get an array of all value changes since the last call to readQueue. + * + *

The "poll storage" subscribe option can be used to set the queue + * depth. + * + * @return Array of values; empty array if no new changes have been + * published since the previous call. + */ + public NetworkTableValue[] readQueue() { + return NetworkTablesJNI.readQueueValue(m_handle); + } + + /** + * Checks if a data value is of a type that can be placed in a NetworkTable entry. + * + * @param data the data to check + * @return true if the data can be placed in an entry, false if it cannot + */ + public static boolean isValidDataType(Object data) { + return data instanceof Number + || data instanceof Boolean + || data instanceof String + || data instanceof long[] + || data instanceof Long[] + || data instanceof float[] + || data instanceof Float[] + || data instanceof double[] + || data instanceof Double[] + || data instanceof Number[] + || data instanceof boolean[] + || data instanceof Boolean[] + || data instanceof String[] + || data instanceof byte[] + || data instanceof Byte[]; + } + + /** + * Sets the entry's value if it does not exist. + * + * @param defaultValue the default value to set + * @return False if the entry exists with a different type + * @throws IllegalArgumentException if the value is not a known type + */ + public boolean setDefaultValue(Object defaultValue) { + if (defaultValue instanceof NetworkTableValue) { + long time = ((NetworkTableValue) defaultValue).getTime(); + Object otherValue = ((NetworkTableValue) defaultValue).getValue(); + switch (((NetworkTableValue) defaultValue).getType()) { + case kBoolean: + return NetworkTablesJNI.setDefaultBoolean(m_handle, time, (Boolean) otherValue); + case kInteger: + return NetworkTablesJNI.setDefaultInteger( + m_handle, time, ((Number) otherValue).longValue()); + case kFloat: + return NetworkTablesJNI.setDefaultFloat( + m_handle, time, ((Number) otherValue).floatValue()); + case kDouble: + return NetworkTablesJNI.setDefaultDouble( + m_handle, time, ((Number) otherValue).doubleValue()); + case kString: + return NetworkTablesJNI.setDefaultString(m_handle, time, (String) otherValue); + case kRaw: + return NetworkTablesJNI.setDefaultRaw(m_handle, time, (byte[]) otherValue); + case kBooleanArray: + return NetworkTablesJNI.setDefaultBooleanArray(m_handle, time, (boolean[]) otherValue); + case kIntegerArray: + return NetworkTablesJNI.setDefaultIntegerArray(m_handle, time, (long[]) otherValue); + case kFloatArray: + return NetworkTablesJNI.setDefaultFloatArray(m_handle, time, (float[]) otherValue); + case kDoubleArray: + return NetworkTablesJNI.setDefaultDoubleArray(m_handle, time, (double[]) otherValue); + case kStringArray: + return NetworkTablesJNI.setDefaultStringArray(m_handle, time, (String[]) otherValue); + default: + return true; + } + } else if (defaultValue instanceof Boolean) { + return setDefaultBoolean((Boolean) defaultValue); + } else if (defaultValue instanceof Integer) { + return setDefaultInteger((Integer) defaultValue); + } else if (defaultValue instanceof Float) { + return setDefaultFloat((Float) defaultValue); + } else if (defaultValue instanceof Number) { + return setDefaultNumber((Number) defaultValue); + } else if (defaultValue instanceof String) { + return setDefaultString((String) defaultValue); + } else if (defaultValue instanceof byte[]) { + return setDefaultRaw((byte[]) defaultValue); + } else if (defaultValue instanceof boolean[]) { + return setDefaultBooleanArray((boolean[]) defaultValue); + } else if (defaultValue instanceof long[]) { + return setDefaultIntegerArray((long[]) defaultValue); + } else if (defaultValue instanceof float[]) { + return setDefaultFloatArray((float[]) defaultValue); + } else if (defaultValue instanceof double[]) { + return setDefaultDoubleArray((double[]) defaultValue); + } else if (defaultValue instanceof Boolean[]) { + return setDefaultBooleanArray((Boolean[]) defaultValue); + } else if (defaultValue instanceof Long[]) { + return setDefaultIntegerArray((Long[]) defaultValue); + } else if (defaultValue instanceof Float[]) { + return setDefaultFloatArray((Float[]) defaultValue); + } else if (defaultValue instanceof Number[]) { + return setDefaultNumberArray((Number[]) defaultValue); + } else if (defaultValue instanceof String[]) { + return setDefaultStringArray((String[]) defaultValue); + } else { + throw new IllegalArgumentException( + "Value of type " + defaultValue.getClass().getName() + " cannot be put into a table"); + } + } + + /** + * Sets the entry's value if it does not exist. + * + * @param defaultValue the default value to set + * @return False if the entry exists with a different type + */ + public boolean setDefaultBoolean(boolean defaultValue) { + return NetworkTablesJNI.setDefaultBoolean(m_handle, 0, defaultValue); + } + + /** + * Sets the entry's value if it does not exist. + * + * @param defaultValue the default value to set + * @return False if the entry exists with a different type + */ + public boolean setDefaultInteger(long defaultValue) { + return NetworkTablesJNI.setDefaultInteger(m_handle, 0, defaultValue); + } + + /** + * Sets the entry's value if it does not exist. + * + * @param defaultValue the default value to set + * @return False if the entry exists with a different type + */ + public boolean setDefaultFloat(float defaultValue) { + return NetworkTablesJNI.setDefaultFloat(m_handle, 0, defaultValue); + } + + /** + * Sets the entry's value if it does not exist. + * + * @param defaultValue the default value to set + * @return False if the entry exists with a different type + */ + public boolean setDefaultDouble(double defaultValue) { + return NetworkTablesJNI.setDefaultDouble(m_handle, 0, defaultValue); + } + + /** + * Sets the entry's value if it does not exist. + * + * @param defaultValue the default value to set + * @return False if the entry exists with a different type + */ + public boolean setDefaultString(String defaultValue) { + return NetworkTablesJNI.setDefaultString(m_handle, 0, defaultValue); + } + + /** + * Sets the entry's value if it does not exist. + * + * @param defaultValue the default value to set + * @return False if the entry exists with a different type + */ + public boolean setDefaultRaw(byte[] defaultValue) { + return NetworkTablesJNI.setDefaultRaw(m_handle, 0, defaultValue); + } + + /** + * Sets the entry's value if it does not exist. + * + * @param defaultValue the default value to set; will send from defaultValue.position() to + * defaultValue.capacity() + * @return False if the entry exists with a different type + */ + public boolean setDefaultRaw(ByteBuffer defaultValue) { + return NetworkTablesJNI.setDefaultRaw(m_handle, 0, defaultValue); + } + + /** + * Sets the entry's value if it does not exist. + * + * @param defaultValue the default value to set + * @param start Start position of data (in buffer) + * @param len Length of data (must be less than or equal to value.length - start) + * @return False if the entry exists with a different type + */ + public boolean setDefaultRaw(byte[] defaultValue, int start, int len) { + return NetworkTablesJNI.setDefaultRaw(m_handle, 0, defaultValue, start, len); + } + + /** + * Sets the entry's value if it does not exist. + * + * @param defaultValue the default value to set + * @param start Start position of data (in buffer) + * @param len Length of data (must be less than or equal to value.capacity() - start) + * @return False if the entry exists with a different type + */ + public boolean setDefaultRaw(ByteBuffer defaultValue, int start, int len) { + return NetworkTablesJNI.setDefaultRaw(m_handle, 0, defaultValue, start, len); + } + + /** + * Sets the entry's value if it does not exist. + * + * @param defaultValue the default value to set + * @return False if the entry exists with a different type + */ + public boolean setDefaultBooleanArray(boolean[] defaultValue) { + return NetworkTablesJNI.setDefaultBooleanArray(m_handle, 0, defaultValue); + } + + /** + * Sets the entry's value if it does not exist. + * + * @param defaultValue the default value to set + * @return False if the entry exists with a different type + */ + public boolean setDefaultBooleanArray(Boolean[] defaultValue) { + return setDefaultBooleanArray(NetworkTableValue.toNativeBooleanArray(defaultValue)); + } + + /** + * Sets the entry's value if it does not exist. + * + * @param defaultValue the default value to set + * @return False if the entry exists with a different type + */ + public boolean setDefaultIntegerArray(long[] defaultValue) { + return NetworkTablesJNI.setDefaultIntegerArray(m_handle, 0, defaultValue); + } + + /** + * Sets the entry's value if it does not exist. + * + * @param defaultValue the default value to set + * @return False if the entry exists with a different type + */ + public boolean setDefaultIntegerArray(Long[] defaultValue) { + return setDefaultIntegerArray(NetworkTableValue.toNativeIntegerArray(defaultValue)); + } + + /** + * Sets the entry's value if it does not exist. + * + * @param defaultValue the default value to set + * @return False if the entry exists with a different type + */ + public boolean setDefaultFloatArray(float[] defaultValue) { + return NetworkTablesJNI.setDefaultFloatArray(m_handle, 0, defaultValue); + } + + /** + * Sets the entry's value if it does not exist. + * + * @param defaultValue the default value to set + * @return False if the entry exists with a different type + */ + public boolean setDefaultFloatArray(Float[] defaultValue) { + return setDefaultFloatArray(NetworkTableValue.toNativeFloatArray(defaultValue)); + } + + /** + * Sets the entry's value if it does not exist. + * + * @param defaultValue the default value to set + * @return False if the entry exists with a different type + */ + public boolean setDefaultDoubleArray(double[] defaultValue) { + return NetworkTablesJNI.setDefaultDoubleArray(m_handle, 0, defaultValue); + } + + /** + * Sets the entry's value if it does not exist. + * + * @param defaultValue the default value to set + * @return False if the entry exists with a different type + */ + public boolean setDefaultDoubleArray(Double[] defaultValue) { + return setDefaultDoubleArray(NetworkTableValue.toNativeDoubleArray(defaultValue)); + } + + /** + * Sets the entry's value if it does not exist. + * + * @param defaultValue the default value to set + * @return False if the entry exists with a different type + */ + public boolean setDefaultStringArray(String[] defaultValue) { + return NetworkTablesJNI.setDefaultStringArray(m_handle, 0, defaultValue); + } + + /** + * Sets the entry's value if it does not exist. + * + * @param defaultValue the default value to set + * @return False if the entry exists with a different type + */ + public boolean setDefaultNumber(Number defaultValue) { + return setDefaultDouble(defaultValue.doubleValue()); + } + + /** + * Sets the entry's value if it does not exist. + * + * @param defaultValue the default value to set + * @return False if the entry exists with a different type + */ + public boolean setDefaultNumberArray(Number[] defaultValue) { + return setDefaultDoubleArray(NetworkTableValue.toNativeDoubleArray(defaultValue)); + } + + /** + * Sets the entry's value. + * + * @param value the value that will be assigned + * @return False if the table key already exists with a different type + * @throws IllegalArgumentException if the value is not a known type + */ + public boolean setValue(Object value) { + if (value instanceof NetworkTableValue) { + long time = ((NetworkTableValue) value).getTime(); + Object otherValue = ((NetworkTableValue) value).getValue(); + switch (((NetworkTableValue) value).getType()) { + case kBoolean: + return NetworkTablesJNI.setBoolean(m_handle, time, (Boolean) otherValue); + case kInteger: + return NetworkTablesJNI.setInteger( + m_handle, time, ((Number) otherValue).longValue()); + case kFloat: + return NetworkTablesJNI.setFloat( + m_handle, time, ((Number) otherValue).floatValue()); + case kDouble: + return NetworkTablesJNI.setDouble( + m_handle, time, ((Number) otherValue).doubleValue()); + case kString: + return NetworkTablesJNI.setString(m_handle, time, (String) otherValue); + case kRaw: + return NetworkTablesJNI.setRaw(m_handle, time, (byte[]) otherValue); + case kBooleanArray: + return NetworkTablesJNI.setBooleanArray(m_handle, time, (boolean[]) otherValue); + case kIntegerArray: + return NetworkTablesJNI.setIntegerArray(m_handle, time, (long[]) otherValue); + case kFloatArray: + return NetworkTablesJNI.setFloatArray(m_handle, time, (float[]) otherValue); + case kDoubleArray: + return NetworkTablesJNI.setDoubleArray(m_handle, time, (double[]) otherValue); + case kStringArray: + return NetworkTablesJNI.setStringArray(m_handle, time, (String[]) otherValue); + default: + return true; + } + } else if (value instanceof Boolean) { + return setBoolean((Boolean) value); + } else if (value instanceof Long) { + return setInteger((Long) value); + } else if (value instanceof Float) { + return setFloat((Float) value); + } else if (value instanceof Number) { + return setNumber((Number) value); + } else if (value instanceof String) { + return setString((String) value); + } else if (value instanceof byte[]) { + return setRaw((byte[]) value); + } else if (value instanceof boolean[]) { + return setBooleanArray((boolean[]) value); + } else if (value instanceof long[]) { + return setIntegerArray((long[]) value); + } else if (value instanceof float[]) { + return setFloatArray((float[]) value); + } else if (value instanceof double[]) { + return setDoubleArray((double[]) value); + } else if (value instanceof Boolean[]) { + return setBooleanArray((Boolean[]) value); + } else if (value instanceof Long[]) { + return setIntegerArray((Long[]) value); + } else if (value instanceof Float[]) { + return setFloatArray((Float[]) value); + } else if (value instanceof Number[]) { + return setNumberArray((Number[]) value); + } else if (value instanceof String[]) { + return setStringArray((String[]) value); + } else { + throw new IllegalArgumentException( + "Value of type " + value.getClass().getName() + " cannot be put into a table"); + } + } + + /** + * Sets the entry's value. + * + * @param value the value to set + * @return False if the entry exists with a different type + */ + public boolean setBoolean(boolean value) { + return NetworkTablesJNI.setBoolean(m_handle, 0, value); + } + + /** + * Sets the entry's value. + * + * @param value the value to set + * @return False if the entry exists with a different type + */ + public boolean setInteger(long value) { + return NetworkTablesJNI.setInteger(m_handle, 0, value); + } + + /** + * Sets the entry's value. + * + * @param value the value to set + * @return False if the entry exists with a different type + */ + public boolean setFloat(float value) { + return NetworkTablesJNI.setFloat(m_handle, 0, value); + } + + /** + * Sets the entry's value. + * + * @param value the value to set + * @return False if the entry exists with a different type + */ + public boolean setDouble(double value) { + return NetworkTablesJNI.setDouble(m_handle, 0, value); + } + + /** + * Sets the entry's value. + * + * @param value the value to set + * @return False if the entry exists with a different type + */ + public boolean setString(String value) { + return NetworkTablesJNI.setString(m_handle, 0, value); + } + + /** + * Sets the entry's value. + * + * @param value the value to set + * @return False if the entry exists with a different type + */ + public boolean setRaw(byte[] value) { + return NetworkTablesJNI.setRaw(m_handle, 0, value); + } + + /** + * Sets the entry's value. + * + * @param value the value to set; will send from value.position() to value.capacity() + * @return False if the entry exists with a different type + */ + public boolean setRaw(ByteBuffer value) { + return NetworkTablesJNI.setRaw(m_handle, 0, value); + } + + /** + * Sets the entry's value. + * + * @param value the value to set + * @param start Start position of data (in buffer) + * @param len Length of data (must be less than or equal to value.length - start) + * @return False if the entry exists with a different type + */ + public boolean setRaw(byte[] value, int start, int len) { + return NetworkTablesJNI.setRaw(m_handle, 0, value, start, len); + } + + /** + * Sets the entry's value. + * + * @param value the value to set + * @param start Start position of data (in buffer) + * @param len Length of data (must be less than or equal to value.capacity() - start) + * @return False if the entry exists with a different type + */ + public boolean setRaw(ByteBuffer value, int start, int len) { + return NetworkTablesJNI.setRaw(m_handle, 0, value, start, len); + } + + /** + * Sets the entry's value. + * + * @param value the value to set + * @return False if the entry exists with a different type + */ + public boolean setBooleanArray(boolean[] value) { + return NetworkTablesJNI.setBooleanArray(m_handle, 0, value); + } + + /** + * Sets the entry's value. + * + * @param value the value to set + * @return False if the entry exists with a different type + */ + public boolean setBooleanArray(Boolean[] value) { + return setBooleanArray(NetworkTableValue.toNativeBooleanArray(value)); + } + + /** + * Sets the entry's value. + * + * @param value the value to set + * @return False if the entry exists with a different type + */ + public boolean setIntegerArray(long[] value) { + return NetworkTablesJNI.setIntegerArray(m_handle, 0, value); + } + + /** + * Sets the entry's value. + * + * @param value the value to set + * @return False if the entry exists with a different type + */ + public boolean setIntegerArray(Long[] value) { + return setIntegerArray(NetworkTableValue.toNativeIntegerArray(value)); + } + + /** + * Sets the entry's value. + * + * @param value the value to set + * @return False if the entry exists with a different type + */ + public boolean setFloatArray(float[] value) { + return NetworkTablesJNI.setFloatArray(m_handle, 0, value); + } + + /** + * Sets the entry's value. + * + * @param value the value to set + * @return False if the entry exists with a different type + */ + public boolean setFloatArray(Float[] value) { + return setFloatArray(NetworkTableValue.toNativeFloatArray(value)); + } + + /** + * Sets the entry's value. + * + * @param value the value to set + * @return False if the entry exists with a different type + */ + public boolean setDoubleArray(double[] value) { + return NetworkTablesJNI.setDoubleArray(m_handle, 0, value); + } + + /** + * Sets the entry's value. + * + * @param value the value to set + * @return False if the entry exists with a different type + */ + public boolean setDoubleArray(Double[] value) { + return setDoubleArray(NetworkTableValue.toNativeDoubleArray(value)); + } + + /** + * Sets the entry's value. + * + * @param value the value to set + * @return False if the entry exists with a different type + */ + public boolean setStringArray(String[] value) { + return NetworkTablesJNI.setStringArray(m_handle, 0, value); + } + + /** + * Sets the entry's value. + * + * @param value the value to set + * @return False if the entry exists with a different type + */ + public boolean setNumber(Number value) { + return setDouble(value.doubleValue()); + } + + /** + * Sets the entry's value. + * + * @param value the value to set + * @return False if the entry exists with a different type + */ + public boolean setNumberArray(Number[] value) { + return setDoubleArray(NetworkTableValue.toNativeDoubleArray(value)); + } + + /** + * Sets flags. + * + * @param flags the flags to set (bitmask) + * @deprecated Use setPersistent() or topic properties instead + */ + @Deprecated(since = "2022", forRemoval = true) + public void setFlags(int flags) { + NetworkTablesJNI.setEntryFlags(m_handle, getFlags() | flags); + } + + /** + * Clears flags. + * + * @param flags the flags to clear (bitmask) + * @deprecated Use setPersistent() or topic properties instead + */ + @Deprecated(since = "2022", forRemoval = true) + public void clearFlags(int flags) { + NetworkTablesJNI.setEntryFlags(m_handle, getFlags() & ~flags); + } + + /** Make value persistent through program restarts. */ + public void setPersistent() { + NetworkTablesJNI.setTopicPersistent(m_topic.getHandle(), true); + } + + /** Stop making value persistent through program restarts. */ + public void clearPersistent() { + NetworkTablesJNI.setTopicPersistent(m_topic.getHandle(), false); + } + + /** + * Returns whether the value is persistent through program restarts. + * + * @return True if the value is persistent. + */ + public boolean isPersistent() { + return NetworkTablesJNI.getTopicPersistent(m_topic.getHandle()); + } + + /** Stops publishing the entry if it's been published. */ + public void unpublish() { + NetworkTablesJNI.unpublish(m_handle); + } + + /** + * Deletes the entry. + * + * @deprecated Use unpublish() instead. + */ + @Deprecated(since = "2022", forRemoval = true) + public void delete() { + unpublish(); + } + + @Override + public boolean equals(Object other) { + if (other == this) { + return true; + } + if (!(other instanceof NetworkTableEntry)) { + return false; + } + + return m_handle == ((NetworkTableEntry) other).m_handle; + } + + @Override + public int hashCode() { + return m_handle; + } + + private final Topic m_topic; + protected int m_handle; +} 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 new file mode 100644 index 0000000000..e5872ba425 --- /dev/null +++ b/ntcore/src/generated/main/java/edu/wpi/first/networktables/NetworkTableInstance.java @@ -0,0 +1,1553 @@ +// 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. + +// THIS FILE WAS AUTO-GENERATED BY ./ntcore/generate_topics.py. DO NOT MODIFY + +package edu.wpi.first.networktables; + +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; +import java.util.EnumSet; +import java.util.HashMap; +import java.util.HashSet; +import java.util.Map; +import java.util.OptionalLong; +import java.util.Set; +import java.util.concurrent.ConcurrentHashMap; +import java.util.concurrent.ConcurrentMap; +import java.util.concurrent.TimeUnit; +import java.util.concurrent.locks.Condition; +import java.util.concurrent.locks.ReentrantLock; +import java.util.function.Consumer; +import us.hebi.quickbuf.ProtoMessage; + +/** + * NetworkTables Instance. + * + *

Instances are completely independent from each other. Table operations on one instance will + * not be visible to other instances unless the instances are connected via the network. The main + * limitation on instances is that you cannot have two servers on the same network port. The main + * utility of instances is for unit testing, but they can also enable one program to connect to two + * different NetworkTables networks. + * + *

The global "default" instance (as returned by {@link #getDefault()}) is always available, and + * is intended for the common case when there is only a single NetworkTables instance being used in + * the program. + * + *

Additional instances can be created with the {@link #create()} function. A reference must be + * kept to the NetworkTableInstance returned by this function to keep it from being garbage + * collected. + */ +@SuppressWarnings("PMD.CouplingBetweenObjects") +public final class NetworkTableInstance implements AutoCloseable { + /** Client/server mode flag values (as returned by {@link #getNetworkMode()}). */ + public enum NetworkMode { + /** Running in server mode. */ + kServer(0x01), + + /** Running in NT3 client mode. */ + kClient3(0x02), + + /** Running in NT4 client mode. */ + kClient4(0x04), + + /** Currently starting up (either client or server). */ + kStarting(0x08), + + /** Running in local-only mode. */ + kLocal(0x10); + + private final int value; + + NetworkMode(int value) { + this.value = value; + } + + public int getValue() { + return value; + } + } + + /** The default port that network tables operates on for NT3. */ + public static final int kDefaultPort3 = 1735; + + /** The default port that network tables operates on for NT4. */ + public static final int kDefaultPort4 = 5810; + + /** + * Construct from native handle. + * + * @param handle Native handle + */ + private NetworkTableInstance(int handle) { + m_owned = false; + m_handle = handle; + } + + /** Destroys the instance (if created by {@link #create()}). */ + @Override + public synchronized void close() { + if (m_owned && m_handle != 0) { + m_listeners.close(); + m_schemas.forEach((k, v) -> v.close()); + NetworkTablesJNI.destroyInstance(m_handle); + m_handle = 0; + } + } + + /** + * Determines if the native handle is valid. + * + * @return True if the native handle is valid, false otherwise. + */ + public boolean isValid() { + return m_handle != 0; + } + + /* The default instance. */ + private static NetworkTableInstance s_defaultInstance; + + /** + * Get global default instance. + * + * @return Global default instance + */ + public static synchronized NetworkTableInstance getDefault() { + if (s_defaultInstance == null) { + s_defaultInstance = new NetworkTableInstance(NetworkTablesJNI.getDefaultInstance()); + } + return s_defaultInstance; + } + + /** + * Create an instance. Note: A reference to the returned instance must be retained to ensure the + * instance is not garbage collected. + * + * @return Newly created instance + */ + public static NetworkTableInstance create() { + NetworkTableInstance inst = new NetworkTableInstance(NetworkTablesJNI.createInstance()); + inst.m_owned = true; + return inst; + } + + /** + * Gets the native handle for the instance. + * + * @return Native handle + */ + public int getHandle() { + return m_handle; + } + + /** + * Get (generic) topic. + * + * @param name topic name + * @return Topic + */ + public Topic getTopic(String name) { + Topic topic = m_topics.get(name); + if (topic == null) { + int handle = NetworkTablesJNI.getTopic(m_handle, name); + topic = new Topic(this, handle); + Topic oldTopic = m_topics.putIfAbsent(name, topic); + if (oldTopic != null) { + topic = oldTopic; + } + // also cache by handle + m_topicsByHandle.putIfAbsent(handle, topic); + } + return topic; + } + + /** + * Get boolean topic. + * + * @param name topic name + * @return BooleanTopic + */ + public BooleanTopic getBooleanTopic(String name) { + Topic topic = m_topics.get(name); + if (topic instanceof BooleanTopic) { + return (BooleanTopic) topic; + } + + int handle; + if (topic == null) { + handle = NetworkTablesJNI.getTopic(m_handle, name); + } else { + handle = topic.getHandle(); + } + + BooleanTopic wrapTopic = new BooleanTopic(this, handle); + m_topics.put(name, wrapTopic); + + // also cache by handle + m_topicsByHandle.put(handle, wrapTopic); + + return wrapTopic; + } + + /** + * Get long topic. + * + * @param name topic name + * @return IntegerTopic + */ + public IntegerTopic getIntegerTopic(String name) { + Topic topic = m_topics.get(name); + if (topic instanceof IntegerTopic) { + return (IntegerTopic) topic; + } + + int handle; + if (topic == null) { + handle = NetworkTablesJNI.getTopic(m_handle, name); + } else { + handle = topic.getHandle(); + } + + IntegerTopic wrapTopic = new IntegerTopic(this, handle); + m_topics.put(name, wrapTopic); + + // also cache by handle + m_topicsByHandle.put(handle, wrapTopic); + + return wrapTopic; + } + + /** + * Get float topic. + * + * @param name topic name + * @return FloatTopic + */ + public FloatTopic getFloatTopic(String name) { + Topic topic = m_topics.get(name); + if (topic instanceof FloatTopic) { + return (FloatTopic) topic; + } + + int handle; + if (topic == null) { + handle = NetworkTablesJNI.getTopic(m_handle, name); + } else { + handle = topic.getHandle(); + } + + FloatTopic wrapTopic = new FloatTopic(this, handle); + m_topics.put(name, wrapTopic); + + // also cache by handle + m_topicsByHandle.put(handle, wrapTopic); + + return wrapTopic; + } + + /** + * Get double topic. + * + * @param name topic name + * @return DoubleTopic + */ + public DoubleTopic getDoubleTopic(String name) { + Topic topic = m_topics.get(name); + if (topic instanceof DoubleTopic) { + return (DoubleTopic) topic; + } + + int handle; + if (topic == null) { + handle = NetworkTablesJNI.getTopic(m_handle, name); + } else { + handle = topic.getHandle(); + } + + DoubleTopic wrapTopic = new DoubleTopic(this, handle); + m_topics.put(name, wrapTopic); + + // also cache by handle + m_topicsByHandle.put(handle, wrapTopic); + + return wrapTopic; + } + + /** + * Get String topic. + * + * @param name topic name + * @return StringTopic + */ + public StringTopic getStringTopic(String name) { + Topic topic = m_topics.get(name); + if (topic instanceof StringTopic) { + return (StringTopic) topic; + } + + int handle; + if (topic == null) { + handle = NetworkTablesJNI.getTopic(m_handle, name); + } else { + handle = topic.getHandle(); + } + + StringTopic wrapTopic = new StringTopic(this, handle); + m_topics.put(name, wrapTopic); + + // also cache by handle + m_topicsByHandle.put(handle, wrapTopic); + + return wrapTopic; + } + + /** + * Get byte[] topic. + * + * @param name topic name + * @return RawTopic + */ + public RawTopic getRawTopic(String name) { + Topic topic = m_topics.get(name); + if (topic instanceof RawTopic) { + return (RawTopic) topic; + } + + int handle; + if (topic == null) { + handle = NetworkTablesJNI.getTopic(m_handle, name); + } else { + handle = topic.getHandle(); + } + + RawTopic wrapTopic = new RawTopic(this, handle); + m_topics.put(name, wrapTopic); + + // also cache by handle + m_topicsByHandle.put(handle, wrapTopic); + + return wrapTopic; + } + + /** + * Get boolean[] topic. + * + * @param name topic name + * @return BooleanArrayTopic + */ + public BooleanArrayTopic getBooleanArrayTopic(String name) { + Topic topic = m_topics.get(name); + if (topic instanceof BooleanArrayTopic) { + return (BooleanArrayTopic) topic; + } + + int handle; + if (topic == null) { + handle = NetworkTablesJNI.getTopic(m_handle, name); + } else { + handle = topic.getHandle(); + } + + BooleanArrayTopic wrapTopic = new BooleanArrayTopic(this, handle); + m_topics.put(name, wrapTopic); + + // also cache by handle + m_topicsByHandle.put(handle, wrapTopic); + + return wrapTopic; + } + + /** + * Get long[] topic. + * + * @param name topic name + * @return IntegerArrayTopic + */ + public IntegerArrayTopic getIntegerArrayTopic(String name) { + Topic topic = m_topics.get(name); + if (topic instanceof IntegerArrayTopic) { + return (IntegerArrayTopic) topic; + } + + int handle; + if (topic == null) { + handle = NetworkTablesJNI.getTopic(m_handle, name); + } else { + handle = topic.getHandle(); + } + + IntegerArrayTopic wrapTopic = new IntegerArrayTopic(this, handle); + m_topics.put(name, wrapTopic); + + // also cache by handle + m_topicsByHandle.put(handle, wrapTopic); + + return wrapTopic; + } + + /** + * Get float[] topic. + * + * @param name topic name + * @return FloatArrayTopic + */ + public FloatArrayTopic getFloatArrayTopic(String name) { + Topic topic = m_topics.get(name); + if (topic instanceof FloatArrayTopic) { + return (FloatArrayTopic) topic; + } + + int handle; + if (topic == null) { + handle = NetworkTablesJNI.getTopic(m_handle, name); + } else { + handle = topic.getHandle(); + } + + FloatArrayTopic wrapTopic = new FloatArrayTopic(this, handle); + m_topics.put(name, wrapTopic); + + // also cache by handle + m_topicsByHandle.put(handle, wrapTopic); + + return wrapTopic; + } + + /** + * Get double[] topic. + * + * @param name topic name + * @return DoubleArrayTopic + */ + public DoubleArrayTopic getDoubleArrayTopic(String name) { + Topic topic = m_topics.get(name); + if (topic instanceof DoubleArrayTopic) { + return (DoubleArrayTopic) topic; + } + + int handle; + if (topic == null) { + handle = NetworkTablesJNI.getTopic(m_handle, name); + } else { + handle = topic.getHandle(); + } + + DoubleArrayTopic wrapTopic = new DoubleArrayTopic(this, handle); + m_topics.put(name, wrapTopic); + + // also cache by handle + m_topicsByHandle.put(handle, wrapTopic); + + return wrapTopic; + } + + /** + * Get String[] topic. + * + * @param name topic name + * @return StringArrayTopic + */ + public StringArrayTopic getStringArrayTopic(String name) { + Topic topic = m_topics.get(name); + if (topic instanceof StringArrayTopic) { + return (StringArrayTopic) topic; + } + + int handle; + if (topic == null) { + handle = NetworkTablesJNI.getTopic(m_handle, name); + } else { + handle = topic.getHandle(); + } + + StringArrayTopic wrapTopic = new StringArrayTopic(this, handle); + m_topics.put(name, wrapTopic); + + // also cache by handle + m_topicsByHandle.put(handle, wrapTopic); + + return wrapTopic; + } + + + /** + * Get protobuf-encoded value topic. + * + * @param value class (inferred from proto) + * @param protobuf message type (inferred from proto) + * @param name topic name + * @param proto protobuf serialization implementation + * @return ProtobufTopic + */ + public > + ProtobufTopic getProtobufTopic(String name, Protobuf proto) { + Topic topic = m_topics.get(name); + if (topic instanceof ProtobufTopic + && ((ProtobufTopic) topic).getProto().equals(proto)) { + @SuppressWarnings("unchecked") + ProtobufTopic wrapTopic = (ProtobufTopic) topic; + return wrapTopic; + } + + int handle; + if (topic == null) { + handle = NetworkTablesJNI.getTopic(m_handle, name); + } else { + handle = topic.getHandle(); + } + + ProtobufTopic wrapTopic = ProtobufTopic.wrap(this, handle, proto); + m_topics.put(name, wrapTopic); + + // also cache by handle + m_topicsByHandle.put(handle, wrapTopic); + + return wrapTopic; + } + + /** + * Get struct-encoded value topic. + * + * @param value class (inferred from struct) + * @param name topic name + * @param struct struct serialization implementation + * @return StructTopic + */ + public + StructTopic getStructTopic(String name, Struct struct) { + Topic topic = m_topics.get(name); + if (topic instanceof StructTopic + && ((StructTopic) topic).getStruct().equals(struct)) { + @SuppressWarnings("unchecked") + StructTopic wrapTopic = (StructTopic) topic; + return wrapTopic; + } + + int handle; + if (topic == null) { + handle = NetworkTablesJNI.getTopic(m_handle, name); + } else { + handle = topic.getHandle(); + } + + StructTopic wrapTopic = StructTopic.wrap(this, handle, struct); + m_topics.put(name, wrapTopic); + + // also cache by handle + m_topicsByHandle.put(handle, wrapTopic); + + return wrapTopic; + } + + /** + * Get struct-encoded value array topic. + * + * @param value class (inferred from struct) + * @param name topic name + * @param struct struct serialization implementation + * @return StructArrayTopic + */ + public + StructArrayTopic getStructArrayTopic(String name, Struct struct) { + Topic topic = m_topics.get(name); + if (topic instanceof StructArrayTopic + && ((StructArrayTopic) topic).getStruct().equals(struct)) { + @SuppressWarnings("unchecked") + StructArrayTopic wrapTopic = (StructArrayTopic) topic; + return wrapTopic; + } + + int handle; + if (topic == null) { + handle = NetworkTablesJNI.getTopic(m_handle, name); + } else { + handle = topic.getHandle(); + } + + StructArrayTopic wrapTopic = StructArrayTopic.wrap(this, handle, struct); + m_topics.put(name, wrapTopic); + + // also cache by handle + m_topicsByHandle.put(handle, wrapTopic); + + return wrapTopic; + } + + private Topic[] topicHandlesToTopics(int[] handles) { + Topic[] topics = new Topic[handles.length]; + for (int i = 0; i < handles.length; i++) { + topics[i] = getCachedTopic(handles[i]); + } + return topics; + } + + /** + * Get all published topics. + * + * @return Array of topics. + */ + public Topic[] getTopics() { + return topicHandlesToTopics(NetworkTablesJNI.getTopics(m_handle, "", 0)); + } + + /** + * Get published topics starting with the given prefix. The results are optionally filtered by + * string prefix to only return a subset of all topics. + * + * @param prefix topic name required prefix; only topics whose name starts with this string are + * returned + * @return Array of topic information. + */ + public Topic[] getTopics(String prefix) { + return topicHandlesToTopics(NetworkTablesJNI.getTopics(m_handle, prefix, 0)); + } + + /** + * Get published topics starting with the given prefix. The results are optionally filtered by + * string prefix and data type to only return a subset of all topics. + * + * @param prefix topic name required prefix; only topics whose name starts with this string are + * returned + * @param types bitmask of data types; 0 is treated as a "don't care" + * @return Array of topic information. + */ + public Topic[] getTopics(String prefix, int types) { + return topicHandlesToTopics(NetworkTablesJNI.getTopics(m_handle, prefix, types)); + } + + /** + * Get published topics starting with the given prefix. The results are optionally filtered by + * string prefix and data type to only return a subset of all topics. + * + * @param prefix topic name required prefix; only topics whose name starts with this string are + * returned + * @param types array of data type strings + * @return Array of topic information. + */ + public Topic[] getTopics(String prefix, String[] types) { + return topicHandlesToTopics(NetworkTablesJNI.getTopicsStr(m_handle, prefix, types)); + } + + /** + * Get information about all topics. + * + * @return Array of topic information. + */ + public TopicInfo[] getTopicInfo() { + return NetworkTablesJNI.getTopicInfos(this, m_handle, "", 0); + } + + /** + * Get information about topics starting with the given prefix. The results are optionally + * filtered by string prefix to only return a subset of all topics. + * + * @param prefix topic name required prefix; only topics whose name starts with this string are + * returned + * @return Array of topic information. + */ + public TopicInfo[] getTopicInfo(String prefix) { + return NetworkTablesJNI.getTopicInfos(this, m_handle, prefix, 0); + } + + /** + * Get information about topics starting with the given prefix. The results are optionally + * filtered by string prefix and data type to only return a subset of all topics. + * + * @param prefix topic name required prefix; only topics whose name starts with this string are + * returned + * @param types bitmask of data types; 0 is treated as a "don't care" + * @return Array of topic information. + */ + public TopicInfo[] getTopicInfo(String prefix, int types) { + return NetworkTablesJNI.getTopicInfos(this, m_handle, prefix, types); + } + + /** + * Get information about topics starting with the given prefix. The results are optionally + * filtered by string prefix and data type to only return a subset of all topics. + * + * @param prefix topic name required prefix; only topics whose name starts with this string are + * returned + * @param types array of data type strings + * @return Array of topic information. + */ + public TopicInfo[] getTopicInfo(String prefix, String[] types) { + return NetworkTablesJNI.getTopicInfosStr(this, m_handle, prefix, types); + } + + /* Cache of created entries. */ + private final ConcurrentMap m_entries = new ConcurrentHashMap<>(); + + /** + * Gets the entry for a key. + * + * @param name Key + * @return Network table entry. + */ + public NetworkTableEntry getEntry(String name) { + NetworkTableEntry entry = m_entries.get(name); + if (entry == null) { + entry = new NetworkTableEntry(this, NetworkTablesJNI.getEntry(m_handle, name)); + NetworkTableEntry oldEntry = m_entries.putIfAbsent(name, entry); + if (oldEntry != null) { + entry = oldEntry; + } + } + return entry; + } + + /* Cache of created topics. */ + private final ConcurrentMap m_topics = new ConcurrentHashMap<>(); + private final ConcurrentMap m_topicsByHandle = new ConcurrentHashMap<>(); + + Topic getCachedTopic(String name) { + Topic topic = m_topics.get(name); + if (topic == null) { + int handle = NetworkTablesJNI.getTopic(m_handle, name); + topic = new Topic(this, handle); + Topic oldTopic = m_topics.putIfAbsent(name, topic); + if (oldTopic != null) { + topic = oldTopic; + } + // also cache by handle + m_topicsByHandle.putIfAbsent(handle, topic); + } + return topic; + } + + Topic getCachedTopic(int handle) { + Topic topic = m_topicsByHandle.get(handle); + if (topic == null) { + topic = new Topic(this, handle); + Topic oldTopic = m_topicsByHandle.putIfAbsent(handle, topic); + if (oldTopic != null) { + topic = oldTopic; + } + } + return topic; + } + + /* Cache of created tables. */ + private final ConcurrentMap m_tables = new ConcurrentHashMap<>(); + + /** + * Gets the table with the specified key. + * + * @param key the key name + * @return The network table + */ + public NetworkTable getTable(String key) { + // prepend leading / if not present + String theKey; + if (key.isEmpty() || "/".equals(key)) { + theKey = ""; + } else if (key.charAt(0) == NetworkTable.PATH_SEPARATOR) { + theKey = key; + } else { + theKey = NetworkTable.PATH_SEPARATOR + key; + } + + // cache created tables + NetworkTable table = m_tables.get(theKey); + if (table == null) { + table = new NetworkTable(this, theKey); + NetworkTable oldTable = m_tables.putIfAbsent(theKey, table); + if (oldTable != null) { + table = oldTable; + } + } + return table; + } + + /* + * Callback Creation Functions + */ + + private static class ListenerStorage implements AutoCloseable { + private final ReentrantLock m_lock = new ReentrantLock(); + private final Map> m_listeners = new HashMap<>(); + private Thread m_thread; + private int m_poller; + private boolean m_waitQueue; + private final Event m_waitQueueEvent = new Event(); + private final Condition m_waitQueueCond = m_lock.newCondition(); + private final NetworkTableInstance m_inst; + + ListenerStorage(NetworkTableInstance inst) { + m_inst = inst; + } + + int add( + String[] prefixes, + EnumSet eventKinds, + Consumer listener) { + m_lock.lock(); + try { + if (m_poller == 0) { + m_poller = NetworkTablesJNI.createListenerPoller(m_inst.getHandle()); + startThread(); + } + int h = NetworkTablesJNI.addListener(m_poller, prefixes, eventKinds); + m_listeners.put(h, listener); + return h; + } finally { + m_lock.unlock(); + } + } + + int add( + int handle, + EnumSet eventKinds, + Consumer listener) { + m_lock.lock(); + try { + if (m_poller == 0) { + m_poller = NetworkTablesJNI.createListenerPoller(m_inst.getHandle()); + startThread(); + } + int h = NetworkTablesJNI.addListener(m_poller, handle, eventKinds); + m_listeners.put(h, listener); + return h; + } finally { + m_lock.unlock(); + } + } + + int addLogger(int minLevel, int maxLevel, Consumer listener) { + m_lock.lock(); + try { + if (m_poller == 0) { + m_poller = NetworkTablesJNI.createListenerPoller(m_inst.getHandle()); + startThread(); + } + int h = NetworkTablesJNI.addLogger(m_poller, minLevel, maxLevel); + m_listeners.put(h, listener); + return h; + } finally { + m_lock.unlock(); + } + } + + void remove(int listener) { + m_lock.lock(); + try { + m_listeners.remove(listener); + } finally { + m_lock.unlock(); + } + NetworkTablesJNI.removeListener(listener); + } + + @Override + public void close() { + if (m_poller != 0) { + NetworkTablesJNI.destroyListenerPoller(m_poller); + } + m_poller = 0; + } + + private void startThread() { + m_thread = + new Thread( + () -> { + boolean wasInterrupted = false; + int[] handles = new int[] { m_poller, m_waitQueueEvent.getHandle() }; + while (!Thread.interrupted()) { + try { + WPIUtilJNI.waitForObjects(handles); + } catch (InterruptedException ex) { + m_lock.lock(); + try { + if (m_waitQueue) { + m_waitQueue = false; + m_waitQueueCond.signalAll(); + } + } finally { + m_lock.unlock(); + } + Thread.currentThread().interrupt(); + // don't try to destroy poller, as its handle is likely no longer valid + wasInterrupted = true; + break; + } + for (NetworkTableEvent event : + NetworkTablesJNI.readListenerQueue(m_inst, m_poller)) { + Consumer listener; + m_lock.lock(); + try { + listener = m_listeners.get(event.listener); + } finally { + m_lock.unlock(); + } + if (listener != null) { + try { + listener.accept(event); + } catch (Throwable throwable) { + System.err.println( + "Unhandled exception during listener callback: " + + throwable.toString()); + throwable.printStackTrace(); + } + } + } + m_lock.lock(); + try { + if (m_waitQueue) { + m_waitQueue = false; + m_waitQueueCond.signalAll(); + } + } finally { + m_lock.unlock(); + } + } + m_lock.lock(); + try { + if (!wasInterrupted) { + NetworkTablesJNI.destroyListenerPoller(m_poller); + } + m_poller = 0; + } finally { + m_lock.unlock(); + } + }, + "NTListener"); + m_thread.setDaemon(true); + m_thread.start(); + } + + boolean waitForQueue(double timeout) { + m_lock.lock(); + try { + if (m_poller != 0) { + m_waitQueue = true; + m_waitQueueEvent.set(); + while (m_waitQueue) { + try { + if (timeout < 0) { + m_waitQueueCond.await(); + } else { + return m_waitQueueCond.await((long) (timeout * 1e9), TimeUnit.NANOSECONDS); + } + } catch (InterruptedException ex) { + Thread.currentThread().interrupt(); + return true; + } + } + } + } finally { + m_lock.unlock(); + } + return true; + } + } + + private final ListenerStorage m_listeners = new ListenerStorage(this); + + /** + * Remove a connection listener. + * + * @param listener Listener handle to remove + */ + public void removeListener(int listener) { + m_listeners.remove(listener); + } + + /** + * Wait for the listener queue to be empty. This is primarily useful for deterministic + * testing. This blocks until either the listener queue is empty (e.g. there are no + * more events that need to be passed along to callbacks or poll queues) or the timeout expires. + * + * @param timeout timeout, in seconds. Set to 0 for non-blocking behavior, or a negative value to + * block indefinitely + * @return False if timed out, otherwise true. + */ + public boolean waitForListenerQueue(double timeout) { + return m_listeners.waitForQueue(timeout); + } + + /** + * Add a connection listener. The callback function is called asynchronously on a separate + * thread, so it's important to use synchronization or atomics when accessing any shared state + * from the callback function. + * + * @param immediateNotify Notify listener of all existing connections + * @param listener Listener to add + * @return Listener handle + */ + public int addConnectionListener( + boolean immediateNotify, Consumer listener) { + EnumSet eventKinds = EnumSet.of(NetworkTableEvent.Kind.kConnection); + if (immediateNotify) { + eventKinds.add(NetworkTableEvent.Kind.kImmediate); + } + return m_listeners.add(m_handle, eventKinds, listener); + } + + /** + * Add a time synchronization listener. The callback function is called asynchronously on a + * separate thread, so it's important to use synchronization or atomics when accessing any shared + * state from the callback function. + * + * @param immediateNotify Notify listener of current time synchronization value + * @param listener Listener to add + * @return Listener handle + */ + public int addTimeSyncListener( + boolean immediateNotify, Consumer listener) { + EnumSet eventKinds = EnumSet.of(NetworkTableEvent.Kind.kTimeSync); + if (immediateNotify) { + eventKinds.add(NetworkTableEvent.Kind.kImmediate); + } + return m_listeners.add(m_handle, eventKinds, listener); + } + + /** + * Add a listener for changes on a particular topic. The callback function is called + * asynchronously on a separate thread, so it's important to use synchronization or atomics when + * accessing any shared state from the callback function. + * + *

This creates a corresponding internal subscriber with the lifetime of the + * listener. + * + * @param topic Topic + * @param eventKinds set of event kinds to listen to + * @param listener Listener function + * @return Listener handle + */ + public int addListener( + Topic topic, + EnumSet eventKinds, + Consumer listener) { + if (topic.getInstance().getHandle() != m_handle) { + throw new IllegalArgumentException("topic is not from this instance"); + } + return m_listeners.add(topic.getHandle(), eventKinds, listener); + } + + /** + * Add a listener for changes on a subscriber. The callback function is called + * asynchronously on a separate thread, so it's important to use synchronization or atomics when + * accessing any shared state from the callback function. This does NOT keep the subscriber + * active. + * + * @param subscriber Subscriber + * @param eventKinds set of event kinds to listen to + * @param listener Listener function + * @return Listener handle + */ + public int addListener( + Subscriber subscriber, + EnumSet eventKinds, + Consumer listener) { + if (subscriber.getTopic().getInstance().getHandle() != m_handle) { + throw new IllegalArgumentException("subscriber is not from this instance"); + } + return m_listeners.add(subscriber.getHandle(), eventKinds, listener); + } + + /** + * Add a listener for changes on a subscriber. The callback function is called + * asynchronously on a separate thread, so it's important to use synchronization or atomics when + * accessing any shared state from the callback function. This does NOT keep the subscriber + * active. + * + * @param subscriber Subscriber + * @param eventKinds set of event kinds to listen to + * @param listener Listener function + * @return Listener handle + */ + public int addListener( + MultiSubscriber subscriber, + EnumSet eventKinds, + Consumer listener) { + if (subscriber.getInstance().getHandle() != m_handle) { + throw new IllegalArgumentException("subscriber is not from this instance"); + } + return m_listeners.add(subscriber.getHandle(), eventKinds, listener); + } + + /** + * Add a listener for changes on an entry. The callback function is called + * asynchronously on a separate thread, so it's important to use synchronization or atomics when + * accessing any shared state from the callback function. + * + * @param entry Entry + * @param eventKinds set of event kinds to listen to + * @param listener Listener function + * @return Listener handle + */ + public int addListener( + NetworkTableEntry entry, + EnumSet eventKinds, + Consumer listener) { + if (entry.getTopic().getInstance().getHandle() != m_handle) { + throw new IllegalArgumentException("entry is not from this instance"); + } + return m_listeners.add(entry.getHandle(), eventKinds, listener); + } + + /** + * Add a listener for changes to topics with names that start with any of the given + * prefixes. The callback function is called asynchronously on a separate thread, so it's + * important to use synchronization or atomics when accessing any shared state from the callback + * function. + * + *

This creates a corresponding internal subscriber with the lifetime of the + * listener. + * + * @param prefixes Topic name string prefixes + * @param eventKinds set of event kinds to listen to + * @param listener Listener function + * @return Listener handle + */ + public int addListener( + String[] prefixes, + EnumSet eventKinds, + Consumer listener) { + return m_listeners.add(prefixes, eventKinds, listener); + } + + /* + * Client/Server Functions + */ + + /** + * Get the current network mode. + * + * @return Enum set of NetworkMode. + */ + public EnumSet getNetworkMode() { + int flags = NetworkTablesJNI.getNetworkMode(m_handle); + EnumSet rv = EnumSet.noneOf(NetworkMode.class); + for (NetworkMode mode : NetworkMode.values()) { + if ((flags & mode.getValue()) != 0) { + rv.add(mode); + } + } + return rv; + } + + /** + * Starts local-only operation. Prevents calls to startServer or startClient from taking effect. + * Has no effect if startServer or startClient has already been called. + */ + public void startLocal() { + NetworkTablesJNI.startLocal(m_handle); + } + + /** + * Stops local-only operation. startServer or startClient can be called after this call to start + * a server or client. + */ + public void stopLocal() { + NetworkTablesJNI.stopLocal(m_handle); + } + + /** + * Starts a server using the networktables.json as the persistent file, using the default + * listening address and port. + */ + public void startServer() { + startServer("networktables.json"); + } + + /** + * Starts a server using the specified persistent filename, using the default listening address + * and port. + * + * @param persistFilename the name of the persist file to use + */ + public void startServer(String persistFilename) { + startServer(persistFilename, ""); + } + + /** + * Starts a server using the specified filename and listening address, using the default port. + * + * @param persistFilename the name of the persist file to use + * @param listenAddress the address to listen on, or empty to listen on any address + */ + public void startServer(String persistFilename, String listenAddress) { + startServer(persistFilename, listenAddress, kDefaultPort3, kDefaultPort4); + } + + /** + * Starts a server using the specified filename, listening address, and port. + * + * @param persistFilename the name of the persist file to use + * @param listenAddress the address to listen on, or empty to listen on any address + * @param port3 port to communicate over (NT3) + */ + public void startServer(String persistFilename, String listenAddress, int port3) { + startServer(persistFilename, listenAddress, port3, kDefaultPort4); + } + + /** + * Starts a server using the specified filename, listening address, and port. + * + * @param persistFilename the name of the persist file to use + * @param listenAddress the address to listen on, or empty to listen on any address + * @param port3 port to communicate over (NT3) + * @param port4 port to communicate over (NT4) + */ + public void startServer(String persistFilename, String listenAddress, int port3, int port4) { + NetworkTablesJNI.startServer(m_handle, persistFilename, listenAddress, port3, port4); + } + + /** Stops the server if it is running. */ + public void stopServer() { + NetworkTablesJNI.stopServer(m_handle); + } + + /** + * Starts a NT3 client. Use SetServer or SetServerTeam to set the server name and port. + * + * @param identity network identity to advertise (cannot be empty string) + */ + public void startClient3(String identity) { + NetworkTablesJNI.startClient3(m_handle, identity); + } + + /** + * Starts a NT4 client. Use SetServer or SetServerTeam to set the server name and port. + * + * @param identity network identity to advertise (cannot be empty string) + */ + public void startClient4(String identity) { + NetworkTablesJNI.startClient4(m_handle, identity); + } + + /** Stops the client if it is running. */ + public void stopClient() { + NetworkTablesJNI.stopClient(m_handle); + } + + /** + * Sets server address and port for client (without restarting client). Changes the port to the + * default port. + * + * @param serverName server name + */ + public void setServer(String serverName) { + setServer(serverName, 0); + } + + /** + * Sets server address and port for client (without restarting client). + * + * @param serverName server name + * @param port port to communicate over (0=default) + */ + public void setServer(String serverName, int port) { + NetworkTablesJNI.setServer(m_handle, serverName, port); + } + + /** + * Sets server addresses and port for client (without restarting client). Changes the port to the + * default port. The client will attempt to connect to each server in round robin fashion. + * + * @param serverNames array of server names + */ + public void setServer(String[] serverNames) { + setServer(serverNames, 0); + } + + /** + * Sets server addresses and port for client (without restarting client). The client will attempt + * to connect to each server in round robin fashion. + * + * @param serverNames array of server names + * @param port port to communicate over (0=default) + */ + public void setServer(String[] serverNames, int port) { + int[] ports = new int[serverNames.length]; + for (int i = 0; i < serverNames.length; i++) { + ports[i] = port; + } + setServer(serverNames, ports); + } + + /** + * Sets server addresses and ports for client (without restarting client). The client will + * attempt to connect to each server in round robin fashion. + * + * @param serverNames array of server names + * @param ports array of port numbers (0=default) + */ + public void setServer(String[] serverNames, int[] ports) { + NetworkTablesJNI.setServer(m_handle, serverNames, ports); + } + + /** + * Sets server addresses and port for client (without restarting client). Changes the port to the + * default port. The client will attempt to connect to each server in round robin fashion. + * + * @param team team number + */ + public void setServerTeam(int team) { + setServerTeam(team, 0); + } + + /** + * Sets server addresses and port for client (without restarting client). Connects using commonly + * known robot addresses for the specified team. + * + * @param team team number + * @param port port to communicate over (0=default) + */ + public void setServerTeam(int team, int port) { + NetworkTablesJNI.setServerTeam(m_handle, team, port); + } + + /** + * Disconnects the client if it's running and connected. This will automatically start + * reconnection attempts to the current server list. + */ + public void disconnect() { + NetworkTablesJNI.disconnect(m_handle); + } + + /** + * Starts requesting server address from Driver Station. This connects to the Driver Station + * running on localhost to obtain the server IP address, and connects with the default port. + */ + public void startDSClient() { + startDSClient(0); + } + + /** + * Starts requesting server address from Driver Station. This connects to the Driver Station + * running on localhost to obtain the server IP address. + * + * @param port server port to use in combination with IP from DS (0=default) + */ + public void startDSClient(int port) { + NetworkTablesJNI.startDSClient(m_handle, port); + } + + /** Stops requesting server address from Driver Station. */ + public void stopDSClient() { + NetworkTablesJNI.stopDSClient(m_handle); + } + + /** + * Flushes all updated values immediately to the local client/server. This does not flush to the + * network. + */ + public void flushLocal() { + NetworkTablesJNI.flushLocal(m_handle); + } + + /** + * Flushes all updated values immediately to the network. Note: This is rate-limited to protect + * the network from flooding. This is primarily useful for synchronizing network updates with + * user code. + */ + public void flush() { + NetworkTablesJNI.flush(m_handle); + } + + /** + * Gets information on the currently established network connections. If operating as a client, + * this will return either zero or one values. + * + * @return array of connection information + */ + public ConnectionInfo[] getConnections() { + return NetworkTablesJNI.getConnections(m_handle); + } + + /** + * Return whether or not the instance is connected to another node. + * + * @return True if connected. + */ + public boolean isConnected() { + return NetworkTablesJNI.isConnected(m_handle); + } + + /** + * Get the time offset between server time and local time. Add this value to local time to get + * the estimated equivalent server time. In server mode, this always returns 0. In client mode, + * this returns the time offset only if the client and server are connected and have exchanged + * synchronization messages. Note the time offset may change over time as it is periodically + * updated; to receive updates as events, add a listener to the "time sync" event. + * + * @return Time offset in microseconds (optional) + */ + public OptionalLong getServerTimeOffset() { + return NetworkTablesJNI.getServerTimeOffset(m_handle); + } + + /** + * Starts logging entry changes to a DataLog. + * + * @param log data log object; lifetime must extend until StopEntryDataLog is called or the + * instance is destroyed + * @param prefix only store entries with names that start with this prefix; the prefix is not + * included in the data log entry name + * @param logPrefix prefix to add to data log entry names + * @return Data logger handle + */ + public int startEntryDataLog(DataLog log, String prefix, String logPrefix) { + return NetworkTablesJNI.startEntryDataLog(m_handle, log, prefix, logPrefix); + } + + /** + * Stops logging entry changes to a DataLog. + * + * @param logger data logger handle + */ + public static void stopEntryDataLog(int logger) { + NetworkTablesJNI.stopEntryDataLog(logger); + } + + /** + * Starts logging connection changes to a DataLog. + * + * @param log data log object; lifetime must extend until StopConnectionDataLog is called or the + * instance is destroyed + * @param name data log entry name + * @return Data logger handle + */ + public int startConnectionDataLog(DataLog log, String name) { + return NetworkTablesJNI.startConnectionDataLog(m_handle, log, name); + } + + /** + * Stops logging connection changes to a DataLog. + * + * @param logger data logger handle + */ + public static void stopConnectionDataLog(int logger) { + NetworkTablesJNI.stopConnectionDataLog(logger); + } + + /** + * Add logger callback function. By default, log messages are sent to stderr; this function sends + * log messages with the specified levels to the provided callback function instead. The callback + * function will only be called for log messages with level greater than or equal to minLevel and + * less than or equal to maxLevel; messages outside this range will be silently ignored. + * + * @param minLevel minimum log level + * @param maxLevel maximum log level + * @param func callback function + * @return Listener handle + */ + public int addLogger(int minLevel, int maxLevel, Consumer func) { + return m_listeners.addLogger(minLevel, maxLevel, func); + } + + /** + * Returns whether there is a data schema already registered with the given name that this + * instance has published. This does NOT perform a check as to whether the schema has already + * been published by another node on the network. + * + * @param name Name (the string passed as the data type for topics using this schema) + * @return True if schema already registered + */ + public boolean hasSchema(String name) { + return m_schemas.containsKey("/.schema/" + name); + } + + /** + * Registers a data schema. Data schemas provide information for how a certain data type string + * can be decoded. The type string of a data schema indicates the type of the schema itself (e.g. + * "protobuf" for protobuf schemas, "struct" for struct schemas, etc). In NetworkTables, schemas + * are published just like normal topics, with the name being generated from the provided name: + * "/.schema/name". Duplicate calls to this function with the same name are silently ignored. + * + * @param name Name (the string passed as the data type for topics using this schema) + * @param type Type of schema (e.g. "protobuf", "struct", etc) + * @param schema Schema data + */ + public void addSchema(String name, String type, byte[] schema) { + m_schemas.computeIfAbsent("/.schema/" + name, k -> { + RawPublisher pub = getRawTopic(k).publishEx(type, "{\"retained\":true}"); + pub.setDefault(schema); + return pub; + }); + } + + /** + * Registers a data schema. Data schemas provide information for how a certain data type string + * can be decoded. The type string of a data schema indicates the type of the schema itself (e.g. + * "protobuf" for protobuf schemas, "struct" for struct schemas, etc). In NetworkTables, schemas + * are published just like normal topics, with the name being generated from the provided name: + * "/.schema/name". Duplicate calls to this function with the same name are silently ignored. + * + * @param name Name (the string passed as the data type for topics using this schema) + * @param type Type of schema (e.g. "protobuf", "struct", etc) + * @param schema Schema data + */ + public void addSchema(String name, String type, String schema) { + m_schemas.computeIfAbsent("/.schema/" + name, k -> { + RawPublisher pub = getRawTopic(k).publishEx(type, "{\"retained\":true}"); + pub.setDefault(StandardCharsets.UTF_8.encode(schema)); + return pub; + }); + } + + /** + * Registers a protobuf schema. Duplicate calls to this function with the same name are silently + * ignored. + * + * @param proto protobuf serialization object + */ + public void addSchema(Protobuf proto) { + proto.forEachDescriptor( + this::hasSchema, + (typeString, schema) -> addSchema(typeString, "proto:FileDescriptorProto", schema)); + } + + /** + * Registers a struct schema. Duplicate calls to this function with the same name are silently + * ignored. + * + * @param struct struct serialization object + */ + public void addSchema(Struct struct) { + addSchemaImpl(struct, new HashSet<>()); + } + + @Override + public boolean equals(Object other) { + if (other == this) { + return true; + } + if (!(other instanceof NetworkTableInstance)) { + return false; + } + + return m_handle == ((NetworkTableInstance) other).m_handle; + } + + @Override + public int hashCode() { + return m_handle; + } + + private void addSchemaImpl(Struct struct, Set seen) { + String typeString = struct.getTypeString(); + if (hasSchema(typeString)) { + return; + } + if (!seen.add(typeString)) { + throw new UnsupportedOperationException(typeString + ": circular reference with " + seen); + } + addSchema(typeString, "structschema", struct.getSchema()); + for (Struct inner : struct.getNested()) { + addSchemaImpl(inner, seen); + } + seen.remove(typeString); + } + + private boolean m_owned; + private int m_handle; + private final ConcurrentMap m_schemas = new ConcurrentHashMap<>(); +} diff --git a/ntcore/src/generated/main/java/edu/wpi/first/networktables/NetworkTableValue.java b/ntcore/src/generated/main/java/edu/wpi/first/networktables/NetworkTableValue.java new file mode 100644 index 0000000000..3045d284a5 --- /dev/null +++ b/ntcore/src/generated/main/java/edu/wpi/first/networktables/NetworkTableValue.java @@ -0,0 +1,742 @@ +// 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. + +// THIS FILE WAS AUTO-GENERATED BY ./ntcore/generate_topics.py. DO NOT MODIFY + +package edu.wpi.first.networktables; + +import java.util.Objects; + +/** A network table entry value. */ +@SuppressWarnings({"UnnecessaryParentheses", "PMD.MethodReturnsInternalArray"}) +public final class NetworkTableValue { + NetworkTableValue(NetworkTableType type, Object value, long time, long serverTime) { + m_type = type; + m_value = value; + m_time = time; + m_serverTime = serverTime; + } + + NetworkTableValue(NetworkTableType type, Object value, long time) { + this(type, value, time, time == 0 ? 0 : 1); + } + + NetworkTableValue(NetworkTableType type, Object value) { + this(type, value, NetworkTablesJNI.now(), 1); + } + + NetworkTableValue(int type, Object value, long time, long serverTime) { + this(NetworkTableType.getFromInt(type), value, time, serverTime); + } + + /** + * Get the data type. + * + * @return The type. + */ + public NetworkTableType getType() { + return m_type; + } + + /** + * Get the data value stored. + * + * @return The type. + */ + public Object getValue() { + return m_value; + } + + /** + * Get the creation time of the value in local time. + * + * @return The time, in the units returned by NetworkTablesJNI.now(). + */ + public long getTime() { + return m_time; + } + + /** + * Get the creation time of the value in server time. + * + * @return The server time. + */ + public long getServerTime() { + return m_serverTime; + } + + /* + * Type Checkers + */ + + /** + * Determine if entry value contains a value or is unassigned. + * + * @return True if the entry value contains a value. + */ + public boolean isValid() { + return m_type != NetworkTableType.kUnassigned; + } + + /** + * Determine if entry value contains a boolean. + * + * @return True if the entry value is of boolean type. + */ + public boolean isBoolean() { + return m_type == NetworkTableType.kBoolean; + } + + /** + * Determine if entry value contains a long. + * + * @return True if the entry value is of long type. + */ + public boolean isInteger() { + return m_type == NetworkTableType.kInteger; + } + + /** + * Determine if entry value contains a float. + * + * @return True if the entry value is of float type. + */ + public boolean isFloat() { + return m_type == NetworkTableType.kFloat; + } + + /** + * Determine if entry value contains a double. + * + * @return True if the entry value is of double type. + */ + public boolean isDouble() { + return m_type == NetworkTableType.kDouble; + } + + /** + * Determine if entry value contains a String. + * + * @return True if the entry value is of String type. + */ + public boolean isString() { + return m_type == NetworkTableType.kString; + } + + /** + * Determine if entry value contains a byte[]. + * + * @return True if the entry value is of byte[] type. + */ + public boolean isRaw() { + return m_type == NetworkTableType.kRaw; + } + + /** + * Determine if entry value contains a boolean[]. + * + * @return True if the entry value is of boolean[] type. + */ + public boolean isBooleanArray() { + return m_type == NetworkTableType.kBooleanArray; + } + + /** + * Determine if entry value contains a long[]. + * + * @return True if the entry value is of long[] type. + */ + public boolean isIntegerArray() { + return m_type == NetworkTableType.kIntegerArray; + } + + /** + * Determine if entry value contains a float[]. + * + * @return True if the entry value is of float[] type. + */ + public boolean isFloatArray() { + return m_type == NetworkTableType.kFloatArray; + } + + /** + * Determine if entry value contains a double[]. + * + * @return True if the entry value is of double[] type. + */ + public boolean isDoubleArray() { + return m_type == NetworkTableType.kDoubleArray; + } + + /** + * Determine if entry value contains a String[]. + * + * @return True if the entry value is of String[] type. + */ + public boolean isStringArray() { + return m_type == NetworkTableType.kStringArray; + } + + /* + * Type-Safe Getters + */ + + /** + * Get the boolean value. + * + * @return The boolean value. + * @throws ClassCastException if the entry value is not of boolean type. + */ + public boolean getBoolean() { + if (m_type != NetworkTableType.kBoolean) { + throw new ClassCastException("cannot convert " + m_type + " to boolean"); + } + return (Boolean) m_value; + } + + /** + * Get the long value. + * + * @return The long value. + * @throws ClassCastException if the entry value is not of long type. + */ + public long getInteger() { + if (m_type != NetworkTableType.kInteger) { + throw new ClassCastException("cannot convert " + m_type + " to long"); + } + return ((Number) m_value).longValue(); + } + + /** + * Get the float value. + * + * @return The float value. + * @throws ClassCastException if the entry value is not of float type. + */ + public float getFloat() { + if (m_type != NetworkTableType.kFloat) { + throw new ClassCastException("cannot convert " + m_type + " to float"); + } + return ((Number) m_value).floatValue(); + } + + /** + * Get the double value. + * + * @return The double value. + * @throws ClassCastException if the entry value is not of double type. + */ + public double getDouble() { + if (m_type != NetworkTableType.kDouble) { + throw new ClassCastException("cannot convert " + m_type + " to double"); + } + return ((Number) m_value).doubleValue(); + } + + /** + * Get the String value. + * + * @return The String value. + * @throws ClassCastException if the entry value is not of String type. + */ + public String getString() { + if (m_type != NetworkTableType.kString) { + throw new ClassCastException("cannot convert " + m_type + " to String"); + } + return (String) m_value; + } + + /** + * Get the byte[] value. + * + * @return The byte[] value. + * @throws ClassCastException if the entry value is not of byte[] type. + */ + public byte[] getRaw() { + if (m_type != NetworkTableType.kRaw) { + throw new ClassCastException("cannot convert " + m_type + " to byte[]"); + } + return (byte[]) m_value; + } + + /** + * Get the boolean[] value. + * + * @return The boolean[] value. + * @throws ClassCastException if the entry value is not of boolean[] type. + */ + public boolean[] getBooleanArray() { + if (m_type != NetworkTableType.kBooleanArray) { + throw new ClassCastException("cannot convert " + m_type + " to boolean[]"); + } + return (boolean[]) m_value; + } + + /** + * Get the long[] value. + * + * @return The long[] value. + * @throws ClassCastException if the entry value is not of long[] type. + */ + public long[] getIntegerArray() { + if (m_type != NetworkTableType.kIntegerArray) { + throw new ClassCastException("cannot convert " + m_type + " to long[]"); + } + return (long[]) m_value; + } + + /** + * Get the float[] value. + * + * @return The float[] value. + * @throws ClassCastException if the entry value is not of float[] type. + */ + public float[] getFloatArray() { + if (m_type != NetworkTableType.kFloatArray) { + throw new ClassCastException("cannot convert " + m_type + " to float[]"); + } + return (float[]) m_value; + } + + /** + * Get the double[] value. + * + * @return The double[] value. + * @throws ClassCastException if the entry value is not of double[] type. + */ + public double[] getDoubleArray() { + if (m_type != NetworkTableType.kDoubleArray) { + throw new ClassCastException("cannot convert " + m_type + " to double[]"); + } + return (double[]) m_value; + } + + /** + * Get the String[] value. + * + * @return The String[] value. + * @throws ClassCastException if the entry value is not of String[] type. + */ + public String[] getStringArray() { + if (m_type != NetworkTableType.kStringArray) { + throw new ClassCastException("cannot convert " + m_type + " to String[]"); + } + return (String[]) m_value; + } + + /* + * Factory functions. + */ + + /** + * Creates a boolean value. + * + * @param value the value + * @return The entry value + */ + public static NetworkTableValue makeBoolean(boolean value) { + return new NetworkTableValue(NetworkTableType.kBoolean, Boolean.valueOf(value)); + } + + /** + * Creates a boolean value. + * + * @param value the value + * @param time the creation time to use (instead of the current time) + * @return The entry value + */ + public static NetworkTableValue makeBoolean(boolean value, long time) { + return new NetworkTableValue(NetworkTableType.kBoolean, Boolean.valueOf(value), time); + } + + /** + * Creates a long value. + * + * @param value the value + * @return The entry value + */ + public static NetworkTableValue makeInteger(long value) { + return new NetworkTableValue(NetworkTableType.kInteger, Long.valueOf(value)); + } + + /** + * Creates a long value. + * + * @param value the value + * @param time the creation time to use (instead of the current time) + * @return The entry value + */ + public static NetworkTableValue makeInteger(long value, long time) { + return new NetworkTableValue(NetworkTableType.kInteger, Long.valueOf(value), time); + } + + /** + * Creates a float value. + * + * @param value the value + * @return The entry value + */ + public static NetworkTableValue makeFloat(float value) { + return new NetworkTableValue(NetworkTableType.kFloat, Float.valueOf(value)); + } + + /** + * Creates a float value. + * + * @param value the value + * @param time the creation time to use (instead of the current time) + * @return The entry value + */ + public static NetworkTableValue makeFloat(float value, long time) { + return new NetworkTableValue(NetworkTableType.kFloat, Float.valueOf(value), time); + } + + /** + * Creates a double value. + * + * @param value the value + * @return The entry value + */ + public static NetworkTableValue makeDouble(double value) { + return new NetworkTableValue(NetworkTableType.kDouble, Double.valueOf(value)); + } + + /** + * Creates a double value. + * + * @param value the value + * @param time the creation time to use (instead of the current time) + * @return The entry value + */ + public static NetworkTableValue makeDouble(double value, long time) { + return new NetworkTableValue(NetworkTableType.kDouble, Double.valueOf(value), time); + } + + /** + * Creates a String value. + * + * @param value the value + * @return The entry value + */ + public static NetworkTableValue makeString(String value) { + return new NetworkTableValue(NetworkTableType.kString, (value)); + } + + /** + * Creates a String value. + * + * @param value the value + * @param time the creation time to use (instead of the current time) + * @return The entry value + */ + public static NetworkTableValue makeString(String value, long time) { + return new NetworkTableValue(NetworkTableType.kString, (value), time); + } + + /** + * Creates a byte[] value. + * + * @param value the value + * @return The entry value + */ + public static NetworkTableValue makeRaw(byte[] value) { + return new NetworkTableValue(NetworkTableType.kRaw, (value)); + } + + /** + * Creates a byte[] value. + * + * @param value the value + * @param time the creation time to use (instead of the current time) + * @return The entry value + */ + public static NetworkTableValue makeRaw(byte[] value, long time) { + return new NetworkTableValue(NetworkTableType.kRaw, (value), time); + } + + /** + * Creates a boolean[] value. + * + * @param value the value + * @return The entry value + */ + public static NetworkTableValue makeBooleanArray(boolean[] value) { + return new NetworkTableValue(NetworkTableType.kBooleanArray, (value)); + } + + /** + * Creates a boolean[] value. + * + * @param value the value + * @param time the creation time to use (instead of the current time) + * @return The entry value + */ + public static NetworkTableValue makeBooleanArray(boolean[] value, long time) { + return new NetworkTableValue(NetworkTableType.kBooleanArray, (value), time); + } + + /** + * Creates a boolean[] value. + * + * @param value the value + * @return The entry value + */ + public static NetworkTableValue makeBooleanArray(Boolean[] value) { + return new NetworkTableValue(NetworkTableType.kBooleanArray, toNativeBooleanArray(value)); + } + + /** + * Creates a boolean[] value. + * + * @param value the value + * @param time the creation time to use (instead of the current time) + * @return The entry value + */ + public static NetworkTableValue makeBooleanArray(Boolean[] value, long time) { + return new NetworkTableValue(NetworkTableType.kBooleanArray, toNativeBooleanArray(value), time); + } + + /** + * Creates a long[] value. + * + * @param value the value + * @return The entry value + */ + public static NetworkTableValue makeIntegerArray(long[] value) { + return new NetworkTableValue(NetworkTableType.kIntegerArray, (value)); + } + + /** + * Creates a long[] value. + * + * @param value the value + * @param time the creation time to use (instead of the current time) + * @return The entry value + */ + public static NetworkTableValue makeIntegerArray(long[] value, long time) { + return new NetworkTableValue(NetworkTableType.kIntegerArray, (value), time); + } + + /** + * Creates a long[] value. + * + * @param value the value + * @return The entry value + */ + public static NetworkTableValue makeIntegerArray(Long[] value) { + return new NetworkTableValue(NetworkTableType.kIntegerArray, toNativeIntegerArray(value)); + } + + /** + * Creates a long[] value. + * + * @param value the value + * @param time the creation time to use (instead of the current time) + * @return The entry value + */ + public static NetworkTableValue makeIntegerArray(Long[] value, long time) { + return new NetworkTableValue(NetworkTableType.kIntegerArray, toNativeIntegerArray(value), time); + } + + /** + * Creates a float[] value. + * + * @param value the value + * @return The entry value + */ + public static NetworkTableValue makeFloatArray(float[] value) { + return new NetworkTableValue(NetworkTableType.kFloatArray, (value)); + } + + /** + * Creates a float[] value. + * + * @param value the value + * @param time the creation time to use (instead of the current time) + * @return The entry value + */ + public static NetworkTableValue makeFloatArray(float[] value, long time) { + return new NetworkTableValue(NetworkTableType.kFloatArray, (value), time); + } + + /** + * Creates a float[] value. + * + * @param value the value + * @return The entry value + */ + public static NetworkTableValue makeFloatArray(Float[] value) { + return new NetworkTableValue(NetworkTableType.kFloatArray, toNativeFloatArray(value)); + } + + /** + * Creates a float[] value. + * + * @param value the value + * @param time the creation time to use (instead of the current time) + * @return The entry value + */ + public static NetworkTableValue makeFloatArray(Float[] value, long time) { + return new NetworkTableValue(NetworkTableType.kFloatArray, toNativeFloatArray(value), time); + } + + /** + * Creates a double[] value. + * + * @param value the value + * @return The entry value + */ + public static NetworkTableValue makeDoubleArray(double[] value) { + return new NetworkTableValue(NetworkTableType.kDoubleArray, (value)); + } + + /** + * Creates a double[] value. + * + * @param value the value + * @param time the creation time to use (instead of the current time) + * @return The entry value + */ + public static NetworkTableValue makeDoubleArray(double[] value, long time) { + return new NetworkTableValue(NetworkTableType.kDoubleArray, (value), time); + } + + /** + * Creates a double[] value. + * + * @param value the value + * @return The entry value + */ + public static NetworkTableValue makeDoubleArray(Double[] value) { + return new NetworkTableValue(NetworkTableType.kDoubleArray, toNativeDoubleArray(value)); + } + + /** + * Creates a double[] value. + * + * @param value the value + * @param time the creation time to use (instead of the current time) + * @return The entry value + */ + public static NetworkTableValue makeDoubleArray(Double[] value, long time) { + return new NetworkTableValue(NetworkTableType.kDoubleArray, toNativeDoubleArray(value), time); + } + + /** + * Creates a String[] value. + * + * @param value the value + * @return The entry value + */ + public static NetworkTableValue makeStringArray(String[] value) { + return new NetworkTableValue(NetworkTableType.kStringArray, (value)); + } + + /** + * Creates a String[] value. + * + * @param value the value + * @param time the creation time to use (instead of the current time) + * @return The entry value + */ + public static NetworkTableValue makeStringArray(String[] value, long time) { + return new NetworkTableValue(NetworkTableType.kStringArray, (value), time); + } + + @Override + public boolean equals(Object other) { + if (other == this) { + return true; + } + if (!(other instanceof NetworkTableValue)) { + return false; + } + NetworkTableValue ntOther = (NetworkTableValue) other; + return m_type == ntOther.m_type && m_value.equals(ntOther.m_value); + } + + @Override + public int hashCode() { + return Objects.hash(m_type, m_value); + } + + // arraycopy() doesn't know how to unwrap boxed values; this is a false positive in PMD + // (see https://sourceforge.net/p/pmd/bugs/804/) + @SuppressWarnings("PMD.AvoidArrayLoops") + static boolean[] toNativeBooleanArray(Boolean[] arr) { + boolean[] out = new boolean[arr.length]; + for (int i = 0; i < arr.length; i++) { + out[i] = arr[i]; + } + return out; + } + + @SuppressWarnings("PMD.AvoidArrayLoops") + static double[] toNativeDoubleArray(Number[] arr) { + double[] out = new double[arr.length]; + for (int i = 0; i < arr.length; i++) { + out[i] = arr[i].doubleValue(); + } + return out; + } + + @SuppressWarnings("PMD.AvoidArrayLoops") + static long[] toNativeIntegerArray(Number[] arr) { + long[] out = new long[arr.length]; + for (int i = 0; i < arr.length; i++) { + out[i] = arr[i].longValue(); + } + return out; + } + + @SuppressWarnings("PMD.AvoidArrayLoops") + static float[] toNativeFloatArray(Number[] arr) { + float[] out = new float[arr.length]; + for (int i = 0; i < arr.length; i++) { + out[i] = arr[i].floatValue(); + } + return out; + } + + @SuppressWarnings("PMD.AvoidArrayLoops") + static Boolean[] fromNativeBooleanArray(boolean[] arr) { + Boolean[] out = new Boolean[arr.length]; + for (int i = 0; i < arr.length; i++) { + out[i] = arr[i]; + } + return out; + } + + @SuppressWarnings("PMD.AvoidArrayLoops") + static Long[] fromNativeIntegerArray(long[] arr) { + Long[] out = new Long[arr.length]; + for (int i = 0; i < arr.length; i++) { + out[i] = arr[i]; + } + return out; + } + + @SuppressWarnings("PMD.AvoidArrayLoops") + static Float[] fromNativeFloatArray(float[] arr) { + Float[] out = new Float[arr.length]; + for (int i = 0; i < arr.length; i++) { + out[i] = arr[i]; + } + return out; + } + + @SuppressWarnings("PMD.AvoidArrayLoops") + static Double[] fromNativeDoubleArray(double[] arr) { + Double[] out = new Double[arr.length]; + for (int i = 0; i < arr.length; i++) { + out[i] = arr[i]; + } + return out; + } + + private NetworkTableType m_type; + private Object m_value; + private long m_time; + private long m_serverTime; +} 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 new file mode 100644 index 0000000000..0f6ae2cfda --- /dev/null +++ b/ntcore/src/generated/main/java/edu/wpi/first/networktables/NetworkTablesJNI.java @@ -0,0 +1,493 @@ +// 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. + +// THIS FILE WAS AUTO-GENERATED BY ./ntcore/generate_topics.py. DO NOT MODIFY + +package edu.wpi.first.networktables; + +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; +import java.util.OptionalLong; +import java.util.concurrent.atomic.AtomicBoolean; + +public final class NetworkTablesJNI { + static boolean libraryLoaded = false; + static RuntimeLoader loader = null; + + public static class Helper { + private static AtomicBoolean extractOnStaticLoad = new AtomicBoolean(true); + + public static boolean getExtractOnStaticLoad() { + return extractOnStaticLoad.get(); + } + + public static void setExtractOnStaticLoad(boolean load) { + extractOnStaticLoad.set(load); + } + } + + static { + if (Helper.getExtractOnStaticLoad()) { + try { + loader = + new RuntimeLoader<>( + "ntcorejni", RuntimeLoader.getDefaultExtractionRoot(), NetworkTablesJNI.class); + loader.loadLibrary(); + } catch (IOException ex) { + ex.printStackTrace(); + System.exit(1); + } + libraryLoaded = true; + } + } + + /** + * Force load the library. + * + * @throws IOException if the library fails to load + */ + public static synchronized void forceLoad() throws IOException { + if (libraryLoaded) { + return; + } + loader = + new RuntimeLoader<>( + "ntcorejni", RuntimeLoader.getDefaultExtractionRoot(), NetworkTablesJNI.class); + loader.loadLibrary(); + libraryLoaded = true; + } + + private static PubSubOptions buildOptions(PubSubOption... options) { + if (options.length == 0) { + return null; // optimize common case (JNI checks for null) + } + return new PubSubOptions(options); + } + + public static native int getDefaultInstance(); + + public static native int createInstance(); + + public static native void destroyInstance(int inst); + + public static native int getInstanceFromHandle(int handle); + + private static native int getEntryImpl( + int topic, int type, String typeStr, PubSubOptions options); + + public static native int getEntry(int inst, String key); + + public static int getEntry( + int topic, int type, String typeStr, PubSubOptions options) { + return getEntryImpl(topic, type, typeStr, options); + } + + public static int getEntry( + int topic, int type, String typeStr, PubSubOption... options) { + return getEntryImpl(topic, type, typeStr, buildOptions(options)); + } + + public static native String getEntryName(int entry); + + public static native long getEntryLastChange(int entry); + + public static native int getType(int entry); + + /* Topic functions */ + + public static native int[] getTopics(int inst, String prefix, int types); + + public static native int[] getTopicsStr(int inst, String prefix, String[] types); + + public static native TopicInfo[] getTopicInfos( + NetworkTableInstance instObject, int inst, String prefix, int types); + + public static native TopicInfo[] getTopicInfosStr( + NetworkTableInstance instObject, int inst, String prefix, String[] types); + + public static native int getTopic(int inst, String name); + + public static native String getTopicName(int topic); + + public static native int getTopicType(int topic); + + public static native void setTopicPersistent(int topic, boolean value); + + public static native boolean getTopicPersistent(int topic); + + public static native void setTopicRetained(int topic, boolean value); + + public static native boolean getTopicRetained(int topic); + + public static native String getTopicTypeString(int topic); + + public static native boolean getTopicExists(int topic); + + public static native String getTopicProperty(int topic, String name); + + public static native void setTopicProperty(int topic, String name, String value); + + public static native void deleteTopicProperty(int topic, String name); + + public static native String getTopicProperties(int topic); + + public static native void setTopicProperties(int topic, String properties); + + public static native int subscribe( + int topic, int type, String typeStr, PubSubOptions options); + + public static int subscribe( + int topic, int type, String typeStr, PubSubOption... options) { + return subscribe(topic, type, typeStr, buildOptions(options)); + } + + public static native void unsubscribe(int sub); + + public static native int publish( + int topic, int type, String typeStr, PubSubOptions options); + + public static int publish( + int topic, int type, String typeStr, PubSubOption... options) { + return publish(topic, type, typeStr, buildOptions(options)); + } + + public static native int publishEx( + int topic, int type, String typeStr, String properties, PubSubOptions options); + + public static int publishEx( + int topic, int type, String typeStr, String properties, PubSubOption... options) { + return publishEx(topic, type, typeStr, properties, buildOptions(options)); + } + + public static native void unpublish(int pubentry); + + public static native void releaseEntry(int entry); + + public static native void release(int pubsubentry); + + public static native int getTopicFromHandle(int pubsubentry); + + public static native int subscribeMultiple(int inst, String[] prefixes, PubSubOptions options); + + public static int subscribeMultiple(int inst, String[] prefixes, PubSubOption... options) { + return subscribeMultiple(inst, prefixes, buildOptions(options)); + } + + public static native void unsubscribeMultiple(int sub); + + public static native TimestampedBoolean getAtomicBoolean( + int subentry, boolean defaultValue); + + public static native TimestampedBoolean[] readQueueBoolean(int subentry); + + public static native boolean[] readQueueValuesBoolean(int subentry); + + public static native boolean setBoolean(int entry, long time, boolean value); + + public static native boolean getBoolean(int entry, boolean defaultValue); + + public static native boolean setDefaultBoolean(int entry, long time, boolean defaultValue); + + + public static native TimestampedInteger getAtomicInteger( + int subentry, long defaultValue); + + public static native TimestampedInteger[] readQueueInteger(int subentry); + + public static native long[] readQueueValuesInteger(int subentry); + + public static native boolean setInteger(int entry, long time, long value); + + public static native long getInteger(int entry, long defaultValue); + + public static native boolean setDefaultInteger(int entry, long time, long defaultValue); + + + public static native TimestampedFloat getAtomicFloat( + int subentry, float defaultValue); + + public static native TimestampedFloat[] readQueueFloat(int subentry); + + public static native float[] readQueueValuesFloat(int subentry); + + public static native boolean setFloat(int entry, long time, float value); + + public static native float getFloat(int entry, float defaultValue); + + public static native boolean setDefaultFloat(int entry, long time, float defaultValue); + + + public static native TimestampedDouble getAtomicDouble( + int subentry, double defaultValue); + + public static native TimestampedDouble[] readQueueDouble(int subentry); + + public static native double[] readQueueValuesDouble(int subentry); + + public static native boolean setDouble(int entry, long time, double value); + + public static native double getDouble(int entry, double defaultValue); + + public static native boolean setDefaultDouble(int entry, long time, double defaultValue); + + + public static native TimestampedString getAtomicString( + int subentry, String defaultValue); + + public static native TimestampedString[] readQueueString(int subentry); + + public static native String[] readQueueValuesString(int subentry); + + public static native boolean setString(int entry, long time, String value); + + public static native String getString(int entry, String defaultValue); + + public static native boolean setDefaultString(int entry, long time, String defaultValue); + + + public static native TimestampedRaw getAtomicRaw( + int subentry, byte[] defaultValue); + + public static native TimestampedRaw[] readQueueRaw(int subentry); + + public static native byte[][] readQueueValuesRaw(int subentry); + + public static boolean setRaw(int entry, long time, byte[] value) { + return setRaw(entry, time, value, 0, value.length); + } + + public static native boolean setRaw(int entry, long time, byte[] value, int start, int len); + + public static boolean setRaw(int entry, long time, ByteBuffer value) { + int pos = value.position(); + return setRaw(entry, time, value, pos, value.capacity() - pos); + } + + public static boolean setRaw(int entry, long time, ByteBuffer value, int start, int len) { + if (value.isDirect()) { + if (start < 0) { + throw new IndexOutOfBoundsException("start must be >= 0"); + } + if (len < 0) { + throw new IndexOutOfBoundsException("len must be >= 0"); + } + if ((start + len) > value.capacity()) { + throw new IndexOutOfBoundsException("start + len must be smaller than buffer capacity"); + } + return setRawBuffer(entry, time, value, start, len); + } else if (value.hasArray()) { + return setRaw(entry, time, value.array(), value.arrayOffset() + start, len); + } else { + throw new UnsupportedOperationException("ByteBuffer must be direct or have a backing array"); + } + } + + private static native boolean setRawBuffer(int entry, long time, ByteBuffer value, int start, int len); + + public static native byte[] getRaw(int entry, byte[] defaultValue); + + public static boolean setDefaultRaw(int entry, long time, byte[] defaultValue) { + return setDefaultRaw(entry, time, defaultValue, 0, defaultValue.length); + } + + public static native boolean setDefaultRaw(int entry, long time, byte[] defaultValue, int start, int len); + + public static boolean setDefaultRaw(int entry, long time, ByteBuffer defaultValue) { + int pos = defaultValue.position(); + return setDefaultRaw(entry, time, defaultValue, pos, defaultValue.limit() - pos); + } + + public static boolean setDefaultRaw(int entry, long time, ByteBuffer defaultValue, int start, int len) { + if (defaultValue.isDirect()) { + if (start < 0) { + throw new IndexOutOfBoundsException("start must be >= 0"); + } + if (len < 0) { + throw new IndexOutOfBoundsException("len must be >= 0"); + } + if ((start + len) > defaultValue.capacity()) { + throw new IndexOutOfBoundsException("start + len must be smaller than buffer capacity"); + } + return setDefaultRawBuffer(entry, time, defaultValue, start, len); + } else if (defaultValue.hasArray()) { + return setDefaultRaw(entry, time, defaultValue.array(), defaultValue.arrayOffset() + start, len); + } else { + throw new UnsupportedOperationException("ByteBuffer must be direct or have a backing array"); + } + } + + private static native boolean setDefaultRawBuffer(int entry, long time, ByteBuffer defaultValue, int start, int len); + + + public static native TimestampedBooleanArray getAtomicBooleanArray( + int subentry, boolean[] defaultValue); + + public static native TimestampedBooleanArray[] readQueueBooleanArray(int subentry); + + public static native boolean[][] readQueueValuesBooleanArray(int subentry); + + public static native boolean setBooleanArray(int entry, long time, boolean[] value); + + public static native boolean[] getBooleanArray(int entry, boolean[] defaultValue); + + public static native boolean setDefaultBooleanArray(int entry, long time, boolean[] defaultValue); + + + public static native TimestampedIntegerArray getAtomicIntegerArray( + int subentry, long[] defaultValue); + + public static native TimestampedIntegerArray[] readQueueIntegerArray(int subentry); + + public static native long[][] readQueueValuesIntegerArray(int subentry); + + public static native boolean setIntegerArray(int entry, long time, long[] value); + + public static native long[] getIntegerArray(int entry, long[] defaultValue); + + public static native boolean setDefaultIntegerArray(int entry, long time, long[] defaultValue); + + + public static native TimestampedFloatArray getAtomicFloatArray( + int subentry, float[] defaultValue); + + public static native TimestampedFloatArray[] readQueueFloatArray(int subentry); + + public static native float[][] readQueueValuesFloatArray(int subentry); + + public static native boolean setFloatArray(int entry, long time, float[] value); + + public static native float[] getFloatArray(int entry, float[] defaultValue); + + public static native boolean setDefaultFloatArray(int entry, long time, float[] defaultValue); + + + public static native TimestampedDoubleArray getAtomicDoubleArray( + int subentry, double[] defaultValue); + + public static native TimestampedDoubleArray[] readQueueDoubleArray(int subentry); + + public static native double[][] readQueueValuesDoubleArray(int subentry); + + public static native boolean setDoubleArray(int entry, long time, double[] value); + + public static native double[] getDoubleArray(int entry, double[] defaultValue); + + public static native boolean setDefaultDoubleArray(int entry, long time, double[] defaultValue); + + + public static native TimestampedStringArray getAtomicStringArray( + int subentry, String[] defaultValue); + + public static native TimestampedStringArray[] readQueueStringArray(int subentry); + + public static native String[][] readQueueValuesStringArray(int subentry); + + public static native boolean setStringArray(int entry, long time, String[] value); + + public static native String[] getStringArray(int entry, String[] defaultValue); + + public static native boolean setDefaultStringArray(int entry, long time, String[] defaultValue); + + + public static native NetworkTableValue[] readQueueValue(int subentry); + + public static native NetworkTableValue getValue(int entry); + + public static native void setEntryFlags(int entry, int flags); + + public static native int getEntryFlags(int entry); + + public static native TopicInfo getTopicInfo(NetworkTableInstance inst, int topic); + + public static native int createListenerPoller(int inst); + + public static native void destroyListenerPoller(int poller); + + private static int kindsToMask(EnumSet kinds) { + int mask = 0; + for (NetworkTableEvent.Kind kind : kinds) { + mask |= kind.getValue(); + } + return mask; + } + + public static int addListener(int poller, String[] prefixes, EnumSet kinds) { + return addListener(poller, prefixes, kindsToMask(kinds)); + } + + public static int addListener(int poller, int handle, EnumSet kinds) { + return addListener(poller, handle, kindsToMask(kinds)); + } + + public static native int addListener(int poller, String[] prefixes, int mask); + + public static native int addListener(int poller, int handle, int mask); + + public static native NetworkTableEvent[] readListenerQueue( + NetworkTableInstance inst, int poller); + + public static native void removeListener(int listener); + + public static native int getNetworkMode(int inst); + + public static native void startLocal(int inst); + + public static native void stopLocal(int inst); + + public static native void startServer( + int inst, String persistFilename, String listenAddress, int port3, int port4); + + public static native void stopServer(int inst); + + public static native void startClient3(int inst, String identity); + + public static native void startClient4(int inst, String identity); + + public static native void stopClient(int inst); + + public static native void setServer(int inst, String serverName, int port); + + public static native void setServer(int inst, String[] serverNames, int[] ports); + + public static native void setServerTeam(int inst, int team, int port); + + public static native void disconnect(int inst); + + public static native void startDSClient(int inst, int port); + + public static native void stopDSClient(int inst); + + public static native void flushLocal(int inst); + + public static native void flush(int inst); + + public static native ConnectionInfo[] getConnections(int inst); + + public static native boolean isConnected(int inst); + + public static native OptionalLong getServerTimeOffset(int inst); + + public static native long now(); + + private static native int startEntryDataLog(int inst, long log, String prefix, String logPrefix); + + public static int startEntryDataLog(int inst, DataLog log, String prefix, String logPrefix) { + return startEntryDataLog(inst, log.getImpl(), prefix, logPrefix); + } + + public static native void stopEntryDataLog(int logger); + + private static native int startConnectionDataLog(int inst, long log, String name); + + public static int startConnectionDataLog(int inst, DataLog log, String name) { + return startConnectionDataLog(inst, log.getImpl(), name); + } + + public static native void stopConnectionDataLog(int logger); + + public static native int addLogger(int poller, int minLevel, int maxLevel); +} diff --git a/ntcore/src/generated/main/java/edu/wpi/first/networktables/RawEntry.java b/ntcore/src/generated/main/java/edu/wpi/first/networktables/RawEntry.java new file mode 100644 index 0000000000..407cdd55ad --- /dev/null +++ b/ntcore/src/generated/main/java/edu/wpi/first/networktables/RawEntry.java @@ -0,0 +1,17 @@ +// 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. + +// THIS FILE WAS AUTO-GENERATED BY ./ntcore/generate_topics.py. DO NOT MODIFY + +package edu.wpi.first.networktables; + +/** + * NetworkTables Raw entry. + * + *

Unlike NetworkTableEntry, the entry goes away when close() is called. + */ +public interface RawEntry extends RawSubscriber, RawPublisher { + /** Stops publishing the entry if it's published. */ + void unpublish(); +} diff --git a/ntcore/src/generated/main/java/edu/wpi/first/networktables/RawEntryImpl.java b/ntcore/src/generated/main/java/edu/wpi/first/networktables/RawEntryImpl.java new file mode 100644 index 0000000000..55767f73ea --- /dev/null +++ b/ntcore/src/generated/main/java/edu/wpi/first/networktables/RawEntryImpl.java @@ -0,0 +1,89 @@ +// 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. + +// THIS FILE WAS AUTO-GENERATED BY ./ntcore/generate_topics.py. DO NOT MODIFY + +package edu.wpi.first.networktables; + +import java.nio.ByteBuffer; + +/** NetworkTables Raw implementation. */ +@SuppressWarnings("PMD.ArrayIsStoredDirectly") +final class RawEntryImpl extends EntryBase implements RawEntry { + /** + * Constructor. + * + * @param topic Topic + * @param handle Native handle + * @param defaultValue Default value for get() + */ + RawEntryImpl(RawTopic topic, int handle, byte[] defaultValue) { + super(handle); + m_topic = topic; + m_defaultValue = defaultValue; + } + + @Override + public RawTopic getTopic() { + return m_topic; + } + + @Override + public byte[] get() { + return NetworkTablesJNI.getRaw(m_handle, m_defaultValue); + } + + @Override + public byte[] get(byte[] defaultValue) { + return NetworkTablesJNI.getRaw(m_handle, defaultValue); + } + + @Override + public TimestampedRaw getAtomic() { + return NetworkTablesJNI.getAtomicRaw(m_handle, m_defaultValue); + } + + @Override + public TimestampedRaw getAtomic(byte[] defaultValue) { + return NetworkTablesJNI.getAtomicRaw(m_handle, defaultValue); + } + + @Override + public TimestampedRaw[] readQueue() { + return NetworkTablesJNI.readQueueRaw(m_handle); + } + + @Override + public byte[][] readQueueValues() { + return NetworkTablesJNI.readQueueValuesRaw(m_handle); + } + + @Override + public void set(byte[] value, int start, int len, long time) { + NetworkTablesJNI.setRaw(m_handle, time, value, start, len); + } + + @Override + public void set(ByteBuffer value, int start, int len, long time) { + NetworkTablesJNI.setRaw(m_handle, time, value, start, len); + } + + @Override + public void setDefault(byte[] value, int start, int len) { + NetworkTablesJNI.setDefaultRaw(m_handle, 0, value, start, len); + } + + @Override + public void setDefault(ByteBuffer value, int start, int len) { + NetworkTablesJNI.setDefaultRaw(m_handle, 0, value, start, len); + } + + @Override + public void unpublish() { + NetworkTablesJNI.unpublish(m_handle); + } + + private final RawTopic m_topic; + private final byte[] m_defaultValue; +} diff --git a/ntcore/src/generated/main/java/edu/wpi/first/networktables/RawPublisher.java b/ntcore/src/generated/main/java/edu/wpi/first/networktables/RawPublisher.java new file mode 100644 index 0000000000..0cd578e507 --- /dev/null +++ b/ntcore/src/generated/main/java/edu/wpi/first/networktables/RawPublisher.java @@ -0,0 +1,154 @@ +// 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. + +// THIS FILE WAS AUTO-GENERATED BY ./ntcore/generate_topics.py. DO NOT MODIFY + +package edu.wpi.first.networktables; + + +import java.nio.ByteBuffer; +import java.util.function.Consumer; + +/** NetworkTables Raw publisher. */ +public interface RawPublisher extends Publisher, Consumer { + /** + * Get the corresponding topic. + * + * @return Topic + */ + @Override + RawTopic getTopic(); + + /** + * Publish a new value using current NT time. + * + * @param value value to publish + */ + default void set(byte[] value) { + set(value, 0); + } + + + /** + * Publish a new value. + * + * @param value value to publish + * @param time timestamp; 0 indicates current NT time should be used + */ + default void set(byte[] value, long time) { + set(value, 0, value.length, time); + } + + /** + * Publish a new value using current NT time. + * + * @param value value to publish + * @param start Start position of data (in buffer) + * @param len Length of data (must be less than or equal to value.length - start) + */ + default void set(byte[] value, int start, int len) { + set(value, start, len, 0); + } + + /** + * Publish a new value. + * + * @param value value to publish + * @param start Start position of data (in buffer) + * @param len Length of data (must be less than or equal to value.length - start) + * @param time timestamp; 0 indicates current NT time should be used + */ + void set(byte[] value, int start, int len, long time); + + /** + * Publish a new value using current NT time. + * + * @param value value to publish; will send from value.position() to value.limit() + */ + default void set(ByteBuffer value) { + set(value, 0); + } + + /** + * Publish a new value. + * + * @param value value to publish; will send from value.position() to value.limit() + * @param time timestamp; 0 indicates current NT time should be used + */ + default void set(ByteBuffer value, long time) { + int pos = value.position(); + set(value, pos, value.limit() - pos, time); + } + + /** + * Publish a new value using current NT time. + * + * @param value value to publish + * @param start Start position of data (in buffer) + * @param len Length of data (must be less than or equal to value.capacity() - start) + */ + default void set(ByteBuffer value, int start, int len) { + set(value, start, len, 0); + } + + /** + * Publish a new value. + * + * @param value value to publish + * @param start Start position of data (in buffer) + * @param len Length of data (must be less than or equal to value.capacity() - start) + * @param time timestamp; 0 indicates current NT time should be used + */ + void set(ByteBuffer value, int start, int len, long time); + + /** + * Publish a default value. + * On reconnect, a default value will never be used in preference to a + * published value. + * + * @param value value + */ + default void setDefault(byte[] value) { + setDefault(value, 0, value.length); + } + + /** + * Publish a default value. + * On reconnect, a default value will never be used in preference to a + * published value. + * + * @param value value + * @param start Start position of data (in buffer) + * @param len Length of data (must be less than or equal to value.length - start) + */ + void setDefault(byte[] value, int start, int len); + + /** + * Publish a default value. + * On reconnect, a default value will never be used in preference to a + * published value. + * + * @param value value; will send from value.position() to value.limit() + */ + default void setDefault(ByteBuffer value) { + int pos = value.position(); + setDefault(value, pos, value.limit() - pos); + } + + /** + * Publish a default value. + * On reconnect, a default value will never be used in preference to a + * published value. + * + * @param value value + * @param start Start position of data (in buffer) + * @param len Length of data (must be less than or equal to value.capacity() - start) + */ + void setDefault(ByteBuffer value, int start, int len); + + @Override + default void accept(byte[] value) { + set(value); + } +} diff --git a/ntcore/src/generated/main/java/edu/wpi/first/networktables/RawSubscriber.java b/ntcore/src/generated/main/java/edu/wpi/first/networktables/RawSubscriber.java new file mode 100644 index 0000000000..089d999dc2 --- /dev/null +++ b/ntcore/src/generated/main/java/edu/wpi/first/networktables/RawSubscriber.java @@ -0,0 +1,80 @@ +// 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. + +// THIS FILE WAS AUTO-GENERATED BY ./ntcore/generate_topics.py. DO NOT MODIFY + +package edu.wpi.first.networktables; + +import java.util.function.Supplier; + +/** NetworkTables Raw subscriber. */ +@SuppressWarnings("PMD.MissingOverride") +public interface RawSubscriber extends Subscriber, Supplier { + /** + * Get the corresponding topic. + * + * @return Topic + */ + @Override + RawTopic getTopic(); + + /** + * Get the last published value. + * If no value has been published, returns the stored default value. + * + * @return value + */ + byte[] get(); + + /** + * Get the last published value. + * If no value has been published, returns the passed defaultValue. + * + * @param defaultValue default value to return if no value has been published + * @return value + */ + byte[] get(byte[] defaultValue); + + /** + * Get the last published value along with its timestamp + * If no value has been published, returns the stored default value and a + * timestamp of 0. + * + * @return timestamped value + */ + TimestampedRaw getAtomic(); + + /** + * Get the last published value along with its timestamp + * If no value has been published, returns the passed defaultValue and a + * timestamp of 0. + * + * @param defaultValue default value to return if no value has been published + * @return timestamped value + */ + TimestampedRaw getAtomic(byte[] defaultValue); + + /** + * Get an array of all value changes since the last call to readQueue. + * Also provides a timestamp for each value. + * + *

The "poll storage" subscribe option can be used to set the queue + * depth. + * + * @return Array of timestamped values; empty array if no new changes have + * been published since the previous call. + */ + TimestampedRaw[] readQueue(); + + /** + * Get an array of all value changes since the last call to readQueue. + * + *

The "poll storage" subscribe option can be used to set the queue + * depth. + * + * @return Array of values; empty array if no new changes have been + * published since the previous call. + */ + byte[][] readQueueValues(); +} diff --git a/ntcore/src/generated/main/java/edu/wpi/first/networktables/RawTopic.java b/ntcore/src/generated/main/java/edu/wpi/first/networktables/RawTopic.java new file mode 100644 index 0000000000..173a88b3ce --- /dev/null +++ b/ntcore/src/generated/main/java/edu/wpi/first/networktables/RawTopic.java @@ -0,0 +1,154 @@ +// 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. + +// THIS FILE WAS AUTO-GENERATED BY ./ntcore/generate_topics.py. DO NOT MODIFY + +package edu.wpi.first.networktables; + +/** NetworkTables Raw topic. */ +public final class RawTopic extends Topic { + /** + * Construct from a generic topic. + * + * @param topic Topic + */ + public RawTopic(Topic topic) { + super(topic.m_inst, topic.m_handle); + } + + /** + * Constructor; use NetworkTableInstance.getRawTopic() instead. + * + * @param inst Instance + * @param handle Native handle + */ + public RawTopic(NetworkTableInstance inst, int handle) { + super(inst, handle); + } + + /** + * Create a new subscriber to the topic. + * + *

The subscriber is only active as long as the returned object + * is not closed. + * + *

Subscribers that do not match the published data type do not return + * any values. To determine if the data type matches, use the appropriate + * Topic functions. + * + * @param typeString type string + + * @param defaultValue default value used when a default is not provided to a + * getter function + * @param options subscribe options + * @return subscriber + */ + public RawSubscriber subscribe( + String typeString, + + byte[] defaultValue, + PubSubOption... options) { + return new RawEntryImpl( + this, + NetworkTablesJNI.subscribe( + m_handle, NetworkTableType.kRaw.getValue(), + typeString, options), + defaultValue); + } + + /** + * Create a new publisher to the topic. + * + *

The publisher is only active as long as the returned object + * is not closed. + * + *

It is not possible to publish two different data types to the same + * topic. Conflicts between publishers are typically resolved by the server on + * a first-come, first-served basis. Any published values that do not match + * the topic's data type are dropped (ignored). To determine if the data type + * matches, use the appropriate Topic functions. + * + * @param typeString type string + + * @param options publish options + * @return publisher + */ + public RawPublisher publish( + String typeString, + + PubSubOption... options) { + return new RawEntryImpl( + this, + NetworkTablesJNI.publish( + m_handle, NetworkTableType.kRaw.getValue(), + typeString, options), + new byte[] {}); + } + + /** + * Create a new publisher to the topic, with type string and initial properties. + * + *

The publisher is only active as long as the returned object + * is not closed. + * + *

It is not possible to publish two different data types to the same + * topic. Conflicts between publishers are typically resolved by the server on + * a first-come, first-served basis. Any published values that do not match + * the topic's data type are dropped (ignored). To determine if the data type + * matches, use the appropriate Topic functions. + * + * @param typeString type string + * @param properties JSON properties + * @param options publish options + * @return publisher + * @throws IllegalArgumentException if properties is not a JSON object + */ + public RawPublisher publishEx( + String typeString, + String properties, + PubSubOption... options) { + return new RawEntryImpl( + this, + NetworkTablesJNI.publishEx( + m_handle, NetworkTableType.kRaw.getValue(), + typeString, properties, options), + new byte[] {}); + } + + /** + * Create a new entry for the topic. + * + *

Entries act as a combination of a subscriber and a weak publisher. The + * subscriber is active as long as the entry is not closed. The publisher is + * created when the entry is first written to, and remains active until either + * unpublish() is called or the entry is closed. + * + *

It is not possible to use two different data types with the same + * topic. Conflicts between publishers are typically resolved by the server on + * a first-come, first-served basis. Any published values that do not match + * the topic's data type are dropped (ignored), and the entry will show no new + * values if the data type does not match. To determine if the data type + * matches, use the appropriate Topic functions. + * + * @param typeString type string + + * @param defaultValue default value used when a default is not provided to a + * getter function + * @param options publish and/or subscribe options + * @return entry + */ + public RawEntry getEntry( + String typeString, + + byte[] defaultValue, + PubSubOption... options) { + return new RawEntryImpl( + this, + NetworkTablesJNI.getEntry( + m_handle, NetworkTableType.kRaw.getValue(), + typeString, options), + defaultValue); + } + +} diff --git a/ntcore/src/generated/main/java/edu/wpi/first/networktables/StringArrayEntry.java b/ntcore/src/generated/main/java/edu/wpi/first/networktables/StringArrayEntry.java new file mode 100644 index 0000000000..9169e9071b --- /dev/null +++ b/ntcore/src/generated/main/java/edu/wpi/first/networktables/StringArrayEntry.java @@ -0,0 +1,17 @@ +// 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. + +// THIS FILE WAS AUTO-GENERATED BY ./ntcore/generate_topics.py. DO NOT MODIFY + +package edu.wpi.first.networktables; + +/** + * NetworkTables StringArray entry. + * + *

Unlike NetworkTableEntry, the entry goes away when close() is called. + */ +public interface StringArrayEntry extends StringArraySubscriber, StringArrayPublisher { + /** Stops publishing the entry if it's published. */ + void unpublish(); +} diff --git a/ntcore/src/generated/main/java/edu/wpi/first/networktables/StringArrayEntryImpl.java b/ntcore/src/generated/main/java/edu/wpi/first/networktables/StringArrayEntryImpl.java new file mode 100644 index 0000000000..536db7b8ac --- /dev/null +++ b/ntcore/src/generated/main/java/edu/wpi/first/networktables/StringArrayEntryImpl.java @@ -0,0 +1,77 @@ +// 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. + +// THIS FILE WAS AUTO-GENERATED BY ./ntcore/generate_topics.py. DO NOT MODIFY + +package edu.wpi.first.networktables; + +/** NetworkTables StringArray implementation. */ +@SuppressWarnings("PMD.ArrayIsStoredDirectly") +final class StringArrayEntryImpl extends EntryBase implements StringArrayEntry { + /** + * Constructor. + * + * @param topic Topic + * @param handle Native handle + * @param defaultValue Default value for get() + */ + StringArrayEntryImpl(StringArrayTopic topic, int handle, String[] defaultValue) { + super(handle); + m_topic = topic; + m_defaultValue = defaultValue; + } + + @Override + public StringArrayTopic getTopic() { + return m_topic; + } + + @Override + public String[] get() { + return NetworkTablesJNI.getStringArray(m_handle, m_defaultValue); + } + + @Override + public String[] get(String[] defaultValue) { + return NetworkTablesJNI.getStringArray(m_handle, defaultValue); + } + + @Override + public TimestampedStringArray getAtomic() { + return NetworkTablesJNI.getAtomicStringArray(m_handle, m_defaultValue); + } + + @Override + public TimestampedStringArray getAtomic(String[] defaultValue) { + return NetworkTablesJNI.getAtomicStringArray(m_handle, defaultValue); + } + + @Override + public TimestampedStringArray[] readQueue() { + return NetworkTablesJNI.readQueueStringArray(m_handle); + } + + @Override + public String[][] readQueueValues() { + return NetworkTablesJNI.readQueueValuesStringArray(m_handle); + } + + @Override + public void set(String[] value, long time) { + NetworkTablesJNI.setStringArray(m_handle, time, value); + } + + @Override + public void setDefault(String[] value) { + NetworkTablesJNI.setDefaultStringArray(m_handle, 0, value); + } + + @Override + public void unpublish() { + NetworkTablesJNI.unpublish(m_handle); + } + + private final StringArrayTopic m_topic; + private final String[] m_defaultValue; +} diff --git a/ntcore/src/generated/main/java/edu/wpi/first/networktables/StringArrayPublisher.java b/ntcore/src/generated/main/java/edu/wpi/first/networktables/StringArrayPublisher.java new file mode 100644 index 0000000000..d32350c92b --- /dev/null +++ b/ntcore/src/generated/main/java/edu/wpi/first/networktables/StringArrayPublisher.java @@ -0,0 +1,52 @@ +// 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. + +// THIS FILE WAS AUTO-GENERATED BY ./ntcore/generate_topics.py. DO NOT MODIFY + +package edu.wpi.first.networktables; + +import java.util.function.Consumer; + +/** NetworkTables StringArray publisher. */ +public interface StringArrayPublisher extends Publisher, Consumer { + /** + * Get the corresponding topic. + * + * @return Topic + */ + @Override + StringArrayTopic getTopic(); + + /** + * Publish a new value using current NT time. + * + * @param value value to publish + */ + default void set(String[] value) { + set(value, 0); + } + + + /** + * Publish a new value. + * + * @param value value to publish + * @param time timestamp; 0 indicates current NT time should be used + */ + void set(String[] value, long time); + + /** + * Publish a default value. + * On reconnect, a default value will never be used in preference to a + * published value. + * + * @param value value + */ + void setDefault(String[] value); + + @Override + default void accept(String[] value) { + set(value); + } +} diff --git a/ntcore/src/generated/main/java/edu/wpi/first/networktables/StringArraySubscriber.java b/ntcore/src/generated/main/java/edu/wpi/first/networktables/StringArraySubscriber.java new file mode 100644 index 0000000000..62a05759bf --- /dev/null +++ b/ntcore/src/generated/main/java/edu/wpi/first/networktables/StringArraySubscriber.java @@ -0,0 +1,80 @@ +// 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. + +// THIS FILE WAS AUTO-GENERATED BY ./ntcore/generate_topics.py. DO NOT MODIFY + +package edu.wpi.first.networktables; + +import java.util.function.Supplier; + +/** NetworkTables StringArray subscriber. */ +@SuppressWarnings("PMD.MissingOverride") +public interface StringArraySubscriber extends Subscriber, Supplier { + /** + * Get the corresponding topic. + * + * @return Topic + */ + @Override + StringArrayTopic getTopic(); + + /** + * Get the last published value. + * If no value has been published, returns the stored default value. + * + * @return value + */ + String[] get(); + + /** + * Get the last published value. + * If no value has been published, returns the passed defaultValue. + * + * @param defaultValue default value to return if no value has been published + * @return value + */ + String[] get(String[] defaultValue); + + /** + * Get the last published value along with its timestamp + * If no value has been published, returns the stored default value and a + * timestamp of 0. + * + * @return timestamped value + */ + TimestampedStringArray getAtomic(); + + /** + * Get the last published value along with its timestamp + * If no value has been published, returns the passed defaultValue and a + * timestamp of 0. + * + * @param defaultValue default value to return if no value has been published + * @return timestamped value + */ + TimestampedStringArray getAtomic(String[] defaultValue); + + /** + * Get an array of all value changes since the last call to readQueue. + * Also provides a timestamp for each value. + * + *

The "poll storage" subscribe option can be used to set the queue + * depth. + * + * @return Array of timestamped values; empty array if no new changes have + * been published since the previous call. + */ + TimestampedStringArray[] readQueue(); + + /** + * Get an array of all value changes since the last call to readQueue. + * + *

The "poll storage" subscribe option can be used to set the queue + * depth. + * + * @return Array of values; empty array if no new changes have been + * published since the previous call. + */ + String[][] readQueueValues(); +} diff --git a/ntcore/src/generated/main/java/edu/wpi/first/networktables/StringArrayTopic.java b/ntcore/src/generated/main/java/edu/wpi/first/networktables/StringArrayTopic.java new file mode 100644 index 0000000000..bde93c08f4 --- /dev/null +++ b/ntcore/src/generated/main/java/edu/wpi/first/networktables/StringArrayTopic.java @@ -0,0 +1,206 @@ +// 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. + +// THIS FILE WAS AUTO-GENERATED BY ./ntcore/generate_topics.py. DO NOT MODIFY + +package edu.wpi.first.networktables; + +/** NetworkTables StringArray topic. */ +public final class StringArrayTopic extends Topic { + /** The default type string for this topic type. */ + public static final String kTypeString = "string[]"; + + /** + * Construct from a generic topic. + * + * @param topic Topic + */ + public StringArrayTopic(Topic topic) { + super(topic.m_inst, topic.m_handle); + } + + /** + * Constructor; use NetworkTableInstance.getStringArrayTopic() instead. + * + * @param inst Instance + * @param handle Native handle + */ + public StringArrayTopic(NetworkTableInstance inst, int handle) { + super(inst, handle); + } + + /** + * Create a new subscriber to the topic. + * + *

The subscriber is only active as long as the returned object + * is not closed. + * + *

Subscribers that do not match the published data type do not return + * any values. To determine if the data type matches, use the appropriate + * Topic functions. + * + * @param defaultValue default value used when a default is not provided to a + * getter function + * @param options subscribe options + * @return subscriber + */ + public StringArraySubscriber subscribe( + String[] defaultValue, + PubSubOption... options) { + return new StringArrayEntryImpl( + this, + NetworkTablesJNI.subscribe( + m_handle, NetworkTableType.kStringArray.getValue(), + "string[]", options), + defaultValue); + } + + /** + * Create a new subscriber to the topic, with specified type string. + * + *

The subscriber is only active as long as the returned object + * is not closed. + * + *

Subscribers that do not match the published data type do not return + * any values. To determine if the data type matches, use the appropriate + * Topic functions. + * + * @param typeString type string + * @param defaultValue default value used when a default is not provided to a + * getter function + * @param options subscribe options + * @return subscriber + */ + public StringArraySubscriber subscribeEx( + String typeString, + String[] defaultValue, + PubSubOption... options) { + return new StringArrayEntryImpl( + this, + NetworkTablesJNI.subscribe( + m_handle, NetworkTableType.kStringArray.getValue(), + typeString, options), + defaultValue); + } + + /** + * Create a new publisher to the topic. + * + *

The publisher is only active as long as the returned object + * is not closed. + * + *

It is not possible to publish two different data types to the same + * topic. Conflicts between publishers are typically resolved by the server on + * a first-come, first-served basis. Any published values that do not match + * the topic's data type are dropped (ignored). To determine if the data type + * matches, use the appropriate Topic functions. + * + * @param options publish options + * @return publisher + */ + public StringArrayPublisher publish( + PubSubOption... options) { + return new StringArrayEntryImpl( + this, + NetworkTablesJNI.publish( + m_handle, NetworkTableType.kStringArray.getValue(), + "string[]", options), + new String[] {}); + } + + /** + * Create a new publisher to the topic, with type string and initial properties. + * + *

The publisher is only active as long as the returned object + * is not closed. + * + *

It is not possible to publish two different data types to the same + * topic. Conflicts between publishers are typically resolved by the server on + * a first-come, first-served basis. Any published values that do not match + * the topic's data type are dropped (ignored). To determine if the data type + * matches, use the appropriate Topic functions. + * + * @param typeString type string + * @param properties JSON properties + * @param options publish options + * @return publisher + * @throws IllegalArgumentException if properties is not a JSON object + */ + public StringArrayPublisher publishEx( + String typeString, + String properties, + PubSubOption... options) { + return new StringArrayEntryImpl( + this, + NetworkTablesJNI.publishEx( + m_handle, NetworkTableType.kStringArray.getValue(), + typeString, properties, options), + new String[] {}); + } + + /** + * Create a new entry for the topic. + * + *

Entries act as a combination of a subscriber and a weak publisher. The + * subscriber is active as long as the entry is not closed. The publisher is + * created when the entry is first written to, and remains active until either + * unpublish() is called or the entry is closed. + * + *

It is not possible to use two different data types with the same + * topic. Conflicts between publishers are typically resolved by the server on + * a first-come, first-served basis. Any published values that do not match + * the topic's data type are dropped (ignored), and the entry will show no new + * values if the data type does not match. To determine if the data type + * matches, use the appropriate Topic functions. + * + * @param defaultValue default value used when a default is not provided to a + * getter function + * @param options publish and/or subscribe options + * @return entry + */ + public StringArrayEntry getEntry( + String[] defaultValue, + PubSubOption... options) { + return new StringArrayEntryImpl( + this, + NetworkTablesJNI.getEntry( + m_handle, NetworkTableType.kStringArray.getValue(), + "string[]", options), + defaultValue); + } + + /** + * Create a new entry for the topic, with specified type string. + * + *

Entries act as a combination of a subscriber and a weak publisher. The + * subscriber is active as long as the entry is not closed. The publisher is + * created when the entry is first written to, and remains active until either + * unpublish() is called or the entry is closed. + * + *

It is not possible to use two different data types with the same + * topic. Conflicts between publishers are typically resolved by the server on + * a first-come, first-served basis. Any published values that do not match + * the topic's data type are dropped (ignored), and the entry will show no new + * values if the data type does not match. To determine if the data type + * matches, use the appropriate Topic functions. + * + * @param typeString type string + * @param defaultValue default value used when a default is not provided to a + * getter function + * @param options publish and/or subscribe options + * @return entry + */ + public StringArrayEntry getEntryEx( + String typeString, + String[] defaultValue, + PubSubOption... options) { + return new StringArrayEntryImpl( + this, + NetworkTablesJNI.getEntry( + m_handle, NetworkTableType.kStringArray.getValue(), + typeString, options), + defaultValue); + } + +} diff --git a/ntcore/src/generated/main/java/edu/wpi/first/networktables/StringEntry.java b/ntcore/src/generated/main/java/edu/wpi/first/networktables/StringEntry.java new file mode 100644 index 0000000000..6914179c31 --- /dev/null +++ b/ntcore/src/generated/main/java/edu/wpi/first/networktables/StringEntry.java @@ -0,0 +1,17 @@ +// 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. + +// THIS FILE WAS AUTO-GENERATED BY ./ntcore/generate_topics.py. DO NOT MODIFY + +package edu.wpi.first.networktables; + +/** + * NetworkTables String entry. + * + *

Unlike NetworkTableEntry, the entry goes away when close() is called. + */ +public interface StringEntry extends StringSubscriber, StringPublisher { + /** Stops publishing the entry if it's published. */ + void unpublish(); +} diff --git a/ntcore/src/generated/main/java/edu/wpi/first/networktables/StringEntryImpl.java b/ntcore/src/generated/main/java/edu/wpi/first/networktables/StringEntryImpl.java new file mode 100644 index 0000000000..76c9b98545 --- /dev/null +++ b/ntcore/src/generated/main/java/edu/wpi/first/networktables/StringEntryImpl.java @@ -0,0 +1,77 @@ +// 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. + +// THIS FILE WAS AUTO-GENERATED BY ./ntcore/generate_topics.py. DO NOT MODIFY + +package edu.wpi.first.networktables; + +/** NetworkTables String implementation. */ +@SuppressWarnings("PMD.ArrayIsStoredDirectly") +final class StringEntryImpl extends EntryBase implements StringEntry { + /** + * Constructor. + * + * @param topic Topic + * @param handle Native handle + * @param defaultValue Default value for get() + */ + StringEntryImpl(StringTopic topic, int handle, String defaultValue) { + super(handle); + m_topic = topic; + m_defaultValue = defaultValue; + } + + @Override + public StringTopic getTopic() { + return m_topic; + } + + @Override + public String get() { + return NetworkTablesJNI.getString(m_handle, m_defaultValue); + } + + @Override + public String get(String defaultValue) { + return NetworkTablesJNI.getString(m_handle, defaultValue); + } + + @Override + public TimestampedString getAtomic() { + return NetworkTablesJNI.getAtomicString(m_handle, m_defaultValue); + } + + @Override + public TimestampedString getAtomic(String defaultValue) { + return NetworkTablesJNI.getAtomicString(m_handle, defaultValue); + } + + @Override + public TimestampedString[] readQueue() { + return NetworkTablesJNI.readQueueString(m_handle); + } + + @Override + public String[] readQueueValues() { + return NetworkTablesJNI.readQueueValuesString(m_handle); + } + + @Override + public void set(String value, long time) { + NetworkTablesJNI.setString(m_handle, time, value); + } + + @Override + public void setDefault(String value) { + NetworkTablesJNI.setDefaultString(m_handle, 0, value); + } + + @Override + public void unpublish() { + NetworkTablesJNI.unpublish(m_handle); + } + + private final StringTopic m_topic; + private final String m_defaultValue; +} diff --git a/ntcore/src/generated/main/java/edu/wpi/first/networktables/StringPublisher.java b/ntcore/src/generated/main/java/edu/wpi/first/networktables/StringPublisher.java new file mode 100644 index 0000000000..c11f11cb88 --- /dev/null +++ b/ntcore/src/generated/main/java/edu/wpi/first/networktables/StringPublisher.java @@ -0,0 +1,52 @@ +// 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. + +// THIS FILE WAS AUTO-GENERATED BY ./ntcore/generate_topics.py. DO NOT MODIFY + +package edu.wpi.first.networktables; + +import java.util.function.Consumer; + +/** NetworkTables String publisher. */ +public interface StringPublisher extends Publisher, Consumer { + /** + * Get the corresponding topic. + * + * @return Topic + */ + @Override + StringTopic getTopic(); + + /** + * Publish a new value using current NT time. + * + * @param value value to publish + */ + default void set(String value) { + set(value, 0); + } + + + /** + * Publish a new value. + * + * @param value value to publish + * @param time timestamp; 0 indicates current NT time should be used + */ + void set(String value, long time); + + /** + * Publish a default value. + * On reconnect, a default value will never be used in preference to a + * published value. + * + * @param value value + */ + void setDefault(String value); + + @Override + default void accept(String value) { + set(value); + } +} diff --git a/ntcore/src/generated/main/java/edu/wpi/first/networktables/StringSubscriber.java b/ntcore/src/generated/main/java/edu/wpi/first/networktables/StringSubscriber.java new file mode 100644 index 0000000000..8c453b03a4 --- /dev/null +++ b/ntcore/src/generated/main/java/edu/wpi/first/networktables/StringSubscriber.java @@ -0,0 +1,80 @@ +// 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. + +// THIS FILE WAS AUTO-GENERATED BY ./ntcore/generate_topics.py. DO NOT MODIFY + +package edu.wpi.first.networktables; + +import java.util.function.Supplier; + +/** NetworkTables String subscriber. */ +@SuppressWarnings("PMD.MissingOverride") +public interface StringSubscriber extends Subscriber, Supplier { + /** + * Get the corresponding topic. + * + * @return Topic + */ + @Override + StringTopic getTopic(); + + /** + * Get the last published value. + * If no value has been published, returns the stored default value. + * + * @return value + */ + String get(); + + /** + * Get the last published value. + * If no value has been published, returns the passed defaultValue. + * + * @param defaultValue default value to return if no value has been published + * @return value + */ + String get(String defaultValue); + + /** + * Get the last published value along with its timestamp + * If no value has been published, returns the stored default value and a + * timestamp of 0. + * + * @return timestamped value + */ + TimestampedString getAtomic(); + + /** + * Get the last published value along with its timestamp + * If no value has been published, returns the passed defaultValue and a + * timestamp of 0. + * + * @param defaultValue default value to return if no value has been published + * @return timestamped value + */ + TimestampedString getAtomic(String defaultValue); + + /** + * Get an array of all value changes since the last call to readQueue. + * Also provides a timestamp for each value. + * + *

The "poll storage" subscribe option can be used to set the queue + * depth. + * + * @return Array of timestamped values; empty array if no new changes have + * been published since the previous call. + */ + TimestampedString[] readQueue(); + + /** + * Get an array of all value changes since the last call to readQueue. + * + *

The "poll storage" subscribe option can be used to set the queue + * depth. + * + * @return Array of values; empty array if no new changes have been + * published since the previous call. + */ + String[] readQueueValues(); +} diff --git a/ntcore/src/generated/main/java/edu/wpi/first/networktables/StringTopic.java b/ntcore/src/generated/main/java/edu/wpi/first/networktables/StringTopic.java new file mode 100644 index 0000000000..a6341808ff --- /dev/null +++ b/ntcore/src/generated/main/java/edu/wpi/first/networktables/StringTopic.java @@ -0,0 +1,206 @@ +// 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. + +// THIS FILE WAS AUTO-GENERATED BY ./ntcore/generate_topics.py. DO NOT MODIFY + +package edu.wpi.first.networktables; + +/** NetworkTables String topic. */ +public final class StringTopic extends Topic { + /** The default type string for this topic type. */ + public static final String kTypeString = "string"; + + /** + * Construct from a generic topic. + * + * @param topic Topic + */ + public StringTopic(Topic topic) { + super(topic.m_inst, topic.m_handle); + } + + /** + * Constructor; use NetworkTableInstance.getStringTopic() instead. + * + * @param inst Instance + * @param handle Native handle + */ + public StringTopic(NetworkTableInstance inst, int handle) { + super(inst, handle); + } + + /** + * Create a new subscriber to the topic. + * + *

The subscriber is only active as long as the returned object + * is not closed. + * + *

Subscribers that do not match the published data type do not return + * any values. To determine if the data type matches, use the appropriate + * Topic functions. + * + * @param defaultValue default value used when a default is not provided to a + * getter function + * @param options subscribe options + * @return subscriber + */ + public StringSubscriber subscribe( + String defaultValue, + PubSubOption... options) { + return new StringEntryImpl( + this, + NetworkTablesJNI.subscribe( + m_handle, NetworkTableType.kString.getValue(), + "string", options), + defaultValue); + } + + /** + * Create a new subscriber to the topic, with specified type string. + * + *

The subscriber is only active as long as the returned object + * is not closed. + * + *

Subscribers that do not match the published data type do not return + * any values. To determine if the data type matches, use the appropriate + * Topic functions. + * + * @param typeString type string + * @param defaultValue default value used when a default is not provided to a + * getter function + * @param options subscribe options + * @return subscriber + */ + public StringSubscriber subscribeEx( + String typeString, + String defaultValue, + PubSubOption... options) { + return new StringEntryImpl( + this, + NetworkTablesJNI.subscribe( + m_handle, NetworkTableType.kString.getValue(), + typeString, options), + defaultValue); + } + + /** + * Create a new publisher to the topic. + * + *

The publisher is only active as long as the returned object + * is not closed. + * + *

It is not possible to publish two different data types to the same + * topic. Conflicts between publishers are typically resolved by the server on + * a first-come, first-served basis. Any published values that do not match + * the topic's data type are dropped (ignored). To determine if the data type + * matches, use the appropriate Topic functions. + * + * @param options publish options + * @return publisher + */ + public StringPublisher publish( + PubSubOption... options) { + return new StringEntryImpl( + this, + NetworkTablesJNI.publish( + m_handle, NetworkTableType.kString.getValue(), + "string", options), + ""); + } + + /** + * Create a new publisher to the topic, with type string and initial properties. + * + *

The publisher is only active as long as the returned object + * is not closed. + * + *

It is not possible to publish two different data types to the same + * topic. Conflicts between publishers are typically resolved by the server on + * a first-come, first-served basis. Any published values that do not match + * the topic's data type are dropped (ignored). To determine if the data type + * matches, use the appropriate Topic functions. + * + * @param typeString type string + * @param properties JSON properties + * @param options publish options + * @return publisher + * @throws IllegalArgumentException if properties is not a JSON object + */ + public StringPublisher publishEx( + String typeString, + String properties, + PubSubOption... options) { + return new StringEntryImpl( + this, + NetworkTablesJNI.publishEx( + m_handle, NetworkTableType.kString.getValue(), + typeString, properties, options), + ""); + } + + /** + * Create a new entry for the topic. + * + *

Entries act as a combination of a subscriber and a weak publisher. The + * subscriber is active as long as the entry is not closed. The publisher is + * created when the entry is first written to, and remains active until either + * unpublish() is called or the entry is closed. + * + *

It is not possible to use two different data types with the same + * topic. Conflicts between publishers are typically resolved by the server on + * a first-come, first-served basis. Any published values that do not match + * the topic's data type are dropped (ignored), and the entry will show no new + * values if the data type does not match. To determine if the data type + * matches, use the appropriate Topic functions. + * + * @param defaultValue default value used when a default is not provided to a + * getter function + * @param options publish and/or subscribe options + * @return entry + */ + public StringEntry getEntry( + String defaultValue, + PubSubOption... options) { + return new StringEntryImpl( + this, + NetworkTablesJNI.getEntry( + m_handle, NetworkTableType.kString.getValue(), + "string", options), + defaultValue); + } + + /** + * Create a new entry for the topic, with specified type string. + * + *

Entries act as a combination of a subscriber and a weak publisher. The + * subscriber is active as long as the entry is not closed. The publisher is + * created when the entry is first written to, and remains active until either + * unpublish() is called or the entry is closed. + * + *

It is not possible to use two different data types with the same + * topic. Conflicts between publishers are typically resolved by the server on + * a first-come, first-served basis. Any published values that do not match + * the topic's data type are dropped (ignored), and the entry will show no new + * values if the data type does not match. To determine if the data type + * matches, use the appropriate Topic functions. + * + * @param typeString type string + * @param defaultValue default value used when a default is not provided to a + * getter function + * @param options publish and/or subscribe options + * @return entry + */ + public StringEntry getEntryEx( + String typeString, + String defaultValue, + PubSubOption... options) { + return new StringEntryImpl( + this, + NetworkTablesJNI.getEntry( + m_handle, NetworkTableType.kString.getValue(), + typeString, options), + defaultValue); + } + +} diff --git a/ntcore/src/generated/main/java/edu/wpi/first/networktables/TimestampedBoolean.java b/ntcore/src/generated/main/java/edu/wpi/first/networktables/TimestampedBoolean.java new file mode 100644 index 0000000000..05497fcb3b --- /dev/null +++ b/ntcore/src/generated/main/java/edu/wpi/first/networktables/TimestampedBoolean.java @@ -0,0 +1,42 @@ +// 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. + +// THIS FILE WAS AUTO-GENERATED BY ./ntcore/generate_topics.py. DO NOT MODIFY + +package edu.wpi.first.networktables; + +/** NetworkTables timestamped Boolean. */ +@SuppressWarnings("PMD.ArrayIsStoredDirectly") +public final class TimestampedBoolean { + /** + * Create a timestamped value. + * + * @param timestamp timestamp in local time base + * @param serverTime timestamp in server time base + * @param value value + */ + public TimestampedBoolean(long timestamp, long serverTime, boolean value) { + this.timestamp = timestamp; + this.serverTime = serverTime; + this.value = value; + } + + /** + * Timestamp in local time base. + */ + @SuppressWarnings("MemberName") + public final long timestamp; + + /** + * Timestamp in server time base. May be 0 or 1 for locally set values. + */ + @SuppressWarnings("MemberName") + public final long serverTime; + + /** + * Value. + */ + @SuppressWarnings("MemberName") + public final boolean value; +} diff --git a/ntcore/src/generated/main/java/edu/wpi/first/networktables/TimestampedBooleanArray.java b/ntcore/src/generated/main/java/edu/wpi/first/networktables/TimestampedBooleanArray.java new file mode 100644 index 0000000000..51e2591291 --- /dev/null +++ b/ntcore/src/generated/main/java/edu/wpi/first/networktables/TimestampedBooleanArray.java @@ -0,0 +1,42 @@ +// 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. + +// THIS FILE WAS AUTO-GENERATED BY ./ntcore/generate_topics.py. DO NOT MODIFY + +package edu.wpi.first.networktables; + +/** NetworkTables timestamped BooleanArray. */ +@SuppressWarnings("PMD.ArrayIsStoredDirectly") +public final class TimestampedBooleanArray { + /** + * Create a timestamped value. + * + * @param timestamp timestamp in local time base + * @param serverTime timestamp in server time base + * @param value value + */ + public TimestampedBooleanArray(long timestamp, long serverTime, boolean[] value) { + this.timestamp = timestamp; + this.serverTime = serverTime; + this.value = value; + } + + /** + * Timestamp in local time base. + */ + @SuppressWarnings("MemberName") + public final long timestamp; + + /** + * Timestamp in server time base. May be 0 or 1 for locally set values. + */ + @SuppressWarnings("MemberName") + public final long serverTime; + + /** + * Value. + */ + @SuppressWarnings("MemberName") + public final boolean[] value; +} diff --git a/ntcore/src/generated/main/java/edu/wpi/first/networktables/TimestampedDouble.java b/ntcore/src/generated/main/java/edu/wpi/first/networktables/TimestampedDouble.java new file mode 100644 index 0000000000..586c9fc1d1 --- /dev/null +++ b/ntcore/src/generated/main/java/edu/wpi/first/networktables/TimestampedDouble.java @@ -0,0 +1,42 @@ +// 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. + +// THIS FILE WAS AUTO-GENERATED BY ./ntcore/generate_topics.py. DO NOT MODIFY + +package edu.wpi.first.networktables; + +/** NetworkTables timestamped Double. */ +@SuppressWarnings("PMD.ArrayIsStoredDirectly") +public final class TimestampedDouble { + /** + * Create a timestamped value. + * + * @param timestamp timestamp in local time base + * @param serverTime timestamp in server time base + * @param value value + */ + public TimestampedDouble(long timestamp, long serverTime, double value) { + this.timestamp = timestamp; + this.serverTime = serverTime; + this.value = value; + } + + /** + * Timestamp in local time base. + */ + @SuppressWarnings("MemberName") + public final long timestamp; + + /** + * Timestamp in server time base. May be 0 or 1 for locally set values. + */ + @SuppressWarnings("MemberName") + public final long serverTime; + + /** + * Value. + */ + @SuppressWarnings("MemberName") + public final double value; +} diff --git a/ntcore/src/generated/main/java/edu/wpi/first/networktables/TimestampedDoubleArray.java b/ntcore/src/generated/main/java/edu/wpi/first/networktables/TimestampedDoubleArray.java new file mode 100644 index 0000000000..aaeafd788e --- /dev/null +++ b/ntcore/src/generated/main/java/edu/wpi/first/networktables/TimestampedDoubleArray.java @@ -0,0 +1,42 @@ +// 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. + +// THIS FILE WAS AUTO-GENERATED BY ./ntcore/generate_topics.py. DO NOT MODIFY + +package edu.wpi.first.networktables; + +/** NetworkTables timestamped DoubleArray. */ +@SuppressWarnings("PMD.ArrayIsStoredDirectly") +public final class TimestampedDoubleArray { + /** + * Create a timestamped value. + * + * @param timestamp timestamp in local time base + * @param serverTime timestamp in server time base + * @param value value + */ + public TimestampedDoubleArray(long timestamp, long serverTime, double[] value) { + this.timestamp = timestamp; + this.serverTime = serverTime; + this.value = value; + } + + /** + * Timestamp in local time base. + */ + @SuppressWarnings("MemberName") + public final long timestamp; + + /** + * Timestamp in server time base. May be 0 or 1 for locally set values. + */ + @SuppressWarnings("MemberName") + public final long serverTime; + + /** + * Value. + */ + @SuppressWarnings("MemberName") + public final double[] value; +} diff --git a/ntcore/src/generated/main/java/edu/wpi/first/networktables/TimestampedFloat.java b/ntcore/src/generated/main/java/edu/wpi/first/networktables/TimestampedFloat.java new file mode 100644 index 0000000000..4d8aa095df --- /dev/null +++ b/ntcore/src/generated/main/java/edu/wpi/first/networktables/TimestampedFloat.java @@ -0,0 +1,42 @@ +// 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. + +// THIS FILE WAS AUTO-GENERATED BY ./ntcore/generate_topics.py. DO NOT MODIFY + +package edu.wpi.first.networktables; + +/** NetworkTables timestamped Float. */ +@SuppressWarnings("PMD.ArrayIsStoredDirectly") +public final class TimestampedFloat { + /** + * Create a timestamped value. + * + * @param timestamp timestamp in local time base + * @param serverTime timestamp in server time base + * @param value value + */ + public TimestampedFloat(long timestamp, long serverTime, float value) { + this.timestamp = timestamp; + this.serverTime = serverTime; + this.value = value; + } + + /** + * Timestamp in local time base. + */ + @SuppressWarnings("MemberName") + public final long timestamp; + + /** + * Timestamp in server time base. May be 0 or 1 for locally set values. + */ + @SuppressWarnings("MemberName") + public final long serverTime; + + /** + * Value. + */ + @SuppressWarnings("MemberName") + public final float value; +} diff --git a/ntcore/src/generated/main/java/edu/wpi/first/networktables/TimestampedFloatArray.java b/ntcore/src/generated/main/java/edu/wpi/first/networktables/TimestampedFloatArray.java new file mode 100644 index 0000000000..85fe7bcac7 --- /dev/null +++ b/ntcore/src/generated/main/java/edu/wpi/first/networktables/TimestampedFloatArray.java @@ -0,0 +1,42 @@ +// 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. + +// THIS FILE WAS AUTO-GENERATED BY ./ntcore/generate_topics.py. DO NOT MODIFY + +package edu.wpi.first.networktables; + +/** NetworkTables timestamped FloatArray. */ +@SuppressWarnings("PMD.ArrayIsStoredDirectly") +public final class TimestampedFloatArray { + /** + * Create a timestamped value. + * + * @param timestamp timestamp in local time base + * @param serverTime timestamp in server time base + * @param value value + */ + public TimestampedFloatArray(long timestamp, long serverTime, float[] value) { + this.timestamp = timestamp; + this.serverTime = serverTime; + this.value = value; + } + + /** + * Timestamp in local time base. + */ + @SuppressWarnings("MemberName") + public final long timestamp; + + /** + * Timestamp in server time base. May be 0 or 1 for locally set values. + */ + @SuppressWarnings("MemberName") + public final long serverTime; + + /** + * Value. + */ + @SuppressWarnings("MemberName") + public final float[] value; +} diff --git a/ntcore/src/generated/main/java/edu/wpi/first/networktables/TimestampedInteger.java b/ntcore/src/generated/main/java/edu/wpi/first/networktables/TimestampedInteger.java new file mode 100644 index 0000000000..0ee7855363 --- /dev/null +++ b/ntcore/src/generated/main/java/edu/wpi/first/networktables/TimestampedInteger.java @@ -0,0 +1,42 @@ +// 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. + +// THIS FILE WAS AUTO-GENERATED BY ./ntcore/generate_topics.py. DO NOT MODIFY + +package edu.wpi.first.networktables; + +/** NetworkTables timestamped Integer. */ +@SuppressWarnings("PMD.ArrayIsStoredDirectly") +public final class TimestampedInteger { + /** + * Create a timestamped value. + * + * @param timestamp timestamp in local time base + * @param serverTime timestamp in server time base + * @param value value + */ + public TimestampedInteger(long timestamp, long serverTime, long value) { + this.timestamp = timestamp; + this.serverTime = serverTime; + this.value = value; + } + + /** + * Timestamp in local time base. + */ + @SuppressWarnings("MemberName") + public final long timestamp; + + /** + * Timestamp in server time base. May be 0 or 1 for locally set values. + */ + @SuppressWarnings("MemberName") + public final long serverTime; + + /** + * Value. + */ + @SuppressWarnings("MemberName") + public final long value; +} diff --git a/ntcore/src/generated/main/java/edu/wpi/first/networktables/TimestampedIntegerArray.java b/ntcore/src/generated/main/java/edu/wpi/first/networktables/TimestampedIntegerArray.java new file mode 100644 index 0000000000..8686326996 --- /dev/null +++ b/ntcore/src/generated/main/java/edu/wpi/first/networktables/TimestampedIntegerArray.java @@ -0,0 +1,42 @@ +// 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. + +// THIS FILE WAS AUTO-GENERATED BY ./ntcore/generate_topics.py. DO NOT MODIFY + +package edu.wpi.first.networktables; + +/** NetworkTables timestamped IntegerArray. */ +@SuppressWarnings("PMD.ArrayIsStoredDirectly") +public final class TimestampedIntegerArray { + /** + * Create a timestamped value. + * + * @param timestamp timestamp in local time base + * @param serverTime timestamp in server time base + * @param value value + */ + public TimestampedIntegerArray(long timestamp, long serverTime, long[] value) { + this.timestamp = timestamp; + this.serverTime = serverTime; + this.value = value; + } + + /** + * Timestamp in local time base. + */ + @SuppressWarnings("MemberName") + public final long timestamp; + + /** + * Timestamp in server time base. May be 0 or 1 for locally set values. + */ + @SuppressWarnings("MemberName") + public final long serverTime; + + /** + * Value. + */ + @SuppressWarnings("MemberName") + public final long[] value; +} diff --git a/ntcore/src/generated/main/java/edu/wpi/first/networktables/TimestampedRaw.java b/ntcore/src/generated/main/java/edu/wpi/first/networktables/TimestampedRaw.java new file mode 100644 index 0000000000..12ec095e3f --- /dev/null +++ b/ntcore/src/generated/main/java/edu/wpi/first/networktables/TimestampedRaw.java @@ -0,0 +1,42 @@ +// 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. + +// THIS FILE WAS AUTO-GENERATED BY ./ntcore/generate_topics.py. DO NOT MODIFY + +package edu.wpi.first.networktables; + +/** NetworkTables timestamped Raw. */ +@SuppressWarnings("PMD.ArrayIsStoredDirectly") +public final class TimestampedRaw { + /** + * Create a timestamped value. + * + * @param timestamp timestamp in local time base + * @param serverTime timestamp in server time base + * @param value value + */ + public TimestampedRaw(long timestamp, long serverTime, byte[] value) { + this.timestamp = timestamp; + this.serverTime = serverTime; + this.value = value; + } + + /** + * Timestamp in local time base. + */ + @SuppressWarnings("MemberName") + public final long timestamp; + + /** + * Timestamp in server time base. May be 0 or 1 for locally set values. + */ + @SuppressWarnings("MemberName") + public final long serverTime; + + /** + * Value. + */ + @SuppressWarnings("MemberName") + public final byte[] value; +} diff --git a/ntcore/src/generated/main/java/edu/wpi/first/networktables/TimestampedString.java b/ntcore/src/generated/main/java/edu/wpi/first/networktables/TimestampedString.java new file mode 100644 index 0000000000..a51432ee49 --- /dev/null +++ b/ntcore/src/generated/main/java/edu/wpi/first/networktables/TimestampedString.java @@ -0,0 +1,42 @@ +// 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. + +// THIS FILE WAS AUTO-GENERATED BY ./ntcore/generate_topics.py. DO NOT MODIFY + +package edu.wpi.first.networktables; + +/** NetworkTables timestamped String. */ +@SuppressWarnings("PMD.ArrayIsStoredDirectly") +public final class TimestampedString { + /** + * Create a timestamped value. + * + * @param timestamp timestamp in local time base + * @param serverTime timestamp in server time base + * @param value value + */ + public TimestampedString(long timestamp, long serverTime, String value) { + this.timestamp = timestamp; + this.serverTime = serverTime; + this.value = value; + } + + /** + * Timestamp in local time base. + */ + @SuppressWarnings("MemberName") + public final long timestamp; + + /** + * Timestamp in server time base. May be 0 or 1 for locally set values. + */ + @SuppressWarnings("MemberName") + public final long serverTime; + + /** + * Value. + */ + @SuppressWarnings("MemberName") + public final String value; +} diff --git a/ntcore/src/generated/main/java/edu/wpi/first/networktables/TimestampedStringArray.java b/ntcore/src/generated/main/java/edu/wpi/first/networktables/TimestampedStringArray.java new file mode 100644 index 0000000000..420a4685a9 --- /dev/null +++ b/ntcore/src/generated/main/java/edu/wpi/first/networktables/TimestampedStringArray.java @@ -0,0 +1,42 @@ +// 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. + +// THIS FILE WAS AUTO-GENERATED BY ./ntcore/generate_topics.py. DO NOT MODIFY + +package edu.wpi.first.networktables; + +/** NetworkTables timestamped StringArray. */ +@SuppressWarnings("PMD.ArrayIsStoredDirectly") +public final class TimestampedStringArray { + /** + * Create a timestamped value. + * + * @param timestamp timestamp in local time base + * @param serverTime timestamp in server time base + * @param value value + */ + public TimestampedStringArray(long timestamp, long serverTime, String[] value) { + this.timestamp = timestamp; + this.serverTime = serverTime; + this.value = value; + } + + /** + * Timestamp in local time base. + */ + @SuppressWarnings("MemberName") + public final long timestamp; + + /** + * Timestamp in server time base. May be 0 or 1 for locally set values. + */ + @SuppressWarnings("MemberName") + public final long serverTime; + + /** + * Value. + */ + @SuppressWarnings("MemberName") + public final String[] value; +} diff --git a/ntcore/src/generated/main/native/cpp/jni/types_jni.cpp b/ntcore/src/generated/main/native/cpp/jni/types_jni.cpp new file mode 100644 index 0000000000..de14d538de --- /dev/null +++ b/ntcore/src/generated/main/native/cpp/jni/types_jni.cpp @@ -0,0 +1,1436 @@ +// 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. + +// THIS FILE WAS AUTO-GENERATED BY ./ntcore/generate_topics.py. DO NOT MODIFY + +#include + +#include + +#include "edu_wpi_first_networktables_NetworkTablesJNI.h" +#include "ntcore.h" + +using namespace wpi::java; + +// +// Globals and load/unload +// + +static JClass timestampedBooleanCls; +static JClass timestampedIntegerCls; +static JClass timestampedFloatCls; +static JClass timestampedDoubleCls; +static JClass timestampedStringCls; +static JClass timestampedRawCls; +static JClass timestampedBooleanArrayCls; +static JClass timestampedIntegerArrayCls; +static JClass timestampedFloatArrayCls; +static JClass timestampedDoubleArrayCls; +static JClass timestampedStringArrayCls; +static JClass jbyteArrayCls; +static JClass jbooleanArrayCls; +static JClass jlongArrayCls; +static JClass jfloatArrayCls; +static JClass jdoubleArrayCls; +static JClass jobjectArrayCls; +static JException illegalArgEx; +static JException indexOobEx; +static JException nullPointerEx; + +static const JClassInit classes[] = { + {"edu/wpi/first/networktables/TimestampedBoolean", ×tampedBooleanCls}, + {"edu/wpi/first/networktables/TimestampedInteger", ×tampedIntegerCls}, + {"edu/wpi/first/networktables/TimestampedFloat", ×tampedFloatCls}, + {"edu/wpi/first/networktables/TimestampedDouble", ×tampedDoubleCls}, + {"edu/wpi/first/networktables/TimestampedString", ×tampedStringCls}, + {"edu/wpi/first/networktables/TimestampedRaw", ×tampedRawCls}, + {"edu/wpi/first/networktables/TimestampedBooleanArray", ×tampedBooleanArrayCls}, + {"edu/wpi/first/networktables/TimestampedIntegerArray", ×tampedIntegerArrayCls}, + {"edu/wpi/first/networktables/TimestampedFloatArray", ×tampedFloatArrayCls}, + {"edu/wpi/first/networktables/TimestampedDoubleArray", ×tampedDoubleArrayCls}, + {"edu/wpi/first/networktables/TimestampedStringArray", ×tampedStringArrayCls}, + {"[B", &jbyteArrayCls}, + {"[Z", &jbooleanArrayCls}, + {"[J", &jlongArrayCls}, + {"[F", &jfloatArrayCls}, + {"[D", &jdoubleArrayCls}, + {"[Ljava/lang/Object;", &jobjectArrayCls}, +}; + +static const JExceptionInit exceptions[] = { + {"java/lang/IllegalArgumentException", &illegalArgEx}, + {"java/lang/IndexOutOfBoundsException", &indexOobEx}, + {"java/lang/NullPointerException", &nullPointerEx}, +}; + +namespace nt { + +bool JNI_LoadTypes(JNIEnv* env) { + // Cache references to classes + for (auto& c : classes) { + *c.cls = JClass(env, c.name); + if (!*c.cls) { + return false; + } + } + + for (auto& c : exceptions) { + *c.cls = JException(env, c.name); + if (!*c.cls) { + return false; + } + } + + return true; +} + +void JNI_UnloadTypes(JNIEnv* env) { + // Delete global references + for (auto& c : classes) { + c.cls->free(env); + } + for (auto& c : exceptions) { + c.cls->free(env); + } +} + +} // namespace nt + +static std::vector FromJavaBooleanArray(JNIEnv* env, jbooleanArray jarr) { + CriticalJSpan ref{env, jarr}; + if (!ref) { + return {}; + } + std::span elements{ref}; + size_t len = elements.size(); + std::vector arr; + arr.reserve(len); + for (size_t i = 0; i < len; ++i) { + arr.push_back(elements[i]); + } + return arr; +} + +static std::vector FromJavaStringArray(JNIEnv* env, jobjectArray jarr) { + size_t len = env->GetArrayLength(jarr); + std::vector arr; + arr.reserve(len); + for (size_t i = 0; i < len; ++i) { + JLocal elem{ + env, static_cast(env->GetObjectArrayElement(jarr, i))}; + if (!elem) { + return {}; + } + arr.emplace_back(JStringRef{env, elem}.str()); + } + return arr; +} + + +static jobject MakeJObject(JNIEnv* env, nt::TimestampedBoolean value) { + static jmethodID constructor = env->GetMethodID( + timestampedBooleanCls, "", "(JJZ)V"); + return env->NewObject(timestampedBooleanCls, constructor, + static_cast(value.time), + static_cast(value.serverTime), + static_cast(value.value)); +} + +static jobject MakeJObject(JNIEnv* env, nt::TimestampedInteger value) { + static jmethodID constructor = env->GetMethodID( + timestampedIntegerCls, "", "(JJJ)V"); + return env->NewObject(timestampedIntegerCls, constructor, + static_cast(value.time), + static_cast(value.serverTime), + static_cast(value.value)); +} + +static jobject MakeJObject(JNIEnv* env, nt::TimestampedFloat value) { + static jmethodID constructor = env->GetMethodID( + timestampedFloatCls, "", "(JJF)V"); + return env->NewObject(timestampedFloatCls, constructor, + static_cast(value.time), + static_cast(value.serverTime), + static_cast(value.value)); +} + +static jobject MakeJObject(JNIEnv* env, nt::TimestampedDouble value) { + static jmethodID constructor = env->GetMethodID( + timestampedDoubleCls, "", "(JJD)V"); + return env->NewObject(timestampedDoubleCls, constructor, + static_cast(value.time), + static_cast(value.serverTime), + static_cast(value.value)); +} + +static jobject MakeJObject(JNIEnv* env, nt::TimestampedString value) { + static jmethodID constructor = env->GetMethodID( + timestampedStringCls, "", "(JJLjava/lang/String;)V"); + JLocal val{env, MakeJString(env, value.value)}; + return env->NewObject(timestampedStringCls, constructor, + static_cast(value.time), + static_cast(value.serverTime), val.obj()); +} + +static jobject MakeJObject(JNIEnv* env, nt::TimestampedRaw value) { + static jmethodID constructor = env->GetMethodID( + timestampedRawCls, "", "(JJ[B)V"); + JLocal val{env, MakeJByteArray(env, value.value)}; + return env->NewObject(timestampedRawCls, constructor, + static_cast(value.time), + static_cast(value.serverTime), val.obj()); +} + +static jobject MakeJObject(JNIEnv* env, nt::TimestampedBooleanArray value) { + static jmethodID constructor = env->GetMethodID( + timestampedBooleanArrayCls, "", "(JJ[Z)V"); + JLocal val{env, MakeJBooleanArray(env, value.value)}; + return env->NewObject(timestampedBooleanArrayCls, constructor, + static_cast(value.time), + static_cast(value.serverTime), val.obj()); +} + +static jobject MakeJObject(JNIEnv* env, nt::TimestampedIntegerArray value) { + static jmethodID constructor = env->GetMethodID( + timestampedIntegerArrayCls, "", "(JJ[J)V"); + JLocal val{env, MakeJLongArray(env, value.value)}; + return env->NewObject(timestampedIntegerArrayCls, constructor, + static_cast(value.time), + static_cast(value.serverTime), val.obj()); +} + +static jobject MakeJObject(JNIEnv* env, nt::TimestampedFloatArray value) { + static jmethodID constructor = env->GetMethodID( + timestampedFloatArrayCls, "", "(JJ[F)V"); + JLocal val{env, MakeJFloatArray(env, value.value)}; + return env->NewObject(timestampedFloatArrayCls, constructor, + static_cast(value.time), + static_cast(value.serverTime), val.obj()); +} + +static jobject MakeJObject(JNIEnv* env, nt::TimestampedDoubleArray value) { + static jmethodID constructor = env->GetMethodID( + timestampedDoubleArrayCls, "", "(JJ[D)V"); + JLocal val{env, MakeJDoubleArray(env, value.value)}; + return env->NewObject(timestampedDoubleArrayCls, constructor, + static_cast(value.time), + static_cast(value.serverTime), val.obj()); +} + +static jobject MakeJObject(JNIEnv* env, nt::TimestampedStringArray value) { + static jmethodID constructor = env->GetMethodID( + timestampedStringArrayCls, "", "(JJ[Ljava/lang/Object;)V"); + JLocal val{env, MakeJStringArray(env, value.value)}; + return env->NewObject(timestampedStringArrayCls, constructor, + static_cast(value.time), + static_cast(value.serverTime), val.obj()); +} + +static jobjectArray MakeJObject(JNIEnv* env, + std::span arr) { + jobjectArray jarr = + env->NewObjectArray(arr.size(), timestampedBooleanCls, nullptr); + if (!jarr) { + return nullptr; + } + for (size_t i = 0; i < arr.size(); ++i) { + JLocal elem{env, MakeJObject(env, arr[i])}; + env->SetObjectArrayElement(jarr, i, elem.obj()); + } + return jarr; +} + +static jobjectArray MakeJObject(JNIEnv* env, + std::span arr) { + jobjectArray jarr = + env->NewObjectArray(arr.size(), timestampedIntegerCls, nullptr); + if (!jarr) { + return nullptr; + } + for (size_t i = 0; i < arr.size(); ++i) { + JLocal elem{env, MakeJObject(env, arr[i])}; + env->SetObjectArrayElement(jarr, i, elem.obj()); + } + return jarr; +} + +static jobjectArray MakeJObject(JNIEnv* env, + std::span arr) { + jobjectArray jarr = + env->NewObjectArray(arr.size(), timestampedFloatCls, nullptr); + if (!jarr) { + return nullptr; + } + for (size_t i = 0; i < arr.size(); ++i) { + JLocal elem{env, MakeJObject(env, arr[i])}; + env->SetObjectArrayElement(jarr, i, elem.obj()); + } + return jarr; +} + +static jobjectArray MakeJObject(JNIEnv* env, + std::span arr) { + jobjectArray jarr = + env->NewObjectArray(arr.size(), timestampedDoubleCls, nullptr); + if (!jarr) { + return nullptr; + } + for (size_t i = 0; i < arr.size(); ++i) { + JLocal elem{env, MakeJObject(env, arr[i])}; + env->SetObjectArrayElement(jarr, i, elem.obj()); + } + return jarr; +} + +static jobjectArray MakeJObject(JNIEnv* env, + std::span arr) { + jobjectArray jarr = + env->NewObjectArray(arr.size(), timestampedStringCls, nullptr); + if (!jarr) { + return nullptr; + } + for (size_t i = 0; i < arr.size(); ++i) { + JLocal elem{env, MakeJObject(env, arr[i])}; + env->SetObjectArrayElement(jarr, i, elem.obj()); + } + return jarr; +} + +static jobjectArray MakeJObject(JNIEnv* env, + std::span arr) { + jobjectArray jarr = + env->NewObjectArray(arr.size(), timestampedRawCls, nullptr); + if (!jarr) { + return nullptr; + } + for (size_t i = 0; i < arr.size(); ++i) { + JLocal elem{env, MakeJObject(env, arr[i])}; + env->SetObjectArrayElement(jarr, i, elem.obj()); + } + return jarr; +} + +static jobjectArray MakeJObject(JNIEnv* env, + std::span arr) { + jobjectArray jarr = + env->NewObjectArray(arr.size(), timestampedBooleanArrayCls, nullptr); + if (!jarr) { + return nullptr; + } + for (size_t i = 0; i < arr.size(); ++i) { + JLocal elem{env, MakeJObject(env, arr[i])}; + env->SetObjectArrayElement(jarr, i, elem.obj()); + } + return jarr; +} + +static jobjectArray MakeJObject(JNIEnv* env, + std::span arr) { + jobjectArray jarr = + env->NewObjectArray(arr.size(), timestampedIntegerArrayCls, nullptr); + if (!jarr) { + return nullptr; + } + for (size_t i = 0; i < arr.size(); ++i) { + JLocal elem{env, MakeJObject(env, arr[i])}; + env->SetObjectArrayElement(jarr, i, elem.obj()); + } + return jarr; +} + +static jobjectArray MakeJObject(JNIEnv* env, + std::span arr) { + jobjectArray jarr = + env->NewObjectArray(arr.size(), timestampedFloatArrayCls, nullptr); + if (!jarr) { + return nullptr; + } + for (size_t i = 0; i < arr.size(); ++i) { + JLocal elem{env, MakeJObject(env, arr[i])}; + env->SetObjectArrayElement(jarr, i, elem.obj()); + } + return jarr; +} + +static jobjectArray MakeJObject(JNIEnv* env, + std::span arr) { + jobjectArray jarr = + env->NewObjectArray(arr.size(), timestampedDoubleArrayCls, nullptr); + if (!jarr) { + return nullptr; + } + for (size_t i = 0; i < arr.size(); ++i) { + JLocal elem{env, MakeJObject(env, arr[i])}; + env->SetObjectArrayElement(jarr, i, elem.obj()); + } + return jarr; +} + +static jobjectArray MakeJObject(JNIEnv* env, + std::span arr) { + jobjectArray jarr = + env->NewObjectArray(arr.size(), timestampedStringArrayCls, nullptr); + if (!jarr) { + return nullptr; + } + for (size_t i = 0; i < arr.size(); ++i) { + JLocal elem{env, MakeJObject(env, arr[i])}; + env->SetObjectArrayElement(jarr, i, elem.obj()); + } + return jarr; +} + +static jobjectArray MakeJObjectArray(JNIEnv* env, std::span> arr) { + jobjectArray jarr = + env->NewObjectArray(arr.size(), jbyteArrayCls, nullptr); + if (!jarr) { + return nullptr; + } + for (size_t i = 0; i < arr.size(); ++i) { + JLocal elem{env, MakeJByteArray(env, arr[i])}; + env->SetObjectArrayElement(jarr, i, elem.obj()); + } + return jarr; +} + +static jobjectArray MakeJObjectArray(JNIEnv* env, std::span> arr) { + jobjectArray jarr = + env->NewObjectArray(arr.size(), jbooleanArrayCls, nullptr); + if (!jarr) { + return nullptr; + } + for (size_t i = 0; i < arr.size(); ++i) { + JLocal elem{env, MakeJBooleanArray(env, arr[i])}; + env->SetObjectArrayElement(jarr, i, elem.obj()); + } + return jarr; +} + +static jobjectArray MakeJObjectArray(JNIEnv* env, std::span> arr) { + jobjectArray jarr = + env->NewObjectArray(arr.size(), jlongArrayCls, nullptr); + if (!jarr) { + return nullptr; + } + for (size_t i = 0; i < arr.size(); ++i) { + JLocal elem{env, MakeJLongArray(env, arr[i])}; + env->SetObjectArrayElement(jarr, i, elem.obj()); + } + return jarr; +} + +static jobjectArray MakeJObjectArray(JNIEnv* env, std::span> arr) { + jobjectArray jarr = + env->NewObjectArray(arr.size(), jfloatArrayCls, nullptr); + if (!jarr) { + return nullptr; + } + for (size_t i = 0; i < arr.size(); ++i) { + JLocal elem{env, MakeJFloatArray(env, arr[i])}; + env->SetObjectArrayElement(jarr, i, elem.obj()); + } + return jarr; +} + +static jobjectArray MakeJObjectArray(JNIEnv* env, std::span> arr) { + jobjectArray jarr = + env->NewObjectArray(arr.size(), jdoubleArrayCls, nullptr); + if (!jarr) { + return nullptr; + } + for (size_t i = 0; i < arr.size(); ++i) { + JLocal elem{env, MakeJDoubleArray(env, arr[i])}; + env->SetObjectArrayElement(jarr, i, elem.obj()); + } + return jarr; +} + +static jobjectArray MakeJObjectArray(JNIEnv* env, std::span> arr) { + jobjectArray jarr = + env->NewObjectArray(arr.size(), jobjectArrayCls, nullptr); + if (!jarr) { + return nullptr; + } + for (size_t i = 0; i < arr.size(); ++i) { + JLocal elem{env, MakeJStringArray(env, arr[i])}; + env->SetObjectArrayElement(jarr, i, elem.obj()); + } + return jarr; +} + + +extern "C" { + +/* + * Class: edu_wpi_first_networktables_NetworkTablesJNI + * Method: getAtomicBoolean + * Signature: (IZ)Ledu/wpi/first/networktables/TimestampedBoolean; + */ +JNIEXPORT jobject JNICALL +Java_edu_wpi_first_networktables_NetworkTablesJNI_getAtomicBoolean + (JNIEnv* env, jclass, jint subentry, jboolean defaultValue) +{ + return MakeJObject(env, nt::GetAtomicBoolean(subentry, defaultValue != JNI_FALSE)); +} + +/* + * Class: edu_wpi_first_networktables_NetworkTablesJNI + * Method: readQueueBoolean + * Signature: (I)[Ledu/wpi/first/networktables/TimestampedBoolean; + */ +JNIEXPORT jobjectArray JNICALL +Java_edu_wpi_first_networktables_NetworkTablesJNI_readQueueBoolean + (JNIEnv* env, jclass, jint subentry) +{ + return MakeJObject(env, nt::ReadQueueBoolean(subentry)); +} + +/* + * Class: edu_wpi_first_networktables_NetworkTablesJNI + * Method: readQueueValuesBoolean + * Signature: (I)[Z + */ +JNIEXPORT jbooleanArray JNICALL +Java_edu_wpi_first_networktables_NetworkTablesJNI_readQueueValuesBoolean + (JNIEnv* env, jclass, jint subentry) +{ + return MakeJBooleanArray(env, nt::ReadQueueValuesBoolean(subentry)); +} + +/* + * Class: edu_wpi_first_networktables_NetworkTablesJNI + * Method: setBoolean + * Signature: (IJZ)Z + */ +JNIEXPORT jboolean JNICALL +Java_edu_wpi_first_networktables_NetworkTablesJNI_setBoolean + (JNIEnv*, jclass, jint entry, jlong time, jboolean value) +{ + return nt::SetBoolean(entry, value != JNI_FALSE, time); +} + +/* + * Class: edu_wpi_first_networktables_NetworkTablesJNI + * Method: getBoolean + * Signature: (IZ)Z + */ +JNIEXPORT jboolean JNICALL +Java_edu_wpi_first_networktables_NetworkTablesJNI_getBoolean + (JNIEnv*, jclass, jint entry, jboolean defaultValue) +{ + return nt::GetBoolean(entry, defaultValue); +} + +/* + * Class: edu_wpi_first_networktables_NetworkTablesJNI + * Method: setDefaultBoolean + * Signature: (IJZ)Z + */ +JNIEXPORT jboolean JNICALL +Java_edu_wpi_first_networktables_NetworkTablesJNI_setDefaultBoolean + (JNIEnv*, jclass, jint entry, jlong, jboolean defaultValue) +{ + return nt::SetDefaultBoolean(entry, defaultValue != JNI_FALSE); +} + + +/* + * Class: edu_wpi_first_networktables_NetworkTablesJNI + * Method: getAtomicInteger + * Signature: (IJ)Ledu/wpi/first/networktables/TimestampedInteger; + */ +JNIEXPORT jobject JNICALL +Java_edu_wpi_first_networktables_NetworkTablesJNI_getAtomicInteger + (JNIEnv* env, jclass, jint subentry, jlong defaultValue) +{ + return MakeJObject(env, nt::GetAtomicInteger(subentry, defaultValue)); +} + +/* + * Class: edu_wpi_first_networktables_NetworkTablesJNI + * Method: readQueueInteger + * Signature: (I)[Ledu/wpi/first/networktables/TimestampedInteger; + */ +JNIEXPORT jobjectArray JNICALL +Java_edu_wpi_first_networktables_NetworkTablesJNI_readQueueInteger + (JNIEnv* env, jclass, jint subentry) +{ + return MakeJObject(env, nt::ReadQueueInteger(subentry)); +} + +/* + * Class: edu_wpi_first_networktables_NetworkTablesJNI + * Method: readQueueValuesInteger + * Signature: (I)[J + */ +JNIEXPORT jlongArray JNICALL +Java_edu_wpi_first_networktables_NetworkTablesJNI_readQueueValuesInteger + (JNIEnv* env, jclass, jint subentry) +{ + return MakeJLongArray(env, nt::ReadQueueValuesInteger(subentry)); +} + +/* + * Class: edu_wpi_first_networktables_NetworkTablesJNI + * Method: setInteger + * Signature: (IJJ)Z + */ +JNIEXPORT jboolean JNICALL +Java_edu_wpi_first_networktables_NetworkTablesJNI_setInteger + (JNIEnv*, jclass, jint entry, jlong time, jlong value) +{ + return nt::SetInteger(entry, value, time); +} + +/* + * Class: edu_wpi_first_networktables_NetworkTablesJNI + * Method: getInteger + * Signature: (IJ)J + */ +JNIEXPORT jlong JNICALL +Java_edu_wpi_first_networktables_NetworkTablesJNI_getInteger + (JNIEnv*, jclass, jint entry, jlong defaultValue) +{ + return nt::GetInteger(entry, defaultValue); +} + +/* + * Class: edu_wpi_first_networktables_NetworkTablesJNI + * Method: setDefaultInteger + * Signature: (IJJ)Z + */ +JNIEXPORT jboolean JNICALL +Java_edu_wpi_first_networktables_NetworkTablesJNI_setDefaultInteger + (JNIEnv*, jclass, jint entry, jlong, jlong defaultValue) +{ + return nt::SetDefaultInteger(entry, defaultValue); +} + + +/* + * Class: edu_wpi_first_networktables_NetworkTablesJNI + * Method: getAtomicFloat + * Signature: (IF)Ledu/wpi/first/networktables/TimestampedFloat; + */ +JNIEXPORT jobject JNICALL +Java_edu_wpi_first_networktables_NetworkTablesJNI_getAtomicFloat + (JNIEnv* env, jclass, jint subentry, jfloat defaultValue) +{ + return MakeJObject(env, nt::GetAtomicFloat(subentry, defaultValue)); +} + +/* + * Class: edu_wpi_first_networktables_NetworkTablesJNI + * Method: readQueueFloat + * Signature: (I)[Ledu/wpi/first/networktables/TimestampedFloat; + */ +JNIEXPORT jobjectArray JNICALL +Java_edu_wpi_first_networktables_NetworkTablesJNI_readQueueFloat + (JNIEnv* env, jclass, jint subentry) +{ + return MakeJObject(env, nt::ReadQueueFloat(subentry)); +} + +/* + * Class: edu_wpi_first_networktables_NetworkTablesJNI + * Method: readQueueValuesFloat + * Signature: (I)[F + */ +JNIEXPORT jfloatArray JNICALL +Java_edu_wpi_first_networktables_NetworkTablesJNI_readQueueValuesFloat + (JNIEnv* env, jclass, jint subentry) +{ + return MakeJFloatArray(env, nt::ReadQueueValuesFloat(subentry)); +} + +/* + * Class: edu_wpi_first_networktables_NetworkTablesJNI + * Method: setFloat + * Signature: (IJF)Z + */ +JNIEXPORT jboolean JNICALL +Java_edu_wpi_first_networktables_NetworkTablesJNI_setFloat + (JNIEnv*, jclass, jint entry, jlong time, jfloat value) +{ + return nt::SetFloat(entry, value, time); +} + +/* + * Class: edu_wpi_first_networktables_NetworkTablesJNI + * Method: getFloat + * Signature: (IF)F + */ +JNIEXPORT jfloat JNICALL +Java_edu_wpi_first_networktables_NetworkTablesJNI_getFloat + (JNIEnv*, jclass, jint entry, jfloat defaultValue) +{ + return nt::GetFloat(entry, defaultValue); +} + +/* + * Class: edu_wpi_first_networktables_NetworkTablesJNI + * Method: setDefaultFloat + * Signature: (IJF)Z + */ +JNIEXPORT jboolean JNICALL +Java_edu_wpi_first_networktables_NetworkTablesJNI_setDefaultFloat + (JNIEnv*, jclass, jint entry, jlong, jfloat defaultValue) +{ + return nt::SetDefaultFloat(entry, defaultValue); +} + + +/* + * Class: edu_wpi_first_networktables_NetworkTablesJNI + * Method: getAtomicDouble + * Signature: (ID)Ledu/wpi/first/networktables/TimestampedDouble; + */ +JNIEXPORT jobject JNICALL +Java_edu_wpi_first_networktables_NetworkTablesJNI_getAtomicDouble + (JNIEnv* env, jclass, jint subentry, jdouble defaultValue) +{ + return MakeJObject(env, nt::GetAtomicDouble(subentry, defaultValue)); +} + +/* + * Class: edu_wpi_first_networktables_NetworkTablesJNI + * Method: readQueueDouble + * Signature: (I)[Ledu/wpi/first/networktables/TimestampedDouble; + */ +JNIEXPORT jobjectArray JNICALL +Java_edu_wpi_first_networktables_NetworkTablesJNI_readQueueDouble + (JNIEnv* env, jclass, jint subentry) +{ + return MakeJObject(env, nt::ReadQueueDouble(subentry)); +} + +/* + * Class: edu_wpi_first_networktables_NetworkTablesJNI + * Method: readQueueValuesDouble + * Signature: (I)[D + */ +JNIEXPORT jdoubleArray JNICALL +Java_edu_wpi_first_networktables_NetworkTablesJNI_readQueueValuesDouble + (JNIEnv* env, jclass, jint subentry) +{ + return MakeJDoubleArray(env, nt::ReadQueueValuesDouble(subentry)); +} + +/* + * Class: edu_wpi_first_networktables_NetworkTablesJNI + * Method: setDouble + * Signature: (IJD)Z + */ +JNIEXPORT jboolean JNICALL +Java_edu_wpi_first_networktables_NetworkTablesJNI_setDouble + (JNIEnv*, jclass, jint entry, jlong time, jdouble value) +{ + return nt::SetDouble(entry, value, time); +} + +/* + * Class: edu_wpi_first_networktables_NetworkTablesJNI + * Method: getDouble + * Signature: (ID)D + */ +JNIEXPORT jdouble JNICALL +Java_edu_wpi_first_networktables_NetworkTablesJNI_getDouble + (JNIEnv*, jclass, jint entry, jdouble defaultValue) +{ + return nt::GetDouble(entry, defaultValue); +} + +/* + * Class: edu_wpi_first_networktables_NetworkTablesJNI + * Method: setDefaultDouble + * Signature: (IJD)Z + */ +JNIEXPORT jboolean JNICALL +Java_edu_wpi_first_networktables_NetworkTablesJNI_setDefaultDouble + (JNIEnv*, jclass, jint entry, jlong, jdouble defaultValue) +{ + return nt::SetDefaultDouble(entry, defaultValue); +} + + +/* + * Class: edu_wpi_first_networktables_NetworkTablesJNI + * Method: getAtomicString + * Signature: (ILjava/lang/String;)Ledu/wpi/first/networktables/TimestampedString; + */ +JNIEXPORT jobject JNICALL +Java_edu_wpi_first_networktables_NetworkTablesJNI_getAtomicString + (JNIEnv* env, jclass, jint subentry, jstring defaultValue) +{ + return MakeJObject(env, nt::GetAtomicString(subentry, JStringRef{env, defaultValue})); +} + +/* + * Class: edu_wpi_first_networktables_NetworkTablesJNI + * Method: readQueueString + * Signature: (I)[Ledu/wpi/first/networktables/TimestampedString; + */ +JNIEXPORT jobjectArray JNICALL +Java_edu_wpi_first_networktables_NetworkTablesJNI_readQueueString + (JNIEnv* env, jclass, jint subentry) +{ + return MakeJObject(env, nt::ReadQueueString(subentry)); +} + +/* + * Class: edu_wpi_first_networktables_NetworkTablesJNI + * Method: readQueueValuesString + * Signature: (I)[Ljava/lang/String; + */ +JNIEXPORT jobjectArray JNICALL +Java_edu_wpi_first_networktables_NetworkTablesJNI_readQueueValuesString + (JNIEnv* env, jclass, jint subentry) +{ + return MakeJStringArray(env, nt::ReadQueueValuesString(subentry)); +} + +/* + * Class: edu_wpi_first_networktables_NetworkTablesJNI + * Method: setString + * Signature: (IJLjava/lang/String;)Z + */ +JNIEXPORT jboolean JNICALL +Java_edu_wpi_first_networktables_NetworkTablesJNI_setString + (JNIEnv* env, jclass, jint entry, jlong time, jstring value) +{ + if (!value) { + nullPointerEx.Throw(env, "value cannot be null"); + return false; + } + return nt::SetString(entry, JStringRef{env, value}, time); +} + +/* + * Class: edu_wpi_first_networktables_NetworkTablesJNI + * Method: getString + * Signature: (ILjava/lang/String;)Ljava/lang/String; + */ +JNIEXPORT jstring JNICALL +Java_edu_wpi_first_networktables_NetworkTablesJNI_getString + (JNIEnv* env, jclass, jint entry, jstring defaultValue) +{ + auto val = nt::GetEntryValue(entry); + if (!val || !val.IsString()) { + return defaultValue; + } + return MakeJString(env, val.GetString()); +} + +/* + * Class: edu_wpi_first_networktables_NetworkTablesJNI + * Method: setDefaultString + * Signature: (IJLjava/lang/String;)Z + */ +JNIEXPORT jboolean JNICALL +Java_edu_wpi_first_networktables_NetworkTablesJNI_setDefaultString + (JNIEnv* env, jclass, jint entry, jlong, jstring defaultValue) +{ + if (!defaultValue) { + nullPointerEx.Throw(env, "defaultValue cannot be null"); + return false; + } + return nt::SetDefaultString(entry, JStringRef{env, defaultValue}); +} + + +/* + * Class: edu_wpi_first_networktables_NetworkTablesJNI + * Method: getAtomicRaw + * Signature: (I[B)Ledu/wpi/first/networktables/TimestampedRaw; + */ +JNIEXPORT jobject JNICALL +Java_edu_wpi_first_networktables_NetworkTablesJNI_getAtomicRaw + (JNIEnv* env, jclass, jint subentry, jbyteArray defaultValue) +{ + return MakeJObject(env, nt::GetAtomicRaw(subentry, CriticalJSpan{env, defaultValue}.uarray())); +} + +/* + * Class: edu_wpi_first_networktables_NetworkTablesJNI + * Method: readQueueRaw + * Signature: (I)[Ledu/wpi/first/networktables/TimestampedRaw; + */ +JNIEXPORT jobjectArray JNICALL +Java_edu_wpi_first_networktables_NetworkTablesJNI_readQueueRaw + (JNIEnv* env, jclass, jint subentry) +{ + return MakeJObject(env, nt::ReadQueueRaw(subentry)); +} + +/* + * Class: edu_wpi_first_networktables_NetworkTablesJNI + * Method: readQueueValuesRaw + * Signature: (I)[[B + */ +JNIEXPORT jobjectArray JNICALL +Java_edu_wpi_first_networktables_NetworkTablesJNI_readQueueValuesRaw + (JNIEnv* env, jclass, jint subentry) +{ + return MakeJObjectArray(env, nt::ReadQueueValuesRaw(subentry)); +} + +/* + * Class: edu_wpi_first_networktables_NetworkTablesJNI + * Method: setRaw + * Signature: (IJ[BII)Z + */ +JNIEXPORT jboolean JNICALL +Java_edu_wpi_first_networktables_NetworkTablesJNI_setRaw + (JNIEnv* env, jclass, jint entry, jlong time, jbyteArray value, jint start, jint len) +{ + if (!value) { + nullPointerEx.Throw(env, "value is null"); + return false; + } + if (start < 0) { + indexOobEx.Throw(env, "start must be >= 0"); + return false; + } + if (len < 0) { + indexOobEx.Throw(env, "len must be >= 0"); + return false; + } + CriticalJSpan cvalue{env, value}; + if (static_cast(start + len) > cvalue.size()) { + indexOobEx.Throw(env, "start + len must be smaller than array length"); + return false; + } + return nt::SetRaw(entry, cvalue.uarray().subspan(start, len), time); +} + +/* + * Class: edu_wpi_first_networktables_NetworkTablesJNI + * Method: setRawBuffer + * Signature: (IJLjava/nio/ByteBuffer;II)Z + */ +JNIEXPORT jboolean JNICALL +Java_edu_wpi_first_networktables_NetworkTablesJNI_setRawBuffer + (JNIEnv* env, jclass, jint entry, jlong time, jobject value, jint start, jint len) +{ + if (!value) { + nullPointerEx.Throw(env, "value is null"); + return false; + } + if (start < 0) { + indexOobEx.Throw(env, "start must be >= 0"); + return false; + } + if (len < 0) { + indexOobEx.Throw(env, "len must be >= 0"); + return false; + } + JSpan cvalue{env, value, static_cast(start + len)}; + if (!cvalue) { + illegalArgEx.Throw(env, "value must be a native ByteBuffer"); + return false; + } + return nt::SetRaw(entry, cvalue.uarray().subspan(start, len), time); +} + +/* + * Class: edu_wpi_first_networktables_NetworkTablesJNI + * Method: getRaw + * Signature: (I[B)[B + */ +JNIEXPORT jbyteArray JNICALL +Java_edu_wpi_first_networktables_NetworkTablesJNI_getRaw + (JNIEnv* env, jclass, jint entry, jbyteArray defaultValue) +{ + auto val = nt::GetEntryValue(entry); + if (!val || !val.IsRaw()) { + return defaultValue; + } + return MakeJByteArray(env, val.GetRaw()); +} + +/* + * Class: edu_wpi_first_networktables_NetworkTablesJNI + * Method: setDefaultRaw + * Signature: (IJ[BII)Z + */ +JNIEXPORT jboolean JNICALL +Java_edu_wpi_first_networktables_NetworkTablesJNI_setDefaultRaw + (JNIEnv* env, jclass, jint entry, jlong, jbyteArray defaultValue, jint start, jint len) +{ + if (!defaultValue) { + nullPointerEx.Throw(env, "value is null"); + return false; + } + if (start < 0) { + indexOobEx.Throw(env, "start must be >= 0"); + return false; + } + if (len < 0) { + indexOobEx.Throw(env, "len must be >= 0"); + return false; + } + CriticalJSpan cvalue{env, defaultValue}; + if (static_cast(start + len) > cvalue.size()) { + indexOobEx.Throw(env, "start + len must be smaller than array length"); + return false; + } + return nt::SetDefaultRaw(entry, cvalue.uarray().subspan(start, len)); +} + +/* + * Class: edu_wpi_first_networktables_NetworkTablesJNI + * Method: setDefaultRawBuffer + * Signature: (IJLjava/nio/ByteBuffer;II)Z + */ +JNIEXPORT jboolean JNICALL +Java_edu_wpi_first_networktables_NetworkTablesJNI_setDefaultRawBuffer + (JNIEnv* env, jclass, jint entry, jlong, jobject defaultValue, jint start, jint len) +{ + if (!defaultValue) { + nullPointerEx.Throw(env, "value is null"); + return false; + } + if (start < 0) { + indexOobEx.Throw(env, "start must be >= 0"); + return false; + } + if (len < 0) { + indexOobEx.Throw(env, "len must be >= 0"); + return false; + } + JSpan cvalue{env, defaultValue, static_cast(start + len)}; + if (!cvalue) { + illegalArgEx.Throw(env, "value must be a native ByteBuffer"); + return false; + } + return nt::SetDefaultRaw(entry, cvalue.uarray().subspan(start, len)); +} + + +/* + * Class: edu_wpi_first_networktables_NetworkTablesJNI + * Method: getAtomicBooleanArray + * Signature: (I[Z)Ledu/wpi/first/networktables/TimestampedBooleanArray; + */ +JNIEXPORT jobject JNICALL +Java_edu_wpi_first_networktables_NetworkTablesJNI_getAtomicBooleanArray + (JNIEnv* env, jclass, jint subentry, jbooleanArray defaultValue) +{ + return MakeJObject(env, nt::GetAtomicBooleanArray(subentry, FromJavaBooleanArray(env, defaultValue))); +} + +/* + * Class: edu_wpi_first_networktables_NetworkTablesJNI + * Method: readQueueBooleanArray + * Signature: (I)[Ledu/wpi/first/networktables/TimestampedBooleanArray; + */ +JNIEXPORT jobjectArray JNICALL +Java_edu_wpi_first_networktables_NetworkTablesJNI_readQueueBooleanArray + (JNIEnv* env, jclass, jint subentry) +{ + return MakeJObject(env, nt::ReadQueueBooleanArray(subentry)); +} + +/* + * Class: edu_wpi_first_networktables_NetworkTablesJNI + * Method: readQueueValuesBooleanArray + * Signature: (I)[[Z + */ +JNIEXPORT jobjectArray JNICALL +Java_edu_wpi_first_networktables_NetworkTablesJNI_readQueueValuesBooleanArray + (JNIEnv* env, jclass, jint subentry) +{ + return MakeJObjectArray(env, nt::ReadQueueValuesBooleanArray(subentry)); +} + +/* + * Class: edu_wpi_first_networktables_NetworkTablesJNI + * Method: setBooleanArray + * Signature: (IJ[Z)Z + */ +JNIEXPORT jboolean JNICALL +Java_edu_wpi_first_networktables_NetworkTablesJNI_setBooleanArray + (JNIEnv* env, jclass, jint entry, jlong time, jbooleanArray value) +{ + if (!value) { + nullPointerEx.Throw(env, "value cannot be null"); + return false; + } + return nt::SetBooleanArray(entry, FromJavaBooleanArray(env, value), time); +} + +/* + * Class: edu_wpi_first_networktables_NetworkTablesJNI + * Method: getBooleanArray + * Signature: (I[Z)[Z + */ +JNIEXPORT jbooleanArray JNICALL +Java_edu_wpi_first_networktables_NetworkTablesJNI_getBooleanArray + (JNIEnv* env, jclass, jint entry, jbooleanArray defaultValue) +{ + auto val = nt::GetEntryValue(entry); + if (!val || !val.IsBooleanArray()) { + return defaultValue; + } + return MakeJBooleanArray(env, val.GetBooleanArray()); +} + +/* + * Class: edu_wpi_first_networktables_NetworkTablesJNI + * Method: setDefaultBooleanArray + * Signature: (IJ[Z)Z + */ +JNIEXPORT jboolean JNICALL +Java_edu_wpi_first_networktables_NetworkTablesJNI_setDefaultBooleanArray + (JNIEnv* env, jclass, jint entry, jlong, jbooleanArray defaultValue) +{ + if (!defaultValue) { + nullPointerEx.Throw(env, "defaultValue cannot be null"); + return false; + } + return nt::SetDefaultBooleanArray(entry, FromJavaBooleanArray(env, defaultValue)); +} + + +/* + * Class: edu_wpi_first_networktables_NetworkTablesJNI + * Method: getAtomicIntegerArray + * Signature: (I[J)Ledu/wpi/first/networktables/TimestampedIntegerArray; + */ +JNIEXPORT jobject JNICALL +Java_edu_wpi_first_networktables_NetworkTablesJNI_getAtomicIntegerArray + (JNIEnv* env, jclass, jint subentry, jlongArray defaultValue) +{ + return MakeJObject(env, nt::GetAtomicIntegerArray(subentry, CriticalJSpan{env, defaultValue})); +} + +/* + * Class: edu_wpi_first_networktables_NetworkTablesJNI + * Method: readQueueIntegerArray + * Signature: (I)[Ledu/wpi/first/networktables/TimestampedIntegerArray; + */ +JNIEXPORT jobjectArray JNICALL +Java_edu_wpi_first_networktables_NetworkTablesJNI_readQueueIntegerArray + (JNIEnv* env, jclass, jint subentry) +{ + return MakeJObject(env, nt::ReadQueueIntegerArray(subentry)); +} + +/* + * Class: edu_wpi_first_networktables_NetworkTablesJNI + * Method: readQueueValuesIntegerArray + * Signature: (I)[[J + */ +JNIEXPORT jobjectArray JNICALL +Java_edu_wpi_first_networktables_NetworkTablesJNI_readQueueValuesIntegerArray + (JNIEnv* env, jclass, jint subentry) +{ + return MakeJObjectArray(env, nt::ReadQueueValuesIntegerArray(subentry)); +} + +/* + * Class: edu_wpi_first_networktables_NetworkTablesJNI + * Method: setIntegerArray + * Signature: (IJ[J)Z + */ +JNIEXPORT jboolean JNICALL +Java_edu_wpi_first_networktables_NetworkTablesJNI_setIntegerArray + (JNIEnv* env, jclass, jint entry, jlong time, jlongArray value) +{ + if (!value) { + nullPointerEx.Throw(env, "value cannot be null"); + return false; + } + return nt::SetIntegerArray(entry, CriticalJSpan{env, value}, time); +} + +/* + * Class: edu_wpi_first_networktables_NetworkTablesJNI + * Method: getIntegerArray + * Signature: (I[J)[J + */ +JNIEXPORT jlongArray JNICALL +Java_edu_wpi_first_networktables_NetworkTablesJNI_getIntegerArray + (JNIEnv* env, jclass, jint entry, jlongArray defaultValue) +{ + auto val = nt::GetEntryValue(entry); + if (!val || !val.IsIntegerArray()) { + return defaultValue; + } + return MakeJLongArray(env, val.GetIntegerArray()); +} + +/* + * Class: edu_wpi_first_networktables_NetworkTablesJNI + * Method: setDefaultIntegerArray + * Signature: (IJ[J)Z + */ +JNIEXPORT jboolean JNICALL +Java_edu_wpi_first_networktables_NetworkTablesJNI_setDefaultIntegerArray + (JNIEnv* env, jclass, jint entry, jlong, jlongArray defaultValue) +{ + if (!defaultValue) { + nullPointerEx.Throw(env, "defaultValue cannot be null"); + return false; + } + return nt::SetDefaultIntegerArray(entry, CriticalJSpan{env, defaultValue}); +} + + +/* + * Class: edu_wpi_first_networktables_NetworkTablesJNI + * Method: getAtomicFloatArray + * Signature: (I[F)Ledu/wpi/first/networktables/TimestampedFloatArray; + */ +JNIEXPORT jobject JNICALL +Java_edu_wpi_first_networktables_NetworkTablesJNI_getAtomicFloatArray + (JNIEnv* env, jclass, jint subentry, jfloatArray defaultValue) +{ + return MakeJObject(env, nt::GetAtomicFloatArray(subentry, CriticalJSpan{env, defaultValue})); +} + +/* + * Class: edu_wpi_first_networktables_NetworkTablesJNI + * Method: readQueueFloatArray + * Signature: (I)[Ledu/wpi/first/networktables/TimestampedFloatArray; + */ +JNIEXPORT jobjectArray JNICALL +Java_edu_wpi_first_networktables_NetworkTablesJNI_readQueueFloatArray + (JNIEnv* env, jclass, jint subentry) +{ + return MakeJObject(env, nt::ReadQueueFloatArray(subentry)); +} + +/* + * Class: edu_wpi_first_networktables_NetworkTablesJNI + * Method: readQueueValuesFloatArray + * Signature: (I)[[F + */ +JNIEXPORT jobjectArray JNICALL +Java_edu_wpi_first_networktables_NetworkTablesJNI_readQueueValuesFloatArray + (JNIEnv* env, jclass, jint subentry) +{ + return MakeJObjectArray(env, nt::ReadQueueValuesFloatArray(subentry)); +} + +/* + * Class: edu_wpi_first_networktables_NetworkTablesJNI + * Method: setFloatArray + * Signature: (IJ[F)Z + */ +JNIEXPORT jboolean JNICALL +Java_edu_wpi_first_networktables_NetworkTablesJNI_setFloatArray + (JNIEnv* env, jclass, jint entry, jlong time, jfloatArray value) +{ + if (!value) { + nullPointerEx.Throw(env, "value cannot be null"); + return false; + } + return nt::SetFloatArray(entry, CriticalJSpan{env, value}, time); +} + +/* + * Class: edu_wpi_first_networktables_NetworkTablesJNI + * Method: getFloatArray + * Signature: (I[F)[F + */ +JNIEXPORT jfloatArray JNICALL +Java_edu_wpi_first_networktables_NetworkTablesJNI_getFloatArray + (JNIEnv* env, jclass, jint entry, jfloatArray defaultValue) +{ + auto val = nt::GetEntryValue(entry); + if (!val || !val.IsFloatArray()) { + return defaultValue; + } + return MakeJFloatArray(env, val.GetFloatArray()); +} + +/* + * Class: edu_wpi_first_networktables_NetworkTablesJNI + * Method: setDefaultFloatArray + * Signature: (IJ[F)Z + */ +JNIEXPORT jboolean JNICALL +Java_edu_wpi_first_networktables_NetworkTablesJNI_setDefaultFloatArray + (JNIEnv* env, jclass, jint entry, jlong, jfloatArray defaultValue) +{ + if (!defaultValue) { + nullPointerEx.Throw(env, "defaultValue cannot be null"); + return false; + } + return nt::SetDefaultFloatArray(entry, CriticalJSpan{env, defaultValue}); +} + + +/* + * Class: edu_wpi_first_networktables_NetworkTablesJNI + * Method: getAtomicDoubleArray + * Signature: (I[D)Ledu/wpi/first/networktables/TimestampedDoubleArray; + */ +JNIEXPORT jobject JNICALL +Java_edu_wpi_first_networktables_NetworkTablesJNI_getAtomicDoubleArray + (JNIEnv* env, jclass, jint subentry, jdoubleArray defaultValue) +{ + return MakeJObject(env, nt::GetAtomicDoubleArray(subentry, CriticalJSpan{env, defaultValue})); +} + +/* + * Class: edu_wpi_first_networktables_NetworkTablesJNI + * Method: readQueueDoubleArray + * Signature: (I)[Ledu/wpi/first/networktables/TimestampedDoubleArray; + */ +JNIEXPORT jobjectArray JNICALL +Java_edu_wpi_first_networktables_NetworkTablesJNI_readQueueDoubleArray + (JNIEnv* env, jclass, jint subentry) +{ + return MakeJObject(env, nt::ReadQueueDoubleArray(subentry)); +} + +/* + * Class: edu_wpi_first_networktables_NetworkTablesJNI + * Method: readQueueValuesDoubleArray + * Signature: (I)[[D + */ +JNIEXPORT jobjectArray JNICALL +Java_edu_wpi_first_networktables_NetworkTablesJNI_readQueueValuesDoubleArray + (JNIEnv* env, jclass, jint subentry) +{ + return MakeJObjectArray(env, nt::ReadQueueValuesDoubleArray(subentry)); +} + +/* + * Class: edu_wpi_first_networktables_NetworkTablesJNI + * Method: setDoubleArray + * Signature: (IJ[D)Z + */ +JNIEXPORT jboolean JNICALL +Java_edu_wpi_first_networktables_NetworkTablesJNI_setDoubleArray + (JNIEnv* env, jclass, jint entry, jlong time, jdoubleArray value) +{ + if (!value) { + nullPointerEx.Throw(env, "value cannot be null"); + return false; + } + return nt::SetDoubleArray(entry, CriticalJSpan{env, value}, time); +} + +/* + * Class: edu_wpi_first_networktables_NetworkTablesJNI + * Method: getDoubleArray + * Signature: (I[D)[D + */ +JNIEXPORT jdoubleArray JNICALL +Java_edu_wpi_first_networktables_NetworkTablesJNI_getDoubleArray + (JNIEnv* env, jclass, jint entry, jdoubleArray defaultValue) +{ + auto val = nt::GetEntryValue(entry); + if (!val || !val.IsDoubleArray()) { + return defaultValue; + } + return MakeJDoubleArray(env, val.GetDoubleArray()); +} + +/* + * Class: edu_wpi_first_networktables_NetworkTablesJNI + * Method: setDefaultDoubleArray + * Signature: (IJ[D)Z + */ +JNIEXPORT jboolean JNICALL +Java_edu_wpi_first_networktables_NetworkTablesJNI_setDefaultDoubleArray + (JNIEnv* env, jclass, jint entry, jlong, jdoubleArray defaultValue) +{ + if (!defaultValue) { + nullPointerEx.Throw(env, "defaultValue cannot be null"); + return false; + } + return nt::SetDefaultDoubleArray(entry, CriticalJSpan{env, defaultValue}); +} + + +/* + * Class: edu_wpi_first_networktables_NetworkTablesJNI + * Method: getAtomicStringArray + * Signature: (I[Ljava/lang/Object;)Ledu/wpi/first/networktables/TimestampedStringArray; + */ +JNIEXPORT jobject JNICALL +Java_edu_wpi_first_networktables_NetworkTablesJNI_getAtomicStringArray + (JNIEnv* env, jclass, jint subentry, jobjectArray defaultValue) +{ + return MakeJObject(env, nt::GetAtomicStringArray(subentry, FromJavaStringArray(env, defaultValue))); +} + +/* + * Class: edu_wpi_first_networktables_NetworkTablesJNI + * Method: readQueueStringArray + * Signature: (I)[Ledu/wpi/first/networktables/TimestampedStringArray; + */ +JNIEXPORT jobjectArray JNICALL +Java_edu_wpi_first_networktables_NetworkTablesJNI_readQueueStringArray + (JNIEnv* env, jclass, jint subentry) +{ + return MakeJObject(env, nt::ReadQueueStringArray(subentry)); +} + +/* + * Class: edu_wpi_first_networktables_NetworkTablesJNI + * Method: readQueueValuesStringArray + * Signature: (I)[[Ljava/lang/Object; + */ +JNIEXPORT jobjectArray JNICALL +Java_edu_wpi_first_networktables_NetworkTablesJNI_readQueueValuesStringArray + (JNIEnv* env, jclass, jint subentry) +{ + return MakeJObjectArray(env, nt::ReadQueueValuesStringArray(subentry)); +} + +/* + * Class: edu_wpi_first_networktables_NetworkTablesJNI + * Method: setStringArray + * Signature: (IJ[Ljava/lang/Object;)Z + */ +JNIEXPORT jboolean JNICALL +Java_edu_wpi_first_networktables_NetworkTablesJNI_setStringArray + (JNIEnv* env, jclass, jint entry, jlong time, jobjectArray value) +{ + if (!value) { + nullPointerEx.Throw(env, "value cannot be null"); + return false; + } + return nt::SetStringArray(entry, FromJavaStringArray(env, value), time); +} + +/* + * Class: edu_wpi_first_networktables_NetworkTablesJNI + * Method: getStringArray + * Signature: (I[Ljava/lang/Object;)[Ljava/lang/Object; + */ +JNIEXPORT jobjectArray JNICALL +Java_edu_wpi_first_networktables_NetworkTablesJNI_getStringArray + (JNIEnv* env, jclass, jint entry, jobjectArray defaultValue) +{ + auto val = nt::GetEntryValue(entry); + if (!val || !val.IsStringArray()) { + return defaultValue; + } + return MakeJStringArray(env, val.GetStringArray()); +} + +/* + * Class: edu_wpi_first_networktables_NetworkTablesJNI + * Method: setDefaultStringArray + * Signature: (IJ[Ljava/lang/Object;)Z + */ +JNIEXPORT jboolean JNICALL +Java_edu_wpi_first_networktables_NetworkTablesJNI_setDefaultStringArray + (JNIEnv* env, jclass, jint entry, jlong, jobjectArray defaultValue) +{ + if (!defaultValue) { + nullPointerEx.Throw(env, "defaultValue cannot be null"); + return false; + } + return nt::SetDefaultStringArray(entry, FromJavaStringArray(env, defaultValue)); +} + + +} // extern "C" diff --git a/ntcore/src/generated/main/native/cpp/ntcore_c_types.cpp b/ntcore/src/generated/main/native/cpp/ntcore_c_types.cpp new file mode 100644 index 0000000000..ca14c7d6cd --- /dev/null +++ b/ntcore/src/generated/main/native/cpp/ntcore_c_types.cpp @@ -0,0 +1,495 @@ +// 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. + +// THIS FILE WAS AUTO-GENERATED BY ./ntcore/generate_topics.py. DO NOT MODIFY + +#include "ntcore_c_types.h" + +#include "Value_internal.h" +#include "ntcore_cpp.h" + +using namespace nt; + +template +static inline std::span ConvertFromC(const T* arr, size_t size) { + return {arr, size}; +} + +static inline std::string_view ConvertFromC(const char* arr, size_t size) { + return {arr, size}; +} + +static std::vector ConvertFromC(const NT_String* arr, size_t size) { + std::vector v; + v.reserve(size); + for (size_t i = 0; i < size; ++i) { + v.emplace_back(ConvertFromC(arr[i])); + } + return v; +} + + +static void ConvertToC(const nt::TimestampedBoolean& in, NT_TimestampedBoolean* out) { + out->time = in.time; + out->serverTime = in.serverTime; + out->value = in.value; +} + +static void ConvertToC(const nt::TimestampedInteger& in, NT_TimestampedInteger* out) { + out->time = in.time; + out->serverTime = in.serverTime; + out->value = in.value; +} + +static void ConvertToC(const nt::TimestampedFloat& in, NT_TimestampedFloat* out) { + out->time = in.time; + out->serverTime = in.serverTime; + out->value = in.value; +} + +static void ConvertToC(const nt::TimestampedDouble& in, NT_TimestampedDouble* out) { + out->time = in.time; + out->serverTime = in.serverTime; + out->value = in.value; +} + +static void ConvertToC(const nt::TimestampedString& in, NT_TimestampedString* out) { + out->time = in.time; + out->serverTime = in.serverTime; + out->value = ConvertToC(in.value, &out->len); +} + +static void ConvertToC(const nt::TimestampedRaw& in, NT_TimestampedRaw* out) { + out->time = in.time; + out->serverTime = in.serverTime; + out->value = ConvertToC(in.value, &out->len); +} + +static void ConvertToC(const nt::TimestampedBooleanArray& in, NT_TimestampedBooleanArray* out) { + out->time = in.time; + out->serverTime = in.serverTime; + out->value = ConvertToC(in.value, &out->len); +} + +static void ConvertToC(const nt::TimestampedIntegerArray& in, NT_TimestampedIntegerArray* out) { + out->time = in.time; + out->serverTime = in.serverTime; + out->value = ConvertToC(in.value, &out->len); +} + +static void ConvertToC(const nt::TimestampedFloatArray& in, NT_TimestampedFloatArray* out) { + out->time = in.time; + out->serverTime = in.serverTime; + out->value = ConvertToC(in.value, &out->len); +} + +static void ConvertToC(const nt::TimestampedDoubleArray& in, NT_TimestampedDoubleArray* out) { + out->time = in.time; + out->serverTime = in.serverTime; + out->value = ConvertToC(in.value, &out->len); +} + +static void ConvertToC(const nt::TimestampedStringArray& in, NT_TimestampedStringArray* out) { + out->time = in.time; + out->serverTime = in.serverTime; + out->value = ConvertToC(in.value, &out->len); +} + + +extern "C" { + +NT_Bool NT_SetBoolean(NT_Handle pubentry, int64_t time, NT_Bool value) { + return nt::SetBoolean(pubentry, value, time); +} + +NT_Bool NT_SetDefaultBoolean(NT_Handle pubentry, NT_Bool defaultValue) { + return nt::SetDefaultBoolean(pubentry, defaultValue); +} + +NT_Bool NT_GetBoolean(NT_Handle subentry, NT_Bool defaultValue) { + return nt::GetBoolean(subentry, defaultValue); +} + +void NT_GetAtomicBoolean(NT_Handle subentry, NT_Bool defaultValue, struct NT_TimestampedBoolean* value) { + auto cppValue = nt::GetAtomicBoolean(subentry, defaultValue); + ConvertToC(cppValue, value); +} + +void NT_DisposeTimestampedBoolean(struct NT_TimestampedBoolean* value) { +} + +struct NT_TimestampedBoolean* NT_ReadQueueBoolean(NT_Handle subentry, size_t* len) { + auto arr = nt::ReadQueueBoolean(subentry); + return ConvertToC(arr, len); +} + +void NT_FreeQueueBoolean(struct NT_TimestampedBoolean* arr, size_t len) { + for (size_t i = 0; i < len; ++i) { + NT_DisposeTimestampedBoolean(&arr[i]); + } + std::free(arr); +} +NT_Bool* NT_ReadQueueValuesBoolean(NT_Handle subentry, size_t* len) { + auto arr = nt::ReadQueueValuesBoolean(subentry); + return ConvertToC(arr, len); +} + + +NT_Bool NT_SetInteger(NT_Handle pubentry, int64_t time, int64_t value) { + return nt::SetInteger(pubentry, value, time); +} + +NT_Bool NT_SetDefaultInteger(NT_Handle pubentry, int64_t defaultValue) { + return nt::SetDefaultInteger(pubentry, defaultValue); +} + +int64_t NT_GetInteger(NT_Handle subentry, int64_t defaultValue) { + return nt::GetInteger(subentry, defaultValue); +} + +void NT_GetAtomicInteger(NT_Handle subentry, int64_t defaultValue, struct NT_TimestampedInteger* value) { + auto cppValue = nt::GetAtomicInteger(subentry, defaultValue); + ConvertToC(cppValue, value); +} + +void NT_DisposeTimestampedInteger(struct NT_TimestampedInteger* value) { +} + +struct NT_TimestampedInteger* NT_ReadQueueInteger(NT_Handle subentry, size_t* len) { + auto arr = nt::ReadQueueInteger(subentry); + return ConvertToC(arr, len); +} + +void NT_FreeQueueInteger(struct NT_TimestampedInteger* arr, size_t len) { + for (size_t i = 0; i < len; ++i) { + NT_DisposeTimestampedInteger(&arr[i]); + } + std::free(arr); +} +int64_t* NT_ReadQueueValuesInteger(NT_Handle subentry, size_t* len) { + auto arr = nt::ReadQueueValuesInteger(subentry); + return ConvertToC(arr, len); +} + + +NT_Bool NT_SetFloat(NT_Handle pubentry, int64_t time, float value) { + return nt::SetFloat(pubentry, value, time); +} + +NT_Bool NT_SetDefaultFloat(NT_Handle pubentry, float defaultValue) { + return nt::SetDefaultFloat(pubentry, defaultValue); +} + +float NT_GetFloat(NT_Handle subentry, float defaultValue) { + return nt::GetFloat(subentry, defaultValue); +} + +void NT_GetAtomicFloat(NT_Handle subentry, float defaultValue, struct NT_TimestampedFloat* value) { + auto cppValue = nt::GetAtomicFloat(subentry, defaultValue); + ConvertToC(cppValue, value); +} + +void NT_DisposeTimestampedFloat(struct NT_TimestampedFloat* value) { +} + +struct NT_TimestampedFloat* NT_ReadQueueFloat(NT_Handle subentry, size_t* len) { + auto arr = nt::ReadQueueFloat(subentry); + return ConvertToC(arr, len); +} + +void NT_FreeQueueFloat(struct NT_TimestampedFloat* arr, size_t len) { + for (size_t i = 0; i < len; ++i) { + NT_DisposeTimestampedFloat(&arr[i]); + } + std::free(arr); +} +float* NT_ReadQueueValuesFloat(NT_Handle subentry, size_t* len) { + auto arr = nt::ReadQueueValuesFloat(subentry); + return ConvertToC(arr, len); +} + + +NT_Bool NT_SetDouble(NT_Handle pubentry, int64_t time, double value) { + return nt::SetDouble(pubentry, value, time); +} + +NT_Bool NT_SetDefaultDouble(NT_Handle pubentry, double defaultValue) { + return nt::SetDefaultDouble(pubentry, defaultValue); +} + +double NT_GetDouble(NT_Handle subentry, double defaultValue) { + return nt::GetDouble(subentry, defaultValue); +} + +void NT_GetAtomicDouble(NT_Handle subentry, double defaultValue, struct NT_TimestampedDouble* value) { + auto cppValue = nt::GetAtomicDouble(subentry, defaultValue); + ConvertToC(cppValue, value); +} + +void NT_DisposeTimestampedDouble(struct NT_TimestampedDouble* value) { +} + +struct NT_TimestampedDouble* NT_ReadQueueDouble(NT_Handle subentry, size_t* len) { + auto arr = nt::ReadQueueDouble(subentry); + return ConvertToC(arr, len); +} + +void NT_FreeQueueDouble(struct NT_TimestampedDouble* arr, size_t len) { + for (size_t i = 0; i < len; ++i) { + NT_DisposeTimestampedDouble(&arr[i]); + } + std::free(arr); +} +double* NT_ReadQueueValuesDouble(NT_Handle subentry, size_t* len) { + auto arr = nt::ReadQueueValuesDouble(subentry); + return ConvertToC(arr, len); +} + + +NT_Bool NT_SetString(NT_Handle pubentry, int64_t time, const char* value, size_t len) { + return nt::SetString(pubentry, ConvertFromC(value, len), time); +} + +NT_Bool NT_SetDefaultString(NT_Handle pubentry, const char* defaultValue, size_t defaultValueLen) { + return nt::SetDefaultString(pubentry, ConvertFromC(defaultValue, defaultValueLen)); +} + +char* NT_GetString(NT_Handle subentry, const char* defaultValue, size_t defaultValueLen, size_t* len) { + auto cppValue = nt::GetString(subentry, ConvertFromC(defaultValue, defaultValueLen)); + return ConvertToC(cppValue, len); +} + +void NT_GetAtomicString(NT_Handle subentry, const char* defaultValue, size_t defaultValueLen, struct NT_TimestampedString* value) { + auto cppValue = nt::GetAtomicString(subentry, ConvertFromC(defaultValue, defaultValueLen)); + ConvertToC(cppValue, value); +} + +void NT_DisposeTimestampedString(struct NT_TimestampedString* value) { + std::free(value->value); +} + +struct NT_TimestampedString* NT_ReadQueueString(NT_Handle subentry, size_t* len) { + auto arr = nt::ReadQueueString(subentry); + return ConvertToC(arr, len); +} + +void NT_FreeQueueString(struct NT_TimestampedString* arr, size_t len) { + for (size_t i = 0; i < len; ++i) { + NT_DisposeTimestampedString(&arr[i]); + } + std::free(arr); +} + + +NT_Bool NT_SetRaw(NT_Handle pubentry, int64_t time, const uint8_t* value, size_t len) { + return nt::SetRaw(pubentry, ConvertFromC(value, len), time); +} + +NT_Bool NT_SetDefaultRaw(NT_Handle pubentry, const uint8_t* defaultValue, size_t defaultValueLen) { + return nt::SetDefaultRaw(pubentry, ConvertFromC(defaultValue, defaultValueLen)); +} + +uint8_t* NT_GetRaw(NT_Handle subentry, const uint8_t* defaultValue, size_t defaultValueLen, size_t* len) { + auto cppValue = nt::GetRaw(subentry, ConvertFromC(defaultValue, defaultValueLen)); + return ConvertToC(cppValue, len); +} + +void NT_GetAtomicRaw(NT_Handle subentry, const uint8_t* defaultValue, size_t defaultValueLen, struct NT_TimestampedRaw* value) { + auto cppValue = nt::GetAtomicRaw(subentry, ConvertFromC(defaultValue, defaultValueLen)); + ConvertToC(cppValue, value); +} + +void NT_DisposeTimestampedRaw(struct NT_TimestampedRaw* value) { + std::free(value->value); +} + +struct NT_TimestampedRaw* NT_ReadQueueRaw(NT_Handle subentry, size_t* len) { + auto arr = nt::ReadQueueRaw(subentry); + return ConvertToC(arr, len); +} + +void NT_FreeQueueRaw(struct NT_TimestampedRaw* arr, size_t len) { + for (size_t i = 0; i < len; ++i) { + NT_DisposeTimestampedRaw(&arr[i]); + } + std::free(arr); +} + + +NT_Bool NT_SetBooleanArray(NT_Handle pubentry, int64_t time, const NT_Bool* value, size_t len) { + return nt::SetBooleanArray(pubentry, ConvertFromC(value, len), time); +} + +NT_Bool NT_SetDefaultBooleanArray(NT_Handle pubentry, const NT_Bool* defaultValue, size_t defaultValueLen) { + return nt::SetDefaultBooleanArray(pubentry, ConvertFromC(defaultValue, defaultValueLen)); +} + +NT_Bool* NT_GetBooleanArray(NT_Handle subentry, const NT_Bool* defaultValue, size_t defaultValueLen, size_t* len) { + auto cppValue = nt::GetBooleanArray(subentry, ConvertFromC(defaultValue, defaultValueLen)); + return ConvertToC(cppValue, len); +} + +void NT_GetAtomicBooleanArray(NT_Handle subentry, const NT_Bool* defaultValue, size_t defaultValueLen, struct NT_TimestampedBooleanArray* value) { + auto cppValue = nt::GetAtomicBooleanArray(subentry, ConvertFromC(defaultValue, defaultValueLen)); + ConvertToC(cppValue, value); +} + +void NT_DisposeTimestampedBooleanArray(struct NT_TimestampedBooleanArray* value) { + std::free(value->value); +} + +struct NT_TimestampedBooleanArray* NT_ReadQueueBooleanArray(NT_Handle subentry, size_t* len) { + auto arr = nt::ReadQueueBooleanArray(subentry); + return ConvertToC(arr, len); +} + +void NT_FreeQueueBooleanArray(struct NT_TimestampedBooleanArray* arr, size_t len) { + for (size_t i = 0; i < len; ++i) { + NT_DisposeTimestampedBooleanArray(&arr[i]); + } + std::free(arr); +} + + +NT_Bool NT_SetIntegerArray(NT_Handle pubentry, int64_t time, const int64_t* value, size_t len) { + return nt::SetIntegerArray(pubentry, ConvertFromC(value, len), time); +} + +NT_Bool NT_SetDefaultIntegerArray(NT_Handle pubentry, const int64_t* defaultValue, size_t defaultValueLen) { + return nt::SetDefaultIntegerArray(pubentry, ConvertFromC(defaultValue, defaultValueLen)); +} + +int64_t* NT_GetIntegerArray(NT_Handle subentry, const int64_t* defaultValue, size_t defaultValueLen, size_t* len) { + auto cppValue = nt::GetIntegerArray(subentry, ConvertFromC(defaultValue, defaultValueLen)); + return ConvertToC(cppValue, len); +} + +void NT_GetAtomicIntegerArray(NT_Handle subentry, const int64_t* defaultValue, size_t defaultValueLen, struct NT_TimestampedIntegerArray* value) { + auto cppValue = nt::GetAtomicIntegerArray(subentry, ConvertFromC(defaultValue, defaultValueLen)); + ConvertToC(cppValue, value); +} + +void NT_DisposeTimestampedIntegerArray(struct NT_TimestampedIntegerArray* value) { + std::free(value->value); +} + +struct NT_TimestampedIntegerArray* NT_ReadQueueIntegerArray(NT_Handle subentry, size_t* len) { + auto arr = nt::ReadQueueIntegerArray(subentry); + return ConvertToC(arr, len); +} + +void NT_FreeQueueIntegerArray(struct NT_TimestampedIntegerArray* arr, size_t len) { + for (size_t i = 0; i < len; ++i) { + NT_DisposeTimestampedIntegerArray(&arr[i]); + } + std::free(arr); +} + + +NT_Bool NT_SetFloatArray(NT_Handle pubentry, int64_t time, const float* value, size_t len) { + return nt::SetFloatArray(pubentry, ConvertFromC(value, len), time); +} + +NT_Bool NT_SetDefaultFloatArray(NT_Handle pubentry, const float* defaultValue, size_t defaultValueLen) { + return nt::SetDefaultFloatArray(pubentry, ConvertFromC(defaultValue, defaultValueLen)); +} + +float* NT_GetFloatArray(NT_Handle subentry, const float* defaultValue, size_t defaultValueLen, size_t* len) { + auto cppValue = nt::GetFloatArray(subentry, ConvertFromC(defaultValue, defaultValueLen)); + return ConvertToC(cppValue, len); +} + +void NT_GetAtomicFloatArray(NT_Handle subentry, const float* defaultValue, size_t defaultValueLen, struct NT_TimestampedFloatArray* value) { + auto cppValue = nt::GetAtomicFloatArray(subentry, ConvertFromC(defaultValue, defaultValueLen)); + ConvertToC(cppValue, value); +} + +void NT_DisposeTimestampedFloatArray(struct NT_TimestampedFloatArray* value) { + std::free(value->value); +} + +struct NT_TimestampedFloatArray* NT_ReadQueueFloatArray(NT_Handle subentry, size_t* len) { + auto arr = nt::ReadQueueFloatArray(subentry); + return ConvertToC(arr, len); +} + +void NT_FreeQueueFloatArray(struct NT_TimestampedFloatArray* arr, size_t len) { + for (size_t i = 0; i < len; ++i) { + NT_DisposeTimestampedFloatArray(&arr[i]); + } + std::free(arr); +} + + +NT_Bool NT_SetDoubleArray(NT_Handle pubentry, int64_t time, const double* value, size_t len) { + return nt::SetDoubleArray(pubentry, ConvertFromC(value, len), time); +} + +NT_Bool NT_SetDefaultDoubleArray(NT_Handle pubentry, const double* defaultValue, size_t defaultValueLen) { + return nt::SetDefaultDoubleArray(pubentry, ConvertFromC(defaultValue, defaultValueLen)); +} + +double* NT_GetDoubleArray(NT_Handle subentry, const double* defaultValue, size_t defaultValueLen, size_t* len) { + auto cppValue = nt::GetDoubleArray(subentry, ConvertFromC(defaultValue, defaultValueLen)); + return ConvertToC(cppValue, len); +} + +void NT_GetAtomicDoubleArray(NT_Handle subentry, const double* defaultValue, size_t defaultValueLen, struct NT_TimestampedDoubleArray* value) { + auto cppValue = nt::GetAtomicDoubleArray(subentry, ConvertFromC(defaultValue, defaultValueLen)); + ConvertToC(cppValue, value); +} + +void NT_DisposeTimestampedDoubleArray(struct NT_TimestampedDoubleArray* value) { + std::free(value->value); +} + +struct NT_TimestampedDoubleArray* NT_ReadQueueDoubleArray(NT_Handle subentry, size_t* len) { + auto arr = nt::ReadQueueDoubleArray(subentry); + return ConvertToC(arr, len); +} + +void NT_FreeQueueDoubleArray(struct NT_TimestampedDoubleArray* arr, size_t len) { + for (size_t i = 0; i < len; ++i) { + NT_DisposeTimestampedDoubleArray(&arr[i]); + } + std::free(arr); +} + + +NT_Bool NT_SetStringArray(NT_Handle pubentry, int64_t time, const struct NT_String* value, size_t len) { + return nt::SetStringArray(pubentry, ConvertFromC(value, len), time); +} + +NT_Bool NT_SetDefaultStringArray(NT_Handle pubentry, const struct NT_String* defaultValue, size_t defaultValueLen) { + return nt::SetDefaultStringArray(pubentry, ConvertFromC(defaultValue, defaultValueLen)); +} + +struct NT_String* NT_GetStringArray(NT_Handle subentry, const struct NT_String* defaultValue, size_t defaultValueLen, size_t* len) { + auto cppValue = nt::GetStringArray(subentry, ConvertFromC(defaultValue, defaultValueLen)); + return ConvertToC(cppValue, len); +} + +void NT_GetAtomicStringArray(NT_Handle subentry, const struct NT_String* defaultValue, size_t defaultValueLen, struct NT_TimestampedStringArray* value) { + auto cppValue = nt::GetAtomicStringArray(subentry, ConvertFromC(defaultValue, defaultValueLen)); + ConvertToC(cppValue, value); +} + +void NT_DisposeTimestampedStringArray(struct NT_TimestampedStringArray* value) { + NT_FreeStringArray(value->value, value->len); +} + +struct NT_TimestampedStringArray* NT_ReadQueueStringArray(NT_Handle subentry, size_t* len) { + auto arr = nt::ReadQueueStringArray(subentry); + return ConvertToC(arr, len); +} + +void NT_FreeQueueStringArray(struct NT_TimestampedStringArray* arr, size_t len) { + for (size_t i = 0; i < len; ++i) { + NT_DisposeTimestampedStringArray(&arr[i]); + } + std::free(arr); +} + + +} // extern "C" diff --git a/ntcore/src/generated/main/native/cpp/ntcore_cpp_types.cpp b/ntcore/src/generated/main/native/cpp/ntcore_cpp_types.cpp new file mode 100644 index 0000000000..030857e895 --- /dev/null +++ b/ntcore/src/generated/main/native/cpp/ntcore_cpp_types.cpp @@ -0,0 +1,463 @@ +// 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. + +// THIS FILE WAS AUTO-GENERATED BY ./ntcore/generate_topics.py. DO NOT MODIFY + +#include "ntcore_cpp_types.h" + +#include "Handle.h" +#include "InstanceImpl.h" + +namespace { +template +struct ValuesType { + using Vector = + std::vector>::Value>; +}; + +template <> +struct ValuesType { + using Vector = std::vector; +}; +} // namespace + +namespace nt { + +template +static inline bool Set(NT_Handle pubentry, typename TypeInfo::View value, + int64_t time) { + if (auto ii = InstanceImpl::Get(Handle{pubentry}.GetInst())) { + return ii->localStorage.SetEntryValue( + pubentry, MakeValue(value, time == 0 ? Now() : time)); + } else { + return {}; + } +} + +template +static inline bool SetDefault(NT_Handle pubentry, + typename TypeInfo::View defaultValue) { + if (auto ii = InstanceImpl::Get(Handle{pubentry}.GetInst())) { + return ii->localStorage.SetDefaultEntryValue(pubentry, + MakeValue(defaultValue, 1)); + } else { + return {}; + } +} + +template +static inline Timestamped::Value> GetAtomic( + NT_Handle subentry, typename TypeInfo::View defaultValue) { + if (auto ii = InstanceImpl::Get(Handle{subentry}.GetInst())) { + return ii->localStorage.GetAtomic(subentry, defaultValue); + } else { + return {}; + } +} + +template +inline Timestamped::SmallRet> GetAtomic( + NT_Handle subentry, + wpi::SmallVectorImpl::SmallElem>& buf, + typename TypeInfo::View defaultValue) { + if (auto ii = InstanceImpl::Get(Handle{subentry}.GetInst())) { + return ii->localStorage.GetAtomic(subentry, buf, defaultValue); + } else { + return {}; + } +} + +template +static inline std::vector::Value>> ReadQueue( + NT_Handle subentry) { + if (auto ii = InstanceImpl::Get(Handle{subentry}.GetInst())) { + return ii->localStorage.ReadQueue(subentry); + } else { + return {}; + } +} + +template +static inline typename ValuesType::Vector ReadQueueValues( + NT_Handle subentry) { + typename ValuesType::Vector rv; + auto arr = ReadQueue(subentry); + rv.reserve(arr.size()); + for (auto&& elem : arr) { + rv.emplace_back(std::move(elem.value)); + } + return rv; +} + +bool SetBoolean(NT_Handle pubentry, bool value, int64_t time) { + return Set(pubentry, value, time); +} + +bool SetDefaultBoolean(NT_Handle pubentry, bool defaultValue) { + return SetDefault(pubentry, defaultValue); +} + +bool GetBoolean(NT_Handle subentry, bool defaultValue) { + return GetAtomic(subentry, defaultValue).value; +} + +TimestampedBoolean GetAtomicBoolean( + NT_Handle subentry, bool defaultValue) { + return GetAtomic(subentry, defaultValue); +} + +std::vector ReadQueueBoolean(NT_Handle subentry) { + return ReadQueue(subentry); +} + +std::vector ReadQueueValuesBoolean(NT_Handle subentry) { + return ReadQueueValues(subentry); +} + + +bool SetInteger(NT_Handle pubentry, int64_t value, int64_t time) { + return Set(pubentry, value, time); +} + +bool SetDefaultInteger(NT_Handle pubentry, int64_t defaultValue) { + return SetDefault(pubentry, defaultValue); +} + +int64_t GetInteger(NT_Handle subentry, int64_t defaultValue) { + return GetAtomic(subentry, defaultValue).value; +} + +TimestampedInteger GetAtomicInteger( + NT_Handle subentry, int64_t defaultValue) { + return GetAtomic(subentry, defaultValue); +} + +std::vector ReadQueueInteger(NT_Handle subentry) { + return ReadQueue(subentry); +} + +std::vector ReadQueueValuesInteger(NT_Handle subentry) { + return ReadQueueValues(subentry); +} + + +bool SetFloat(NT_Handle pubentry, float value, int64_t time) { + return Set(pubentry, value, time); +} + +bool SetDefaultFloat(NT_Handle pubentry, float defaultValue) { + return SetDefault(pubentry, defaultValue); +} + +float GetFloat(NT_Handle subentry, float defaultValue) { + return GetAtomic(subentry, defaultValue).value; +} + +TimestampedFloat GetAtomicFloat( + NT_Handle subentry, float defaultValue) { + return GetAtomic(subentry, defaultValue); +} + +std::vector ReadQueueFloat(NT_Handle subentry) { + return ReadQueue(subentry); +} + +std::vector ReadQueueValuesFloat(NT_Handle subentry) { + return ReadQueueValues(subentry); +} + + +bool SetDouble(NT_Handle pubentry, double value, int64_t time) { + return Set(pubentry, value, time); +} + +bool SetDefaultDouble(NT_Handle pubentry, double defaultValue) { + return SetDefault(pubentry, defaultValue); +} + +double GetDouble(NT_Handle subentry, double defaultValue) { + return GetAtomic(subentry, defaultValue).value; +} + +TimestampedDouble GetAtomicDouble( + NT_Handle subentry, double defaultValue) { + return GetAtomic(subentry, defaultValue); +} + +std::vector ReadQueueDouble(NT_Handle subentry) { + return ReadQueue(subentry); +} + +std::vector ReadQueueValuesDouble(NT_Handle subentry) { + return ReadQueueValues(subentry); +} + + +bool SetString(NT_Handle pubentry, std::string_view value, int64_t time) { + return Set(pubentry, value, time); +} + +bool SetDefaultString(NT_Handle pubentry, std::string_view defaultValue) { + return SetDefault(pubentry, defaultValue); +} + +std::string GetString(NT_Handle subentry, std::string_view defaultValue) { + return GetAtomic(subentry, defaultValue).value; +} + +TimestampedString GetAtomicString( + NT_Handle subentry, std::string_view defaultValue) { + return GetAtomic(subentry, defaultValue); +} + +std::vector ReadQueueString(NT_Handle subentry) { + return ReadQueue(subentry); +} + +std::vector ReadQueueValuesString(NT_Handle subentry) { + return ReadQueueValues(subentry); +} + +std::string_view GetString( + NT_Handle subentry, + wpi::SmallVectorImpl& buf, + std::string_view defaultValue) { + return GetAtomic(subentry, buf, defaultValue).value; +} + +TimestampedStringView GetAtomicString( + NT_Handle subentry, + wpi::SmallVectorImpl& buf, + std::string_view defaultValue) { + return GetAtomic(subentry, buf, defaultValue); +} + + +bool SetRaw(NT_Handle pubentry, std::span value, int64_t time) { + return Set(pubentry, value, time); +} + +bool SetDefaultRaw(NT_Handle pubentry, std::span defaultValue) { + return SetDefault(pubentry, defaultValue); +} + +std::vector GetRaw(NT_Handle subentry, std::span defaultValue) { + return GetAtomic(subentry, defaultValue).value; +} + +TimestampedRaw GetAtomicRaw( + NT_Handle subentry, std::span defaultValue) { + return GetAtomic(subentry, defaultValue); +} + +std::vector ReadQueueRaw(NT_Handle subentry) { + return ReadQueue(subentry); +} + +std::vector> ReadQueueValuesRaw(NT_Handle subentry) { + return ReadQueueValues(subentry); +} + +std::span GetRaw( + NT_Handle subentry, + wpi::SmallVectorImpl& buf, + std::span defaultValue) { + return GetAtomic(subentry, buf, defaultValue).value; +} + +TimestampedRawView GetAtomicRaw( + NT_Handle subentry, + wpi::SmallVectorImpl& buf, + std::span defaultValue) { + return GetAtomic(subentry, buf, defaultValue); +} + + +bool SetBooleanArray(NT_Handle pubentry, std::span value, int64_t time) { + return Set(pubentry, value, time); +} + +bool SetDefaultBooleanArray(NT_Handle pubentry, std::span defaultValue) { + return SetDefault(pubentry, defaultValue); +} + +std::vector GetBooleanArray(NT_Handle subentry, std::span defaultValue) { + return GetAtomic(subentry, defaultValue).value; +} + +TimestampedBooleanArray GetAtomicBooleanArray( + NT_Handle subentry, std::span defaultValue) { + return GetAtomic(subentry, defaultValue); +} + +std::vector ReadQueueBooleanArray(NT_Handle subentry) { + return ReadQueue(subentry); +} + +std::vector> ReadQueueValuesBooleanArray(NT_Handle subentry) { + return ReadQueueValues(subentry); +} + +std::span GetBooleanArray( + NT_Handle subentry, + wpi::SmallVectorImpl& buf, + std::span defaultValue) { + return GetAtomic(subentry, buf, defaultValue).value; +} + +TimestampedBooleanArrayView GetAtomicBooleanArray( + NT_Handle subentry, + wpi::SmallVectorImpl& buf, + std::span defaultValue) { + return GetAtomic(subentry, buf, defaultValue); +} + + +bool SetIntegerArray(NT_Handle pubentry, std::span value, int64_t time) { + return Set(pubentry, value, time); +} + +bool SetDefaultIntegerArray(NT_Handle pubentry, std::span defaultValue) { + return SetDefault(pubentry, defaultValue); +} + +std::vector GetIntegerArray(NT_Handle subentry, std::span defaultValue) { + return GetAtomic(subentry, defaultValue).value; +} + +TimestampedIntegerArray GetAtomicIntegerArray( + NT_Handle subentry, std::span defaultValue) { + return GetAtomic(subentry, defaultValue); +} + +std::vector ReadQueueIntegerArray(NT_Handle subentry) { + return ReadQueue(subentry); +} + +std::vector> ReadQueueValuesIntegerArray(NT_Handle subentry) { + return ReadQueueValues(subentry); +} + +std::span GetIntegerArray( + NT_Handle subentry, + wpi::SmallVectorImpl& buf, + std::span defaultValue) { + return GetAtomic(subentry, buf, defaultValue).value; +} + +TimestampedIntegerArrayView GetAtomicIntegerArray( + NT_Handle subentry, + wpi::SmallVectorImpl& buf, + std::span defaultValue) { + return GetAtomic(subentry, buf, defaultValue); +} + + +bool SetFloatArray(NT_Handle pubentry, std::span value, int64_t time) { + return Set(pubentry, value, time); +} + +bool SetDefaultFloatArray(NT_Handle pubentry, std::span defaultValue) { + return SetDefault(pubentry, defaultValue); +} + +std::vector GetFloatArray(NT_Handle subentry, std::span defaultValue) { + return GetAtomic(subentry, defaultValue).value; +} + +TimestampedFloatArray GetAtomicFloatArray( + NT_Handle subentry, std::span defaultValue) { + return GetAtomic(subentry, defaultValue); +} + +std::vector ReadQueueFloatArray(NT_Handle subentry) { + return ReadQueue(subentry); +} + +std::vector> ReadQueueValuesFloatArray(NT_Handle subentry) { + return ReadQueueValues(subentry); +} + +std::span GetFloatArray( + NT_Handle subentry, + wpi::SmallVectorImpl& buf, + std::span defaultValue) { + return GetAtomic(subentry, buf, defaultValue).value; +} + +TimestampedFloatArrayView GetAtomicFloatArray( + NT_Handle subentry, + wpi::SmallVectorImpl& buf, + std::span defaultValue) { + return GetAtomic(subentry, buf, defaultValue); +} + + +bool SetDoubleArray(NT_Handle pubentry, std::span value, int64_t time) { + return Set(pubentry, value, time); +} + +bool SetDefaultDoubleArray(NT_Handle pubentry, std::span defaultValue) { + return SetDefault(pubentry, defaultValue); +} + +std::vector GetDoubleArray(NT_Handle subentry, std::span defaultValue) { + return GetAtomic(subentry, defaultValue).value; +} + +TimestampedDoubleArray GetAtomicDoubleArray( + NT_Handle subentry, std::span defaultValue) { + return GetAtomic(subentry, defaultValue); +} + +std::vector ReadQueueDoubleArray(NT_Handle subentry) { + return ReadQueue(subentry); +} + +std::vector> ReadQueueValuesDoubleArray(NT_Handle subentry) { + return ReadQueueValues(subentry); +} + +std::span GetDoubleArray( + NT_Handle subentry, + wpi::SmallVectorImpl& buf, + std::span defaultValue) { + return GetAtomic(subentry, buf, defaultValue).value; +} + +TimestampedDoubleArrayView GetAtomicDoubleArray( + NT_Handle subentry, + wpi::SmallVectorImpl& buf, + std::span defaultValue) { + return GetAtomic(subentry, buf, defaultValue); +} + + +bool SetStringArray(NT_Handle pubentry, std::span value, int64_t time) { + return Set(pubentry, value, time); +} + +bool SetDefaultStringArray(NT_Handle pubentry, std::span defaultValue) { + return SetDefault(pubentry, defaultValue); +} + +std::vector GetStringArray(NT_Handle subentry, std::span defaultValue) { + return GetAtomic(subentry, defaultValue).value; +} + +TimestampedStringArray GetAtomicStringArray( + NT_Handle subentry, std::span defaultValue) { + return GetAtomic(subentry, defaultValue); +} + +std::vector ReadQueueStringArray(NT_Handle subentry) { + return ReadQueue(subentry); +} + +std::vector> ReadQueueValuesStringArray(NT_Handle subentry) { + return ReadQueueValues(subentry); +} + + +} // namespace nt diff --git a/ntcore/src/generated/main/native/include/networktables/BooleanArrayTopic.h b/ntcore/src/generated/main/native/include/networktables/BooleanArrayTopic.h new file mode 100644 index 0000000000..de89f4b2b0 --- /dev/null +++ b/ntcore/src/generated/main/native/include/networktables/BooleanArrayTopic.h @@ -0,0 +1,426 @@ +// 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. + +// THIS FILE WAS AUTO-GENERATED BY ./ntcore/generate_topics.py. DO NOT MODIFY + +#pragma once + +#include + +#include +#include +#include +#include + +#include + +#include "networktables/Topic.h" + +namespace wpi { +template +class SmallVectorImpl; +} // namespace wpi + +namespace nt { + +class BooleanArrayTopic; + +/** + * NetworkTables BooleanArray subscriber. + */ +class BooleanArraySubscriber : public Subscriber { + public: + using TopicType = BooleanArrayTopic; + using ValueType = std::vector; + using ParamType = std::span; + using TimestampedValueType = TimestampedBooleanArray; + + using SmallRetType = std::span; + using SmallElemType = int; + using TimestampedValueViewType = TimestampedBooleanArrayView; + + + BooleanArraySubscriber() = default; + + /** + * Construct from a subscriber handle; recommended to use + * BooleanArrayTopic::Subscribe() instead. + * + * @param handle Native handle + * @param defaultValue Default value + */ + BooleanArraySubscriber(NT_Subscriber handle, ParamType defaultValue); + + /** + * Get the last published value. + * If no value has been published, returns the stored default value. + * + * @return value + */ + ValueType Get() const; + + /** + * Get the last published value. + * If no value has been published, returns the passed defaultValue. + * + * @param defaultValue default value to return if no value has been published + * @return value + */ + ValueType Get(ParamType defaultValue) const; + + /** + * Get the last published value. + * If no value has been published, returns the stored default value. + * + * @param buf storage for returned value + * @return value + */ + SmallRetType Get(wpi::SmallVectorImpl& buf) const; + + /** + * Get the last published value. + * If no value has been published, returns the passed defaultValue. + * + * @param buf storage for returned value + * @param defaultValue default value to return if no value has been published + * @return value + */ + SmallRetType Get(wpi::SmallVectorImpl& buf, ParamType defaultValue) const; + + /** + * Get the last published value along with its timestamp + * If no value has been published, returns the stored default value and a + * timestamp of 0. + * + * @return timestamped value + */ + TimestampedValueType GetAtomic() const; + + /** + * Get the last published value along with its timestamp. + * If no value has been published, returns the passed defaultValue and a + * timestamp of 0. + * + * @param defaultValue default value to return if no value has been published + * @return timestamped value + */ + TimestampedValueType GetAtomic(ParamType defaultValue) const; + + /** + * Get the last published value along with its timestamp. + * If no value has been published, returns the stored default value and a + * timestamp of 0. + * + * @param buf storage for returned value + * @return timestamped value + */ + TimestampedValueViewType GetAtomic( + wpi::SmallVectorImpl& buf) const; + + /** + * Get the last published value along with its timestamp. + * If no value has been published, returns the passed defaultValue and a + * timestamp of 0. + * + * @param buf storage for returned value + * @param defaultValue default value to return if no value has been published + * @return timestamped value + */ + TimestampedValueViewType GetAtomic( + wpi::SmallVectorImpl& buf, + ParamType defaultValue) const; + + /** + * Get an array of all value changes since the last call to ReadQueue. + * Also provides a timestamp for each value. + * + * @note The "poll storage" subscribe option can be used to set the queue + * depth. + * + * @return Array of timestamped values; empty array if no new changes have + * been published since the previous call. + */ + std::vector ReadQueue(); + + /** + * Get the corresponding topic. + * + * @return Topic + */ + TopicType GetTopic() const; + + private: + ValueType m_defaultValue; +}; + +/** + * NetworkTables BooleanArray publisher. + */ +class BooleanArrayPublisher : public Publisher { + public: + using TopicType = BooleanArrayTopic; + using ValueType = std::vector; + using ParamType = std::span; + + using SmallRetType = std::span; + using SmallElemType = int; + + using TimestampedValueType = TimestampedBooleanArray; + + BooleanArrayPublisher() = default; + + /** + * Construct from a publisher handle; recommended to use + * BooleanArrayTopic::Publish() instead. + * + * @param handle Native handle + */ + explicit BooleanArrayPublisher(NT_Publisher handle); + + /** + * Publish a new value. + * + * @param value value to publish + * @param time timestamp; 0 indicates current NT time should be used + */ + void Set(ParamType value, int64_t time = 0); + + /** + * Publish a default value. + * On reconnect, a default value will never be used in preference to a + * published value. + * + * @param value value + */ + void SetDefault(ParamType value); + + /** + * Get the corresponding topic. + * + * @return Topic + */ + TopicType GetTopic() const; +}; + +/** + * NetworkTables BooleanArray entry. + * + * @note Unlike NetworkTableEntry, the entry goes away when this is destroyed. + */ +class BooleanArrayEntry final : public BooleanArraySubscriber, + public BooleanArrayPublisher { + public: + using SubscriberType = BooleanArraySubscriber; + using PublisherType = BooleanArrayPublisher; + using TopicType = BooleanArrayTopic; + using ValueType = std::vector; + using ParamType = std::span; + + using SmallRetType = std::span; + using SmallElemType = int; + + using TimestampedValueType = TimestampedBooleanArray; + + BooleanArrayEntry() = default; + + /** + * Construct from an entry handle; recommended to use + * BooleanArrayTopic::GetEntry() instead. + * + * @param handle Native handle + * @param defaultValue Default value + */ + BooleanArrayEntry(NT_Entry handle, ParamType defaultValue); + + /** + * Determines if the native handle is valid. + * + * @return True if the native handle is valid, false otherwise. + */ + explicit operator bool() const { return m_subHandle != 0; } + + /** + * Gets the native handle for the entry. + * + * @return Native handle + */ + NT_Entry GetHandle() const { return m_subHandle; } + + /** + * Get the corresponding topic. + * + * @return Topic + */ + TopicType GetTopic() const; + + /** + * Stops publishing the entry if it's published. + */ + void Unpublish(); +}; + +/** + * NetworkTables BooleanArray topic. + */ +class BooleanArrayTopic final : public Topic { + public: + using SubscriberType = BooleanArraySubscriber; + using PublisherType = BooleanArrayPublisher; + using EntryType = BooleanArrayEntry; + using ValueType = std::vector; + using ParamType = std::span; + using TimestampedValueType = TimestampedBooleanArray; + /** The default type string for this topic type. */ + static constexpr std::string_view kTypeString = "boolean[]"; + + BooleanArrayTopic() = default; + + /** + * Construct from a topic handle; recommended to use + * NetworkTableInstance::GetBooleanArrayTopic() instead. + * + * @param handle Native handle + */ + explicit BooleanArrayTopic(NT_Topic handle) : Topic{handle} {} + + /** + * Construct from a generic topic. + * + * @param topic Topic + */ + explicit BooleanArrayTopic(Topic topic) : Topic{topic} {} + + /** + * Create a new subscriber to the topic. + * + *

The subscriber is only active as long as the returned object + * is not destroyed. + * + * @note Subscribers that do not match the published data type do not return + * any values. To determine if the data type matches, use the appropriate + * Topic functions. + * + * @param defaultValue default value used when a default is not provided to a + * getter function + * @param options subscribe options + * @return subscriber + */ + [[nodiscard]] + SubscriberType Subscribe( + ParamType defaultValue, + const PubSubOptions& options = kDefaultPubSubOptions); + /** + * Create a new subscriber to the topic, with specific type string. + * + *

The subscriber is only active as long as the returned object + * is not destroyed. + * + * @note Subscribers that do not match the published data type do not return + * any values. To determine if the data type matches, use the appropriate + * Topic functions. + * + * @param typeString type string + * @param defaultValue default value used when a default is not provided to a + * getter function + * @param options subscribe options + * @return subscriber + */ + [[nodiscard]] + SubscriberType SubscribeEx( + std::string_view typeString, ParamType defaultValue, + const PubSubOptions& options = kDefaultPubSubOptions); + + /** + * Create a new publisher to the topic. + * + * The publisher is only active as long as the returned object + * is not destroyed. + * + * @note It is not possible to publish two different data types to the same + * topic. Conflicts between publishers are typically resolved by the + * server on a first-come, first-served basis. Any published values that + * do not match the topic's data type are dropped (ignored). To determine + * if the data type matches, use the appropriate Topic functions. + * + * @param options publish options + * @return publisher + */ + [[nodiscard]] + PublisherType Publish(const PubSubOptions& options = kDefaultPubSubOptions); + + /** + * Create a new publisher to the topic, with type string and initial + * properties. + * + * The publisher is only active as long as the returned object + * is not destroyed. + * + * @note It is not possible to publish two different data types to the same + * topic. Conflicts between publishers are typically resolved by the + * server on a first-come, first-served basis. Any published values that + * do not match the topic's data type are dropped (ignored). To determine + * if the data type matches, use the appropriate Topic functions. + * + * @param typeString type string + * @param properties JSON properties + * @param options publish options + * @return publisher + */ + [[nodiscard]] + PublisherType PublishEx(std::string_view typeString, + const wpi::json& properties, const PubSubOptions& options = kDefaultPubSubOptions); + + /** + * Create a new entry for the topic. + * + * Entries act as a combination of a subscriber and a weak publisher. The + * subscriber is active as long as the entry is not destroyed. The publisher + * is created when the entry is first written to, and remains active until + * either Unpublish() is called or the entry is destroyed. + * + * @note It is not possible to use two different data types with the same + * topic. Conflicts between publishers are typically resolved by the + * server on a first-come, first-served basis. Any published values that + * do not match the topic's data type are dropped (ignored), and the entry + * will show no new values if the data type does not match. To determine + * if the data type matches, use the appropriate Topic functions. + * + * @param defaultValue default value used when a default is not provided to a + * getter function + * @param options publish and/or subscribe options + * @return entry + */ + [[nodiscard]] + EntryType GetEntry(ParamType defaultValue, + const PubSubOptions& options = kDefaultPubSubOptions); + /** + * Create a new entry for the topic, with specific type string. + * + * Entries act as a combination of a subscriber and a weak publisher. The + * subscriber is active as long as the entry is not destroyed. The publisher + * is created when the entry is first written to, and remains active until + * either Unpublish() is called or the entry is destroyed. + * + * @note It is not possible to use two different data types with the same + * topic. Conflicts between publishers are typically resolved by the + * server on a first-come, first-served basis. Any published values that + * do not match the topic's data type are dropped (ignored), and the entry + * will show no new values if the data type does not match. To determine + * if the data type matches, use the appropriate Topic functions. + * + * @param typeString type string + * @param defaultValue default value used when a default is not provided to a + * getter function + * @param options publish and/or subscribe options + * @return entry + */ + [[nodiscard]] + EntryType GetEntryEx(std::string_view typeString, ParamType defaultValue, + const PubSubOptions& options = kDefaultPubSubOptions); + +}; + +} // namespace nt + +#include "networktables/BooleanArrayTopic.inc" diff --git a/ntcore/src/generated/main/native/include/networktables/BooleanArrayTopic.inc b/ntcore/src/generated/main/native/include/networktables/BooleanArrayTopic.inc new file mode 100644 index 0000000000..404ec7e23d --- /dev/null +++ b/ntcore/src/generated/main/native/include/networktables/BooleanArrayTopic.inc @@ -0,0 +1,137 @@ +// 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. + +// THIS FILE WAS AUTO-GENERATED BY ./ntcore/generate_topics.py. DO NOT MODIFY + +#pragma once + +#include + +#include "networktables/BooleanArrayTopic.h" +#include "networktables/NetworkTableType.h" +#include "ntcore_cpp.h" + +namespace nt { + +inline BooleanArraySubscriber::BooleanArraySubscriber( + NT_Subscriber handle, std::span defaultValue) + : Subscriber{handle}, + m_defaultValue{defaultValue.begin(), defaultValue.end()} {} + +inline std::vector BooleanArraySubscriber::Get() const { + return Get(m_defaultValue); +} + +inline std::vector BooleanArraySubscriber::Get( + std::span defaultValue) const { + return ::nt::GetBooleanArray(m_subHandle, defaultValue); +} + +inline std::span BooleanArraySubscriber::Get(wpi::SmallVectorImpl& buf) const { + return Get(buf, m_defaultValue); +} + +inline std::span BooleanArraySubscriber::Get(wpi::SmallVectorImpl& buf, std::span defaultValue) const { + return nt::GetBooleanArray(m_subHandle, buf, defaultValue); +} + +inline TimestampedBooleanArray BooleanArraySubscriber::GetAtomic() const { + return GetAtomic(m_defaultValue); +} + +inline TimestampedBooleanArray BooleanArraySubscriber::GetAtomic( + std::span defaultValue) const { + return ::nt::GetAtomicBooleanArray(m_subHandle, defaultValue); +} + +inline TimestampedBooleanArrayView BooleanArraySubscriber::GetAtomic(wpi::SmallVectorImpl& buf) const { + return GetAtomic(buf, m_defaultValue); +} + +inline TimestampedBooleanArrayView BooleanArraySubscriber::GetAtomic(wpi::SmallVectorImpl& buf, std::span defaultValue) const { + return nt::GetAtomicBooleanArray(m_subHandle, buf, defaultValue); +} + +inline std::vector +BooleanArraySubscriber::ReadQueue() { + return ::nt::ReadQueueBooleanArray(m_subHandle); +} + +inline BooleanArrayTopic BooleanArraySubscriber::GetTopic() const { + return BooleanArrayTopic{::nt::GetTopicFromHandle(m_subHandle)}; +} + +inline BooleanArrayPublisher::BooleanArrayPublisher(NT_Publisher handle) + : Publisher{handle} {} + +inline void BooleanArrayPublisher::Set(std::span value, + int64_t time) { + ::nt::SetBooleanArray(m_pubHandle, value, time); +} + +inline void BooleanArrayPublisher::SetDefault(std::span value) { + ::nt::SetDefaultBooleanArray(m_pubHandle, value); +} + +inline BooleanArrayTopic BooleanArrayPublisher::GetTopic() const { + return BooleanArrayTopic{::nt::GetTopicFromHandle(m_pubHandle)}; +} + +inline BooleanArrayEntry::BooleanArrayEntry( + NT_Entry handle, std::span defaultValue) + : BooleanArraySubscriber{handle, defaultValue}, + BooleanArrayPublisher{handle} {} + +inline BooleanArrayTopic BooleanArrayEntry::GetTopic() const { + return BooleanArrayTopic{::nt::GetTopicFromHandle(m_subHandle)}; +} + +inline void BooleanArrayEntry::Unpublish() { + ::nt::Unpublish(m_pubHandle); +} + +inline BooleanArraySubscriber BooleanArrayTopic::Subscribe( + std::span defaultValue, + const PubSubOptions& options) { + return BooleanArraySubscriber{ + ::nt::Subscribe(m_handle, NT_BOOLEAN_ARRAY, "boolean[]", options), + defaultValue}; +} +inline BooleanArraySubscriber BooleanArrayTopic::SubscribeEx( + std::string_view typeString, std::span defaultValue, + const PubSubOptions& options) { + return BooleanArraySubscriber{ + ::nt::Subscribe(m_handle, NT_BOOLEAN_ARRAY, typeString, options), + defaultValue}; +} + +inline BooleanArrayPublisher BooleanArrayTopic::Publish( + const PubSubOptions& options) { + return BooleanArrayPublisher{ + ::nt::Publish(m_handle, NT_BOOLEAN_ARRAY, "boolean[]", options)}; +} + +inline BooleanArrayPublisher BooleanArrayTopic::PublishEx( + std::string_view typeString, + const wpi::json& properties, const PubSubOptions& options) { + return BooleanArrayPublisher{ + ::nt::PublishEx(m_handle, NT_BOOLEAN_ARRAY, typeString, properties, options)}; +} + +inline BooleanArrayEntry BooleanArrayTopic::GetEntry( + std::span defaultValue, + const PubSubOptions& options) { + return BooleanArrayEntry{ + ::nt::GetEntry(m_handle, NT_BOOLEAN_ARRAY, "boolean[]", options), + defaultValue}; +} +inline BooleanArrayEntry BooleanArrayTopic::GetEntryEx( + std::string_view typeString, std::span defaultValue, + const PubSubOptions& options) { + return BooleanArrayEntry{ + ::nt::GetEntry(m_handle, NT_BOOLEAN_ARRAY, typeString, options), + defaultValue}; +} + +} // namespace nt diff --git a/ntcore/src/generated/main/native/include/networktables/BooleanTopic.h b/ntcore/src/generated/main/native/include/networktables/BooleanTopic.h new file mode 100644 index 0000000000..22db06b9e1 --- /dev/null +++ b/ntcore/src/generated/main/native/include/networktables/BooleanTopic.h @@ -0,0 +1,373 @@ +// 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. + +// THIS FILE WAS AUTO-GENERATED BY ./ntcore/generate_topics.py. DO NOT MODIFY + +#pragma once + +#include + + +#include +#include +#include + +#include + +#include "networktables/Topic.h" + +namespace wpi { +template +class SmallVectorImpl; +} // namespace wpi + +namespace nt { + +class BooleanTopic; + +/** + * NetworkTables Boolean subscriber. + */ +class BooleanSubscriber : public Subscriber { + public: + using TopicType = BooleanTopic; + using ValueType = bool; + using ParamType = bool; + using TimestampedValueType = TimestampedBoolean; + + + BooleanSubscriber() = default; + + /** + * Construct from a subscriber handle; recommended to use + * BooleanTopic::Subscribe() instead. + * + * @param handle Native handle + * @param defaultValue Default value + */ + BooleanSubscriber(NT_Subscriber handle, ParamType defaultValue); + + /** + * Get the last published value. + * If no value has been published, returns the stored default value. + * + * @return value + */ + ValueType Get() const; + + /** + * Get the last published value. + * If no value has been published, returns the passed defaultValue. + * + * @param defaultValue default value to return if no value has been published + * @return value + */ + ValueType Get(ParamType defaultValue) const; + + /** + * Get the last published value along with its timestamp + * If no value has been published, returns the stored default value and a + * timestamp of 0. + * + * @return timestamped value + */ + TimestampedValueType GetAtomic() const; + + /** + * Get the last published value along with its timestamp. + * If no value has been published, returns the passed defaultValue and a + * timestamp of 0. + * + * @param defaultValue default value to return if no value has been published + * @return timestamped value + */ + TimestampedValueType GetAtomic(ParamType defaultValue) const; + + /** + * Get an array of all value changes since the last call to ReadQueue. + * Also provides a timestamp for each value. + * + * @note The "poll storage" subscribe option can be used to set the queue + * depth. + * + * @return Array of timestamped values; empty array if no new changes have + * been published since the previous call. + */ + std::vector ReadQueue(); + + /** + * Get the corresponding topic. + * + * @return Topic + */ + TopicType GetTopic() const; + + private: + ValueType m_defaultValue; +}; + +/** + * NetworkTables Boolean publisher. + */ +class BooleanPublisher : public Publisher { + public: + using TopicType = BooleanTopic; + using ValueType = bool; + using ParamType = bool; + + using TimestampedValueType = TimestampedBoolean; + + BooleanPublisher() = default; + + /** + * Construct from a publisher handle; recommended to use + * BooleanTopic::Publish() instead. + * + * @param handle Native handle + */ + explicit BooleanPublisher(NT_Publisher handle); + + /** + * Publish a new value. + * + * @param value value to publish + * @param time timestamp; 0 indicates current NT time should be used + */ + void Set(ParamType value, int64_t time = 0); + + /** + * Publish a default value. + * On reconnect, a default value will never be used in preference to a + * published value. + * + * @param value value + */ + void SetDefault(ParamType value); + + /** + * Get the corresponding topic. + * + * @return Topic + */ + TopicType GetTopic() const; +}; + +/** + * NetworkTables Boolean entry. + * + * @note Unlike NetworkTableEntry, the entry goes away when this is destroyed. + */ +class BooleanEntry final : public BooleanSubscriber, + public BooleanPublisher { + public: + using SubscriberType = BooleanSubscriber; + using PublisherType = BooleanPublisher; + using TopicType = BooleanTopic; + using ValueType = bool; + using ParamType = bool; + + using TimestampedValueType = TimestampedBoolean; + + BooleanEntry() = default; + + /** + * Construct from an entry handle; recommended to use + * BooleanTopic::GetEntry() instead. + * + * @param handle Native handle + * @param defaultValue Default value + */ + BooleanEntry(NT_Entry handle, ParamType defaultValue); + + /** + * Determines if the native handle is valid. + * + * @return True if the native handle is valid, false otherwise. + */ + explicit operator bool() const { return m_subHandle != 0; } + + /** + * Gets the native handle for the entry. + * + * @return Native handle + */ + NT_Entry GetHandle() const { return m_subHandle; } + + /** + * Get the corresponding topic. + * + * @return Topic + */ + TopicType GetTopic() const; + + /** + * Stops publishing the entry if it's published. + */ + void Unpublish(); +}; + +/** + * NetworkTables Boolean topic. + */ +class BooleanTopic final : public Topic { + public: + using SubscriberType = BooleanSubscriber; + using PublisherType = BooleanPublisher; + using EntryType = BooleanEntry; + using ValueType = bool; + using ParamType = bool; + using TimestampedValueType = TimestampedBoolean; + /** The default type string for this topic type. */ + static constexpr std::string_view kTypeString = "boolean"; + + BooleanTopic() = default; + + /** + * Construct from a topic handle; recommended to use + * NetworkTableInstance::GetBooleanTopic() instead. + * + * @param handle Native handle + */ + explicit BooleanTopic(NT_Topic handle) : Topic{handle} {} + + /** + * Construct from a generic topic. + * + * @param topic Topic + */ + explicit BooleanTopic(Topic topic) : Topic{topic} {} + + /** + * Create a new subscriber to the topic. + * + *

The subscriber is only active as long as the returned object + * is not destroyed. + * + * @note Subscribers that do not match the published data type do not return + * any values. To determine if the data type matches, use the appropriate + * Topic functions. + * + * @param defaultValue default value used when a default is not provided to a + * getter function + * @param options subscribe options + * @return subscriber + */ + [[nodiscard]] + SubscriberType Subscribe( + ParamType defaultValue, + const PubSubOptions& options = kDefaultPubSubOptions); + /** + * Create a new subscriber to the topic, with specific type string. + * + *

The subscriber is only active as long as the returned object + * is not destroyed. + * + * @note Subscribers that do not match the published data type do not return + * any values. To determine if the data type matches, use the appropriate + * Topic functions. + * + * @param typeString type string + * @param defaultValue default value used when a default is not provided to a + * getter function + * @param options subscribe options + * @return subscriber + */ + [[nodiscard]] + SubscriberType SubscribeEx( + std::string_view typeString, ParamType defaultValue, + const PubSubOptions& options = kDefaultPubSubOptions); + + /** + * Create a new publisher to the topic. + * + * The publisher is only active as long as the returned object + * is not destroyed. + * + * @note It is not possible to publish two different data types to the same + * topic. Conflicts between publishers are typically resolved by the + * server on a first-come, first-served basis. Any published values that + * do not match the topic's data type are dropped (ignored). To determine + * if the data type matches, use the appropriate Topic functions. + * + * @param options publish options + * @return publisher + */ + [[nodiscard]] + PublisherType Publish(const PubSubOptions& options = kDefaultPubSubOptions); + + /** + * Create a new publisher to the topic, with type string and initial + * properties. + * + * The publisher is only active as long as the returned object + * is not destroyed. + * + * @note It is not possible to publish two different data types to the same + * topic. Conflicts between publishers are typically resolved by the + * server on a first-come, first-served basis. Any published values that + * do not match the topic's data type are dropped (ignored). To determine + * if the data type matches, use the appropriate Topic functions. + * + * @param typeString type string + * @param properties JSON properties + * @param options publish options + * @return publisher + */ + [[nodiscard]] + PublisherType PublishEx(std::string_view typeString, + const wpi::json& properties, const PubSubOptions& options = kDefaultPubSubOptions); + + /** + * Create a new entry for the topic. + * + * Entries act as a combination of a subscriber and a weak publisher. The + * subscriber is active as long as the entry is not destroyed. The publisher + * is created when the entry is first written to, and remains active until + * either Unpublish() is called or the entry is destroyed. + * + * @note It is not possible to use two different data types with the same + * topic. Conflicts between publishers are typically resolved by the + * server on a first-come, first-served basis. Any published values that + * do not match the topic's data type are dropped (ignored), and the entry + * will show no new values if the data type does not match. To determine + * if the data type matches, use the appropriate Topic functions. + * + * @param defaultValue default value used when a default is not provided to a + * getter function + * @param options publish and/or subscribe options + * @return entry + */ + [[nodiscard]] + EntryType GetEntry(ParamType defaultValue, + const PubSubOptions& options = kDefaultPubSubOptions); + /** + * Create a new entry for the topic, with specific type string. + * + * Entries act as a combination of a subscriber and a weak publisher. The + * subscriber is active as long as the entry is not destroyed. The publisher + * is created when the entry is first written to, and remains active until + * either Unpublish() is called or the entry is destroyed. + * + * @note It is not possible to use two different data types with the same + * topic. Conflicts between publishers are typically resolved by the + * server on a first-come, first-served basis. Any published values that + * do not match the topic's data type are dropped (ignored), and the entry + * will show no new values if the data type does not match. To determine + * if the data type matches, use the appropriate Topic functions. + * + * @param typeString type string + * @param defaultValue default value used when a default is not provided to a + * getter function + * @param options publish and/or subscribe options + * @return entry + */ + [[nodiscard]] + EntryType GetEntryEx(std::string_view typeString, ParamType defaultValue, + const PubSubOptions& options = kDefaultPubSubOptions); + +}; + +} // namespace nt + +#include "networktables/BooleanTopic.inc" diff --git a/ntcore/src/generated/main/native/include/networktables/BooleanTopic.inc b/ntcore/src/generated/main/native/include/networktables/BooleanTopic.inc new file mode 100644 index 0000000000..2a4d7e61ce --- /dev/null +++ b/ntcore/src/generated/main/native/include/networktables/BooleanTopic.inc @@ -0,0 +1,121 @@ +// 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. + +// THIS FILE WAS AUTO-GENERATED BY ./ntcore/generate_topics.py. DO NOT MODIFY + +#pragma once + +#include + +#include "networktables/BooleanTopic.h" +#include "networktables/NetworkTableType.h" +#include "ntcore_cpp.h" + +namespace nt { + +inline BooleanSubscriber::BooleanSubscriber( + NT_Subscriber handle, bool defaultValue) + : Subscriber{handle}, + m_defaultValue{defaultValue} {} + +inline bool BooleanSubscriber::Get() const { + return Get(m_defaultValue); +} + +inline bool BooleanSubscriber::Get( + bool defaultValue) const { + return ::nt::GetBoolean(m_subHandle, defaultValue); +} + +inline TimestampedBoolean BooleanSubscriber::GetAtomic() const { + return GetAtomic(m_defaultValue); +} + +inline TimestampedBoolean BooleanSubscriber::GetAtomic( + bool defaultValue) const { + return ::nt::GetAtomicBoolean(m_subHandle, defaultValue); +} + +inline std::vector +BooleanSubscriber::ReadQueue() { + return ::nt::ReadQueueBoolean(m_subHandle); +} + +inline BooleanTopic BooleanSubscriber::GetTopic() const { + return BooleanTopic{::nt::GetTopicFromHandle(m_subHandle)}; +} + +inline BooleanPublisher::BooleanPublisher(NT_Publisher handle) + : Publisher{handle} {} + +inline void BooleanPublisher::Set(bool value, + int64_t time) { + ::nt::SetBoolean(m_pubHandle, value, time); +} + +inline void BooleanPublisher::SetDefault(bool value) { + ::nt::SetDefaultBoolean(m_pubHandle, value); +} + +inline BooleanTopic BooleanPublisher::GetTopic() const { + return BooleanTopic{::nt::GetTopicFromHandle(m_pubHandle)}; +} + +inline BooleanEntry::BooleanEntry( + NT_Entry handle, bool defaultValue) + : BooleanSubscriber{handle, defaultValue}, + BooleanPublisher{handle} {} + +inline BooleanTopic BooleanEntry::GetTopic() const { + return BooleanTopic{::nt::GetTopicFromHandle(m_subHandle)}; +} + +inline void BooleanEntry::Unpublish() { + ::nt::Unpublish(m_pubHandle); +} + +inline BooleanSubscriber BooleanTopic::Subscribe( + bool defaultValue, + const PubSubOptions& options) { + return BooleanSubscriber{ + ::nt::Subscribe(m_handle, NT_BOOLEAN, "boolean", options), + defaultValue}; +} +inline BooleanSubscriber BooleanTopic::SubscribeEx( + std::string_view typeString, bool defaultValue, + const PubSubOptions& options) { + return BooleanSubscriber{ + ::nt::Subscribe(m_handle, NT_BOOLEAN, typeString, options), + defaultValue}; +} + +inline BooleanPublisher BooleanTopic::Publish( + const PubSubOptions& options) { + return BooleanPublisher{ + ::nt::Publish(m_handle, NT_BOOLEAN, "boolean", options)}; +} + +inline BooleanPublisher BooleanTopic::PublishEx( + std::string_view typeString, + const wpi::json& properties, const PubSubOptions& options) { + return BooleanPublisher{ + ::nt::PublishEx(m_handle, NT_BOOLEAN, typeString, properties, options)}; +} + +inline BooleanEntry BooleanTopic::GetEntry( + bool defaultValue, + const PubSubOptions& options) { + return BooleanEntry{ + ::nt::GetEntry(m_handle, NT_BOOLEAN, "boolean", options), + defaultValue}; +} +inline BooleanEntry BooleanTopic::GetEntryEx( + std::string_view typeString, bool defaultValue, + const PubSubOptions& options) { + return BooleanEntry{ + ::nt::GetEntry(m_handle, NT_BOOLEAN, typeString, options), + defaultValue}; +} + +} // namespace nt diff --git a/ntcore/src/generated/main/native/include/networktables/DoubleArrayTopic.h b/ntcore/src/generated/main/native/include/networktables/DoubleArrayTopic.h new file mode 100644 index 0000000000..6f64d367f2 --- /dev/null +++ b/ntcore/src/generated/main/native/include/networktables/DoubleArrayTopic.h @@ -0,0 +1,426 @@ +// 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. + +// THIS FILE WAS AUTO-GENERATED BY ./ntcore/generate_topics.py. DO NOT MODIFY + +#pragma once + +#include + +#include +#include +#include +#include + +#include + +#include "networktables/Topic.h" + +namespace wpi { +template +class SmallVectorImpl; +} // namespace wpi + +namespace nt { + +class DoubleArrayTopic; + +/** + * NetworkTables DoubleArray subscriber. + */ +class DoubleArraySubscriber : public Subscriber { + public: + using TopicType = DoubleArrayTopic; + using ValueType = std::vector; + using ParamType = std::span; + using TimestampedValueType = TimestampedDoubleArray; + + using SmallRetType = std::span; + using SmallElemType = double; + using TimestampedValueViewType = TimestampedDoubleArrayView; + + + DoubleArraySubscriber() = default; + + /** + * Construct from a subscriber handle; recommended to use + * DoubleArrayTopic::Subscribe() instead. + * + * @param handle Native handle + * @param defaultValue Default value + */ + DoubleArraySubscriber(NT_Subscriber handle, ParamType defaultValue); + + /** + * Get the last published value. + * If no value has been published, returns the stored default value. + * + * @return value + */ + ValueType Get() const; + + /** + * Get the last published value. + * If no value has been published, returns the passed defaultValue. + * + * @param defaultValue default value to return if no value has been published + * @return value + */ + ValueType Get(ParamType defaultValue) const; + + /** + * Get the last published value. + * If no value has been published, returns the stored default value. + * + * @param buf storage for returned value + * @return value + */ + SmallRetType Get(wpi::SmallVectorImpl& buf) const; + + /** + * Get the last published value. + * If no value has been published, returns the passed defaultValue. + * + * @param buf storage for returned value + * @param defaultValue default value to return if no value has been published + * @return value + */ + SmallRetType Get(wpi::SmallVectorImpl& buf, ParamType defaultValue) const; + + /** + * Get the last published value along with its timestamp + * If no value has been published, returns the stored default value and a + * timestamp of 0. + * + * @return timestamped value + */ + TimestampedValueType GetAtomic() const; + + /** + * Get the last published value along with its timestamp. + * If no value has been published, returns the passed defaultValue and a + * timestamp of 0. + * + * @param defaultValue default value to return if no value has been published + * @return timestamped value + */ + TimestampedValueType GetAtomic(ParamType defaultValue) const; + + /** + * Get the last published value along with its timestamp. + * If no value has been published, returns the stored default value and a + * timestamp of 0. + * + * @param buf storage for returned value + * @return timestamped value + */ + TimestampedValueViewType GetAtomic( + wpi::SmallVectorImpl& buf) const; + + /** + * Get the last published value along with its timestamp. + * If no value has been published, returns the passed defaultValue and a + * timestamp of 0. + * + * @param buf storage for returned value + * @param defaultValue default value to return if no value has been published + * @return timestamped value + */ + TimestampedValueViewType GetAtomic( + wpi::SmallVectorImpl& buf, + ParamType defaultValue) const; + + /** + * Get an array of all value changes since the last call to ReadQueue. + * Also provides a timestamp for each value. + * + * @note The "poll storage" subscribe option can be used to set the queue + * depth. + * + * @return Array of timestamped values; empty array if no new changes have + * been published since the previous call. + */ + std::vector ReadQueue(); + + /** + * Get the corresponding topic. + * + * @return Topic + */ + TopicType GetTopic() const; + + private: + ValueType m_defaultValue; +}; + +/** + * NetworkTables DoubleArray publisher. + */ +class DoubleArrayPublisher : public Publisher { + public: + using TopicType = DoubleArrayTopic; + using ValueType = std::vector; + using ParamType = std::span; + + using SmallRetType = std::span; + using SmallElemType = double; + + using TimestampedValueType = TimestampedDoubleArray; + + DoubleArrayPublisher() = default; + + /** + * Construct from a publisher handle; recommended to use + * DoubleArrayTopic::Publish() instead. + * + * @param handle Native handle + */ + explicit DoubleArrayPublisher(NT_Publisher handle); + + /** + * Publish a new value. + * + * @param value value to publish + * @param time timestamp; 0 indicates current NT time should be used + */ + void Set(ParamType value, int64_t time = 0); + + /** + * Publish a default value. + * On reconnect, a default value will never be used in preference to a + * published value. + * + * @param value value + */ + void SetDefault(ParamType value); + + /** + * Get the corresponding topic. + * + * @return Topic + */ + TopicType GetTopic() const; +}; + +/** + * NetworkTables DoubleArray entry. + * + * @note Unlike NetworkTableEntry, the entry goes away when this is destroyed. + */ +class DoubleArrayEntry final : public DoubleArraySubscriber, + public DoubleArrayPublisher { + public: + using SubscriberType = DoubleArraySubscriber; + using PublisherType = DoubleArrayPublisher; + using TopicType = DoubleArrayTopic; + using ValueType = std::vector; + using ParamType = std::span; + + using SmallRetType = std::span; + using SmallElemType = double; + + using TimestampedValueType = TimestampedDoubleArray; + + DoubleArrayEntry() = default; + + /** + * Construct from an entry handle; recommended to use + * DoubleArrayTopic::GetEntry() instead. + * + * @param handle Native handle + * @param defaultValue Default value + */ + DoubleArrayEntry(NT_Entry handle, ParamType defaultValue); + + /** + * Determines if the native handle is valid. + * + * @return True if the native handle is valid, false otherwise. + */ + explicit operator bool() const { return m_subHandle != 0; } + + /** + * Gets the native handle for the entry. + * + * @return Native handle + */ + NT_Entry GetHandle() const { return m_subHandle; } + + /** + * Get the corresponding topic. + * + * @return Topic + */ + TopicType GetTopic() const; + + /** + * Stops publishing the entry if it's published. + */ + void Unpublish(); +}; + +/** + * NetworkTables DoubleArray topic. + */ +class DoubleArrayTopic final : public Topic { + public: + using SubscriberType = DoubleArraySubscriber; + using PublisherType = DoubleArrayPublisher; + using EntryType = DoubleArrayEntry; + using ValueType = std::vector; + using ParamType = std::span; + using TimestampedValueType = TimestampedDoubleArray; + /** The default type string for this topic type. */ + static constexpr std::string_view kTypeString = "double[]"; + + DoubleArrayTopic() = default; + + /** + * Construct from a topic handle; recommended to use + * NetworkTableInstance::GetDoubleArrayTopic() instead. + * + * @param handle Native handle + */ + explicit DoubleArrayTopic(NT_Topic handle) : Topic{handle} {} + + /** + * Construct from a generic topic. + * + * @param topic Topic + */ + explicit DoubleArrayTopic(Topic topic) : Topic{topic} {} + + /** + * Create a new subscriber to the topic. + * + *

The subscriber is only active as long as the returned object + * is not destroyed. + * + * @note Subscribers that do not match the published data type do not return + * any values. To determine if the data type matches, use the appropriate + * Topic functions. + * + * @param defaultValue default value used when a default is not provided to a + * getter function + * @param options subscribe options + * @return subscriber + */ + [[nodiscard]] + SubscriberType Subscribe( + ParamType defaultValue, + const PubSubOptions& options = kDefaultPubSubOptions); + /** + * Create a new subscriber to the topic, with specific type string. + * + *

The subscriber is only active as long as the returned object + * is not destroyed. + * + * @note Subscribers that do not match the published data type do not return + * any values. To determine if the data type matches, use the appropriate + * Topic functions. + * + * @param typeString type string + * @param defaultValue default value used when a default is not provided to a + * getter function + * @param options subscribe options + * @return subscriber + */ + [[nodiscard]] + SubscriberType SubscribeEx( + std::string_view typeString, ParamType defaultValue, + const PubSubOptions& options = kDefaultPubSubOptions); + + /** + * Create a new publisher to the topic. + * + * The publisher is only active as long as the returned object + * is not destroyed. + * + * @note It is not possible to publish two different data types to the same + * topic. Conflicts between publishers are typically resolved by the + * server on a first-come, first-served basis. Any published values that + * do not match the topic's data type are dropped (ignored). To determine + * if the data type matches, use the appropriate Topic functions. + * + * @param options publish options + * @return publisher + */ + [[nodiscard]] + PublisherType Publish(const PubSubOptions& options = kDefaultPubSubOptions); + + /** + * Create a new publisher to the topic, with type string and initial + * properties. + * + * The publisher is only active as long as the returned object + * is not destroyed. + * + * @note It is not possible to publish two different data types to the same + * topic. Conflicts between publishers are typically resolved by the + * server on a first-come, first-served basis. Any published values that + * do not match the topic's data type are dropped (ignored). To determine + * if the data type matches, use the appropriate Topic functions. + * + * @param typeString type string + * @param properties JSON properties + * @param options publish options + * @return publisher + */ + [[nodiscard]] + PublisherType PublishEx(std::string_view typeString, + const wpi::json& properties, const PubSubOptions& options = kDefaultPubSubOptions); + + /** + * Create a new entry for the topic. + * + * Entries act as a combination of a subscriber and a weak publisher. The + * subscriber is active as long as the entry is not destroyed. The publisher + * is created when the entry is first written to, and remains active until + * either Unpublish() is called or the entry is destroyed. + * + * @note It is not possible to use two different data types with the same + * topic. Conflicts between publishers are typically resolved by the + * server on a first-come, first-served basis. Any published values that + * do not match the topic's data type are dropped (ignored), and the entry + * will show no new values if the data type does not match. To determine + * if the data type matches, use the appropriate Topic functions. + * + * @param defaultValue default value used when a default is not provided to a + * getter function + * @param options publish and/or subscribe options + * @return entry + */ + [[nodiscard]] + EntryType GetEntry(ParamType defaultValue, + const PubSubOptions& options = kDefaultPubSubOptions); + /** + * Create a new entry for the topic, with specific type string. + * + * Entries act as a combination of a subscriber and a weak publisher. The + * subscriber is active as long as the entry is not destroyed. The publisher + * is created when the entry is first written to, and remains active until + * either Unpublish() is called or the entry is destroyed. + * + * @note It is not possible to use two different data types with the same + * topic. Conflicts between publishers are typically resolved by the + * server on a first-come, first-served basis. Any published values that + * do not match the topic's data type are dropped (ignored), and the entry + * will show no new values if the data type does not match. To determine + * if the data type matches, use the appropriate Topic functions. + * + * @param typeString type string + * @param defaultValue default value used when a default is not provided to a + * getter function + * @param options publish and/or subscribe options + * @return entry + */ + [[nodiscard]] + EntryType GetEntryEx(std::string_view typeString, ParamType defaultValue, + const PubSubOptions& options = kDefaultPubSubOptions); + +}; + +} // namespace nt + +#include "networktables/DoubleArrayTopic.inc" diff --git a/ntcore/src/generated/main/native/include/networktables/DoubleArrayTopic.inc b/ntcore/src/generated/main/native/include/networktables/DoubleArrayTopic.inc new file mode 100644 index 0000000000..bab8dd0080 --- /dev/null +++ b/ntcore/src/generated/main/native/include/networktables/DoubleArrayTopic.inc @@ -0,0 +1,137 @@ +// 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. + +// THIS FILE WAS AUTO-GENERATED BY ./ntcore/generate_topics.py. DO NOT MODIFY + +#pragma once + +#include + +#include "networktables/DoubleArrayTopic.h" +#include "networktables/NetworkTableType.h" +#include "ntcore_cpp.h" + +namespace nt { + +inline DoubleArraySubscriber::DoubleArraySubscriber( + NT_Subscriber handle, std::span defaultValue) + : Subscriber{handle}, + m_defaultValue{defaultValue.begin(), defaultValue.end()} {} + +inline std::vector DoubleArraySubscriber::Get() const { + return Get(m_defaultValue); +} + +inline std::vector DoubleArraySubscriber::Get( + std::span defaultValue) const { + return ::nt::GetDoubleArray(m_subHandle, defaultValue); +} + +inline std::span DoubleArraySubscriber::Get(wpi::SmallVectorImpl& buf) const { + return Get(buf, m_defaultValue); +} + +inline std::span DoubleArraySubscriber::Get(wpi::SmallVectorImpl& buf, std::span defaultValue) const { + return nt::GetDoubleArray(m_subHandle, buf, defaultValue); +} + +inline TimestampedDoubleArray DoubleArraySubscriber::GetAtomic() const { + return GetAtomic(m_defaultValue); +} + +inline TimestampedDoubleArray DoubleArraySubscriber::GetAtomic( + std::span defaultValue) const { + return ::nt::GetAtomicDoubleArray(m_subHandle, defaultValue); +} + +inline TimestampedDoubleArrayView DoubleArraySubscriber::GetAtomic(wpi::SmallVectorImpl& buf) const { + return GetAtomic(buf, m_defaultValue); +} + +inline TimestampedDoubleArrayView DoubleArraySubscriber::GetAtomic(wpi::SmallVectorImpl& buf, std::span defaultValue) const { + return nt::GetAtomicDoubleArray(m_subHandle, buf, defaultValue); +} + +inline std::vector +DoubleArraySubscriber::ReadQueue() { + return ::nt::ReadQueueDoubleArray(m_subHandle); +} + +inline DoubleArrayTopic DoubleArraySubscriber::GetTopic() const { + return DoubleArrayTopic{::nt::GetTopicFromHandle(m_subHandle)}; +} + +inline DoubleArrayPublisher::DoubleArrayPublisher(NT_Publisher handle) + : Publisher{handle} {} + +inline void DoubleArrayPublisher::Set(std::span value, + int64_t time) { + ::nt::SetDoubleArray(m_pubHandle, value, time); +} + +inline void DoubleArrayPublisher::SetDefault(std::span value) { + ::nt::SetDefaultDoubleArray(m_pubHandle, value); +} + +inline DoubleArrayTopic DoubleArrayPublisher::GetTopic() const { + return DoubleArrayTopic{::nt::GetTopicFromHandle(m_pubHandle)}; +} + +inline DoubleArrayEntry::DoubleArrayEntry( + NT_Entry handle, std::span defaultValue) + : DoubleArraySubscriber{handle, defaultValue}, + DoubleArrayPublisher{handle} {} + +inline DoubleArrayTopic DoubleArrayEntry::GetTopic() const { + return DoubleArrayTopic{::nt::GetTopicFromHandle(m_subHandle)}; +} + +inline void DoubleArrayEntry::Unpublish() { + ::nt::Unpublish(m_pubHandle); +} + +inline DoubleArraySubscriber DoubleArrayTopic::Subscribe( + std::span defaultValue, + const PubSubOptions& options) { + return DoubleArraySubscriber{ + ::nt::Subscribe(m_handle, NT_DOUBLE_ARRAY, "double[]", options), + defaultValue}; +} +inline DoubleArraySubscriber DoubleArrayTopic::SubscribeEx( + std::string_view typeString, std::span defaultValue, + const PubSubOptions& options) { + return DoubleArraySubscriber{ + ::nt::Subscribe(m_handle, NT_DOUBLE_ARRAY, typeString, options), + defaultValue}; +} + +inline DoubleArrayPublisher DoubleArrayTopic::Publish( + const PubSubOptions& options) { + return DoubleArrayPublisher{ + ::nt::Publish(m_handle, NT_DOUBLE_ARRAY, "double[]", options)}; +} + +inline DoubleArrayPublisher DoubleArrayTopic::PublishEx( + std::string_view typeString, + const wpi::json& properties, const PubSubOptions& options) { + return DoubleArrayPublisher{ + ::nt::PublishEx(m_handle, NT_DOUBLE_ARRAY, typeString, properties, options)}; +} + +inline DoubleArrayEntry DoubleArrayTopic::GetEntry( + std::span defaultValue, + const PubSubOptions& options) { + return DoubleArrayEntry{ + ::nt::GetEntry(m_handle, NT_DOUBLE_ARRAY, "double[]", options), + defaultValue}; +} +inline DoubleArrayEntry DoubleArrayTopic::GetEntryEx( + std::string_view typeString, std::span defaultValue, + const PubSubOptions& options) { + return DoubleArrayEntry{ + ::nt::GetEntry(m_handle, NT_DOUBLE_ARRAY, typeString, options), + defaultValue}; +} + +} // namespace nt diff --git a/ntcore/src/generated/main/native/include/networktables/DoubleTopic.h b/ntcore/src/generated/main/native/include/networktables/DoubleTopic.h new file mode 100644 index 0000000000..bcb1751b40 --- /dev/null +++ b/ntcore/src/generated/main/native/include/networktables/DoubleTopic.h @@ -0,0 +1,373 @@ +// 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. + +// THIS FILE WAS AUTO-GENERATED BY ./ntcore/generate_topics.py. DO NOT MODIFY + +#pragma once + +#include + + +#include +#include +#include + +#include + +#include "networktables/Topic.h" + +namespace wpi { +template +class SmallVectorImpl; +} // namespace wpi + +namespace nt { + +class DoubleTopic; + +/** + * NetworkTables Double subscriber. + */ +class DoubleSubscriber : public Subscriber { + public: + using TopicType = DoubleTopic; + using ValueType = double; + using ParamType = double; + using TimestampedValueType = TimestampedDouble; + + + DoubleSubscriber() = default; + + /** + * Construct from a subscriber handle; recommended to use + * DoubleTopic::Subscribe() instead. + * + * @param handle Native handle + * @param defaultValue Default value + */ + DoubleSubscriber(NT_Subscriber handle, ParamType defaultValue); + + /** + * Get the last published value. + * If no value has been published, returns the stored default value. + * + * @return value + */ + ValueType Get() const; + + /** + * Get the last published value. + * If no value has been published, returns the passed defaultValue. + * + * @param defaultValue default value to return if no value has been published + * @return value + */ + ValueType Get(ParamType defaultValue) const; + + /** + * Get the last published value along with its timestamp + * If no value has been published, returns the stored default value and a + * timestamp of 0. + * + * @return timestamped value + */ + TimestampedValueType GetAtomic() const; + + /** + * Get the last published value along with its timestamp. + * If no value has been published, returns the passed defaultValue and a + * timestamp of 0. + * + * @param defaultValue default value to return if no value has been published + * @return timestamped value + */ + TimestampedValueType GetAtomic(ParamType defaultValue) const; + + /** + * Get an array of all value changes since the last call to ReadQueue. + * Also provides a timestamp for each value. + * + * @note The "poll storage" subscribe option can be used to set the queue + * depth. + * + * @return Array of timestamped values; empty array if no new changes have + * been published since the previous call. + */ + std::vector ReadQueue(); + + /** + * Get the corresponding topic. + * + * @return Topic + */ + TopicType GetTopic() const; + + private: + ValueType m_defaultValue; +}; + +/** + * NetworkTables Double publisher. + */ +class DoublePublisher : public Publisher { + public: + using TopicType = DoubleTopic; + using ValueType = double; + using ParamType = double; + + using TimestampedValueType = TimestampedDouble; + + DoublePublisher() = default; + + /** + * Construct from a publisher handle; recommended to use + * DoubleTopic::Publish() instead. + * + * @param handle Native handle + */ + explicit DoublePublisher(NT_Publisher handle); + + /** + * Publish a new value. + * + * @param value value to publish + * @param time timestamp; 0 indicates current NT time should be used + */ + void Set(ParamType value, int64_t time = 0); + + /** + * Publish a default value. + * On reconnect, a default value will never be used in preference to a + * published value. + * + * @param value value + */ + void SetDefault(ParamType value); + + /** + * Get the corresponding topic. + * + * @return Topic + */ + TopicType GetTopic() const; +}; + +/** + * NetworkTables Double entry. + * + * @note Unlike NetworkTableEntry, the entry goes away when this is destroyed. + */ +class DoubleEntry final : public DoubleSubscriber, + public DoublePublisher { + public: + using SubscriberType = DoubleSubscriber; + using PublisherType = DoublePublisher; + using TopicType = DoubleTopic; + using ValueType = double; + using ParamType = double; + + using TimestampedValueType = TimestampedDouble; + + DoubleEntry() = default; + + /** + * Construct from an entry handle; recommended to use + * DoubleTopic::GetEntry() instead. + * + * @param handle Native handle + * @param defaultValue Default value + */ + DoubleEntry(NT_Entry handle, ParamType defaultValue); + + /** + * Determines if the native handle is valid. + * + * @return True if the native handle is valid, false otherwise. + */ + explicit operator bool() const { return m_subHandle != 0; } + + /** + * Gets the native handle for the entry. + * + * @return Native handle + */ + NT_Entry GetHandle() const { return m_subHandle; } + + /** + * Get the corresponding topic. + * + * @return Topic + */ + TopicType GetTopic() const; + + /** + * Stops publishing the entry if it's published. + */ + void Unpublish(); +}; + +/** + * NetworkTables Double topic. + */ +class DoubleTopic final : public Topic { + public: + using SubscriberType = DoubleSubscriber; + using PublisherType = DoublePublisher; + using EntryType = DoubleEntry; + using ValueType = double; + using ParamType = double; + using TimestampedValueType = TimestampedDouble; + /** The default type string for this topic type. */ + static constexpr std::string_view kTypeString = "double"; + + DoubleTopic() = default; + + /** + * Construct from a topic handle; recommended to use + * NetworkTableInstance::GetDoubleTopic() instead. + * + * @param handle Native handle + */ + explicit DoubleTopic(NT_Topic handle) : Topic{handle} {} + + /** + * Construct from a generic topic. + * + * @param topic Topic + */ + explicit DoubleTopic(Topic topic) : Topic{topic} {} + + /** + * Create a new subscriber to the topic. + * + *

The subscriber is only active as long as the returned object + * is not destroyed. + * + * @note Subscribers that do not match the published data type do not return + * any values. To determine if the data type matches, use the appropriate + * Topic functions. + * + * @param defaultValue default value used when a default is not provided to a + * getter function + * @param options subscribe options + * @return subscriber + */ + [[nodiscard]] + SubscriberType Subscribe( + ParamType defaultValue, + const PubSubOptions& options = kDefaultPubSubOptions); + /** + * Create a new subscriber to the topic, with specific type string. + * + *

The subscriber is only active as long as the returned object + * is not destroyed. + * + * @note Subscribers that do not match the published data type do not return + * any values. To determine if the data type matches, use the appropriate + * Topic functions. + * + * @param typeString type string + * @param defaultValue default value used when a default is not provided to a + * getter function + * @param options subscribe options + * @return subscriber + */ + [[nodiscard]] + SubscriberType SubscribeEx( + std::string_view typeString, ParamType defaultValue, + const PubSubOptions& options = kDefaultPubSubOptions); + + /** + * Create a new publisher to the topic. + * + * The publisher is only active as long as the returned object + * is not destroyed. + * + * @note It is not possible to publish two different data types to the same + * topic. Conflicts between publishers are typically resolved by the + * server on a first-come, first-served basis. Any published values that + * do not match the topic's data type are dropped (ignored). To determine + * if the data type matches, use the appropriate Topic functions. + * + * @param options publish options + * @return publisher + */ + [[nodiscard]] + PublisherType Publish(const PubSubOptions& options = kDefaultPubSubOptions); + + /** + * Create a new publisher to the topic, with type string and initial + * properties. + * + * The publisher is only active as long as the returned object + * is not destroyed. + * + * @note It is not possible to publish two different data types to the same + * topic. Conflicts between publishers are typically resolved by the + * server on a first-come, first-served basis. Any published values that + * do not match the topic's data type are dropped (ignored). To determine + * if the data type matches, use the appropriate Topic functions. + * + * @param typeString type string + * @param properties JSON properties + * @param options publish options + * @return publisher + */ + [[nodiscard]] + PublisherType PublishEx(std::string_view typeString, + const wpi::json& properties, const PubSubOptions& options = kDefaultPubSubOptions); + + /** + * Create a new entry for the topic. + * + * Entries act as a combination of a subscriber and a weak publisher. The + * subscriber is active as long as the entry is not destroyed. The publisher + * is created when the entry is first written to, and remains active until + * either Unpublish() is called or the entry is destroyed. + * + * @note It is not possible to use two different data types with the same + * topic. Conflicts between publishers are typically resolved by the + * server on a first-come, first-served basis. Any published values that + * do not match the topic's data type are dropped (ignored), and the entry + * will show no new values if the data type does not match. To determine + * if the data type matches, use the appropriate Topic functions. + * + * @param defaultValue default value used when a default is not provided to a + * getter function + * @param options publish and/or subscribe options + * @return entry + */ + [[nodiscard]] + EntryType GetEntry(ParamType defaultValue, + const PubSubOptions& options = kDefaultPubSubOptions); + /** + * Create a new entry for the topic, with specific type string. + * + * Entries act as a combination of a subscriber and a weak publisher. The + * subscriber is active as long as the entry is not destroyed. The publisher + * is created when the entry is first written to, and remains active until + * either Unpublish() is called or the entry is destroyed. + * + * @note It is not possible to use two different data types with the same + * topic. Conflicts between publishers are typically resolved by the + * server on a first-come, first-served basis. Any published values that + * do not match the topic's data type are dropped (ignored), and the entry + * will show no new values if the data type does not match. To determine + * if the data type matches, use the appropriate Topic functions. + * + * @param typeString type string + * @param defaultValue default value used when a default is not provided to a + * getter function + * @param options publish and/or subscribe options + * @return entry + */ + [[nodiscard]] + EntryType GetEntryEx(std::string_view typeString, ParamType defaultValue, + const PubSubOptions& options = kDefaultPubSubOptions); + +}; + +} // namespace nt + +#include "networktables/DoubleTopic.inc" diff --git a/ntcore/src/generated/main/native/include/networktables/DoubleTopic.inc b/ntcore/src/generated/main/native/include/networktables/DoubleTopic.inc new file mode 100644 index 0000000000..49b1c4c8b5 --- /dev/null +++ b/ntcore/src/generated/main/native/include/networktables/DoubleTopic.inc @@ -0,0 +1,121 @@ +// 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. + +// THIS FILE WAS AUTO-GENERATED BY ./ntcore/generate_topics.py. DO NOT MODIFY + +#pragma once + +#include + +#include "networktables/DoubleTopic.h" +#include "networktables/NetworkTableType.h" +#include "ntcore_cpp.h" + +namespace nt { + +inline DoubleSubscriber::DoubleSubscriber( + NT_Subscriber handle, double defaultValue) + : Subscriber{handle}, + m_defaultValue{defaultValue} {} + +inline double DoubleSubscriber::Get() const { + return Get(m_defaultValue); +} + +inline double DoubleSubscriber::Get( + double defaultValue) const { + return ::nt::GetDouble(m_subHandle, defaultValue); +} + +inline TimestampedDouble DoubleSubscriber::GetAtomic() const { + return GetAtomic(m_defaultValue); +} + +inline TimestampedDouble DoubleSubscriber::GetAtomic( + double defaultValue) const { + return ::nt::GetAtomicDouble(m_subHandle, defaultValue); +} + +inline std::vector +DoubleSubscriber::ReadQueue() { + return ::nt::ReadQueueDouble(m_subHandle); +} + +inline DoubleTopic DoubleSubscriber::GetTopic() const { + return DoubleTopic{::nt::GetTopicFromHandle(m_subHandle)}; +} + +inline DoublePublisher::DoublePublisher(NT_Publisher handle) + : Publisher{handle} {} + +inline void DoublePublisher::Set(double value, + int64_t time) { + ::nt::SetDouble(m_pubHandle, value, time); +} + +inline void DoublePublisher::SetDefault(double value) { + ::nt::SetDefaultDouble(m_pubHandle, value); +} + +inline DoubleTopic DoublePublisher::GetTopic() const { + return DoubleTopic{::nt::GetTopicFromHandle(m_pubHandle)}; +} + +inline DoubleEntry::DoubleEntry( + NT_Entry handle, double defaultValue) + : DoubleSubscriber{handle, defaultValue}, + DoublePublisher{handle} {} + +inline DoubleTopic DoubleEntry::GetTopic() const { + return DoubleTopic{::nt::GetTopicFromHandle(m_subHandle)}; +} + +inline void DoubleEntry::Unpublish() { + ::nt::Unpublish(m_pubHandle); +} + +inline DoubleSubscriber DoubleTopic::Subscribe( + double defaultValue, + const PubSubOptions& options) { + return DoubleSubscriber{ + ::nt::Subscribe(m_handle, NT_DOUBLE, "double", options), + defaultValue}; +} +inline DoubleSubscriber DoubleTopic::SubscribeEx( + std::string_view typeString, double defaultValue, + const PubSubOptions& options) { + return DoubleSubscriber{ + ::nt::Subscribe(m_handle, NT_DOUBLE, typeString, options), + defaultValue}; +} + +inline DoublePublisher DoubleTopic::Publish( + const PubSubOptions& options) { + return DoublePublisher{ + ::nt::Publish(m_handle, NT_DOUBLE, "double", options)}; +} + +inline DoublePublisher DoubleTopic::PublishEx( + std::string_view typeString, + const wpi::json& properties, const PubSubOptions& options) { + return DoublePublisher{ + ::nt::PublishEx(m_handle, NT_DOUBLE, typeString, properties, options)}; +} + +inline DoubleEntry DoubleTopic::GetEntry( + double defaultValue, + const PubSubOptions& options) { + return DoubleEntry{ + ::nt::GetEntry(m_handle, NT_DOUBLE, "double", options), + defaultValue}; +} +inline DoubleEntry DoubleTopic::GetEntryEx( + std::string_view typeString, double defaultValue, + const PubSubOptions& options) { + return DoubleEntry{ + ::nt::GetEntry(m_handle, NT_DOUBLE, typeString, options), + defaultValue}; +} + +} // namespace nt diff --git a/ntcore/src/generated/main/native/include/networktables/FloatArrayTopic.h b/ntcore/src/generated/main/native/include/networktables/FloatArrayTopic.h new file mode 100644 index 0000000000..a0d2b66b33 --- /dev/null +++ b/ntcore/src/generated/main/native/include/networktables/FloatArrayTopic.h @@ -0,0 +1,426 @@ +// 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. + +// THIS FILE WAS AUTO-GENERATED BY ./ntcore/generate_topics.py. DO NOT MODIFY + +#pragma once + +#include + +#include +#include +#include +#include + +#include + +#include "networktables/Topic.h" + +namespace wpi { +template +class SmallVectorImpl; +} // namespace wpi + +namespace nt { + +class FloatArrayTopic; + +/** + * NetworkTables FloatArray subscriber. + */ +class FloatArraySubscriber : public Subscriber { + public: + using TopicType = FloatArrayTopic; + using ValueType = std::vector; + using ParamType = std::span; + using TimestampedValueType = TimestampedFloatArray; + + using SmallRetType = std::span; + using SmallElemType = float; + using TimestampedValueViewType = TimestampedFloatArrayView; + + + FloatArraySubscriber() = default; + + /** + * Construct from a subscriber handle; recommended to use + * FloatArrayTopic::Subscribe() instead. + * + * @param handle Native handle + * @param defaultValue Default value + */ + FloatArraySubscriber(NT_Subscriber handle, ParamType defaultValue); + + /** + * Get the last published value. + * If no value has been published, returns the stored default value. + * + * @return value + */ + ValueType Get() const; + + /** + * Get the last published value. + * If no value has been published, returns the passed defaultValue. + * + * @param defaultValue default value to return if no value has been published + * @return value + */ + ValueType Get(ParamType defaultValue) const; + + /** + * Get the last published value. + * If no value has been published, returns the stored default value. + * + * @param buf storage for returned value + * @return value + */ + SmallRetType Get(wpi::SmallVectorImpl& buf) const; + + /** + * Get the last published value. + * If no value has been published, returns the passed defaultValue. + * + * @param buf storage for returned value + * @param defaultValue default value to return if no value has been published + * @return value + */ + SmallRetType Get(wpi::SmallVectorImpl& buf, ParamType defaultValue) const; + + /** + * Get the last published value along with its timestamp + * If no value has been published, returns the stored default value and a + * timestamp of 0. + * + * @return timestamped value + */ + TimestampedValueType GetAtomic() const; + + /** + * Get the last published value along with its timestamp. + * If no value has been published, returns the passed defaultValue and a + * timestamp of 0. + * + * @param defaultValue default value to return if no value has been published + * @return timestamped value + */ + TimestampedValueType GetAtomic(ParamType defaultValue) const; + + /** + * Get the last published value along with its timestamp. + * If no value has been published, returns the stored default value and a + * timestamp of 0. + * + * @param buf storage for returned value + * @return timestamped value + */ + TimestampedValueViewType GetAtomic( + wpi::SmallVectorImpl& buf) const; + + /** + * Get the last published value along with its timestamp. + * If no value has been published, returns the passed defaultValue and a + * timestamp of 0. + * + * @param buf storage for returned value + * @param defaultValue default value to return if no value has been published + * @return timestamped value + */ + TimestampedValueViewType GetAtomic( + wpi::SmallVectorImpl& buf, + ParamType defaultValue) const; + + /** + * Get an array of all value changes since the last call to ReadQueue. + * Also provides a timestamp for each value. + * + * @note The "poll storage" subscribe option can be used to set the queue + * depth. + * + * @return Array of timestamped values; empty array if no new changes have + * been published since the previous call. + */ + std::vector ReadQueue(); + + /** + * Get the corresponding topic. + * + * @return Topic + */ + TopicType GetTopic() const; + + private: + ValueType m_defaultValue; +}; + +/** + * NetworkTables FloatArray publisher. + */ +class FloatArrayPublisher : public Publisher { + public: + using TopicType = FloatArrayTopic; + using ValueType = std::vector; + using ParamType = std::span; + + using SmallRetType = std::span; + using SmallElemType = float; + + using TimestampedValueType = TimestampedFloatArray; + + FloatArrayPublisher() = default; + + /** + * Construct from a publisher handle; recommended to use + * FloatArrayTopic::Publish() instead. + * + * @param handle Native handle + */ + explicit FloatArrayPublisher(NT_Publisher handle); + + /** + * Publish a new value. + * + * @param value value to publish + * @param time timestamp; 0 indicates current NT time should be used + */ + void Set(ParamType value, int64_t time = 0); + + /** + * Publish a default value. + * On reconnect, a default value will never be used in preference to a + * published value. + * + * @param value value + */ + void SetDefault(ParamType value); + + /** + * Get the corresponding topic. + * + * @return Topic + */ + TopicType GetTopic() const; +}; + +/** + * NetworkTables FloatArray entry. + * + * @note Unlike NetworkTableEntry, the entry goes away when this is destroyed. + */ +class FloatArrayEntry final : public FloatArraySubscriber, + public FloatArrayPublisher { + public: + using SubscriberType = FloatArraySubscriber; + using PublisherType = FloatArrayPublisher; + using TopicType = FloatArrayTopic; + using ValueType = std::vector; + using ParamType = std::span; + + using SmallRetType = std::span; + using SmallElemType = float; + + using TimestampedValueType = TimestampedFloatArray; + + FloatArrayEntry() = default; + + /** + * Construct from an entry handle; recommended to use + * FloatArrayTopic::GetEntry() instead. + * + * @param handle Native handle + * @param defaultValue Default value + */ + FloatArrayEntry(NT_Entry handle, ParamType defaultValue); + + /** + * Determines if the native handle is valid. + * + * @return True if the native handle is valid, false otherwise. + */ + explicit operator bool() const { return m_subHandle != 0; } + + /** + * Gets the native handle for the entry. + * + * @return Native handle + */ + NT_Entry GetHandle() const { return m_subHandle; } + + /** + * Get the corresponding topic. + * + * @return Topic + */ + TopicType GetTopic() const; + + /** + * Stops publishing the entry if it's published. + */ + void Unpublish(); +}; + +/** + * NetworkTables FloatArray topic. + */ +class FloatArrayTopic final : public Topic { + public: + using SubscriberType = FloatArraySubscriber; + using PublisherType = FloatArrayPublisher; + using EntryType = FloatArrayEntry; + using ValueType = std::vector; + using ParamType = std::span; + using TimestampedValueType = TimestampedFloatArray; + /** The default type string for this topic type. */ + static constexpr std::string_view kTypeString = "float[]"; + + FloatArrayTopic() = default; + + /** + * Construct from a topic handle; recommended to use + * NetworkTableInstance::GetFloatArrayTopic() instead. + * + * @param handle Native handle + */ + explicit FloatArrayTopic(NT_Topic handle) : Topic{handle} {} + + /** + * Construct from a generic topic. + * + * @param topic Topic + */ + explicit FloatArrayTopic(Topic topic) : Topic{topic} {} + + /** + * Create a new subscriber to the topic. + * + *

The subscriber is only active as long as the returned object + * is not destroyed. + * + * @note Subscribers that do not match the published data type do not return + * any values. To determine if the data type matches, use the appropriate + * Topic functions. + * + * @param defaultValue default value used when a default is not provided to a + * getter function + * @param options subscribe options + * @return subscriber + */ + [[nodiscard]] + SubscriberType Subscribe( + ParamType defaultValue, + const PubSubOptions& options = kDefaultPubSubOptions); + /** + * Create a new subscriber to the topic, with specific type string. + * + *

The subscriber is only active as long as the returned object + * is not destroyed. + * + * @note Subscribers that do not match the published data type do not return + * any values. To determine if the data type matches, use the appropriate + * Topic functions. + * + * @param typeString type string + * @param defaultValue default value used when a default is not provided to a + * getter function + * @param options subscribe options + * @return subscriber + */ + [[nodiscard]] + SubscriberType SubscribeEx( + std::string_view typeString, ParamType defaultValue, + const PubSubOptions& options = kDefaultPubSubOptions); + + /** + * Create a new publisher to the topic. + * + * The publisher is only active as long as the returned object + * is not destroyed. + * + * @note It is not possible to publish two different data types to the same + * topic. Conflicts between publishers are typically resolved by the + * server on a first-come, first-served basis. Any published values that + * do not match the topic's data type are dropped (ignored). To determine + * if the data type matches, use the appropriate Topic functions. + * + * @param options publish options + * @return publisher + */ + [[nodiscard]] + PublisherType Publish(const PubSubOptions& options = kDefaultPubSubOptions); + + /** + * Create a new publisher to the topic, with type string and initial + * properties. + * + * The publisher is only active as long as the returned object + * is not destroyed. + * + * @note It is not possible to publish two different data types to the same + * topic. Conflicts between publishers are typically resolved by the + * server on a first-come, first-served basis. Any published values that + * do not match the topic's data type are dropped (ignored). To determine + * if the data type matches, use the appropriate Topic functions. + * + * @param typeString type string + * @param properties JSON properties + * @param options publish options + * @return publisher + */ + [[nodiscard]] + PublisherType PublishEx(std::string_view typeString, + const wpi::json& properties, const PubSubOptions& options = kDefaultPubSubOptions); + + /** + * Create a new entry for the topic. + * + * Entries act as a combination of a subscriber and a weak publisher. The + * subscriber is active as long as the entry is not destroyed. The publisher + * is created when the entry is first written to, and remains active until + * either Unpublish() is called or the entry is destroyed. + * + * @note It is not possible to use two different data types with the same + * topic. Conflicts between publishers are typically resolved by the + * server on a first-come, first-served basis. Any published values that + * do not match the topic's data type are dropped (ignored), and the entry + * will show no new values if the data type does not match. To determine + * if the data type matches, use the appropriate Topic functions. + * + * @param defaultValue default value used when a default is not provided to a + * getter function + * @param options publish and/or subscribe options + * @return entry + */ + [[nodiscard]] + EntryType GetEntry(ParamType defaultValue, + const PubSubOptions& options = kDefaultPubSubOptions); + /** + * Create a new entry for the topic, with specific type string. + * + * Entries act as a combination of a subscriber and a weak publisher. The + * subscriber is active as long as the entry is not destroyed. The publisher + * is created when the entry is first written to, and remains active until + * either Unpublish() is called or the entry is destroyed. + * + * @note It is not possible to use two different data types with the same + * topic. Conflicts between publishers are typically resolved by the + * server on a first-come, first-served basis. Any published values that + * do not match the topic's data type are dropped (ignored), and the entry + * will show no new values if the data type does not match. To determine + * if the data type matches, use the appropriate Topic functions. + * + * @param typeString type string + * @param defaultValue default value used when a default is not provided to a + * getter function + * @param options publish and/or subscribe options + * @return entry + */ + [[nodiscard]] + EntryType GetEntryEx(std::string_view typeString, ParamType defaultValue, + const PubSubOptions& options = kDefaultPubSubOptions); + +}; + +} // namespace nt + +#include "networktables/FloatArrayTopic.inc" diff --git a/ntcore/src/generated/main/native/include/networktables/FloatArrayTopic.inc b/ntcore/src/generated/main/native/include/networktables/FloatArrayTopic.inc new file mode 100644 index 0000000000..93570765e1 --- /dev/null +++ b/ntcore/src/generated/main/native/include/networktables/FloatArrayTopic.inc @@ -0,0 +1,137 @@ +// 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. + +// THIS FILE WAS AUTO-GENERATED BY ./ntcore/generate_topics.py. DO NOT MODIFY + +#pragma once + +#include + +#include "networktables/FloatArrayTopic.h" +#include "networktables/NetworkTableType.h" +#include "ntcore_cpp.h" + +namespace nt { + +inline FloatArraySubscriber::FloatArraySubscriber( + NT_Subscriber handle, std::span defaultValue) + : Subscriber{handle}, + m_defaultValue{defaultValue.begin(), defaultValue.end()} {} + +inline std::vector FloatArraySubscriber::Get() const { + return Get(m_defaultValue); +} + +inline std::vector FloatArraySubscriber::Get( + std::span defaultValue) const { + return ::nt::GetFloatArray(m_subHandle, defaultValue); +} + +inline std::span FloatArraySubscriber::Get(wpi::SmallVectorImpl& buf) const { + return Get(buf, m_defaultValue); +} + +inline std::span FloatArraySubscriber::Get(wpi::SmallVectorImpl& buf, std::span defaultValue) const { + return nt::GetFloatArray(m_subHandle, buf, defaultValue); +} + +inline TimestampedFloatArray FloatArraySubscriber::GetAtomic() const { + return GetAtomic(m_defaultValue); +} + +inline TimestampedFloatArray FloatArraySubscriber::GetAtomic( + std::span defaultValue) const { + return ::nt::GetAtomicFloatArray(m_subHandle, defaultValue); +} + +inline TimestampedFloatArrayView FloatArraySubscriber::GetAtomic(wpi::SmallVectorImpl& buf) const { + return GetAtomic(buf, m_defaultValue); +} + +inline TimestampedFloatArrayView FloatArraySubscriber::GetAtomic(wpi::SmallVectorImpl& buf, std::span defaultValue) const { + return nt::GetAtomicFloatArray(m_subHandle, buf, defaultValue); +} + +inline std::vector +FloatArraySubscriber::ReadQueue() { + return ::nt::ReadQueueFloatArray(m_subHandle); +} + +inline FloatArrayTopic FloatArraySubscriber::GetTopic() const { + return FloatArrayTopic{::nt::GetTopicFromHandle(m_subHandle)}; +} + +inline FloatArrayPublisher::FloatArrayPublisher(NT_Publisher handle) + : Publisher{handle} {} + +inline void FloatArrayPublisher::Set(std::span value, + int64_t time) { + ::nt::SetFloatArray(m_pubHandle, value, time); +} + +inline void FloatArrayPublisher::SetDefault(std::span value) { + ::nt::SetDefaultFloatArray(m_pubHandle, value); +} + +inline FloatArrayTopic FloatArrayPublisher::GetTopic() const { + return FloatArrayTopic{::nt::GetTopicFromHandle(m_pubHandle)}; +} + +inline FloatArrayEntry::FloatArrayEntry( + NT_Entry handle, std::span defaultValue) + : FloatArraySubscriber{handle, defaultValue}, + FloatArrayPublisher{handle} {} + +inline FloatArrayTopic FloatArrayEntry::GetTopic() const { + return FloatArrayTopic{::nt::GetTopicFromHandle(m_subHandle)}; +} + +inline void FloatArrayEntry::Unpublish() { + ::nt::Unpublish(m_pubHandle); +} + +inline FloatArraySubscriber FloatArrayTopic::Subscribe( + std::span defaultValue, + const PubSubOptions& options) { + return FloatArraySubscriber{ + ::nt::Subscribe(m_handle, NT_FLOAT_ARRAY, "float[]", options), + defaultValue}; +} +inline FloatArraySubscriber FloatArrayTopic::SubscribeEx( + std::string_view typeString, std::span defaultValue, + const PubSubOptions& options) { + return FloatArraySubscriber{ + ::nt::Subscribe(m_handle, NT_FLOAT_ARRAY, typeString, options), + defaultValue}; +} + +inline FloatArrayPublisher FloatArrayTopic::Publish( + const PubSubOptions& options) { + return FloatArrayPublisher{ + ::nt::Publish(m_handle, NT_FLOAT_ARRAY, "float[]", options)}; +} + +inline FloatArrayPublisher FloatArrayTopic::PublishEx( + std::string_view typeString, + const wpi::json& properties, const PubSubOptions& options) { + return FloatArrayPublisher{ + ::nt::PublishEx(m_handle, NT_FLOAT_ARRAY, typeString, properties, options)}; +} + +inline FloatArrayEntry FloatArrayTopic::GetEntry( + std::span defaultValue, + const PubSubOptions& options) { + return FloatArrayEntry{ + ::nt::GetEntry(m_handle, NT_FLOAT_ARRAY, "float[]", options), + defaultValue}; +} +inline FloatArrayEntry FloatArrayTopic::GetEntryEx( + std::string_view typeString, std::span defaultValue, + const PubSubOptions& options) { + return FloatArrayEntry{ + ::nt::GetEntry(m_handle, NT_FLOAT_ARRAY, typeString, options), + defaultValue}; +} + +} // namespace nt diff --git a/ntcore/src/generated/main/native/include/networktables/FloatTopic.h b/ntcore/src/generated/main/native/include/networktables/FloatTopic.h new file mode 100644 index 0000000000..9a83834876 --- /dev/null +++ b/ntcore/src/generated/main/native/include/networktables/FloatTopic.h @@ -0,0 +1,373 @@ +// 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. + +// THIS FILE WAS AUTO-GENERATED BY ./ntcore/generate_topics.py. DO NOT MODIFY + +#pragma once + +#include + + +#include +#include +#include + +#include + +#include "networktables/Topic.h" + +namespace wpi { +template +class SmallVectorImpl; +} // namespace wpi + +namespace nt { + +class FloatTopic; + +/** + * NetworkTables Float subscriber. + */ +class FloatSubscriber : public Subscriber { + public: + using TopicType = FloatTopic; + using ValueType = float; + using ParamType = float; + using TimestampedValueType = TimestampedFloat; + + + FloatSubscriber() = default; + + /** + * Construct from a subscriber handle; recommended to use + * FloatTopic::Subscribe() instead. + * + * @param handle Native handle + * @param defaultValue Default value + */ + FloatSubscriber(NT_Subscriber handle, ParamType defaultValue); + + /** + * Get the last published value. + * If no value has been published, returns the stored default value. + * + * @return value + */ + ValueType Get() const; + + /** + * Get the last published value. + * If no value has been published, returns the passed defaultValue. + * + * @param defaultValue default value to return if no value has been published + * @return value + */ + ValueType Get(ParamType defaultValue) const; + + /** + * Get the last published value along with its timestamp + * If no value has been published, returns the stored default value and a + * timestamp of 0. + * + * @return timestamped value + */ + TimestampedValueType GetAtomic() const; + + /** + * Get the last published value along with its timestamp. + * If no value has been published, returns the passed defaultValue and a + * timestamp of 0. + * + * @param defaultValue default value to return if no value has been published + * @return timestamped value + */ + TimestampedValueType GetAtomic(ParamType defaultValue) const; + + /** + * Get an array of all value changes since the last call to ReadQueue. + * Also provides a timestamp for each value. + * + * @note The "poll storage" subscribe option can be used to set the queue + * depth. + * + * @return Array of timestamped values; empty array if no new changes have + * been published since the previous call. + */ + std::vector ReadQueue(); + + /** + * Get the corresponding topic. + * + * @return Topic + */ + TopicType GetTopic() const; + + private: + ValueType m_defaultValue; +}; + +/** + * NetworkTables Float publisher. + */ +class FloatPublisher : public Publisher { + public: + using TopicType = FloatTopic; + using ValueType = float; + using ParamType = float; + + using TimestampedValueType = TimestampedFloat; + + FloatPublisher() = default; + + /** + * Construct from a publisher handle; recommended to use + * FloatTopic::Publish() instead. + * + * @param handle Native handle + */ + explicit FloatPublisher(NT_Publisher handle); + + /** + * Publish a new value. + * + * @param value value to publish + * @param time timestamp; 0 indicates current NT time should be used + */ + void Set(ParamType value, int64_t time = 0); + + /** + * Publish a default value. + * On reconnect, a default value will never be used in preference to a + * published value. + * + * @param value value + */ + void SetDefault(ParamType value); + + /** + * Get the corresponding topic. + * + * @return Topic + */ + TopicType GetTopic() const; +}; + +/** + * NetworkTables Float entry. + * + * @note Unlike NetworkTableEntry, the entry goes away when this is destroyed. + */ +class FloatEntry final : public FloatSubscriber, + public FloatPublisher { + public: + using SubscriberType = FloatSubscriber; + using PublisherType = FloatPublisher; + using TopicType = FloatTopic; + using ValueType = float; + using ParamType = float; + + using TimestampedValueType = TimestampedFloat; + + FloatEntry() = default; + + /** + * Construct from an entry handle; recommended to use + * FloatTopic::GetEntry() instead. + * + * @param handle Native handle + * @param defaultValue Default value + */ + FloatEntry(NT_Entry handle, ParamType defaultValue); + + /** + * Determines if the native handle is valid. + * + * @return True if the native handle is valid, false otherwise. + */ + explicit operator bool() const { return m_subHandle != 0; } + + /** + * Gets the native handle for the entry. + * + * @return Native handle + */ + NT_Entry GetHandle() const { return m_subHandle; } + + /** + * Get the corresponding topic. + * + * @return Topic + */ + TopicType GetTopic() const; + + /** + * Stops publishing the entry if it's published. + */ + void Unpublish(); +}; + +/** + * NetworkTables Float topic. + */ +class FloatTopic final : public Topic { + public: + using SubscriberType = FloatSubscriber; + using PublisherType = FloatPublisher; + using EntryType = FloatEntry; + using ValueType = float; + using ParamType = float; + using TimestampedValueType = TimestampedFloat; + /** The default type string for this topic type. */ + static constexpr std::string_view kTypeString = "float"; + + FloatTopic() = default; + + /** + * Construct from a topic handle; recommended to use + * NetworkTableInstance::GetFloatTopic() instead. + * + * @param handle Native handle + */ + explicit FloatTopic(NT_Topic handle) : Topic{handle} {} + + /** + * Construct from a generic topic. + * + * @param topic Topic + */ + explicit FloatTopic(Topic topic) : Topic{topic} {} + + /** + * Create a new subscriber to the topic. + * + *

The subscriber is only active as long as the returned object + * is not destroyed. + * + * @note Subscribers that do not match the published data type do not return + * any values. To determine if the data type matches, use the appropriate + * Topic functions. + * + * @param defaultValue default value used when a default is not provided to a + * getter function + * @param options subscribe options + * @return subscriber + */ + [[nodiscard]] + SubscriberType Subscribe( + ParamType defaultValue, + const PubSubOptions& options = kDefaultPubSubOptions); + /** + * Create a new subscriber to the topic, with specific type string. + * + *

The subscriber is only active as long as the returned object + * is not destroyed. + * + * @note Subscribers that do not match the published data type do not return + * any values. To determine if the data type matches, use the appropriate + * Topic functions. + * + * @param typeString type string + * @param defaultValue default value used when a default is not provided to a + * getter function + * @param options subscribe options + * @return subscriber + */ + [[nodiscard]] + SubscriberType SubscribeEx( + std::string_view typeString, ParamType defaultValue, + const PubSubOptions& options = kDefaultPubSubOptions); + + /** + * Create a new publisher to the topic. + * + * The publisher is only active as long as the returned object + * is not destroyed. + * + * @note It is not possible to publish two different data types to the same + * topic. Conflicts between publishers are typically resolved by the + * server on a first-come, first-served basis. Any published values that + * do not match the topic's data type are dropped (ignored). To determine + * if the data type matches, use the appropriate Topic functions. + * + * @param options publish options + * @return publisher + */ + [[nodiscard]] + PublisherType Publish(const PubSubOptions& options = kDefaultPubSubOptions); + + /** + * Create a new publisher to the topic, with type string and initial + * properties. + * + * The publisher is only active as long as the returned object + * is not destroyed. + * + * @note It is not possible to publish two different data types to the same + * topic. Conflicts between publishers are typically resolved by the + * server on a first-come, first-served basis. Any published values that + * do not match the topic's data type are dropped (ignored). To determine + * if the data type matches, use the appropriate Topic functions. + * + * @param typeString type string + * @param properties JSON properties + * @param options publish options + * @return publisher + */ + [[nodiscard]] + PublisherType PublishEx(std::string_view typeString, + const wpi::json& properties, const PubSubOptions& options = kDefaultPubSubOptions); + + /** + * Create a new entry for the topic. + * + * Entries act as a combination of a subscriber and a weak publisher. The + * subscriber is active as long as the entry is not destroyed. The publisher + * is created when the entry is first written to, and remains active until + * either Unpublish() is called or the entry is destroyed. + * + * @note It is not possible to use two different data types with the same + * topic. Conflicts between publishers are typically resolved by the + * server on a first-come, first-served basis. Any published values that + * do not match the topic's data type are dropped (ignored), and the entry + * will show no new values if the data type does not match. To determine + * if the data type matches, use the appropriate Topic functions. + * + * @param defaultValue default value used when a default is not provided to a + * getter function + * @param options publish and/or subscribe options + * @return entry + */ + [[nodiscard]] + EntryType GetEntry(ParamType defaultValue, + const PubSubOptions& options = kDefaultPubSubOptions); + /** + * Create a new entry for the topic, with specific type string. + * + * Entries act as a combination of a subscriber and a weak publisher. The + * subscriber is active as long as the entry is not destroyed. The publisher + * is created when the entry is first written to, and remains active until + * either Unpublish() is called or the entry is destroyed. + * + * @note It is not possible to use two different data types with the same + * topic. Conflicts between publishers are typically resolved by the + * server on a first-come, first-served basis. Any published values that + * do not match the topic's data type are dropped (ignored), and the entry + * will show no new values if the data type does not match. To determine + * if the data type matches, use the appropriate Topic functions. + * + * @param typeString type string + * @param defaultValue default value used when a default is not provided to a + * getter function + * @param options publish and/or subscribe options + * @return entry + */ + [[nodiscard]] + EntryType GetEntryEx(std::string_view typeString, ParamType defaultValue, + const PubSubOptions& options = kDefaultPubSubOptions); + +}; + +} // namespace nt + +#include "networktables/FloatTopic.inc" diff --git a/ntcore/src/generated/main/native/include/networktables/FloatTopic.inc b/ntcore/src/generated/main/native/include/networktables/FloatTopic.inc new file mode 100644 index 0000000000..9df0f793ed --- /dev/null +++ b/ntcore/src/generated/main/native/include/networktables/FloatTopic.inc @@ -0,0 +1,121 @@ +// 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. + +// THIS FILE WAS AUTO-GENERATED BY ./ntcore/generate_topics.py. DO NOT MODIFY + +#pragma once + +#include + +#include "networktables/FloatTopic.h" +#include "networktables/NetworkTableType.h" +#include "ntcore_cpp.h" + +namespace nt { + +inline FloatSubscriber::FloatSubscriber( + NT_Subscriber handle, float defaultValue) + : Subscriber{handle}, + m_defaultValue{defaultValue} {} + +inline float FloatSubscriber::Get() const { + return Get(m_defaultValue); +} + +inline float FloatSubscriber::Get( + float defaultValue) const { + return ::nt::GetFloat(m_subHandle, defaultValue); +} + +inline TimestampedFloat FloatSubscriber::GetAtomic() const { + return GetAtomic(m_defaultValue); +} + +inline TimestampedFloat FloatSubscriber::GetAtomic( + float defaultValue) const { + return ::nt::GetAtomicFloat(m_subHandle, defaultValue); +} + +inline std::vector +FloatSubscriber::ReadQueue() { + return ::nt::ReadQueueFloat(m_subHandle); +} + +inline FloatTopic FloatSubscriber::GetTopic() const { + return FloatTopic{::nt::GetTopicFromHandle(m_subHandle)}; +} + +inline FloatPublisher::FloatPublisher(NT_Publisher handle) + : Publisher{handle} {} + +inline void FloatPublisher::Set(float value, + int64_t time) { + ::nt::SetFloat(m_pubHandle, value, time); +} + +inline void FloatPublisher::SetDefault(float value) { + ::nt::SetDefaultFloat(m_pubHandle, value); +} + +inline FloatTopic FloatPublisher::GetTopic() const { + return FloatTopic{::nt::GetTopicFromHandle(m_pubHandle)}; +} + +inline FloatEntry::FloatEntry( + NT_Entry handle, float defaultValue) + : FloatSubscriber{handle, defaultValue}, + FloatPublisher{handle} {} + +inline FloatTopic FloatEntry::GetTopic() const { + return FloatTopic{::nt::GetTopicFromHandle(m_subHandle)}; +} + +inline void FloatEntry::Unpublish() { + ::nt::Unpublish(m_pubHandle); +} + +inline FloatSubscriber FloatTopic::Subscribe( + float defaultValue, + const PubSubOptions& options) { + return FloatSubscriber{ + ::nt::Subscribe(m_handle, NT_FLOAT, "float", options), + defaultValue}; +} +inline FloatSubscriber FloatTopic::SubscribeEx( + std::string_view typeString, float defaultValue, + const PubSubOptions& options) { + return FloatSubscriber{ + ::nt::Subscribe(m_handle, NT_FLOAT, typeString, options), + defaultValue}; +} + +inline FloatPublisher FloatTopic::Publish( + const PubSubOptions& options) { + return FloatPublisher{ + ::nt::Publish(m_handle, NT_FLOAT, "float", options)}; +} + +inline FloatPublisher FloatTopic::PublishEx( + std::string_view typeString, + const wpi::json& properties, const PubSubOptions& options) { + return FloatPublisher{ + ::nt::PublishEx(m_handle, NT_FLOAT, typeString, properties, options)}; +} + +inline FloatEntry FloatTopic::GetEntry( + float defaultValue, + const PubSubOptions& options) { + return FloatEntry{ + ::nt::GetEntry(m_handle, NT_FLOAT, "float", options), + defaultValue}; +} +inline FloatEntry FloatTopic::GetEntryEx( + std::string_view typeString, float defaultValue, + const PubSubOptions& options) { + return FloatEntry{ + ::nt::GetEntry(m_handle, NT_FLOAT, typeString, options), + defaultValue}; +} + +} // namespace nt diff --git a/ntcore/src/generated/main/native/include/networktables/IntegerArrayTopic.h b/ntcore/src/generated/main/native/include/networktables/IntegerArrayTopic.h new file mode 100644 index 0000000000..a99823acd8 --- /dev/null +++ b/ntcore/src/generated/main/native/include/networktables/IntegerArrayTopic.h @@ -0,0 +1,426 @@ +// 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. + +// THIS FILE WAS AUTO-GENERATED BY ./ntcore/generate_topics.py. DO NOT MODIFY + +#pragma once + +#include + +#include +#include +#include +#include + +#include + +#include "networktables/Topic.h" + +namespace wpi { +template +class SmallVectorImpl; +} // namespace wpi + +namespace nt { + +class IntegerArrayTopic; + +/** + * NetworkTables IntegerArray subscriber. + */ +class IntegerArraySubscriber : public Subscriber { + public: + using TopicType = IntegerArrayTopic; + using ValueType = std::vector; + using ParamType = std::span; + using TimestampedValueType = TimestampedIntegerArray; + + using SmallRetType = std::span; + using SmallElemType = int64_t; + using TimestampedValueViewType = TimestampedIntegerArrayView; + + + IntegerArraySubscriber() = default; + + /** + * Construct from a subscriber handle; recommended to use + * IntegerArrayTopic::Subscribe() instead. + * + * @param handle Native handle + * @param defaultValue Default value + */ + IntegerArraySubscriber(NT_Subscriber handle, ParamType defaultValue); + + /** + * Get the last published value. + * If no value has been published, returns the stored default value. + * + * @return value + */ + ValueType Get() const; + + /** + * Get the last published value. + * If no value has been published, returns the passed defaultValue. + * + * @param defaultValue default value to return if no value has been published + * @return value + */ + ValueType Get(ParamType defaultValue) const; + + /** + * Get the last published value. + * If no value has been published, returns the stored default value. + * + * @param buf storage for returned value + * @return value + */ + SmallRetType Get(wpi::SmallVectorImpl& buf) const; + + /** + * Get the last published value. + * If no value has been published, returns the passed defaultValue. + * + * @param buf storage for returned value + * @param defaultValue default value to return if no value has been published + * @return value + */ + SmallRetType Get(wpi::SmallVectorImpl& buf, ParamType defaultValue) const; + + /** + * Get the last published value along with its timestamp + * If no value has been published, returns the stored default value and a + * timestamp of 0. + * + * @return timestamped value + */ + TimestampedValueType GetAtomic() const; + + /** + * Get the last published value along with its timestamp. + * If no value has been published, returns the passed defaultValue and a + * timestamp of 0. + * + * @param defaultValue default value to return if no value has been published + * @return timestamped value + */ + TimestampedValueType GetAtomic(ParamType defaultValue) const; + + /** + * Get the last published value along with its timestamp. + * If no value has been published, returns the stored default value and a + * timestamp of 0. + * + * @param buf storage for returned value + * @return timestamped value + */ + TimestampedValueViewType GetAtomic( + wpi::SmallVectorImpl& buf) const; + + /** + * Get the last published value along with its timestamp. + * If no value has been published, returns the passed defaultValue and a + * timestamp of 0. + * + * @param buf storage for returned value + * @param defaultValue default value to return if no value has been published + * @return timestamped value + */ + TimestampedValueViewType GetAtomic( + wpi::SmallVectorImpl& buf, + ParamType defaultValue) const; + + /** + * Get an array of all value changes since the last call to ReadQueue. + * Also provides a timestamp for each value. + * + * @note The "poll storage" subscribe option can be used to set the queue + * depth. + * + * @return Array of timestamped values; empty array if no new changes have + * been published since the previous call. + */ + std::vector ReadQueue(); + + /** + * Get the corresponding topic. + * + * @return Topic + */ + TopicType GetTopic() const; + + private: + ValueType m_defaultValue; +}; + +/** + * NetworkTables IntegerArray publisher. + */ +class IntegerArrayPublisher : public Publisher { + public: + using TopicType = IntegerArrayTopic; + using ValueType = std::vector; + using ParamType = std::span; + + using SmallRetType = std::span; + using SmallElemType = int64_t; + + using TimestampedValueType = TimestampedIntegerArray; + + IntegerArrayPublisher() = default; + + /** + * Construct from a publisher handle; recommended to use + * IntegerArrayTopic::Publish() instead. + * + * @param handle Native handle + */ + explicit IntegerArrayPublisher(NT_Publisher handle); + + /** + * Publish a new value. + * + * @param value value to publish + * @param time timestamp; 0 indicates current NT time should be used + */ + void Set(ParamType value, int64_t time = 0); + + /** + * Publish a default value. + * On reconnect, a default value will never be used in preference to a + * published value. + * + * @param value value + */ + void SetDefault(ParamType value); + + /** + * Get the corresponding topic. + * + * @return Topic + */ + TopicType GetTopic() const; +}; + +/** + * NetworkTables IntegerArray entry. + * + * @note Unlike NetworkTableEntry, the entry goes away when this is destroyed. + */ +class IntegerArrayEntry final : public IntegerArraySubscriber, + public IntegerArrayPublisher { + public: + using SubscriberType = IntegerArraySubscriber; + using PublisherType = IntegerArrayPublisher; + using TopicType = IntegerArrayTopic; + using ValueType = std::vector; + using ParamType = std::span; + + using SmallRetType = std::span; + using SmallElemType = int64_t; + + using TimestampedValueType = TimestampedIntegerArray; + + IntegerArrayEntry() = default; + + /** + * Construct from an entry handle; recommended to use + * IntegerArrayTopic::GetEntry() instead. + * + * @param handle Native handle + * @param defaultValue Default value + */ + IntegerArrayEntry(NT_Entry handle, ParamType defaultValue); + + /** + * Determines if the native handle is valid. + * + * @return True if the native handle is valid, false otherwise. + */ + explicit operator bool() const { return m_subHandle != 0; } + + /** + * Gets the native handle for the entry. + * + * @return Native handle + */ + NT_Entry GetHandle() const { return m_subHandle; } + + /** + * Get the corresponding topic. + * + * @return Topic + */ + TopicType GetTopic() const; + + /** + * Stops publishing the entry if it's published. + */ + void Unpublish(); +}; + +/** + * NetworkTables IntegerArray topic. + */ +class IntegerArrayTopic final : public Topic { + public: + using SubscriberType = IntegerArraySubscriber; + using PublisherType = IntegerArrayPublisher; + using EntryType = IntegerArrayEntry; + using ValueType = std::vector; + using ParamType = std::span; + using TimestampedValueType = TimestampedIntegerArray; + /** The default type string for this topic type. */ + static constexpr std::string_view kTypeString = "int[]"; + + IntegerArrayTopic() = default; + + /** + * Construct from a topic handle; recommended to use + * NetworkTableInstance::GetIntegerArrayTopic() instead. + * + * @param handle Native handle + */ + explicit IntegerArrayTopic(NT_Topic handle) : Topic{handle} {} + + /** + * Construct from a generic topic. + * + * @param topic Topic + */ + explicit IntegerArrayTopic(Topic topic) : Topic{topic} {} + + /** + * Create a new subscriber to the topic. + * + *

The subscriber is only active as long as the returned object + * is not destroyed. + * + * @note Subscribers that do not match the published data type do not return + * any values. To determine if the data type matches, use the appropriate + * Topic functions. + * + * @param defaultValue default value used when a default is not provided to a + * getter function + * @param options subscribe options + * @return subscriber + */ + [[nodiscard]] + SubscriberType Subscribe( + ParamType defaultValue, + const PubSubOptions& options = kDefaultPubSubOptions); + /** + * Create a new subscriber to the topic, with specific type string. + * + *

The subscriber is only active as long as the returned object + * is not destroyed. + * + * @note Subscribers that do not match the published data type do not return + * any values. To determine if the data type matches, use the appropriate + * Topic functions. + * + * @param typeString type string + * @param defaultValue default value used when a default is not provided to a + * getter function + * @param options subscribe options + * @return subscriber + */ + [[nodiscard]] + SubscriberType SubscribeEx( + std::string_view typeString, ParamType defaultValue, + const PubSubOptions& options = kDefaultPubSubOptions); + + /** + * Create a new publisher to the topic. + * + * The publisher is only active as long as the returned object + * is not destroyed. + * + * @note It is not possible to publish two different data types to the same + * topic. Conflicts between publishers are typically resolved by the + * server on a first-come, first-served basis. Any published values that + * do not match the topic's data type are dropped (ignored). To determine + * if the data type matches, use the appropriate Topic functions. + * + * @param options publish options + * @return publisher + */ + [[nodiscard]] + PublisherType Publish(const PubSubOptions& options = kDefaultPubSubOptions); + + /** + * Create a new publisher to the topic, with type string and initial + * properties. + * + * The publisher is only active as long as the returned object + * is not destroyed. + * + * @note It is not possible to publish two different data types to the same + * topic. Conflicts between publishers are typically resolved by the + * server on a first-come, first-served basis. Any published values that + * do not match the topic's data type are dropped (ignored). To determine + * if the data type matches, use the appropriate Topic functions. + * + * @param typeString type string + * @param properties JSON properties + * @param options publish options + * @return publisher + */ + [[nodiscard]] + PublisherType PublishEx(std::string_view typeString, + const wpi::json& properties, const PubSubOptions& options = kDefaultPubSubOptions); + + /** + * Create a new entry for the topic. + * + * Entries act as a combination of a subscriber and a weak publisher. The + * subscriber is active as long as the entry is not destroyed. The publisher + * is created when the entry is first written to, and remains active until + * either Unpublish() is called or the entry is destroyed. + * + * @note It is not possible to use two different data types with the same + * topic. Conflicts between publishers are typically resolved by the + * server on a first-come, first-served basis. Any published values that + * do not match the topic's data type are dropped (ignored), and the entry + * will show no new values if the data type does not match. To determine + * if the data type matches, use the appropriate Topic functions. + * + * @param defaultValue default value used when a default is not provided to a + * getter function + * @param options publish and/or subscribe options + * @return entry + */ + [[nodiscard]] + EntryType GetEntry(ParamType defaultValue, + const PubSubOptions& options = kDefaultPubSubOptions); + /** + * Create a new entry for the topic, with specific type string. + * + * Entries act as a combination of a subscriber and a weak publisher. The + * subscriber is active as long as the entry is not destroyed. The publisher + * is created when the entry is first written to, and remains active until + * either Unpublish() is called or the entry is destroyed. + * + * @note It is not possible to use two different data types with the same + * topic. Conflicts between publishers are typically resolved by the + * server on a first-come, first-served basis. Any published values that + * do not match the topic's data type are dropped (ignored), and the entry + * will show no new values if the data type does not match. To determine + * if the data type matches, use the appropriate Topic functions. + * + * @param typeString type string + * @param defaultValue default value used when a default is not provided to a + * getter function + * @param options publish and/or subscribe options + * @return entry + */ + [[nodiscard]] + EntryType GetEntryEx(std::string_view typeString, ParamType defaultValue, + const PubSubOptions& options = kDefaultPubSubOptions); + +}; + +} // namespace nt + +#include "networktables/IntegerArrayTopic.inc" diff --git a/ntcore/src/generated/main/native/include/networktables/IntegerArrayTopic.inc b/ntcore/src/generated/main/native/include/networktables/IntegerArrayTopic.inc new file mode 100644 index 0000000000..ba3d00d1d2 --- /dev/null +++ b/ntcore/src/generated/main/native/include/networktables/IntegerArrayTopic.inc @@ -0,0 +1,137 @@ +// 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. + +// THIS FILE WAS AUTO-GENERATED BY ./ntcore/generate_topics.py. DO NOT MODIFY + +#pragma once + +#include + +#include "networktables/IntegerArrayTopic.h" +#include "networktables/NetworkTableType.h" +#include "ntcore_cpp.h" + +namespace nt { + +inline IntegerArraySubscriber::IntegerArraySubscriber( + NT_Subscriber handle, std::span defaultValue) + : Subscriber{handle}, + m_defaultValue{defaultValue.begin(), defaultValue.end()} {} + +inline std::vector IntegerArraySubscriber::Get() const { + return Get(m_defaultValue); +} + +inline std::vector IntegerArraySubscriber::Get( + std::span defaultValue) const { + return ::nt::GetIntegerArray(m_subHandle, defaultValue); +} + +inline std::span IntegerArraySubscriber::Get(wpi::SmallVectorImpl& buf) const { + return Get(buf, m_defaultValue); +} + +inline std::span IntegerArraySubscriber::Get(wpi::SmallVectorImpl& buf, std::span defaultValue) const { + return nt::GetIntegerArray(m_subHandle, buf, defaultValue); +} + +inline TimestampedIntegerArray IntegerArraySubscriber::GetAtomic() const { + return GetAtomic(m_defaultValue); +} + +inline TimestampedIntegerArray IntegerArraySubscriber::GetAtomic( + std::span defaultValue) const { + return ::nt::GetAtomicIntegerArray(m_subHandle, defaultValue); +} + +inline TimestampedIntegerArrayView IntegerArraySubscriber::GetAtomic(wpi::SmallVectorImpl& buf) const { + return GetAtomic(buf, m_defaultValue); +} + +inline TimestampedIntegerArrayView IntegerArraySubscriber::GetAtomic(wpi::SmallVectorImpl& buf, std::span defaultValue) const { + return nt::GetAtomicIntegerArray(m_subHandle, buf, defaultValue); +} + +inline std::vector +IntegerArraySubscriber::ReadQueue() { + return ::nt::ReadQueueIntegerArray(m_subHandle); +} + +inline IntegerArrayTopic IntegerArraySubscriber::GetTopic() const { + return IntegerArrayTopic{::nt::GetTopicFromHandle(m_subHandle)}; +} + +inline IntegerArrayPublisher::IntegerArrayPublisher(NT_Publisher handle) + : Publisher{handle} {} + +inline void IntegerArrayPublisher::Set(std::span value, + int64_t time) { + ::nt::SetIntegerArray(m_pubHandle, value, time); +} + +inline void IntegerArrayPublisher::SetDefault(std::span value) { + ::nt::SetDefaultIntegerArray(m_pubHandle, value); +} + +inline IntegerArrayTopic IntegerArrayPublisher::GetTopic() const { + return IntegerArrayTopic{::nt::GetTopicFromHandle(m_pubHandle)}; +} + +inline IntegerArrayEntry::IntegerArrayEntry( + NT_Entry handle, std::span defaultValue) + : IntegerArraySubscriber{handle, defaultValue}, + IntegerArrayPublisher{handle} {} + +inline IntegerArrayTopic IntegerArrayEntry::GetTopic() const { + return IntegerArrayTopic{::nt::GetTopicFromHandle(m_subHandle)}; +} + +inline void IntegerArrayEntry::Unpublish() { + ::nt::Unpublish(m_pubHandle); +} + +inline IntegerArraySubscriber IntegerArrayTopic::Subscribe( + std::span defaultValue, + const PubSubOptions& options) { + return IntegerArraySubscriber{ + ::nt::Subscribe(m_handle, NT_INTEGER_ARRAY, "int[]", options), + defaultValue}; +} +inline IntegerArraySubscriber IntegerArrayTopic::SubscribeEx( + std::string_view typeString, std::span defaultValue, + const PubSubOptions& options) { + return IntegerArraySubscriber{ + ::nt::Subscribe(m_handle, NT_INTEGER_ARRAY, typeString, options), + defaultValue}; +} + +inline IntegerArrayPublisher IntegerArrayTopic::Publish( + const PubSubOptions& options) { + return IntegerArrayPublisher{ + ::nt::Publish(m_handle, NT_INTEGER_ARRAY, "int[]", options)}; +} + +inline IntegerArrayPublisher IntegerArrayTopic::PublishEx( + std::string_view typeString, + const wpi::json& properties, const PubSubOptions& options) { + return IntegerArrayPublisher{ + ::nt::PublishEx(m_handle, NT_INTEGER_ARRAY, typeString, properties, options)}; +} + +inline IntegerArrayEntry IntegerArrayTopic::GetEntry( + std::span defaultValue, + const PubSubOptions& options) { + return IntegerArrayEntry{ + ::nt::GetEntry(m_handle, NT_INTEGER_ARRAY, "int[]", options), + defaultValue}; +} +inline IntegerArrayEntry IntegerArrayTopic::GetEntryEx( + std::string_view typeString, std::span defaultValue, + const PubSubOptions& options) { + return IntegerArrayEntry{ + ::nt::GetEntry(m_handle, NT_INTEGER_ARRAY, typeString, options), + defaultValue}; +} + +} // namespace nt diff --git a/ntcore/src/generated/main/native/include/networktables/IntegerTopic.h b/ntcore/src/generated/main/native/include/networktables/IntegerTopic.h new file mode 100644 index 0000000000..0d5ab21492 --- /dev/null +++ b/ntcore/src/generated/main/native/include/networktables/IntegerTopic.h @@ -0,0 +1,373 @@ +// 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. + +// THIS FILE WAS AUTO-GENERATED BY ./ntcore/generate_topics.py. DO NOT MODIFY + +#pragma once + +#include + + +#include +#include +#include + +#include + +#include "networktables/Topic.h" + +namespace wpi { +template +class SmallVectorImpl; +} // namespace wpi + +namespace nt { + +class IntegerTopic; + +/** + * NetworkTables Integer subscriber. + */ +class IntegerSubscriber : public Subscriber { + public: + using TopicType = IntegerTopic; + using ValueType = int64_t; + using ParamType = int64_t; + using TimestampedValueType = TimestampedInteger; + + + IntegerSubscriber() = default; + + /** + * Construct from a subscriber handle; recommended to use + * IntegerTopic::Subscribe() instead. + * + * @param handle Native handle + * @param defaultValue Default value + */ + IntegerSubscriber(NT_Subscriber handle, ParamType defaultValue); + + /** + * Get the last published value. + * If no value has been published, returns the stored default value. + * + * @return value + */ + ValueType Get() const; + + /** + * Get the last published value. + * If no value has been published, returns the passed defaultValue. + * + * @param defaultValue default value to return if no value has been published + * @return value + */ + ValueType Get(ParamType defaultValue) const; + + /** + * Get the last published value along with its timestamp + * If no value has been published, returns the stored default value and a + * timestamp of 0. + * + * @return timestamped value + */ + TimestampedValueType GetAtomic() const; + + /** + * Get the last published value along with its timestamp. + * If no value has been published, returns the passed defaultValue and a + * timestamp of 0. + * + * @param defaultValue default value to return if no value has been published + * @return timestamped value + */ + TimestampedValueType GetAtomic(ParamType defaultValue) const; + + /** + * Get an array of all value changes since the last call to ReadQueue. + * Also provides a timestamp for each value. + * + * @note The "poll storage" subscribe option can be used to set the queue + * depth. + * + * @return Array of timestamped values; empty array if no new changes have + * been published since the previous call. + */ + std::vector ReadQueue(); + + /** + * Get the corresponding topic. + * + * @return Topic + */ + TopicType GetTopic() const; + + private: + ValueType m_defaultValue; +}; + +/** + * NetworkTables Integer publisher. + */ +class IntegerPublisher : public Publisher { + public: + using TopicType = IntegerTopic; + using ValueType = int64_t; + using ParamType = int64_t; + + using TimestampedValueType = TimestampedInteger; + + IntegerPublisher() = default; + + /** + * Construct from a publisher handle; recommended to use + * IntegerTopic::Publish() instead. + * + * @param handle Native handle + */ + explicit IntegerPublisher(NT_Publisher handle); + + /** + * Publish a new value. + * + * @param value value to publish + * @param time timestamp; 0 indicates current NT time should be used + */ + void Set(ParamType value, int64_t time = 0); + + /** + * Publish a default value. + * On reconnect, a default value will never be used in preference to a + * published value. + * + * @param value value + */ + void SetDefault(ParamType value); + + /** + * Get the corresponding topic. + * + * @return Topic + */ + TopicType GetTopic() const; +}; + +/** + * NetworkTables Integer entry. + * + * @note Unlike NetworkTableEntry, the entry goes away when this is destroyed. + */ +class IntegerEntry final : public IntegerSubscriber, + public IntegerPublisher { + public: + using SubscriberType = IntegerSubscriber; + using PublisherType = IntegerPublisher; + using TopicType = IntegerTopic; + using ValueType = int64_t; + using ParamType = int64_t; + + using TimestampedValueType = TimestampedInteger; + + IntegerEntry() = default; + + /** + * Construct from an entry handle; recommended to use + * IntegerTopic::GetEntry() instead. + * + * @param handle Native handle + * @param defaultValue Default value + */ + IntegerEntry(NT_Entry handle, ParamType defaultValue); + + /** + * Determines if the native handle is valid. + * + * @return True if the native handle is valid, false otherwise. + */ + explicit operator bool() const { return m_subHandle != 0; } + + /** + * Gets the native handle for the entry. + * + * @return Native handle + */ + NT_Entry GetHandle() const { return m_subHandle; } + + /** + * Get the corresponding topic. + * + * @return Topic + */ + TopicType GetTopic() const; + + /** + * Stops publishing the entry if it's published. + */ + void Unpublish(); +}; + +/** + * NetworkTables Integer topic. + */ +class IntegerTopic final : public Topic { + public: + using SubscriberType = IntegerSubscriber; + using PublisherType = IntegerPublisher; + using EntryType = IntegerEntry; + using ValueType = int64_t; + using ParamType = int64_t; + using TimestampedValueType = TimestampedInteger; + /** The default type string for this topic type. */ + static constexpr std::string_view kTypeString = "int"; + + IntegerTopic() = default; + + /** + * Construct from a topic handle; recommended to use + * NetworkTableInstance::GetIntegerTopic() instead. + * + * @param handle Native handle + */ + explicit IntegerTopic(NT_Topic handle) : Topic{handle} {} + + /** + * Construct from a generic topic. + * + * @param topic Topic + */ + explicit IntegerTopic(Topic topic) : Topic{topic} {} + + /** + * Create a new subscriber to the topic. + * + *

The subscriber is only active as long as the returned object + * is not destroyed. + * + * @note Subscribers that do not match the published data type do not return + * any values. To determine if the data type matches, use the appropriate + * Topic functions. + * + * @param defaultValue default value used when a default is not provided to a + * getter function + * @param options subscribe options + * @return subscriber + */ + [[nodiscard]] + SubscriberType Subscribe( + ParamType defaultValue, + const PubSubOptions& options = kDefaultPubSubOptions); + /** + * Create a new subscriber to the topic, with specific type string. + * + *

The subscriber is only active as long as the returned object + * is not destroyed. + * + * @note Subscribers that do not match the published data type do not return + * any values. To determine if the data type matches, use the appropriate + * Topic functions. + * + * @param typeString type string + * @param defaultValue default value used when a default is not provided to a + * getter function + * @param options subscribe options + * @return subscriber + */ + [[nodiscard]] + SubscriberType SubscribeEx( + std::string_view typeString, ParamType defaultValue, + const PubSubOptions& options = kDefaultPubSubOptions); + + /** + * Create a new publisher to the topic. + * + * The publisher is only active as long as the returned object + * is not destroyed. + * + * @note It is not possible to publish two different data types to the same + * topic. Conflicts between publishers are typically resolved by the + * server on a first-come, first-served basis. Any published values that + * do not match the topic's data type are dropped (ignored). To determine + * if the data type matches, use the appropriate Topic functions. + * + * @param options publish options + * @return publisher + */ + [[nodiscard]] + PublisherType Publish(const PubSubOptions& options = kDefaultPubSubOptions); + + /** + * Create a new publisher to the topic, with type string and initial + * properties. + * + * The publisher is only active as long as the returned object + * is not destroyed. + * + * @note It is not possible to publish two different data types to the same + * topic. Conflicts between publishers are typically resolved by the + * server on a first-come, first-served basis. Any published values that + * do not match the topic's data type are dropped (ignored). To determine + * if the data type matches, use the appropriate Topic functions. + * + * @param typeString type string + * @param properties JSON properties + * @param options publish options + * @return publisher + */ + [[nodiscard]] + PublisherType PublishEx(std::string_view typeString, + const wpi::json& properties, const PubSubOptions& options = kDefaultPubSubOptions); + + /** + * Create a new entry for the topic. + * + * Entries act as a combination of a subscriber and a weak publisher. The + * subscriber is active as long as the entry is not destroyed. The publisher + * is created when the entry is first written to, and remains active until + * either Unpublish() is called or the entry is destroyed. + * + * @note It is not possible to use two different data types with the same + * topic. Conflicts between publishers are typically resolved by the + * server on a first-come, first-served basis. Any published values that + * do not match the topic's data type are dropped (ignored), and the entry + * will show no new values if the data type does not match. To determine + * if the data type matches, use the appropriate Topic functions. + * + * @param defaultValue default value used when a default is not provided to a + * getter function + * @param options publish and/or subscribe options + * @return entry + */ + [[nodiscard]] + EntryType GetEntry(ParamType defaultValue, + const PubSubOptions& options = kDefaultPubSubOptions); + /** + * Create a new entry for the topic, with specific type string. + * + * Entries act as a combination of a subscriber and a weak publisher. The + * subscriber is active as long as the entry is not destroyed. The publisher + * is created when the entry is first written to, and remains active until + * either Unpublish() is called or the entry is destroyed. + * + * @note It is not possible to use two different data types with the same + * topic. Conflicts between publishers are typically resolved by the + * server on a first-come, first-served basis. Any published values that + * do not match the topic's data type are dropped (ignored), and the entry + * will show no new values if the data type does not match. To determine + * if the data type matches, use the appropriate Topic functions. + * + * @param typeString type string + * @param defaultValue default value used when a default is not provided to a + * getter function + * @param options publish and/or subscribe options + * @return entry + */ + [[nodiscard]] + EntryType GetEntryEx(std::string_view typeString, ParamType defaultValue, + const PubSubOptions& options = kDefaultPubSubOptions); + +}; + +} // namespace nt + +#include "networktables/IntegerTopic.inc" diff --git a/ntcore/src/generated/main/native/include/networktables/IntegerTopic.inc b/ntcore/src/generated/main/native/include/networktables/IntegerTopic.inc new file mode 100644 index 0000000000..2ca31e53e1 --- /dev/null +++ b/ntcore/src/generated/main/native/include/networktables/IntegerTopic.inc @@ -0,0 +1,121 @@ +// 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. + +// THIS FILE WAS AUTO-GENERATED BY ./ntcore/generate_topics.py. DO NOT MODIFY + +#pragma once + +#include + +#include "networktables/IntegerTopic.h" +#include "networktables/NetworkTableType.h" +#include "ntcore_cpp.h" + +namespace nt { + +inline IntegerSubscriber::IntegerSubscriber( + NT_Subscriber handle, int64_t defaultValue) + : Subscriber{handle}, + m_defaultValue{defaultValue} {} + +inline int64_t IntegerSubscriber::Get() const { + return Get(m_defaultValue); +} + +inline int64_t IntegerSubscriber::Get( + int64_t defaultValue) const { + return ::nt::GetInteger(m_subHandle, defaultValue); +} + +inline TimestampedInteger IntegerSubscriber::GetAtomic() const { + return GetAtomic(m_defaultValue); +} + +inline TimestampedInteger IntegerSubscriber::GetAtomic( + int64_t defaultValue) const { + return ::nt::GetAtomicInteger(m_subHandle, defaultValue); +} + +inline std::vector +IntegerSubscriber::ReadQueue() { + return ::nt::ReadQueueInteger(m_subHandle); +} + +inline IntegerTopic IntegerSubscriber::GetTopic() const { + return IntegerTopic{::nt::GetTopicFromHandle(m_subHandle)}; +} + +inline IntegerPublisher::IntegerPublisher(NT_Publisher handle) + : Publisher{handle} {} + +inline void IntegerPublisher::Set(int64_t value, + int64_t time) { + ::nt::SetInteger(m_pubHandle, value, time); +} + +inline void IntegerPublisher::SetDefault(int64_t value) { + ::nt::SetDefaultInteger(m_pubHandle, value); +} + +inline IntegerTopic IntegerPublisher::GetTopic() const { + return IntegerTopic{::nt::GetTopicFromHandle(m_pubHandle)}; +} + +inline IntegerEntry::IntegerEntry( + NT_Entry handle, int64_t defaultValue) + : IntegerSubscriber{handle, defaultValue}, + IntegerPublisher{handle} {} + +inline IntegerTopic IntegerEntry::GetTopic() const { + return IntegerTopic{::nt::GetTopicFromHandle(m_subHandle)}; +} + +inline void IntegerEntry::Unpublish() { + ::nt::Unpublish(m_pubHandle); +} + +inline IntegerSubscriber IntegerTopic::Subscribe( + int64_t defaultValue, + const PubSubOptions& options) { + return IntegerSubscriber{ + ::nt::Subscribe(m_handle, NT_INTEGER, "int", options), + defaultValue}; +} +inline IntegerSubscriber IntegerTopic::SubscribeEx( + std::string_view typeString, int64_t defaultValue, + const PubSubOptions& options) { + return IntegerSubscriber{ + ::nt::Subscribe(m_handle, NT_INTEGER, typeString, options), + defaultValue}; +} + +inline IntegerPublisher IntegerTopic::Publish( + const PubSubOptions& options) { + return IntegerPublisher{ + ::nt::Publish(m_handle, NT_INTEGER, "int", options)}; +} + +inline IntegerPublisher IntegerTopic::PublishEx( + std::string_view typeString, + const wpi::json& properties, const PubSubOptions& options) { + return IntegerPublisher{ + ::nt::PublishEx(m_handle, NT_INTEGER, typeString, properties, options)}; +} + +inline IntegerEntry IntegerTopic::GetEntry( + int64_t defaultValue, + const PubSubOptions& options) { + return IntegerEntry{ + ::nt::GetEntry(m_handle, NT_INTEGER, "int", options), + defaultValue}; +} +inline IntegerEntry IntegerTopic::GetEntryEx( + std::string_view typeString, int64_t defaultValue, + const PubSubOptions& options) { + return IntegerEntry{ + ::nt::GetEntry(m_handle, NT_INTEGER, typeString, options), + defaultValue}; +} + +} // namespace nt diff --git a/ntcore/src/generated/main/native/include/networktables/RawTopic.h b/ntcore/src/generated/main/native/include/networktables/RawTopic.h new file mode 100644 index 0000000000..e124fe1db6 --- /dev/null +++ b/ntcore/src/generated/main/native/include/networktables/RawTopic.h @@ -0,0 +1,384 @@ +// 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. + +// THIS FILE WAS AUTO-GENERATED BY ./ntcore/generate_topics.py. DO NOT MODIFY + +#pragma once + +#include + +#include +#include +#include +#include + +#include + +#include "networktables/Topic.h" + +namespace wpi { +template +class SmallVectorImpl; +} // namespace wpi + +namespace nt { + +class RawTopic; + +/** + * NetworkTables Raw subscriber. + */ +class RawSubscriber : public Subscriber { + public: + using TopicType = RawTopic; + using ValueType = std::vector; + using ParamType = std::span; + using TimestampedValueType = TimestampedRaw; + + using SmallRetType = std::span; + using SmallElemType = uint8_t; + using TimestampedValueViewType = TimestampedRawView; + + + RawSubscriber() = default; + + /** + * Construct from a subscriber handle; recommended to use + * RawTopic::Subscribe() instead. + * + * @param handle Native handle + * @param defaultValue Default value + */ + RawSubscriber(NT_Subscriber handle, ParamType defaultValue); + + /** + * Get the last published value. + * If no value has been published, returns the stored default value. + * + * @return value + */ + ValueType Get() const; + + /** + * Get the last published value. + * If no value has been published, returns the passed defaultValue. + * + * @param defaultValue default value to return if no value has been published + * @return value + */ + ValueType Get(ParamType defaultValue) const; + + /** + * Get the last published value. + * If no value has been published, returns the stored default value. + * + * @param buf storage for returned value + * @return value + */ + SmallRetType Get(wpi::SmallVectorImpl& buf) const; + + /** + * Get the last published value. + * If no value has been published, returns the passed defaultValue. + * + * @param buf storage for returned value + * @param defaultValue default value to return if no value has been published + * @return value + */ + SmallRetType Get(wpi::SmallVectorImpl& buf, ParamType defaultValue) const; + + /** + * Get the last published value along with its timestamp + * If no value has been published, returns the stored default value and a + * timestamp of 0. + * + * @return timestamped value + */ + TimestampedValueType GetAtomic() const; + + /** + * Get the last published value along with its timestamp. + * If no value has been published, returns the passed defaultValue and a + * timestamp of 0. + * + * @param defaultValue default value to return if no value has been published + * @return timestamped value + */ + TimestampedValueType GetAtomic(ParamType defaultValue) const; + + /** + * Get the last published value along with its timestamp. + * If no value has been published, returns the stored default value and a + * timestamp of 0. + * + * @param buf storage for returned value + * @return timestamped value + */ + TimestampedValueViewType GetAtomic( + wpi::SmallVectorImpl& buf) const; + + /** + * Get the last published value along with its timestamp. + * If no value has been published, returns the passed defaultValue and a + * timestamp of 0. + * + * @param buf storage for returned value + * @param defaultValue default value to return if no value has been published + * @return timestamped value + */ + TimestampedValueViewType GetAtomic( + wpi::SmallVectorImpl& buf, + ParamType defaultValue) const; + + /** + * Get an array of all value changes since the last call to ReadQueue. + * Also provides a timestamp for each value. + * + * @note The "poll storage" subscribe option can be used to set the queue + * depth. + * + * @return Array of timestamped values; empty array if no new changes have + * been published since the previous call. + */ + std::vector ReadQueue(); + + /** + * Get the corresponding topic. + * + * @return Topic + */ + TopicType GetTopic() const; + + private: + ValueType m_defaultValue; +}; + +/** + * NetworkTables Raw publisher. + */ +class RawPublisher : public Publisher { + public: + using TopicType = RawTopic; + using ValueType = std::vector; + using ParamType = std::span; + + using SmallRetType = std::span; + using SmallElemType = uint8_t; + + using TimestampedValueType = TimestampedRaw; + + RawPublisher() = default; + + /** + * Construct from a publisher handle; recommended to use + * RawTopic::Publish() instead. + * + * @param handle Native handle + */ + explicit RawPublisher(NT_Publisher handle); + + /** + * Publish a new value. + * + * @param value value to publish + * @param time timestamp; 0 indicates current NT time should be used + */ + void Set(ParamType value, int64_t time = 0); + + /** + * Publish a default value. + * On reconnect, a default value will never be used in preference to a + * published value. + * + * @param value value + */ + void SetDefault(ParamType value); + + /** + * Get the corresponding topic. + * + * @return Topic + */ + TopicType GetTopic() const; +}; + +/** + * NetworkTables Raw entry. + * + * @note Unlike NetworkTableEntry, the entry goes away when this is destroyed. + */ +class RawEntry final : public RawSubscriber, + public RawPublisher { + public: + using SubscriberType = RawSubscriber; + using PublisherType = RawPublisher; + using TopicType = RawTopic; + using ValueType = std::vector; + using ParamType = std::span; + + using SmallRetType = std::span; + using SmallElemType = uint8_t; + + using TimestampedValueType = TimestampedRaw; + + RawEntry() = default; + + /** + * Construct from an entry handle; recommended to use + * RawTopic::GetEntry() instead. + * + * @param handle Native handle + * @param defaultValue Default value + */ + RawEntry(NT_Entry handle, ParamType defaultValue); + + /** + * Determines if the native handle is valid. + * + * @return True if the native handle is valid, false otherwise. + */ + explicit operator bool() const { return m_subHandle != 0; } + + /** + * Gets the native handle for the entry. + * + * @return Native handle + */ + NT_Entry GetHandle() const { return m_subHandle; } + + /** + * Get the corresponding topic. + * + * @return Topic + */ + TopicType GetTopic() const; + + /** + * Stops publishing the entry if it's published. + */ + void Unpublish(); +}; + +/** + * NetworkTables Raw topic. + */ +class RawTopic final : public Topic { + public: + using SubscriberType = RawSubscriber; + using PublisherType = RawPublisher; + using EntryType = RawEntry; + using ValueType = std::vector; + using ParamType = std::span; + using TimestampedValueType = TimestampedRaw; + + RawTopic() = default; + + /** + * Construct from a topic handle; recommended to use + * NetworkTableInstance::GetRawTopic() instead. + * + * @param handle Native handle + */ + explicit RawTopic(NT_Topic handle) : Topic{handle} {} + + /** + * Construct from a generic topic. + * + * @param topic Topic + */ + explicit RawTopic(Topic topic) : Topic{topic} {} + + /** + * Create a new subscriber to the topic. + * + *

The subscriber is only active as long as the returned object + * is not destroyed. + * + * @note Subscribers that do not match the published data type do not return + * any values. To determine if the data type matches, use the appropriate + * Topic functions. + * + * @param typeString type string + + * @param defaultValue default value used when a default is not provided to a + * getter function + * @param options subscribe options + * @return subscriber + */ + [[nodiscard]] + SubscriberType Subscribe( + std::string_view typeString, ParamType defaultValue, + const PubSubOptions& options = kDefaultPubSubOptions); + /** + * Create a new publisher to the topic. + * + * The publisher is only active as long as the returned object + * is not destroyed. + * + * @note It is not possible to publish two different data types to the same + * topic. Conflicts between publishers are typically resolved by the + * server on a first-come, first-served basis. Any published values that + * do not match the topic's data type are dropped (ignored). To determine + * if the data type matches, use the appropriate Topic functions. + * + * @param typeString type string + + * @param options publish options + * @return publisher + */ + [[nodiscard]] + PublisherType Publish(std::string_view typeString, const PubSubOptions& options = kDefaultPubSubOptions); + + /** + * Create a new publisher to the topic, with type string and initial + * properties. + * + * The publisher is only active as long as the returned object + * is not destroyed. + * + * @note It is not possible to publish two different data types to the same + * topic. Conflicts between publishers are typically resolved by the + * server on a first-come, first-served basis. Any published values that + * do not match the topic's data type are dropped (ignored). To determine + * if the data type matches, use the appropriate Topic functions. + * + * @param typeString type string + * @param properties JSON properties + * @param options publish options + * @return publisher + */ + [[nodiscard]] + PublisherType PublishEx(std::string_view typeString, + const wpi::json& properties, const PubSubOptions& options = kDefaultPubSubOptions); + + /** + * Create a new entry for the topic. + * + * Entries act as a combination of a subscriber and a weak publisher. The + * subscriber is active as long as the entry is not destroyed. The publisher + * is created when the entry is first written to, and remains active until + * either Unpublish() is called or the entry is destroyed. + * + * @note It is not possible to use two different data types with the same + * topic. Conflicts between publishers are typically resolved by the + * server on a first-come, first-served basis. Any published values that + * do not match the topic's data type are dropped (ignored), and the entry + * will show no new values if the data type does not match. To determine + * if the data type matches, use the appropriate Topic functions. + * + * @param typeString type string + + * @param defaultValue default value used when a default is not provided to a + * getter function + * @param options publish and/or subscribe options + * @return entry + */ + [[nodiscard]] + EntryType GetEntry(std::string_view typeString, ParamType defaultValue, + const PubSubOptions& options = kDefaultPubSubOptions); +}; + +} // namespace nt + +#include "networktables/RawTopic.inc" diff --git a/ntcore/src/generated/main/native/include/networktables/RawTopic.inc b/ntcore/src/generated/main/native/include/networktables/RawTopic.inc new file mode 100644 index 0000000000..b31ebcb1f7 --- /dev/null +++ b/ntcore/src/generated/main/native/include/networktables/RawTopic.inc @@ -0,0 +1,121 @@ +// 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. + +// THIS FILE WAS AUTO-GENERATED BY ./ntcore/generate_topics.py. DO NOT MODIFY + +#pragma once + +#include + +#include "networktables/RawTopic.h" +#include "networktables/NetworkTableType.h" +#include "ntcore_cpp.h" + +namespace nt { + +inline RawSubscriber::RawSubscriber( + NT_Subscriber handle, std::span defaultValue) + : Subscriber{handle}, + m_defaultValue{defaultValue.begin(), defaultValue.end()} {} + +inline std::vector RawSubscriber::Get() const { + return Get(m_defaultValue); +} + +inline std::vector RawSubscriber::Get( + std::span defaultValue) const { + return ::nt::GetRaw(m_subHandle, defaultValue); +} + +inline std::span RawSubscriber::Get(wpi::SmallVectorImpl& buf) const { + return Get(buf, m_defaultValue); +} + +inline std::span RawSubscriber::Get(wpi::SmallVectorImpl& buf, std::span defaultValue) const { + return nt::GetRaw(m_subHandle, buf, defaultValue); +} + +inline TimestampedRaw RawSubscriber::GetAtomic() const { + return GetAtomic(m_defaultValue); +} + +inline TimestampedRaw RawSubscriber::GetAtomic( + std::span defaultValue) const { + return ::nt::GetAtomicRaw(m_subHandle, defaultValue); +} + +inline TimestampedRawView RawSubscriber::GetAtomic(wpi::SmallVectorImpl& buf) const { + return GetAtomic(buf, m_defaultValue); +} + +inline TimestampedRawView RawSubscriber::GetAtomic(wpi::SmallVectorImpl& buf, std::span defaultValue) const { + return nt::GetAtomicRaw(m_subHandle, buf, defaultValue); +} + +inline std::vector +RawSubscriber::ReadQueue() { + return ::nt::ReadQueueRaw(m_subHandle); +} + +inline RawTopic RawSubscriber::GetTopic() const { + return RawTopic{::nt::GetTopicFromHandle(m_subHandle)}; +} + +inline RawPublisher::RawPublisher(NT_Publisher handle) + : Publisher{handle} {} + +inline void RawPublisher::Set(std::span value, + int64_t time) { + ::nt::SetRaw(m_pubHandle, value, time); +} + +inline void RawPublisher::SetDefault(std::span value) { + ::nt::SetDefaultRaw(m_pubHandle, value); +} + +inline RawTopic RawPublisher::GetTopic() const { + return RawTopic{::nt::GetTopicFromHandle(m_pubHandle)}; +} + +inline RawEntry::RawEntry( + NT_Entry handle, std::span defaultValue) + : RawSubscriber{handle, defaultValue}, + RawPublisher{handle} {} + +inline RawTopic RawEntry::GetTopic() const { + return RawTopic{::nt::GetTopicFromHandle(m_subHandle)}; +} + +inline void RawEntry::Unpublish() { + ::nt::Unpublish(m_pubHandle); +} + +inline RawSubscriber RawTopic::Subscribe( + std::string_view typeString, std::span defaultValue, + const PubSubOptions& options) { + return RawSubscriber{ + ::nt::Subscribe(m_handle, NT_RAW, typeString, options), + defaultValue}; +} +inline RawPublisher RawTopic::Publish( + std::string_view typeString, const PubSubOptions& options) { + return RawPublisher{ + ::nt::Publish(m_handle, NT_RAW, typeString, options)}; +} + +inline RawPublisher RawTopic::PublishEx( + std::string_view typeString, + const wpi::json& properties, const PubSubOptions& options) { + return RawPublisher{ + ::nt::PublishEx(m_handle, NT_RAW, typeString, properties, options)}; +} + +inline RawEntry RawTopic::GetEntry( + std::string_view typeString, std::span defaultValue, + const PubSubOptions& options) { + return RawEntry{ + ::nt::GetEntry(m_handle, NT_RAW, typeString, options), + defaultValue}; +} +} // namespace nt diff --git a/ntcore/src/generated/main/native/include/networktables/StringArrayTopic.h b/ntcore/src/generated/main/native/include/networktables/StringArrayTopic.h new file mode 100644 index 0000000000..9339521002 --- /dev/null +++ b/ntcore/src/generated/main/native/include/networktables/StringArrayTopic.h @@ -0,0 +1,373 @@ +// 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. + +// THIS FILE WAS AUTO-GENERATED BY ./ntcore/generate_topics.py. DO NOT MODIFY + +#pragma once + +#include + +#include +#include +#include +#include + +#include + +#include "networktables/Topic.h" + +namespace wpi { +template +class SmallVectorImpl; +} // namespace wpi + +namespace nt { + +class StringArrayTopic; + +/** + * NetworkTables StringArray subscriber. + */ +class StringArraySubscriber : public Subscriber { + public: + using TopicType = StringArrayTopic; + using ValueType = std::vector; + using ParamType = std::span; + using TimestampedValueType = TimestampedStringArray; + + + StringArraySubscriber() = default; + + /** + * Construct from a subscriber handle; recommended to use + * StringArrayTopic::Subscribe() instead. + * + * @param handle Native handle + * @param defaultValue Default value + */ + StringArraySubscriber(NT_Subscriber handle, ParamType defaultValue); + + /** + * Get the last published value. + * If no value has been published, returns the stored default value. + * + * @return value + */ + ValueType Get() const; + + /** + * Get the last published value. + * If no value has been published, returns the passed defaultValue. + * + * @param defaultValue default value to return if no value has been published + * @return value + */ + ValueType Get(ParamType defaultValue) const; + + /** + * Get the last published value along with its timestamp + * If no value has been published, returns the stored default value and a + * timestamp of 0. + * + * @return timestamped value + */ + TimestampedValueType GetAtomic() const; + + /** + * Get the last published value along with its timestamp. + * If no value has been published, returns the passed defaultValue and a + * timestamp of 0. + * + * @param defaultValue default value to return if no value has been published + * @return timestamped value + */ + TimestampedValueType GetAtomic(ParamType defaultValue) const; + + /** + * Get an array of all value changes since the last call to ReadQueue. + * Also provides a timestamp for each value. + * + * @note The "poll storage" subscribe option can be used to set the queue + * depth. + * + * @return Array of timestamped values; empty array if no new changes have + * been published since the previous call. + */ + std::vector ReadQueue(); + + /** + * Get the corresponding topic. + * + * @return Topic + */ + TopicType GetTopic() const; + + private: + ValueType m_defaultValue; +}; + +/** + * NetworkTables StringArray publisher. + */ +class StringArrayPublisher : public Publisher { + public: + using TopicType = StringArrayTopic; + using ValueType = std::vector; + using ParamType = std::span; + + using TimestampedValueType = TimestampedStringArray; + + StringArrayPublisher() = default; + + /** + * Construct from a publisher handle; recommended to use + * StringArrayTopic::Publish() instead. + * + * @param handle Native handle + */ + explicit StringArrayPublisher(NT_Publisher handle); + + /** + * Publish a new value. + * + * @param value value to publish + * @param time timestamp; 0 indicates current NT time should be used + */ + void Set(ParamType value, int64_t time = 0); + + /** + * Publish a default value. + * On reconnect, a default value will never be used in preference to a + * published value. + * + * @param value value + */ + void SetDefault(ParamType value); + + /** + * Get the corresponding topic. + * + * @return Topic + */ + TopicType GetTopic() const; +}; + +/** + * NetworkTables StringArray entry. + * + * @note Unlike NetworkTableEntry, the entry goes away when this is destroyed. + */ +class StringArrayEntry final : public StringArraySubscriber, + public StringArrayPublisher { + public: + using SubscriberType = StringArraySubscriber; + using PublisherType = StringArrayPublisher; + using TopicType = StringArrayTopic; + using ValueType = std::vector; + using ParamType = std::span; + + using TimestampedValueType = TimestampedStringArray; + + StringArrayEntry() = default; + + /** + * Construct from an entry handle; recommended to use + * StringArrayTopic::GetEntry() instead. + * + * @param handle Native handle + * @param defaultValue Default value + */ + StringArrayEntry(NT_Entry handle, ParamType defaultValue); + + /** + * Determines if the native handle is valid. + * + * @return True if the native handle is valid, false otherwise. + */ + explicit operator bool() const { return m_subHandle != 0; } + + /** + * Gets the native handle for the entry. + * + * @return Native handle + */ + NT_Entry GetHandle() const { return m_subHandle; } + + /** + * Get the corresponding topic. + * + * @return Topic + */ + TopicType GetTopic() const; + + /** + * Stops publishing the entry if it's published. + */ + void Unpublish(); +}; + +/** + * NetworkTables StringArray topic. + */ +class StringArrayTopic final : public Topic { + public: + using SubscriberType = StringArraySubscriber; + using PublisherType = StringArrayPublisher; + using EntryType = StringArrayEntry; + using ValueType = std::vector; + using ParamType = std::span; + using TimestampedValueType = TimestampedStringArray; + /** The default type string for this topic type. */ + static constexpr std::string_view kTypeString = "string[]"; + + StringArrayTopic() = default; + + /** + * Construct from a topic handle; recommended to use + * NetworkTableInstance::GetStringArrayTopic() instead. + * + * @param handle Native handle + */ + explicit StringArrayTopic(NT_Topic handle) : Topic{handle} {} + + /** + * Construct from a generic topic. + * + * @param topic Topic + */ + explicit StringArrayTopic(Topic topic) : Topic{topic} {} + + /** + * Create a new subscriber to the topic. + * + *

The subscriber is only active as long as the returned object + * is not destroyed. + * + * @note Subscribers that do not match the published data type do not return + * any values. To determine if the data type matches, use the appropriate + * Topic functions. + * + * @param defaultValue default value used when a default is not provided to a + * getter function + * @param options subscribe options + * @return subscriber + */ + [[nodiscard]] + SubscriberType Subscribe( + ParamType defaultValue, + const PubSubOptions& options = kDefaultPubSubOptions); + /** + * Create a new subscriber to the topic, with specific type string. + * + *

The subscriber is only active as long as the returned object + * is not destroyed. + * + * @note Subscribers that do not match the published data type do not return + * any values. To determine if the data type matches, use the appropriate + * Topic functions. + * + * @param typeString type string + * @param defaultValue default value used when a default is not provided to a + * getter function + * @param options subscribe options + * @return subscriber + */ + [[nodiscard]] + SubscriberType SubscribeEx( + std::string_view typeString, ParamType defaultValue, + const PubSubOptions& options = kDefaultPubSubOptions); + + /** + * Create a new publisher to the topic. + * + * The publisher is only active as long as the returned object + * is not destroyed. + * + * @note It is not possible to publish two different data types to the same + * topic. Conflicts between publishers are typically resolved by the + * server on a first-come, first-served basis. Any published values that + * do not match the topic's data type are dropped (ignored). To determine + * if the data type matches, use the appropriate Topic functions. + * + * @param options publish options + * @return publisher + */ + [[nodiscard]] + PublisherType Publish(const PubSubOptions& options = kDefaultPubSubOptions); + + /** + * Create a new publisher to the topic, with type string and initial + * properties. + * + * The publisher is only active as long as the returned object + * is not destroyed. + * + * @note It is not possible to publish two different data types to the same + * topic. Conflicts between publishers are typically resolved by the + * server on a first-come, first-served basis. Any published values that + * do not match the topic's data type are dropped (ignored). To determine + * if the data type matches, use the appropriate Topic functions. + * + * @param typeString type string + * @param properties JSON properties + * @param options publish options + * @return publisher + */ + [[nodiscard]] + PublisherType PublishEx(std::string_view typeString, + const wpi::json& properties, const PubSubOptions& options = kDefaultPubSubOptions); + + /** + * Create a new entry for the topic. + * + * Entries act as a combination of a subscriber and a weak publisher. The + * subscriber is active as long as the entry is not destroyed. The publisher + * is created when the entry is first written to, and remains active until + * either Unpublish() is called or the entry is destroyed. + * + * @note It is not possible to use two different data types with the same + * topic. Conflicts between publishers are typically resolved by the + * server on a first-come, first-served basis. Any published values that + * do not match the topic's data type are dropped (ignored), and the entry + * will show no new values if the data type does not match. To determine + * if the data type matches, use the appropriate Topic functions. + * + * @param defaultValue default value used when a default is not provided to a + * getter function + * @param options publish and/or subscribe options + * @return entry + */ + [[nodiscard]] + EntryType GetEntry(ParamType defaultValue, + const PubSubOptions& options = kDefaultPubSubOptions); + /** + * Create a new entry for the topic, with specific type string. + * + * Entries act as a combination of a subscriber and a weak publisher. The + * subscriber is active as long as the entry is not destroyed. The publisher + * is created when the entry is first written to, and remains active until + * either Unpublish() is called or the entry is destroyed. + * + * @note It is not possible to use two different data types with the same + * topic. Conflicts between publishers are typically resolved by the + * server on a first-come, first-served basis. Any published values that + * do not match the topic's data type are dropped (ignored), and the entry + * will show no new values if the data type does not match. To determine + * if the data type matches, use the appropriate Topic functions. + * + * @param typeString type string + * @param defaultValue default value used when a default is not provided to a + * getter function + * @param options publish and/or subscribe options + * @return entry + */ + [[nodiscard]] + EntryType GetEntryEx(std::string_view typeString, ParamType defaultValue, + const PubSubOptions& options = kDefaultPubSubOptions); + +}; + +} // namespace nt + +#include "networktables/StringArrayTopic.inc" diff --git a/ntcore/src/generated/main/native/include/networktables/StringArrayTopic.inc b/ntcore/src/generated/main/native/include/networktables/StringArrayTopic.inc new file mode 100644 index 0000000000..f003ff00c5 --- /dev/null +++ b/ntcore/src/generated/main/native/include/networktables/StringArrayTopic.inc @@ -0,0 +1,121 @@ +// 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. + +// THIS FILE WAS AUTO-GENERATED BY ./ntcore/generate_topics.py. DO NOT MODIFY + +#pragma once + +#include + +#include "networktables/StringArrayTopic.h" +#include "networktables/NetworkTableType.h" +#include "ntcore_cpp.h" + +namespace nt { + +inline StringArraySubscriber::StringArraySubscriber( + NT_Subscriber handle, std::span defaultValue) + : Subscriber{handle}, + m_defaultValue{defaultValue.begin(), defaultValue.end()} {} + +inline std::vector StringArraySubscriber::Get() const { + return Get(m_defaultValue); +} + +inline std::vector StringArraySubscriber::Get( + std::span defaultValue) const { + return ::nt::GetStringArray(m_subHandle, defaultValue); +} + +inline TimestampedStringArray StringArraySubscriber::GetAtomic() const { + return GetAtomic(m_defaultValue); +} + +inline TimestampedStringArray StringArraySubscriber::GetAtomic( + std::span defaultValue) const { + return ::nt::GetAtomicStringArray(m_subHandle, defaultValue); +} + +inline std::vector +StringArraySubscriber::ReadQueue() { + return ::nt::ReadQueueStringArray(m_subHandle); +} + +inline StringArrayTopic StringArraySubscriber::GetTopic() const { + return StringArrayTopic{::nt::GetTopicFromHandle(m_subHandle)}; +} + +inline StringArrayPublisher::StringArrayPublisher(NT_Publisher handle) + : Publisher{handle} {} + +inline void StringArrayPublisher::Set(std::span value, + int64_t time) { + ::nt::SetStringArray(m_pubHandle, value, time); +} + +inline void StringArrayPublisher::SetDefault(std::span value) { + ::nt::SetDefaultStringArray(m_pubHandle, value); +} + +inline StringArrayTopic StringArrayPublisher::GetTopic() const { + return StringArrayTopic{::nt::GetTopicFromHandle(m_pubHandle)}; +} + +inline StringArrayEntry::StringArrayEntry( + NT_Entry handle, std::span defaultValue) + : StringArraySubscriber{handle, defaultValue}, + StringArrayPublisher{handle} {} + +inline StringArrayTopic StringArrayEntry::GetTopic() const { + return StringArrayTopic{::nt::GetTopicFromHandle(m_subHandle)}; +} + +inline void StringArrayEntry::Unpublish() { + ::nt::Unpublish(m_pubHandle); +} + +inline StringArraySubscriber StringArrayTopic::Subscribe( + std::span defaultValue, + const PubSubOptions& options) { + return StringArraySubscriber{ + ::nt::Subscribe(m_handle, NT_STRING_ARRAY, "string[]", options), + defaultValue}; +} +inline StringArraySubscriber StringArrayTopic::SubscribeEx( + std::string_view typeString, std::span defaultValue, + const PubSubOptions& options) { + return StringArraySubscriber{ + ::nt::Subscribe(m_handle, NT_STRING_ARRAY, typeString, options), + defaultValue}; +} + +inline StringArrayPublisher StringArrayTopic::Publish( + const PubSubOptions& options) { + return StringArrayPublisher{ + ::nt::Publish(m_handle, NT_STRING_ARRAY, "string[]", options)}; +} + +inline StringArrayPublisher StringArrayTopic::PublishEx( + std::string_view typeString, + const wpi::json& properties, const PubSubOptions& options) { + return StringArrayPublisher{ + ::nt::PublishEx(m_handle, NT_STRING_ARRAY, typeString, properties, options)}; +} + +inline StringArrayEntry StringArrayTopic::GetEntry( + std::span defaultValue, + const PubSubOptions& options) { + return StringArrayEntry{ + ::nt::GetEntry(m_handle, NT_STRING_ARRAY, "string[]", options), + defaultValue}; +} +inline StringArrayEntry StringArrayTopic::GetEntryEx( + std::string_view typeString, std::span defaultValue, + const PubSubOptions& options) { + return StringArrayEntry{ + ::nt::GetEntry(m_handle, NT_STRING_ARRAY, typeString, options), + defaultValue}; +} + +} // namespace nt diff --git a/ntcore/src/generated/main/native/include/networktables/StringTopic.h b/ntcore/src/generated/main/native/include/networktables/StringTopic.h new file mode 100644 index 0000000000..3e0ff87545 --- /dev/null +++ b/ntcore/src/generated/main/native/include/networktables/StringTopic.h @@ -0,0 +1,428 @@ +// 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. + +// THIS FILE WAS AUTO-GENERATED BY ./ntcore/generate_topics.py. DO NOT MODIFY + +#pragma once + +#include + +#include +#include +#include +#include +#include +#include + +#include + +#include "networktables/Topic.h" + +namespace wpi { +template +class SmallVectorImpl; +} // namespace wpi + +namespace nt { + +class StringTopic; + +/** + * NetworkTables String subscriber. + */ +class StringSubscriber : public Subscriber { + public: + using TopicType = StringTopic; + using ValueType = std::string; + using ParamType = std::string_view; + using TimestampedValueType = TimestampedString; + + using SmallRetType = std::string_view; + using SmallElemType = char; + using TimestampedValueViewType = TimestampedStringView; + + + StringSubscriber() = default; + + /** + * Construct from a subscriber handle; recommended to use + * StringTopic::Subscribe() instead. + * + * @param handle Native handle + * @param defaultValue Default value + */ + StringSubscriber(NT_Subscriber handle, ParamType defaultValue); + + /** + * Get the last published value. + * If no value has been published, returns the stored default value. + * + * @return value + */ + ValueType Get() const; + + /** + * Get the last published value. + * If no value has been published, returns the passed defaultValue. + * + * @param defaultValue default value to return if no value has been published + * @return value + */ + ValueType Get(ParamType defaultValue) const; + + /** + * Get the last published value. + * If no value has been published, returns the stored default value. + * + * @param buf storage for returned value + * @return value + */ + SmallRetType Get(wpi::SmallVectorImpl& buf) const; + + /** + * Get the last published value. + * If no value has been published, returns the passed defaultValue. + * + * @param buf storage for returned value + * @param defaultValue default value to return if no value has been published + * @return value + */ + SmallRetType Get(wpi::SmallVectorImpl& buf, ParamType defaultValue) const; + + /** + * Get the last published value along with its timestamp + * If no value has been published, returns the stored default value and a + * timestamp of 0. + * + * @return timestamped value + */ + TimestampedValueType GetAtomic() const; + + /** + * Get the last published value along with its timestamp. + * If no value has been published, returns the passed defaultValue and a + * timestamp of 0. + * + * @param defaultValue default value to return if no value has been published + * @return timestamped value + */ + TimestampedValueType GetAtomic(ParamType defaultValue) const; + + /** + * Get the last published value along with its timestamp. + * If no value has been published, returns the stored default value and a + * timestamp of 0. + * + * @param buf storage for returned value + * @return timestamped value + */ + TimestampedValueViewType GetAtomic( + wpi::SmallVectorImpl& buf) const; + + /** + * Get the last published value along with its timestamp. + * If no value has been published, returns the passed defaultValue and a + * timestamp of 0. + * + * @param buf storage for returned value + * @param defaultValue default value to return if no value has been published + * @return timestamped value + */ + TimestampedValueViewType GetAtomic( + wpi::SmallVectorImpl& buf, + ParamType defaultValue) const; + + /** + * Get an array of all value changes since the last call to ReadQueue. + * Also provides a timestamp for each value. + * + * @note The "poll storage" subscribe option can be used to set the queue + * depth. + * + * @return Array of timestamped values; empty array if no new changes have + * been published since the previous call. + */ + std::vector ReadQueue(); + + /** + * Get the corresponding topic. + * + * @return Topic + */ + TopicType GetTopic() const; + + private: + ValueType m_defaultValue; +}; + +/** + * NetworkTables String publisher. + */ +class StringPublisher : public Publisher { + public: + using TopicType = StringTopic; + using ValueType = std::string; + using ParamType = std::string_view; + + using SmallRetType = std::string_view; + using SmallElemType = char; + + using TimestampedValueType = TimestampedString; + + StringPublisher() = default; + + /** + * Construct from a publisher handle; recommended to use + * StringTopic::Publish() instead. + * + * @param handle Native handle + */ + explicit StringPublisher(NT_Publisher handle); + + /** + * Publish a new value. + * + * @param value value to publish + * @param time timestamp; 0 indicates current NT time should be used + */ + void Set(ParamType value, int64_t time = 0); + + /** + * Publish a default value. + * On reconnect, a default value will never be used in preference to a + * published value. + * + * @param value value + */ + void SetDefault(ParamType value); + + /** + * Get the corresponding topic. + * + * @return Topic + */ + TopicType GetTopic() const; +}; + +/** + * NetworkTables String entry. + * + * @note Unlike NetworkTableEntry, the entry goes away when this is destroyed. + */ +class StringEntry final : public StringSubscriber, + public StringPublisher { + public: + using SubscriberType = StringSubscriber; + using PublisherType = StringPublisher; + using TopicType = StringTopic; + using ValueType = std::string; + using ParamType = std::string_view; + + using SmallRetType = std::string_view; + using SmallElemType = char; + + using TimestampedValueType = TimestampedString; + + StringEntry() = default; + + /** + * Construct from an entry handle; recommended to use + * StringTopic::GetEntry() instead. + * + * @param handle Native handle + * @param defaultValue Default value + */ + StringEntry(NT_Entry handle, ParamType defaultValue); + + /** + * Determines if the native handle is valid. + * + * @return True if the native handle is valid, false otherwise. + */ + explicit operator bool() const { return m_subHandle != 0; } + + /** + * Gets the native handle for the entry. + * + * @return Native handle + */ + NT_Entry GetHandle() const { return m_subHandle; } + + /** + * Get the corresponding topic. + * + * @return Topic + */ + TopicType GetTopic() const; + + /** + * Stops publishing the entry if it's published. + */ + void Unpublish(); +}; + +/** + * NetworkTables String topic. + */ +class StringTopic final : public Topic { + public: + using SubscriberType = StringSubscriber; + using PublisherType = StringPublisher; + using EntryType = StringEntry; + using ValueType = std::string; + using ParamType = std::string_view; + using TimestampedValueType = TimestampedString; + /** The default type string for this topic type. */ + static constexpr std::string_view kTypeString = "string"; + + StringTopic() = default; + + /** + * Construct from a topic handle; recommended to use + * NetworkTableInstance::GetStringTopic() instead. + * + * @param handle Native handle + */ + explicit StringTopic(NT_Topic handle) : Topic{handle} {} + + /** + * Construct from a generic topic. + * + * @param topic Topic + */ + explicit StringTopic(Topic topic) : Topic{topic} {} + + /** + * Create a new subscriber to the topic. + * + *

The subscriber is only active as long as the returned object + * is not destroyed. + * + * @note Subscribers that do not match the published data type do not return + * any values. To determine if the data type matches, use the appropriate + * Topic functions. + * + * @param defaultValue default value used when a default is not provided to a + * getter function + * @param options subscribe options + * @return subscriber + */ + [[nodiscard]] + SubscriberType Subscribe( + ParamType defaultValue, + const PubSubOptions& options = kDefaultPubSubOptions); + /** + * Create a new subscriber to the topic, with specific type string. + * + *

The subscriber is only active as long as the returned object + * is not destroyed. + * + * @note Subscribers that do not match the published data type do not return + * any values. To determine if the data type matches, use the appropriate + * Topic functions. + * + * @param typeString type string + * @param defaultValue default value used when a default is not provided to a + * getter function + * @param options subscribe options + * @return subscriber + */ + [[nodiscard]] + SubscriberType SubscribeEx( + std::string_view typeString, ParamType defaultValue, + const PubSubOptions& options = kDefaultPubSubOptions); + + /** + * Create a new publisher to the topic. + * + * The publisher is only active as long as the returned object + * is not destroyed. + * + * @note It is not possible to publish two different data types to the same + * topic. Conflicts between publishers are typically resolved by the + * server on a first-come, first-served basis. Any published values that + * do not match the topic's data type are dropped (ignored). To determine + * if the data type matches, use the appropriate Topic functions. + * + * @param options publish options + * @return publisher + */ + [[nodiscard]] + PublisherType Publish(const PubSubOptions& options = kDefaultPubSubOptions); + + /** + * Create a new publisher to the topic, with type string and initial + * properties. + * + * The publisher is only active as long as the returned object + * is not destroyed. + * + * @note It is not possible to publish two different data types to the same + * topic. Conflicts between publishers are typically resolved by the + * server on a first-come, first-served basis. Any published values that + * do not match the topic's data type are dropped (ignored). To determine + * if the data type matches, use the appropriate Topic functions. + * + * @param typeString type string + * @param properties JSON properties + * @param options publish options + * @return publisher + */ + [[nodiscard]] + PublisherType PublishEx(std::string_view typeString, + const wpi::json& properties, const PubSubOptions& options = kDefaultPubSubOptions); + + /** + * Create a new entry for the topic. + * + * Entries act as a combination of a subscriber and a weak publisher. The + * subscriber is active as long as the entry is not destroyed. The publisher + * is created when the entry is first written to, and remains active until + * either Unpublish() is called or the entry is destroyed. + * + * @note It is not possible to use two different data types with the same + * topic. Conflicts between publishers are typically resolved by the + * server on a first-come, first-served basis. Any published values that + * do not match the topic's data type are dropped (ignored), and the entry + * will show no new values if the data type does not match. To determine + * if the data type matches, use the appropriate Topic functions. + * + * @param defaultValue default value used when a default is not provided to a + * getter function + * @param options publish and/or subscribe options + * @return entry + */ + [[nodiscard]] + EntryType GetEntry(ParamType defaultValue, + const PubSubOptions& options = kDefaultPubSubOptions); + /** + * Create a new entry for the topic, with specific type string. + * + * Entries act as a combination of a subscriber and a weak publisher. The + * subscriber is active as long as the entry is not destroyed. The publisher + * is created when the entry is first written to, and remains active until + * either Unpublish() is called or the entry is destroyed. + * + * @note It is not possible to use two different data types with the same + * topic. Conflicts between publishers are typically resolved by the + * server on a first-come, first-served basis. Any published values that + * do not match the topic's data type are dropped (ignored), and the entry + * will show no new values if the data type does not match. To determine + * if the data type matches, use the appropriate Topic functions. + * + * @param typeString type string + * @param defaultValue default value used when a default is not provided to a + * getter function + * @param options publish and/or subscribe options + * @return entry + */ + [[nodiscard]] + EntryType GetEntryEx(std::string_view typeString, ParamType defaultValue, + const PubSubOptions& options = kDefaultPubSubOptions); + +}; + +} // namespace nt + +#include "networktables/StringTopic.inc" diff --git a/ntcore/src/generated/main/native/include/networktables/StringTopic.inc b/ntcore/src/generated/main/native/include/networktables/StringTopic.inc new file mode 100644 index 0000000000..a1934e4cfd --- /dev/null +++ b/ntcore/src/generated/main/native/include/networktables/StringTopic.inc @@ -0,0 +1,137 @@ +// 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. + +// THIS FILE WAS AUTO-GENERATED BY ./ntcore/generate_topics.py. DO NOT MODIFY + +#pragma once + +#include + +#include "networktables/StringTopic.h" +#include "networktables/NetworkTableType.h" +#include "ntcore_cpp.h" + +namespace nt { + +inline StringSubscriber::StringSubscriber( + NT_Subscriber handle, std::string_view defaultValue) + : Subscriber{handle}, + m_defaultValue{defaultValue} {} + +inline std::string StringSubscriber::Get() const { + return Get(m_defaultValue); +} + +inline std::string StringSubscriber::Get( + std::string_view defaultValue) const { + return ::nt::GetString(m_subHandle, defaultValue); +} + +inline std::string_view StringSubscriber::Get(wpi::SmallVectorImpl& buf) const { + return Get(buf, m_defaultValue); +} + +inline std::string_view StringSubscriber::Get(wpi::SmallVectorImpl& buf, std::string_view defaultValue) const { + return nt::GetString(m_subHandle, buf, defaultValue); +} + +inline TimestampedString StringSubscriber::GetAtomic() const { + return GetAtomic(m_defaultValue); +} + +inline TimestampedString StringSubscriber::GetAtomic( + std::string_view defaultValue) const { + return ::nt::GetAtomicString(m_subHandle, defaultValue); +} + +inline TimestampedStringView StringSubscriber::GetAtomic(wpi::SmallVectorImpl& buf) const { + return GetAtomic(buf, m_defaultValue); +} + +inline TimestampedStringView StringSubscriber::GetAtomic(wpi::SmallVectorImpl& buf, std::string_view defaultValue) const { + return nt::GetAtomicString(m_subHandle, buf, defaultValue); +} + +inline std::vector +StringSubscriber::ReadQueue() { + return ::nt::ReadQueueString(m_subHandle); +} + +inline StringTopic StringSubscriber::GetTopic() const { + return StringTopic{::nt::GetTopicFromHandle(m_subHandle)}; +} + +inline StringPublisher::StringPublisher(NT_Publisher handle) + : Publisher{handle} {} + +inline void StringPublisher::Set(std::string_view value, + int64_t time) { + ::nt::SetString(m_pubHandle, value, time); +} + +inline void StringPublisher::SetDefault(std::string_view value) { + ::nt::SetDefaultString(m_pubHandle, value); +} + +inline StringTopic StringPublisher::GetTopic() const { + return StringTopic{::nt::GetTopicFromHandle(m_pubHandle)}; +} + +inline StringEntry::StringEntry( + NT_Entry handle, std::string_view defaultValue) + : StringSubscriber{handle, defaultValue}, + StringPublisher{handle} {} + +inline StringTopic StringEntry::GetTopic() const { + return StringTopic{::nt::GetTopicFromHandle(m_subHandle)}; +} + +inline void StringEntry::Unpublish() { + ::nt::Unpublish(m_pubHandle); +} + +inline StringSubscriber StringTopic::Subscribe( + std::string_view defaultValue, + const PubSubOptions& options) { + return StringSubscriber{ + ::nt::Subscribe(m_handle, NT_STRING, "string", options), + defaultValue}; +} +inline StringSubscriber StringTopic::SubscribeEx( + std::string_view typeString, std::string_view defaultValue, + const PubSubOptions& options) { + return StringSubscriber{ + ::nt::Subscribe(m_handle, NT_STRING, typeString, options), + defaultValue}; +} + +inline StringPublisher StringTopic::Publish( + const PubSubOptions& options) { + return StringPublisher{ + ::nt::Publish(m_handle, NT_STRING, "string", options)}; +} + +inline StringPublisher StringTopic::PublishEx( + std::string_view typeString, + const wpi::json& properties, const PubSubOptions& options) { + return StringPublisher{ + ::nt::PublishEx(m_handle, NT_STRING, typeString, properties, options)}; +} + +inline StringEntry StringTopic::GetEntry( + std::string_view defaultValue, + const PubSubOptions& options) { + return StringEntry{ + ::nt::GetEntry(m_handle, NT_STRING, "string", options), + defaultValue}; +} +inline StringEntry StringTopic::GetEntryEx( + std::string_view typeString, std::string_view defaultValue, + const PubSubOptions& options) { + return StringEntry{ + ::nt::GetEntry(m_handle, NT_STRING, typeString, options), + defaultValue}; +} + +} // namespace nt diff --git a/ntcore/src/generated/main/native/include/ntcore_c_types.h b/ntcore/src/generated/main/native/include/ntcore_c_types.h new file mode 100644 index 0000000000..3b95a09b6f --- /dev/null +++ b/ntcore/src/generated/main/native/include/ntcore_c_types.h @@ -0,0 +1,1245 @@ +// 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. + +// THIS FILE WAS AUTO-GENERATED BY ./ntcore/generate_topics.py. DO NOT MODIFY + +#pragma once + +#include + +#include "ntcore_c.h" + +#ifdef __cplusplus +extern "C" { +#endif + + +/** + * Timestamped Boolean. + * @ingroup ntcore_c_api + */ +struct NT_TimestampedBoolean { + /** + * Time in local time base. + */ + int64_t time; + + /** + * Time in server time base. May be 0 or 1 for locally set values. + */ + int64_t serverTime; + + /** + * Value. + */ + NT_Bool value; +}; + +/** + * @defgroup ntcore_Boolean_cfunc Boolean Functions + * @ingroup ntcore_c_api + * @{ + */ + +/** + * Publish a new value. + * + * @param pubentry publisher or entry handle + * @param time timestamp; 0 indicates current NT time should be used + * @param value value to publish + */ +NT_Bool NT_SetBoolean(NT_Handle pubentry, int64_t time, NT_Bool value); + +/** + * Publish a default value. + * On reconnect, a default value will never be used in preference to a + * published value. + * + * @param pubentry publisher or entry handle + * @param defaultValue default value + */ +NT_Bool NT_SetDefaultBoolean(NT_Handle pubentry, NT_Bool defaultValue); + +/** + * Get the last published value. + * If no value has been published, returns the passed defaultValue. + * + * @param subentry subscriber or entry handle + * @param defaultValue default value to return if no value has been published + * @return value + */ +NT_Bool NT_GetBoolean(NT_Handle subentry, NT_Bool defaultValue); + +/** + * Get the last published value along with its timestamp. + * If no value has been published, returns the passed defaultValue and a + * timestamp of 0. + * + * @param subentry subscriber or entry handle + * @param defaultValue default value to return if no value has been published + * @param value timestamped value (output) + */ +void NT_GetAtomicBoolean(NT_Handle subentry, NT_Bool defaultValue, struct NT_TimestampedBoolean* value); + +/** + * Disposes a timestamped value (as returned by NT_GetAtomicBoolean). + * + * @param value timestamped value + */ +void NT_DisposeTimestampedBoolean(struct NT_TimestampedBoolean* value); + +/** + * Get an array of all value changes since the last call to ReadQueue. + * Also provides a timestamp for each value. + * + * @note The "poll storage" subscribe option can be used to set the queue + * depth. + * + * @param subentry subscriber or entry handle + * @param len length of returned array (output) + * @return Array of timestamped values; NULL if no new changes have + * been published since the previous call. + */ +struct NT_TimestampedBoolean* NT_ReadQueueBoolean(NT_Handle subentry, size_t* len); + +/** + * Frees a timestamped array of values (as returned by NT_ReadQueueBoolean). + * + * @param arr array + * @param len length of array + */ +void NT_FreeQueueBoolean(struct NT_TimestampedBoolean* arr, size_t len); +/** + * Get an array of all value changes since the last call to ReadQueue. + * + * @note The "poll storage" subscribe option can be used to set the queue + * depth. + * + * @param subentry subscriber or entry handle + * @param len length of returned array (output) + * @return Array of values; NULL if no new changes have + * been published since the previous call. + */ +NT_Bool* NT_ReadQueueValuesBoolean(NT_Handle subentry, size_t* len); + +/** @} */ + +/** + * Timestamped Integer. + * @ingroup ntcore_c_api + */ +struct NT_TimestampedInteger { + /** + * Time in local time base. + */ + int64_t time; + + /** + * Time in server time base. May be 0 or 1 for locally set values. + */ + int64_t serverTime; + + /** + * Value. + */ + int64_t value; +}; + +/** + * @defgroup ntcore_Integer_cfunc Integer Functions + * @ingroup ntcore_c_api + * @{ + */ + +/** + * Publish a new value. + * + * @param pubentry publisher or entry handle + * @param time timestamp; 0 indicates current NT time should be used + * @param value value to publish + */ +NT_Bool NT_SetInteger(NT_Handle pubentry, int64_t time, int64_t value); + +/** + * Publish a default value. + * On reconnect, a default value will never be used in preference to a + * published value. + * + * @param pubentry publisher or entry handle + * @param defaultValue default value + */ +NT_Bool NT_SetDefaultInteger(NT_Handle pubentry, int64_t defaultValue); + +/** + * Get the last published value. + * If no value has been published, returns the passed defaultValue. + * + * @param subentry subscriber or entry handle + * @param defaultValue default value to return if no value has been published + * @return value + */ +int64_t NT_GetInteger(NT_Handle subentry, int64_t defaultValue); + +/** + * Get the last published value along with its timestamp. + * If no value has been published, returns the passed defaultValue and a + * timestamp of 0. + * + * @param subentry subscriber or entry handle + * @param defaultValue default value to return if no value has been published + * @param value timestamped value (output) + */ +void NT_GetAtomicInteger(NT_Handle subentry, int64_t defaultValue, struct NT_TimestampedInteger* value); + +/** + * Disposes a timestamped value (as returned by NT_GetAtomicInteger). + * + * @param value timestamped value + */ +void NT_DisposeTimestampedInteger(struct NT_TimestampedInteger* value); + +/** + * Get an array of all value changes since the last call to ReadQueue. + * Also provides a timestamp for each value. + * + * @note The "poll storage" subscribe option can be used to set the queue + * depth. + * + * @param subentry subscriber or entry handle + * @param len length of returned array (output) + * @return Array of timestamped values; NULL if no new changes have + * been published since the previous call. + */ +struct NT_TimestampedInteger* NT_ReadQueueInteger(NT_Handle subentry, size_t* len); + +/** + * Frees a timestamped array of values (as returned by NT_ReadQueueInteger). + * + * @param arr array + * @param len length of array + */ +void NT_FreeQueueInteger(struct NT_TimestampedInteger* arr, size_t len); +/** + * Get an array of all value changes since the last call to ReadQueue. + * + * @note The "poll storage" subscribe option can be used to set the queue + * depth. + * + * @param subentry subscriber or entry handle + * @param len length of returned array (output) + * @return Array of values; NULL if no new changes have + * been published since the previous call. + */ +int64_t* NT_ReadQueueValuesInteger(NT_Handle subentry, size_t* len); + +/** @} */ + +/** + * Timestamped Float. + * @ingroup ntcore_c_api + */ +struct NT_TimestampedFloat { + /** + * Time in local time base. + */ + int64_t time; + + /** + * Time in server time base. May be 0 or 1 for locally set values. + */ + int64_t serverTime; + + /** + * Value. + */ + float value; +}; + +/** + * @defgroup ntcore_Float_cfunc Float Functions + * @ingroup ntcore_c_api + * @{ + */ + +/** + * Publish a new value. + * + * @param pubentry publisher or entry handle + * @param time timestamp; 0 indicates current NT time should be used + * @param value value to publish + */ +NT_Bool NT_SetFloat(NT_Handle pubentry, int64_t time, float value); + +/** + * Publish a default value. + * On reconnect, a default value will never be used in preference to a + * published value. + * + * @param pubentry publisher or entry handle + * @param defaultValue default value + */ +NT_Bool NT_SetDefaultFloat(NT_Handle pubentry, float defaultValue); + +/** + * Get the last published value. + * If no value has been published, returns the passed defaultValue. + * + * @param subentry subscriber or entry handle + * @param defaultValue default value to return if no value has been published + * @return value + */ +float NT_GetFloat(NT_Handle subentry, float defaultValue); + +/** + * Get the last published value along with its timestamp. + * If no value has been published, returns the passed defaultValue and a + * timestamp of 0. + * + * @param subentry subscriber or entry handle + * @param defaultValue default value to return if no value has been published + * @param value timestamped value (output) + */ +void NT_GetAtomicFloat(NT_Handle subentry, float defaultValue, struct NT_TimestampedFloat* value); + +/** + * Disposes a timestamped value (as returned by NT_GetAtomicFloat). + * + * @param value timestamped value + */ +void NT_DisposeTimestampedFloat(struct NT_TimestampedFloat* value); + +/** + * Get an array of all value changes since the last call to ReadQueue. + * Also provides a timestamp for each value. + * + * @note The "poll storage" subscribe option can be used to set the queue + * depth. + * + * @param subentry subscriber or entry handle + * @param len length of returned array (output) + * @return Array of timestamped values; NULL if no new changes have + * been published since the previous call. + */ +struct NT_TimestampedFloat* NT_ReadQueueFloat(NT_Handle subentry, size_t* len); + +/** + * Frees a timestamped array of values (as returned by NT_ReadQueueFloat). + * + * @param arr array + * @param len length of array + */ +void NT_FreeQueueFloat(struct NT_TimestampedFloat* arr, size_t len); +/** + * Get an array of all value changes since the last call to ReadQueue. + * + * @note The "poll storage" subscribe option can be used to set the queue + * depth. + * + * @param subentry subscriber or entry handle + * @param len length of returned array (output) + * @return Array of values; NULL if no new changes have + * been published since the previous call. + */ +float* NT_ReadQueueValuesFloat(NT_Handle subentry, size_t* len); + +/** @} */ + +/** + * Timestamped Double. + * @ingroup ntcore_c_api + */ +struct NT_TimestampedDouble { + /** + * Time in local time base. + */ + int64_t time; + + /** + * Time in server time base. May be 0 or 1 for locally set values. + */ + int64_t serverTime; + + /** + * Value. + */ + double value; +}; + +/** + * @defgroup ntcore_Double_cfunc Double Functions + * @ingroup ntcore_c_api + * @{ + */ + +/** + * Publish a new value. + * + * @param pubentry publisher or entry handle + * @param time timestamp; 0 indicates current NT time should be used + * @param value value to publish + */ +NT_Bool NT_SetDouble(NT_Handle pubentry, int64_t time, double value); + +/** + * Publish a default value. + * On reconnect, a default value will never be used in preference to a + * published value. + * + * @param pubentry publisher or entry handle + * @param defaultValue default value + */ +NT_Bool NT_SetDefaultDouble(NT_Handle pubentry, double defaultValue); + +/** + * Get the last published value. + * If no value has been published, returns the passed defaultValue. + * + * @param subentry subscriber or entry handle + * @param defaultValue default value to return if no value has been published + * @return value + */ +double NT_GetDouble(NT_Handle subentry, double defaultValue); + +/** + * Get the last published value along with its timestamp. + * If no value has been published, returns the passed defaultValue and a + * timestamp of 0. + * + * @param subentry subscriber or entry handle + * @param defaultValue default value to return if no value has been published + * @param value timestamped value (output) + */ +void NT_GetAtomicDouble(NT_Handle subentry, double defaultValue, struct NT_TimestampedDouble* value); + +/** + * Disposes a timestamped value (as returned by NT_GetAtomicDouble). + * + * @param value timestamped value + */ +void NT_DisposeTimestampedDouble(struct NT_TimestampedDouble* value); + +/** + * Get an array of all value changes since the last call to ReadQueue. + * Also provides a timestamp for each value. + * + * @note The "poll storage" subscribe option can be used to set the queue + * depth. + * + * @param subentry subscriber or entry handle + * @param len length of returned array (output) + * @return Array of timestamped values; NULL if no new changes have + * been published since the previous call. + */ +struct NT_TimestampedDouble* NT_ReadQueueDouble(NT_Handle subentry, size_t* len); + +/** + * Frees a timestamped array of values (as returned by NT_ReadQueueDouble). + * + * @param arr array + * @param len length of array + */ +void NT_FreeQueueDouble(struct NT_TimestampedDouble* arr, size_t len); +/** + * Get an array of all value changes since the last call to ReadQueue. + * + * @note The "poll storage" subscribe option can be used to set the queue + * depth. + * + * @param subentry subscriber or entry handle + * @param len length of returned array (output) + * @return Array of values; NULL if no new changes have + * been published since the previous call. + */ +double* NT_ReadQueueValuesDouble(NT_Handle subentry, size_t* len); + +/** @} */ + +/** + * Timestamped String. + * @ingroup ntcore_c_api + */ +struct NT_TimestampedString { + /** + * Time in local time base. + */ + int64_t time; + + /** + * Time in server time base. May be 0 or 1 for locally set values. + */ + int64_t serverTime; + + /** + * Value. + */ + char* value; + /** + * Value length. + */ + size_t len; + +}; + +/** + * @defgroup ntcore_String_cfunc String Functions + * @ingroup ntcore_c_api + * @{ + */ + +/** + * Publish a new value. + * + * @param pubentry publisher or entry handle + * @param time timestamp; 0 indicates current NT time should be used + * @param value value to publish + * @param len length of value + + */ +NT_Bool NT_SetString(NT_Handle pubentry, int64_t time, const char* value, size_t len); + +/** + * Publish a default value. + * On reconnect, a default value will never be used in preference to a + * published value. + * + * @param pubentry publisher or entry handle + * @param defaultValue default value + * @param defaultValueLen length of default value + + */ +NT_Bool NT_SetDefaultString(NT_Handle pubentry, const char* defaultValue, size_t defaultValueLen); + +/** + * Get the last published value. + * If no value has been published, returns the passed defaultValue. + * + * @param subentry subscriber or entry handle + * @param defaultValue default value to return if no value has been published + * @param defaultValueLen length of default value + * @param len length of returned value (output) + + * @return value + */ +char* NT_GetString(NT_Handle subentry, const char* defaultValue, size_t defaultValueLen, size_t* len); + +/** + * Get the last published value along with its timestamp. + * If no value has been published, returns the passed defaultValue and a + * timestamp of 0. + * + * @param subentry subscriber or entry handle + * @param defaultValue default value to return if no value has been published + * @param defaultValueLen length of default value + + * @param value timestamped value (output) + */ +void NT_GetAtomicString(NT_Handle subentry, const char* defaultValue, size_t defaultValueLen, struct NT_TimestampedString* value); + +/** + * Disposes a timestamped value (as returned by NT_GetAtomicString). + * + * @param value timestamped value + */ +void NT_DisposeTimestampedString(struct NT_TimestampedString* value); + +/** + * Get an array of all value changes since the last call to ReadQueue. + * Also provides a timestamp for each value. + * + * @note The "poll storage" subscribe option can be used to set the queue + * depth. + * + * @param subentry subscriber or entry handle + * @param len length of returned array (output) + * @return Array of timestamped values; NULL if no new changes have + * been published since the previous call. + */ +struct NT_TimestampedString* NT_ReadQueueString(NT_Handle subentry, size_t* len); + +/** + * Frees a timestamped array of values (as returned by NT_ReadQueueString). + * + * @param arr array + * @param len length of array + */ +void NT_FreeQueueString(struct NT_TimestampedString* arr, size_t len); + +/** @} */ + +/** + * Timestamped Raw. + * @ingroup ntcore_c_api + */ +struct NT_TimestampedRaw { + /** + * Time in local time base. + */ + int64_t time; + + /** + * Time in server time base. May be 0 or 1 for locally set values. + */ + int64_t serverTime; + + /** + * Value. + */ + uint8_t* value; + /** + * Value length. + */ + size_t len; + +}; + +/** + * @defgroup ntcore_Raw_cfunc Raw Functions + * @ingroup ntcore_c_api + * @{ + */ + +/** + * Publish a new value. + * + * @param pubentry publisher or entry handle + * @param time timestamp; 0 indicates current NT time should be used + * @param value value to publish + * @param len length of value + + */ +NT_Bool NT_SetRaw(NT_Handle pubentry, int64_t time, const uint8_t* value, size_t len); + +/** + * Publish a default value. + * On reconnect, a default value will never be used in preference to a + * published value. + * + * @param pubentry publisher or entry handle + * @param defaultValue default value + * @param defaultValueLen length of default value + + */ +NT_Bool NT_SetDefaultRaw(NT_Handle pubentry, const uint8_t* defaultValue, size_t defaultValueLen); + +/** + * Get the last published value. + * If no value has been published, returns the passed defaultValue. + * + * @param subentry subscriber or entry handle + * @param defaultValue default value to return if no value has been published + * @param defaultValueLen length of default value + * @param len length of returned value (output) + + * @return value + */ +uint8_t* NT_GetRaw(NT_Handle subentry, const uint8_t* defaultValue, size_t defaultValueLen, size_t* len); + +/** + * Get the last published value along with its timestamp. + * If no value has been published, returns the passed defaultValue and a + * timestamp of 0. + * + * @param subentry subscriber or entry handle + * @param defaultValue default value to return if no value has been published + * @param defaultValueLen length of default value + + * @param value timestamped value (output) + */ +void NT_GetAtomicRaw(NT_Handle subentry, const uint8_t* defaultValue, size_t defaultValueLen, struct NT_TimestampedRaw* value); + +/** + * Disposes a timestamped value (as returned by NT_GetAtomicRaw). + * + * @param value timestamped value + */ +void NT_DisposeTimestampedRaw(struct NT_TimestampedRaw* value); + +/** + * Get an array of all value changes since the last call to ReadQueue. + * Also provides a timestamp for each value. + * + * @note The "poll storage" subscribe option can be used to set the queue + * depth. + * + * @param subentry subscriber or entry handle + * @param len length of returned array (output) + * @return Array of timestamped values; NULL if no new changes have + * been published since the previous call. + */ +struct NT_TimestampedRaw* NT_ReadQueueRaw(NT_Handle subentry, size_t* len); + +/** + * Frees a timestamped array of values (as returned by NT_ReadQueueRaw). + * + * @param arr array + * @param len length of array + */ +void NT_FreeQueueRaw(struct NT_TimestampedRaw* arr, size_t len); + +/** @} */ + +/** + * Timestamped BooleanArray. + * @ingroup ntcore_c_api + */ +struct NT_TimestampedBooleanArray { + /** + * Time in local time base. + */ + int64_t time; + + /** + * Time in server time base. May be 0 or 1 for locally set values. + */ + int64_t serverTime; + + /** + * Value. + */ + NT_Bool* value; + /** + * Value length. + */ + size_t len; + +}; + +/** + * @defgroup ntcore_BooleanArray_cfunc BooleanArray Functions + * @ingroup ntcore_c_api + * @{ + */ + +/** + * Publish a new value. + * + * @param pubentry publisher or entry handle + * @param time timestamp; 0 indicates current NT time should be used + * @param value value to publish + * @param len length of value + + */ +NT_Bool NT_SetBooleanArray(NT_Handle pubentry, int64_t time, const NT_Bool* value, size_t len); + +/** + * Publish a default value. + * On reconnect, a default value will never be used in preference to a + * published value. + * + * @param pubentry publisher or entry handle + * @param defaultValue default value + * @param defaultValueLen length of default value + + */ +NT_Bool NT_SetDefaultBooleanArray(NT_Handle pubentry, const NT_Bool* defaultValue, size_t defaultValueLen); + +/** + * Get the last published value. + * If no value has been published, returns the passed defaultValue. + * + * @param subentry subscriber or entry handle + * @param defaultValue default value to return if no value has been published + * @param defaultValueLen length of default value + * @param len length of returned value (output) + + * @return value + */ +NT_Bool* NT_GetBooleanArray(NT_Handle subentry, const NT_Bool* defaultValue, size_t defaultValueLen, size_t* len); + +/** + * Get the last published value along with its timestamp. + * If no value has been published, returns the passed defaultValue and a + * timestamp of 0. + * + * @param subentry subscriber or entry handle + * @param defaultValue default value to return if no value has been published + * @param defaultValueLen length of default value + + * @param value timestamped value (output) + */ +void NT_GetAtomicBooleanArray(NT_Handle subentry, const NT_Bool* defaultValue, size_t defaultValueLen, struct NT_TimestampedBooleanArray* value); + +/** + * Disposes a timestamped value (as returned by NT_GetAtomicBooleanArray). + * + * @param value timestamped value + */ +void NT_DisposeTimestampedBooleanArray(struct NT_TimestampedBooleanArray* value); + +/** + * Get an array of all value changes since the last call to ReadQueue. + * Also provides a timestamp for each value. + * + * @note The "poll storage" subscribe option can be used to set the queue + * depth. + * + * @param subentry subscriber or entry handle + * @param len length of returned array (output) + * @return Array of timestamped values; NULL if no new changes have + * been published since the previous call. + */ +struct NT_TimestampedBooleanArray* NT_ReadQueueBooleanArray(NT_Handle subentry, size_t* len); + +/** + * Frees a timestamped array of values (as returned by NT_ReadQueueBooleanArray). + * + * @param arr array + * @param len length of array + */ +void NT_FreeQueueBooleanArray(struct NT_TimestampedBooleanArray* arr, size_t len); + +/** @} */ + +/** + * Timestamped IntegerArray. + * @ingroup ntcore_c_api + */ +struct NT_TimestampedIntegerArray { + /** + * Time in local time base. + */ + int64_t time; + + /** + * Time in server time base. May be 0 or 1 for locally set values. + */ + int64_t serverTime; + + /** + * Value. + */ + int64_t* value; + /** + * Value length. + */ + size_t len; + +}; + +/** + * @defgroup ntcore_IntegerArray_cfunc IntegerArray Functions + * @ingroup ntcore_c_api + * @{ + */ + +/** + * Publish a new value. + * + * @param pubentry publisher or entry handle + * @param time timestamp; 0 indicates current NT time should be used + * @param value value to publish + * @param len length of value + + */ +NT_Bool NT_SetIntegerArray(NT_Handle pubentry, int64_t time, const int64_t* value, size_t len); + +/** + * Publish a default value. + * On reconnect, a default value will never be used in preference to a + * published value. + * + * @param pubentry publisher or entry handle + * @param defaultValue default value + * @param defaultValueLen length of default value + + */ +NT_Bool NT_SetDefaultIntegerArray(NT_Handle pubentry, const int64_t* defaultValue, size_t defaultValueLen); + +/** + * Get the last published value. + * If no value has been published, returns the passed defaultValue. + * + * @param subentry subscriber or entry handle + * @param defaultValue default value to return if no value has been published + * @param defaultValueLen length of default value + * @param len length of returned value (output) + + * @return value + */ +int64_t* NT_GetIntegerArray(NT_Handle subentry, const int64_t* defaultValue, size_t defaultValueLen, size_t* len); + +/** + * Get the last published value along with its timestamp. + * If no value has been published, returns the passed defaultValue and a + * timestamp of 0. + * + * @param subentry subscriber or entry handle + * @param defaultValue default value to return if no value has been published + * @param defaultValueLen length of default value + + * @param value timestamped value (output) + */ +void NT_GetAtomicIntegerArray(NT_Handle subentry, const int64_t* defaultValue, size_t defaultValueLen, struct NT_TimestampedIntegerArray* value); + +/** + * Disposes a timestamped value (as returned by NT_GetAtomicIntegerArray). + * + * @param value timestamped value + */ +void NT_DisposeTimestampedIntegerArray(struct NT_TimestampedIntegerArray* value); + +/** + * Get an array of all value changes since the last call to ReadQueue. + * Also provides a timestamp for each value. + * + * @note The "poll storage" subscribe option can be used to set the queue + * depth. + * + * @param subentry subscriber or entry handle + * @param len length of returned array (output) + * @return Array of timestamped values; NULL if no new changes have + * been published since the previous call. + */ +struct NT_TimestampedIntegerArray* NT_ReadQueueIntegerArray(NT_Handle subentry, size_t* len); + +/** + * Frees a timestamped array of values (as returned by NT_ReadQueueIntegerArray). + * + * @param arr array + * @param len length of array + */ +void NT_FreeQueueIntegerArray(struct NT_TimestampedIntegerArray* arr, size_t len); + +/** @} */ + +/** + * Timestamped FloatArray. + * @ingroup ntcore_c_api + */ +struct NT_TimestampedFloatArray { + /** + * Time in local time base. + */ + int64_t time; + + /** + * Time in server time base. May be 0 or 1 for locally set values. + */ + int64_t serverTime; + + /** + * Value. + */ + float* value; + /** + * Value length. + */ + size_t len; + +}; + +/** + * @defgroup ntcore_FloatArray_cfunc FloatArray Functions + * @ingroup ntcore_c_api + * @{ + */ + +/** + * Publish a new value. + * + * @param pubentry publisher or entry handle + * @param time timestamp; 0 indicates current NT time should be used + * @param value value to publish + * @param len length of value + + */ +NT_Bool NT_SetFloatArray(NT_Handle pubentry, int64_t time, const float* value, size_t len); + +/** + * Publish a default value. + * On reconnect, a default value will never be used in preference to a + * published value. + * + * @param pubentry publisher or entry handle + * @param defaultValue default value + * @param defaultValueLen length of default value + + */ +NT_Bool NT_SetDefaultFloatArray(NT_Handle pubentry, const float* defaultValue, size_t defaultValueLen); + +/** + * Get the last published value. + * If no value has been published, returns the passed defaultValue. + * + * @param subentry subscriber or entry handle + * @param defaultValue default value to return if no value has been published + * @param defaultValueLen length of default value + * @param len length of returned value (output) + + * @return value + */ +float* NT_GetFloatArray(NT_Handle subentry, const float* defaultValue, size_t defaultValueLen, size_t* len); + +/** + * Get the last published value along with its timestamp. + * If no value has been published, returns the passed defaultValue and a + * timestamp of 0. + * + * @param subentry subscriber or entry handle + * @param defaultValue default value to return if no value has been published + * @param defaultValueLen length of default value + + * @param value timestamped value (output) + */ +void NT_GetAtomicFloatArray(NT_Handle subentry, const float* defaultValue, size_t defaultValueLen, struct NT_TimestampedFloatArray* value); + +/** + * Disposes a timestamped value (as returned by NT_GetAtomicFloatArray). + * + * @param value timestamped value + */ +void NT_DisposeTimestampedFloatArray(struct NT_TimestampedFloatArray* value); + +/** + * Get an array of all value changes since the last call to ReadQueue. + * Also provides a timestamp for each value. + * + * @note The "poll storage" subscribe option can be used to set the queue + * depth. + * + * @param subentry subscriber or entry handle + * @param len length of returned array (output) + * @return Array of timestamped values; NULL if no new changes have + * been published since the previous call. + */ +struct NT_TimestampedFloatArray* NT_ReadQueueFloatArray(NT_Handle subentry, size_t* len); + +/** + * Frees a timestamped array of values (as returned by NT_ReadQueueFloatArray). + * + * @param arr array + * @param len length of array + */ +void NT_FreeQueueFloatArray(struct NT_TimestampedFloatArray* arr, size_t len); + +/** @} */ + +/** + * Timestamped DoubleArray. + * @ingroup ntcore_c_api + */ +struct NT_TimestampedDoubleArray { + /** + * Time in local time base. + */ + int64_t time; + + /** + * Time in server time base. May be 0 or 1 for locally set values. + */ + int64_t serverTime; + + /** + * Value. + */ + double* value; + /** + * Value length. + */ + size_t len; + +}; + +/** + * @defgroup ntcore_DoubleArray_cfunc DoubleArray Functions + * @ingroup ntcore_c_api + * @{ + */ + +/** + * Publish a new value. + * + * @param pubentry publisher or entry handle + * @param time timestamp; 0 indicates current NT time should be used + * @param value value to publish + * @param len length of value + + */ +NT_Bool NT_SetDoubleArray(NT_Handle pubentry, int64_t time, const double* value, size_t len); + +/** + * Publish a default value. + * On reconnect, a default value will never be used in preference to a + * published value. + * + * @param pubentry publisher or entry handle + * @param defaultValue default value + * @param defaultValueLen length of default value + + */ +NT_Bool NT_SetDefaultDoubleArray(NT_Handle pubentry, const double* defaultValue, size_t defaultValueLen); + +/** + * Get the last published value. + * If no value has been published, returns the passed defaultValue. + * + * @param subentry subscriber or entry handle + * @param defaultValue default value to return if no value has been published + * @param defaultValueLen length of default value + * @param len length of returned value (output) + + * @return value + */ +double* NT_GetDoubleArray(NT_Handle subentry, const double* defaultValue, size_t defaultValueLen, size_t* len); + +/** + * Get the last published value along with its timestamp. + * If no value has been published, returns the passed defaultValue and a + * timestamp of 0. + * + * @param subentry subscriber or entry handle + * @param defaultValue default value to return if no value has been published + * @param defaultValueLen length of default value + + * @param value timestamped value (output) + */ +void NT_GetAtomicDoubleArray(NT_Handle subentry, const double* defaultValue, size_t defaultValueLen, struct NT_TimestampedDoubleArray* value); + +/** + * Disposes a timestamped value (as returned by NT_GetAtomicDoubleArray). + * + * @param value timestamped value + */ +void NT_DisposeTimestampedDoubleArray(struct NT_TimestampedDoubleArray* value); + +/** + * Get an array of all value changes since the last call to ReadQueue. + * Also provides a timestamp for each value. + * + * @note The "poll storage" subscribe option can be used to set the queue + * depth. + * + * @param subentry subscriber or entry handle + * @param len length of returned array (output) + * @return Array of timestamped values; NULL if no new changes have + * been published since the previous call. + */ +struct NT_TimestampedDoubleArray* NT_ReadQueueDoubleArray(NT_Handle subentry, size_t* len); + +/** + * Frees a timestamped array of values (as returned by NT_ReadQueueDoubleArray). + * + * @param arr array + * @param len length of array + */ +void NT_FreeQueueDoubleArray(struct NT_TimestampedDoubleArray* arr, size_t len); + +/** @} */ + +/** + * Timestamped StringArray. + * @ingroup ntcore_c_api + */ +struct NT_TimestampedStringArray { + /** + * Time in local time base. + */ + int64_t time; + + /** + * Time in server time base. May be 0 or 1 for locally set values. + */ + int64_t serverTime; + + /** + * Value. + */ + struct NT_String* value; + /** + * Value length. + */ + size_t len; + +}; + +/** + * @defgroup ntcore_StringArray_cfunc StringArray Functions + * @ingroup ntcore_c_api + * @{ + */ + +/** + * Publish a new value. + * + * @param pubentry publisher or entry handle + * @param time timestamp; 0 indicates current NT time should be used + * @param value value to publish + * @param len length of value + + */ +NT_Bool NT_SetStringArray(NT_Handle pubentry, int64_t time, const struct NT_String* value, size_t len); + +/** + * Publish a default value. + * On reconnect, a default value will never be used in preference to a + * published value. + * + * @param pubentry publisher or entry handle + * @param defaultValue default value + * @param defaultValueLen length of default value + + */ +NT_Bool NT_SetDefaultStringArray(NT_Handle pubentry, const struct NT_String* defaultValue, size_t defaultValueLen); + +/** + * Get the last published value. + * If no value has been published, returns the passed defaultValue. + * + * @param subentry subscriber or entry handle + * @param defaultValue default value to return if no value has been published + * @param defaultValueLen length of default value + * @param len length of returned value (output) + + * @return value + */ +struct NT_String* NT_GetStringArray(NT_Handle subentry, const struct NT_String* defaultValue, size_t defaultValueLen, size_t* len); + +/** + * Get the last published value along with its timestamp. + * If no value has been published, returns the passed defaultValue and a + * timestamp of 0. + * + * @param subentry subscriber or entry handle + * @param defaultValue default value to return if no value has been published + * @param defaultValueLen length of default value + + * @param value timestamped value (output) + */ +void NT_GetAtomicStringArray(NT_Handle subentry, const struct NT_String* defaultValue, size_t defaultValueLen, struct NT_TimestampedStringArray* value); + +/** + * Disposes a timestamped value (as returned by NT_GetAtomicStringArray). + * + * @param value timestamped value + */ +void NT_DisposeTimestampedStringArray(struct NT_TimestampedStringArray* value); + +/** + * Get an array of all value changes since the last call to ReadQueue. + * Also provides a timestamp for each value. + * + * @note The "poll storage" subscribe option can be used to set the queue + * depth. + * + * @param subentry subscriber or entry handle + * @param len length of returned array (output) + * @return Array of timestamped values; NULL if no new changes have + * been published since the previous call. + */ +struct NT_TimestampedStringArray* NT_ReadQueueStringArray(NT_Handle subentry, size_t* len); + +/** + * Frees a timestamped array of values (as returned by NT_ReadQueueStringArray). + * + * @param arr array + * @param len length of array + */ +void NT_FreeQueueStringArray(struct NT_TimestampedStringArray* arr, size_t len); + +/** @} */ + + +#ifdef __cplusplus +} // extern "C" +#endif diff --git a/ntcore/src/generated/main/native/include/ntcore_cpp_types.h b/ntcore/src/generated/main/native/include/ntcore_cpp_types.h new file mode 100644 index 0000000000..c0cac5e5a5 --- /dev/null +++ b/ntcore/src/generated/main/native/include/ntcore_cpp_types.h @@ -0,0 +1,998 @@ +// 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. + +// THIS FILE WAS AUTO-GENERATED BY ./ntcore/generate_topics.py. DO NOT MODIFY + +#pragma once + +#include + +#include +#include +#include +#include +#include + +#include "ntcore_c.h" + +namespace wpi { +template +class SmallVectorImpl; +} // namespace wpi + +namespace nt { +/** + * Timestamped value. + * @ingroup ntcore_cpp_handle_api + */ +template +struct Timestamped { + Timestamped() = default; + Timestamped(int64_t time, int64_t serverTime, T value) + : time{time}, serverTime{serverTime}, value{std::move(value)} {} + + /** + * Time in local time base. + */ + int64_t time = 0; + + /** + * Time in server time base. May be 0 or 1 for locally set values. + */ + int64_t serverTime = 0; + + /** + * Value. + */ + T value = {}; +}; + +/** + * Timestamped Boolean. + * @ingroup ntcore_cpp_handle_api + */ +using TimestampedBoolean = Timestamped; + +/** + * @defgroup ntcore_Boolean_func Boolean Functions + * @ingroup ntcore_cpp_handle_api + * @{ + */ + +/** + * Publish a new value. + * + * @param pubentry publisher or entry handle + * @param value value to publish + * @param time timestamp; 0 indicates current NT time should be used + */ +bool SetBoolean(NT_Handle pubentry, bool value, int64_t time = 0); + +/** + * Publish a default value. + * On reconnect, a default value will never be used in preference to a + * published value. + * + * @param pubentry publisher or entry handle + * @param defaultValue default value + */ +bool SetDefaultBoolean(NT_Handle pubentry, bool defaultValue); + +/** + * Get the last published value. + * If no value has been published, returns the passed defaultValue. + * + * @param subentry subscriber or entry handle + * @param defaultValue default value to return if no value has been published + * @return value + */ +bool GetBoolean(NT_Handle subentry, bool defaultValue); + +/** + * Get the last published value along with its timestamp. + * If no value has been published, returns the passed defaultValue and a + * timestamp of 0. + * + * @param subentry subscriber or entry handle + * @param defaultValue default value to return if no value has been published + * @return timestamped value + */ +TimestampedBoolean GetAtomicBoolean(NT_Handle subentry, bool defaultValue); + +/** + * Get an array of all value changes since the last call to ReadQueue. + * Also provides a timestamp for each value. + * + * @note The "poll storage" subscribe option can be used to set the queue + * depth. + * + * @param subentry subscriber or entry handle + * @return Array of timestamped values; empty array if no new changes have + * been published since the previous call. + */ +std::vector ReadQueueBoolean(NT_Handle subentry); + +/** + * Get an array of all value changes since the last call to ReadQueue. + * + * @note The "poll storage" subscribe option can be used to set the queue + * depth. + * + * @param subentry subscriber or entry handle + * @return Array of values; empty array if no new changes have + * been published since the previous call. + */ +std::vector ReadQueueValuesBoolean(NT_Handle subentry); + +/** @} */ + +/** + * Timestamped Integer. + * @ingroup ntcore_cpp_handle_api + */ +using TimestampedInteger = Timestamped; + +/** + * @defgroup ntcore_Integer_func Integer Functions + * @ingroup ntcore_cpp_handle_api + * @{ + */ + +/** + * Publish a new value. + * + * @param pubentry publisher or entry handle + * @param value value to publish + * @param time timestamp; 0 indicates current NT time should be used + */ +bool SetInteger(NT_Handle pubentry, int64_t value, int64_t time = 0); + +/** + * Publish a default value. + * On reconnect, a default value will never be used in preference to a + * published value. + * + * @param pubentry publisher or entry handle + * @param defaultValue default value + */ +bool SetDefaultInteger(NT_Handle pubentry, int64_t defaultValue); + +/** + * Get the last published value. + * If no value has been published, returns the passed defaultValue. + * + * @param subentry subscriber or entry handle + * @param defaultValue default value to return if no value has been published + * @return value + */ +int64_t GetInteger(NT_Handle subentry, int64_t defaultValue); + +/** + * Get the last published value along with its timestamp. + * If no value has been published, returns the passed defaultValue and a + * timestamp of 0. + * + * @param subentry subscriber or entry handle + * @param defaultValue default value to return if no value has been published + * @return timestamped value + */ +TimestampedInteger GetAtomicInteger(NT_Handle subentry, int64_t defaultValue); + +/** + * Get an array of all value changes since the last call to ReadQueue. + * Also provides a timestamp for each value. + * + * @note The "poll storage" subscribe option can be used to set the queue + * depth. + * + * @param subentry subscriber or entry handle + * @return Array of timestamped values; empty array if no new changes have + * been published since the previous call. + */ +std::vector ReadQueueInteger(NT_Handle subentry); + +/** + * Get an array of all value changes since the last call to ReadQueue. + * + * @note The "poll storage" subscribe option can be used to set the queue + * depth. + * + * @param subentry subscriber or entry handle + * @return Array of values; empty array if no new changes have + * been published since the previous call. + */ +std::vector ReadQueueValuesInteger(NT_Handle subentry); + +/** @} */ + +/** + * Timestamped Float. + * @ingroup ntcore_cpp_handle_api + */ +using TimestampedFloat = Timestamped; + +/** + * @defgroup ntcore_Float_func Float Functions + * @ingroup ntcore_cpp_handle_api + * @{ + */ + +/** + * Publish a new value. + * + * @param pubentry publisher or entry handle + * @param value value to publish + * @param time timestamp; 0 indicates current NT time should be used + */ +bool SetFloat(NT_Handle pubentry, float value, int64_t time = 0); + +/** + * Publish a default value. + * On reconnect, a default value will never be used in preference to a + * published value. + * + * @param pubentry publisher or entry handle + * @param defaultValue default value + */ +bool SetDefaultFloat(NT_Handle pubentry, float defaultValue); + +/** + * Get the last published value. + * If no value has been published, returns the passed defaultValue. + * + * @param subentry subscriber or entry handle + * @param defaultValue default value to return if no value has been published + * @return value + */ +float GetFloat(NT_Handle subentry, float defaultValue); + +/** + * Get the last published value along with its timestamp. + * If no value has been published, returns the passed defaultValue and a + * timestamp of 0. + * + * @param subentry subscriber or entry handle + * @param defaultValue default value to return if no value has been published + * @return timestamped value + */ +TimestampedFloat GetAtomicFloat(NT_Handle subentry, float defaultValue); + +/** + * Get an array of all value changes since the last call to ReadQueue. + * Also provides a timestamp for each value. + * + * @note The "poll storage" subscribe option can be used to set the queue + * depth. + * + * @param subentry subscriber or entry handle + * @return Array of timestamped values; empty array if no new changes have + * been published since the previous call. + */ +std::vector ReadQueueFloat(NT_Handle subentry); + +/** + * Get an array of all value changes since the last call to ReadQueue. + * + * @note The "poll storage" subscribe option can be used to set the queue + * depth. + * + * @param subentry subscriber or entry handle + * @return Array of values; empty array if no new changes have + * been published since the previous call. + */ +std::vector ReadQueueValuesFloat(NT_Handle subentry); + +/** @} */ + +/** + * Timestamped Double. + * @ingroup ntcore_cpp_handle_api + */ +using TimestampedDouble = Timestamped; + +/** + * @defgroup ntcore_Double_func Double Functions + * @ingroup ntcore_cpp_handle_api + * @{ + */ + +/** + * Publish a new value. + * + * @param pubentry publisher or entry handle + * @param value value to publish + * @param time timestamp; 0 indicates current NT time should be used + */ +bool SetDouble(NT_Handle pubentry, double value, int64_t time = 0); + +/** + * Publish a default value. + * On reconnect, a default value will never be used in preference to a + * published value. + * + * @param pubentry publisher or entry handle + * @param defaultValue default value + */ +bool SetDefaultDouble(NT_Handle pubentry, double defaultValue); + +/** + * Get the last published value. + * If no value has been published, returns the passed defaultValue. + * + * @param subentry subscriber or entry handle + * @param defaultValue default value to return if no value has been published + * @return value + */ +double GetDouble(NT_Handle subentry, double defaultValue); + +/** + * Get the last published value along with its timestamp. + * If no value has been published, returns the passed defaultValue and a + * timestamp of 0. + * + * @param subentry subscriber or entry handle + * @param defaultValue default value to return if no value has been published + * @return timestamped value + */ +TimestampedDouble GetAtomicDouble(NT_Handle subentry, double defaultValue); + +/** + * Get an array of all value changes since the last call to ReadQueue. + * Also provides a timestamp for each value. + * + * @note The "poll storage" subscribe option can be used to set the queue + * depth. + * + * @param subentry subscriber or entry handle + * @return Array of timestamped values; empty array if no new changes have + * been published since the previous call. + */ +std::vector ReadQueueDouble(NT_Handle subentry); + +/** + * Get an array of all value changes since the last call to ReadQueue. + * + * @note The "poll storage" subscribe option can be used to set the queue + * depth. + * + * @param subentry subscriber or entry handle + * @return Array of values; empty array if no new changes have + * been published since the previous call. + */ +std::vector ReadQueueValuesDouble(NT_Handle subentry); + +/** @} */ + +/** + * Timestamped String. + * @ingroup ntcore_cpp_handle_api + */ +using TimestampedString = Timestamped; + +/** + * Timestamped String view (for SmallVector-taking functions). + * @ingroup ntcore_cpp_handle_api + */ +using TimestampedStringView = Timestamped; + +/** + * @defgroup ntcore_String_func String Functions + * @ingroup ntcore_cpp_handle_api + * @{ + */ + +/** + * Publish a new value. + * + * @param pubentry publisher or entry handle + * @param value value to publish + * @param time timestamp; 0 indicates current NT time should be used + */ +bool SetString(NT_Handle pubentry, std::string_view value, int64_t time = 0); + +/** + * Publish a default value. + * On reconnect, a default value will never be used in preference to a + * published value. + * + * @param pubentry publisher or entry handle + * @param defaultValue default value + */ +bool SetDefaultString(NT_Handle pubentry, std::string_view defaultValue); + +/** + * Get the last published value. + * If no value has been published, returns the passed defaultValue. + * + * @param subentry subscriber or entry handle + * @param defaultValue default value to return if no value has been published + * @return value + */ +std::string GetString(NT_Handle subentry, std::string_view defaultValue); + +/** + * Get the last published value along with its timestamp. + * If no value has been published, returns the passed defaultValue and a + * timestamp of 0. + * + * @param subentry subscriber or entry handle + * @param defaultValue default value to return if no value has been published + * @return timestamped value + */ +TimestampedString GetAtomicString(NT_Handle subentry, std::string_view defaultValue); + +/** + * Get an array of all value changes since the last call to ReadQueue. + * Also provides a timestamp for each value. + * + * @note The "poll storage" subscribe option can be used to set the queue + * depth. + * + * @param subentry subscriber or entry handle + * @return Array of timestamped values; empty array if no new changes have + * been published since the previous call. + */ +std::vector ReadQueueString(NT_Handle subentry); + +/** + * Get an array of all value changes since the last call to ReadQueue. + * + * @note The "poll storage" subscribe option can be used to set the queue + * depth. + * + * @param subentry subscriber or entry handle + * @return Array of values; empty array if no new changes have + * been published since the previous call. + */ +std::vector ReadQueueValuesString(NT_Handle subentry); + +std::string_view GetString(NT_Handle subentry, wpi::SmallVectorImpl& buf, std::string_view defaultValue); + +TimestampedStringView GetAtomicString( + NT_Handle subentry, + wpi::SmallVectorImpl& buf, + std::string_view defaultValue); + +/** @} */ + +/** + * Timestamped Raw. + * @ingroup ntcore_cpp_handle_api + */ +using TimestampedRaw = Timestamped>; + +/** + * Timestamped Raw view (for SmallVector-taking functions). + * @ingroup ntcore_cpp_handle_api + */ +using TimestampedRawView = Timestamped>; + +/** + * @defgroup ntcore_Raw_func Raw Functions + * @ingroup ntcore_cpp_handle_api + * @{ + */ + +/** + * Publish a new value. + * + * @param pubentry publisher or entry handle + * @param value value to publish + * @param time timestamp; 0 indicates current NT time should be used + */ +bool SetRaw(NT_Handle pubentry, std::span value, int64_t time = 0); + +/** + * Publish a default value. + * On reconnect, a default value will never be used in preference to a + * published value. + * + * @param pubentry publisher or entry handle + * @param defaultValue default value + */ +bool SetDefaultRaw(NT_Handle pubentry, std::span defaultValue); + +/** + * Get the last published value. + * If no value has been published, returns the passed defaultValue. + * + * @param subentry subscriber or entry handle + * @param defaultValue default value to return if no value has been published + * @return value + */ +std::vector GetRaw(NT_Handle subentry, std::span defaultValue); + +/** + * Get the last published value along with its timestamp. + * If no value has been published, returns the passed defaultValue and a + * timestamp of 0. + * + * @param subentry subscriber or entry handle + * @param defaultValue default value to return if no value has been published + * @return timestamped value + */ +TimestampedRaw GetAtomicRaw(NT_Handle subentry, std::span defaultValue); + +/** + * Get an array of all value changes since the last call to ReadQueue. + * Also provides a timestamp for each value. + * + * @note The "poll storage" subscribe option can be used to set the queue + * depth. + * + * @param subentry subscriber or entry handle + * @return Array of timestamped values; empty array if no new changes have + * been published since the previous call. + */ +std::vector ReadQueueRaw(NT_Handle subentry); + +/** + * Get an array of all value changes since the last call to ReadQueue. + * + * @note The "poll storage" subscribe option can be used to set the queue + * depth. + * + * @param subentry subscriber or entry handle + * @return Array of values; empty array if no new changes have + * been published since the previous call. + */ +std::vector> ReadQueueValuesRaw(NT_Handle subentry); + +std::span GetRaw(NT_Handle subentry, wpi::SmallVectorImpl& buf, std::span defaultValue); + +TimestampedRawView GetAtomicRaw( + NT_Handle subentry, + wpi::SmallVectorImpl& buf, + std::span defaultValue); + +/** @} */ + +/** + * Timestamped BooleanArray. + * @ingroup ntcore_cpp_handle_api + */ +using TimestampedBooleanArray = Timestamped>; + +/** + * Timestamped BooleanArray view (for SmallVector-taking functions). + * @ingroup ntcore_cpp_handle_api + */ +using TimestampedBooleanArrayView = Timestamped>; + +/** + * @defgroup ntcore_BooleanArray_func BooleanArray Functions + * @ingroup ntcore_cpp_handle_api + * @{ + */ + +/** + * Publish a new value. + * + * @param pubentry publisher or entry handle + * @param value value to publish + * @param time timestamp; 0 indicates current NT time should be used + */ +bool SetBooleanArray(NT_Handle pubentry, std::span value, int64_t time = 0); + +/** + * Publish a default value. + * On reconnect, a default value will never be used in preference to a + * published value. + * + * @param pubentry publisher or entry handle + * @param defaultValue default value + */ +bool SetDefaultBooleanArray(NT_Handle pubentry, std::span defaultValue); + +/** + * Get the last published value. + * If no value has been published, returns the passed defaultValue. + * + * @param subentry subscriber or entry handle + * @param defaultValue default value to return if no value has been published + * @return value + */ +std::vector GetBooleanArray(NT_Handle subentry, std::span defaultValue); + +/** + * Get the last published value along with its timestamp. + * If no value has been published, returns the passed defaultValue and a + * timestamp of 0. + * + * @param subentry subscriber or entry handle + * @param defaultValue default value to return if no value has been published + * @return timestamped value + */ +TimestampedBooleanArray GetAtomicBooleanArray(NT_Handle subentry, std::span defaultValue); + +/** + * Get an array of all value changes since the last call to ReadQueue. + * Also provides a timestamp for each value. + * + * @note The "poll storage" subscribe option can be used to set the queue + * depth. + * + * @param subentry subscriber or entry handle + * @return Array of timestamped values; empty array if no new changes have + * been published since the previous call. + */ +std::vector ReadQueueBooleanArray(NT_Handle subentry); + +/** + * Get an array of all value changes since the last call to ReadQueue. + * + * @note The "poll storage" subscribe option can be used to set the queue + * depth. + * + * @param subentry subscriber or entry handle + * @return Array of values; empty array if no new changes have + * been published since the previous call. + */ +std::vector> ReadQueueValuesBooleanArray(NT_Handle subentry); + +std::span GetBooleanArray(NT_Handle subentry, wpi::SmallVectorImpl& buf, std::span defaultValue); + +TimestampedBooleanArrayView GetAtomicBooleanArray( + NT_Handle subentry, + wpi::SmallVectorImpl& buf, + std::span defaultValue); + +/** @} */ + +/** + * Timestamped IntegerArray. + * @ingroup ntcore_cpp_handle_api + */ +using TimestampedIntegerArray = Timestamped>; + +/** + * Timestamped IntegerArray view (for SmallVector-taking functions). + * @ingroup ntcore_cpp_handle_api + */ +using TimestampedIntegerArrayView = Timestamped>; + +/** + * @defgroup ntcore_IntegerArray_func IntegerArray Functions + * @ingroup ntcore_cpp_handle_api + * @{ + */ + +/** + * Publish a new value. + * + * @param pubentry publisher or entry handle + * @param value value to publish + * @param time timestamp; 0 indicates current NT time should be used + */ +bool SetIntegerArray(NT_Handle pubentry, std::span value, int64_t time = 0); + +/** + * Publish a default value. + * On reconnect, a default value will never be used in preference to a + * published value. + * + * @param pubentry publisher or entry handle + * @param defaultValue default value + */ +bool SetDefaultIntegerArray(NT_Handle pubentry, std::span defaultValue); + +/** + * Get the last published value. + * If no value has been published, returns the passed defaultValue. + * + * @param subentry subscriber or entry handle + * @param defaultValue default value to return if no value has been published + * @return value + */ +std::vector GetIntegerArray(NT_Handle subentry, std::span defaultValue); + +/** + * Get the last published value along with its timestamp. + * If no value has been published, returns the passed defaultValue and a + * timestamp of 0. + * + * @param subentry subscriber or entry handle + * @param defaultValue default value to return if no value has been published + * @return timestamped value + */ +TimestampedIntegerArray GetAtomicIntegerArray(NT_Handle subentry, std::span defaultValue); + +/** + * Get an array of all value changes since the last call to ReadQueue. + * Also provides a timestamp for each value. + * + * @note The "poll storage" subscribe option can be used to set the queue + * depth. + * + * @param subentry subscriber or entry handle + * @return Array of timestamped values; empty array if no new changes have + * been published since the previous call. + */ +std::vector ReadQueueIntegerArray(NT_Handle subentry); + +/** + * Get an array of all value changes since the last call to ReadQueue. + * + * @note The "poll storage" subscribe option can be used to set the queue + * depth. + * + * @param subentry subscriber or entry handle + * @return Array of values; empty array if no new changes have + * been published since the previous call. + */ +std::vector> ReadQueueValuesIntegerArray(NT_Handle subentry); + +std::span GetIntegerArray(NT_Handle subentry, wpi::SmallVectorImpl& buf, std::span defaultValue); + +TimestampedIntegerArrayView GetAtomicIntegerArray( + NT_Handle subentry, + wpi::SmallVectorImpl& buf, + std::span defaultValue); + +/** @} */ + +/** + * Timestamped FloatArray. + * @ingroup ntcore_cpp_handle_api + */ +using TimestampedFloatArray = Timestamped>; + +/** + * Timestamped FloatArray view (for SmallVector-taking functions). + * @ingroup ntcore_cpp_handle_api + */ +using TimestampedFloatArrayView = Timestamped>; + +/** + * @defgroup ntcore_FloatArray_func FloatArray Functions + * @ingroup ntcore_cpp_handle_api + * @{ + */ + +/** + * Publish a new value. + * + * @param pubentry publisher or entry handle + * @param value value to publish + * @param time timestamp; 0 indicates current NT time should be used + */ +bool SetFloatArray(NT_Handle pubentry, std::span value, int64_t time = 0); + +/** + * Publish a default value. + * On reconnect, a default value will never be used in preference to a + * published value. + * + * @param pubentry publisher or entry handle + * @param defaultValue default value + */ +bool SetDefaultFloatArray(NT_Handle pubentry, std::span defaultValue); + +/** + * Get the last published value. + * If no value has been published, returns the passed defaultValue. + * + * @param subentry subscriber or entry handle + * @param defaultValue default value to return if no value has been published + * @return value + */ +std::vector GetFloatArray(NT_Handle subentry, std::span defaultValue); + +/** + * Get the last published value along with its timestamp. + * If no value has been published, returns the passed defaultValue and a + * timestamp of 0. + * + * @param subentry subscriber or entry handle + * @param defaultValue default value to return if no value has been published + * @return timestamped value + */ +TimestampedFloatArray GetAtomicFloatArray(NT_Handle subentry, std::span defaultValue); + +/** + * Get an array of all value changes since the last call to ReadQueue. + * Also provides a timestamp for each value. + * + * @note The "poll storage" subscribe option can be used to set the queue + * depth. + * + * @param subentry subscriber or entry handle + * @return Array of timestamped values; empty array if no new changes have + * been published since the previous call. + */ +std::vector ReadQueueFloatArray(NT_Handle subentry); + +/** + * Get an array of all value changes since the last call to ReadQueue. + * + * @note The "poll storage" subscribe option can be used to set the queue + * depth. + * + * @param subentry subscriber or entry handle + * @return Array of values; empty array if no new changes have + * been published since the previous call. + */ +std::vector> ReadQueueValuesFloatArray(NT_Handle subentry); + +std::span GetFloatArray(NT_Handle subentry, wpi::SmallVectorImpl& buf, std::span defaultValue); + +TimestampedFloatArrayView GetAtomicFloatArray( + NT_Handle subentry, + wpi::SmallVectorImpl& buf, + std::span defaultValue); + +/** @} */ + +/** + * Timestamped DoubleArray. + * @ingroup ntcore_cpp_handle_api + */ +using TimestampedDoubleArray = Timestamped>; + +/** + * Timestamped DoubleArray view (for SmallVector-taking functions). + * @ingroup ntcore_cpp_handle_api + */ +using TimestampedDoubleArrayView = Timestamped>; + +/** + * @defgroup ntcore_DoubleArray_func DoubleArray Functions + * @ingroup ntcore_cpp_handle_api + * @{ + */ + +/** + * Publish a new value. + * + * @param pubentry publisher or entry handle + * @param value value to publish + * @param time timestamp; 0 indicates current NT time should be used + */ +bool SetDoubleArray(NT_Handle pubentry, std::span value, int64_t time = 0); + +/** + * Publish a default value. + * On reconnect, a default value will never be used in preference to a + * published value. + * + * @param pubentry publisher or entry handle + * @param defaultValue default value + */ +bool SetDefaultDoubleArray(NT_Handle pubentry, std::span defaultValue); + +/** + * Get the last published value. + * If no value has been published, returns the passed defaultValue. + * + * @param subentry subscriber or entry handle + * @param defaultValue default value to return if no value has been published + * @return value + */ +std::vector GetDoubleArray(NT_Handle subentry, std::span defaultValue); + +/** + * Get the last published value along with its timestamp. + * If no value has been published, returns the passed defaultValue and a + * timestamp of 0. + * + * @param subentry subscriber or entry handle + * @param defaultValue default value to return if no value has been published + * @return timestamped value + */ +TimestampedDoubleArray GetAtomicDoubleArray(NT_Handle subentry, std::span defaultValue); + +/** + * Get an array of all value changes since the last call to ReadQueue. + * Also provides a timestamp for each value. + * + * @note The "poll storage" subscribe option can be used to set the queue + * depth. + * + * @param subentry subscriber or entry handle + * @return Array of timestamped values; empty array if no new changes have + * been published since the previous call. + */ +std::vector ReadQueueDoubleArray(NT_Handle subentry); + +/** + * Get an array of all value changes since the last call to ReadQueue. + * + * @note The "poll storage" subscribe option can be used to set the queue + * depth. + * + * @param subentry subscriber or entry handle + * @return Array of values; empty array if no new changes have + * been published since the previous call. + */ +std::vector> ReadQueueValuesDoubleArray(NT_Handle subentry); + +std::span GetDoubleArray(NT_Handle subentry, wpi::SmallVectorImpl& buf, std::span defaultValue); + +TimestampedDoubleArrayView GetAtomicDoubleArray( + NT_Handle subentry, + wpi::SmallVectorImpl& buf, + std::span defaultValue); + +/** @} */ + +/** + * Timestamped StringArray. + * @ingroup ntcore_cpp_handle_api + */ +using TimestampedStringArray = Timestamped>; + +/** + * @defgroup ntcore_StringArray_func StringArray Functions + * @ingroup ntcore_cpp_handle_api + * @{ + */ + +/** + * Publish a new value. + * + * @param pubentry publisher or entry handle + * @param value value to publish + * @param time timestamp; 0 indicates current NT time should be used + */ +bool SetStringArray(NT_Handle pubentry, std::span value, int64_t time = 0); + +/** + * Publish a default value. + * On reconnect, a default value will never be used in preference to a + * published value. + * + * @param pubentry publisher or entry handle + * @param defaultValue default value + */ +bool SetDefaultStringArray(NT_Handle pubentry, std::span defaultValue); + +/** + * Get the last published value. + * If no value has been published, returns the passed defaultValue. + * + * @param subentry subscriber or entry handle + * @param defaultValue default value to return if no value has been published + * @return value + */ +std::vector GetStringArray(NT_Handle subentry, std::span defaultValue); + +/** + * Get the last published value along with its timestamp. + * If no value has been published, returns the passed defaultValue and a + * timestamp of 0. + * + * @param subentry subscriber or entry handle + * @param defaultValue default value to return if no value has been published + * @return timestamped value + */ +TimestampedStringArray GetAtomicStringArray(NT_Handle subentry, std::span defaultValue); + +/** + * Get an array of all value changes since the last call to ReadQueue. + * Also provides a timestamp for each value. + * + * @note The "poll storage" subscribe option can be used to set the queue + * depth. + * + * @param subentry subscriber or entry handle + * @return Array of timestamped values; empty array if no new changes have + * been published since the previous call. + */ +std::vector ReadQueueStringArray(NT_Handle subentry); + +/** + * Get an array of all value changes since the last call to ReadQueue. + * + * @note The "poll storage" subscribe option can be used to set the queue + * depth. + * + * @param subentry subscriber or entry handle + * @return Array of values; empty array if no new changes have + * been published since the previous call. + */ +std::vector> ReadQueueValuesStringArray(NT_Handle subentry); + +/** @} */ + +} // namespace nt diff --git a/shared/java/javastyle.gradle b/shared/java/javastyle.gradle index 49332bf748..5049efa48f 100644 --- a/shared/java/javastyle.gradle +++ b/shared/java/javastyle.gradle @@ -23,7 +23,7 @@ if (!project.hasProperty('skipJavaFormat')) { java { target fileTree('.') { include '**/*.java' - exclude '**/build/**', '**/build-*/**', '**/bin/**' + exclude '**/build/**', '**/build-*/**', '**/bin/**', "src/generated/**" } toggleOffOn() googleJavaFormat()