From 64d074330a09488bf331a12d29aa5a30bf42a653 Mon Sep 17 00:00:00 2001 From: DeltaDizzy Date: Sun, 5 Jan 2025 11:44:13 -0600 Subject: [PATCH 01/64] move datalogreaderthread to wpiutil --- .../src/main/native/cpp}/DataLogReaderThread.cpp | 4 ++-- .../src/main/native/include/wpi}/DataLogReaderThread.h | 4 ++-- 2 files changed, 4 insertions(+), 4 deletions(-) rename {glass/src/lib/native/cpp/support => wpiutil/src/main/native/cpp}/DataLogReaderThread.cpp (98%) rename {glass/src/lib/native/include/glass/support => wpiutil/src/main/native/include/wpi}/DataLogReaderThread.h (98%) diff --git a/glass/src/lib/native/cpp/support/DataLogReaderThread.cpp b/wpiutil/src/main/native/cpp/DataLogReaderThread.cpp similarity index 98% rename from glass/src/lib/native/cpp/support/DataLogReaderThread.cpp rename to wpiutil/src/main/native/cpp/DataLogReaderThread.cpp index c4336f65567..ca34fcb139f 100644 --- a/glass/src/lib/native/cpp/support/DataLogReaderThread.cpp +++ b/wpiutil/src/main/native/cpp/DataLogReaderThread.cpp @@ -2,7 +2,7 @@ // Open Source Software; you can modify and/or share it under the terms of // the WPILib BSD license file in the root directory of this project. -#include "glass/support/DataLogReaderThread.h" +#include "wpi/DataLogReaderThread.h" #include #include @@ -10,7 +10,7 @@ #include #include -using namespace glass; +using namespace wpi; DataLogReaderThread::~DataLogReaderThread() { if (m_thread.joinable()) { diff --git a/glass/src/lib/native/include/glass/support/DataLogReaderThread.h b/wpiutil/src/main/native/include/wpi/DataLogReaderThread.h similarity index 98% rename from glass/src/lib/native/include/glass/support/DataLogReaderThread.h rename to wpiutil/src/main/native/include/wpi/DataLogReaderThread.h index 2cfb89e39be..e88736aba9d 100644 --- a/glass/src/lib/native/include/glass/support/DataLogReaderThread.h +++ b/wpiutil/src/main/native/include/wpi/DataLogReaderThread.h @@ -23,7 +23,7 @@ #include #endif -namespace glass { +namespace wpi { class DataLogReaderRange { public: @@ -105,4 +105,4 @@ class DataLogReaderThread { std::thread m_thread; }; -} // namespace glass +} // namespace wpi From f6c9c4874ad90a60529edbc7be98b59436d1cf1b Mon Sep 17 00:00:00 2001 From: DeltaDizzy Date: Sun, 5 Jan 2025 11:46:54 -0600 Subject: [PATCH 02/64] fix datalog rader references in sysid --- sysid/src/main/native/cpp/view/DataSelector.cpp | 12 ++++++------ sysid/src/main/native/cpp/view/LogLoader.cpp | 8 ++++---- .../main/native/include/sysid/view/DataSelector.h | 14 +++++++------- .../src/main/native/include/sysid/view/LogLoader.h | 8 ++++---- 4 files changed, 21 insertions(+), 21 deletions(-) diff --git a/sysid/src/main/native/cpp/view/DataSelector.cpp b/sysid/src/main/native/cpp/view/DataSelector.cpp index 3409bf6ee37..7ec927f9327 100644 --- a/sysid/src/main/native/cpp/view/DataSelector.cpp +++ b/sysid/src/main/native/cpp/view/DataSelector.cpp @@ -10,7 +10,7 @@ #include #include -#include +#include #include #include #include @@ -25,7 +25,7 @@ using namespace sysid; static constexpr const char* kAnalysisTypes[] = {"Elevator", "Arm", "Simple"}; static bool EmitEntryTarget(const char* name, bool isString, - const glass::DataLogReaderEntry** entry) { + const wpi::DataLogReaderEntry** entry) { if (*entry) { auto text = fmt::format("{}: {} ({})", name, (*entry)->name, (*entry)->type); @@ -38,8 +38,8 @@ static bool EmitEntryTarget(const char* name, bool isString, if (ImGui::BeginDragDropTarget()) { if (const ImGuiPayload* payload = ImGui::AcceptDragDropPayload( isString ? "DataLogEntryString" : "DataLogEntry")) { - assert(payload->DataSize == sizeof(const glass::DataLogReaderEntry*)); - *entry = *static_cast(payload->Data); + assert(payload->DataSize == sizeof(const wpi::DataLogReaderEntry*)); + *entry = *static_cast(payload->Data); rv = true; } ImGui::EndDragDropTarget(); @@ -179,7 +179,7 @@ void DataSelector::Reset() { } DataSelector::Tests DataSelector::LoadTests( - const glass::DataLogReaderEntry& testStateEntry) { + const wpi::DataLogReaderEntry& testStateEntry) { Tests tests; for (auto&& range : testStateEntry.ranges) { std::string_view prevState; @@ -245,7 +245,7 @@ static void AddSamples(std::vector>& samples, } static std::vector> GetData( - const glass::DataLogReaderEntry& entry, double scale) { + const wpi::DataLogReaderEntry& entry, double scale) { std::vector> rv; bool isDouble = entry.type == "double"; for (auto&& range : entry.ranges) { diff --git a/sysid/src/main/native/cpp/view/LogLoader.cpp b/sysid/src/main/native/cpp/view/LogLoader.cpp index 8e0fe429b2e..0050fd85593 100644 --- a/sysid/src/main/native/cpp/view/LogLoader.cpp +++ b/sysid/src/main/native/cpp/view/LogLoader.cpp @@ -12,7 +12,7 @@ #include #include -#include +#include #include #include #include @@ -55,7 +55,7 @@ void LogLoader::Display() { } unload(); m_reader = - std::make_unique(std::move(reader)); + std::make_unique(std::move(reader)); m_entryTree.clear(); } m_opener.reset(); @@ -108,7 +108,7 @@ void LogLoader::Display() { void LogLoader::RebuildEntryTree() { m_entryTree.clear(); wpi::SmallVector parts; - m_reader->ForEachEntryName([&](const glass::DataLogReaderEntry& entry) { + m_reader->ForEachEntryName([&](const wpi::DataLogReaderEntry& entry) { // only show double/float/string entries (TODO: support struct/protobuf) if (entry.type != "double" && entry.type != "float" && entry.type != "string") { @@ -167,7 +167,7 @@ void LogLoader::RebuildEntryTree() { } static void EmitEntry(const std::string& name, - const glass::DataLogReaderEntry& entry) { + const wpi::DataLogReaderEntry& entry) { ImGui::TableNextColumn(); ImGui::Selectable(name.c_str()); if (ImGui::BeginDragDropSource()) { diff --git a/sysid/src/main/native/include/sysid/view/DataSelector.h b/sysid/src/main/native/include/sysid/view/DataSelector.h index 71732a7ed74..9b021f88d71 100644 --- a/sysid/src/main/native/include/sysid/view/DataSelector.h +++ b/sysid/src/main/native/include/sysid/view/DataSelector.h @@ -12,17 +12,17 @@ #include #include -#include +#include #include #include "sysid/analysis/Storage.h" namespace glass { -class DataLogReaderEntry; class Storage; } // namespace glass namespace wpi { +class DataLogReaderEntry; class Logger; } // namespace wpi @@ -64,10 +64,10 @@ class DataSelector : public glass::View { std::future m_testsFuture; Tests m_tests; std::string m_selectedTest; - const glass::DataLogReaderEntry* m_testStateEntry = nullptr; - const glass::DataLogReaderEntry* m_velocityEntry = nullptr; - const glass::DataLogReaderEntry* m_positionEntry = nullptr; - const glass::DataLogReaderEntry* m_voltageEntry = nullptr; + const wpi::DataLogReaderEntry* m_testStateEntry = nullptr; + const wpi::DataLogReaderEntry* m_velocityEntry = nullptr; + const wpi::DataLogReaderEntry* m_positionEntry = nullptr; + const wpi::DataLogReaderEntry* m_voltageEntry = nullptr; double m_velocityScale = 1.0; double m_positionScale = 1.0; int m_selectedUnit = 0; @@ -75,7 +75,7 @@ class DataSelector : public glass::View { std::future m_testdataFuture; std::vector m_testdataStats; - static Tests LoadTests(const glass::DataLogReaderEntry& testStateEntry); + static Tests LoadTests(const wpi::DataLogReaderEntry& testStateEntry); TestData BuildTestData(); }; } // namespace sysid diff --git a/sysid/src/main/native/include/sysid/view/LogLoader.h b/sysid/src/main/native/include/sysid/view/LogLoader.h index 04ddd84dab3..f641a4de10b 100644 --- a/sysid/src/main/native/include/sysid/view/LogLoader.h +++ b/sysid/src/main/native/include/sysid/view/LogLoader.h @@ -13,8 +13,6 @@ #include namespace glass { -class DataLogReaderEntry; -class DataLogReaderThread; class Storage; } // namespace glass @@ -23,6 +21,8 @@ class open_file; } // namespace pfd namespace wpi { +class DataLogReaderEntry; +class DataLogReaderThread; class Logger; } // namespace wpi @@ -57,7 +57,7 @@ class LogLoader : public glass::View { std::string m_filename; std::unique_ptr m_opener; - std::unique_ptr m_reader; + std::unique_ptr m_reader; std::string m_error; @@ -67,7 +67,7 @@ class LogLoader : public glass::View { explicit EntryTreeNode(std::string_view name) : name{name} {} std::string name; // name of just this node std::string path; // full path if entry is nullptr - const glass::DataLogReaderEntry* entry = nullptr; + const wpi::DataLogReaderEntry* entry = nullptr; std::vector children; // children, sorted by name }; std::vector m_entryTree; From 3ed7b7edb2e8cab17fc1b2e00c2e7be0d58cb4c9 Mon Sep 17 00:00:00 2001 From: DeltaDizzy Date: Sun, 5 Jan 2025 12:05:44 -0600 Subject: [PATCH 03/64] run wpiformat --- sysid/src/main/native/cpp/view/DataSelector.cpp | 2 +- sysid/src/main/native/cpp/view/LogLoader.cpp | 5 ++--- wpiutil/src/main/native/cpp/DataLogReaderThread.cpp | 6 +++--- .../main/native/include/wpi/DataLogReaderThread.h | 12 ++++++------ 4 files changed, 12 insertions(+), 13 deletions(-) diff --git a/sysid/src/main/native/cpp/view/DataSelector.cpp b/sysid/src/main/native/cpp/view/DataSelector.cpp index 7ec927f9327..39eddb8294d 100644 --- a/sysid/src/main/native/cpp/view/DataSelector.cpp +++ b/sysid/src/main/native/cpp/view/DataSelector.cpp @@ -10,9 +10,9 @@ #include #include -#include #include #include +#include #include #include diff --git a/sysid/src/main/native/cpp/view/LogLoader.cpp b/sysid/src/main/native/cpp/view/LogLoader.cpp index 0050fd85593..0b2f41a8da0 100644 --- a/sysid/src/main/native/cpp/view/LogLoader.cpp +++ b/sysid/src/main/native/cpp/view/LogLoader.cpp @@ -12,10 +12,10 @@ #include #include -#include #include #include #include +#include #include #include #include @@ -54,8 +54,7 @@ void LogLoader::Display() { return; } unload(); - m_reader = - std::make_unique(std::move(reader)); + m_reader = std::make_unique(std::move(reader)); m_entryTree.clear(); } m_opener.reset(); diff --git a/wpiutil/src/main/native/cpp/DataLogReaderThread.cpp b/wpiutil/src/main/native/cpp/DataLogReaderThread.cpp index ca34fcb139f..ad8bd767dfe 100644 --- a/wpiutil/src/main/native/cpp/DataLogReaderThread.cpp +++ b/wpiutil/src/main/native/cpp/DataLogReaderThread.cpp @@ -4,12 +4,12 @@ #include "wpi/DataLogReaderThread.h" -#include -#include - #include #include +#include +#include + using namespace wpi; DataLogReaderThread::~DataLogReaderThread() { diff --git a/wpiutil/src/main/native/include/wpi/DataLogReaderThread.h b/wpiutil/src/main/native/include/wpi/DataLogReaderThread.h index e88736aba9d..168b0049576 100644 --- a/wpiutil/src/main/native/include/wpi/DataLogReaderThread.h +++ b/wpiutil/src/main/native/include/wpi/DataLogReaderThread.h @@ -4,6 +4,12 @@ #pragma once +#include +#include +#include +#include +#include + #include #include #include @@ -13,12 +19,6 @@ #include #include -#include -#include -#include -#include -#include - #ifndef NO_PROTOBUF #include #endif From f1bf505aeedcd83eb2d829a24ebc93dc54483d56 Mon Sep 17 00:00:00 2001 From: DeltaDizzy Date: Sun, 5 Jan 2025 12:19:29 -0600 Subject: [PATCH 04/64] point datalogtool at wpiutil --- datalogtool/src/main/native/cpp/Exporter.cpp | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/datalogtool/src/main/native/cpp/Exporter.cpp b/datalogtool/src/main/native/cpp/Exporter.cpp index 149b6718309..b391b8f59f0 100644 --- a/datalogtool/src/main/native/cpp/Exporter.cpp +++ b/datalogtool/src/main/native/cpp/Exporter.cpp @@ -20,7 +20,7 @@ #include #include #include -#include +#include #include #include #include @@ -40,7 +40,7 @@ namespace { struct InputFile { - explicit InputFile(std::unique_ptr datalog); + explicit InputFile(std::unique_ptr datalog); InputFile(std::string_view filename, std::string_view status) : filename{filename}, @@ -51,7 +51,7 @@ struct InputFile { std::string filename; std::string stem; - std::unique_ptr datalog; + std::unique_ptr datalog; std::string status; bool highlight = false; }; @@ -140,7 +140,7 @@ static void RebuildEntryTree() { } } -InputFile::InputFile(std::unique_ptr datalog_) +InputFile::InputFile(std::unique_ptr datalog_) : filename{datalog_->GetBufferIdentifier()}, stem{fs::path{filename}.stem().string()}, datalog{std::move(datalog_)} { @@ -196,7 +196,7 @@ static std::unique_ptr LoadDataLog(std::string_view filename) { } return std::make_unique( - std::make_unique(std::move(reader))); + std::make_unique(std::move(reader))); } void DisplayInputFiles() { From ee30eed465d0ce64034064d35164d53e79809c91 Mon Sep 17 00:00:00 2001 From: DeltaDizzy Date: Sun, 5 Jan 2025 12:20:04 -0600 Subject: [PATCH 05/64] run wpiformat on datalogtool --- datalogtool/src/main/native/cpp/Exporter.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/datalogtool/src/main/native/cpp/Exporter.cpp b/datalogtool/src/main/native/cpp/Exporter.cpp index b391b8f59f0..39563335925 100644 --- a/datalogtool/src/main/native/cpp/Exporter.cpp +++ b/datalogtool/src/main/native/cpp/Exporter.cpp @@ -20,11 +20,11 @@ #include #include #include -#include #include #include #include #include +#include #include #include #include From cf6f062bd49ed043c4e2795f79d107a9f5d66493 Mon Sep 17 00:00:00 2001 From: DeltaDizzy Date: Tue, 7 Jan 2025 16:33:58 -0600 Subject: [PATCH 06/64] move DataLog classes to wpi::log namespace --- datalogtool/src/main/native/cpp/Exporter.cpp | 8 ++++---- sysid/src/main/native/cpp/view/DataSelector.cpp | 10 +++++----- sysid/src/main/native/cpp/view/LogLoader.cpp | 6 +++--- .../main/native/include/sysid/view/DataSelector.h | 14 ++++++++------ .../src/main/native/include/sysid/view/LogLoader.h | 10 ++++++---- .../src/main/native/cpp/DataLogReaderThread.cpp | 2 +- .../main/native/include/wpi/DataLogReaderThread.h | 2 +- 7 files changed, 28 insertions(+), 24 deletions(-) diff --git a/datalogtool/src/main/native/cpp/Exporter.cpp b/datalogtool/src/main/native/cpp/Exporter.cpp index 39563335925..d0b85d7a92b 100644 --- a/datalogtool/src/main/native/cpp/Exporter.cpp +++ b/datalogtool/src/main/native/cpp/Exporter.cpp @@ -40,7 +40,7 @@ namespace { struct InputFile { - explicit InputFile(std::unique_ptr datalog); + explicit InputFile(std::unique_ptr datalog); InputFile(std::string_view filename, std::string_view status) : filename{filename}, @@ -51,7 +51,7 @@ struct InputFile { std::string filename; std::string stem; - std::unique_ptr datalog; + std::unique_ptr datalog; std::string status; bool highlight = false; }; @@ -140,7 +140,7 @@ static void RebuildEntryTree() { } } -InputFile::InputFile(std::unique_ptr datalog_) +InputFile::InputFile(std::unique_ptr datalog_) : filename{datalog_->GetBufferIdentifier()}, stem{fs::path{filename}.stem().string()}, datalog{std::move(datalog_)} { @@ -196,7 +196,7 @@ static std::unique_ptr LoadDataLog(std::string_view filename) { } return std::make_unique( - std::make_unique(std::move(reader))); + std::make_unique(std::move(reader))); } void DisplayInputFiles() { diff --git a/sysid/src/main/native/cpp/view/DataSelector.cpp b/sysid/src/main/native/cpp/view/DataSelector.cpp index 39eddb8294d..7b59ab2e6a3 100644 --- a/sysid/src/main/native/cpp/view/DataSelector.cpp +++ b/sysid/src/main/native/cpp/view/DataSelector.cpp @@ -25,7 +25,7 @@ using namespace sysid; static constexpr const char* kAnalysisTypes[] = {"Elevator", "Arm", "Simple"}; static bool EmitEntryTarget(const char* name, bool isString, - const wpi::DataLogReaderEntry** entry) { + const wpi::log::DataLogReaderEntry** entry) { if (*entry) { auto text = fmt::format("{}: {} ({})", name, (*entry)->name, (*entry)->type); @@ -38,8 +38,8 @@ static bool EmitEntryTarget(const char* name, bool isString, if (ImGui::BeginDragDropTarget()) { if (const ImGuiPayload* payload = ImGui::AcceptDragDropPayload( isString ? "DataLogEntryString" : "DataLogEntry")) { - assert(payload->DataSize == sizeof(const wpi::DataLogReaderEntry*)); - *entry = *static_cast(payload->Data); + assert(payload->DataSize == sizeof(const wpi::log::DataLogReaderEntry*)); + *entry = *static_cast(payload->Data); rv = true; } ImGui::EndDragDropTarget(); @@ -179,7 +179,7 @@ void DataSelector::Reset() { } DataSelector::Tests DataSelector::LoadTests( - const wpi::DataLogReaderEntry& testStateEntry) { + const wpi::log::DataLogReaderEntry& testStateEntry) { Tests tests; for (auto&& range : testStateEntry.ranges) { std::string_view prevState; @@ -245,7 +245,7 @@ static void AddSamples(std::vector>& samples, } static std::vector> GetData( - const wpi::DataLogReaderEntry& entry, double scale) { + const wpi::log::DataLogReaderEntry& entry, double scale) { std::vector> rv; bool isDouble = entry.type == "double"; for (auto&& range : entry.ranges) { diff --git a/sysid/src/main/native/cpp/view/LogLoader.cpp b/sysid/src/main/native/cpp/view/LogLoader.cpp index 0b2f41a8da0..893ef52f077 100644 --- a/sysid/src/main/native/cpp/view/LogLoader.cpp +++ b/sysid/src/main/native/cpp/view/LogLoader.cpp @@ -54,7 +54,7 @@ void LogLoader::Display() { return; } unload(); - m_reader = std::make_unique(std::move(reader)); + m_reader = std::make_unique(std::move(reader)); m_entryTree.clear(); } m_opener.reset(); @@ -107,7 +107,7 @@ void LogLoader::Display() { void LogLoader::RebuildEntryTree() { m_entryTree.clear(); wpi::SmallVector parts; - m_reader->ForEachEntryName([&](const wpi::DataLogReaderEntry& entry) { + m_reader->ForEachEntryName([&](const wpi::log::DataLogReaderEntry& entry) { // only show double/float/string entries (TODO: support struct/protobuf) if (entry.type != "double" && entry.type != "float" && entry.type != "string") { @@ -166,7 +166,7 @@ void LogLoader::RebuildEntryTree() { } static void EmitEntry(const std::string& name, - const wpi::DataLogReaderEntry& entry) { + const wpi::log::DataLogReaderEntry& entry) { ImGui::TableNextColumn(); ImGui::Selectable(name.c_str()); if (ImGui::BeginDragDropSource()) { diff --git a/sysid/src/main/native/include/sysid/view/DataSelector.h b/sysid/src/main/native/include/sysid/view/DataSelector.h index 9b021f88d71..d11444e2d2c 100644 --- a/sysid/src/main/native/include/sysid/view/DataSelector.h +++ b/sysid/src/main/native/include/sysid/view/DataSelector.h @@ -22,7 +22,9 @@ class Storage; } // namespace glass namespace wpi { -class DataLogReaderEntry; +namespace log{ + class DataLogReaderEntry; +} class Logger; } // namespace wpi @@ -64,10 +66,10 @@ class DataSelector : public glass::View { std::future m_testsFuture; Tests m_tests; std::string m_selectedTest; - const wpi::DataLogReaderEntry* m_testStateEntry = nullptr; - const wpi::DataLogReaderEntry* m_velocityEntry = nullptr; - const wpi::DataLogReaderEntry* m_positionEntry = nullptr; - const wpi::DataLogReaderEntry* m_voltageEntry = nullptr; + const wpi::log::DataLogReaderEntry* m_testStateEntry = nullptr; + const wpi::log::DataLogReaderEntry* m_velocityEntry = nullptr; + const wpi::log::DataLogReaderEntry* m_positionEntry = nullptr; + const wpi::log::DataLogReaderEntry* m_voltageEntry = nullptr; double m_velocityScale = 1.0; double m_positionScale = 1.0; int m_selectedUnit = 0; @@ -75,7 +77,7 @@ class DataSelector : public glass::View { std::future m_testdataFuture; std::vector m_testdataStats; - static Tests LoadTests(const wpi::DataLogReaderEntry& testStateEntry); + static Tests LoadTests(const wpi::log::DataLogReaderEntry& testStateEntry); TestData BuildTestData(); }; } // namespace sysid diff --git a/sysid/src/main/native/include/sysid/view/LogLoader.h b/sysid/src/main/native/include/sysid/view/LogLoader.h index f641a4de10b..56de22671c6 100644 --- a/sysid/src/main/native/include/sysid/view/LogLoader.h +++ b/sysid/src/main/native/include/sysid/view/LogLoader.h @@ -21,8 +21,10 @@ class open_file; } // namespace pfd namespace wpi { -class DataLogReaderEntry; -class DataLogReaderThread; +namespace log { + class DataLogReaderEntry; + class DataLogReaderThread; +} class Logger; } // namespace wpi @@ -57,7 +59,7 @@ class LogLoader : public glass::View { std::string m_filename; std::unique_ptr m_opener; - std::unique_ptr m_reader; + std::unique_ptr m_reader; std::string m_error; @@ -67,7 +69,7 @@ class LogLoader : public glass::View { explicit EntryTreeNode(std::string_view name) : name{name} {} std::string name; // name of just this node std::string path; // full path if entry is nullptr - const wpi::DataLogReaderEntry* entry = nullptr; + const wpi::log::DataLogReaderEntry* entry = nullptr; std::vector children; // children, sorted by name }; std::vector m_entryTree; diff --git a/wpiutil/src/main/native/cpp/DataLogReaderThread.cpp b/wpiutil/src/main/native/cpp/DataLogReaderThread.cpp index ad8bd767dfe..0fccaa22329 100644 --- a/wpiutil/src/main/native/cpp/DataLogReaderThread.cpp +++ b/wpiutil/src/main/native/cpp/DataLogReaderThread.cpp @@ -10,7 +10,7 @@ #include #include -using namespace wpi; +using namespace wpi::log; DataLogReaderThread::~DataLogReaderThread() { if (m_thread.joinable()) { diff --git a/wpiutil/src/main/native/include/wpi/DataLogReaderThread.h b/wpiutil/src/main/native/include/wpi/DataLogReaderThread.h index 168b0049576..ec70619ca6c 100644 --- a/wpiutil/src/main/native/include/wpi/DataLogReaderThread.h +++ b/wpiutil/src/main/native/include/wpi/DataLogReaderThread.h @@ -23,7 +23,7 @@ #include #endif -namespace wpi { +namespace wpi::log { class DataLogReaderRange { public: From 20741743ddcc0e3a6009587cc73e27a01c7b95a9 Mon Sep 17 00:00:00 2001 From: DeltaDizzy Date: Tue, 7 Jan 2025 16:39:18 -0600 Subject: [PATCH 07/64] wpiformat --- sysid/src/main/native/cpp/view/DataSelector.cpp | 3 ++- sysid/src/main/native/cpp/view/LogLoader.cpp | 3 ++- sysid/src/main/native/include/sysid/view/DataSelector.h | 6 +++--- sysid/src/main/native/include/sysid/view/LogLoader.h | 6 +++--- wpiutil/src/main/native/include/wpi/DataLogReaderThread.h | 2 +- 5 files changed, 11 insertions(+), 9 deletions(-) diff --git a/sysid/src/main/native/cpp/view/DataSelector.cpp b/sysid/src/main/native/cpp/view/DataSelector.cpp index 7b59ab2e6a3..7d8d8e572a6 100644 --- a/sysid/src/main/native/cpp/view/DataSelector.cpp +++ b/sysid/src/main/native/cpp/view/DataSelector.cpp @@ -39,7 +39,8 @@ static bool EmitEntryTarget(const char* name, bool isString, if (const ImGuiPayload* payload = ImGui::AcceptDragDropPayload( isString ? "DataLogEntryString" : "DataLogEntry")) { assert(payload->DataSize == sizeof(const wpi::log::DataLogReaderEntry*)); - *entry = *static_cast(payload->Data); + *entry = + *static_cast(payload->Data); rv = true; } ImGui::EndDragDropTarget(); diff --git a/sysid/src/main/native/cpp/view/LogLoader.cpp b/sysid/src/main/native/cpp/view/LogLoader.cpp index 893ef52f077..3289dea28ed 100644 --- a/sysid/src/main/native/cpp/view/LogLoader.cpp +++ b/sysid/src/main/native/cpp/view/LogLoader.cpp @@ -54,7 +54,8 @@ void LogLoader::Display() { return; } unload(); - m_reader = std::make_unique(std::move(reader)); + m_reader = + std::make_unique(std::move(reader)); m_entryTree.clear(); } m_opener.reset(); diff --git a/sysid/src/main/native/include/sysid/view/DataSelector.h b/sysid/src/main/native/include/sysid/view/DataSelector.h index d11444e2d2c..60ba2da5b82 100644 --- a/sysid/src/main/native/include/sysid/view/DataSelector.h +++ b/sysid/src/main/native/include/sysid/view/DataSelector.h @@ -22,9 +22,9 @@ class Storage; } // namespace glass namespace wpi { -namespace log{ - class DataLogReaderEntry; -} +namespace log { +class DataLogReaderEntry; +} // namespace log class Logger; } // namespace wpi diff --git a/sysid/src/main/native/include/sysid/view/LogLoader.h b/sysid/src/main/native/include/sysid/view/LogLoader.h index 56de22671c6..70931bc8cab 100644 --- a/sysid/src/main/native/include/sysid/view/LogLoader.h +++ b/sysid/src/main/native/include/sysid/view/LogLoader.h @@ -22,9 +22,9 @@ class open_file; namespace wpi { namespace log { - class DataLogReaderEntry; - class DataLogReaderThread; -} +class DataLogReaderEntry; +class DataLogReaderThread; +} // namespace log class Logger; } // namespace wpi diff --git a/wpiutil/src/main/native/include/wpi/DataLogReaderThread.h b/wpiutil/src/main/native/include/wpi/DataLogReaderThread.h index ec70619ca6c..aeb737ba24a 100644 --- a/wpiutil/src/main/native/include/wpi/DataLogReaderThread.h +++ b/wpiutil/src/main/native/include/wpi/DataLogReaderThread.h @@ -105,4 +105,4 @@ class DataLogReaderThread { std::thread m_thread; }; -} // namespace wpi +} // namespace wpi::log From 64f562cd2065963ad9af300ad8349d8b10011209 Mon Sep 17 00:00:00 2001 From: DeltaDizzy Date: Wed, 8 Jan 2025 15:25:36 -0600 Subject: [PATCH 08/64] create libdatalog, move datalog from wpiutil --- CMakeLists.txt | 2 ++ libdatalog/CMakeLists.txt | 29 +++++++++++++++++++ .../src/main/native/cpp/DataLog.cpp | 0 .../native/cpp/DataLogBackgroundWriter.cpp | 0 .../src/main/native/cpp/DataLogReader.cpp | 0 .../main/native/cpp/DataLogReaderThread.cpp | 0 .../src/main/native/cpp/DataLogWriter.cpp | 0 .../src/main/native/include/wpi/DataLog.h | 0 .../include/wpi/DataLogBackgroundWriter.h | 0 .../main/native/include/wpi/DataLogReader.h | 0 .../native/include/wpi/DataLogReaderThread.h | 0 .../main/native/include/wpi/DataLogWriter.h | 0 .../src/main/native/include/wpi/DataLog_c.h | 0 13 files changed, 31 insertions(+) create mode 100644 libdatalog/CMakeLists.txt rename {wpiutil => libdatalog}/src/main/native/cpp/DataLog.cpp (100%) rename {wpiutil => libdatalog}/src/main/native/cpp/DataLogBackgroundWriter.cpp (100%) rename {wpiutil => libdatalog}/src/main/native/cpp/DataLogReader.cpp (100%) rename {wpiutil => libdatalog}/src/main/native/cpp/DataLogReaderThread.cpp (100%) rename {wpiutil => libdatalog}/src/main/native/cpp/DataLogWriter.cpp (100%) rename {wpiutil => libdatalog}/src/main/native/include/wpi/DataLog.h (100%) rename {wpiutil => libdatalog}/src/main/native/include/wpi/DataLogBackgroundWriter.h (100%) rename {wpiutil => libdatalog}/src/main/native/include/wpi/DataLogReader.h (100%) rename {wpiutil => libdatalog}/src/main/native/include/wpi/DataLogReaderThread.h (100%) rename {wpiutil => libdatalog}/src/main/native/include/wpi/DataLogWriter.h (100%) rename {wpiutil => libdatalog}/src/main/native/include/wpi/DataLog_c.h (100%) diff --git a/CMakeLists.txt b/CMakeLists.txt index df1e06e890f..860167b2ed3 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -291,6 +291,8 @@ set(WPIUNITS_DEP_REPLACE_IMPL "find_dependency(wpiunits)") set(WPIUTIL_DEP_REPLACE "find_dependency(wpiutil)") add_subdirectory(wpiutil) +add_subdirectory(libdatalog) + if(WITH_NTCORE) set(NTCORE_DEP_REPLACE "find_dependency(ntcore)") set(WPINET_DEP_REPLACE "find_dependency(wpinet)") diff --git a/libdatalog/CMakeLists.txt b/libdatalog/CMakeLists.txt new file mode 100644 index 00000000000..3869c1861c0 --- /dev/null +++ b/libdatalog/CMakeLists.txt @@ -0,0 +1,29 @@ +project(libdatalog) + +include(CompileWarnings) + +file( + GLOB libdatalog_src + src/main/native/cpp/*.cpp +) + +add_library(libdatalog ${libdatalog_src}) +set_target_properties(wpiutil PROPERTIES DEBUG_POSTFIX "d") + +target_compile_features(libdatalog PUBLIC cxx_std_20) +if(MSVC) + target_compile_options( + libdatalog + PUBLIC /permissive- /Zc:preprocessor /Zc:__cplusplus /Zc:throwingNew /MP /bigobj /utf-8 + ) + target_compile_definitions(libdatalog PRIVATE -D_CRT_SECURE_NO_WARNINGS) +endif() +wpilib_target_warnings(libdatalog) + +target_include_directories( + libdatalog + PUBLIC + $ +) + +target_link_libraries(libdatalog PRIVATE wpiutil) diff --git a/wpiutil/src/main/native/cpp/DataLog.cpp b/libdatalog/src/main/native/cpp/DataLog.cpp similarity index 100% rename from wpiutil/src/main/native/cpp/DataLog.cpp rename to libdatalog/src/main/native/cpp/DataLog.cpp diff --git a/wpiutil/src/main/native/cpp/DataLogBackgroundWriter.cpp b/libdatalog/src/main/native/cpp/DataLogBackgroundWriter.cpp similarity index 100% rename from wpiutil/src/main/native/cpp/DataLogBackgroundWriter.cpp rename to libdatalog/src/main/native/cpp/DataLogBackgroundWriter.cpp diff --git a/wpiutil/src/main/native/cpp/DataLogReader.cpp b/libdatalog/src/main/native/cpp/DataLogReader.cpp similarity index 100% rename from wpiutil/src/main/native/cpp/DataLogReader.cpp rename to libdatalog/src/main/native/cpp/DataLogReader.cpp diff --git a/wpiutil/src/main/native/cpp/DataLogReaderThread.cpp b/libdatalog/src/main/native/cpp/DataLogReaderThread.cpp similarity index 100% rename from wpiutil/src/main/native/cpp/DataLogReaderThread.cpp rename to libdatalog/src/main/native/cpp/DataLogReaderThread.cpp diff --git a/wpiutil/src/main/native/cpp/DataLogWriter.cpp b/libdatalog/src/main/native/cpp/DataLogWriter.cpp similarity index 100% rename from wpiutil/src/main/native/cpp/DataLogWriter.cpp rename to libdatalog/src/main/native/cpp/DataLogWriter.cpp diff --git a/wpiutil/src/main/native/include/wpi/DataLog.h b/libdatalog/src/main/native/include/wpi/DataLog.h similarity index 100% rename from wpiutil/src/main/native/include/wpi/DataLog.h rename to libdatalog/src/main/native/include/wpi/DataLog.h diff --git a/wpiutil/src/main/native/include/wpi/DataLogBackgroundWriter.h b/libdatalog/src/main/native/include/wpi/DataLogBackgroundWriter.h similarity index 100% rename from wpiutil/src/main/native/include/wpi/DataLogBackgroundWriter.h rename to libdatalog/src/main/native/include/wpi/DataLogBackgroundWriter.h diff --git a/wpiutil/src/main/native/include/wpi/DataLogReader.h b/libdatalog/src/main/native/include/wpi/DataLogReader.h similarity index 100% rename from wpiutil/src/main/native/include/wpi/DataLogReader.h rename to libdatalog/src/main/native/include/wpi/DataLogReader.h diff --git a/wpiutil/src/main/native/include/wpi/DataLogReaderThread.h b/libdatalog/src/main/native/include/wpi/DataLogReaderThread.h similarity index 100% rename from wpiutil/src/main/native/include/wpi/DataLogReaderThread.h rename to libdatalog/src/main/native/include/wpi/DataLogReaderThread.h diff --git a/wpiutil/src/main/native/include/wpi/DataLogWriter.h b/libdatalog/src/main/native/include/wpi/DataLogWriter.h similarity index 100% rename from wpiutil/src/main/native/include/wpi/DataLogWriter.h rename to libdatalog/src/main/native/include/wpi/DataLogWriter.h diff --git a/wpiutil/src/main/native/include/wpi/DataLog_c.h b/libdatalog/src/main/native/include/wpi/DataLog_c.h similarity index 100% rename from wpiutil/src/main/native/include/wpi/DataLog_c.h rename to libdatalog/src/main/native/include/wpi/DataLog_c.h From a7117a7571da3b5c8aae8e6e60e7ab50aa85b7d7 Mon Sep 17 00:00:00 2001 From: DeltaDizzy Date: Wed, 8 Jan 2025 18:50:23 -0600 Subject: [PATCH 09/64] 1st try at bazel --- libdatalog/BUILD.bazel | 10 ++++++++++ 1 file changed, 10 insertions(+) create mode 100644 libdatalog/BUILD.bazel diff --git a/libdatalog/BUILD.bazel b/libdatalog/BUILD.bazel new file mode 100644 index 00000000000..c5ee0d9f74a --- /dev/null +++ b/libdatalog/BUILD.bazel @@ -0,0 +1,10 @@ +load("@rules_cc//cc:defs.bzl", "cc_library") +load("//shared/bazel/rules/gen:gen-resources.bzl", "generate_resources") + +cc_library( + name = "libdatalog", + hdrs = glob(["src/main/native/include/**"]), + includes = ["src/main/native/include"] + strip_include_prefix = "src/main/native/include" + visibility = ["//libdatalog:__subpackages__"] +) \ No newline at end of file From 8a3a17f11de5b80f1b757bb795e148d9bf324087 Mon Sep 17 00:00:00 2001 From: DeltaDizzy Date: Wed, 8 Jan 2025 18:56:32 -0600 Subject: [PATCH 10/64] include deps and sources for bazel --- libdatalog/BUILD.bazel | 19 ++++++++++++++----- 1 file changed, 14 insertions(+), 5 deletions(-) diff --git a/libdatalog/BUILD.bazel b/libdatalog/BUILD.bazel index c5ee0d9f74a..0c987c8f982 100644 --- a/libdatalog/BUILD.bazel +++ b/libdatalog/BUILD.bazel @@ -2,9 +2,18 @@ load("@rules_cc//cc:defs.bzl", "cc_library") load("//shared/bazel/rules/gen:gen-resources.bzl", "generate_resources") cc_library( - name = "libdatalog", - hdrs = glob(["src/main/native/include/**"]), - includes = ["src/main/native/include"] - strip_include_prefix = "src/main/native/include" - visibility = ["//libdatalog:__subpackages__"] + name = "libdatalog.static", + srcs = glob( + ["src/main/native/cpp/**"], + ), + hdrs = glob(["src/main/native/include/*"]), + includes = [ + "src/main/native/cpp", + "src/main/native/include", + ], + strip_include_prefix = "src/main/native/include", + visibility = ["//visibility:public"], + deps = [ + "//wpiutil:wpiutil.static", + ] ) \ No newline at end of file From 0bf51606bde70bed3d8005aadc4dd81d1e742dd3 Mon Sep 17 00:00:00 2001 From: DeltaDizzy Date: Wed, 8 Jan 2025 19:28:56 -0600 Subject: [PATCH 11/64] move datalog examples to libdatalog --- {wpiutil => libdatalog}/examples/printlog/datalog.py | 0 {wpiutil => libdatalog}/examples/printlog/printlog.cpp | 0 {wpiutil => libdatalog}/examples/writelog/writelog.cpp | 0 3 files changed, 0 insertions(+), 0 deletions(-) rename {wpiutil => libdatalog}/examples/printlog/datalog.py (100%) rename {wpiutil => libdatalog}/examples/printlog/printlog.cpp (100%) rename {wpiutil => libdatalog}/examples/writelog/writelog.cpp (100%) diff --git a/wpiutil/examples/printlog/datalog.py b/libdatalog/examples/printlog/datalog.py similarity index 100% rename from wpiutil/examples/printlog/datalog.py rename to libdatalog/examples/printlog/datalog.py diff --git a/wpiutil/examples/printlog/printlog.cpp b/libdatalog/examples/printlog/printlog.cpp similarity index 100% rename from wpiutil/examples/printlog/printlog.cpp rename to libdatalog/examples/printlog/printlog.cpp diff --git a/wpiutil/examples/writelog/writelog.cpp b/libdatalog/examples/writelog/writelog.cpp similarity index 100% rename from wpiutil/examples/writelog/writelog.cpp rename to libdatalog/examples/writelog/writelog.cpp From e130736db0d8ed443ff0b6ff46587e0756e73cbd Mon Sep 17 00:00:00 2001 From: DeltaDizzy Date: Thu, 9 Jan 2025 11:08:57 -0600 Subject: [PATCH 12/64] add datalog examples and jni --- libdatalog/CMakeLists.txt | 33 ++++++++++++++++++++++++++++++++- 1 file changed, 32 insertions(+), 1 deletion(-) diff --git a/libdatalog/CMakeLists.txt b/libdatalog/CMakeLists.txt index 3869c1861c0..ca80ccf1295 100644 --- a/libdatalog/CMakeLists.txt +++ b/libdatalog/CMakeLists.txt @@ -7,8 +7,13 @@ file( src/main/native/cpp/*.cpp ) +file( + GLOB libdatalog_jni_src + src/main/native/cpp/jni/DataLogJNI.cpp +) + add_library(libdatalog ${libdatalog_src}) -set_target_properties(wpiutil PROPERTIES DEBUG_POSTFIX "d") +set_target_properties(libdatalog PROPERTIES DEBUG_POSTFIX "d") target_compile_features(libdatalog PUBLIC cxx_std_20) if(MSVC) @@ -27,3 +32,29 @@ target_include_directories( ) target_link_libraries(libdatalog PRIVATE wpiutil) + +subdir_list(libdatalog_examples "${CMAKE_CURRENT_SOURCE_DIR}/examples") +foreach(example ${libdatalog_examples}) + file(GLOB libdatalog_example_src examples/${example}/*.cpp) + if(libdatalog_example_src) + add_executable(libdatalog_${example} ${libdatalog_example_src}) + wpilib_target_warnings(libdatalog_${example}) + target_link_libraries(libdatalog_${example} libdatalog) + set_property(TARGET libdatalog_${example} PROPERTY FOLDER "examples") + endif() +endforeach() + +add_library(libdatalogjni ${libdatalog_jni_src}) +wpilib_target_warnings(libdatalogjni) +target_link_libraries(libdatalogjni PUBLIC libdatalog) + +# if(WITH_TESTS) +# file(GLOB_RECURSE libdatalog_test_src src/test/native/cpp/*.cpp) +# target_sources(libdatalog_test PRIVATE ${libdatalog_test_src}) +# wpilib_add_test(libdatalog src/test/native/cpp) +# target_link_libraries(libdatalog_test libdatalog googletest libdatalog_testlib) +# if(MSVC) +# target_compile_options(libdatalog_test PRIVATE /utf-8) +# endif() +# endif() + From 4d934c3563b95416440177c3adcdd8437b80371a Mon Sep 17 00:00:00 2001 From: DeltaDizzy Date: Thu, 9 Jan 2025 11:10:16 -0600 Subject: [PATCH 13/64] move java datalog lib --- .../java/edu/wpi/first}/datalog/BooleanArrayLogEntry.java | 0 .../src/main/java/edu/wpi/first}/datalog/BooleanLogEntry.java | 0 .../src/main/java/edu/wpi/first}/datalog/DataLog.java | 0 .../java/edu/wpi/first}/datalog/DataLogBackgroundWriter.java | 0 .../src/main/java/edu/wpi/first}/datalog/DataLogEntry.java | 0 .../src/main/java/edu/wpi/first}/datalog/DataLogIterator.java | 0 .../src/main/java/edu/wpi/first}/datalog/DataLogJNI.java | 0 .../src/main/java/edu/wpi/first}/datalog/DataLogReader.java | 0 .../src/main/java/edu/wpi/first}/datalog/DataLogRecord.java | 0 .../src/main/java/edu/wpi/first}/datalog/DataLogWriter.java | 0 .../main/java/edu/wpi/first}/datalog/DoubleArrayLogEntry.java | 0 .../src/main/java/edu/wpi/first}/datalog/DoubleLogEntry.java | 0 .../src/main/java/edu/wpi/first/datalog}/FileLogger.java | 4 ++-- .../main/java/edu/wpi/first}/datalog/FloatArrayLogEntry.java | 0 .../src/main/java/edu/wpi/first}/datalog/FloatLogEntry.java | 0 .../java/edu/wpi/first}/datalog/IntegerArrayLogEntry.java | 0 .../src/main/java/edu/wpi/first}/datalog/IntegerLogEntry.java | 0 .../main/java/edu/wpi/first}/datalog/ProtobufLogEntry.java | 0 .../src/main/java/edu/wpi/first}/datalog/RawLogEntry.java | 0 .../main/java/edu/wpi/first}/datalog/StringArrayLogEntry.java | 0 .../src/main/java/edu/wpi/first}/datalog/StringLogEntry.java | 0 .../main/java/edu/wpi/first}/datalog/StructArrayLogEntry.java | 0 .../src/main/java/edu/wpi/first}/datalog/StructLogEntry.java | 0 .../src/printlog/java/printlog/PrintLog.java | 0 24 files changed, 2 insertions(+), 2 deletions(-) rename {wpiutil/src/main/java/edu/wpi/first/util => libdatalog/src/main/java/edu/wpi/first}/datalog/BooleanArrayLogEntry.java (100%) rename {wpiutil/src/main/java/edu/wpi/first/util => libdatalog/src/main/java/edu/wpi/first}/datalog/BooleanLogEntry.java (100%) rename {wpiutil/src/main/java/edu/wpi/first/util => libdatalog/src/main/java/edu/wpi/first}/datalog/DataLog.java (100%) rename {wpiutil/src/main/java/edu/wpi/first/util => libdatalog/src/main/java/edu/wpi/first}/datalog/DataLogBackgroundWriter.java (100%) rename {wpiutil/src/main/java/edu/wpi/first/util => libdatalog/src/main/java/edu/wpi/first}/datalog/DataLogEntry.java (100%) rename {wpiutil/src/main/java/edu/wpi/first/util => libdatalog/src/main/java/edu/wpi/first}/datalog/DataLogIterator.java (100%) rename {wpiutil/src/main/java/edu/wpi/first/util => libdatalog/src/main/java/edu/wpi/first}/datalog/DataLogJNI.java (100%) rename {wpiutil/src/main/java/edu/wpi/first/util => libdatalog/src/main/java/edu/wpi/first}/datalog/DataLogReader.java (100%) rename {wpiutil/src/main/java/edu/wpi/first/util => libdatalog/src/main/java/edu/wpi/first}/datalog/DataLogRecord.java (100%) rename {wpiutil/src/main/java/edu/wpi/first/util => libdatalog/src/main/java/edu/wpi/first}/datalog/DataLogWriter.java (100%) rename {wpiutil/src/main/java/edu/wpi/first/util => libdatalog/src/main/java/edu/wpi/first}/datalog/DoubleArrayLogEntry.java (100%) rename {wpiutil/src/main/java/edu/wpi/first/util => libdatalog/src/main/java/edu/wpi/first}/datalog/DoubleLogEntry.java (100%) rename {wpiutil/src/main/java/edu/wpi/first/util => libdatalog/src/main/java/edu/wpi/first/datalog}/FileLogger.java (92%) rename {wpiutil/src/main/java/edu/wpi/first/util => libdatalog/src/main/java/edu/wpi/first}/datalog/FloatArrayLogEntry.java (100%) rename {wpiutil/src/main/java/edu/wpi/first/util => libdatalog/src/main/java/edu/wpi/first}/datalog/FloatLogEntry.java (100%) rename {wpiutil/src/main/java/edu/wpi/first/util => libdatalog/src/main/java/edu/wpi/first}/datalog/IntegerArrayLogEntry.java (100%) rename {wpiutil/src/main/java/edu/wpi/first/util => libdatalog/src/main/java/edu/wpi/first}/datalog/IntegerLogEntry.java (100%) rename {wpiutil/src/main/java/edu/wpi/first/util => libdatalog/src/main/java/edu/wpi/first}/datalog/ProtobufLogEntry.java (100%) rename {wpiutil/src/main/java/edu/wpi/first/util => libdatalog/src/main/java/edu/wpi/first}/datalog/RawLogEntry.java (100%) rename {wpiutil/src/main/java/edu/wpi/first/util => libdatalog/src/main/java/edu/wpi/first}/datalog/StringArrayLogEntry.java (100%) rename {wpiutil/src/main/java/edu/wpi/first/util => libdatalog/src/main/java/edu/wpi/first}/datalog/StringLogEntry.java (100%) rename {wpiutil/src/main/java/edu/wpi/first/util => libdatalog/src/main/java/edu/wpi/first}/datalog/StructArrayLogEntry.java (100%) rename {wpiutil/src/main/java/edu/wpi/first/util => libdatalog/src/main/java/edu/wpi/first}/datalog/StructLogEntry.java (100%) rename {wpiutil => libdatalog}/src/printlog/java/printlog/PrintLog.java (100%) diff --git a/wpiutil/src/main/java/edu/wpi/first/util/datalog/BooleanArrayLogEntry.java b/libdatalog/src/main/java/edu/wpi/first/datalog/BooleanArrayLogEntry.java similarity index 100% rename from wpiutil/src/main/java/edu/wpi/first/util/datalog/BooleanArrayLogEntry.java rename to libdatalog/src/main/java/edu/wpi/first/datalog/BooleanArrayLogEntry.java diff --git a/wpiutil/src/main/java/edu/wpi/first/util/datalog/BooleanLogEntry.java b/libdatalog/src/main/java/edu/wpi/first/datalog/BooleanLogEntry.java similarity index 100% rename from wpiutil/src/main/java/edu/wpi/first/util/datalog/BooleanLogEntry.java rename to libdatalog/src/main/java/edu/wpi/first/datalog/BooleanLogEntry.java diff --git a/wpiutil/src/main/java/edu/wpi/first/util/datalog/DataLog.java b/libdatalog/src/main/java/edu/wpi/first/datalog/DataLog.java similarity index 100% rename from wpiutil/src/main/java/edu/wpi/first/util/datalog/DataLog.java rename to libdatalog/src/main/java/edu/wpi/first/datalog/DataLog.java diff --git a/wpiutil/src/main/java/edu/wpi/first/util/datalog/DataLogBackgroundWriter.java b/libdatalog/src/main/java/edu/wpi/first/datalog/DataLogBackgroundWriter.java similarity index 100% rename from wpiutil/src/main/java/edu/wpi/first/util/datalog/DataLogBackgroundWriter.java rename to libdatalog/src/main/java/edu/wpi/first/datalog/DataLogBackgroundWriter.java diff --git a/wpiutil/src/main/java/edu/wpi/first/util/datalog/DataLogEntry.java b/libdatalog/src/main/java/edu/wpi/first/datalog/DataLogEntry.java similarity index 100% rename from wpiutil/src/main/java/edu/wpi/first/util/datalog/DataLogEntry.java rename to libdatalog/src/main/java/edu/wpi/first/datalog/DataLogEntry.java diff --git a/wpiutil/src/main/java/edu/wpi/first/util/datalog/DataLogIterator.java b/libdatalog/src/main/java/edu/wpi/first/datalog/DataLogIterator.java similarity index 100% rename from wpiutil/src/main/java/edu/wpi/first/util/datalog/DataLogIterator.java rename to libdatalog/src/main/java/edu/wpi/first/datalog/DataLogIterator.java diff --git a/wpiutil/src/main/java/edu/wpi/first/util/datalog/DataLogJNI.java b/libdatalog/src/main/java/edu/wpi/first/datalog/DataLogJNI.java similarity index 100% rename from wpiutil/src/main/java/edu/wpi/first/util/datalog/DataLogJNI.java rename to libdatalog/src/main/java/edu/wpi/first/datalog/DataLogJNI.java diff --git a/wpiutil/src/main/java/edu/wpi/first/util/datalog/DataLogReader.java b/libdatalog/src/main/java/edu/wpi/first/datalog/DataLogReader.java similarity index 100% rename from wpiutil/src/main/java/edu/wpi/first/util/datalog/DataLogReader.java rename to libdatalog/src/main/java/edu/wpi/first/datalog/DataLogReader.java diff --git a/wpiutil/src/main/java/edu/wpi/first/util/datalog/DataLogRecord.java b/libdatalog/src/main/java/edu/wpi/first/datalog/DataLogRecord.java similarity index 100% rename from wpiutil/src/main/java/edu/wpi/first/util/datalog/DataLogRecord.java rename to libdatalog/src/main/java/edu/wpi/first/datalog/DataLogRecord.java diff --git a/wpiutil/src/main/java/edu/wpi/first/util/datalog/DataLogWriter.java b/libdatalog/src/main/java/edu/wpi/first/datalog/DataLogWriter.java similarity index 100% rename from wpiutil/src/main/java/edu/wpi/first/util/datalog/DataLogWriter.java rename to libdatalog/src/main/java/edu/wpi/first/datalog/DataLogWriter.java diff --git a/wpiutil/src/main/java/edu/wpi/first/util/datalog/DoubleArrayLogEntry.java b/libdatalog/src/main/java/edu/wpi/first/datalog/DoubleArrayLogEntry.java similarity index 100% rename from wpiutil/src/main/java/edu/wpi/first/util/datalog/DoubleArrayLogEntry.java rename to libdatalog/src/main/java/edu/wpi/first/datalog/DoubleArrayLogEntry.java diff --git a/wpiutil/src/main/java/edu/wpi/first/util/datalog/DoubleLogEntry.java b/libdatalog/src/main/java/edu/wpi/first/datalog/DoubleLogEntry.java similarity index 100% rename from wpiutil/src/main/java/edu/wpi/first/util/datalog/DoubleLogEntry.java rename to libdatalog/src/main/java/edu/wpi/first/datalog/DoubleLogEntry.java diff --git a/wpiutil/src/main/java/edu/wpi/first/util/FileLogger.java b/libdatalog/src/main/java/edu/wpi/first/datalog/FileLogger.java similarity index 92% rename from wpiutil/src/main/java/edu/wpi/first/util/FileLogger.java rename to libdatalog/src/main/java/edu/wpi/first/datalog/FileLogger.java index 438861b53ee..5fff3fc5f23 100644 --- a/wpiutil/src/main/java/edu/wpi/first/util/FileLogger.java +++ b/libdatalog/src/main/java/edu/wpi/first/datalog/FileLogger.java @@ -2,9 +2,9 @@ // Open Source Software; you can modify and/or share it under the terms of // the WPILib BSD license file in the root directory of this project. -package edu.wpi.first.util; +package edu.wpi.first.datalog; -import edu.wpi.first.util.datalog.DataLog; +import edu.wpi.first.datalog.DataLog; /** * A class version of `tail -f`, otherwise known as `tail -f` at home. Watches a file and puts the diff --git a/wpiutil/src/main/java/edu/wpi/first/util/datalog/FloatArrayLogEntry.java b/libdatalog/src/main/java/edu/wpi/first/datalog/FloatArrayLogEntry.java similarity index 100% rename from wpiutil/src/main/java/edu/wpi/first/util/datalog/FloatArrayLogEntry.java rename to libdatalog/src/main/java/edu/wpi/first/datalog/FloatArrayLogEntry.java diff --git a/wpiutil/src/main/java/edu/wpi/first/util/datalog/FloatLogEntry.java b/libdatalog/src/main/java/edu/wpi/first/datalog/FloatLogEntry.java similarity index 100% rename from wpiutil/src/main/java/edu/wpi/first/util/datalog/FloatLogEntry.java rename to libdatalog/src/main/java/edu/wpi/first/datalog/FloatLogEntry.java diff --git a/wpiutil/src/main/java/edu/wpi/first/util/datalog/IntegerArrayLogEntry.java b/libdatalog/src/main/java/edu/wpi/first/datalog/IntegerArrayLogEntry.java similarity index 100% rename from wpiutil/src/main/java/edu/wpi/first/util/datalog/IntegerArrayLogEntry.java rename to libdatalog/src/main/java/edu/wpi/first/datalog/IntegerArrayLogEntry.java diff --git a/wpiutil/src/main/java/edu/wpi/first/util/datalog/IntegerLogEntry.java b/libdatalog/src/main/java/edu/wpi/first/datalog/IntegerLogEntry.java similarity index 100% rename from wpiutil/src/main/java/edu/wpi/first/util/datalog/IntegerLogEntry.java rename to libdatalog/src/main/java/edu/wpi/first/datalog/IntegerLogEntry.java diff --git a/wpiutil/src/main/java/edu/wpi/first/util/datalog/ProtobufLogEntry.java b/libdatalog/src/main/java/edu/wpi/first/datalog/ProtobufLogEntry.java similarity index 100% rename from wpiutil/src/main/java/edu/wpi/first/util/datalog/ProtobufLogEntry.java rename to libdatalog/src/main/java/edu/wpi/first/datalog/ProtobufLogEntry.java diff --git a/wpiutil/src/main/java/edu/wpi/first/util/datalog/RawLogEntry.java b/libdatalog/src/main/java/edu/wpi/first/datalog/RawLogEntry.java similarity index 100% rename from wpiutil/src/main/java/edu/wpi/first/util/datalog/RawLogEntry.java rename to libdatalog/src/main/java/edu/wpi/first/datalog/RawLogEntry.java diff --git a/wpiutil/src/main/java/edu/wpi/first/util/datalog/StringArrayLogEntry.java b/libdatalog/src/main/java/edu/wpi/first/datalog/StringArrayLogEntry.java similarity index 100% rename from wpiutil/src/main/java/edu/wpi/first/util/datalog/StringArrayLogEntry.java rename to libdatalog/src/main/java/edu/wpi/first/datalog/StringArrayLogEntry.java diff --git a/wpiutil/src/main/java/edu/wpi/first/util/datalog/StringLogEntry.java b/libdatalog/src/main/java/edu/wpi/first/datalog/StringLogEntry.java similarity index 100% rename from wpiutil/src/main/java/edu/wpi/first/util/datalog/StringLogEntry.java rename to libdatalog/src/main/java/edu/wpi/first/datalog/StringLogEntry.java diff --git a/wpiutil/src/main/java/edu/wpi/first/util/datalog/StructArrayLogEntry.java b/libdatalog/src/main/java/edu/wpi/first/datalog/StructArrayLogEntry.java similarity index 100% rename from wpiutil/src/main/java/edu/wpi/first/util/datalog/StructArrayLogEntry.java rename to libdatalog/src/main/java/edu/wpi/first/datalog/StructArrayLogEntry.java diff --git a/wpiutil/src/main/java/edu/wpi/first/util/datalog/StructLogEntry.java b/libdatalog/src/main/java/edu/wpi/first/datalog/StructLogEntry.java similarity index 100% rename from wpiutil/src/main/java/edu/wpi/first/util/datalog/StructLogEntry.java rename to libdatalog/src/main/java/edu/wpi/first/datalog/StructLogEntry.java diff --git a/wpiutil/src/printlog/java/printlog/PrintLog.java b/libdatalog/src/printlog/java/printlog/PrintLog.java similarity index 100% rename from wpiutil/src/printlog/java/printlog/PrintLog.java rename to libdatalog/src/printlog/java/printlog/PrintLog.java From 7c8d1bb24337646b73f8698cceef2abefb6d3746 Mon Sep 17 00:00:00 2001 From: DeltaDizzy Date: Thu, 9 Jan 2025 11:11:16 -0600 Subject: [PATCH 14/64] mvoe filelogger (cpp) and cpp jni --- .../src/main/native/cpp/FileLogger.cpp | 0 .../src/main/native/cpp/jni/DataLogJNI.cpp | 615 ++++++++++++++++ .../src/main/native/include/wpi/FileLogger.h | 0 .../src/main/test/native/cpp/DataLogTest.cpp | 675 ++++++++++++++++++ wpiutil/CMakeLists.txt | 3 +- .../src/main/native/cpp/jni/DataLogJNI.cpp | 614 ---------------- .../src/main/native/cpp/jni/WPIUtilJNI.cpp | 1 - wpiutil/src/test/native/cpp/DataLogTest.cpp | 674 ----------------- 8 files changed, 1291 insertions(+), 1291 deletions(-) rename {wpiutil => libdatalog}/src/main/native/cpp/FileLogger.cpp (100%) create mode 100644 libdatalog/src/main/native/cpp/jni/DataLogJNI.cpp rename {wpiutil => libdatalog}/src/main/native/include/wpi/FileLogger.h (100%) create mode 100644 libdatalog/src/main/test/native/cpp/DataLogTest.cpp delete mode 100644 wpiutil/src/main/native/cpp/jni/DataLogJNI.cpp delete mode 100644 wpiutil/src/test/native/cpp/DataLogTest.cpp diff --git a/wpiutil/src/main/native/cpp/FileLogger.cpp b/libdatalog/src/main/native/cpp/FileLogger.cpp similarity index 100% rename from wpiutil/src/main/native/cpp/FileLogger.cpp rename to libdatalog/src/main/native/cpp/FileLogger.cpp diff --git a/libdatalog/src/main/native/cpp/jni/DataLogJNI.cpp b/libdatalog/src/main/native/cpp/jni/DataLogJNI.cpp new file mode 100644 index 00000000000..dd1b574120c --- /dev/null +++ b/libdatalog/src/main/native/cpp/jni/DataLogJNI.cpp @@ -0,0 +1,615 @@ +// // Copyright (c) FIRST and other WPILib contributors. +// // Open Source Software; you can modify and/or share it under the terms of +// // the WPILib BSD license file in the root directory of this project. + +// #include + +// #include +// #include +// #include + +// #include + +// #include "WPIUtilJNI.h" +// #include "edu_wpi_first_util_datalog_DataLogJNI.h" +// #include "wpi/DataLog.h" +// #include "wpi/DataLogBackgroundWriter.h" +// #include "wpi/DataLogWriter.h" +// #include "wpi/jni_util.h" + +// using namespace wpi::java; +// using namespace wpi::log; + +// namespace { +// class buf_ostream : public wpi::raw_uvector_ostream { +// private: +// std::vector data; + +// public: +// buf_ostream() : raw_uvector_ostream{data} {} + +// void clear() { data.clear(); } +// }; +// } // namespace + +// extern "C" { + +// /* +// * Class: edu_wpi_first_util_datalog_DataLogJNI +// * Method: bgCreate +// * Signature: (Ljava/lang/String;Ljava/lang/String;DLjava/lang/String;)J +// */ +// JNIEXPORT jlong JNICALL +// Java_edu_wpi_first_util_datalog_DataLogJNI_bgCreate +// (JNIEnv* env, jclass, jstring dir, jstring filename, jdouble period, +// jstring extraHeader) +// { +// if (!dir) { +// wpi::ThrowNullPointerException(env, "dir is null"); +// return 0; +// } +// if (!filename) { +// wpi::ThrowNullPointerException(env, "filename is null"); +// return 0; +// } +// if (!extraHeader) { +// wpi::ThrowNullPointerException(env, "extraHeader is null"); +// return 0; +// } +// return reinterpret_cast(new DataLogBackgroundWriter{ +// JStringRef{env, dir}, JStringRef{env, filename}, period, +// JStringRef{env, extraHeader}}); +// } + +// /* +// * Class: edu_wpi_first_util_datalog_DataLogJNI +// * Method: bgSetFilename +// * Signature: (JLjava/lang/String;)V +// */ +// JNIEXPORT void JNICALL +// Java_edu_wpi_first_util_datalog_DataLogJNI_bgSetFilename +// (JNIEnv* env, jclass, jlong impl, jstring filename) +// { +// if (impl == 0) { +// wpi::ThrowNullPointerException(env, "impl is null"); +// return; +// } +// if (!filename) { +// wpi::ThrowNullPointerException(env, "filename is null"); +// return; +// } +// reinterpret_cast(impl)->SetFilename( +// JStringRef{env, filename}); +// } + +// /* +// * Class: edu_wpi_first_util_datalog_DataLogJNI +// * Method: fgCreate +// * Signature: (Ljava/lang/String;Ljava/lang/String;)J +// */ +// JNIEXPORT jlong JNICALL +// Java_edu_wpi_first_util_datalog_DataLogJNI_fgCreate +// (JNIEnv* env, jclass, jstring filename, jstring extraHeader) +// { +// if (!filename) { +// wpi::ThrowNullPointerException(env, "filename is null"); +// return 0; +// } +// if (!extraHeader) { +// wpi::ThrowNullPointerException(env, "extraHeader is null"); +// return 0; +// } +// std::error_code ec; +// auto writer = new DataLogWriter{JStringRef{env, filename}, ec, +// JStringRef{env, extraHeader}}; +// if (ec) { +// wpi::ThrowIOException(env, ec.message()); +// delete writer; +// return 0; +// } +// return reinterpret_cast(writer); +// } + +// /* +// * Class: edu_wpi_first_util_datalog_DataLogJNI +// * Method: fgCreateMemory +// * Signature: (Ljava/lang/String;)J +// */ +// JNIEXPORT jlong JNICALL +// Java_edu_wpi_first_util_datalog_DataLogJNI_fgCreateMemory +// (JNIEnv* env, jclass, jstring extraHeader) +// { +// if (!extraHeader) { +// wpi::ThrowNullPointerException(env, "extraHeader is null"); +// return 0; +// } +// auto writer = new DataLogWriter{std::make_unique(), +// JStringRef{env, extraHeader}}; +// return reinterpret_cast(writer); +// } + +// /* +// * Class: edu_wpi_first_util_datalog_DataLogJNI +// * Method: flush +// * Signature: (J)V +// */ +// JNIEXPORT void JNICALL +// Java_edu_wpi_first_util_datalog_DataLogJNI_flush +// (JNIEnv* env, jclass, jlong impl) +// { +// if (impl == 0) { +// wpi::ThrowNullPointerException(env, "impl is null"); +// return; +// } +// reinterpret_cast(impl)->Flush(); +// } + +// /* +// * Class: edu_wpi_first_util_datalog_DataLogJNI +// * Method: copyWriteBuffer +// * Signature: (J[BI)I +// */ +// JNIEXPORT jint JNICALL +// Java_edu_wpi_first_util_datalog_DataLogJNI_copyWriteBuffer +// (JNIEnv* env, jclass, jlong impl, jbyteArray buf, jint start) +// { +// if (impl == 0) { +// wpi::ThrowNullPointerException(env, "impl is null"); +// return 0; +// } +// auto writer = reinterpret_cast(impl); +// writer->Flush(); +// auto& stream = static_cast(writer->GetStream()); +// JSpan jbuf{env, buf}; +// auto arr = stream.array(); +// if (start < 0 || static_cast(start) >= arr.size()) { +// stream.clear(); +// return 0; +// } +// size_t qty = (std::min)(jbuf.size(), arr.size() - start); +// std::copy(arr.begin(), arr.begin() + qty, jbuf.begin()); +// return qty; +// } + +// /* +// * Class: edu_wpi_first_util_datalog_DataLogJNI +// * Method: pause +// * Signature: (J)V +// */ +// JNIEXPORT void JNICALL +// Java_edu_wpi_first_util_datalog_DataLogJNI_pause +// (JNIEnv* env, jclass, jlong impl) +// { +// if (impl == 0) { +// wpi::ThrowNullPointerException(env, "impl is null"); +// return; +// } +// reinterpret_cast(impl)->Pause(); +// } + +// /* +// * Class: edu_wpi_first_util_datalog_DataLogJNI +// * Method: resume +// * Signature: (J)V +// */ +// JNIEXPORT void JNICALL +// Java_edu_wpi_first_util_datalog_DataLogJNI_resume +// (JNIEnv* env, jclass, jlong impl) +// { +// if (impl == 0) { +// wpi::ThrowNullPointerException(env, "impl is null"); +// return; +// } +// reinterpret_cast(impl)->Resume(); +// } + +// /* +// * Class: edu_wpi_first_util_datalog_DataLogJNI +// * Method: stop +// * Signature: (J)V +// */ +// JNIEXPORT void JNICALL +// Java_edu_wpi_first_util_datalog_DataLogJNI_stop +// (JNIEnv* env, jclass, jlong impl) +// { +// if (impl == 0) { +// wpi::ThrowNullPointerException(env, "impl is null"); +// return; +// } +// reinterpret_cast(impl)->Stop(); +// } + +// /* +// * Class: edu_wpi_first_util_datalog_DataLogJNI +// * Method: addSchema +// * Signature: (JLjava/lang/String;Ljava/lang/String;[BJ)V +// */ +// JNIEXPORT void JNICALL +// Java_edu_wpi_first_util_datalog_DataLogJNI_addSchema +// (JNIEnv* env, jclass, jlong impl, jstring name, jstring type, +// jbyteArray schema, jlong timestamp) +// { +// if (impl == 0) { +// wpi::ThrowNullPointerException(env, "impl is null"); +// return; +// } +// reinterpret_cast(impl)->AddSchema( +// JStringRef{env, name}, JStringRef{env, type}, +// JSpan{env, schema}.uarray(), timestamp); +// } + +// /* +// * Class: edu_wpi_first_util_datalog_DataLogJNI +// * Method: addSchemaString +// * Signature: (JLjava/lang/String;Ljava/lang/String;Ljava/lang/String;J)V +// */ +// JNIEXPORT void JNICALL +// Java_edu_wpi_first_util_datalog_DataLogJNI_addSchemaString +// (JNIEnv* env, jclass, jlong impl, jstring name, jstring type, jstring schema, +// jlong timestamp) +// { +// if (impl == 0) { +// wpi::ThrowNullPointerException(env, "impl is null"); +// return; +// } +// JStringRef schemaStr{env, schema}; +// std::string_view schemaView = schemaStr.str(); +// reinterpret_cast(impl)->AddSchema( +// JStringRef{env, name}, JStringRef{env, type}, +// {reinterpret_cast(schemaView.data()), schemaView.size()}, +// timestamp); +// } + +// /* +// * Class: edu_wpi_first_util_datalog_DataLogJNI +// * Method: start +// * Signature: (JLjava/lang/String;Ljava/lang/String;Ljava/lang/String;J)I +// */ +// JNIEXPORT jint JNICALL +// Java_edu_wpi_first_util_datalog_DataLogJNI_start +// (JNIEnv* env, jclass, jlong impl, jstring name, jstring type, +// jstring metadata, jlong timestamp) +// { +// if (impl == 0) { +// wpi::ThrowNullPointerException(env, "impl is null"); +// return 0; +// } +// return reinterpret_cast(impl)->Start( +// JStringRef{env, name}, JStringRef{env, type}, JStringRef{env, metadata}, +// timestamp); +// } + +// /* +// * Class: edu_wpi_first_util_datalog_DataLogJNI +// * Method: finish +// * Signature: (JIJ)V +// */ +// JNIEXPORT void JNICALL +// Java_edu_wpi_first_util_datalog_DataLogJNI_finish +// (JNIEnv* env, jclass, jlong impl, jint entry, jlong timestamp) +// { +// if (impl == 0) { +// wpi::ThrowNullPointerException(env, "impl is null"); +// return; +// } +// reinterpret_cast(impl)->Finish(entry, timestamp); +// } + +// /* +// * Class: edu_wpi_first_util_datalog_DataLogJNI +// * Method: setMetadata +// * Signature: (JILjava/lang/String;J)V +// */ +// JNIEXPORT void JNICALL +// Java_edu_wpi_first_util_datalog_DataLogJNI_setMetadata +// (JNIEnv* env, jclass, jlong impl, jint entry, jstring metadata, +// jlong timestamp) +// { +// if (impl == 0) { +// wpi::ThrowNullPointerException(env, "impl is null"); +// return; +// } +// reinterpret_cast(impl)->SetMetadata( +// entry, JStringRef{env, metadata}, timestamp); +// } + +// /* +// * Class: edu_wpi_first_util_datalog_DataLogJNI +// * Method: close +// * Signature: (J)V +// */ +// JNIEXPORT void JNICALL +// Java_edu_wpi_first_util_datalog_DataLogJNI_close +// (JNIEnv*, jclass, jlong impl) +// { +// delete reinterpret_cast(impl); +// } + +// /* +// * Class: edu_wpi_first_util_datalog_DataLogJNI +// * Method: appendRaw +// * Signature: (JI[BIIJ)V +// */ +// JNIEXPORT void JNICALL +// Java_edu_wpi_first_util_datalog_DataLogJNI_appendRaw +// (JNIEnv* env, jclass, jlong impl, jint entry, jbyteArray value, jint start, +// jint length, jlong timestamp) +// { +// if (impl == 0) { +// wpi::ThrowNullPointerException(env, "impl is null"); +// return; +// } +// if (!value) { +// wpi::ThrowNullPointerException(env, "value is null"); +// return; +// } +// if (start < 0) { +// wpi::ThrowIndexOobException(env, "start must be >= 0"); +// return; +// } +// if (length < 0) { +// wpi::ThrowIndexOobException(env, "length must be >= 0"); +// return; +// } +// CriticalJSpan cvalue{env, value}; +// if (static_cast(start + length) > cvalue.size()) { +// wpi::ThrowIndexOobException( +// env, "start + len must be smaller than array length"); +// return; +// } +// reinterpret_cast(impl)->AppendRaw( +// entry, cvalue.uarray().subspan(start, length), timestamp); +// } + +// /* +// * Class: edu_wpi_first_util_datalog_DataLogJNI +// * Method: appendRawBuffer +// * Signature: (JILjava/lang/Object;IIJ)V +// */ +// JNIEXPORT void JNICALL +// Java_edu_wpi_first_util_datalog_DataLogJNI_appendRawBuffer +// (JNIEnv* env, jclass, jlong impl, jint entry, jobject value, jint start, +// jint length, jlong timestamp) +// { +// if (impl == 0) { +// wpi::ThrowNullPointerException(env, "impl is null"); +// return; +// } +// if (!value) { +// wpi::ThrowNullPointerException(env, "value is null"); +// return; +// } +// if (start < 0) { +// wpi::ThrowIndexOobException(env, "start must be >= 0"); +// return; +// } +// if (length < 0) { +// wpi::ThrowIndexOobException(env, "length must be >= 0"); +// return; +// } +// JSpan cvalue{env, value, static_cast(start + length)}; +// if (!cvalue) { +// wpi::ThrowIllegalArgumentException(env, +// "value must be a native ByteBuffer"); +// return; +// } +// reinterpret_cast(impl)->AppendRaw( +// entry, cvalue.uarray().subspan(start, length), timestamp); +// } + +// /* +// * Class: edu_wpi_first_util_datalog_DataLogJNI +// * Method: appendBoolean +// * Signature: (JIZJ)V +// */ +// JNIEXPORT void JNICALL +// Java_edu_wpi_first_util_datalog_DataLogJNI_appendBoolean +// (JNIEnv* env, jclass, jlong impl, jint entry, jboolean value, jlong timestamp) +// { +// if (impl == 0) { +// wpi::ThrowNullPointerException(env, "impl is null"); +// return; +// } +// reinterpret_cast(impl)->AppendBoolean(entry, value, timestamp); +// } + +// /* +// * Class: edu_wpi_first_util_datalog_DataLogJNI +// * Method: appendInteger +// * Signature: (JIJJ)V +// */ +// JNIEXPORT void JNICALL +// Java_edu_wpi_first_util_datalog_DataLogJNI_appendInteger +// (JNIEnv* env, jclass, jlong impl, jint entry, jlong value, jlong timestamp) +// { +// if (impl == 0) { +// wpi::ThrowNullPointerException(env, "impl is null"); +// return; +// } +// reinterpret_cast(impl)->AppendInteger(entry, value, timestamp); +// } + +// /* +// * Class: edu_wpi_first_util_datalog_DataLogJNI +// * Method: appendFloat +// * Signature: (JIFJ)V +// */ +// JNIEXPORT void JNICALL +// Java_edu_wpi_first_util_datalog_DataLogJNI_appendFloat +// (JNIEnv* env, jclass, jlong impl, jint entry, jfloat value, jlong timestamp) +// { +// if (impl == 0) { +// wpi::ThrowNullPointerException(env, "impl is null"); +// return; +// } +// reinterpret_cast(impl)->AppendFloat(entry, value, timestamp); +// } + +// /* +// * Class: edu_wpi_first_util_datalog_DataLogJNI +// * Method: appendDouble +// * Signature: (JIDJ)V +// */ +// JNIEXPORT void JNICALL +// Java_edu_wpi_first_util_datalog_DataLogJNI_appendDouble +// (JNIEnv* env, jclass, jlong impl, jint entry, jdouble value, jlong timestamp) +// { +// if (impl == 0) { +// wpi::ThrowNullPointerException(env, "impl is null"); +// return; +// } +// reinterpret_cast(impl)->AppendDouble(entry, value, timestamp); +// } + +// /* +// * Class: edu_wpi_first_util_datalog_DataLogJNI +// * Method: appendString +// * Signature: (JILjava/lang/String;J)V +// */ +// JNIEXPORT void JNICALL +// Java_edu_wpi_first_util_datalog_DataLogJNI_appendString +// (JNIEnv* env, jclass, jlong impl, jint entry, jstring value, jlong timestamp) +// { +// if (impl == 0) { +// wpi::ThrowNullPointerException(env, "impl is null"); +// return; +// } +// reinterpret_cast(impl)->AppendString(entry, JStringRef{env, value}, +// timestamp); +// } + +// /* +// * Class: edu_wpi_first_util_datalog_DataLogJNI +// * Method: appendBooleanArray +// * Signature: (JI[ZJ)V +// */ +// JNIEXPORT void JNICALL +// Java_edu_wpi_first_util_datalog_DataLogJNI_appendBooleanArray +// (JNIEnv* env, jclass, jlong impl, jint entry, jbooleanArray value, +// jlong timestamp) +// { +// if (impl == 0) { +// wpi::ThrowNullPointerException(env, "impl is null"); +// return; +// } +// if (!value) { +// wpi::ThrowNullPointerException(env, "value is null"); +// return; +// } +// reinterpret_cast(impl)->AppendBooleanArray( +// entry, JSpan{env, value}, timestamp); +// } + +// /* +// * Class: edu_wpi_first_util_datalog_DataLogJNI +// * Method: appendIntegerArray +// * Signature: (JI[JJ)V +// */ +// JNIEXPORT void JNICALL +// Java_edu_wpi_first_util_datalog_DataLogJNI_appendIntegerArray +// (JNIEnv* env, jclass, jlong impl, jint entry, jlongArray value, +// jlong timestamp) +// { +// if (impl == 0) { +// wpi::ThrowNullPointerException(env, "impl is null"); +// return; +// } +// if (!value) { +// wpi::ThrowNullPointerException(env, "value is null"); +// return; +// } +// JSpan jarr{env, value}; +// if constexpr (sizeof(jlong) == sizeof(int64_t)) { +// reinterpret_cast(impl)->AppendIntegerArray( +// entry, {reinterpret_cast(jarr.data()), jarr.size()}, +// timestamp); +// } else { +// wpi::SmallVector arr; +// arr.reserve(jarr.size()); +// for (auto v : jarr) { +// arr.push_back(v); +// } +// reinterpret_cast(impl)->AppendIntegerArray(entry, arr, timestamp); +// } +// } + +// /* +// * Class: edu_wpi_first_util_datalog_DataLogJNI +// * Method: appendFloatArray +// * Signature: (JI[FJ)V +// */ +// JNIEXPORT void JNICALL +// Java_edu_wpi_first_util_datalog_DataLogJNI_appendFloatArray +// (JNIEnv* env, jclass, jlong impl, jint entry, jfloatArray value, +// jlong timestamp) +// { +// if (impl == 0) { +// wpi::ThrowNullPointerException(env, "impl is null"); +// return; +// } +// if (!value) { +// wpi::ThrowNullPointerException(env, "value is null"); +// return; +// } +// reinterpret_cast(impl)->AppendFloatArray( +// entry, JSpan{env, value}, timestamp); +// } + +// /* +// * Class: edu_wpi_first_util_datalog_DataLogJNI +// * Method: appendDoubleArray +// * Signature: (JI[DJ)V +// */ +// JNIEXPORT void JNICALL +// Java_edu_wpi_first_util_datalog_DataLogJNI_appendDoubleArray +// (JNIEnv* env, jclass, jlong impl, jint entry, jdoubleArray value, +// jlong timestamp) +// { +// if (impl == 0) { +// wpi::ThrowNullPointerException(env, "impl is null"); +// return; +// } +// if (!value) { +// wpi::ThrowNullPointerException(env, "value is null"); +// return; +// } +// reinterpret_cast(impl)->AppendDoubleArray( +// entry, JSpan{env, value}, timestamp); +// } + +// /* +// * Class: edu_wpi_first_util_datalog_DataLogJNI +// * Method: appendStringArray +// * Signature: (JI[Ljava/lang/Object;J)V +// */ +// JNIEXPORT void JNICALL +// Java_edu_wpi_first_util_datalog_DataLogJNI_appendStringArray +// (JNIEnv* env, jclass, jlong impl, jint entry, jobjectArray value, +// jlong timestamp) +// { +// if (impl == 0) { +// wpi::ThrowNullPointerException(env, "impl is null"); +// return; +// } +// if (!value) { +// wpi::ThrowNullPointerException(env, "value is null"); +// return; +// } +// size_t len = env->GetArrayLength(value); +// std::vector arr; +// arr.reserve(len); +// for (size_t i = 0; i < len; ++i) { +// JLocal elem{ +// env, static_cast(env->GetObjectArrayElement(value, i))}; +// if (!elem) { +// wpi::ThrowNullPointerException( +// env, fmt::format("string at element {} is null", i)); +// return; +// } +// arr.emplace_back(JStringRef{env, elem}.str()); +// } +// reinterpret_cast(impl)->AppendStringArray(entry, arr, timestamp); +// } + +// } // extern "C" +// TODO: get JNI working diff --git a/wpiutil/src/main/native/include/wpi/FileLogger.h b/libdatalog/src/main/native/include/wpi/FileLogger.h similarity index 100% rename from wpiutil/src/main/native/include/wpi/FileLogger.h rename to libdatalog/src/main/native/include/wpi/FileLogger.h diff --git a/libdatalog/src/main/test/native/cpp/DataLogTest.cpp b/libdatalog/src/main/test/native/cpp/DataLogTest.cpp new file mode 100644 index 00000000000..ebe6517c4d5 --- /dev/null +++ b/libdatalog/src/main/test/native/cpp/DataLogTest.cpp @@ -0,0 +1,675 @@ +// // Copyright (c) FIRST and other WPILib contributors. +// // Open Source Software; you can modify and/or share it under the terms of +// // the WPILib BSD license file in the root directory of this project. + +// #include +// #include +// #include +// #include + +// #include + +// #include "wpi/DataLogWriter.h" +// #include "wpi/Logger.h" +// #include "wpi/raw_ostream.h" + +// namespace { +// struct ThingA { +// int x = 0; +// }; + +// inline bool operator==(const ThingA& a, const ThingA& b) { +// return a.x == b.x; +// } + +// struct ThingB { +// int x = 0; +// }; + +// struct ThingC { +// int x = 0; +// }; + +// struct Info1 { +// int info = 0; +// }; + +// struct Info2 { +// int info = 0; +// }; +// } // namespace + +// template <> +// struct wpi::Struct { +// static constexpr std::string_view GetTypeName() { return "ThingA"; } +// static constexpr size_t GetSize() { return 1; } +// static constexpr std::string_view GetSchema() { return "uint8 value"; } +// static ThingA Unpack(std::span data) { +// return ThingA{.x = data[0]}; +// } +// static void Pack(std::span data, const ThingA& value) { +// data[0] = value.x; +// } +// }; + +// template <> +// struct wpi::Struct { +// static constexpr std::string_view GetTypeName(const Info1&) { +// return "ThingB"; +// } +// static constexpr size_t GetSize(const Info1&) { return 1; } +// static constexpr std::string_view GetSchema(const Info1&) { +// return "uint8 value"; +// } +// static ThingB Unpack(std::span data, const Info1&) { +// return ThingB{.x = data[0]}; +// } +// static void Pack(std::span data, const ThingB& value, const Info1&) { +// data[0] = value.x; +// } +// }; + +// template <> +// struct wpi::Struct { +// static constexpr std::string_view GetTypeName() { return "ThingC"; } +// static constexpr size_t GetSize() { return 1; } +// static constexpr std::string_view GetSchema() { return "uint8 value"; } +// static ThingC Unpack(std::span data) { +// return ThingC{.x = data[0]}; +// } +// static void Pack(std::span data, const ThingC& value) { +// data[0] = value.x; +// } +// }; + +// template <> +// struct wpi::Struct { +// static constexpr std::string_view GetTypeName(const Info1&) { +// return "ThingC"; +// } +// static constexpr size_t GetSize(const Info1&) { return 1; } +// static constexpr std::string_view GetSchema(const Info1&) { +// return "uint8 value"; +// } +// static ThingC Unpack(std::span data, const Info1&) { +// return ThingC{.x = data[0]}; +// } +// static void Pack(std::span data, const ThingC& value, const Info1&) { +// data[0] = value.x; +// } +// }; + +// template <> +// struct wpi::Struct { +// static constexpr std::string_view GetTypeName(const Info2&) { +// return "ThingC"; +// } +// static constexpr size_t GetSize(const Info2&) { return 1; } +// static constexpr std::string_view GetSchema(const Info2&) { +// return "uint8 value"; +// } +// static ThingC Unpack(std::span data, const Info2&) { +// return ThingC{.x = data[0]}; +// } +// static void Pack(std::span data, const ThingC& value, const Info2&) { +// data[0] = value.x; +// } +// }; + +// static_assert(wpi::StructSerializable); +// static_assert(!wpi::StructSerializable); + +// static_assert(!wpi::StructSerializable); +// static_assert(wpi::StructSerializable); +// static_assert(!wpi::StructSerializable); + +// static_assert(wpi::StructSerializable); +// static_assert(wpi::StructSerializable); +// static_assert(wpi::StructSerializable); + +// class DataLogTest : public ::testing::Test { +// public: +// wpi::Logger msglog; +// std::vector data; +// wpi::log::DataLogWriter log{msglog, +// std::make_unique(data)}; +// }; + +// TEST_F(DataLogTest, SimpleInt) { +// int entry = log.Start("test", "int64", "", 1); +// log.AppendInteger(entry, 1, 2); +// log.Flush(); +// ASSERT_EQ(data.size(), 54u); +// } + +// TEST_F(DataLogTest, BooleanAppend) { +// wpi::log::BooleanLogEntry entry{log, "a", 5}; +// entry.Append(false, 7); +// log.Flush(); +// ASSERT_EQ(data.size(), 46u); +// } + +// TEST_F(DataLogTest, BooleanUpdate) { +// wpi::log::BooleanLogEntry entry{log, "a", 5}; +// ASSERT_FALSE(entry.GetLastValue().has_value()); +// entry.Update(false, 7); +// log.Flush(); +// ASSERT_EQ(data.size(), 46u); +// ASSERT_TRUE(entry.GetLastValue().has_value()); +// ASSERT_EQ(entry.GetLastValue().value(), false); +// entry.Update(false, 8); +// log.Flush(); +// ASSERT_EQ(data.size(), 46u); +// entry.Update(true, 9); +// log.Flush(); +// ASSERT_EQ(data.size(), 51u); +// ASSERT_TRUE(entry.GetLastValue().has_value()); +// ASSERT_EQ(entry.GetLastValue().value(), true); +// } + +// TEST_F(DataLogTest, IntegerAppend) { +// wpi::log::IntegerLogEntry entry{log, "a", 5}; +// entry.Append(5, 7); +// log.Flush(); +// ASSERT_EQ(data.size(), 51u); +// } + +// TEST_F(DataLogTest, IntegerUpdate) { +// wpi::log::IntegerLogEntry entry{log, "a", 5}; +// ASSERT_FALSE(entry.GetLastValue().has_value()); +// entry.Update(0, 7); +// log.Flush(); +// ASSERT_EQ(data.size(), 51u); +// ASSERT_TRUE(entry.GetLastValue().has_value()); +// ASSERT_EQ(entry.GetLastValue().value(), 0); +// entry.Update(0, 8); +// log.Flush(); +// ASSERT_EQ(data.size(), 51u); +// entry.Update(2, 9); +// log.Flush(); +// ASSERT_EQ(data.size(), 63u); +// ASSERT_TRUE(entry.GetLastValue().has_value()); +// ASSERT_EQ(entry.GetLastValue().value(), 2); +// } + +// TEST_F(DataLogTest, FloatAppend) { +// wpi::log::FloatLogEntry entry{log, "a", 5}; +// entry.Append(5.0, 7); +// log.Flush(); +// ASSERT_EQ(data.size(), 47u); +// } + +// TEST_F(DataLogTest, FloatUpdate) { +// wpi::log::FloatLogEntry entry{log, "a", 5}; +// ASSERT_FALSE(entry.GetLastValue().has_value()); +// entry.Update(0.0f, 7); +// log.Flush(); +// ASSERT_EQ(data.size(), 47u); +// ASSERT_TRUE(entry.GetLastValue().has_value()); +// ASSERT_EQ(entry.GetLastValue().value(), 0.0f); +// entry.Update(0.0f, 8); +// log.Flush(); +// ASSERT_EQ(data.size(), 47u); +// entry.Update(0.1f, 9); +// log.Flush(); +// ASSERT_EQ(data.size(), 55u); +// ASSERT_TRUE(entry.GetLastValue().has_value()); +// ASSERT_EQ(entry.GetLastValue().value(), 0.1f); +// } + +// TEST_F(DataLogTest, DoubleAppend) { +// wpi::log::DoubleLogEntry entry{log, "a", 5}; +// entry.Append(5.0, 7); +// log.Flush(); +// ASSERT_EQ(data.size(), 52u); +// } + +// TEST_F(DataLogTest, DoubleUpdate) { +// wpi::log::DoubleLogEntry entry{log, "a", 5}; +// ASSERT_FALSE(entry.GetLastValue().has_value()); +// entry.Update(0.0, 7); +// log.Flush(); +// ASSERT_EQ(data.size(), 52u); +// ASSERT_TRUE(entry.GetLastValue().has_value()); +// ASSERT_EQ(entry.GetLastValue().value(), 0.0); +// entry.Update(0.0, 8); +// log.Flush(); +// ASSERT_EQ(data.size(), 52u); +// entry.Update(0.1, 9); +// log.Flush(); +// ASSERT_EQ(data.size(), 64u); +// ASSERT_TRUE(entry.GetLastValue().has_value()); +// ASSERT_EQ(entry.GetLastValue().value(), 0.1); +// } + +// TEST_F(DataLogTest, StringAppend) { +// wpi::log::StringLogEntry entry{log, "a", 5}; +// entry.Append("x", 7); +// log.Flush(); +// ASSERT_EQ(data.size(), 45u); +// } + +// TEST_F(DataLogTest, StringUpdate) { +// wpi::log::StringLogEntry entry{log, "a", 5}; +// ASSERT_FALSE(entry.HasLastValue()); + +// entry.Update("x", 7); +// log.Flush(); +// ASSERT_EQ(data.size(), 45u); +// ASSERT_TRUE(entry.GetLastValue().has_value()); +// ASSERT_EQ(entry.GetLastValue().value(), "x"); + +// entry.Update("x", 8); +// log.Flush(); +// ASSERT_EQ(data.size(), 45u); + +// entry.Update("y", 9); +// log.Flush(); +// ASSERT_EQ(data.size(), 50u); +// ASSERT_TRUE(entry.GetLastValue().has_value()); +// ASSERT_EQ(entry.GetLastValue().value(), "y"); + +// entry.Update("yy", 10); +// log.Flush(); +// ASSERT_EQ(data.size(), 56u); +// ASSERT_TRUE(entry.GetLastValue().has_value()); +// ASSERT_EQ(entry.GetLastValue().value(), "yy"); + +// entry.Update("", 11); +// log.Flush(); +// ASSERT_EQ(data.size(), 60u); +// ASSERT_TRUE(entry.GetLastValue().has_value()); +// ASSERT_EQ(entry.GetLastValue().value(), ""); +// } + +// TEST_F(DataLogTest, RawAppend) { +// wpi::log::RawLogEntry entry{log, "a", 5}; +// entry.Append({{5}}, 7); +// log.Flush(); +// ASSERT_EQ(data.size(), 42u); +// } + +// TEST_F(DataLogTest, RawUpdate) { +// wpi::log::RawLogEntry entry{log, "a", 5}; +// ASSERT_FALSE(entry.HasLastValue()); + +// entry.Update({{5}}, 7); +// log.Flush(); +// ASSERT_EQ(data.size(), 42u); +// ASSERT_TRUE(entry.GetLastValue().has_value()); +// ASSERT_EQ(entry.GetLastValue().value(), std::vector{5}); + +// entry.Update({{5}}, 8); +// log.Flush(); +// ASSERT_EQ(data.size(), 42u); + +// entry.Update({{6}}, 9); +// log.Flush(); +// ASSERT_EQ(data.size(), 47u); +// ASSERT_TRUE(entry.GetLastValue().has_value()); +// ASSERT_EQ(entry.GetLastValue().value(), std::vector{6}); + +// entry.Update({{6, 6}}, 9); +// log.Flush(); +// ASSERT_EQ(data.size(), 53u); +// ASSERT_TRUE(entry.GetLastValue().has_value()); +// ASSERT_EQ(entry.GetLastValue().value(), (std::vector{6, 6})); + +// entry.Update(std::span{}, 10); +// log.Flush(); +// ASSERT_EQ(data.size(), 57u); +// ASSERT_TRUE(entry.GetLastValue().has_value()); +// ASSERT_EQ(entry.GetLastValue().value(), std::vector{}); +// } + +// TEST_F(DataLogTest, BooleanArrayAppendEmpty) { +// wpi::log::BooleanArrayLogEntry entry{log, "a", 5}; +// entry.Append(std::span{}, 7); +// log.Flush(); +// ASSERT_EQ(data.size(), 47u); +// } + +// TEST_F(DataLogTest, BooleanArrayAppend) { +// wpi::log::BooleanArrayLogEntry entry{log, "a", 5}; +// entry.Append({false}, 7); +// log.Flush(); +// ASSERT_EQ(data.size(), 48u); +// } + +// TEST_F(DataLogTest, BooleanArrayUpdate) { +// wpi::log::BooleanArrayLogEntry entry{log, "a", 5}; +// ASSERT_FALSE(entry.GetLastValue().has_value()); +// entry.Update({false}, 7); +// log.Flush(); +// ASSERT_EQ(data.size(), 48u); +// ASSERT_TRUE(entry.GetLastValue().has_value()); +// ASSERT_EQ(entry.GetLastValue().value(), std::vector{false}); +// entry.Update({false}, 8); +// log.Flush(); +// ASSERT_EQ(data.size(), 48u); +// entry.Update({true}, 9); +// log.Flush(); +// ASSERT_EQ(data.size(), 53u); +// ASSERT_TRUE(entry.GetLastValue().has_value()); +// ASSERT_EQ(entry.GetLastValue().value(), std::vector{true}); +// entry.Update(std::span{}, 10); +// log.Flush(); +// ASSERT_EQ(data.size(), 57u); +// ASSERT_TRUE(entry.GetLastValue().has_value()); +// ASSERT_EQ(entry.GetLastValue().value(), std::vector{}); +// } + +// TEST_F(DataLogTest, IntegerArrayAppendEmpty) { +// wpi::log::IntegerArrayLogEntry entry{log, "a", 5}; +// entry.Append(std::span{}, 7); +// log.Flush(); +// ASSERT_EQ(data.size(), 45u); +// } + +// TEST_F(DataLogTest, IntegerArrayAppend) { +// wpi::log::IntegerArrayLogEntry entry{log, "a", 5}; +// entry.Append({1}, 7); +// log.Flush(); +// ASSERT_EQ(data.size(), 53u); +// } + +// TEST_F(DataLogTest, IntegerArrayUpdate) { +// wpi::log::IntegerArrayLogEntry entry{log, "a", 5}; +// ASSERT_FALSE(entry.GetLastValue().has_value()); +// entry.Update({1}, 7); +// log.Flush(); +// ASSERT_EQ(data.size(), 53u); +// ASSERT_TRUE(entry.GetLastValue().has_value()); +// ASSERT_EQ(entry.GetLastValue().value(), std::vector{1}); +// entry.Update({1}, 8); +// log.Flush(); +// ASSERT_EQ(data.size(), 53u); +// entry.Update({2}, 9); +// log.Flush(); +// ASSERT_EQ(data.size(), 65u); +// ASSERT_TRUE(entry.GetLastValue().has_value()); +// ASSERT_EQ(entry.GetLastValue().value(), std::vector{2}); +// entry.Update(std::span{}, 10); +// log.Flush(); +// ASSERT_EQ(data.size(), 69u); +// ASSERT_TRUE(entry.GetLastValue().has_value()); +// ASSERT_EQ(entry.GetLastValue().value(), std::vector{}); +// } + +// TEST_F(DataLogTest, DoubleArrayAppendEmpty) { +// wpi::log::DoubleArrayLogEntry entry{log, "a", 5}; +// entry.Append(std::span{}, 7); +// log.Flush(); +// ASSERT_EQ(data.size(), 46u); +// } + +// TEST_F(DataLogTest, DoubleArrayAppend) { +// wpi::log::DoubleArrayLogEntry entry{log, "a", 5}; +// entry.Append({1.0}, 7); +// log.Flush(); +// ASSERT_EQ(data.size(), 54u); +// } + +// TEST_F(DataLogTest, DoubleArrayUpdate) { +// wpi::log::DoubleArrayLogEntry entry{log, "a", 5}; +// ASSERT_FALSE(entry.GetLastValue().has_value()); +// entry.Update({1.0}, 7); +// log.Flush(); +// ASSERT_EQ(data.size(), 54u); +// ASSERT_TRUE(entry.GetLastValue().has_value()); +// ASSERT_EQ(entry.GetLastValue().value(), std::vector{1.0}); +// entry.Update({1.0}, 8); +// log.Flush(); +// ASSERT_EQ(data.size(), 54u); +// entry.Update({2.0}, 9); +// log.Flush(); +// ASSERT_EQ(data.size(), 66u); +// ASSERT_TRUE(entry.GetLastValue().has_value()); +// ASSERT_EQ(entry.GetLastValue().value(), std::vector{2}); +// entry.Update(std::span{}, 10); +// log.Flush(); +// ASSERT_EQ(data.size(), 70u); +// ASSERT_TRUE(entry.GetLastValue().has_value()); +// ASSERT_EQ(entry.GetLastValue().value(), std::vector{}); +// } + +// TEST_F(DataLogTest, FloatArrayAppendEmpty) { +// wpi::log::FloatArrayLogEntry entry{log, "a", 5}; +// entry.Append(std::span{}, 7); +// log.Flush(); +// ASSERT_EQ(data.size(), 45u); +// } + +// TEST_F(DataLogTest, FloatArrayAppend) { +// wpi::log::FloatArrayLogEntry entry{log, "a", 5}; +// entry.Append({1.0f}, 7); +// log.Flush(); +// ASSERT_EQ(data.size(), 49u); +// } + +// TEST_F(DataLogTest, FloatArrayUpdate) { +// wpi::log::FloatArrayLogEntry entry{log, "a", 5}; +// ASSERT_FALSE(entry.GetLastValue().has_value()); +// entry.Update({1.0f}, 7); +// log.Flush(); +// ASSERT_EQ(data.size(), 49u); +// ASSERT_TRUE(entry.GetLastValue().has_value()); +// ASSERT_EQ(entry.GetLastValue().value(), std::vector{1.0f}); +// entry.Update({1.0f}, 8); +// log.Flush(); +// ASSERT_EQ(data.size(), 49u); +// entry.Update({2.0f}, 9); +// log.Flush(); +// ASSERT_EQ(data.size(), 57u); +// ASSERT_TRUE(entry.GetLastValue().has_value()); +// ASSERT_EQ(entry.GetLastValue().value(), std::vector{2.0f}); +// entry.Update(std::span{}, 10); +// log.Flush(); +// ASSERT_EQ(data.size(), 61u); +// ASSERT_TRUE(entry.GetLastValue().has_value()); +// ASSERT_EQ(entry.GetLastValue().value(), std::vector{}); +// } + +// TEST_F(DataLogTest, StringArrayAppendEmpty) { +// wpi::log::StringArrayLogEntry entry{log, "a", 5}; +// entry.Append(std::span{}, 7); +// entry.Append(std::span{}, 7); +// log.Flush(); +// ASSERT_EQ(data.size(), 58u); +// } + +// TEST_F(DataLogTest, StringArrayAppend) { +// wpi::log::StringArrayLogEntry entry{log, "a", 5}; +// entry.Append({"x"}, 7); +// log.Flush(); +// ASSERT_EQ(data.size(), 55u); +// } + +// TEST_F(DataLogTest, StringArrayUpdate) { +// wpi::log::StringArrayLogEntry entry{log, "a", 5}; +// ASSERT_FALSE(entry.GetLastValue().has_value()); +// entry.Update({"x"}, 7); +// log.Flush(); +// ASSERT_EQ(data.size(), 55u); +// ASSERT_TRUE(entry.GetLastValue().has_value()); +// ASSERT_EQ(entry.GetLastValue().value(), std::vector{"x"}); +// entry.Update({"x"}, 8); +// log.Flush(); +// ASSERT_EQ(data.size(), 55u); +// entry.Update({"y"}, 9); +// log.Flush(); +// ASSERT_EQ(data.size(), 68u); +// ASSERT_TRUE(entry.GetLastValue().has_value()); +// ASSERT_EQ(entry.GetLastValue().value(), std::vector{"y"}); +// entry.Update(std::span{}, 10); +// log.Flush(); +// ASSERT_EQ(data.size(), 76u); +// ASSERT_TRUE(entry.GetLastValue().has_value()); +// ASSERT_EQ(entry.GetLastValue().value(), std::vector{}); +// } + +// TEST_F(DataLogTest, StructA) { +// [[maybe_unused]] +// wpi::log::StructLogEntry entry0; +// wpi::log::StructLogEntry entry{log, "a", 5}; +// entry.Append(ThingA{}); +// entry.Append(ThingA{}, 7); +// } + +// TEST_F(DataLogTest, StructUpdate) { +// wpi::log::StructLogEntry entry{log, "a", 5}; +// ASSERT_FALSE(entry.GetLastValue().has_value()); + +// entry.Update(ThingA{}, 7); +// log.Flush(); +// ASSERT_EQ(data.size(), 122u); +// ASSERT_TRUE(entry.GetLastValue().has_value()); +// ASSERT_EQ(entry.GetLastValue().value(), ThingA{}); + +// entry.Update(ThingA{}, 8); +// log.Flush(); +// ASSERT_EQ(data.size(), 122u); + +// entry.Update(ThingA{.x = 1}, 9); +// log.Flush(); +// ASSERT_EQ(data.size(), 127u); +// ASSERT_TRUE(entry.GetLastValue().has_value()); +// ASSERT_EQ(entry.GetLastValue().value(), ThingA{.x = 1}); +// } + +// TEST_F(DataLogTest, StructArrayA) { +// [[maybe_unused]] +// wpi::log::StructArrayLogEntry entry0; +// wpi::log::StructArrayLogEntry entry{log, "a", 5}; +// entry.Append({{ThingA{}, ThingA{}}}); +// entry.Append({{ThingA{}, ThingA{}}}, 7); +// } + +// TEST_F(DataLogTest, StructArrayUpdate) { +// wpi::log::StructArrayLogEntry entry{log, "a", 5}; +// ASSERT_FALSE(entry.GetLastValue().has_value()); + +// entry.Update({{ThingA{}, ThingA{.x = 1}}}, 7); +// log.Flush(); +// ASSERT_EQ(data.size(), 125u); +// ASSERT_TRUE(entry.GetLastValue().has_value()); +// ASSERT_EQ(entry.GetLastValue().value(), +// (std::vector{ThingA{}, ThingA{.x = 1}})); + +// entry.Update({{ThingA{}, ThingA{.x = 1}}}, 8); +// log.Flush(); +// ASSERT_EQ(data.size(), 125u); + +// entry.Update({{ThingA{}, ThingA{.x = 2}}}, 9); +// log.Flush(); +// ASSERT_EQ(data.size(), 131u); +// ASSERT_TRUE(entry.GetLastValue().has_value()); +// ASSERT_EQ(entry.GetLastValue().value(), +// (std::vector{ThingA{}, ThingA{.x = 2}})); + +// entry.Update(std::span{}, 10); +// log.Flush(); +// ASSERT_EQ(data.size(), 135u); +// ASSERT_TRUE(entry.GetLastValue().has_value()); +// ASSERT_EQ(entry.GetLastValue().value(), std::vector{}); +// } + +// TEST_F(DataLogTest, StructFixedArrayA) { +// [[maybe_unused]] +// wpi::log::StructArrayLogEntry> entry0; +// wpi::log::StructLogEntry> entry{log, "a", 5}; +// std::array arr; +// entry.Append(arr); +// entry.Append(arr, 7); +// } + +// TEST_F(DataLogTest, StructB) { +// Info1 info; +// [[maybe_unused]] +// wpi::log::StructLogEntry entry0; +// wpi::log::StructLogEntry entry{log, "b", info, 5}; +// entry.Append(ThingB{}); +// entry.Append(ThingB{}, 7); +// } + +// TEST_F(DataLogTest, StructArrayB) { +// Info1 info; +// [[maybe_unused]] +// wpi::log::StructArrayLogEntry entry0; +// wpi::log::StructArrayLogEntry entry{log, "a", info, 5}; +// entry.Append({{ThingB{}, ThingB{}}}); +// entry.Append({{ThingB{}, ThingB{}}}, 7); +// } + +// TEST_F(DataLogTest, StructFixedArrayB) { +// Info1 info; +// wpi::log::StructLogEntry, Info1> entry{log, "a", info, +// 5}; +// std::array arr; +// entry.Append(arr); +// entry.Append(arr, 7); +// } + +// TEST_F(DataLogTest, StructC) { +// { +// wpi::log::StructLogEntry entry{log, "c", 5}; +// entry.Append(ThingC{}); +// entry.Append(ThingC{}, 7); +// } +// { +// Info1 info; +// wpi::log::StructLogEntry entry{log, "c1", info, 5}; +// entry.Append(ThingC{}); +// entry.Append(ThingC{}, 7); +// } +// { +// Info2 info; +// wpi::log::StructLogEntry entry{log, "c2", info, 5}; +// entry.Append(ThingC{}); +// entry.Append(ThingC{}, 7); +// } +// } + +// TEST_F(DataLogTest, StructArrayC) { +// { +// wpi::log::StructArrayLogEntry entry{log, "c", 5}; +// entry.Append({{ThingC{}, ThingC{}}}); +// entry.Append({{ThingC{}, ThingC{}}}, 7); +// } +// { +// Info1 info; +// wpi::log::StructArrayLogEntry entry{log, "c1", info, 5}; +// entry.Append({{ThingC{}, ThingC{}}}); +// entry.Append({{ThingC{}, ThingC{}}}, 7); +// } +// { +// Info2 info; +// wpi::log::StructArrayLogEntry entry{log, "c2", info, 5}; +// entry.Append({{ThingC{}, ThingC{}}}); +// entry.Append({{ThingC{}, ThingC{}}}, 7); +// } +// } + +// TEST_F(DataLogTest, StructFixedArrayC) { +// std::array arr; +// { +// wpi::log::StructLogEntry> entry{log, "c", 5}; +// entry.Append(arr); +// entry.Append(arr, 7); +// } +// { +// Info1 info; +// wpi::log::StructLogEntry, Info1> entry{log, "c1", +// info, 5}; +// entry.Append(arr); +// entry.Append(arr, 7); +// } +// { +// Info2 info; +// wpi::log::StructLogEntry, Info2> entry{log, "c2", +// info, 5}; +// entry.Append(arr); +// entry.Append(arr, 7); +// } +// } +// TODO: get tests working diff --git a/wpiutil/CMakeLists.txt b/wpiutil/CMakeLists.txt index 9d98b7fc984..293425a4605 100644 --- a/wpiutil/CMakeLists.txt +++ b/wpiutil/CMakeLists.txt @@ -9,7 +9,6 @@ include(DownloadAndCheck) file( GLOB wpiutil_jni_src src/main/native/cpp/jni/WPIUtilJNI.cpp - src/main/native/cpp/jni/DataLogJNI.cpp ) # Java bindings @@ -260,4 +259,4 @@ if(WITH_TESTS) if(MSVC) target_compile_options(wpiutil_test PRIVATE /utf-8) endif() -endif() +endif() \ No newline at end of file diff --git a/wpiutil/src/main/native/cpp/jni/DataLogJNI.cpp b/wpiutil/src/main/native/cpp/jni/DataLogJNI.cpp deleted file mode 100644 index 782266874d0..00000000000 --- a/wpiutil/src/main/native/cpp/jni/DataLogJNI.cpp +++ /dev/null @@ -1,614 +0,0 @@ -// Copyright (c) FIRST and other WPILib contributors. -// Open Source Software; you can modify and/or share it under the terms of -// the WPILib BSD license file in the root directory of this project. - -#include - -#include -#include -#include - -#include - -#include "WPIUtilJNI.h" -#include "edu_wpi_first_util_datalog_DataLogJNI.h" -#include "wpi/DataLog.h" -#include "wpi/DataLogBackgroundWriter.h" -#include "wpi/DataLogWriter.h" -#include "wpi/jni_util.h" - -using namespace wpi::java; -using namespace wpi::log; - -namespace { -class buf_ostream : public wpi::raw_uvector_ostream { - private: - std::vector data; - - public: - buf_ostream() : raw_uvector_ostream{data} {} - - void clear() { data.clear(); } -}; -} // namespace - -extern "C" { - -/* - * Class: edu_wpi_first_util_datalog_DataLogJNI - * Method: bgCreate - * Signature: (Ljava/lang/String;Ljava/lang/String;DLjava/lang/String;)J - */ -JNIEXPORT jlong JNICALL -Java_edu_wpi_first_util_datalog_DataLogJNI_bgCreate - (JNIEnv* env, jclass, jstring dir, jstring filename, jdouble period, - jstring extraHeader) -{ - if (!dir) { - wpi::ThrowNullPointerException(env, "dir is null"); - return 0; - } - if (!filename) { - wpi::ThrowNullPointerException(env, "filename is null"); - return 0; - } - if (!extraHeader) { - wpi::ThrowNullPointerException(env, "extraHeader is null"); - return 0; - } - return reinterpret_cast(new DataLogBackgroundWriter{ - JStringRef{env, dir}, JStringRef{env, filename}, period, - JStringRef{env, extraHeader}}); -} - -/* - * Class: edu_wpi_first_util_datalog_DataLogJNI - * Method: bgSetFilename - * Signature: (JLjava/lang/String;)V - */ -JNIEXPORT void JNICALL -Java_edu_wpi_first_util_datalog_DataLogJNI_bgSetFilename - (JNIEnv* env, jclass, jlong impl, jstring filename) -{ - if (impl == 0) { - wpi::ThrowNullPointerException(env, "impl is null"); - return; - } - if (!filename) { - wpi::ThrowNullPointerException(env, "filename is null"); - return; - } - reinterpret_cast(impl)->SetFilename( - JStringRef{env, filename}); -} - -/* - * Class: edu_wpi_first_util_datalog_DataLogJNI - * Method: fgCreate - * Signature: (Ljava/lang/String;Ljava/lang/String;)J - */ -JNIEXPORT jlong JNICALL -Java_edu_wpi_first_util_datalog_DataLogJNI_fgCreate - (JNIEnv* env, jclass, jstring filename, jstring extraHeader) -{ - if (!filename) { - wpi::ThrowNullPointerException(env, "filename is null"); - return 0; - } - if (!extraHeader) { - wpi::ThrowNullPointerException(env, "extraHeader is null"); - return 0; - } - std::error_code ec; - auto writer = new DataLogWriter{JStringRef{env, filename}, ec, - JStringRef{env, extraHeader}}; - if (ec) { - wpi::ThrowIOException(env, ec.message()); - delete writer; - return 0; - } - return reinterpret_cast(writer); -} - -/* - * Class: edu_wpi_first_util_datalog_DataLogJNI - * Method: fgCreateMemory - * Signature: (Ljava/lang/String;)J - */ -JNIEXPORT jlong JNICALL -Java_edu_wpi_first_util_datalog_DataLogJNI_fgCreateMemory - (JNIEnv* env, jclass, jstring extraHeader) -{ - if (!extraHeader) { - wpi::ThrowNullPointerException(env, "extraHeader is null"); - return 0; - } - auto writer = new DataLogWriter{std::make_unique(), - JStringRef{env, extraHeader}}; - return reinterpret_cast(writer); -} - -/* - * Class: edu_wpi_first_util_datalog_DataLogJNI - * Method: flush - * Signature: (J)V - */ -JNIEXPORT void JNICALL -Java_edu_wpi_first_util_datalog_DataLogJNI_flush - (JNIEnv* env, jclass, jlong impl) -{ - if (impl == 0) { - wpi::ThrowNullPointerException(env, "impl is null"); - return; - } - reinterpret_cast(impl)->Flush(); -} - -/* - * Class: edu_wpi_first_util_datalog_DataLogJNI - * Method: copyWriteBuffer - * Signature: (J[BI)I - */ -JNIEXPORT jint JNICALL -Java_edu_wpi_first_util_datalog_DataLogJNI_copyWriteBuffer - (JNIEnv* env, jclass, jlong impl, jbyteArray buf, jint start) -{ - if (impl == 0) { - wpi::ThrowNullPointerException(env, "impl is null"); - return 0; - } - auto writer = reinterpret_cast(impl); - writer->Flush(); - auto& stream = static_cast(writer->GetStream()); - JSpan jbuf{env, buf}; - auto arr = stream.array(); - if (start < 0 || static_cast(start) >= arr.size()) { - stream.clear(); - return 0; - } - size_t qty = (std::min)(jbuf.size(), arr.size() - start); - std::copy(arr.begin(), arr.begin() + qty, jbuf.begin()); - return qty; -} - -/* - * Class: edu_wpi_first_util_datalog_DataLogJNI - * Method: pause - * Signature: (J)V - */ -JNIEXPORT void JNICALL -Java_edu_wpi_first_util_datalog_DataLogJNI_pause - (JNIEnv* env, jclass, jlong impl) -{ - if (impl == 0) { - wpi::ThrowNullPointerException(env, "impl is null"); - return; - } - reinterpret_cast(impl)->Pause(); -} - -/* - * Class: edu_wpi_first_util_datalog_DataLogJNI - * Method: resume - * Signature: (J)V - */ -JNIEXPORT void JNICALL -Java_edu_wpi_first_util_datalog_DataLogJNI_resume - (JNIEnv* env, jclass, jlong impl) -{ - if (impl == 0) { - wpi::ThrowNullPointerException(env, "impl is null"); - return; - } - reinterpret_cast(impl)->Resume(); -} - -/* - * Class: edu_wpi_first_util_datalog_DataLogJNI - * Method: stop - * Signature: (J)V - */ -JNIEXPORT void JNICALL -Java_edu_wpi_first_util_datalog_DataLogJNI_stop - (JNIEnv* env, jclass, jlong impl) -{ - if (impl == 0) { - wpi::ThrowNullPointerException(env, "impl is null"); - return; - } - reinterpret_cast(impl)->Stop(); -} - -/* - * Class: edu_wpi_first_util_datalog_DataLogJNI - * Method: addSchema - * Signature: (JLjava/lang/String;Ljava/lang/String;[BJ)V - */ -JNIEXPORT void JNICALL -Java_edu_wpi_first_util_datalog_DataLogJNI_addSchema - (JNIEnv* env, jclass, jlong impl, jstring name, jstring type, - jbyteArray schema, jlong timestamp) -{ - if (impl == 0) { - wpi::ThrowNullPointerException(env, "impl is null"); - return; - } - reinterpret_cast(impl)->AddSchema( - JStringRef{env, name}, JStringRef{env, type}, - JSpan{env, schema}.uarray(), timestamp); -} - -/* - * Class: edu_wpi_first_util_datalog_DataLogJNI - * Method: addSchemaString - * Signature: (JLjava/lang/String;Ljava/lang/String;Ljava/lang/String;J)V - */ -JNIEXPORT void JNICALL -Java_edu_wpi_first_util_datalog_DataLogJNI_addSchemaString - (JNIEnv* env, jclass, jlong impl, jstring name, jstring type, jstring schema, - jlong timestamp) -{ - if (impl == 0) { - wpi::ThrowNullPointerException(env, "impl is null"); - return; - } - JStringRef schemaStr{env, schema}; - std::string_view schemaView = schemaStr.str(); - reinterpret_cast(impl)->AddSchema( - JStringRef{env, name}, JStringRef{env, type}, - {reinterpret_cast(schemaView.data()), schemaView.size()}, - timestamp); -} - -/* - * Class: edu_wpi_first_util_datalog_DataLogJNI - * Method: start - * Signature: (JLjava/lang/String;Ljava/lang/String;Ljava/lang/String;J)I - */ -JNIEXPORT jint JNICALL -Java_edu_wpi_first_util_datalog_DataLogJNI_start - (JNIEnv* env, jclass, jlong impl, jstring name, jstring type, - jstring metadata, jlong timestamp) -{ - if (impl == 0) { - wpi::ThrowNullPointerException(env, "impl is null"); - return 0; - } - return reinterpret_cast(impl)->Start( - JStringRef{env, name}, JStringRef{env, type}, JStringRef{env, metadata}, - timestamp); -} - -/* - * Class: edu_wpi_first_util_datalog_DataLogJNI - * Method: finish - * Signature: (JIJ)V - */ -JNIEXPORT void JNICALL -Java_edu_wpi_first_util_datalog_DataLogJNI_finish - (JNIEnv* env, jclass, jlong impl, jint entry, jlong timestamp) -{ - if (impl == 0) { - wpi::ThrowNullPointerException(env, "impl is null"); - return; - } - reinterpret_cast(impl)->Finish(entry, timestamp); -} - -/* - * Class: edu_wpi_first_util_datalog_DataLogJNI - * Method: setMetadata - * Signature: (JILjava/lang/String;J)V - */ -JNIEXPORT void JNICALL -Java_edu_wpi_first_util_datalog_DataLogJNI_setMetadata - (JNIEnv* env, jclass, jlong impl, jint entry, jstring metadata, - jlong timestamp) -{ - if (impl == 0) { - wpi::ThrowNullPointerException(env, "impl is null"); - return; - } - reinterpret_cast(impl)->SetMetadata( - entry, JStringRef{env, metadata}, timestamp); -} - -/* - * Class: edu_wpi_first_util_datalog_DataLogJNI - * Method: close - * Signature: (J)V - */ -JNIEXPORT void JNICALL -Java_edu_wpi_first_util_datalog_DataLogJNI_close - (JNIEnv*, jclass, jlong impl) -{ - delete reinterpret_cast(impl); -} - -/* - * Class: edu_wpi_first_util_datalog_DataLogJNI - * Method: appendRaw - * Signature: (JI[BIIJ)V - */ -JNIEXPORT void JNICALL -Java_edu_wpi_first_util_datalog_DataLogJNI_appendRaw - (JNIEnv* env, jclass, jlong impl, jint entry, jbyteArray value, jint start, - jint length, jlong timestamp) -{ - if (impl == 0) { - wpi::ThrowNullPointerException(env, "impl is null"); - return; - } - if (!value) { - wpi::ThrowNullPointerException(env, "value is null"); - return; - } - if (start < 0) { - wpi::ThrowIndexOobException(env, "start must be >= 0"); - return; - } - if (length < 0) { - wpi::ThrowIndexOobException(env, "length must be >= 0"); - return; - } - CriticalJSpan cvalue{env, value}; - if (static_cast(start + length) > cvalue.size()) { - wpi::ThrowIndexOobException( - env, "start + len must be smaller than array length"); - return; - } - reinterpret_cast(impl)->AppendRaw( - entry, cvalue.uarray().subspan(start, length), timestamp); -} - -/* - * Class: edu_wpi_first_util_datalog_DataLogJNI - * Method: appendRawBuffer - * Signature: (JILjava/lang/Object;IIJ)V - */ -JNIEXPORT void JNICALL -Java_edu_wpi_first_util_datalog_DataLogJNI_appendRawBuffer - (JNIEnv* env, jclass, jlong impl, jint entry, jobject value, jint start, - jint length, jlong timestamp) -{ - if (impl == 0) { - wpi::ThrowNullPointerException(env, "impl is null"); - return; - } - if (!value) { - wpi::ThrowNullPointerException(env, "value is null"); - return; - } - if (start < 0) { - wpi::ThrowIndexOobException(env, "start must be >= 0"); - return; - } - if (length < 0) { - wpi::ThrowIndexOobException(env, "length must be >= 0"); - return; - } - JSpan cvalue{env, value, static_cast(start + length)}; - if (!cvalue) { - wpi::ThrowIllegalArgumentException(env, - "value must be a native ByteBuffer"); - return; - } - reinterpret_cast(impl)->AppendRaw( - entry, cvalue.uarray().subspan(start, length), timestamp); -} - -/* - * Class: edu_wpi_first_util_datalog_DataLogJNI - * Method: appendBoolean - * Signature: (JIZJ)V - */ -JNIEXPORT void JNICALL -Java_edu_wpi_first_util_datalog_DataLogJNI_appendBoolean - (JNIEnv* env, jclass, jlong impl, jint entry, jboolean value, jlong timestamp) -{ - if (impl == 0) { - wpi::ThrowNullPointerException(env, "impl is null"); - return; - } - reinterpret_cast(impl)->AppendBoolean(entry, value, timestamp); -} - -/* - * Class: edu_wpi_first_util_datalog_DataLogJNI - * Method: appendInteger - * Signature: (JIJJ)V - */ -JNIEXPORT void JNICALL -Java_edu_wpi_first_util_datalog_DataLogJNI_appendInteger - (JNIEnv* env, jclass, jlong impl, jint entry, jlong value, jlong timestamp) -{ - if (impl == 0) { - wpi::ThrowNullPointerException(env, "impl is null"); - return; - } - reinterpret_cast(impl)->AppendInteger(entry, value, timestamp); -} - -/* - * Class: edu_wpi_first_util_datalog_DataLogJNI - * Method: appendFloat - * Signature: (JIFJ)V - */ -JNIEXPORT void JNICALL -Java_edu_wpi_first_util_datalog_DataLogJNI_appendFloat - (JNIEnv* env, jclass, jlong impl, jint entry, jfloat value, jlong timestamp) -{ - if (impl == 0) { - wpi::ThrowNullPointerException(env, "impl is null"); - return; - } - reinterpret_cast(impl)->AppendFloat(entry, value, timestamp); -} - -/* - * Class: edu_wpi_first_util_datalog_DataLogJNI - * Method: appendDouble - * Signature: (JIDJ)V - */ -JNIEXPORT void JNICALL -Java_edu_wpi_first_util_datalog_DataLogJNI_appendDouble - (JNIEnv* env, jclass, jlong impl, jint entry, jdouble value, jlong timestamp) -{ - if (impl == 0) { - wpi::ThrowNullPointerException(env, "impl is null"); - return; - } - reinterpret_cast(impl)->AppendDouble(entry, value, timestamp); -} - -/* - * Class: edu_wpi_first_util_datalog_DataLogJNI - * Method: appendString - * Signature: (JILjava/lang/String;J)V - */ -JNIEXPORT void JNICALL -Java_edu_wpi_first_util_datalog_DataLogJNI_appendString - (JNIEnv* env, jclass, jlong impl, jint entry, jstring value, jlong timestamp) -{ - if (impl == 0) { - wpi::ThrowNullPointerException(env, "impl is null"); - return; - } - reinterpret_cast(impl)->AppendString(entry, JStringRef{env, value}, - timestamp); -} - -/* - * Class: edu_wpi_first_util_datalog_DataLogJNI - * Method: appendBooleanArray - * Signature: (JI[ZJ)V - */ -JNIEXPORT void JNICALL -Java_edu_wpi_first_util_datalog_DataLogJNI_appendBooleanArray - (JNIEnv* env, jclass, jlong impl, jint entry, jbooleanArray value, - jlong timestamp) -{ - if (impl == 0) { - wpi::ThrowNullPointerException(env, "impl is null"); - return; - } - if (!value) { - wpi::ThrowNullPointerException(env, "value is null"); - return; - } - reinterpret_cast(impl)->AppendBooleanArray( - entry, JSpan{env, value}, timestamp); -} - -/* - * Class: edu_wpi_first_util_datalog_DataLogJNI - * Method: appendIntegerArray - * Signature: (JI[JJ)V - */ -JNIEXPORT void JNICALL -Java_edu_wpi_first_util_datalog_DataLogJNI_appendIntegerArray - (JNIEnv* env, jclass, jlong impl, jint entry, jlongArray value, - jlong timestamp) -{ - if (impl == 0) { - wpi::ThrowNullPointerException(env, "impl is null"); - return; - } - if (!value) { - wpi::ThrowNullPointerException(env, "value is null"); - return; - } - JSpan jarr{env, value}; - if constexpr (sizeof(jlong) == sizeof(int64_t)) { - reinterpret_cast(impl)->AppendIntegerArray( - entry, {reinterpret_cast(jarr.data()), jarr.size()}, - timestamp); - } else { - wpi::SmallVector arr; - arr.reserve(jarr.size()); - for (auto v : jarr) { - arr.push_back(v); - } - reinterpret_cast(impl)->AppendIntegerArray(entry, arr, timestamp); - } -} - -/* - * Class: edu_wpi_first_util_datalog_DataLogJNI - * Method: appendFloatArray - * Signature: (JI[FJ)V - */ -JNIEXPORT void JNICALL -Java_edu_wpi_first_util_datalog_DataLogJNI_appendFloatArray - (JNIEnv* env, jclass, jlong impl, jint entry, jfloatArray value, - jlong timestamp) -{ - if (impl == 0) { - wpi::ThrowNullPointerException(env, "impl is null"); - return; - } - if (!value) { - wpi::ThrowNullPointerException(env, "value is null"); - return; - } - reinterpret_cast(impl)->AppendFloatArray( - entry, JSpan{env, value}, timestamp); -} - -/* - * Class: edu_wpi_first_util_datalog_DataLogJNI - * Method: appendDoubleArray - * Signature: (JI[DJ)V - */ -JNIEXPORT void JNICALL -Java_edu_wpi_first_util_datalog_DataLogJNI_appendDoubleArray - (JNIEnv* env, jclass, jlong impl, jint entry, jdoubleArray value, - jlong timestamp) -{ - if (impl == 0) { - wpi::ThrowNullPointerException(env, "impl is null"); - return; - } - if (!value) { - wpi::ThrowNullPointerException(env, "value is null"); - return; - } - reinterpret_cast(impl)->AppendDoubleArray( - entry, JSpan{env, value}, timestamp); -} - -/* - * Class: edu_wpi_first_util_datalog_DataLogJNI - * Method: appendStringArray - * Signature: (JI[Ljava/lang/Object;J)V - */ -JNIEXPORT void JNICALL -Java_edu_wpi_first_util_datalog_DataLogJNI_appendStringArray - (JNIEnv* env, jclass, jlong impl, jint entry, jobjectArray value, - jlong timestamp) -{ - if (impl == 0) { - wpi::ThrowNullPointerException(env, "impl is null"); - return; - } - if (!value) { - wpi::ThrowNullPointerException(env, "value is null"); - return; - } - size_t len = env->GetArrayLength(value); - std::vector arr; - arr.reserve(len); - for (size_t i = 0; i < len; ++i) { - JLocal elem{ - env, static_cast(env->GetObjectArrayElement(value, i))}; - if (!elem) { - wpi::ThrowNullPointerException( - env, fmt::format("string at element {} is null", i)); - return; - } - arr.emplace_back(JStringRef{env, elem}.str()); - } - reinterpret_cast(impl)->AppendStringArray(entry, arr, timestamp); -} - -} // extern "C" diff --git a/wpiutil/src/main/native/cpp/jni/WPIUtilJNI.cpp b/wpiutil/src/main/native/cpp/jni/WPIUtilJNI.cpp index b55100de0ed..7a6051e34c7 100644 --- a/wpiutil/src/main/native/cpp/jni/WPIUtilJNI.cpp +++ b/wpiutil/src/main/native/cpp/jni/WPIUtilJNI.cpp @@ -7,7 +7,6 @@ #include #include "edu_wpi_first_util_WPIUtilJNI.h" -#include "wpi/DataLog.h" #include "wpi/FileLogger.h" #include "wpi/RawFrame.h" #include "wpi/RuntimeCheck.h" diff --git a/wpiutil/src/test/native/cpp/DataLogTest.cpp b/wpiutil/src/test/native/cpp/DataLogTest.cpp deleted file mode 100644 index 149d3a36b78..00000000000 --- a/wpiutil/src/test/native/cpp/DataLogTest.cpp +++ /dev/null @@ -1,674 +0,0 @@ -// Copyright (c) FIRST and other WPILib contributors. -// Open Source Software; you can modify and/or share it under the terms of -// the WPILib BSD license file in the root directory of this project. - -#include -#include -#include -#include - -#include - -#include "wpi/DataLogWriter.h" -#include "wpi/Logger.h" -#include "wpi/raw_ostream.h" - -namespace { -struct ThingA { - int x = 0; -}; - -inline bool operator==(const ThingA& a, const ThingA& b) { - return a.x == b.x; -} - -struct ThingB { - int x = 0; -}; - -struct ThingC { - int x = 0; -}; - -struct Info1 { - int info = 0; -}; - -struct Info2 { - int info = 0; -}; -} // namespace - -template <> -struct wpi::Struct { - static constexpr std::string_view GetTypeName() { return "ThingA"; } - static constexpr size_t GetSize() { return 1; } - static constexpr std::string_view GetSchema() { return "uint8 value"; } - static ThingA Unpack(std::span data) { - return ThingA{.x = data[0]}; - } - static void Pack(std::span data, const ThingA& value) { - data[0] = value.x; - } -}; - -template <> -struct wpi::Struct { - static constexpr std::string_view GetTypeName(const Info1&) { - return "ThingB"; - } - static constexpr size_t GetSize(const Info1&) { return 1; } - static constexpr std::string_view GetSchema(const Info1&) { - return "uint8 value"; - } - static ThingB Unpack(std::span data, const Info1&) { - return ThingB{.x = data[0]}; - } - static void Pack(std::span data, const ThingB& value, const Info1&) { - data[0] = value.x; - } -}; - -template <> -struct wpi::Struct { - static constexpr std::string_view GetTypeName() { return "ThingC"; } - static constexpr size_t GetSize() { return 1; } - static constexpr std::string_view GetSchema() { return "uint8 value"; } - static ThingC Unpack(std::span data) { - return ThingC{.x = data[0]}; - } - static void Pack(std::span data, const ThingC& value) { - data[0] = value.x; - } -}; - -template <> -struct wpi::Struct { - static constexpr std::string_view GetTypeName(const Info1&) { - return "ThingC"; - } - static constexpr size_t GetSize(const Info1&) { return 1; } - static constexpr std::string_view GetSchema(const Info1&) { - return "uint8 value"; - } - static ThingC Unpack(std::span data, const Info1&) { - return ThingC{.x = data[0]}; - } - static void Pack(std::span data, const ThingC& value, const Info1&) { - data[0] = value.x; - } -}; - -template <> -struct wpi::Struct { - static constexpr std::string_view GetTypeName(const Info2&) { - return "ThingC"; - } - static constexpr size_t GetSize(const Info2&) { return 1; } - static constexpr std::string_view GetSchema(const Info2&) { - return "uint8 value"; - } - static ThingC Unpack(std::span data, const Info2&) { - return ThingC{.x = data[0]}; - } - static void Pack(std::span data, const ThingC& value, const Info2&) { - data[0] = value.x; - } -}; - -static_assert(wpi::StructSerializable); -static_assert(!wpi::StructSerializable); - -static_assert(!wpi::StructSerializable); -static_assert(wpi::StructSerializable); -static_assert(!wpi::StructSerializable); - -static_assert(wpi::StructSerializable); -static_assert(wpi::StructSerializable); -static_assert(wpi::StructSerializable); - -class DataLogTest : public ::testing::Test { - public: - wpi::Logger msglog; - std::vector data; - wpi::log::DataLogWriter log{msglog, - std::make_unique(data)}; -}; - -TEST_F(DataLogTest, SimpleInt) { - int entry = log.Start("test", "int64", "", 1); - log.AppendInteger(entry, 1, 2); - log.Flush(); - ASSERT_EQ(data.size(), 54u); -} - -TEST_F(DataLogTest, BooleanAppend) { - wpi::log::BooleanLogEntry entry{log, "a", 5}; - entry.Append(false, 7); - log.Flush(); - ASSERT_EQ(data.size(), 46u); -} - -TEST_F(DataLogTest, BooleanUpdate) { - wpi::log::BooleanLogEntry entry{log, "a", 5}; - ASSERT_FALSE(entry.GetLastValue().has_value()); - entry.Update(false, 7); - log.Flush(); - ASSERT_EQ(data.size(), 46u); - ASSERT_TRUE(entry.GetLastValue().has_value()); - ASSERT_EQ(entry.GetLastValue().value(), false); - entry.Update(false, 8); - log.Flush(); - ASSERT_EQ(data.size(), 46u); - entry.Update(true, 9); - log.Flush(); - ASSERT_EQ(data.size(), 51u); - ASSERT_TRUE(entry.GetLastValue().has_value()); - ASSERT_EQ(entry.GetLastValue().value(), true); -} - -TEST_F(DataLogTest, IntegerAppend) { - wpi::log::IntegerLogEntry entry{log, "a", 5}; - entry.Append(5, 7); - log.Flush(); - ASSERT_EQ(data.size(), 51u); -} - -TEST_F(DataLogTest, IntegerUpdate) { - wpi::log::IntegerLogEntry entry{log, "a", 5}; - ASSERT_FALSE(entry.GetLastValue().has_value()); - entry.Update(0, 7); - log.Flush(); - ASSERT_EQ(data.size(), 51u); - ASSERT_TRUE(entry.GetLastValue().has_value()); - ASSERT_EQ(entry.GetLastValue().value(), 0); - entry.Update(0, 8); - log.Flush(); - ASSERT_EQ(data.size(), 51u); - entry.Update(2, 9); - log.Flush(); - ASSERT_EQ(data.size(), 63u); - ASSERT_TRUE(entry.GetLastValue().has_value()); - ASSERT_EQ(entry.GetLastValue().value(), 2); -} - -TEST_F(DataLogTest, FloatAppend) { - wpi::log::FloatLogEntry entry{log, "a", 5}; - entry.Append(5.0, 7); - log.Flush(); - ASSERT_EQ(data.size(), 47u); -} - -TEST_F(DataLogTest, FloatUpdate) { - wpi::log::FloatLogEntry entry{log, "a", 5}; - ASSERT_FALSE(entry.GetLastValue().has_value()); - entry.Update(0.0f, 7); - log.Flush(); - ASSERT_EQ(data.size(), 47u); - ASSERT_TRUE(entry.GetLastValue().has_value()); - ASSERT_EQ(entry.GetLastValue().value(), 0.0f); - entry.Update(0.0f, 8); - log.Flush(); - ASSERT_EQ(data.size(), 47u); - entry.Update(0.1f, 9); - log.Flush(); - ASSERT_EQ(data.size(), 55u); - ASSERT_TRUE(entry.GetLastValue().has_value()); - ASSERT_EQ(entry.GetLastValue().value(), 0.1f); -} - -TEST_F(DataLogTest, DoubleAppend) { - wpi::log::DoubleLogEntry entry{log, "a", 5}; - entry.Append(5.0, 7); - log.Flush(); - ASSERT_EQ(data.size(), 52u); -} - -TEST_F(DataLogTest, DoubleUpdate) { - wpi::log::DoubleLogEntry entry{log, "a", 5}; - ASSERT_FALSE(entry.GetLastValue().has_value()); - entry.Update(0.0, 7); - log.Flush(); - ASSERT_EQ(data.size(), 52u); - ASSERT_TRUE(entry.GetLastValue().has_value()); - ASSERT_EQ(entry.GetLastValue().value(), 0.0); - entry.Update(0.0, 8); - log.Flush(); - ASSERT_EQ(data.size(), 52u); - entry.Update(0.1, 9); - log.Flush(); - ASSERT_EQ(data.size(), 64u); - ASSERT_TRUE(entry.GetLastValue().has_value()); - ASSERT_EQ(entry.GetLastValue().value(), 0.1); -} - -TEST_F(DataLogTest, StringAppend) { - wpi::log::StringLogEntry entry{log, "a", 5}; - entry.Append("x", 7); - log.Flush(); - ASSERT_EQ(data.size(), 45u); -} - -TEST_F(DataLogTest, StringUpdate) { - wpi::log::StringLogEntry entry{log, "a", 5}; - ASSERT_FALSE(entry.HasLastValue()); - - entry.Update("x", 7); - log.Flush(); - ASSERT_EQ(data.size(), 45u); - ASSERT_TRUE(entry.GetLastValue().has_value()); - ASSERT_EQ(entry.GetLastValue().value(), "x"); - - entry.Update("x", 8); - log.Flush(); - ASSERT_EQ(data.size(), 45u); - - entry.Update("y", 9); - log.Flush(); - ASSERT_EQ(data.size(), 50u); - ASSERT_TRUE(entry.GetLastValue().has_value()); - ASSERT_EQ(entry.GetLastValue().value(), "y"); - - entry.Update("yy", 10); - log.Flush(); - ASSERT_EQ(data.size(), 56u); - ASSERT_TRUE(entry.GetLastValue().has_value()); - ASSERT_EQ(entry.GetLastValue().value(), "yy"); - - entry.Update("", 11); - log.Flush(); - ASSERT_EQ(data.size(), 60u); - ASSERT_TRUE(entry.GetLastValue().has_value()); - ASSERT_EQ(entry.GetLastValue().value(), ""); -} - -TEST_F(DataLogTest, RawAppend) { - wpi::log::RawLogEntry entry{log, "a", 5}; - entry.Append({{5}}, 7); - log.Flush(); - ASSERT_EQ(data.size(), 42u); -} - -TEST_F(DataLogTest, RawUpdate) { - wpi::log::RawLogEntry entry{log, "a", 5}; - ASSERT_FALSE(entry.HasLastValue()); - - entry.Update({{5}}, 7); - log.Flush(); - ASSERT_EQ(data.size(), 42u); - ASSERT_TRUE(entry.GetLastValue().has_value()); - ASSERT_EQ(entry.GetLastValue().value(), std::vector{5}); - - entry.Update({{5}}, 8); - log.Flush(); - ASSERT_EQ(data.size(), 42u); - - entry.Update({{6}}, 9); - log.Flush(); - ASSERT_EQ(data.size(), 47u); - ASSERT_TRUE(entry.GetLastValue().has_value()); - ASSERT_EQ(entry.GetLastValue().value(), std::vector{6}); - - entry.Update({{6, 6}}, 9); - log.Flush(); - ASSERT_EQ(data.size(), 53u); - ASSERT_TRUE(entry.GetLastValue().has_value()); - ASSERT_EQ(entry.GetLastValue().value(), (std::vector{6, 6})); - - entry.Update(std::span{}, 10); - log.Flush(); - ASSERT_EQ(data.size(), 57u); - ASSERT_TRUE(entry.GetLastValue().has_value()); - ASSERT_EQ(entry.GetLastValue().value(), std::vector{}); -} - -TEST_F(DataLogTest, BooleanArrayAppendEmpty) { - wpi::log::BooleanArrayLogEntry entry{log, "a", 5}; - entry.Append(std::span{}, 7); - log.Flush(); - ASSERT_EQ(data.size(), 47u); -} - -TEST_F(DataLogTest, BooleanArrayAppend) { - wpi::log::BooleanArrayLogEntry entry{log, "a", 5}; - entry.Append({false}, 7); - log.Flush(); - ASSERT_EQ(data.size(), 48u); -} - -TEST_F(DataLogTest, BooleanArrayUpdate) { - wpi::log::BooleanArrayLogEntry entry{log, "a", 5}; - ASSERT_FALSE(entry.GetLastValue().has_value()); - entry.Update({false}, 7); - log.Flush(); - ASSERT_EQ(data.size(), 48u); - ASSERT_TRUE(entry.GetLastValue().has_value()); - ASSERT_EQ(entry.GetLastValue().value(), std::vector{false}); - entry.Update({false}, 8); - log.Flush(); - ASSERT_EQ(data.size(), 48u); - entry.Update({true}, 9); - log.Flush(); - ASSERT_EQ(data.size(), 53u); - ASSERT_TRUE(entry.GetLastValue().has_value()); - ASSERT_EQ(entry.GetLastValue().value(), std::vector{true}); - entry.Update(std::span{}, 10); - log.Flush(); - ASSERT_EQ(data.size(), 57u); - ASSERT_TRUE(entry.GetLastValue().has_value()); - ASSERT_EQ(entry.GetLastValue().value(), std::vector{}); -} - -TEST_F(DataLogTest, IntegerArrayAppendEmpty) { - wpi::log::IntegerArrayLogEntry entry{log, "a", 5}; - entry.Append(std::span{}, 7); - log.Flush(); - ASSERT_EQ(data.size(), 45u); -} - -TEST_F(DataLogTest, IntegerArrayAppend) { - wpi::log::IntegerArrayLogEntry entry{log, "a", 5}; - entry.Append({1}, 7); - log.Flush(); - ASSERT_EQ(data.size(), 53u); -} - -TEST_F(DataLogTest, IntegerArrayUpdate) { - wpi::log::IntegerArrayLogEntry entry{log, "a", 5}; - ASSERT_FALSE(entry.GetLastValue().has_value()); - entry.Update({1}, 7); - log.Flush(); - ASSERT_EQ(data.size(), 53u); - ASSERT_TRUE(entry.GetLastValue().has_value()); - ASSERT_EQ(entry.GetLastValue().value(), std::vector{1}); - entry.Update({1}, 8); - log.Flush(); - ASSERT_EQ(data.size(), 53u); - entry.Update({2}, 9); - log.Flush(); - ASSERT_EQ(data.size(), 65u); - ASSERT_TRUE(entry.GetLastValue().has_value()); - ASSERT_EQ(entry.GetLastValue().value(), std::vector{2}); - entry.Update(std::span{}, 10); - log.Flush(); - ASSERT_EQ(data.size(), 69u); - ASSERT_TRUE(entry.GetLastValue().has_value()); - ASSERT_EQ(entry.GetLastValue().value(), std::vector{}); -} - -TEST_F(DataLogTest, DoubleArrayAppendEmpty) { - wpi::log::DoubleArrayLogEntry entry{log, "a", 5}; - entry.Append(std::span{}, 7); - log.Flush(); - ASSERT_EQ(data.size(), 46u); -} - -TEST_F(DataLogTest, DoubleArrayAppend) { - wpi::log::DoubleArrayLogEntry entry{log, "a", 5}; - entry.Append({1.0}, 7); - log.Flush(); - ASSERT_EQ(data.size(), 54u); -} - -TEST_F(DataLogTest, DoubleArrayUpdate) { - wpi::log::DoubleArrayLogEntry entry{log, "a", 5}; - ASSERT_FALSE(entry.GetLastValue().has_value()); - entry.Update({1.0}, 7); - log.Flush(); - ASSERT_EQ(data.size(), 54u); - ASSERT_TRUE(entry.GetLastValue().has_value()); - ASSERT_EQ(entry.GetLastValue().value(), std::vector{1.0}); - entry.Update({1.0}, 8); - log.Flush(); - ASSERT_EQ(data.size(), 54u); - entry.Update({2.0}, 9); - log.Flush(); - ASSERT_EQ(data.size(), 66u); - ASSERT_TRUE(entry.GetLastValue().has_value()); - ASSERT_EQ(entry.GetLastValue().value(), std::vector{2}); - entry.Update(std::span{}, 10); - log.Flush(); - ASSERT_EQ(data.size(), 70u); - ASSERT_TRUE(entry.GetLastValue().has_value()); - ASSERT_EQ(entry.GetLastValue().value(), std::vector{}); -} - -TEST_F(DataLogTest, FloatArrayAppendEmpty) { - wpi::log::FloatArrayLogEntry entry{log, "a", 5}; - entry.Append(std::span{}, 7); - log.Flush(); - ASSERT_EQ(data.size(), 45u); -} - -TEST_F(DataLogTest, FloatArrayAppend) { - wpi::log::FloatArrayLogEntry entry{log, "a", 5}; - entry.Append({1.0f}, 7); - log.Flush(); - ASSERT_EQ(data.size(), 49u); -} - -TEST_F(DataLogTest, FloatArrayUpdate) { - wpi::log::FloatArrayLogEntry entry{log, "a", 5}; - ASSERT_FALSE(entry.GetLastValue().has_value()); - entry.Update({1.0f}, 7); - log.Flush(); - ASSERT_EQ(data.size(), 49u); - ASSERT_TRUE(entry.GetLastValue().has_value()); - ASSERT_EQ(entry.GetLastValue().value(), std::vector{1.0f}); - entry.Update({1.0f}, 8); - log.Flush(); - ASSERT_EQ(data.size(), 49u); - entry.Update({2.0f}, 9); - log.Flush(); - ASSERT_EQ(data.size(), 57u); - ASSERT_TRUE(entry.GetLastValue().has_value()); - ASSERT_EQ(entry.GetLastValue().value(), std::vector{2.0f}); - entry.Update(std::span{}, 10); - log.Flush(); - ASSERT_EQ(data.size(), 61u); - ASSERT_TRUE(entry.GetLastValue().has_value()); - ASSERT_EQ(entry.GetLastValue().value(), std::vector{}); -} - -TEST_F(DataLogTest, StringArrayAppendEmpty) { - wpi::log::StringArrayLogEntry entry{log, "a", 5}; - entry.Append(std::span{}, 7); - entry.Append(std::span{}, 7); - log.Flush(); - ASSERT_EQ(data.size(), 58u); -} - -TEST_F(DataLogTest, StringArrayAppend) { - wpi::log::StringArrayLogEntry entry{log, "a", 5}; - entry.Append({"x"}, 7); - log.Flush(); - ASSERT_EQ(data.size(), 55u); -} - -TEST_F(DataLogTest, StringArrayUpdate) { - wpi::log::StringArrayLogEntry entry{log, "a", 5}; - ASSERT_FALSE(entry.GetLastValue().has_value()); - entry.Update({"x"}, 7); - log.Flush(); - ASSERT_EQ(data.size(), 55u); - ASSERT_TRUE(entry.GetLastValue().has_value()); - ASSERT_EQ(entry.GetLastValue().value(), std::vector{"x"}); - entry.Update({"x"}, 8); - log.Flush(); - ASSERT_EQ(data.size(), 55u); - entry.Update({"y"}, 9); - log.Flush(); - ASSERT_EQ(data.size(), 68u); - ASSERT_TRUE(entry.GetLastValue().has_value()); - ASSERT_EQ(entry.GetLastValue().value(), std::vector{"y"}); - entry.Update(std::span{}, 10); - log.Flush(); - ASSERT_EQ(data.size(), 76u); - ASSERT_TRUE(entry.GetLastValue().has_value()); - ASSERT_EQ(entry.GetLastValue().value(), std::vector{}); -} - -TEST_F(DataLogTest, StructA) { - [[maybe_unused]] - wpi::log::StructLogEntry entry0; - wpi::log::StructLogEntry entry{log, "a", 5}; - entry.Append(ThingA{}); - entry.Append(ThingA{}, 7); -} - -TEST_F(DataLogTest, StructUpdate) { - wpi::log::StructLogEntry entry{log, "a", 5}; - ASSERT_FALSE(entry.GetLastValue().has_value()); - - entry.Update(ThingA{}, 7); - log.Flush(); - ASSERT_EQ(data.size(), 122u); - ASSERT_TRUE(entry.GetLastValue().has_value()); - ASSERT_EQ(entry.GetLastValue().value(), ThingA{}); - - entry.Update(ThingA{}, 8); - log.Flush(); - ASSERT_EQ(data.size(), 122u); - - entry.Update(ThingA{.x = 1}, 9); - log.Flush(); - ASSERT_EQ(data.size(), 127u); - ASSERT_TRUE(entry.GetLastValue().has_value()); - ASSERT_EQ(entry.GetLastValue().value(), ThingA{.x = 1}); -} - -TEST_F(DataLogTest, StructArrayA) { - [[maybe_unused]] - wpi::log::StructArrayLogEntry entry0; - wpi::log::StructArrayLogEntry entry{log, "a", 5}; - entry.Append({{ThingA{}, ThingA{}}}); - entry.Append({{ThingA{}, ThingA{}}}, 7); -} - -TEST_F(DataLogTest, StructArrayUpdate) { - wpi::log::StructArrayLogEntry entry{log, "a", 5}; - ASSERT_FALSE(entry.GetLastValue().has_value()); - - entry.Update({{ThingA{}, ThingA{.x = 1}}}, 7); - log.Flush(); - ASSERT_EQ(data.size(), 125u); - ASSERT_TRUE(entry.GetLastValue().has_value()); - ASSERT_EQ(entry.GetLastValue().value(), - (std::vector{ThingA{}, ThingA{.x = 1}})); - - entry.Update({{ThingA{}, ThingA{.x = 1}}}, 8); - log.Flush(); - ASSERT_EQ(data.size(), 125u); - - entry.Update({{ThingA{}, ThingA{.x = 2}}}, 9); - log.Flush(); - ASSERT_EQ(data.size(), 131u); - ASSERT_TRUE(entry.GetLastValue().has_value()); - ASSERT_EQ(entry.GetLastValue().value(), - (std::vector{ThingA{}, ThingA{.x = 2}})); - - entry.Update(std::span{}, 10); - log.Flush(); - ASSERT_EQ(data.size(), 135u); - ASSERT_TRUE(entry.GetLastValue().has_value()); - ASSERT_EQ(entry.GetLastValue().value(), std::vector{}); -} - -TEST_F(DataLogTest, StructFixedArrayA) { - [[maybe_unused]] - wpi::log::StructArrayLogEntry> entry0; - wpi::log::StructLogEntry> entry{log, "a", 5}; - std::array arr; - entry.Append(arr); - entry.Append(arr, 7); -} - -TEST_F(DataLogTest, StructB) { - Info1 info; - [[maybe_unused]] - wpi::log::StructLogEntry entry0; - wpi::log::StructLogEntry entry{log, "b", info, 5}; - entry.Append(ThingB{}); - entry.Append(ThingB{}, 7); -} - -TEST_F(DataLogTest, StructArrayB) { - Info1 info; - [[maybe_unused]] - wpi::log::StructArrayLogEntry entry0; - wpi::log::StructArrayLogEntry entry{log, "a", info, 5}; - entry.Append({{ThingB{}, ThingB{}}}); - entry.Append({{ThingB{}, ThingB{}}}, 7); -} - -TEST_F(DataLogTest, StructFixedArrayB) { - Info1 info; - wpi::log::StructLogEntry, Info1> entry{log, "a", info, - 5}; - std::array arr; - entry.Append(arr); - entry.Append(arr, 7); -} - -TEST_F(DataLogTest, StructC) { - { - wpi::log::StructLogEntry entry{log, "c", 5}; - entry.Append(ThingC{}); - entry.Append(ThingC{}, 7); - } - { - Info1 info; - wpi::log::StructLogEntry entry{log, "c1", info, 5}; - entry.Append(ThingC{}); - entry.Append(ThingC{}, 7); - } - { - Info2 info; - wpi::log::StructLogEntry entry{log, "c2", info, 5}; - entry.Append(ThingC{}); - entry.Append(ThingC{}, 7); - } -} - -TEST_F(DataLogTest, StructArrayC) { - { - wpi::log::StructArrayLogEntry entry{log, "c", 5}; - entry.Append({{ThingC{}, ThingC{}}}); - entry.Append({{ThingC{}, ThingC{}}}, 7); - } - { - Info1 info; - wpi::log::StructArrayLogEntry entry{log, "c1", info, 5}; - entry.Append({{ThingC{}, ThingC{}}}); - entry.Append({{ThingC{}, ThingC{}}}, 7); - } - { - Info2 info; - wpi::log::StructArrayLogEntry entry{log, "c2", info, 5}; - entry.Append({{ThingC{}, ThingC{}}}); - entry.Append({{ThingC{}, ThingC{}}}, 7); - } -} - -TEST_F(DataLogTest, StructFixedArrayC) { - std::array arr; - { - wpi::log::StructLogEntry> entry{log, "c", 5}; - entry.Append(arr); - entry.Append(arr, 7); - } - { - Info1 info; - wpi::log::StructLogEntry, Info1> entry{log, "c1", - info, 5}; - entry.Append(arr); - entry.Append(arr, 7); - } - { - Info2 info; - wpi::log::StructLogEntry, Info2> entry{log, "c2", - info, 5}; - entry.Append(arr); - entry.Append(arr, 7); - } -} From fd8dcb5a119c539e1ed6d2064170841281fe1506 Mon Sep 17 00:00:00 2001 From: DeltaDizzy Date: Thu, 9 Jan 2025 11:11:26 -0600 Subject: [PATCH 15/64] add build.gradle --- libdatalog/build.gradle | 0 1 file changed, 0 insertions(+), 0 deletions(-) create mode 100644 libdatalog/build.gradle diff --git a/libdatalog/build.gradle b/libdatalog/build.gradle new file mode 100644 index 00000000000..e69de29bb2d From b62a633c8773fbadeac47305e41573d14a60ba23 Mon Sep 17 00:00:00 2001 From: DeltaDizzy Date: Thu, 9 Jan 2025 11:20:32 -0600 Subject: [PATCH 16/64] move tests --- libdatalog/CMakeLists.txt | 18 +++++++++--------- .../edu/wpi/first}/datalog/DataLogTest.java | 2 +- .../{main => }/test/native/cpp/DataLogTest.cpp | 0 .../src/test/native/cpp/FileLoggerTest.cpp | 0 4 files changed, 10 insertions(+), 10 deletions(-) rename {wpiutil/src/test/java/edu/wpi/first/util => libdatalog/src/test/java/edu/wpi/first}/datalog/DataLogTest.java (99%) rename libdatalog/src/{main => }/test/native/cpp/DataLogTest.cpp (100%) rename {wpiutil => libdatalog}/src/test/native/cpp/FileLoggerTest.cpp (100%) diff --git a/libdatalog/CMakeLists.txt b/libdatalog/CMakeLists.txt index ca80ccf1295..d20d7d98ad2 100644 --- a/libdatalog/CMakeLists.txt +++ b/libdatalog/CMakeLists.txt @@ -48,13 +48,13 @@ add_library(libdatalogjni ${libdatalog_jni_src}) wpilib_target_warnings(libdatalogjni) target_link_libraries(libdatalogjni PUBLIC libdatalog) -# if(WITH_TESTS) -# file(GLOB_RECURSE libdatalog_test_src src/test/native/cpp/*.cpp) -# target_sources(libdatalog_test PRIVATE ${libdatalog_test_src}) -# wpilib_add_test(libdatalog src/test/native/cpp) -# target_link_libraries(libdatalog_test libdatalog googletest libdatalog_testlib) -# if(MSVC) -# target_compile_options(libdatalog_test PRIVATE /utf-8) -# endif() -# endif() +if(WITH_TESTS) + file(GLOB_RECURSE libdatalog_test_src src/test/native/cpp/*.cpp) + target_sources(libdatalog_test PRIVATE ${libdatalog_test_src}) + wpilib_add_test(libdatalog src/test/native/cpp) + target_link_libraries(libdatalog_test libdatalog googletest libdatalog_testlib) + if(MSVC) + target_compile_options(libdatalog_test PRIVATE /utf-8) + endif() +endif() diff --git a/wpiutil/src/test/java/edu/wpi/first/util/datalog/DataLogTest.java b/libdatalog/src/test/java/edu/wpi/first/datalog/DataLogTest.java similarity index 99% rename from wpiutil/src/test/java/edu/wpi/first/util/datalog/DataLogTest.java rename to libdatalog/src/test/java/edu/wpi/first/datalog/DataLogTest.java index b6d140bfbd7..217bb7d4094 100644 --- a/wpiutil/src/test/java/edu/wpi/first/util/datalog/DataLogTest.java +++ b/libdatalog/src/test/java/edu/wpi/first/datalog/DataLogTest.java @@ -2,7 +2,7 @@ // Open Source Software; you can modify and/or share it under the terms of // the WPILib BSD license file in the root directory of this project. -package edu.wpi.first.util.datalog; +package edu.wpi.first.datalog; import static org.junit.jupiter.api.Assertions.assertArrayEquals; import static org.junit.jupiter.api.Assertions.assertEquals; diff --git a/libdatalog/src/main/test/native/cpp/DataLogTest.cpp b/libdatalog/src/test/native/cpp/DataLogTest.cpp similarity index 100% rename from libdatalog/src/main/test/native/cpp/DataLogTest.cpp rename to libdatalog/src/test/native/cpp/DataLogTest.cpp diff --git a/wpiutil/src/test/native/cpp/FileLoggerTest.cpp b/libdatalog/src/test/native/cpp/FileLoggerTest.cpp similarity index 100% rename from wpiutil/src/test/native/cpp/FileLoggerTest.cpp rename to libdatalog/src/test/native/cpp/FileLoggerTest.cpp From 402816bd91566e33a3b9aa1eb3fd78694035bca6 Mon Sep 17 00:00:00 2001 From: DeltaDizzy Date: Thu, 9 Jan 2025 11:26:41 -0600 Subject: [PATCH 17/64] fix tests cmake --- libdatalog/CMakeLists.txt | 9 ++++++--- 1 file changed, 6 insertions(+), 3 deletions(-) diff --git a/libdatalog/CMakeLists.txt b/libdatalog/CMakeLists.txt index d20d7d98ad2..0ca79c50b08 100644 --- a/libdatalog/CMakeLists.txt +++ b/libdatalog/CMakeLists.txt @@ -49,12 +49,15 @@ wpilib_target_warnings(libdatalogjni) target_link_libraries(libdatalogjni PUBLIC libdatalog) if(WITH_TESTS) - file(GLOB_RECURSE libdatalog_test_src src/test/native/cpp/*.cpp) - target_sources(libdatalog_test PRIVATE ${libdatalog_test_src}) + file(GLOB_RECURSE libdatalog_testlib_src src/test/native/include/*.h) + add_library(libdatalog_testlib INTERFACE ${libdatalog_test_src}) + target_include_directories(libdatalog_testlib INTERFACE src/test/native/include) + wpilib_add_test(libdatalog src/test/native/cpp) + target_include_directories(libdatalog_test PRIVATE src/generated/test/native/cpp) target_link_libraries(libdatalog_test libdatalog googletest libdatalog_testlib) if(MSVC) - target_compile_options(libdatalog_test PRIVATE /utf-8) + target_compile_options(lobdatalog_test PRIVATE /utf-8) endif() endif() From 48810a465f06c9a5fd84e0dfa49a8934ce0f5af4 Mon Sep 17 00:00:00 2001 From: Jade Turner Date: Fri, 10 Jan 2025 01:23:56 +0800 Subject: [PATCH 18/64] Add gradle build Signed-off-by: Jade Turner --- libdatalog/build.gradle | 27 +++++++++++++++++++ .../java/edu/wpi/first/datalog/DataLog.java | 2 +- .../edu/wpi/first/datalog/FileLogger.java | 2 -- settings.gradle | 1 + 4 files changed, 29 insertions(+), 3 deletions(-) diff --git a/libdatalog/build.gradle b/libdatalog/build.gradle index e69de29bb2d..0f618ce0a23 100644 --- a/libdatalog/build.gradle +++ b/libdatalog/build.gradle @@ -0,0 +1,27 @@ +ext { + useJava = true + useCpp = true + baseId = 'libdatalog' + groupId = 'edu.wpi.first.datalog' + + nativeName = 'libdatalog' + devMain = 'edu.wpi.first.math.DevMain' +} + +apply from: "${rootDir}/shared/jni/setupBuild.gradle" + +model { + components { + all { + it.sources.each { + it.exportedHeaders { + srcDirs 'src/main/native/include' + } + } + } + } +} + +dependencies { + api project(":wpiutil") +} diff --git a/libdatalog/src/main/java/edu/wpi/first/datalog/DataLog.java b/libdatalog/src/main/java/edu/wpi/first/datalog/DataLog.java index 4a89542cb75..fed02a0a49d 100644 --- a/libdatalog/src/main/java/edu/wpi/first/datalog/DataLog.java +++ b/libdatalog/src/main/java/edu/wpi/first/datalog/DataLog.java @@ -2,7 +2,7 @@ // Open Source Software; you can modify and/or share it under the terms of // the WPILib BSD license file in the root directory of this project. -package edu.wpi.first.util.datalog; +package edu.wpi.first.datalog; import edu.wpi.first.util.WPIUtilJNI; import edu.wpi.first.util.protobuf.Protobuf; diff --git a/libdatalog/src/main/java/edu/wpi/first/datalog/FileLogger.java b/libdatalog/src/main/java/edu/wpi/first/datalog/FileLogger.java index 5fff3fc5f23..7dfead47267 100644 --- a/libdatalog/src/main/java/edu/wpi/first/datalog/FileLogger.java +++ b/libdatalog/src/main/java/edu/wpi/first/datalog/FileLogger.java @@ -4,8 +4,6 @@ package edu.wpi.first.datalog; -import edu.wpi.first.datalog.DataLog; - /** * A class version of `tail -f`, otherwise known as `tail -f` at home. Watches a file and puts the * data into a data log. Only works on Linux-based platforms. diff --git a/settings.gradle b/settings.gradle index 45ef87e77d8..3f9f00ae16a 100644 --- a/settings.gradle +++ b/settings.gradle @@ -59,6 +59,7 @@ include 'epilogue-runtime' include 'thirdparty:googletest' include 'thirdparty:imgui_suite' include 'wpical' +include 'libdatalog' buildCache { def cred = { From 6a19dbd09b3502fa5735621c90d6593d918d543e Mon Sep 17 00:00:00 2001 From: DeltaDizzy Date: Thu, 9 Jan 2025 11:31:13 -0600 Subject: [PATCH 19/64] update java datalog package --- .../first/epilogue/logging/FileBackend.java | 30 +++++++++---------- .../first/datalog/BooleanArrayLogEntry.java | 2 +- .../wpi/first/datalog/BooleanLogEntry.java | 2 +- .../datalog/DataLogBackgroundWriter.java | 2 +- .../edu/wpi/first/datalog/DataLogEntry.java | 2 +- .../wpi/first/datalog/DataLogIterator.java | 2 +- .../edu/wpi/first/datalog/DataLogJNI.java | 2 +- .../edu/wpi/first/datalog/DataLogReader.java | 2 +- .../edu/wpi/first/datalog/DataLogRecord.java | 2 +- .../edu/wpi/first/datalog/DataLogWriter.java | 2 +- .../first/datalog/DoubleArrayLogEntry.java | 2 +- .../edu/wpi/first/datalog/DoubleLogEntry.java | 2 +- .../wpi/first/datalog/FloatArrayLogEntry.java | 2 +- .../edu/wpi/first/datalog/FloatLogEntry.java | 2 +- .../first/datalog/IntegerArrayLogEntry.java | 2 +- .../wpi/first/datalog/IntegerLogEntry.java | 2 +- .../wpi/first/datalog/ProtobufLogEntry.java | 2 +- .../edu/wpi/first/datalog/RawLogEntry.java | 2 +- .../first/datalog/StringArrayLogEntry.java | 2 +- .../edu/wpi/first/datalog/StringLogEntry.java | 2 +- .../first/datalog/StructArrayLogEntry.java | 2 +- .../edu/wpi/first/datalog/StructLogEntry.java | 2 +- .../src/printlog/java/printlog/PrintLog.java | 4 +-- .../main/java/NetworkTableInstance.java.jinja | 2 +- .../main/java/NetworkTablesJNI.java.jinja | 2 +- .../networktables/NetworkTableInstance.java | 2 +- .../first/networktables/NetworkTablesJNI.java | 2 +- .../edu/wpi/first/wpilibj/DataLogManager.java | 8 ++--- .../edu/wpi/first/wpilibj/DriverStation.java | 10 +++---- .../first/wpilibj/sysid/SysIdRoutineLog.java | 4 +-- 30 files changed, 53 insertions(+), 53 deletions(-) diff --git a/epilogue-runtime/src/main/java/edu/wpi/first/epilogue/logging/FileBackend.java b/epilogue-runtime/src/main/java/edu/wpi/first/epilogue/logging/FileBackend.java index 2b5b6b2071b..b9fbbb95dcb 100644 --- a/epilogue-runtime/src/main/java/edu/wpi/first/epilogue/logging/FileBackend.java +++ b/epilogue-runtime/src/main/java/edu/wpi/first/epilogue/logging/FileBackend.java @@ -6,21 +6,21 @@ import static edu.wpi.first.util.ErrorMessages.requireNonNullParam; -import edu.wpi.first.util.datalog.BooleanArrayLogEntry; -import edu.wpi.first.util.datalog.BooleanLogEntry; -import edu.wpi.first.util.datalog.DataLog; -import edu.wpi.first.util.datalog.DataLogEntry; -import edu.wpi.first.util.datalog.DoubleArrayLogEntry; -import edu.wpi.first.util.datalog.DoubleLogEntry; -import edu.wpi.first.util.datalog.FloatArrayLogEntry; -import edu.wpi.first.util.datalog.FloatLogEntry; -import edu.wpi.first.util.datalog.IntegerArrayLogEntry; -import edu.wpi.first.util.datalog.IntegerLogEntry; -import edu.wpi.first.util.datalog.RawLogEntry; -import edu.wpi.first.util.datalog.StringArrayLogEntry; -import edu.wpi.first.util.datalog.StringLogEntry; -import edu.wpi.first.util.datalog.StructArrayLogEntry; -import edu.wpi.first.util.datalog.StructLogEntry; +import edu.wpi.first.datalog.BooleanArrayLogEntry; +import edu.wpi.first.datalog.BooleanLogEntry; +import edu.wpi.first.datalog.DataLog; +import edu.wpi.first.datalog.DataLogEntry; +import edu.wpi.first.datalog.DoubleArrayLogEntry; +import edu.wpi.first.datalog.DoubleLogEntry; +import edu.wpi.first.datalog.FloatArrayLogEntry; +import edu.wpi.first.datalog.FloatLogEntry; +import edu.wpi.first.datalog.IntegerArrayLogEntry; +import edu.wpi.first.datalog.IntegerLogEntry; +import edu.wpi.first.datalog.RawLogEntry; +import edu.wpi.first.datalog.StringArrayLogEntry; +import edu.wpi.first.datalog.StringLogEntry; +import edu.wpi.first.datalog.StructArrayLogEntry; +import edu.wpi.first.datalog.StructLogEntry; import edu.wpi.first.util.struct.Struct; import java.util.HashMap; import java.util.Map; diff --git a/libdatalog/src/main/java/edu/wpi/first/datalog/BooleanArrayLogEntry.java b/libdatalog/src/main/java/edu/wpi/first/datalog/BooleanArrayLogEntry.java index 76b85f518c2..01a3fffce15 100644 --- a/libdatalog/src/main/java/edu/wpi/first/datalog/BooleanArrayLogEntry.java +++ b/libdatalog/src/main/java/edu/wpi/first/datalog/BooleanArrayLogEntry.java @@ -2,7 +2,7 @@ // Open Source Software; you can modify and/or share it under the terms of // the WPILib BSD license file in the root directory of this project. -package edu.wpi.first.util.datalog; +package edu.wpi.first.datalog; import java.util.Arrays; diff --git a/libdatalog/src/main/java/edu/wpi/first/datalog/BooleanLogEntry.java b/libdatalog/src/main/java/edu/wpi/first/datalog/BooleanLogEntry.java index ba1783e1618..b037370fcc4 100644 --- a/libdatalog/src/main/java/edu/wpi/first/datalog/BooleanLogEntry.java +++ b/libdatalog/src/main/java/edu/wpi/first/datalog/BooleanLogEntry.java @@ -2,7 +2,7 @@ // Open Source Software; you can modify and/or share it under the terms of // the WPILib BSD license file in the root directory of this project. -package edu.wpi.first.util.datalog; +package edu.wpi.first.datalog; /** Log boolean values. */ public class BooleanLogEntry extends DataLogEntry { diff --git a/libdatalog/src/main/java/edu/wpi/first/datalog/DataLogBackgroundWriter.java b/libdatalog/src/main/java/edu/wpi/first/datalog/DataLogBackgroundWriter.java index 18a6e5e63c6..f9ac427e6a6 100644 --- a/libdatalog/src/main/java/edu/wpi/first/datalog/DataLogBackgroundWriter.java +++ b/libdatalog/src/main/java/edu/wpi/first/datalog/DataLogBackgroundWriter.java @@ -2,7 +2,7 @@ // Open Source Software; you can modify and/or share it under the terms of // the WPILib BSD license file in the root directory of this project. -package edu.wpi.first.util.datalog; +package edu.wpi.first.datalog; /** * A data log background writer that periodically flushes the data log on a background thread. The diff --git a/libdatalog/src/main/java/edu/wpi/first/datalog/DataLogEntry.java b/libdatalog/src/main/java/edu/wpi/first/datalog/DataLogEntry.java index 8502428405e..9c58f94e970 100644 --- a/libdatalog/src/main/java/edu/wpi/first/datalog/DataLogEntry.java +++ b/libdatalog/src/main/java/edu/wpi/first/datalog/DataLogEntry.java @@ -2,7 +2,7 @@ // Open Source Software; you can modify and/or share it under the terms of // the WPILib BSD license file in the root directory of this project. -package edu.wpi.first.util.datalog; +package edu.wpi.first.datalog; /** Log entry base class. */ public class DataLogEntry { diff --git a/libdatalog/src/main/java/edu/wpi/first/datalog/DataLogIterator.java b/libdatalog/src/main/java/edu/wpi/first/datalog/DataLogIterator.java index 3f1d66e72d8..f6579e54a48 100644 --- a/libdatalog/src/main/java/edu/wpi/first/datalog/DataLogIterator.java +++ b/libdatalog/src/main/java/edu/wpi/first/datalog/DataLogIterator.java @@ -2,7 +2,7 @@ // Open Source Software; you can modify and/or share it under the terms of // the WPILib BSD license file in the root directory of this project. -package edu.wpi.first.util.datalog; +package edu.wpi.first.datalog; import java.util.Iterator; import java.util.NoSuchElementException; diff --git a/libdatalog/src/main/java/edu/wpi/first/datalog/DataLogJNI.java b/libdatalog/src/main/java/edu/wpi/first/datalog/DataLogJNI.java index 8b949e55ced..fab19c25ae4 100644 --- a/libdatalog/src/main/java/edu/wpi/first/datalog/DataLogJNI.java +++ b/libdatalog/src/main/java/edu/wpi/first/datalog/DataLogJNI.java @@ -2,7 +2,7 @@ // Open Source Software; you can modify and/or share it under the terms of // the WPILib BSD license file in the root directory of this project. -package edu.wpi.first.util.datalog; +package edu.wpi.first.datalog; import edu.wpi.first.util.WPIUtilJNI; import java.io.IOException; diff --git a/libdatalog/src/main/java/edu/wpi/first/datalog/DataLogReader.java b/libdatalog/src/main/java/edu/wpi/first/datalog/DataLogReader.java index 55eabf3ad74..c58da2dc160 100644 --- a/libdatalog/src/main/java/edu/wpi/first/datalog/DataLogReader.java +++ b/libdatalog/src/main/java/edu/wpi/first/datalog/DataLogReader.java @@ -2,7 +2,7 @@ // Open Source Software; you can modify and/or share it under the terms of // the WPILib BSD license file in the root directory of this project. -package edu.wpi.first.util.datalog; +package edu.wpi.first.datalog; import java.io.IOException; import java.io.RandomAccessFile; diff --git a/libdatalog/src/main/java/edu/wpi/first/datalog/DataLogRecord.java b/libdatalog/src/main/java/edu/wpi/first/datalog/DataLogRecord.java index 5e3965b5aae..cf7f2d2d526 100644 --- a/libdatalog/src/main/java/edu/wpi/first/datalog/DataLogRecord.java +++ b/libdatalog/src/main/java/edu/wpi/first/datalog/DataLogRecord.java @@ -2,7 +2,7 @@ // Open Source Software; you can modify and/or share it under the terms of // the WPILib BSD license file in the root directory of this project. -package edu.wpi.first.util.datalog; +package edu.wpi.first.datalog; import java.nio.BufferUnderflowException; import java.nio.ByteBuffer; diff --git a/libdatalog/src/main/java/edu/wpi/first/datalog/DataLogWriter.java b/libdatalog/src/main/java/edu/wpi/first/datalog/DataLogWriter.java index 058d6dd8a46..ce751d77768 100644 --- a/libdatalog/src/main/java/edu/wpi/first/datalog/DataLogWriter.java +++ b/libdatalog/src/main/java/edu/wpi/first/datalog/DataLogWriter.java @@ -2,7 +2,7 @@ // Open Source Software; you can modify and/or share it under the terms of // the WPILib BSD license file in the root directory of this project. -package edu.wpi.first.util.datalog; +package edu.wpi.first.datalog; import java.io.IOException; import java.io.OutputStream; diff --git a/libdatalog/src/main/java/edu/wpi/first/datalog/DoubleArrayLogEntry.java b/libdatalog/src/main/java/edu/wpi/first/datalog/DoubleArrayLogEntry.java index 2fe528f1bd3..7a9b4943524 100644 --- a/libdatalog/src/main/java/edu/wpi/first/datalog/DoubleArrayLogEntry.java +++ b/libdatalog/src/main/java/edu/wpi/first/datalog/DoubleArrayLogEntry.java @@ -2,7 +2,7 @@ // Open Source Software; you can modify and/or share it under the terms of // the WPILib BSD license file in the root directory of this project. -package edu.wpi.first.util.datalog; +package edu.wpi.first.datalog; import java.util.Arrays; diff --git a/libdatalog/src/main/java/edu/wpi/first/datalog/DoubleLogEntry.java b/libdatalog/src/main/java/edu/wpi/first/datalog/DoubleLogEntry.java index 2484063aba0..e4ec6909af6 100644 --- a/libdatalog/src/main/java/edu/wpi/first/datalog/DoubleLogEntry.java +++ b/libdatalog/src/main/java/edu/wpi/first/datalog/DoubleLogEntry.java @@ -2,7 +2,7 @@ // Open Source Software; you can modify and/or share it under the terms of // the WPILib BSD license file in the root directory of this project. -package edu.wpi.first.util.datalog; +package edu.wpi.first.datalog; /** Log double values. */ public class DoubleLogEntry extends DataLogEntry { diff --git a/libdatalog/src/main/java/edu/wpi/first/datalog/FloatArrayLogEntry.java b/libdatalog/src/main/java/edu/wpi/first/datalog/FloatArrayLogEntry.java index 136b7e5b420..8532e3ab1e0 100644 --- a/libdatalog/src/main/java/edu/wpi/first/datalog/FloatArrayLogEntry.java +++ b/libdatalog/src/main/java/edu/wpi/first/datalog/FloatArrayLogEntry.java @@ -2,7 +2,7 @@ // Open Source Software; you can modify and/or share it under the terms of // the WPILib BSD license file in the root directory of this project. -package edu.wpi.first.util.datalog; +package edu.wpi.first.datalog; import java.util.Arrays; diff --git a/libdatalog/src/main/java/edu/wpi/first/datalog/FloatLogEntry.java b/libdatalog/src/main/java/edu/wpi/first/datalog/FloatLogEntry.java index 8cb02cfafdd..2286a7328c8 100644 --- a/libdatalog/src/main/java/edu/wpi/first/datalog/FloatLogEntry.java +++ b/libdatalog/src/main/java/edu/wpi/first/datalog/FloatLogEntry.java @@ -2,7 +2,7 @@ // Open Source Software; you can modify and/or share it under the terms of // the WPILib BSD license file in the root directory of this project. -package edu.wpi.first.util.datalog; +package edu.wpi.first.datalog; /** Log float values. */ public class FloatLogEntry extends DataLogEntry { diff --git a/libdatalog/src/main/java/edu/wpi/first/datalog/IntegerArrayLogEntry.java b/libdatalog/src/main/java/edu/wpi/first/datalog/IntegerArrayLogEntry.java index 80e2be36d95..1f9c9ff64e3 100644 --- a/libdatalog/src/main/java/edu/wpi/first/datalog/IntegerArrayLogEntry.java +++ b/libdatalog/src/main/java/edu/wpi/first/datalog/IntegerArrayLogEntry.java @@ -2,7 +2,7 @@ // Open Source Software; you can modify and/or share it under the terms of // the WPILib BSD license file in the root directory of this project. -package edu.wpi.first.util.datalog; +package edu.wpi.first.datalog; import java.util.Arrays; diff --git a/libdatalog/src/main/java/edu/wpi/first/datalog/IntegerLogEntry.java b/libdatalog/src/main/java/edu/wpi/first/datalog/IntegerLogEntry.java index 25f491cc035..0b807e70e97 100644 --- a/libdatalog/src/main/java/edu/wpi/first/datalog/IntegerLogEntry.java +++ b/libdatalog/src/main/java/edu/wpi/first/datalog/IntegerLogEntry.java @@ -2,7 +2,7 @@ // Open Source Software; you can modify and/or share it under the terms of // the WPILib BSD license file in the root directory of this project. -package edu.wpi.first.util.datalog; +package edu.wpi.first.datalog; /** Log integer values. */ public class IntegerLogEntry extends DataLogEntry { diff --git a/libdatalog/src/main/java/edu/wpi/first/datalog/ProtobufLogEntry.java b/libdatalog/src/main/java/edu/wpi/first/datalog/ProtobufLogEntry.java index 9108e56bbf9..f91cc47bf4b 100644 --- a/libdatalog/src/main/java/edu/wpi/first/datalog/ProtobufLogEntry.java +++ b/libdatalog/src/main/java/edu/wpi/first/datalog/ProtobufLogEntry.java @@ -2,7 +2,7 @@ // Open Source Software; you can modify and/or share it under the terms of // the WPILib BSD license file in the root directory of this project. -package edu.wpi.first.util.datalog; +package edu.wpi.first.datalog; import edu.wpi.first.util.protobuf.Protobuf; import edu.wpi.first.util.protobuf.ProtobufBuffer; diff --git a/libdatalog/src/main/java/edu/wpi/first/datalog/RawLogEntry.java b/libdatalog/src/main/java/edu/wpi/first/datalog/RawLogEntry.java index 9ab59e9659c..b2a29b9b270 100644 --- a/libdatalog/src/main/java/edu/wpi/first/datalog/RawLogEntry.java +++ b/libdatalog/src/main/java/edu/wpi/first/datalog/RawLogEntry.java @@ -2,7 +2,7 @@ // Open Source Software; you can modify and/or share it under the terms of // the WPILib BSD license file in the root directory of this project. -package edu.wpi.first.util.datalog; +package edu.wpi.first.datalog; import java.nio.ByteBuffer; import java.util.Arrays; diff --git a/libdatalog/src/main/java/edu/wpi/first/datalog/StringArrayLogEntry.java b/libdatalog/src/main/java/edu/wpi/first/datalog/StringArrayLogEntry.java index 0218502fc04..f93603833c4 100644 --- a/libdatalog/src/main/java/edu/wpi/first/datalog/StringArrayLogEntry.java +++ b/libdatalog/src/main/java/edu/wpi/first/datalog/StringArrayLogEntry.java @@ -2,7 +2,7 @@ // Open Source Software; you can modify and/or share it under the terms of // the WPILib BSD license file in the root directory of this project. -package edu.wpi.first.util.datalog; +package edu.wpi.first.datalog; import java.util.Arrays; diff --git a/libdatalog/src/main/java/edu/wpi/first/datalog/StringLogEntry.java b/libdatalog/src/main/java/edu/wpi/first/datalog/StringLogEntry.java index 523abd6646b..367c0c89861 100644 --- a/libdatalog/src/main/java/edu/wpi/first/datalog/StringLogEntry.java +++ b/libdatalog/src/main/java/edu/wpi/first/datalog/StringLogEntry.java @@ -2,7 +2,7 @@ // Open Source Software; you can modify and/or share it under the terms of // the WPILib BSD license file in the root directory of this project. -package edu.wpi.first.util.datalog; +package edu.wpi.first.datalog; /** Log string values. */ public class StringLogEntry extends DataLogEntry { diff --git a/libdatalog/src/main/java/edu/wpi/first/datalog/StructArrayLogEntry.java b/libdatalog/src/main/java/edu/wpi/first/datalog/StructArrayLogEntry.java index 43d69b10f10..1fcd6f05d1d 100644 --- a/libdatalog/src/main/java/edu/wpi/first/datalog/StructArrayLogEntry.java +++ b/libdatalog/src/main/java/edu/wpi/first/datalog/StructArrayLogEntry.java @@ -2,7 +2,7 @@ // Open Source Software; you can modify and/or share it under the terms of // the WPILib BSD license file in the root directory of this project. -package edu.wpi.first.util.datalog; +package edu.wpi.first.datalog; import edu.wpi.first.util.struct.Struct; import edu.wpi.first.util.struct.StructBuffer; diff --git a/libdatalog/src/main/java/edu/wpi/first/datalog/StructLogEntry.java b/libdatalog/src/main/java/edu/wpi/first/datalog/StructLogEntry.java index c7bdf0a8589..1d0351e7fcf 100644 --- a/libdatalog/src/main/java/edu/wpi/first/datalog/StructLogEntry.java +++ b/libdatalog/src/main/java/edu/wpi/first/datalog/StructLogEntry.java @@ -2,7 +2,7 @@ // Open Source Software; you can modify and/or share it under the terms of // the WPILib BSD license file in the root directory of this project. -package edu.wpi.first.util.datalog; +package edu.wpi.first.datalog; import edu.wpi.first.util.struct.Struct; import edu.wpi.first.util.struct.StructBuffer; diff --git a/libdatalog/src/printlog/java/printlog/PrintLog.java b/libdatalog/src/printlog/java/printlog/PrintLog.java index c0074df0b7c..739e5ec187b 100644 --- a/libdatalog/src/printlog/java/printlog/PrintLog.java +++ b/libdatalog/src/printlog/java/printlog/PrintLog.java @@ -4,8 +4,8 @@ package printlog; -import edu.wpi.first.util.datalog.DataLogReader; -import edu.wpi.first.util.datalog.DataLogRecord; +import edu.wpi.first.datalog.DataLogReader; +import edu.wpi.first.datalog.DataLogRecord; import java.io.IOException; import java.time.LocalDateTime; import java.time.ZoneOffset; diff --git a/ntcore/src/generate/main/java/NetworkTableInstance.java.jinja b/ntcore/src/generate/main/java/NetworkTableInstance.java.jinja index 50883074a3d..43003c871a9 100644 --- a/ntcore/src/generate/main/java/NetworkTableInstance.java.jinja +++ b/ntcore/src/generate/main/java/NetworkTableInstance.java.jinja @@ -8,7 +8,7 @@ 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.datalog.DataLog; import edu.wpi.first.util.protobuf.Protobuf; import edu.wpi.first.util.struct.Struct; import java.nio.charset.StandardCharsets; diff --git a/ntcore/src/generate/main/java/NetworkTablesJNI.java.jinja b/ntcore/src/generate/main/java/NetworkTablesJNI.java.jinja index c63515d3e0d..2553f5f0b23 100644 --- a/ntcore/src/generate/main/java/NetworkTablesJNI.java.jinja +++ b/ntcore/src/generate/main/java/NetworkTablesJNI.java.jinja @@ -7,7 +7,7 @@ package edu.wpi.first.networktables; import edu.wpi.first.util.RuntimeLoader; -import edu.wpi.first.util.datalog.DataLog; +import edu.wpi.first.datalog.DataLog; import java.io.IOException; import java.nio.ByteBuffer; import java.util.EnumSet; diff --git a/ntcore/src/generated/main/java/edu/wpi/first/networktables/NetworkTableInstance.java b/ntcore/src/generated/main/java/edu/wpi/first/networktables/NetworkTableInstance.java index 5b116148f77..5f94eaf3ad0 100644 --- a/ntcore/src/generated/main/java/edu/wpi/first/networktables/NetworkTableInstance.java +++ b/ntcore/src/generated/main/java/edu/wpi/first/networktables/NetworkTableInstance.java @@ -8,7 +8,7 @@ import edu.wpi.first.util.WPIUtilJNI; import edu.wpi.first.util.concurrent.Event; -import edu.wpi.first.util.datalog.DataLog; +import edu.wpi.first.datalog.DataLog; import edu.wpi.first.util.protobuf.Protobuf; import edu.wpi.first.util.struct.Struct; import java.nio.charset.StandardCharsets; diff --git a/ntcore/src/generated/main/java/edu/wpi/first/networktables/NetworkTablesJNI.java b/ntcore/src/generated/main/java/edu/wpi/first/networktables/NetworkTablesJNI.java index 4fddd9f51f3..4cd6594844f 100644 --- a/ntcore/src/generated/main/java/edu/wpi/first/networktables/NetworkTablesJNI.java +++ b/ntcore/src/generated/main/java/edu/wpi/first/networktables/NetworkTablesJNI.java @@ -7,7 +7,7 @@ package edu.wpi.first.networktables; import edu.wpi.first.util.RuntimeLoader; -import edu.wpi.first.util.datalog.DataLog; +import edu.wpi.first.datalog.DataLog; import java.io.IOException; import java.nio.ByteBuffer; import java.util.EnumSet; diff --git a/wpilibj/src/main/java/edu/wpi/first/wpilibj/DataLogManager.java b/wpilibj/src/main/java/edu/wpi/first/wpilibj/DataLogManager.java index 53e8b84c2d2..e395493f9cc 100644 --- a/wpilibj/src/main/java/edu/wpi/first/wpilibj/DataLogManager.java +++ b/wpilibj/src/main/java/edu/wpi/first/wpilibj/DataLogManager.java @@ -11,10 +11,10 @@ import edu.wpi.first.util.FileLogger; import edu.wpi.first.util.WPIUtilJNI; import edu.wpi.first.util.concurrent.Event; -import edu.wpi.first.util.datalog.DataLog; -import edu.wpi.first.util.datalog.DataLogBackgroundWriter; -import edu.wpi.first.util.datalog.IntegerLogEntry; -import edu.wpi.first.util.datalog.StringLogEntry; +import edu.wpi.first.datalog.DataLog; +import edu.wpi.first.datalog.DataLogBackgroundWriter; +import edu.wpi.first.datalog.IntegerLogEntry; +import edu.wpi.first.datalog.StringLogEntry; import java.io.File; import java.io.IOException; import java.nio.file.Files; diff --git a/wpilibj/src/main/java/edu/wpi/first/wpilibj/DriverStation.java b/wpilibj/src/main/java/edu/wpi/first/wpilibj/DriverStation.java index 36721e355aa..a29d6c661b5 100644 --- a/wpilibj/src/main/java/edu/wpi/first/wpilibj/DriverStation.java +++ b/wpilibj/src/main/java/edu/wpi/first/wpilibj/DriverStation.java @@ -16,11 +16,11 @@ import edu.wpi.first.networktables.StringTopic; import edu.wpi.first.util.EventVector; import edu.wpi.first.util.WPIUtilJNI; -import edu.wpi.first.util.datalog.BooleanArrayLogEntry; -import edu.wpi.first.util.datalog.BooleanLogEntry; -import edu.wpi.first.util.datalog.DataLog; -import edu.wpi.first.util.datalog.FloatArrayLogEntry; -import edu.wpi.first.util.datalog.IntegerArrayLogEntry; +import edu.wpi.first.datalog.BooleanArrayLogEntry; +import edu.wpi.first.datalog.BooleanLogEntry; +import edu.wpi.first.datalog.DataLog; +import edu.wpi.first.datalog.FloatArrayLogEntry; +import edu.wpi.first.datalog.IntegerArrayLogEntry; import java.nio.ByteBuffer; import java.util.Map; import java.util.Optional; diff --git a/wpilibj/src/main/java/edu/wpi/first/wpilibj/sysid/SysIdRoutineLog.java b/wpilibj/src/main/java/edu/wpi/first/wpilibj/sysid/SysIdRoutineLog.java index 82c9ed9b05f..468e586bdcc 100644 --- a/wpilibj/src/main/java/edu/wpi/first/wpilibj/sysid/SysIdRoutineLog.java +++ b/wpilibj/src/main/java/edu/wpi/first/wpilibj/sysid/SysIdRoutineLog.java @@ -20,8 +20,8 @@ import edu.wpi.first.units.measure.LinearAcceleration; import edu.wpi.first.units.measure.LinearVelocity; import edu.wpi.first.units.measure.Voltage; -import edu.wpi.first.util.datalog.DoubleLogEntry; -import edu.wpi.first.util.datalog.StringLogEntry; +import edu.wpi.first.datalog.DoubleLogEntry; +import edu.wpi.first.datalog.StringLogEntry; import edu.wpi.first.wpilibj.DataLogManager; import java.util.HashMap; import java.util.Map; From f7d73cb4d11d078ac2e9d7368e3dc075f6eae92f Mon Sep 17 00:00:00 2001 From: DeltaDizzy Date: Thu, 9 Jan 2025 11:34:15 -0600 Subject: [PATCH 20/64] import wpiutil jni --- libdatalog/src/main/java/edu/wpi/first/datalog/FileLogger.java | 2 ++ 1 file changed, 2 insertions(+) diff --git a/libdatalog/src/main/java/edu/wpi/first/datalog/FileLogger.java b/libdatalog/src/main/java/edu/wpi/first/datalog/FileLogger.java index 7dfead47267..ad746429541 100644 --- a/libdatalog/src/main/java/edu/wpi/first/datalog/FileLogger.java +++ b/libdatalog/src/main/java/edu/wpi/first/datalog/FileLogger.java @@ -4,6 +4,8 @@ package edu.wpi.first.datalog; +import edu.wpi.first.util.WPIUtilJNI; + /** * A class version of `tail -f`, otherwise known as `tail -f` at home. Watches a file and puts the * data into a data log. Only works on Linux-based platforms. From a1da409854a3db4b0586e0da64946e4c851ff945 Mon Sep 17 00:00:00 2001 From: DeltaDizzy Date: Thu, 9 Jan 2025 11:39:37 -0600 Subject: [PATCH 21/64] add datalog to ntcore gradle --- ntcore/build.gradle | 2 ++ 1 file changed, 2 insertions(+) diff --git a/ntcore/build.gradle b/ntcore/build.gradle index 937c2d11b81..09cbf38d460 100644 --- a/ntcore/build.gradle +++ b/ntcore/build.gradle @@ -34,9 +34,11 @@ model { if (it.component.name == "${nativeName}JNI") { lib project: ':wpinet', library: 'wpinet', linkage: 'static' lib project: ':wpiutil', library: 'wpiutil', linkage: 'static' + lib project: ':libdatalog', library 'libdatalog', linkage: 'static' } else { lib project: ':wpinet', library: 'wpinet', linkage: 'shared' lib project: ':wpiutil', library: 'wpiutil', linkage: 'shared' + lib project: ':libdatalog', library 'libdatalog', linkage: 'shared' } } } From 0e0e2edeff9e4d1f0d54470d3f31388c19f6f306 Mon Sep 17 00:00:00 2001 From: DeltaDizzy Date: Thu, 9 Jan 2025 13:56:58 -0600 Subject: [PATCH 22/64] gradle updates --- epilogue-runtime/build.gradle | 1 + libdatalog/CMakeLists.txt | 101 +- libdatalog/build.gradle | 34 +- libdatalog/libdatalog-config.cmake.in | 5 + .../src/main/native/cpp/jni/DataLogJNI.cpp | 1268 +++++++++-------- ntcore/build.gradle | 4 +- .../src/main/native/cpp/jni/WPIUtilJNI.cpp | 39 - 7 files changed, 788 insertions(+), 664 deletions(-) create mode 100644 libdatalog/libdatalog-config.cmake.in diff --git a/epilogue-runtime/build.gradle b/epilogue-runtime/build.gradle index fb96095a0a5..615ab3e510b 100644 --- a/epilogue-runtime/build.gradle +++ b/epilogue-runtime/build.gradle @@ -13,4 +13,5 @@ dependencies { api(project(':ntcore')) api(project(':wpiutil')) api(project(':wpiunits')) + api(project(':libdatalog')) } diff --git a/libdatalog/CMakeLists.txt b/libdatalog/CMakeLists.txt index 0ca79c50b08..d89c428a3ca 100644 --- a/libdatalog/CMakeLists.txt +++ b/libdatalog/CMakeLists.txt @@ -3,7 +3,7 @@ project(libdatalog) include(CompileWarnings) file( - GLOB libdatalog_src + GLOB libdatalog_native_src src/main/native/cpp/*.cpp ) @@ -11,8 +11,9 @@ file( GLOB libdatalog_jni_src src/main/native/cpp/jni/DataLogJNI.cpp ) +list(REMOVE_ITEM libdatalog_native_src ${libdatalog_jni_src}) -add_library(libdatalog ${libdatalog_src}) +add_library(libdatalog ${libdatalog_native_src}) set_target_properties(libdatalog PROPERTIES DEBUG_POSTFIX "d") target_compile_features(libdatalog PUBLIC cxx_std_20) @@ -44,9 +45,99 @@ foreach(example ${libdatalog_examples}) endif() endforeach() -add_library(libdatalogjni ${libdatalog_jni_src}) -wpilib_target_warnings(libdatalogjni) -target_link_libraries(libdatalogjni PUBLIC libdatalog) +# Java bindings +if(WITH_JAVA) + include(UseJava) + + # if(NOT EXISTS "${WPILIB_BINARY_DIR}/wpiutil/thirdparty/jackson/jackson-core-2.15.2.jar") + # set(BASE_URL "https://search.maven.org/remotecontent?filepath=") + # set(JAR_ROOT "${WPILIB_BINARY_DIR}/wpiutil/thirdparty/jackson") + + # message(STATUS "Downloading Jackson jarfiles...") + + # download_and_check( + # "${BASE_URL}com/fasterxml/jackson/core/jackson-core/2.15.2/jackson-core-2.15.2.jar" + # "${JAR_ROOT}/jackson-core-2.15.2.jar" + # ) + # download_and_check( + # "${BASE_URL}com/fasterxml/jackson/core/jackson-databind/2.15.2/jackson-databind-2.15.2.jar" + # "${JAR_ROOT}/jackson-databind-2.15.2.jar" + # ) + # download_and_check( + # "${BASE_URL}com/fasterxml/jackson/core/jackson-annotations/2.15.2/jackson-annotations-2.15.2.jar" + # "${JAR_ROOT}/jackson-annotations-2.15.2.jar" + # ) + + # message(STATUS "All files downloaded.") + # endif() + + # file(GLOB JACKSON_JARS ${WPILIB_BINARY_DIR}/wpiutil/thirdparty/jackson/*.jar) + + # if(NOT EXISTS "${WPILIB_BINARY_DIR}/wpiutil/thirdparty/quickbuf/quickbuf-runtime-1.3.3.jar") + # set(BASE_URL "https://search.maven.org/remotecontent?filepath=") + # set(JAR_ROOT "${WPILIB_BINARY_DIR}/wpiutil/thirdparty/quickbuf") + + # message(STATUS "Downloading Quickbuf jarfile...") + # download_and_check( + # "${BASE_URL}us/hebi/quickbuf/quickbuf-runtime/1.3.3/quickbuf-runtime-1.3.3.jar" + # "${JAR_ROOT}/quickbuf-runtime-1.3.3.jar" + # ) + + # message(STATUS "Downloaded.") + # endif() + + # file(GLOB QUICKBUF_JAR ${WPILIB_BINARY_DIR}/wpiutil/thirdparty/quickbuf/*.jar) + + set(CMAKE_JNI_TARGET true) + + file(GLOB_RECURSE JAVA_SOURCES src/main/java/*.java) + + add_jar( + libdatalog_jar + ${JAVA_SOURCES} + # INCLUDE_JARS ${JACKSON_JARS} ${QUICKBUF_JAR} + OUTPUT_NAME libdatalog + OUTPUT_DIR ${WPILIB_BINARY_DIR}/${java_lib_dest} + GENERATE_NATIVE_HEADERS libdatalog_jni_headers + ) + set_property(TARGET libdatalog_jar PROPERTY FOLDER "java") + + install_jar(libdatalog_jar DESTINATION ${java_lib_dest}) + install_jar_exports(TARGETS libdatalog_jar FILE libdatalog_jar.cmake DESTINATION share/libdatalog) + + add_library(libdatalogjni ${libdatalog_jni_src}) + wpilib_target_warnings(libdatalogjni) + target_link_libraries(libdatalogjni PUBLIC libdatalog wpiutil) + + set_property(TARGET libdatalogjni PROPERTY FOLDER "libraries") + + target_link_libraries(libdatalogjni PRIVATE libdatalog_jni_headers) + add_dependencies(libdatalogjni libdatalog_jar) + + install(TARGETS libdatalogjni EXPORT libdatalogjni) + export(TARGETS libdatalogjni FILE libdatalogjni.cmake NAMESPACE libdatalogjni::) +endif() + +if(WITH_JAVA_SOURCE) + include(UseJava) + include(CreateSourceJar) + add_source_jar( + libdatalog_src_jar + BASE_DIRECTORIES ${CMAKE_CURRENT_SOURCE_DIR}/src/main/java + OUTPUT_NAME libdatalog-sources + OUTPUT_DIR ${WPILIB_BINARY_DIR}/${java_lib_dest} + ) + set_property(TARGET libdatalog_src_jar PROPERTY FOLDER "java") + + install_jar(libdatalog_src_jar DESTINATION ${java_lib_dest}) +endif() + +install(TARGETS libdatalog EXPORT libdatalog) +export(TARGETS libdatalog FILE libdatalog.cmake NAMESPACE libdatalog::) + +configure_file(libdatalog-config.cmake.in ${WPILIB_BINARY_DIR}/libdatalog-config.cmake) +install(FILES ${WPILIB_BINARY_DIR}/libdatalog-config.cmake DESTINATION share/libdatalog) +install(EXPORT libdatalog DESTINATION share/libdatalog) if(WITH_TESTS) file(GLOB_RECURSE libdatalog_testlib_src src/test/native/include/*.h) diff --git a/libdatalog/build.gradle b/libdatalog/build.gradle index 0f618ce0a23..0a4081458fd 100644 --- a/libdatalog/build.gradle +++ b/libdatalog/build.gradle @@ -18,10 +18,38 @@ model { srcDirs 'src/main/native/include' } } + if (!it.buildable || !(it instanceof NativeBinarySpec)) { + return + } + if (it.component.name == "${nativeName}JNI") { + lib project ':wpiutil', library: 'wpiutil', linkage: 'static' + } else { + lib project: ':wpiutil', library: 'wpiutil', linkage: 'shared' + } } } } -dependencies { - api project(":wpiutil") -} +// model { +// components {} +// binaries { +// all { +// if (!it.buildable || !(it instanceof NativeBinarySpec)) { +// return +// } +// if (it.component.name == "${nativeName}JNI") { +// lib project: ':wpinet', library: 'wpinet', linkage: 'static' +// lib project: ':wpiutil', library: 'wpiutil', linkage: 'static' +// lib project: ':libdatalog', library: 'libdatalog', linkage: 'static' +// } else { +// lib project: ':wpinet', library: 'wpinet', linkage: 'shared' +// lib project: ':wpiutil', library: 'wpiutil', linkage: 'shared' +// lib project: ':libdatalog', library: 'libdatalog', linkage: 'shared' +// } +// } +// } +// } + +// dependencies { +// api project(":wpiutil") +// } diff --git a/libdatalog/libdatalog-config.cmake.in b/libdatalog/libdatalog-config.cmake.in new file mode 100644 index 00000000000..04e55b994b7 --- /dev/null +++ b/libdatalog/libdatalog-config.cmake.in @@ -0,0 +1,5 @@ +@FILENAME_DEP_REPLACE@ +include(${SELF_DIR}/wpiutil.cmake) +if(@WITH_JAVA@) + include(${SELF_DIR}/wpiutil_jar.cmake) +endif() \ No newline at end of file diff --git a/libdatalog/src/main/native/cpp/jni/DataLogJNI.cpp b/libdatalog/src/main/native/cpp/jni/DataLogJNI.cpp index dd1b574120c..e9fc20c8386 100644 --- a/libdatalog/src/main/native/cpp/jni/DataLogJNI.cpp +++ b/libdatalog/src/main/native/cpp/jni/DataLogJNI.cpp @@ -1,615 +1,653 @@ -// // Copyright (c) FIRST and other WPILib contributors. -// // Open Source Software; you can modify and/or share it under the terms of -// // the WPILib BSD license file in the root directory of this project. - -// #include - -// #include -// #include -// #include - -// #include - -// #include "WPIUtilJNI.h" -// #include "edu_wpi_first_util_datalog_DataLogJNI.h" -// #include "wpi/DataLog.h" -// #include "wpi/DataLogBackgroundWriter.h" -// #include "wpi/DataLogWriter.h" -// #include "wpi/jni_util.h" - -// using namespace wpi::java; -// using namespace wpi::log; - -// namespace { -// class buf_ostream : public wpi::raw_uvector_ostream { -// private: -// std::vector data; - -// public: -// buf_ostream() : raw_uvector_ostream{data} {} - -// void clear() { data.clear(); } -// }; -// } // namespace - -// extern "C" { - -// /* -// * Class: edu_wpi_first_util_datalog_DataLogJNI -// * Method: bgCreate -// * Signature: (Ljava/lang/String;Ljava/lang/String;DLjava/lang/String;)J -// */ -// JNIEXPORT jlong JNICALL -// Java_edu_wpi_first_util_datalog_DataLogJNI_bgCreate -// (JNIEnv* env, jclass, jstring dir, jstring filename, jdouble period, -// jstring extraHeader) -// { -// if (!dir) { -// wpi::ThrowNullPointerException(env, "dir is null"); -// return 0; -// } -// if (!filename) { -// wpi::ThrowNullPointerException(env, "filename is null"); -// return 0; -// } -// if (!extraHeader) { -// wpi::ThrowNullPointerException(env, "extraHeader is null"); -// return 0; -// } -// return reinterpret_cast(new DataLogBackgroundWriter{ -// JStringRef{env, dir}, JStringRef{env, filename}, period, -// JStringRef{env, extraHeader}}); -// } - -// /* -// * Class: edu_wpi_first_util_datalog_DataLogJNI -// * Method: bgSetFilename -// * Signature: (JLjava/lang/String;)V -// */ -// JNIEXPORT void JNICALL -// Java_edu_wpi_first_util_datalog_DataLogJNI_bgSetFilename -// (JNIEnv* env, jclass, jlong impl, jstring filename) -// { -// if (impl == 0) { -// wpi::ThrowNullPointerException(env, "impl is null"); -// return; -// } -// if (!filename) { -// wpi::ThrowNullPointerException(env, "filename is null"); -// return; -// } -// reinterpret_cast(impl)->SetFilename( -// JStringRef{env, filename}); -// } - -// /* -// * Class: edu_wpi_first_util_datalog_DataLogJNI -// * Method: fgCreate -// * Signature: (Ljava/lang/String;Ljava/lang/String;)J -// */ -// JNIEXPORT jlong JNICALL -// Java_edu_wpi_first_util_datalog_DataLogJNI_fgCreate -// (JNIEnv* env, jclass, jstring filename, jstring extraHeader) -// { -// if (!filename) { -// wpi::ThrowNullPointerException(env, "filename is null"); -// return 0; -// } -// if (!extraHeader) { -// wpi::ThrowNullPointerException(env, "extraHeader is null"); -// return 0; -// } -// std::error_code ec; -// auto writer = new DataLogWriter{JStringRef{env, filename}, ec, -// JStringRef{env, extraHeader}}; -// if (ec) { -// wpi::ThrowIOException(env, ec.message()); -// delete writer; -// return 0; -// } -// return reinterpret_cast(writer); -// } - -// /* -// * Class: edu_wpi_first_util_datalog_DataLogJNI -// * Method: fgCreateMemory -// * Signature: (Ljava/lang/String;)J -// */ -// JNIEXPORT jlong JNICALL -// Java_edu_wpi_first_util_datalog_DataLogJNI_fgCreateMemory -// (JNIEnv* env, jclass, jstring extraHeader) -// { -// if (!extraHeader) { -// wpi::ThrowNullPointerException(env, "extraHeader is null"); -// return 0; -// } -// auto writer = new DataLogWriter{std::make_unique(), -// JStringRef{env, extraHeader}}; -// return reinterpret_cast(writer); -// } - -// /* -// * Class: edu_wpi_first_util_datalog_DataLogJNI -// * Method: flush -// * Signature: (J)V -// */ -// JNIEXPORT void JNICALL -// Java_edu_wpi_first_util_datalog_DataLogJNI_flush -// (JNIEnv* env, jclass, jlong impl) -// { -// if (impl == 0) { -// wpi::ThrowNullPointerException(env, "impl is null"); -// return; -// } -// reinterpret_cast(impl)->Flush(); -// } - -// /* -// * Class: edu_wpi_first_util_datalog_DataLogJNI -// * Method: copyWriteBuffer -// * Signature: (J[BI)I -// */ -// JNIEXPORT jint JNICALL -// Java_edu_wpi_first_util_datalog_DataLogJNI_copyWriteBuffer -// (JNIEnv* env, jclass, jlong impl, jbyteArray buf, jint start) -// { -// if (impl == 0) { -// wpi::ThrowNullPointerException(env, "impl is null"); -// return 0; -// } -// auto writer = reinterpret_cast(impl); -// writer->Flush(); -// auto& stream = static_cast(writer->GetStream()); -// JSpan jbuf{env, buf}; -// auto arr = stream.array(); -// if (start < 0 || static_cast(start) >= arr.size()) { -// stream.clear(); -// return 0; -// } -// size_t qty = (std::min)(jbuf.size(), arr.size() - start); -// std::copy(arr.begin(), arr.begin() + qty, jbuf.begin()); -// return qty; -// } - -// /* -// * Class: edu_wpi_first_util_datalog_DataLogJNI -// * Method: pause -// * Signature: (J)V -// */ -// JNIEXPORT void JNICALL -// Java_edu_wpi_first_util_datalog_DataLogJNI_pause -// (JNIEnv* env, jclass, jlong impl) -// { -// if (impl == 0) { -// wpi::ThrowNullPointerException(env, "impl is null"); -// return; -// } -// reinterpret_cast(impl)->Pause(); -// } - -// /* -// * Class: edu_wpi_first_util_datalog_DataLogJNI -// * Method: resume -// * Signature: (J)V -// */ -// JNIEXPORT void JNICALL -// Java_edu_wpi_first_util_datalog_DataLogJNI_resume -// (JNIEnv* env, jclass, jlong impl) -// { -// if (impl == 0) { -// wpi::ThrowNullPointerException(env, "impl is null"); -// return; -// } -// reinterpret_cast(impl)->Resume(); -// } - -// /* -// * Class: edu_wpi_first_util_datalog_DataLogJNI -// * Method: stop -// * Signature: (J)V -// */ -// JNIEXPORT void JNICALL -// Java_edu_wpi_first_util_datalog_DataLogJNI_stop -// (JNIEnv* env, jclass, jlong impl) -// { -// if (impl == 0) { -// wpi::ThrowNullPointerException(env, "impl is null"); -// return; -// } -// reinterpret_cast(impl)->Stop(); -// } - -// /* -// * Class: edu_wpi_first_util_datalog_DataLogJNI -// * Method: addSchema -// * Signature: (JLjava/lang/String;Ljava/lang/String;[BJ)V -// */ -// JNIEXPORT void JNICALL -// Java_edu_wpi_first_util_datalog_DataLogJNI_addSchema -// (JNIEnv* env, jclass, jlong impl, jstring name, jstring type, -// jbyteArray schema, jlong timestamp) -// { -// if (impl == 0) { -// wpi::ThrowNullPointerException(env, "impl is null"); -// return; -// } -// reinterpret_cast(impl)->AddSchema( -// JStringRef{env, name}, JStringRef{env, type}, -// JSpan{env, schema}.uarray(), timestamp); -// } - -// /* -// * Class: edu_wpi_first_util_datalog_DataLogJNI -// * Method: addSchemaString -// * Signature: (JLjava/lang/String;Ljava/lang/String;Ljava/lang/String;J)V -// */ -// JNIEXPORT void JNICALL -// Java_edu_wpi_first_util_datalog_DataLogJNI_addSchemaString -// (JNIEnv* env, jclass, jlong impl, jstring name, jstring type, jstring schema, -// jlong timestamp) -// { -// if (impl == 0) { -// wpi::ThrowNullPointerException(env, "impl is null"); -// return; -// } -// JStringRef schemaStr{env, schema}; -// std::string_view schemaView = schemaStr.str(); -// reinterpret_cast(impl)->AddSchema( -// JStringRef{env, name}, JStringRef{env, type}, -// {reinterpret_cast(schemaView.data()), schemaView.size()}, -// timestamp); -// } - -// /* -// * Class: edu_wpi_first_util_datalog_DataLogJNI -// * Method: start -// * Signature: (JLjava/lang/String;Ljava/lang/String;Ljava/lang/String;J)I -// */ -// JNIEXPORT jint JNICALL -// Java_edu_wpi_first_util_datalog_DataLogJNI_start -// (JNIEnv* env, jclass, jlong impl, jstring name, jstring type, -// jstring metadata, jlong timestamp) -// { -// if (impl == 0) { -// wpi::ThrowNullPointerException(env, "impl is null"); -// return 0; -// } -// return reinterpret_cast(impl)->Start( -// JStringRef{env, name}, JStringRef{env, type}, JStringRef{env, metadata}, -// timestamp); -// } - -// /* -// * Class: edu_wpi_first_util_datalog_DataLogJNI -// * Method: finish -// * Signature: (JIJ)V -// */ -// JNIEXPORT void JNICALL -// Java_edu_wpi_first_util_datalog_DataLogJNI_finish -// (JNIEnv* env, jclass, jlong impl, jint entry, jlong timestamp) -// { -// if (impl == 0) { -// wpi::ThrowNullPointerException(env, "impl is null"); -// return; -// } -// reinterpret_cast(impl)->Finish(entry, timestamp); -// } - -// /* -// * Class: edu_wpi_first_util_datalog_DataLogJNI -// * Method: setMetadata -// * Signature: (JILjava/lang/String;J)V -// */ -// JNIEXPORT void JNICALL -// Java_edu_wpi_first_util_datalog_DataLogJNI_setMetadata -// (JNIEnv* env, jclass, jlong impl, jint entry, jstring metadata, -// jlong timestamp) -// { -// if (impl == 0) { -// wpi::ThrowNullPointerException(env, "impl is null"); -// return; -// } -// reinterpret_cast(impl)->SetMetadata( -// entry, JStringRef{env, metadata}, timestamp); -// } - -// /* -// * Class: edu_wpi_first_util_datalog_DataLogJNI -// * Method: close -// * Signature: (J)V -// */ -// JNIEXPORT void JNICALL -// Java_edu_wpi_first_util_datalog_DataLogJNI_close -// (JNIEnv*, jclass, jlong impl) -// { -// delete reinterpret_cast(impl); -// } - -// /* -// * Class: edu_wpi_first_util_datalog_DataLogJNI -// * Method: appendRaw -// * Signature: (JI[BIIJ)V -// */ -// JNIEXPORT void JNICALL -// Java_edu_wpi_first_util_datalog_DataLogJNI_appendRaw -// (JNIEnv* env, jclass, jlong impl, jint entry, jbyteArray value, jint start, -// jint length, jlong timestamp) -// { -// if (impl == 0) { -// wpi::ThrowNullPointerException(env, "impl is null"); -// return; -// } -// if (!value) { -// wpi::ThrowNullPointerException(env, "value is null"); -// return; -// } -// if (start < 0) { -// wpi::ThrowIndexOobException(env, "start must be >= 0"); -// return; -// } -// if (length < 0) { -// wpi::ThrowIndexOobException(env, "length must be >= 0"); -// return; -// } -// CriticalJSpan cvalue{env, value}; -// if (static_cast(start + length) > cvalue.size()) { -// wpi::ThrowIndexOobException( -// env, "start + len must be smaller than array length"); -// return; -// } -// reinterpret_cast(impl)->AppendRaw( -// entry, cvalue.uarray().subspan(start, length), timestamp); -// } - -// /* -// * Class: edu_wpi_first_util_datalog_DataLogJNI -// * Method: appendRawBuffer -// * Signature: (JILjava/lang/Object;IIJ)V -// */ -// JNIEXPORT void JNICALL -// Java_edu_wpi_first_util_datalog_DataLogJNI_appendRawBuffer -// (JNIEnv* env, jclass, jlong impl, jint entry, jobject value, jint start, -// jint length, jlong timestamp) -// { -// if (impl == 0) { -// wpi::ThrowNullPointerException(env, "impl is null"); -// return; -// } -// if (!value) { -// wpi::ThrowNullPointerException(env, "value is null"); -// return; -// } -// if (start < 0) { -// wpi::ThrowIndexOobException(env, "start must be >= 0"); -// return; -// } -// if (length < 0) { -// wpi::ThrowIndexOobException(env, "length must be >= 0"); -// return; -// } -// JSpan cvalue{env, value, static_cast(start + length)}; -// if (!cvalue) { -// wpi::ThrowIllegalArgumentException(env, -// "value must be a native ByteBuffer"); -// return; -// } -// reinterpret_cast(impl)->AppendRaw( -// entry, cvalue.uarray().subspan(start, length), timestamp); -// } - -// /* -// * Class: edu_wpi_first_util_datalog_DataLogJNI -// * Method: appendBoolean -// * Signature: (JIZJ)V -// */ -// JNIEXPORT void JNICALL -// Java_edu_wpi_first_util_datalog_DataLogJNI_appendBoolean -// (JNIEnv* env, jclass, jlong impl, jint entry, jboolean value, jlong timestamp) -// { -// if (impl == 0) { -// wpi::ThrowNullPointerException(env, "impl is null"); -// return; -// } -// reinterpret_cast(impl)->AppendBoolean(entry, value, timestamp); -// } - -// /* -// * Class: edu_wpi_first_util_datalog_DataLogJNI -// * Method: appendInteger -// * Signature: (JIJJ)V -// */ -// JNIEXPORT void JNICALL -// Java_edu_wpi_first_util_datalog_DataLogJNI_appendInteger -// (JNIEnv* env, jclass, jlong impl, jint entry, jlong value, jlong timestamp) -// { -// if (impl == 0) { -// wpi::ThrowNullPointerException(env, "impl is null"); -// return; -// } -// reinterpret_cast(impl)->AppendInteger(entry, value, timestamp); -// } - -// /* -// * Class: edu_wpi_first_util_datalog_DataLogJNI -// * Method: appendFloat -// * Signature: (JIFJ)V -// */ -// JNIEXPORT void JNICALL -// Java_edu_wpi_first_util_datalog_DataLogJNI_appendFloat -// (JNIEnv* env, jclass, jlong impl, jint entry, jfloat value, jlong timestamp) -// { -// if (impl == 0) { -// wpi::ThrowNullPointerException(env, "impl is null"); -// return; -// } -// reinterpret_cast(impl)->AppendFloat(entry, value, timestamp); -// } - -// /* -// * Class: edu_wpi_first_util_datalog_DataLogJNI -// * Method: appendDouble -// * Signature: (JIDJ)V -// */ -// JNIEXPORT void JNICALL -// Java_edu_wpi_first_util_datalog_DataLogJNI_appendDouble -// (JNIEnv* env, jclass, jlong impl, jint entry, jdouble value, jlong timestamp) -// { -// if (impl == 0) { -// wpi::ThrowNullPointerException(env, "impl is null"); -// return; -// } -// reinterpret_cast(impl)->AppendDouble(entry, value, timestamp); -// } - -// /* -// * Class: edu_wpi_first_util_datalog_DataLogJNI -// * Method: appendString -// * Signature: (JILjava/lang/String;J)V -// */ -// JNIEXPORT void JNICALL -// Java_edu_wpi_first_util_datalog_DataLogJNI_appendString -// (JNIEnv* env, jclass, jlong impl, jint entry, jstring value, jlong timestamp) -// { -// if (impl == 0) { -// wpi::ThrowNullPointerException(env, "impl is null"); -// return; -// } -// reinterpret_cast(impl)->AppendString(entry, JStringRef{env, value}, -// timestamp); -// } - -// /* -// * Class: edu_wpi_first_util_datalog_DataLogJNI -// * Method: appendBooleanArray -// * Signature: (JI[ZJ)V -// */ -// JNIEXPORT void JNICALL -// Java_edu_wpi_first_util_datalog_DataLogJNI_appendBooleanArray -// (JNIEnv* env, jclass, jlong impl, jint entry, jbooleanArray value, -// jlong timestamp) -// { -// if (impl == 0) { -// wpi::ThrowNullPointerException(env, "impl is null"); -// return; -// } -// if (!value) { -// wpi::ThrowNullPointerException(env, "value is null"); -// return; -// } -// reinterpret_cast(impl)->AppendBooleanArray( -// entry, JSpan{env, value}, timestamp); -// } - -// /* -// * Class: edu_wpi_first_util_datalog_DataLogJNI -// * Method: appendIntegerArray -// * Signature: (JI[JJ)V -// */ -// JNIEXPORT void JNICALL -// Java_edu_wpi_first_util_datalog_DataLogJNI_appendIntegerArray -// (JNIEnv* env, jclass, jlong impl, jint entry, jlongArray value, -// jlong timestamp) -// { -// if (impl == 0) { -// wpi::ThrowNullPointerException(env, "impl is null"); -// return; -// } -// if (!value) { -// wpi::ThrowNullPointerException(env, "value is null"); -// return; -// } -// JSpan jarr{env, value}; -// if constexpr (sizeof(jlong) == sizeof(int64_t)) { -// reinterpret_cast(impl)->AppendIntegerArray( -// entry, {reinterpret_cast(jarr.data()), jarr.size()}, -// timestamp); -// } else { -// wpi::SmallVector arr; -// arr.reserve(jarr.size()); -// for (auto v : jarr) { -// arr.push_back(v); -// } -// reinterpret_cast(impl)->AppendIntegerArray(entry, arr, timestamp); -// } -// } - -// /* -// * Class: edu_wpi_first_util_datalog_DataLogJNI -// * Method: appendFloatArray -// * Signature: (JI[FJ)V -// */ -// JNIEXPORT void JNICALL -// Java_edu_wpi_first_util_datalog_DataLogJNI_appendFloatArray -// (JNIEnv* env, jclass, jlong impl, jint entry, jfloatArray value, -// jlong timestamp) -// { -// if (impl == 0) { -// wpi::ThrowNullPointerException(env, "impl is null"); -// return; -// } -// if (!value) { -// wpi::ThrowNullPointerException(env, "value is null"); -// return; -// } -// reinterpret_cast(impl)->AppendFloatArray( -// entry, JSpan{env, value}, timestamp); -// } - -// /* -// * Class: edu_wpi_first_util_datalog_DataLogJNI -// * Method: appendDoubleArray -// * Signature: (JI[DJ)V -// */ -// JNIEXPORT void JNICALL -// Java_edu_wpi_first_util_datalog_DataLogJNI_appendDoubleArray -// (JNIEnv* env, jclass, jlong impl, jint entry, jdoubleArray value, -// jlong timestamp) -// { -// if (impl == 0) { -// wpi::ThrowNullPointerException(env, "impl is null"); -// return; -// } -// if (!value) { -// wpi::ThrowNullPointerException(env, "value is null"); -// return; -// } -// reinterpret_cast(impl)->AppendDoubleArray( -// entry, JSpan{env, value}, timestamp); -// } - -// /* -// * Class: edu_wpi_first_util_datalog_DataLogJNI -// * Method: appendStringArray -// * Signature: (JI[Ljava/lang/Object;J)V -// */ -// JNIEXPORT void JNICALL -// Java_edu_wpi_first_util_datalog_DataLogJNI_appendStringArray -// (JNIEnv* env, jclass, jlong impl, jint entry, jobjectArray value, -// jlong timestamp) -// { -// if (impl == 0) { -// wpi::ThrowNullPointerException(env, "impl is null"); -// return; -// } -// if (!value) { -// wpi::ThrowNullPointerException(env, "value is null"); -// return; -// } -// size_t len = env->GetArrayLength(value); -// std::vector arr; -// arr.reserve(len); -// for (size_t i = 0; i < len; ++i) { -// JLocal elem{ -// env, static_cast(env->GetObjectArrayElement(value, i))}; -// if (!elem) { -// wpi::ThrowNullPointerException( -// env, fmt::format("string at element {} is null", i)); -// return; -// } -// arr.emplace_back(JStringRef{env, elem}.str()); -// } -// reinterpret_cast(impl)->AppendStringArray(entry, arr, timestamp); -// } - -// } // extern "C" -// TODO: get JNI working +// Copyright (c) FIRST and other WPILib contributors. +// Open Source Software; you can modify and/or share it under the terms of +// the WPILib BSD license file in the root directory of this project. + +#include +#include "WPIUtilJNI.h" + +#include "wpi/FileLogger.h" + + +#include +#include +#include + +#include + +#include "edu_wpi_first_util_datalog_DataLogJNI.h" +#include "wpi/DataLog.h" +#include "wpi/DataLogBackgroundWriter.h" +#include "wpi/DataLogWriter.h" +#include "wpi/jni_util.h" + +using namespace wpi::java; +using namespace wpi::log; + +namespace { +class buf_ostream : public wpi::raw_uvector_ostream { + private: + std::vector data; + + public: + buf_ostream() : raw_uvector_ostream{data} {} + + void clear() { data.clear(); } +}; +} // namespace + +extern "C" { + +/* + * Class: edu_wpi_first_util_datalog_DataLogJNI + * Method: bgCreate + * Signature: (Ljava/lang/String;Ljava/lang/String;DLjava/lang/String;)J + */ +JNIEXPORT jlong JNICALL +Java_edu_wpi_first_util_datalog_DataLogJNI_bgCreate + (JNIEnv* env, jclass, jstring dir, jstring filename, jdouble period, + jstring extraHeader) +{ + if (!dir) { + wpi::ThrowNullPointerException(env, "dir is null"); + return 0; + } + if (!filename) { + wpi::ThrowNullPointerException(env, "filename is null"); + return 0; + } + if (!extraHeader) { + wpi::ThrowNullPointerException(env, "extraHeader is null"); + return 0; + } + return reinterpret_cast(new DataLogBackgroundWriter{ + JStringRef{env, dir}, JStringRef{env, filename}, period, + JStringRef{env, extraHeader}}); +} + +/* + * Class: edu_wpi_first_util_datalog_DataLogJNI + * Method: bgSetFilename + * Signature: (JLjava/lang/String;)V + */ +JNIEXPORT void JNICALL +Java_edu_wpi_first_util_datalog_DataLogJNI_bgSetFilename + (JNIEnv* env, jclass, jlong impl, jstring filename) +{ + if (impl == 0) { + wpi::ThrowNullPointerException(env, "impl is null"); + return; + } + if (!filename) { + wpi::ThrowNullPointerException(env, "filename is null"); + return; + } + reinterpret_cast(impl)->SetFilename( + JStringRef{env, filename}); +} + +/* + * Class: edu_wpi_first_util_datalog_DataLogJNI + * Method: fgCreate + * Signature: (Ljava/lang/String;Ljava/lang/String;)J + */ +JNIEXPORT jlong JNICALL +Java_edu_wpi_first_util_datalog_DataLogJNI_fgCreate + (JNIEnv* env, jclass, jstring filename, jstring extraHeader) +{ + if (!filename) { + wpi::ThrowNullPointerException(env, "filename is null"); + return 0; + } + if (!extraHeader) { + wpi::ThrowNullPointerException(env, "extraHeader is null"); + return 0; + } + std::error_code ec; + auto writer = new DataLogWriter{JStringRef{env, filename}, ec, + JStringRef{env, extraHeader}}; + if (ec) { + wpi::ThrowIOException(env, ec.message()); + delete writer; + return 0; + } + return reinterpret_cast(writer); +} + +/* + * Class: edu_wpi_first_util_datalog_DataLogJNI + * Method: fgCreateMemory + * Signature: (Ljava/lang/String;)J + */ +JNIEXPORT jlong JNICALL +Java_edu_wpi_first_util_datalog_DataLogJNI_fgCreateMemory + (JNIEnv* env, jclass, jstring extraHeader) +{ + if (!extraHeader) { + wpi::ThrowNullPointerException(env, "extraHeader is null"); + return 0; + } + auto writer = new DataLogWriter{std::make_unique(), + JStringRef{env, extraHeader}}; + return reinterpret_cast(writer); +} + +/* + * Class: edu_wpi_first_util_datalog_DataLogJNI + * Method: flush + * Signature: (J)V + */ +JNIEXPORT void JNICALL +Java_edu_wpi_first_util_datalog_DataLogJNI_flush + (JNIEnv* env, jclass, jlong impl) +{ + if (impl == 0) { + wpi::ThrowNullPointerException(env, "impl is null"); + return; + } + reinterpret_cast(impl)->Flush(); +} + +/* + * Class: edu_wpi_first_util_datalog_DataLogJNI + * Method: copyWriteBuffer + * Signature: (J[BI)I + */ +JNIEXPORT jint JNICALL +Java_edu_wpi_first_util_datalog_DataLogJNI_copyWriteBuffer + (JNIEnv* env, jclass, jlong impl, jbyteArray buf, jint start) +{ + if (impl == 0) { + wpi::ThrowNullPointerException(env, "impl is null"); + return 0; + } + auto writer = reinterpret_cast(impl); + writer->Flush(); + auto& stream = static_cast(writer->GetStream()); + JSpan jbuf{env, buf}; + auto arr = stream.array(); + if (start < 0 || static_cast(start) >= arr.size()) { + stream.clear(); + return 0; + } + size_t qty = (std::min)(jbuf.size(), arr.size() - start); + std::copy(arr.begin(), arr.begin() + qty, jbuf.begin()); + return qty; +} + +/* + * Class: edu_wpi_first_util_datalog_DataLogJNI + * Method: pause + * Signature: (J)V + */ +JNIEXPORT void JNICALL +Java_edu_wpi_first_util_datalog_DataLogJNI_pause + (JNIEnv* env, jclass, jlong impl) +{ + if (impl == 0) { + wpi::ThrowNullPointerException(env, "impl is null"); + return; + } + reinterpret_cast(impl)->Pause(); +} + +/* + * Class: edu_wpi_first_util_datalog_DataLogJNI + * Method: resume + * Signature: (J)V + */ +JNIEXPORT void JNICALL +Java_edu_wpi_first_util_datalog_DataLogJNI_resume + (JNIEnv* env, jclass, jlong impl) +{ + if (impl == 0) { + wpi::ThrowNullPointerException(env, "impl is null"); + return; + } + reinterpret_cast(impl)->Resume(); +} + +/* + * Class: edu_wpi_first_util_datalog_DataLogJNI + * Method: stop + * Signature: (J)V + */ +JNIEXPORT void JNICALL +Java_edu_wpi_first_util_datalog_DataLogJNI_stop + (JNIEnv* env, jclass, jlong impl) +{ + if (impl == 0) { + wpi::ThrowNullPointerException(env, "impl is null"); + return; + } + reinterpret_cast(impl)->Stop(); +} + +/* + * Class: edu_wpi_first_util_datalog_DataLogJNI + * Method: addSchema + * Signature: (JLjava/lang/String;Ljava/lang/String;[BJ)V + */ +JNIEXPORT void JNICALL +Java_edu_wpi_first_util_datalog_DataLogJNI_addSchema + (JNIEnv* env, jclass, jlong impl, jstring name, jstring type, + jbyteArray schema, jlong timestamp) +{ + if (impl == 0) { + wpi::ThrowNullPointerException(env, "impl is null"); + return; + } + reinterpret_cast(impl)->AddSchema( + JStringRef{env, name}, JStringRef{env, type}, + JSpan{env, schema}.uarray(), timestamp); +} + +/* + * Class: edu_wpi_first_util_datalog_DataLogJNI + * Method: addSchemaString + * Signature: (JLjava/lang/String;Ljava/lang/String;Ljava/lang/String;J)V + */ +JNIEXPORT void JNICALL +Java_edu_wpi_first_util_datalog_DataLogJNI_addSchemaString + (JNIEnv* env, jclass, jlong impl, jstring name, jstring type, jstring schema, + jlong timestamp) +{ + if (impl == 0) { + wpi::ThrowNullPointerException(env, "impl is null"); + return; + } + JStringRef schemaStr{env, schema}; + std::string_view schemaView = schemaStr.str(); + reinterpret_cast(impl)->AddSchema( + JStringRef{env, name}, JStringRef{env, type}, + {reinterpret_cast(schemaView.data()), schemaView.size()}, + timestamp); +} + +/* + * Class: edu_wpi_first_util_datalog_DataLogJNI + * Method: start + * Signature: (JLjava/lang/String;Ljava/lang/String;Ljava/lang/String;J)I + */ +JNIEXPORT jint JNICALL +Java_edu_wpi_first_util_datalog_DataLogJNI_start + (JNIEnv* env, jclass, jlong impl, jstring name, jstring type, + jstring metadata, jlong timestamp) +{ + if (impl == 0) { + wpi::ThrowNullPointerException(env, "impl is null"); + return 0; + } + return reinterpret_cast(impl)->Start( + JStringRef{env, name}, JStringRef{env, type}, JStringRef{env, metadata}, + timestamp); +} + +/* + * Class: edu_wpi_first_util_datalog_DataLogJNI + * Method: finish + * Signature: (JIJ)V + */ +JNIEXPORT void JNICALL +Java_edu_wpi_first_util_datalog_DataLogJNI_finish + (JNIEnv* env, jclass, jlong impl, jint entry, jlong timestamp) +{ + if (impl == 0) { + wpi::ThrowNullPointerException(env, "impl is null"); + return; + } + reinterpret_cast(impl)->Finish(entry, timestamp); +} + +/* + * Class: edu_wpi_first_util_datalog_DataLogJNI + * Method: setMetadata + * Signature: (JILjava/lang/String;J)V + */ +JNIEXPORT void JNICALL +Java_edu_wpi_first_util_datalog_DataLogJNI_setMetadata + (JNIEnv* env, jclass, jlong impl, jint entry, jstring metadata, + jlong timestamp) +{ + if (impl == 0) { + wpi::ThrowNullPointerException(env, "impl is null"); + return; + } + reinterpret_cast(impl)->SetMetadata( + entry, JStringRef{env, metadata}, timestamp); +} + +/* + * Class: edu_wpi_first_util_datalog_DataLogJNI + * Method: close + * Signature: (J)V + */ +JNIEXPORT void JNICALL +Java_edu_wpi_first_util_datalog_DataLogJNI_close + (JNIEnv*, jclass, jlong impl) +{ + delete reinterpret_cast(impl); +} + +/* + * Class: edu_wpi_first_util_datalog_DataLogJNI + * Method: appendRaw + * Signature: (JI[BIIJ)V + */ +JNIEXPORT void JNICALL +Java_edu_wpi_first_util_datalog_DataLogJNI_appendRaw + (JNIEnv* env, jclass, jlong impl, jint entry, jbyteArray value, jint start, + jint length, jlong timestamp) +{ + if (impl == 0) { + wpi::ThrowNullPointerException(env, "impl is null"); + return; + } + if (!value) { + wpi::ThrowNullPointerException(env, "value is null"); + return; + } + if (start < 0) { + wpi::ThrowIndexOobException(env, "start must be >= 0"); + return; + } + if (length < 0) { + wpi::ThrowIndexOobException(env, "length must be >= 0"); + return; + } + CriticalJSpan cvalue{env, value}; + if (static_cast(start + length) > cvalue.size()) { + wpi::ThrowIndexOobException( + env, "start + len must be smaller than array length"); + return; + } + reinterpret_cast(impl)->AppendRaw( + entry, cvalue.uarray().subspan(start, length), timestamp); +} + +/* + * Class: edu_wpi_first_util_datalog_DataLogJNI + * Method: appendRawBuffer + * Signature: (JILjava/lang/Object;IIJ)V + */ +JNIEXPORT void JNICALL +Java_edu_wpi_first_util_datalog_DataLogJNI_appendRawBuffer + (JNIEnv* env, jclass, jlong impl, jint entry, jobject value, jint start, + jint length, jlong timestamp) +{ + if (impl == 0) { + wpi::ThrowNullPointerException(env, "impl is null"); + return; + } + if (!value) { + wpi::ThrowNullPointerException(env, "value is null"); + return; + } + if (start < 0) { + wpi::ThrowIndexOobException(env, "start must be >= 0"); + return; + } + if (length < 0) { + wpi::ThrowIndexOobException(env, "length must be >= 0"); + return; + } + JSpan cvalue{env, value, static_cast(start + length)}; + if (!cvalue) { + wpi::ThrowIllegalArgumentException(env, + "value must be a native ByteBuffer"); + return; + } + reinterpret_cast(impl)->AppendRaw( + entry, cvalue.uarray().subspan(start, length), timestamp); +} + +/* + * Class: edu_wpi_first_util_datalog_DataLogJNI + * Method: appendBoolean + * Signature: (JIZJ)V + */ +JNIEXPORT void JNICALL +Java_edu_wpi_first_util_datalog_DataLogJNI_appendBoolean + (JNIEnv* env, jclass, jlong impl, jint entry, jboolean value, jlong timestamp) +{ + if (impl == 0) { + wpi::ThrowNullPointerException(env, "impl is null"); + return; + } + reinterpret_cast(impl)->AppendBoolean(entry, value, timestamp); +} + +/* + * Class: edu_wpi_first_util_datalog_DataLogJNI + * Method: appendInteger + * Signature: (JIJJ)V + */ +JNIEXPORT void JNICALL +Java_edu_wpi_first_util_datalog_DataLogJNI_appendInteger + (JNIEnv* env, jclass, jlong impl, jint entry, jlong value, jlong timestamp) +{ + if (impl == 0) { + wpi::ThrowNullPointerException(env, "impl is null"); + return; + } + reinterpret_cast(impl)->AppendInteger(entry, value, timestamp); +} + +/* + * Class: edu_wpi_first_util_datalog_DataLogJNI + * Method: appendFloat + * Signature: (JIFJ)V + */ +JNIEXPORT void JNICALL +Java_edu_wpi_first_util_datalog_DataLogJNI_appendFloat + (JNIEnv* env, jclass, jlong impl, jint entry, jfloat value, jlong timestamp) +{ + if (impl == 0) { + wpi::ThrowNullPointerException(env, "impl is null"); + return; + } + reinterpret_cast(impl)->AppendFloat(entry, value, timestamp); +} + +/* + * Class: edu_wpi_first_util_datalog_DataLogJNI + * Method: appendDouble + * Signature: (JIDJ)V + */ +JNIEXPORT void JNICALL +Java_edu_wpi_first_util_datalog_DataLogJNI_appendDouble + (JNIEnv* env, jclass, jlong impl, jint entry, jdouble value, jlong timestamp) +{ + if (impl == 0) { + wpi::ThrowNullPointerException(env, "impl is null"); + return; + } + reinterpret_cast(impl)->AppendDouble(entry, value, timestamp); +} + +/* + * Class: edu_wpi_first_util_datalog_DataLogJNI + * Method: appendString + * Signature: (JILjava/lang/String;J)V + */ +JNIEXPORT void JNICALL +Java_edu_wpi_first_util_datalog_DataLogJNI_appendString + (JNIEnv* env, jclass, jlong impl, jint entry, jstring value, jlong timestamp) +{ + if (impl == 0) { + wpi::ThrowNullPointerException(env, "impl is null"); + return; + } + reinterpret_cast(impl)->AppendString(entry, JStringRef{env, value}, + timestamp); +} + +/* + * Class: edu_wpi_first_util_datalog_DataLogJNI + * Method: appendBooleanArray + * Signature: (JI[ZJ)V + */ +JNIEXPORT void JNICALL +Java_edu_wpi_first_util_datalog_DataLogJNI_appendBooleanArray + (JNIEnv* env, jclass, jlong impl, jint entry, jbooleanArray value, + jlong timestamp) +{ + if (impl == 0) { + wpi::ThrowNullPointerException(env, "impl is null"); + return; + } + if (!value) { + wpi::ThrowNullPointerException(env, "value is null"); + return; + } + reinterpret_cast(impl)->AppendBooleanArray( + entry, JSpan{env, value}, timestamp); +} + +/* + * Class: edu_wpi_first_util_datalog_DataLogJNI + * Method: appendIntegerArray + * Signature: (JI[JJ)V + */ +JNIEXPORT void JNICALL +Java_edu_wpi_first_util_datalog_DataLogJNI_appendIntegerArray + (JNIEnv* env, jclass, jlong impl, jint entry, jlongArray value, + jlong timestamp) +{ + if (impl == 0) { + wpi::ThrowNullPointerException(env, "impl is null"); + return; + } + if (!value) { + wpi::ThrowNullPointerException(env, "value is null"); + return; + } + JSpan jarr{env, value}; + if constexpr (sizeof(jlong) == sizeof(int64_t)) { + reinterpret_cast(impl)->AppendIntegerArray( + entry, {reinterpret_cast(jarr.data()), jarr.size()}, + timestamp); + } else { + wpi::SmallVector arr; + arr.reserve(jarr.size()); + for (auto v : jarr) { + arr.push_back(v); + } + reinterpret_cast(impl)->AppendIntegerArray(entry, arr, timestamp); + } +} + +/* + * Class: edu_wpi_first_util_datalog_DataLogJNI + * Method: appendFloatArray + * Signature: (JI[FJ)V + */ +JNIEXPORT void JNICALL +Java_edu_wpi_first_util_datalog_DataLogJNI_appendFloatArray + (JNIEnv* env, jclass, jlong impl, jint entry, jfloatArray value, + jlong timestamp) +{ + if (impl == 0) { + wpi::ThrowNullPointerException(env, "impl is null"); + return; + } + if (!value) { + wpi::ThrowNullPointerException(env, "value is null"); + return; + } + reinterpret_cast(impl)->AppendFloatArray( + entry, JSpan{env, value}, timestamp); +} + +/* + * Class: edu_wpi_first_util_datalog_DataLogJNI + * Method: appendDoubleArray + * Signature: (JI[DJ)V + */ +JNIEXPORT void JNICALL +Java_edu_wpi_first_util_datalog_DataLogJNI_appendDoubleArray + (JNIEnv* env, jclass, jlong impl, jint entry, jdoubleArray value, + jlong timestamp) +{ + if (impl == 0) { + wpi::ThrowNullPointerException(env, "impl is null"); + return; + } + if (!value) { + wpi::ThrowNullPointerException(env, "value is null"); + return; + } + reinterpret_cast(impl)->AppendDoubleArray( + entry, JSpan{env, value}, timestamp); +} + +/* + * Class: edu_wpi_first_util_datalog_DataLogJNI + * Method: appendStringArray + * Signature: (JI[Ljava/lang/Object;J)V + */ +JNIEXPORT void JNICALL +Java_edu_wpi_first_util_datalog_DataLogJNI_appendStringArray + (JNIEnv* env, jclass, jlong impl, jint entry, jobjectArray value, + jlong timestamp) +{ + if (impl == 0) { + wpi::ThrowNullPointerException(env, "impl is null"); + return; + } + if (!value) { + wpi::ThrowNullPointerException(env, "value is null"); + return; + } + size_t len = env->GetArrayLength(value); + std::vector arr; + arr.reserve(len); + for (size_t i = 0; i < len; ++i) { + JLocal elem{ + env, static_cast(env->GetObjectArrayElement(value, i))}; + if (!elem) { + wpi::ThrowNullPointerException( + env, fmt::format("string at element {} is null", i)); + return; + } + arr.emplace_back(JStringRef{env, elem}.str()); + } + reinterpret_cast(impl)->AppendStringArray(entry, arr, timestamp); +} +/* + * Class: edu_wpi_first_util_WPIUtilJNI + * Method: createFileLogger + * Signature: (Ljava/lang/String;JLjava/lang/String;)J + */ +JNIEXPORT jlong JNICALL +Java_edu_wpi_first_util_WPIUtilJNI_createFileLogger + (JNIEnv* env, jclass, jstring file, jlong log, jstring key) +{ + if (!file) { + wpi::ThrowNullPointerException(env, "file is null"); + return 0; + } + auto* f = reinterpret_cast(log); + if (!f) { + wpi::ThrowNullPointerException(env, "log is null"); + return 0; + } + if (!key) { + wpi::ThrowNullPointerException(env, "key is null"); + return 0; + } + return reinterpret_cast( + new wpi::FileLogger{JStringRef{env, file}, *f, JStringRef{env, key}}); +} + +/* + * Class: edu_wpi_first_util_WPIUtilJNI + * Method: freeFileLogger + * Signature: (J)V + */ +JNIEXPORT void JNICALL +Java_edu_wpi_first_util_WPIUtilJNI_freeFileLogger + (JNIEnv* env, jclass, jlong fileTail) +{ + delete reinterpret_cast(fileTail); +} +} // extern "C" diff --git a/ntcore/build.gradle b/ntcore/build.gradle index 09cbf38d460..4a9afad7e79 100644 --- a/ntcore/build.gradle +++ b/ntcore/build.gradle @@ -34,11 +34,11 @@ model { if (it.component.name == "${nativeName}JNI") { lib project: ':wpinet', library: 'wpinet', linkage: 'static' lib project: ':wpiutil', library: 'wpiutil', linkage: 'static' - lib project: ':libdatalog', library 'libdatalog', linkage: 'static' + lib project: ':libdatalog', library: 'libdatalog', linkage: 'static' } else { lib project: ':wpinet', library: 'wpinet', linkage: 'shared' lib project: ':wpiutil', library: 'wpiutil', linkage: 'shared' - lib project: ':libdatalog', library 'libdatalog', linkage: 'shared' + lib project: ':libdatalog', library: 'libdatalog', linkage: 'shared' } } } diff --git a/wpiutil/src/main/native/cpp/jni/WPIUtilJNI.cpp b/wpiutil/src/main/native/cpp/jni/WPIUtilJNI.cpp index 7a6051e34c7..55764642a46 100644 --- a/wpiutil/src/main/native/cpp/jni/WPIUtilJNI.cpp +++ b/wpiutil/src/main/native/cpp/jni/WPIUtilJNI.cpp @@ -7,7 +7,6 @@ #include #include "edu_wpi_first_util_WPIUtilJNI.h" -#include "wpi/FileLogger.h" #include "wpi/RawFrame.h" #include "wpi/RuntimeCheck.h" #include "wpi/Synchronization.h" @@ -463,42 +462,4 @@ Java_edu_wpi_first_util_WPIUtilJNI_setRawFrameInfo f->stride = stride; f->pixelFormat = pixelFormat; } - -/* - * Class: edu_wpi_first_util_WPIUtilJNI - * Method: createFileLogger - * Signature: (Ljava/lang/String;JLjava/lang/String;)J - */ -JNIEXPORT jlong JNICALL -Java_edu_wpi_first_util_WPIUtilJNI_createFileLogger - (JNIEnv* env, jclass, jstring file, jlong log, jstring key) -{ - if (!file) { - wpi::ThrowNullPointerException(env, "file is null"); - return 0; - } - auto* f = reinterpret_cast(log); - if (!f) { - wpi::ThrowNullPointerException(env, "log is null"); - return 0; - } - if (!key) { - wpi::ThrowNullPointerException(env, "key is null"); - return 0; - } - return reinterpret_cast( - new wpi::FileLogger{JStringRef{env, file}, *f, JStringRef{env, key}}); -} - -/* - * Class: edu_wpi_first_util_WPIUtilJNI - * Method: freeFileLogger - * Signature: (J)V - */ -JNIEXPORT void JNICALL -Java_edu_wpi_first_util_WPIUtilJNI_freeFileLogger - (JNIEnv* env, jclass, jlong fileTail) -{ - delete reinterpret_cast(fileTail); -} } // extern "C" From 50d383492cbf2829fcf50e02012cf2e72a1c84e8 Mon Sep 17 00:00:00 2001 From: DeltaDizzy Date: Thu, 9 Jan 2025 14:00:28 -0600 Subject: [PATCH 23/64] revert to og gradle --- libdatalog/build.gradle | 22 +++++++++++----------- 1 file changed, 11 insertions(+), 11 deletions(-) diff --git a/libdatalog/build.gradle b/libdatalog/build.gradle index 0a4081458fd..792a9947404 100644 --- a/libdatalog/build.gradle +++ b/libdatalog/build.gradle @@ -18,14 +18,14 @@ model { srcDirs 'src/main/native/include' } } - if (!it.buildable || !(it instanceof NativeBinarySpec)) { - return - } - if (it.component.name == "${nativeName}JNI") { - lib project ':wpiutil', library: 'wpiutil', linkage: 'static' - } else { - lib project: ':wpiutil', library: 'wpiutil', linkage: 'shared' - } + // if (!it.buildable || !(it instanceof NativeBinarySpec)) { + // return + // } + // if (it.component.name == "${nativeName}JNI") { + // lib project ':wpiutil', library: 'wpiutil', linkage: 'static' + // } else { + // lib project: ':wpiutil', library: 'wpiutil', linkage: 'shared' + // } } } } @@ -50,6 +50,6 @@ model { // } // } -// dependencies { -// api project(":wpiutil") -// } +dependencies { + api project(":wpiutil") +} From 59aa058d036d02608636f151dad87bd664289360 Mon Sep 17 00:00:00 2001 From: DeltaDizzy Date: Thu, 9 Jan 2025 14:39:25 -0600 Subject: [PATCH 24/64] jni hell part 2 --- libdatalog/build.gradle | 33 +++---------------- .../src/main/native/cpp/jni/DataLogJNI.cpp | 2 +- .../src/main/native/include/wpi/DataLogJNI.h | 13 ++++++++ ntcore/CMakeLists.txt | 2 +- 4 files changed, 20 insertions(+), 30 deletions(-) create mode 100644 libdatalog/src/main/native/include/wpi/DataLogJNI.h diff --git a/libdatalog/build.gradle b/libdatalog/build.gradle index 792a9947404..0ff9c066ea2 100644 --- a/libdatalog/build.gradle +++ b/libdatalog/build.gradle @@ -10,6 +10,11 @@ ext { apply from: "${rootDir}/shared/jni/setupBuild.gradle" +nativeUtils.exportsConfigs { + libdatalog { + } +} + model { components { all { @@ -18,38 +23,10 @@ model { srcDirs 'src/main/native/include' } } - // if (!it.buildable || !(it instanceof NativeBinarySpec)) { - // return - // } - // if (it.component.name == "${nativeName}JNI") { - // lib project ':wpiutil', library: 'wpiutil', linkage: 'static' - // } else { - // lib project: ':wpiutil', library: 'wpiutil', linkage: 'shared' - // } } } } -// model { -// components {} -// binaries { -// all { -// if (!it.buildable || !(it instanceof NativeBinarySpec)) { -// return -// } -// if (it.component.name == "${nativeName}JNI") { -// lib project: ':wpinet', library: 'wpinet', linkage: 'static' -// lib project: ':wpiutil', library: 'wpiutil', linkage: 'static' -// lib project: ':libdatalog', library: 'libdatalog', linkage: 'static' -// } else { -// lib project: ':wpinet', library: 'wpinet', linkage: 'shared' -// lib project: ':wpiutil', library: 'wpiutil', linkage: 'shared' -// lib project: ':libdatalog', library: 'libdatalog', linkage: 'shared' -// } -// } -// } -// } - dependencies { api project(":wpiutil") } diff --git a/libdatalog/src/main/native/cpp/jni/DataLogJNI.cpp b/libdatalog/src/main/native/cpp/jni/DataLogJNI.cpp index e9fc20c8386..921be8669e2 100644 --- a/libdatalog/src/main/native/cpp/jni/DataLogJNI.cpp +++ b/libdatalog/src/main/native/cpp/jni/DataLogJNI.cpp @@ -3,8 +3,8 @@ // the WPILib BSD license file in the root directory of this project. #include -#include "WPIUtilJNI.h" +#include "wpi/DataLogJNI.h" #include "wpi/FileLogger.h" diff --git a/libdatalog/src/main/native/include/wpi/DataLogJNI.h b/libdatalog/src/main/native/include/wpi/DataLogJNI.h new file mode 100644 index 00000000000..b0561b91be8 --- /dev/null +++ b/libdatalog/src/main/native/include/wpi/DataLogJNI.h @@ -0,0 +1,13 @@ +#pragma once + +#include +#include + +namespace wpi { + +void ThrowIllegalArgumentException(JNIEnv* env, std::string_view msg); +void ThrowIndexOobException(JNIEnv* env, std::string_view msg); +void ThrowIOException(JNIEnv* env, std::string_view msg); +void ThrowNullPointerException(JNIEnv* env, std::string_view msg); + +} // namespace wpi \ No newline at end of file diff --git a/ntcore/CMakeLists.txt b/ntcore/CMakeLists.txt index f108a9133d2..88106ca6ae3 100644 --- a/ntcore/CMakeLists.txt +++ b/ntcore/CMakeLists.txt @@ -26,7 +26,7 @@ target_include_directories( ) wpilib_target_warnings(ntcore) target_compile_features(ntcore PUBLIC cxx_std_20) -target_link_libraries(ntcore PUBLIC wpinet wpiutil) +target_link_libraries(ntcore PUBLIC wpinet wpiutil libdatalog) set_property(TARGET ntcore PROPERTY FOLDER "libraries") From 69a78b439b34027e05154dae0086388c35461f35 Mon Sep 17 00:00:00 2001 From: DeltaDizzy Date: Thu, 9 Jan 2025 15:12:41 -0600 Subject: [PATCH 25/64] almost there! --- libdatalog/CMakeLists.txt | 8 +- libdatalog/build.gradle | 2 +- .../java/edu/wpi/first/datalog/DataLog.java | 5 +- .../edu/wpi/first/datalog/FileLogger.java | 6 +- .../src/main/native/cpp/jni/DataLogJNI.cpp | 21 +- .../src/test/native/cpp/DataLogTest.cpp | 1349 ++++++++--------- .../src/main/native/cpp/jni/WPIUtilJNI.cpp | 2 +- 7 files changed, 705 insertions(+), 688 deletions(-) diff --git a/libdatalog/CMakeLists.txt b/libdatalog/CMakeLists.txt index d89c428a3ca..436102e9995 100644 --- a/libdatalog/CMakeLists.txt +++ b/libdatalog/CMakeLists.txt @@ -40,7 +40,7 @@ foreach(example ${libdatalog_examples}) if(libdatalog_example_src) add_executable(libdatalog_${example} ${libdatalog_example_src}) wpilib_target_warnings(libdatalog_${example}) - target_link_libraries(libdatalog_${example} libdatalog) + target_link_libraries(libdatalog_${example} libdatalog wpiutil) set_property(TARGET libdatalog_${example} PROPERTY FOLDER "examples") endif() endforeach() @@ -91,11 +91,13 @@ if(WITH_JAVA) set(CMAKE_JNI_TARGET true) file(GLOB_RECURSE JAVA_SOURCES src/main/java/*.java) + file(GLOB QUICKBUF_JAR ${WPILIB_BINARY_DIR}/wpiutil/thirdparty/quickbuf/*.jar) add_jar( libdatalog_jar ${JAVA_SOURCES} # INCLUDE_JARS ${JACKSON_JARS} ${QUICKBUF_JAR} + INCLUDE_JARS wpiutil_jar ${QUICKBUF_JAR} OUTPUT_NAME libdatalog OUTPUT_DIR ${WPILIB_BINARY_DIR}/${java_lib_dest} GENERATE_NATIVE_HEADERS libdatalog_jni_headers @@ -146,9 +148,9 @@ if(WITH_TESTS) wpilib_add_test(libdatalog src/test/native/cpp) target_include_directories(libdatalog_test PRIVATE src/generated/test/native/cpp) - target_link_libraries(libdatalog_test libdatalog googletest libdatalog_testlib) + target_link_libraries(libdatalog_test libdatalog googletest libdatalog_testlib wpiutil) if(MSVC) - target_compile_options(lobdatalog_test PRIVATE /utf-8) + target_compile_options(libdatalog_test PRIVATE /utf-8) endif() endif() diff --git a/libdatalog/build.gradle b/libdatalog/build.gradle index 0ff9c066ea2..c02d4d80d8a 100644 --- a/libdatalog/build.gradle +++ b/libdatalog/build.gradle @@ -4,7 +4,7 @@ ext { baseId = 'libdatalog' groupId = 'edu.wpi.first.datalog' - nativeName = 'libdatalog' + nativeName = 'datalog' devMain = 'edu.wpi.first.math.DevMain' } diff --git a/libdatalog/src/main/java/edu/wpi/first/datalog/DataLog.java b/libdatalog/src/main/java/edu/wpi/first/datalog/DataLog.java index fed02a0a49d..2d5e1908806 100644 --- a/libdatalog/src/main/java/edu/wpi/first/datalog/DataLog.java +++ b/libdatalog/src/main/java/edu/wpi/first/datalog/DataLog.java @@ -4,7 +4,6 @@ package edu.wpi.first.datalog; -import edu.wpi.first.util.WPIUtilJNI; import edu.wpi.first.util.protobuf.Protobuf; import edu.wpi.first.util.struct.Struct; import java.nio.ByteBuffer; @@ -146,7 +145,7 @@ public void addSchema(String name, String type, String schema) { * @param timestamp Time stamp (0 to indicate now) */ public void addSchema(Protobuf proto, long timestamp) { - final long actualTimestamp = timestamp == 0 ? WPIUtilJNI.now() : timestamp; + final long actualTimestamp = timestamp == 0 ? DataLogJNI.now() : timestamp; proto.forEachDescriptor( this::hasSchema, (typeString, schema) -> @@ -171,7 +170,7 @@ public void addSchema(Protobuf proto) { * @param timestamp Time stamp (0 to indicate now) */ public void addSchema(Struct struct, long timestamp) { - addSchemaImpl(struct, timestamp == 0 ? WPIUtilJNI.now() : timestamp, new HashSet<>()); + addSchemaImpl(struct, timestamp == 0 ? DataLogJNI.now() : timestamp, new HashSet<>()); } /** diff --git a/libdatalog/src/main/java/edu/wpi/first/datalog/FileLogger.java b/libdatalog/src/main/java/edu/wpi/first/datalog/FileLogger.java index ad746429541..afa98b2a6f9 100644 --- a/libdatalog/src/main/java/edu/wpi/first/datalog/FileLogger.java +++ b/libdatalog/src/main/java/edu/wpi/first/datalog/FileLogger.java @@ -4,8 +4,6 @@ package edu.wpi.first.datalog; -import edu.wpi.first.util.WPIUtilJNI; - /** * A class version of `tail -f`, otherwise known as `tail -f` at home. Watches a file and puts the * data into a data log. Only works on Linux-based platforms. @@ -22,11 +20,11 @@ public class FileLogger implements AutoCloseable { * @param key The log key to append data to. */ public FileLogger(String file, DataLog log, String key) { - m_impl = WPIUtilJNI.createFileLogger(file, log.getImpl(), key); + m_impl = DataLogJNI.createFileLogger(file, log.getImpl(), key); } @Override public void close() { - WPIUtilJNI.freeFileLogger(m_impl); + DataLogJNI.freeFileLogger(m_impl); } } diff --git a/libdatalog/src/main/native/cpp/jni/DataLogJNI.cpp b/libdatalog/src/main/native/cpp/jni/DataLogJNI.cpp index 921be8669e2..35606d42e47 100644 --- a/libdatalog/src/main/native/cpp/jni/DataLogJNI.cpp +++ b/libdatalog/src/main/native/cpp/jni/DataLogJNI.cpp @@ -14,7 +14,7 @@ #include -#include "edu_wpi_first_util_datalog_DataLogJNI.h" +//#include "edu_wpi_first_util_datalog_DataLogJNI.h" #include "wpi/DataLog.h" #include "wpi/DataLogBackgroundWriter.h" #include "wpi/DataLogWriter.h" @@ -23,6 +23,9 @@ using namespace wpi::java; using namespace wpi::log; +static bool mockTimeEnabled = false; +static uint64_t mockNow = 0; + namespace { class buf_ostream : public wpi::raw_uvector_ostream { private: @@ -113,6 +116,22 @@ Java_edu_wpi_first_util_datalog_DataLogJNI_fgCreate return reinterpret_cast(writer); } +/* + * Class: edu_wpi_first_util_WPIUtilJNI + * Method: now + * Signature: ()J + */ +JNIEXPORT jlong JNICALL +Java_edu_wpi_first_util_WPIUtilJNI_now + (JNIEnv*, jclass) +{ + if (mockTimeEnabled) { + return mockNow; + } else { + return wpi::Now(); + } +} + /* * Class: edu_wpi_first_util_datalog_DataLogJNI * Method: fgCreateMemory diff --git a/libdatalog/src/test/native/cpp/DataLogTest.cpp b/libdatalog/src/test/native/cpp/DataLogTest.cpp index ebe6517c4d5..149d3a36b78 100644 --- a/libdatalog/src/test/native/cpp/DataLogTest.cpp +++ b/libdatalog/src/test/native/cpp/DataLogTest.cpp @@ -1,675 +1,674 @@ -// // Copyright (c) FIRST and other WPILib contributors. -// // Open Source Software; you can modify and/or share it under the terms of -// // the WPILib BSD license file in the root directory of this project. - -// #include -// #include -// #include -// #include - -// #include - -// #include "wpi/DataLogWriter.h" -// #include "wpi/Logger.h" -// #include "wpi/raw_ostream.h" - -// namespace { -// struct ThingA { -// int x = 0; -// }; - -// inline bool operator==(const ThingA& a, const ThingA& b) { -// return a.x == b.x; -// } - -// struct ThingB { -// int x = 0; -// }; - -// struct ThingC { -// int x = 0; -// }; - -// struct Info1 { -// int info = 0; -// }; - -// struct Info2 { -// int info = 0; -// }; -// } // namespace - -// template <> -// struct wpi::Struct { -// static constexpr std::string_view GetTypeName() { return "ThingA"; } -// static constexpr size_t GetSize() { return 1; } -// static constexpr std::string_view GetSchema() { return "uint8 value"; } -// static ThingA Unpack(std::span data) { -// return ThingA{.x = data[0]}; -// } -// static void Pack(std::span data, const ThingA& value) { -// data[0] = value.x; -// } -// }; - -// template <> -// struct wpi::Struct { -// static constexpr std::string_view GetTypeName(const Info1&) { -// return "ThingB"; -// } -// static constexpr size_t GetSize(const Info1&) { return 1; } -// static constexpr std::string_view GetSchema(const Info1&) { -// return "uint8 value"; -// } -// static ThingB Unpack(std::span data, const Info1&) { -// return ThingB{.x = data[0]}; -// } -// static void Pack(std::span data, const ThingB& value, const Info1&) { -// data[0] = value.x; -// } -// }; - -// template <> -// struct wpi::Struct { -// static constexpr std::string_view GetTypeName() { return "ThingC"; } -// static constexpr size_t GetSize() { return 1; } -// static constexpr std::string_view GetSchema() { return "uint8 value"; } -// static ThingC Unpack(std::span data) { -// return ThingC{.x = data[0]}; -// } -// static void Pack(std::span data, const ThingC& value) { -// data[0] = value.x; -// } -// }; - -// template <> -// struct wpi::Struct { -// static constexpr std::string_view GetTypeName(const Info1&) { -// return "ThingC"; -// } -// static constexpr size_t GetSize(const Info1&) { return 1; } -// static constexpr std::string_view GetSchema(const Info1&) { -// return "uint8 value"; -// } -// static ThingC Unpack(std::span data, const Info1&) { -// return ThingC{.x = data[0]}; -// } -// static void Pack(std::span data, const ThingC& value, const Info1&) { -// data[0] = value.x; -// } -// }; - -// template <> -// struct wpi::Struct { -// static constexpr std::string_view GetTypeName(const Info2&) { -// return "ThingC"; -// } -// static constexpr size_t GetSize(const Info2&) { return 1; } -// static constexpr std::string_view GetSchema(const Info2&) { -// return "uint8 value"; -// } -// static ThingC Unpack(std::span data, const Info2&) { -// return ThingC{.x = data[0]}; -// } -// static void Pack(std::span data, const ThingC& value, const Info2&) { -// data[0] = value.x; -// } -// }; - -// static_assert(wpi::StructSerializable); -// static_assert(!wpi::StructSerializable); - -// static_assert(!wpi::StructSerializable); -// static_assert(wpi::StructSerializable); -// static_assert(!wpi::StructSerializable); - -// static_assert(wpi::StructSerializable); -// static_assert(wpi::StructSerializable); -// static_assert(wpi::StructSerializable); - -// class DataLogTest : public ::testing::Test { -// public: -// wpi::Logger msglog; -// std::vector data; -// wpi::log::DataLogWriter log{msglog, -// std::make_unique(data)}; -// }; - -// TEST_F(DataLogTest, SimpleInt) { -// int entry = log.Start("test", "int64", "", 1); -// log.AppendInteger(entry, 1, 2); -// log.Flush(); -// ASSERT_EQ(data.size(), 54u); -// } - -// TEST_F(DataLogTest, BooleanAppend) { -// wpi::log::BooleanLogEntry entry{log, "a", 5}; -// entry.Append(false, 7); -// log.Flush(); -// ASSERT_EQ(data.size(), 46u); -// } - -// TEST_F(DataLogTest, BooleanUpdate) { -// wpi::log::BooleanLogEntry entry{log, "a", 5}; -// ASSERT_FALSE(entry.GetLastValue().has_value()); -// entry.Update(false, 7); -// log.Flush(); -// ASSERT_EQ(data.size(), 46u); -// ASSERT_TRUE(entry.GetLastValue().has_value()); -// ASSERT_EQ(entry.GetLastValue().value(), false); -// entry.Update(false, 8); -// log.Flush(); -// ASSERT_EQ(data.size(), 46u); -// entry.Update(true, 9); -// log.Flush(); -// ASSERT_EQ(data.size(), 51u); -// ASSERT_TRUE(entry.GetLastValue().has_value()); -// ASSERT_EQ(entry.GetLastValue().value(), true); -// } - -// TEST_F(DataLogTest, IntegerAppend) { -// wpi::log::IntegerLogEntry entry{log, "a", 5}; -// entry.Append(5, 7); -// log.Flush(); -// ASSERT_EQ(data.size(), 51u); -// } - -// TEST_F(DataLogTest, IntegerUpdate) { -// wpi::log::IntegerLogEntry entry{log, "a", 5}; -// ASSERT_FALSE(entry.GetLastValue().has_value()); -// entry.Update(0, 7); -// log.Flush(); -// ASSERT_EQ(data.size(), 51u); -// ASSERT_TRUE(entry.GetLastValue().has_value()); -// ASSERT_EQ(entry.GetLastValue().value(), 0); -// entry.Update(0, 8); -// log.Flush(); -// ASSERT_EQ(data.size(), 51u); -// entry.Update(2, 9); -// log.Flush(); -// ASSERT_EQ(data.size(), 63u); -// ASSERT_TRUE(entry.GetLastValue().has_value()); -// ASSERT_EQ(entry.GetLastValue().value(), 2); -// } - -// TEST_F(DataLogTest, FloatAppend) { -// wpi::log::FloatLogEntry entry{log, "a", 5}; -// entry.Append(5.0, 7); -// log.Flush(); -// ASSERT_EQ(data.size(), 47u); -// } - -// TEST_F(DataLogTest, FloatUpdate) { -// wpi::log::FloatLogEntry entry{log, "a", 5}; -// ASSERT_FALSE(entry.GetLastValue().has_value()); -// entry.Update(0.0f, 7); -// log.Flush(); -// ASSERT_EQ(data.size(), 47u); -// ASSERT_TRUE(entry.GetLastValue().has_value()); -// ASSERT_EQ(entry.GetLastValue().value(), 0.0f); -// entry.Update(0.0f, 8); -// log.Flush(); -// ASSERT_EQ(data.size(), 47u); -// entry.Update(0.1f, 9); -// log.Flush(); -// ASSERT_EQ(data.size(), 55u); -// ASSERT_TRUE(entry.GetLastValue().has_value()); -// ASSERT_EQ(entry.GetLastValue().value(), 0.1f); -// } - -// TEST_F(DataLogTest, DoubleAppend) { -// wpi::log::DoubleLogEntry entry{log, "a", 5}; -// entry.Append(5.0, 7); -// log.Flush(); -// ASSERT_EQ(data.size(), 52u); -// } - -// TEST_F(DataLogTest, DoubleUpdate) { -// wpi::log::DoubleLogEntry entry{log, "a", 5}; -// ASSERT_FALSE(entry.GetLastValue().has_value()); -// entry.Update(0.0, 7); -// log.Flush(); -// ASSERT_EQ(data.size(), 52u); -// ASSERT_TRUE(entry.GetLastValue().has_value()); -// ASSERT_EQ(entry.GetLastValue().value(), 0.0); -// entry.Update(0.0, 8); -// log.Flush(); -// ASSERT_EQ(data.size(), 52u); -// entry.Update(0.1, 9); -// log.Flush(); -// ASSERT_EQ(data.size(), 64u); -// ASSERT_TRUE(entry.GetLastValue().has_value()); -// ASSERT_EQ(entry.GetLastValue().value(), 0.1); -// } - -// TEST_F(DataLogTest, StringAppend) { -// wpi::log::StringLogEntry entry{log, "a", 5}; -// entry.Append("x", 7); -// log.Flush(); -// ASSERT_EQ(data.size(), 45u); -// } - -// TEST_F(DataLogTest, StringUpdate) { -// wpi::log::StringLogEntry entry{log, "a", 5}; -// ASSERT_FALSE(entry.HasLastValue()); - -// entry.Update("x", 7); -// log.Flush(); -// ASSERT_EQ(data.size(), 45u); -// ASSERT_TRUE(entry.GetLastValue().has_value()); -// ASSERT_EQ(entry.GetLastValue().value(), "x"); - -// entry.Update("x", 8); -// log.Flush(); -// ASSERT_EQ(data.size(), 45u); - -// entry.Update("y", 9); -// log.Flush(); -// ASSERT_EQ(data.size(), 50u); -// ASSERT_TRUE(entry.GetLastValue().has_value()); -// ASSERT_EQ(entry.GetLastValue().value(), "y"); - -// entry.Update("yy", 10); -// log.Flush(); -// ASSERT_EQ(data.size(), 56u); -// ASSERT_TRUE(entry.GetLastValue().has_value()); -// ASSERT_EQ(entry.GetLastValue().value(), "yy"); - -// entry.Update("", 11); -// log.Flush(); -// ASSERT_EQ(data.size(), 60u); -// ASSERT_TRUE(entry.GetLastValue().has_value()); -// ASSERT_EQ(entry.GetLastValue().value(), ""); -// } - -// TEST_F(DataLogTest, RawAppend) { -// wpi::log::RawLogEntry entry{log, "a", 5}; -// entry.Append({{5}}, 7); -// log.Flush(); -// ASSERT_EQ(data.size(), 42u); -// } - -// TEST_F(DataLogTest, RawUpdate) { -// wpi::log::RawLogEntry entry{log, "a", 5}; -// ASSERT_FALSE(entry.HasLastValue()); - -// entry.Update({{5}}, 7); -// log.Flush(); -// ASSERT_EQ(data.size(), 42u); -// ASSERT_TRUE(entry.GetLastValue().has_value()); -// ASSERT_EQ(entry.GetLastValue().value(), std::vector{5}); - -// entry.Update({{5}}, 8); -// log.Flush(); -// ASSERT_EQ(data.size(), 42u); - -// entry.Update({{6}}, 9); -// log.Flush(); -// ASSERT_EQ(data.size(), 47u); -// ASSERT_TRUE(entry.GetLastValue().has_value()); -// ASSERT_EQ(entry.GetLastValue().value(), std::vector{6}); - -// entry.Update({{6, 6}}, 9); -// log.Flush(); -// ASSERT_EQ(data.size(), 53u); -// ASSERT_TRUE(entry.GetLastValue().has_value()); -// ASSERT_EQ(entry.GetLastValue().value(), (std::vector{6, 6})); - -// entry.Update(std::span{}, 10); -// log.Flush(); -// ASSERT_EQ(data.size(), 57u); -// ASSERT_TRUE(entry.GetLastValue().has_value()); -// ASSERT_EQ(entry.GetLastValue().value(), std::vector{}); -// } - -// TEST_F(DataLogTest, BooleanArrayAppendEmpty) { -// wpi::log::BooleanArrayLogEntry entry{log, "a", 5}; -// entry.Append(std::span{}, 7); -// log.Flush(); -// ASSERT_EQ(data.size(), 47u); -// } - -// TEST_F(DataLogTest, BooleanArrayAppend) { -// wpi::log::BooleanArrayLogEntry entry{log, "a", 5}; -// entry.Append({false}, 7); -// log.Flush(); -// ASSERT_EQ(data.size(), 48u); -// } - -// TEST_F(DataLogTest, BooleanArrayUpdate) { -// wpi::log::BooleanArrayLogEntry entry{log, "a", 5}; -// ASSERT_FALSE(entry.GetLastValue().has_value()); -// entry.Update({false}, 7); -// log.Flush(); -// ASSERT_EQ(data.size(), 48u); -// ASSERT_TRUE(entry.GetLastValue().has_value()); -// ASSERT_EQ(entry.GetLastValue().value(), std::vector{false}); -// entry.Update({false}, 8); -// log.Flush(); -// ASSERT_EQ(data.size(), 48u); -// entry.Update({true}, 9); -// log.Flush(); -// ASSERT_EQ(data.size(), 53u); -// ASSERT_TRUE(entry.GetLastValue().has_value()); -// ASSERT_EQ(entry.GetLastValue().value(), std::vector{true}); -// entry.Update(std::span{}, 10); -// log.Flush(); -// ASSERT_EQ(data.size(), 57u); -// ASSERT_TRUE(entry.GetLastValue().has_value()); -// ASSERT_EQ(entry.GetLastValue().value(), std::vector{}); -// } - -// TEST_F(DataLogTest, IntegerArrayAppendEmpty) { -// wpi::log::IntegerArrayLogEntry entry{log, "a", 5}; -// entry.Append(std::span{}, 7); -// log.Flush(); -// ASSERT_EQ(data.size(), 45u); -// } - -// TEST_F(DataLogTest, IntegerArrayAppend) { -// wpi::log::IntegerArrayLogEntry entry{log, "a", 5}; -// entry.Append({1}, 7); -// log.Flush(); -// ASSERT_EQ(data.size(), 53u); -// } - -// TEST_F(DataLogTest, IntegerArrayUpdate) { -// wpi::log::IntegerArrayLogEntry entry{log, "a", 5}; -// ASSERT_FALSE(entry.GetLastValue().has_value()); -// entry.Update({1}, 7); -// log.Flush(); -// ASSERT_EQ(data.size(), 53u); -// ASSERT_TRUE(entry.GetLastValue().has_value()); -// ASSERT_EQ(entry.GetLastValue().value(), std::vector{1}); -// entry.Update({1}, 8); -// log.Flush(); -// ASSERT_EQ(data.size(), 53u); -// entry.Update({2}, 9); -// log.Flush(); -// ASSERT_EQ(data.size(), 65u); -// ASSERT_TRUE(entry.GetLastValue().has_value()); -// ASSERT_EQ(entry.GetLastValue().value(), std::vector{2}); -// entry.Update(std::span{}, 10); -// log.Flush(); -// ASSERT_EQ(data.size(), 69u); -// ASSERT_TRUE(entry.GetLastValue().has_value()); -// ASSERT_EQ(entry.GetLastValue().value(), std::vector{}); -// } - -// TEST_F(DataLogTest, DoubleArrayAppendEmpty) { -// wpi::log::DoubleArrayLogEntry entry{log, "a", 5}; -// entry.Append(std::span{}, 7); -// log.Flush(); -// ASSERT_EQ(data.size(), 46u); -// } - -// TEST_F(DataLogTest, DoubleArrayAppend) { -// wpi::log::DoubleArrayLogEntry entry{log, "a", 5}; -// entry.Append({1.0}, 7); -// log.Flush(); -// ASSERT_EQ(data.size(), 54u); -// } - -// TEST_F(DataLogTest, DoubleArrayUpdate) { -// wpi::log::DoubleArrayLogEntry entry{log, "a", 5}; -// ASSERT_FALSE(entry.GetLastValue().has_value()); -// entry.Update({1.0}, 7); -// log.Flush(); -// ASSERT_EQ(data.size(), 54u); -// ASSERT_TRUE(entry.GetLastValue().has_value()); -// ASSERT_EQ(entry.GetLastValue().value(), std::vector{1.0}); -// entry.Update({1.0}, 8); -// log.Flush(); -// ASSERT_EQ(data.size(), 54u); -// entry.Update({2.0}, 9); -// log.Flush(); -// ASSERT_EQ(data.size(), 66u); -// ASSERT_TRUE(entry.GetLastValue().has_value()); -// ASSERT_EQ(entry.GetLastValue().value(), std::vector{2}); -// entry.Update(std::span{}, 10); -// log.Flush(); -// ASSERT_EQ(data.size(), 70u); -// ASSERT_TRUE(entry.GetLastValue().has_value()); -// ASSERT_EQ(entry.GetLastValue().value(), std::vector{}); -// } - -// TEST_F(DataLogTest, FloatArrayAppendEmpty) { -// wpi::log::FloatArrayLogEntry entry{log, "a", 5}; -// entry.Append(std::span{}, 7); -// log.Flush(); -// ASSERT_EQ(data.size(), 45u); -// } - -// TEST_F(DataLogTest, FloatArrayAppend) { -// wpi::log::FloatArrayLogEntry entry{log, "a", 5}; -// entry.Append({1.0f}, 7); -// log.Flush(); -// ASSERT_EQ(data.size(), 49u); -// } - -// TEST_F(DataLogTest, FloatArrayUpdate) { -// wpi::log::FloatArrayLogEntry entry{log, "a", 5}; -// ASSERT_FALSE(entry.GetLastValue().has_value()); -// entry.Update({1.0f}, 7); -// log.Flush(); -// ASSERT_EQ(data.size(), 49u); -// ASSERT_TRUE(entry.GetLastValue().has_value()); -// ASSERT_EQ(entry.GetLastValue().value(), std::vector{1.0f}); -// entry.Update({1.0f}, 8); -// log.Flush(); -// ASSERT_EQ(data.size(), 49u); -// entry.Update({2.0f}, 9); -// log.Flush(); -// ASSERT_EQ(data.size(), 57u); -// ASSERT_TRUE(entry.GetLastValue().has_value()); -// ASSERT_EQ(entry.GetLastValue().value(), std::vector{2.0f}); -// entry.Update(std::span{}, 10); -// log.Flush(); -// ASSERT_EQ(data.size(), 61u); -// ASSERT_TRUE(entry.GetLastValue().has_value()); -// ASSERT_EQ(entry.GetLastValue().value(), std::vector{}); -// } - -// TEST_F(DataLogTest, StringArrayAppendEmpty) { -// wpi::log::StringArrayLogEntry entry{log, "a", 5}; -// entry.Append(std::span{}, 7); -// entry.Append(std::span{}, 7); -// log.Flush(); -// ASSERT_EQ(data.size(), 58u); -// } - -// TEST_F(DataLogTest, StringArrayAppend) { -// wpi::log::StringArrayLogEntry entry{log, "a", 5}; -// entry.Append({"x"}, 7); -// log.Flush(); -// ASSERT_EQ(data.size(), 55u); -// } - -// TEST_F(DataLogTest, StringArrayUpdate) { -// wpi::log::StringArrayLogEntry entry{log, "a", 5}; -// ASSERT_FALSE(entry.GetLastValue().has_value()); -// entry.Update({"x"}, 7); -// log.Flush(); -// ASSERT_EQ(data.size(), 55u); -// ASSERT_TRUE(entry.GetLastValue().has_value()); -// ASSERT_EQ(entry.GetLastValue().value(), std::vector{"x"}); -// entry.Update({"x"}, 8); -// log.Flush(); -// ASSERT_EQ(data.size(), 55u); -// entry.Update({"y"}, 9); -// log.Flush(); -// ASSERT_EQ(data.size(), 68u); -// ASSERT_TRUE(entry.GetLastValue().has_value()); -// ASSERT_EQ(entry.GetLastValue().value(), std::vector{"y"}); -// entry.Update(std::span{}, 10); -// log.Flush(); -// ASSERT_EQ(data.size(), 76u); -// ASSERT_TRUE(entry.GetLastValue().has_value()); -// ASSERT_EQ(entry.GetLastValue().value(), std::vector{}); -// } - -// TEST_F(DataLogTest, StructA) { -// [[maybe_unused]] -// wpi::log::StructLogEntry entry0; -// wpi::log::StructLogEntry entry{log, "a", 5}; -// entry.Append(ThingA{}); -// entry.Append(ThingA{}, 7); -// } - -// TEST_F(DataLogTest, StructUpdate) { -// wpi::log::StructLogEntry entry{log, "a", 5}; -// ASSERT_FALSE(entry.GetLastValue().has_value()); - -// entry.Update(ThingA{}, 7); -// log.Flush(); -// ASSERT_EQ(data.size(), 122u); -// ASSERT_TRUE(entry.GetLastValue().has_value()); -// ASSERT_EQ(entry.GetLastValue().value(), ThingA{}); - -// entry.Update(ThingA{}, 8); -// log.Flush(); -// ASSERT_EQ(data.size(), 122u); - -// entry.Update(ThingA{.x = 1}, 9); -// log.Flush(); -// ASSERT_EQ(data.size(), 127u); -// ASSERT_TRUE(entry.GetLastValue().has_value()); -// ASSERT_EQ(entry.GetLastValue().value(), ThingA{.x = 1}); -// } - -// TEST_F(DataLogTest, StructArrayA) { -// [[maybe_unused]] -// wpi::log::StructArrayLogEntry entry0; -// wpi::log::StructArrayLogEntry entry{log, "a", 5}; -// entry.Append({{ThingA{}, ThingA{}}}); -// entry.Append({{ThingA{}, ThingA{}}}, 7); -// } - -// TEST_F(DataLogTest, StructArrayUpdate) { -// wpi::log::StructArrayLogEntry entry{log, "a", 5}; -// ASSERT_FALSE(entry.GetLastValue().has_value()); - -// entry.Update({{ThingA{}, ThingA{.x = 1}}}, 7); -// log.Flush(); -// ASSERT_EQ(data.size(), 125u); -// ASSERT_TRUE(entry.GetLastValue().has_value()); -// ASSERT_EQ(entry.GetLastValue().value(), -// (std::vector{ThingA{}, ThingA{.x = 1}})); - -// entry.Update({{ThingA{}, ThingA{.x = 1}}}, 8); -// log.Flush(); -// ASSERT_EQ(data.size(), 125u); - -// entry.Update({{ThingA{}, ThingA{.x = 2}}}, 9); -// log.Flush(); -// ASSERT_EQ(data.size(), 131u); -// ASSERT_TRUE(entry.GetLastValue().has_value()); -// ASSERT_EQ(entry.GetLastValue().value(), -// (std::vector{ThingA{}, ThingA{.x = 2}})); - -// entry.Update(std::span{}, 10); -// log.Flush(); -// ASSERT_EQ(data.size(), 135u); -// ASSERT_TRUE(entry.GetLastValue().has_value()); -// ASSERT_EQ(entry.GetLastValue().value(), std::vector{}); -// } - -// TEST_F(DataLogTest, StructFixedArrayA) { -// [[maybe_unused]] -// wpi::log::StructArrayLogEntry> entry0; -// wpi::log::StructLogEntry> entry{log, "a", 5}; -// std::array arr; -// entry.Append(arr); -// entry.Append(arr, 7); -// } - -// TEST_F(DataLogTest, StructB) { -// Info1 info; -// [[maybe_unused]] -// wpi::log::StructLogEntry entry0; -// wpi::log::StructLogEntry entry{log, "b", info, 5}; -// entry.Append(ThingB{}); -// entry.Append(ThingB{}, 7); -// } - -// TEST_F(DataLogTest, StructArrayB) { -// Info1 info; -// [[maybe_unused]] -// wpi::log::StructArrayLogEntry entry0; -// wpi::log::StructArrayLogEntry entry{log, "a", info, 5}; -// entry.Append({{ThingB{}, ThingB{}}}); -// entry.Append({{ThingB{}, ThingB{}}}, 7); -// } - -// TEST_F(DataLogTest, StructFixedArrayB) { -// Info1 info; -// wpi::log::StructLogEntry, Info1> entry{log, "a", info, -// 5}; -// std::array arr; -// entry.Append(arr); -// entry.Append(arr, 7); -// } - -// TEST_F(DataLogTest, StructC) { -// { -// wpi::log::StructLogEntry entry{log, "c", 5}; -// entry.Append(ThingC{}); -// entry.Append(ThingC{}, 7); -// } -// { -// Info1 info; -// wpi::log::StructLogEntry entry{log, "c1", info, 5}; -// entry.Append(ThingC{}); -// entry.Append(ThingC{}, 7); -// } -// { -// Info2 info; -// wpi::log::StructLogEntry entry{log, "c2", info, 5}; -// entry.Append(ThingC{}); -// entry.Append(ThingC{}, 7); -// } -// } - -// TEST_F(DataLogTest, StructArrayC) { -// { -// wpi::log::StructArrayLogEntry entry{log, "c", 5}; -// entry.Append({{ThingC{}, ThingC{}}}); -// entry.Append({{ThingC{}, ThingC{}}}, 7); -// } -// { -// Info1 info; -// wpi::log::StructArrayLogEntry entry{log, "c1", info, 5}; -// entry.Append({{ThingC{}, ThingC{}}}); -// entry.Append({{ThingC{}, ThingC{}}}, 7); -// } -// { -// Info2 info; -// wpi::log::StructArrayLogEntry entry{log, "c2", info, 5}; -// entry.Append({{ThingC{}, ThingC{}}}); -// entry.Append({{ThingC{}, ThingC{}}}, 7); -// } -// } - -// TEST_F(DataLogTest, StructFixedArrayC) { -// std::array arr; -// { -// wpi::log::StructLogEntry> entry{log, "c", 5}; -// entry.Append(arr); -// entry.Append(arr, 7); -// } -// { -// Info1 info; -// wpi::log::StructLogEntry, Info1> entry{log, "c1", -// info, 5}; -// entry.Append(arr); -// entry.Append(arr, 7); -// } -// { -// Info2 info; -// wpi::log::StructLogEntry, Info2> entry{log, "c2", -// info, 5}; -// entry.Append(arr); -// entry.Append(arr, 7); -// } -// } -// TODO: get tests working +// Copyright (c) FIRST and other WPILib contributors. +// Open Source Software; you can modify and/or share it under the terms of +// the WPILib BSD license file in the root directory of this project. + +#include +#include +#include +#include + +#include + +#include "wpi/DataLogWriter.h" +#include "wpi/Logger.h" +#include "wpi/raw_ostream.h" + +namespace { +struct ThingA { + int x = 0; +}; + +inline bool operator==(const ThingA& a, const ThingA& b) { + return a.x == b.x; +} + +struct ThingB { + int x = 0; +}; + +struct ThingC { + int x = 0; +}; + +struct Info1 { + int info = 0; +}; + +struct Info2 { + int info = 0; +}; +} // namespace + +template <> +struct wpi::Struct { + static constexpr std::string_view GetTypeName() { return "ThingA"; } + static constexpr size_t GetSize() { return 1; } + static constexpr std::string_view GetSchema() { return "uint8 value"; } + static ThingA Unpack(std::span data) { + return ThingA{.x = data[0]}; + } + static void Pack(std::span data, const ThingA& value) { + data[0] = value.x; + } +}; + +template <> +struct wpi::Struct { + static constexpr std::string_view GetTypeName(const Info1&) { + return "ThingB"; + } + static constexpr size_t GetSize(const Info1&) { return 1; } + static constexpr std::string_view GetSchema(const Info1&) { + return "uint8 value"; + } + static ThingB Unpack(std::span data, const Info1&) { + return ThingB{.x = data[0]}; + } + static void Pack(std::span data, const ThingB& value, const Info1&) { + data[0] = value.x; + } +}; + +template <> +struct wpi::Struct { + static constexpr std::string_view GetTypeName() { return "ThingC"; } + static constexpr size_t GetSize() { return 1; } + static constexpr std::string_view GetSchema() { return "uint8 value"; } + static ThingC Unpack(std::span data) { + return ThingC{.x = data[0]}; + } + static void Pack(std::span data, const ThingC& value) { + data[0] = value.x; + } +}; + +template <> +struct wpi::Struct { + static constexpr std::string_view GetTypeName(const Info1&) { + return "ThingC"; + } + static constexpr size_t GetSize(const Info1&) { return 1; } + static constexpr std::string_view GetSchema(const Info1&) { + return "uint8 value"; + } + static ThingC Unpack(std::span data, const Info1&) { + return ThingC{.x = data[0]}; + } + static void Pack(std::span data, const ThingC& value, const Info1&) { + data[0] = value.x; + } +}; + +template <> +struct wpi::Struct { + static constexpr std::string_view GetTypeName(const Info2&) { + return "ThingC"; + } + static constexpr size_t GetSize(const Info2&) { return 1; } + static constexpr std::string_view GetSchema(const Info2&) { + return "uint8 value"; + } + static ThingC Unpack(std::span data, const Info2&) { + return ThingC{.x = data[0]}; + } + static void Pack(std::span data, const ThingC& value, const Info2&) { + data[0] = value.x; + } +}; + +static_assert(wpi::StructSerializable); +static_assert(!wpi::StructSerializable); + +static_assert(!wpi::StructSerializable); +static_assert(wpi::StructSerializable); +static_assert(!wpi::StructSerializable); + +static_assert(wpi::StructSerializable); +static_assert(wpi::StructSerializable); +static_assert(wpi::StructSerializable); + +class DataLogTest : public ::testing::Test { + public: + wpi::Logger msglog; + std::vector data; + wpi::log::DataLogWriter log{msglog, + std::make_unique(data)}; +}; + +TEST_F(DataLogTest, SimpleInt) { + int entry = log.Start("test", "int64", "", 1); + log.AppendInteger(entry, 1, 2); + log.Flush(); + ASSERT_EQ(data.size(), 54u); +} + +TEST_F(DataLogTest, BooleanAppend) { + wpi::log::BooleanLogEntry entry{log, "a", 5}; + entry.Append(false, 7); + log.Flush(); + ASSERT_EQ(data.size(), 46u); +} + +TEST_F(DataLogTest, BooleanUpdate) { + wpi::log::BooleanLogEntry entry{log, "a", 5}; + ASSERT_FALSE(entry.GetLastValue().has_value()); + entry.Update(false, 7); + log.Flush(); + ASSERT_EQ(data.size(), 46u); + ASSERT_TRUE(entry.GetLastValue().has_value()); + ASSERT_EQ(entry.GetLastValue().value(), false); + entry.Update(false, 8); + log.Flush(); + ASSERT_EQ(data.size(), 46u); + entry.Update(true, 9); + log.Flush(); + ASSERT_EQ(data.size(), 51u); + ASSERT_TRUE(entry.GetLastValue().has_value()); + ASSERT_EQ(entry.GetLastValue().value(), true); +} + +TEST_F(DataLogTest, IntegerAppend) { + wpi::log::IntegerLogEntry entry{log, "a", 5}; + entry.Append(5, 7); + log.Flush(); + ASSERT_EQ(data.size(), 51u); +} + +TEST_F(DataLogTest, IntegerUpdate) { + wpi::log::IntegerLogEntry entry{log, "a", 5}; + ASSERT_FALSE(entry.GetLastValue().has_value()); + entry.Update(0, 7); + log.Flush(); + ASSERT_EQ(data.size(), 51u); + ASSERT_TRUE(entry.GetLastValue().has_value()); + ASSERT_EQ(entry.GetLastValue().value(), 0); + entry.Update(0, 8); + log.Flush(); + ASSERT_EQ(data.size(), 51u); + entry.Update(2, 9); + log.Flush(); + ASSERT_EQ(data.size(), 63u); + ASSERT_TRUE(entry.GetLastValue().has_value()); + ASSERT_EQ(entry.GetLastValue().value(), 2); +} + +TEST_F(DataLogTest, FloatAppend) { + wpi::log::FloatLogEntry entry{log, "a", 5}; + entry.Append(5.0, 7); + log.Flush(); + ASSERT_EQ(data.size(), 47u); +} + +TEST_F(DataLogTest, FloatUpdate) { + wpi::log::FloatLogEntry entry{log, "a", 5}; + ASSERT_FALSE(entry.GetLastValue().has_value()); + entry.Update(0.0f, 7); + log.Flush(); + ASSERT_EQ(data.size(), 47u); + ASSERT_TRUE(entry.GetLastValue().has_value()); + ASSERT_EQ(entry.GetLastValue().value(), 0.0f); + entry.Update(0.0f, 8); + log.Flush(); + ASSERT_EQ(data.size(), 47u); + entry.Update(0.1f, 9); + log.Flush(); + ASSERT_EQ(data.size(), 55u); + ASSERT_TRUE(entry.GetLastValue().has_value()); + ASSERT_EQ(entry.GetLastValue().value(), 0.1f); +} + +TEST_F(DataLogTest, DoubleAppend) { + wpi::log::DoubleLogEntry entry{log, "a", 5}; + entry.Append(5.0, 7); + log.Flush(); + ASSERT_EQ(data.size(), 52u); +} + +TEST_F(DataLogTest, DoubleUpdate) { + wpi::log::DoubleLogEntry entry{log, "a", 5}; + ASSERT_FALSE(entry.GetLastValue().has_value()); + entry.Update(0.0, 7); + log.Flush(); + ASSERT_EQ(data.size(), 52u); + ASSERT_TRUE(entry.GetLastValue().has_value()); + ASSERT_EQ(entry.GetLastValue().value(), 0.0); + entry.Update(0.0, 8); + log.Flush(); + ASSERT_EQ(data.size(), 52u); + entry.Update(0.1, 9); + log.Flush(); + ASSERT_EQ(data.size(), 64u); + ASSERT_TRUE(entry.GetLastValue().has_value()); + ASSERT_EQ(entry.GetLastValue().value(), 0.1); +} + +TEST_F(DataLogTest, StringAppend) { + wpi::log::StringLogEntry entry{log, "a", 5}; + entry.Append("x", 7); + log.Flush(); + ASSERT_EQ(data.size(), 45u); +} + +TEST_F(DataLogTest, StringUpdate) { + wpi::log::StringLogEntry entry{log, "a", 5}; + ASSERT_FALSE(entry.HasLastValue()); + + entry.Update("x", 7); + log.Flush(); + ASSERT_EQ(data.size(), 45u); + ASSERT_TRUE(entry.GetLastValue().has_value()); + ASSERT_EQ(entry.GetLastValue().value(), "x"); + + entry.Update("x", 8); + log.Flush(); + ASSERT_EQ(data.size(), 45u); + + entry.Update("y", 9); + log.Flush(); + ASSERT_EQ(data.size(), 50u); + ASSERT_TRUE(entry.GetLastValue().has_value()); + ASSERT_EQ(entry.GetLastValue().value(), "y"); + + entry.Update("yy", 10); + log.Flush(); + ASSERT_EQ(data.size(), 56u); + ASSERT_TRUE(entry.GetLastValue().has_value()); + ASSERT_EQ(entry.GetLastValue().value(), "yy"); + + entry.Update("", 11); + log.Flush(); + ASSERT_EQ(data.size(), 60u); + ASSERT_TRUE(entry.GetLastValue().has_value()); + ASSERT_EQ(entry.GetLastValue().value(), ""); +} + +TEST_F(DataLogTest, RawAppend) { + wpi::log::RawLogEntry entry{log, "a", 5}; + entry.Append({{5}}, 7); + log.Flush(); + ASSERT_EQ(data.size(), 42u); +} + +TEST_F(DataLogTest, RawUpdate) { + wpi::log::RawLogEntry entry{log, "a", 5}; + ASSERT_FALSE(entry.HasLastValue()); + + entry.Update({{5}}, 7); + log.Flush(); + ASSERT_EQ(data.size(), 42u); + ASSERT_TRUE(entry.GetLastValue().has_value()); + ASSERT_EQ(entry.GetLastValue().value(), std::vector{5}); + + entry.Update({{5}}, 8); + log.Flush(); + ASSERT_EQ(data.size(), 42u); + + entry.Update({{6}}, 9); + log.Flush(); + ASSERT_EQ(data.size(), 47u); + ASSERT_TRUE(entry.GetLastValue().has_value()); + ASSERT_EQ(entry.GetLastValue().value(), std::vector{6}); + + entry.Update({{6, 6}}, 9); + log.Flush(); + ASSERT_EQ(data.size(), 53u); + ASSERT_TRUE(entry.GetLastValue().has_value()); + ASSERT_EQ(entry.GetLastValue().value(), (std::vector{6, 6})); + + entry.Update(std::span{}, 10); + log.Flush(); + ASSERT_EQ(data.size(), 57u); + ASSERT_TRUE(entry.GetLastValue().has_value()); + ASSERT_EQ(entry.GetLastValue().value(), std::vector{}); +} + +TEST_F(DataLogTest, BooleanArrayAppendEmpty) { + wpi::log::BooleanArrayLogEntry entry{log, "a", 5}; + entry.Append(std::span{}, 7); + log.Flush(); + ASSERT_EQ(data.size(), 47u); +} + +TEST_F(DataLogTest, BooleanArrayAppend) { + wpi::log::BooleanArrayLogEntry entry{log, "a", 5}; + entry.Append({false}, 7); + log.Flush(); + ASSERT_EQ(data.size(), 48u); +} + +TEST_F(DataLogTest, BooleanArrayUpdate) { + wpi::log::BooleanArrayLogEntry entry{log, "a", 5}; + ASSERT_FALSE(entry.GetLastValue().has_value()); + entry.Update({false}, 7); + log.Flush(); + ASSERT_EQ(data.size(), 48u); + ASSERT_TRUE(entry.GetLastValue().has_value()); + ASSERT_EQ(entry.GetLastValue().value(), std::vector{false}); + entry.Update({false}, 8); + log.Flush(); + ASSERT_EQ(data.size(), 48u); + entry.Update({true}, 9); + log.Flush(); + ASSERT_EQ(data.size(), 53u); + ASSERT_TRUE(entry.GetLastValue().has_value()); + ASSERT_EQ(entry.GetLastValue().value(), std::vector{true}); + entry.Update(std::span{}, 10); + log.Flush(); + ASSERT_EQ(data.size(), 57u); + ASSERT_TRUE(entry.GetLastValue().has_value()); + ASSERT_EQ(entry.GetLastValue().value(), std::vector{}); +} + +TEST_F(DataLogTest, IntegerArrayAppendEmpty) { + wpi::log::IntegerArrayLogEntry entry{log, "a", 5}; + entry.Append(std::span{}, 7); + log.Flush(); + ASSERT_EQ(data.size(), 45u); +} + +TEST_F(DataLogTest, IntegerArrayAppend) { + wpi::log::IntegerArrayLogEntry entry{log, "a", 5}; + entry.Append({1}, 7); + log.Flush(); + ASSERT_EQ(data.size(), 53u); +} + +TEST_F(DataLogTest, IntegerArrayUpdate) { + wpi::log::IntegerArrayLogEntry entry{log, "a", 5}; + ASSERT_FALSE(entry.GetLastValue().has_value()); + entry.Update({1}, 7); + log.Flush(); + ASSERT_EQ(data.size(), 53u); + ASSERT_TRUE(entry.GetLastValue().has_value()); + ASSERT_EQ(entry.GetLastValue().value(), std::vector{1}); + entry.Update({1}, 8); + log.Flush(); + ASSERT_EQ(data.size(), 53u); + entry.Update({2}, 9); + log.Flush(); + ASSERT_EQ(data.size(), 65u); + ASSERT_TRUE(entry.GetLastValue().has_value()); + ASSERT_EQ(entry.GetLastValue().value(), std::vector{2}); + entry.Update(std::span{}, 10); + log.Flush(); + ASSERT_EQ(data.size(), 69u); + ASSERT_TRUE(entry.GetLastValue().has_value()); + ASSERT_EQ(entry.GetLastValue().value(), std::vector{}); +} + +TEST_F(DataLogTest, DoubleArrayAppendEmpty) { + wpi::log::DoubleArrayLogEntry entry{log, "a", 5}; + entry.Append(std::span{}, 7); + log.Flush(); + ASSERT_EQ(data.size(), 46u); +} + +TEST_F(DataLogTest, DoubleArrayAppend) { + wpi::log::DoubleArrayLogEntry entry{log, "a", 5}; + entry.Append({1.0}, 7); + log.Flush(); + ASSERT_EQ(data.size(), 54u); +} + +TEST_F(DataLogTest, DoubleArrayUpdate) { + wpi::log::DoubleArrayLogEntry entry{log, "a", 5}; + ASSERT_FALSE(entry.GetLastValue().has_value()); + entry.Update({1.0}, 7); + log.Flush(); + ASSERT_EQ(data.size(), 54u); + ASSERT_TRUE(entry.GetLastValue().has_value()); + ASSERT_EQ(entry.GetLastValue().value(), std::vector{1.0}); + entry.Update({1.0}, 8); + log.Flush(); + ASSERT_EQ(data.size(), 54u); + entry.Update({2.0}, 9); + log.Flush(); + ASSERT_EQ(data.size(), 66u); + ASSERT_TRUE(entry.GetLastValue().has_value()); + ASSERT_EQ(entry.GetLastValue().value(), std::vector{2}); + entry.Update(std::span{}, 10); + log.Flush(); + ASSERT_EQ(data.size(), 70u); + ASSERT_TRUE(entry.GetLastValue().has_value()); + ASSERT_EQ(entry.GetLastValue().value(), std::vector{}); +} + +TEST_F(DataLogTest, FloatArrayAppendEmpty) { + wpi::log::FloatArrayLogEntry entry{log, "a", 5}; + entry.Append(std::span{}, 7); + log.Flush(); + ASSERT_EQ(data.size(), 45u); +} + +TEST_F(DataLogTest, FloatArrayAppend) { + wpi::log::FloatArrayLogEntry entry{log, "a", 5}; + entry.Append({1.0f}, 7); + log.Flush(); + ASSERT_EQ(data.size(), 49u); +} + +TEST_F(DataLogTest, FloatArrayUpdate) { + wpi::log::FloatArrayLogEntry entry{log, "a", 5}; + ASSERT_FALSE(entry.GetLastValue().has_value()); + entry.Update({1.0f}, 7); + log.Flush(); + ASSERT_EQ(data.size(), 49u); + ASSERT_TRUE(entry.GetLastValue().has_value()); + ASSERT_EQ(entry.GetLastValue().value(), std::vector{1.0f}); + entry.Update({1.0f}, 8); + log.Flush(); + ASSERT_EQ(data.size(), 49u); + entry.Update({2.0f}, 9); + log.Flush(); + ASSERT_EQ(data.size(), 57u); + ASSERT_TRUE(entry.GetLastValue().has_value()); + ASSERT_EQ(entry.GetLastValue().value(), std::vector{2.0f}); + entry.Update(std::span{}, 10); + log.Flush(); + ASSERT_EQ(data.size(), 61u); + ASSERT_TRUE(entry.GetLastValue().has_value()); + ASSERT_EQ(entry.GetLastValue().value(), std::vector{}); +} + +TEST_F(DataLogTest, StringArrayAppendEmpty) { + wpi::log::StringArrayLogEntry entry{log, "a", 5}; + entry.Append(std::span{}, 7); + entry.Append(std::span{}, 7); + log.Flush(); + ASSERT_EQ(data.size(), 58u); +} + +TEST_F(DataLogTest, StringArrayAppend) { + wpi::log::StringArrayLogEntry entry{log, "a", 5}; + entry.Append({"x"}, 7); + log.Flush(); + ASSERT_EQ(data.size(), 55u); +} + +TEST_F(DataLogTest, StringArrayUpdate) { + wpi::log::StringArrayLogEntry entry{log, "a", 5}; + ASSERT_FALSE(entry.GetLastValue().has_value()); + entry.Update({"x"}, 7); + log.Flush(); + ASSERT_EQ(data.size(), 55u); + ASSERT_TRUE(entry.GetLastValue().has_value()); + ASSERT_EQ(entry.GetLastValue().value(), std::vector{"x"}); + entry.Update({"x"}, 8); + log.Flush(); + ASSERT_EQ(data.size(), 55u); + entry.Update({"y"}, 9); + log.Flush(); + ASSERT_EQ(data.size(), 68u); + ASSERT_TRUE(entry.GetLastValue().has_value()); + ASSERT_EQ(entry.GetLastValue().value(), std::vector{"y"}); + entry.Update(std::span{}, 10); + log.Flush(); + ASSERT_EQ(data.size(), 76u); + ASSERT_TRUE(entry.GetLastValue().has_value()); + ASSERT_EQ(entry.GetLastValue().value(), std::vector{}); +} + +TEST_F(DataLogTest, StructA) { + [[maybe_unused]] + wpi::log::StructLogEntry entry0; + wpi::log::StructLogEntry entry{log, "a", 5}; + entry.Append(ThingA{}); + entry.Append(ThingA{}, 7); +} + +TEST_F(DataLogTest, StructUpdate) { + wpi::log::StructLogEntry entry{log, "a", 5}; + ASSERT_FALSE(entry.GetLastValue().has_value()); + + entry.Update(ThingA{}, 7); + log.Flush(); + ASSERT_EQ(data.size(), 122u); + ASSERT_TRUE(entry.GetLastValue().has_value()); + ASSERT_EQ(entry.GetLastValue().value(), ThingA{}); + + entry.Update(ThingA{}, 8); + log.Flush(); + ASSERT_EQ(data.size(), 122u); + + entry.Update(ThingA{.x = 1}, 9); + log.Flush(); + ASSERT_EQ(data.size(), 127u); + ASSERT_TRUE(entry.GetLastValue().has_value()); + ASSERT_EQ(entry.GetLastValue().value(), ThingA{.x = 1}); +} + +TEST_F(DataLogTest, StructArrayA) { + [[maybe_unused]] + wpi::log::StructArrayLogEntry entry0; + wpi::log::StructArrayLogEntry entry{log, "a", 5}; + entry.Append({{ThingA{}, ThingA{}}}); + entry.Append({{ThingA{}, ThingA{}}}, 7); +} + +TEST_F(DataLogTest, StructArrayUpdate) { + wpi::log::StructArrayLogEntry entry{log, "a", 5}; + ASSERT_FALSE(entry.GetLastValue().has_value()); + + entry.Update({{ThingA{}, ThingA{.x = 1}}}, 7); + log.Flush(); + ASSERT_EQ(data.size(), 125u); + ASSERT_TRUE(entry.GetLastValue().has_value()); + ASSERT_EQ(entry.GetLastValue().value(), + (std::vector{ThingA{}, ThingA{.x = 1}})); + + entry.Update({{ThingA{}, ThingA{.x = 1}}}, 8); + log.Flush(); + ASSERT_EQ(data.size(), 125u); + + entry.Update({{ThingA{}, ThingA{.x = 2}}}, 9); + log.Flush(); + ASSERT_EQ(data.size(), 131u); + ASSERT_TRUE(entry.GetLastValue().has_value()); + ASSERT_EQ(entry.GetLastValue().value(), + (std::vector{ThingA{}, ThingA{.x = 2}})); + + entry.Update(std::span{}, 10); + log.Flush(); + ASSERT_EQ(data.size(), 135u); + ASSERT_TRUE(entry.GetLastValue().has_value()); + ASSERT_EQ(entry.GetLastValue().value(), std::vector{}); +} + +TEST_F(DataLogTest, StructFixedArrayA) { + [[maybe_unused]] + wpi::log::StructArrayLogEntry> entry0; + wpi::log::StructLogEntry> entry{log, "a", 5}; + std::array arr; + entry.Append(arr); + entry.Append(arr, 7); +} + +TEST_F(DataLogTest, StructB) { + Info1 info; + [[maybe_unused]] + wpi::log::StructLogEntry entry0; + wpi::log::StructLogEntry entry{log, "b", info, 5}; + entry.Append(ThingB{}); + entry.Append(ThingB{}, 7); +} + +TEST_F(DataLogTest, StructArrayB) { + Info1 info; + [[maybe_unused]] + wpi::log::StructArrayLogEntry entry0; + wpi::log::StructArrayLogEntry entry{log, "a", info, 5}; + entry.Append({{ThingB{}, ThingB{}}}); + entry.Append({{ThingB{}, ThingB{}}}, 7); +} + +TEST_F(DataLogTest, StructFixedArrayB) { + Info1 info; + wpi::log::StructLogEntry, Info1> entry{log, "a", info, + 5}; + std::array arr; + entry.Append(arr); + entry.Append(arr, 7); +} + +TEST_F(DataLogTest, StructC) { + { + wpi::log::StructLogEntry entry{log, "c", 5}; + entry.Append(ThingC{}); + entry.Append(ThingC{}, 7); + } + { + Info1 info; + wpi::log::StructLogEntry entry{log, "c1", info, 5}; + entry.Append(ThingC{}); + entry.Append(ThingC{}, 7); + } + { + Info2 info; + wpi::log::StructLogEntry entry{log, "c2", info, 5}; + entry.Append(ThingC{}); + entry.Append(ThingC{}, 7); + } +} + +TEST_F(DataLogTest, StructArrayC) { + { + wpi::log::StructArrayLogEntry entry{log, "c", 5}; + entry.Append({{ThingC{}, ThingC{}}}); + entry.Append({{ThingC{}, ThingC{}}}, 7); + } + { + Info1 info; + wpi::log::StructArrayLogEntry entry{log, "c1", info, 5}; + entry.Append({{ThingC{}, ThingC{}}}); + entry.Append({{ThingC{}, ThingC{}}}, 7); + } + { + Info2 info; + wpi::log::StructArrayLogEntry entry{log, "c2", info, 5}; + entry.Append({{ThingC{}, ThingC{}}}); + entry.Append({{ThingC{}, ThingC{}}}, 7); + } +} + +TEST_F(DataLogTest, StructFixedArrayC) { + std::array arr; + { + wpi::log::StructLogEntry> entry{log, "c", 5}; + entry.Append(arr); + entry.Append(arr, 7); + } + { + Info1 info; + wpi::log::StructLogEntry, Info1> entry{log, "c1", + info, 5}; + entry.Append(arr); + entry.Append(arr, 7); + } + { + Info2 info; + wpi::log::StructLogEntry, Info2> entry{log, "c2", + info, 5}; + entry.Append(arr); + entry.Append(arr, 7); + } +} diff --git a/wpiutil/src/main/native/cpp/jni/WPIUtilJNI.cpp b/wpiutil/src/main/native/cpp/jni/WPIUtilJNI.cpp index 55764642a46..4b0eab4a6fd 100644 --- a/wpiutil/src/main/native/cpp/jni/WPIUtilJNI.cpp +++ b/wpiutil/src/main/native/cpp/jni/WPIUtilJNI.cpp @@ -6,7 +6,7 @@ #include -#include "edu_wpi_first_util_WPIUtilJNI.h" +//#include "edu_wpi_first_util_WPIUtilJNI.h" #include "wpi/RawFrame.h" #include "wpi/RuntimeCheck.h" #include "wpi/Synchronization.h" From 061acdc3c699b89c8d7b1bda1843bb3fa301bc68 Mon Sep 17 00:00:00 2001 From: DeltaDizzy Date: Thu, 9 Jan 2025 15:27:43 -0600 Subject: [PATCH 26/64] libdatalog builds --- .../src/main/native/cpp/jni/DataLogJNI.cpp | 56 +++++++++---------- libdatalog/src/test/native/cpp/main.cpp | 11 ++++ ntcore/build.gradle | 2 +- .../src/main/native/cpp/jni/WPIUtilJNI.cpp | 2 +- 4 files changed, 41 insertions(+), 30 deletions(-) create mode 100644 libdatalog/src/test/native/cpp/main.cpp diff --git a/libdatalog/src/main/native/cpp/jni/DataLogJNI.cpp b/libdatalog/src/main/native/cpp/jni/DataLogJNI.cpp index 35606d42e47..0273ffd5a87 100644 --- a/libdatalog/src/main/native/cpp/jni/DataLogJNI.cpp +++ b/libdatalog/src/main/native/cpp/jni/DataLogJNI.cpp @@ -14,7 +14,7 @@ #include -//#include "edu_wpi_first_util_datalog_DataLogJNI.h" +#include "edu_wpi_first_datalog_DataLogJNI.h" #include "wpi/DataLog.h" #include "wpi/DataLogBackgroundWriter.h" #include "wpi/DataLogWriter.h" @@ -46,7 +46,7 @@ extern "C" { * Signature: (Ljava/lang/String;Ljava/lang/String;DLjava/lang/String;)J */ JNIEXPORT jlong JNICALL -Java_edu_wpi_first_util_datalog_DataLogJNI_bgCreate +Java_edu_wpi_first_datalog_DataLogJNI_bgCreate (JNIEnv* env, jclass, jstring dir, jstring filename, jdouble period, jstring extraHeader) { @@ -73,7 +73,7 @@ Java_edu_wpi_first_util_datalog_DataLogJNI_bgCreate * Signature: (JLjava/lang/String;)V */ JNIEXPORT void JNICALL -Java_edu_wpi_first_util_datalog_DataLogJNI_bgSetFilename +Java_edu_wpi_first_datalog_DataLogJNI_bgSetFilename (JNIEnv* env, jclass, jlong impl, jstring filename) { if (impl == 0) { @@ -94,7 +94,7 @@ Java_edu_wpi_first_util_datalog_DataLogJNI_bgSetFilename * Signature: (Ljava/lang/String;Ljava/lang/String;)J */ JNIEXPORT jlong JNICALL -Java_edu_wpi_first_util_datalog_DataLogJNI_fgCreate +Java_edu_wpi_first_datalog_DataLogJNI_fgCreate (JNIEnv* env, jclass, jstring filename, jstring extraHeader) { if (!filename) { @@ -138,7 +138,7 @@ Java_edu_wpi_first_util_WPIUtilJNI_now * Signature: (Ljava/lang/String;)J */ JNIEXPORT jlong JNICALL -Java_edu_wpi_first_util_datalog_DataLogJNI_fgCreateMemory +Java_edu_wpi_first_datalog_DataLogJNI_fgCreateMemory (JNIEnv* env, jclass, jstring extraHeader) { if (!extraHeader) { @@ -156,7 +156,7 @@ Java_edu_wpi_first_util_datalog_DataLogJNI_fgCreateMemory * Signature: (J)V */ JNIEXPORT void JNICALL -Java_edu_wpi_first_util_datalog_DataLogJNI_flush +Java_edu_wpi_first_datalog_DataLogJNI_flush (JNIEnv* env, jclass, jlong impl) { if (impl == 0) { @@ -172,7 +172,7 @@ Java_edu_wpi_first_util_datalog_DataLogJNI_flush * Signature: (J[BI)I */ JNIEXPORT jint JNICALL -Java_edu_wpi_first_util_datalog_DataLogJNI_copyWriteBuffer +Java_edu_wpi_first_datalog_DataLogJNI_copyWriteBuffer (JNIEnv* env, jclass, jlong impl, jbyteArray buf, jint start) { if (impl == 0) { @@ -199,7 +199,7 @@ Java_edu_wpi_first_util_datalog_DataLogJNI_copyWriteBuffer * Signature: (J)V */ JNIEXPORT void JNICALL -Java_edu_wpi_first_util_datalog_DataLogJNI_pause +Java_edu_wpi_first_datalog_DataLogJNI_pause (JNIEnv* env, jclass, jlong impl) { if (impl == 0) { @@ -215,7 +215,7 @@ Java_edu_wpi_first_util_datalog_DataLogJNI_pause * Signature: (J)V */ JNIEXPORT void JNICALL -Java_edu_wpi_first_util_datalog_DataLogJNI_resume +Java_edu_wpi_first_datalog_DataLogJNI_resume (JNIEnv* env, jclass, jlong impl) { if (impl == 0) { @@ -231,7 +231,7 @@ Java_edu_wpi_first_util_datalog_DataLogJNI_resume * Signature: (J)V */ JNIEXPORT void JNICALL -Java_edu_wpi_first_util_datalog_DataLogJNI_stop +Java_edu_wpi_first_datalog_DataLogJNI_stop (JNIEnv* env, jclass, jlong impl) { if (impl == 0) { @@ -247,7 +247,7 @@ Java_edu_wpi_first_util_datalog_DataLogJNI_stop * Signature: (JLjava/lang/String;Ljava/lang/String;[BJ)V */ JNIEXPORT void JNICALL -Java_edu_wpi_first_util_datalog_DataLogJNI_addSchema +Java_edu_wpi_first_datalog_DataLogJNI_addSchema (JNIEnv* env, jclass, jlong impl, jstring name, jstring type, jbyteArray schema, jlong timestamp) { @@ -266,7 +266,7 @@ Java_edu_wpi_first_util_datalog_DataLogJNI_addSchema * Signature: (JLjava/lang/String;Ljava/lang/String;Ljava/lang/String;J)V */ JNIEXPORT void JNICALL -Java_edu_wpi_first_util_datalog_DataLogJNI_addSchemaString +Java_edu_wpi_first_datalog_DataLogJNI_addSchemaString (JNIEnv* env, jclass, jlong impl, jstring name, jstring type, jstring schema, jlong timestamp) { @@ -288,7 +288,7 @@ Java_edu_wpi_first_util_datalog_DataLogJNI_addSchemaString * Signature: (JLjava/lang/String;Ljava/lang/String;Ljava/lang/String;J)I */ JNIEXPORT jint JNICALL -Java_edu_wpi_first_util_datalog_DataLogJNI_start +Java_edu_wpi_first_datalog_DataLogJNI_start (JNIEnv* env, jclass, jlong impl, jstring name, jstring type, jstring metadata, jlong timestamp) { @@ -307,7 +307,7 @@ Java_edu_wpi_first_util_datalog_DataLogJNI_start * Signature: (JIJ)V */ JNIEXPORT void JNICALL -Java_edu_wpi_first_util_datalog_DataLogJNI_finish +Java_edu_wpi_first_datalog_DataLogJNI_finish (JNIEnv* env, jclass, jlong impl, jint entry, jlong timestamp) { if (impl == 0) { @@ -323,7 +323,7 @@ Java_edu_wpi_first_util_datalog_DataLogJNI_finish * Signature: (JILjava/lang/String;J)V */ JNIEXPORT void JNICALL -Java_edu_wpi_first_util_datalog_DataLogJNI_setMetadata +Java_edu_wpi_first_datalog_DataLogJNI_setMetadata (JNIEnv* env, jclass, jlong impl, jint entry, jstring metadata, jlong timestamp) { @@ -341,7 +341,7 @@ Java_edu_wpi_first_util_datalog_DataLogJNI_setMetadata * Signature: (J)V */ JNIEXPORT void JNICALL -Java_edu_wpi_first_util_datalog_DataLogJNI_close +Java_edu_wpi_first_datalog_DataLogJNI_close (JNIEnv*, jclass, jlong impl) { delete reinterpret_cast(impl); @@ -353,7 +353,7 @@ Java_edu_wpi_first_util_datalog_DataLogJNI_close * Signature: (JI[BIIJ)V */ JNIEXPORT void JNICALL -Java_edu_wpi_first_util_datalog_DataLogJNI_appendRaw +Java_edu_wpi_first_datalog_DataLogJNI_appendRaw (JNIEnv* env, jclass, jlong impl, jint entry, jbyteArray value, jint start, jint length, jlong timestamp) { @@ -389,7 +389,7 @@ Java_edu_wpi_first_util_datalog_DataLogJNI_appendRaw * Signature: (JILjava/lang/Object;IIJ)V */ JNIEXPORT void JNICALL -Java_edu_wpi_first_util_datalog_DataLogJNI_appendRawBuffer +Java_edu_wpi_first_datalog_DataLogJNI_appendRawBuffer (JNIEnv* env, jclass, jlong impl, jint entry, jobject value, jint start, jint length, jlong timestamp) { @@ -425,7 +425,7 @@ Java_edu_wpi_first_util_datalog_DataLogJNI_appendRawBuffer * Signature: (JIZJ)V */ JNIEXPORT void JNICALL -Java_edu_wpi_first_util_datalog_DataLogJNI_appendBoolean +Java_edu_wpi_first_datalog_DataLogJNI_appendBoolean (JNIEnv* env, jclass, jlong impl, jint entry, jboolean value, jlong timestamp) { if (impl == 0) { @@ -441,7 +441,7 @@ Java_edu_wpi_first_util_datalog_DataLogJNI_appendBoolean * Signature: (JIJJ)V */ JNIEXPORT void JNICALL -Java_edu_wpi_first_util_datalog_DataLogJNI_appendInteger +Java_edu_wpi_first_datalog_DataLogJNI_appendInteger (JNIEnv* env, jclass, jlong impl, jint entry, jlong value, jlong timestamp) { if (impl == 0) { @@ -457,7 +457,7 @@ Java_edu_wpi_first_util_datalog_DataLogJNI_appendInteger * Signature: (JIFJ)V */ JNIEXPORT void JNICALL -Java_edu_wpi_first_util_datalog_DataLogJNI_appendFloat +Java_edu_wpi_first_datalog_DataLogJNI_appendFloat (JNIEnv* env, jclass, jlong impl, jint entry, jfloat value, jlong timestamp) { if (impl == 0) { @@ -473,7 +473,7 @@ Java_edu_wpi_first_util_datalog_DataLogJNI_appendFloat * Signature: (JIDJ)V */ JNIEXPORT void JNICALL -Java_edu_wpi_first_util_datalog_DataLogJNI_appendDouble +Java_edu_wpi_first_datalog_DataLogJNI_appendDouble (JNIEnv* env, jclass, jlong impl, jint entry, jdouble value, jlong timestamp) { if (impl == 0) { @@ -489,7 +489,7 @@ Java_edu_wpi_first_util_datalog_DataLogJNI_appendDouble * Signature: (JILjava/lang/String;J)V */ JNIEXPORT void JNICALL -Java_edu_wpi_first_util_datalog_DataLogJNI_appendString +Java_edu_wpi_first_datalog_DataLogJNI_appendString (JNIEnv* env, jclass, jlong impl, jint entry, jstring value, jlong timestamp) { if (impl == 0) { @@ -506,7 +506,7 @@ Java_edu_wpi_first_util_datalog_DataLogJNI_appendString * Signature: (JI[ZJ)V */ JNIEXPORT void JNICALL -Java_edu_wpi_first_util_datalog_DataLogJNI_appendBooleanArray +Java_edu_wpi_first_datalog_DataLogJNI_appendBooleanArray (JNIEnv* env, jclass, jlong impl, jint entry, jbooleanArray value, jlong timestamp) { @@ -528,7 +528,7 @@ Java_edu_wpi_first_util_datalog_DataLogJNI_appendBooleanArray * Signature: (JI[JJ)V */ JNIEXPORT void JNICALL -Java_edu_wpi_first_util_datalog_DataLogJNI_appendIntegerArray +Java_edu_wpi_first_datalog_DataLogJNI_appendIntegerArray (JNIEnv* env, jclass, jlong impl, jint entry, jlongArray value, jlong timestamp) { @@ -561,7 +561,7 @@ Java_edu_wpi_first_util_datalog_DataLogJNI_appendIntegerArray * Signature: (JI[FJ)V */ JNIEXPORT void JNICALL -Java_edu_wpi_first_util_datalog_DataLogJNI_appendFloatArray +Java_edu_wpi_first_datalog_DataLogJNI_appendFloatArray (JNIEnv* env, jclass, jlong impl, jint entry, jfloatArray value, jlong timestamp) { @@ -583,7 +583,7 @@ Java_edu_wpi_first_util_datalog_DataLogJNI_appendFloatArray * Signature: (JI[DJ)V */ JNIEXPORT void JNICALL -Java_edu_wpi_first_util_datalog_DataLogJNI_appendDoubleArray +Java_edu_wpi_first_datalog_DataLogJNI_appendDoubleArray (JNIEnv* env, jclass, jlong impl, jint entry, jdoubleArray value, jlong timestamp) { @@ -605,7 +605,7 @@ Java_edu_wpi_first_util_datalog_DataLogJNI_appendDoubleArray * Signature: (JI[Ljava/lang/Object;J)V */ JNIEXPORT void JNICALL -Java_edu_wpi_first_util_datalog_DataLogJNI_appendStringArray +Java_edu_wpi_first_datalog_DataLogJNI_appendStringArray (JNIEnv* env, jclass, jlong impl, jint entry, jobjectArray value, jlong timestamp) { diff --git a/libdatalog/src/test/native/cpp/main.cpp b/libdatalog/src/test/native/cpp/main.cpp new file mode 100644 index 00000000000..e993c1f14ef --- /dev/null +++ b/libdatalog/src/test/native/cpp/main.cpp @@ -0,0 +1,11 @@ +// Copyright (c) FIRST and other WPILib contributors. +// Open Source Software; you can modify and/or share it under the terms of +// the WPILib BSD license file in the root directory of this project. + +#include + +int main(int argc, char** argv) { + ::testing::InitGoogleTest(&argc, argv); + int ret = RUN_ALL_TESTS(); + return ret; +} diff --git a/ntcore/build.gradle b/ntcore/build.gradle index 4a9afad7e79..00f6f3dadf3 100644 --- a/ntcore/build.gradle +++ b/ntcore/build.gradle @@ -38,7 +38,7 @@ model { } else { lib project: ':wpinet', library: 'wpinet', linkage: 'shared' lib project: ':wpiutil', library: 'wpiutil', linkage: 'shared' - lib project: ':libdatalog', library: 'libdatalog', linkage: 'shared' + lib project: ':libdatalog', library: 'liblibdatalog', linkage: 'shared' } } } diff --git a/wpiutil/src/main/native/cpp/jni/WPIUtilJNI.cpp b/wpiutil/src/main/native/cpp/jni/WPIUtilJNI.cpp index 4b0eab4a6fd..55764642a46 100644 --- a/wpiutil/src/main/native/cpp/jni/WPIUtilJNI.cpp +++ b/wpiutil/src/main/native/cpp/jni/WPIUtilJNI.cpp @@ -6,7 +6,7 @@ #include -//#include "edu_wpi_first_util_WPIUtilJNI.h" +#include "edu_wpi_first_util_WPIUtilJNI.h" #include "wpi/RawFrame.h" #include "wpi/RuntimeCheck.h" #include "wpi/Synchronization.h" From bfe5af562159080179d1c37fa9d64a0ffad59c0e Mon Sep 17 00:00:00 2001 From: DeltaDizzy Date: Thu, 9 Jan 2025 16:07:20 -0600 Subject: [PATCH 27/64] SUCCESS --- datalogtool/CMakeLists.txt | 2 +- datalogtool/build.gradle | 1 + libdatalog/CMakeLists.txt | 1 - libdatalog/build.gradle | 2 +- ntcore/CMakeLists.txt | 2 +- ntcore/build.gradle | 6 +++++- .../src/generate/main/java/NetworkTableInstance.java.jinja | 2 +- ntcore/src/generate/main/java/NetworkTablesJNI.java.jinja | 2 +- .../edu/wpi/first/networktables/NetworkTableInstance.java | 2 +- .../java/edu/wpi/first/networktables/NetworkTablesJNI.java | 2 +- sysid/CMakeLists.txt | 4 ++-- sysid/build.gradle | 1 + wpilibc/CMakeLists.txt | 2 +- wpilibc/build.gradle | 1 + wpilibj/CMakeLists.txt | 1 + wpilibj/build.gradle | 1 + .../src/main/java/edu/wpi/first/wpilibj/DataLogManager.java | 2 +- 17 files changed, 21 insertions(+), 13 deletions(-) diff --git a/datalogtool/CMakeLists.txt b/datalogtool/CMakeLists.txt index ba9475d2eb7..9c7d1c5f3ba 100644 --- a/datalogtool/CMakeLists.txt +++ b/datalogtool/CMakeLists.txt @@ -25,7 +25,7 @@ add_executable( ${APP_ICON_MACOSX} ) wpilib_link_macos_gui(datalogtool) -target_link_libraries(datalogtool libglass ssh) +target_link_libraries(datalogtool libglass ssh libdatalog) if(WIN32) set_target_properties(datalogtool PROPERTIES WIN32_EXECUTABLE YES) diff --git a/datalogtool/build.gradle b/datalogtool/build.gradle index 418dd60294a..34092745c83 100644 --- a/datalogtool/build.gradle +++ b/datalogtool/build.gradle @@ -101,6 +101,7 @@ model { lib project: ':glass', library: 'glass', linkage: 'static' lib project: ':wpiutil', library: 'wpiutil', linkage: 'static' lib project: ':wpigui', library: 'wpigui', linkage: 'static' + lib project: ':libdatalog', library: 'libdatalog', linkage: 'static' lib project: ':thirdparty:imgui_suite', library: 'imguiSuite', linkage: 'static' nativeUtils.useRequiredLibrary(it, 'libssh') if (it.targetPlatform.operatingSystem.isWindows()) { diff --git a/libdatalog/CMakeLists.txt b/libdatalog/CMakeLists.txt index 436102e9995..dca23e54938 100644 --- a/libdatalog/CMakeLists.txt +++ b/libdatalog/CMakeLists.txt @@ -147,7 +147,6 @@ if(WITH_TESTS) target_include_directories(libdatalog_testlib INTERFACE src/test/native/include) wpilib_add_test(libdatalog src/test/native/cpp) - target_include_directories(libdatalog_test PRIVATE src/generated/test/native/cpp) target_link_libraries(libdatalog_test libdatalog googletest libdatalog_testlib wpiutil) if(MSVC) target_compile_options(libdatalog_test PRIVATE /utf-8) diff --git a/libdatalog/build.gradle b/libdatalog/build.gradle index c02d4d80d8a..0ff9c066ea2 100644 --- a/libdatalog/build.gradle +++ b/libdatalog/build.gradle @@ -4,7 +4,7 @@ ext { baseId = 'libdatalog' groupId = 'edu.wpi.first.datalog' - nativeName = 'datalog' + nativeName = 'libdatalog' devMain = 'edu.wpi.first.math.DevMain' } diff --git a/ntcore/CMakeLists.txt b/ntcore/CMakeLists.txt index 88106ca6ae3..1dc9b6c806c 100644 --- a/ntcore/CMakeLists.txt +++ b/ntcore/CMakeLists.txt @@ -53,7 +53,7 @@ if(WITH_JAVA) add_jar( ntcore_jar ${JAVA_SOURCES} - INCLUDE_JARS wpiutil_jar ${QUICKBUF_JAR} + INCLUDE_JARS wpiutil_jar ${QUICKBUF_JAR} libdatalog_jar OUTPUT_NAME ntcore OUTPUT_DIR ${WPILIB_BINARY_DIR}/${java_lib_dest} GENERATE_NATIVE_HEADERS ntcore_jni_headers diff --git a/ntcore/build.gradle b/ntcore/build.gradle index 00f6f3dadf3..81af9ceb667 100644 --- a/ntcore/build.gradle +++ b/ntcore/build.gradle @@ -38,7 +38,7 @@ model { } else { lib project: ':wpinet', library: 'wpinet', linkage: 'shared' lib project: ':wpiutil', library: 'wpiutil', linkage: 'shared' - lib project: ':libdatalog', library: 'liblibdatalog', linkage: 'shared' + lib project: ':libdatalog', library: 'libdatalog', linkage: 'shared' } } } @@ -63,3 +63,7 @@ nativeUtils.exportsConfigs { x64SymbolFilter = symbolFilter } } + +dependencies { + api project(":libdatalog") +} diff --git a/ntcore/src/generate/main/java/NetworkTableInstance.java.jinja b/ntcore/src/generate/main/java/NetworkTableInstance.java.jinja index 43003c871a9..a91ffed4ebf 100644 --- a/ntcore/src/generate/main/java/NetworkTableInstance.java.jinja +++ b/ntcore/src/generate/main/java/NetworkTableInstance.java.jinja @@ -7,8 +7,8 @@ package edu.wpi.first.networktables; import edu.wpi.first.util.WPIUtilJNI; -import edu.wpi.first.util.concurrent.Event; import edu.wpi.first.datalog.DataLog; +import edu.wpi.first.util.concurrent.Event; import edu.wpi.first.util.protobuf.Protobuf; import edu.wpi.first.util.struct.Struct; import java.nio.charset.StandardCharsets; diff --git a/ntcore/src/generate/main/java/NetworkTablesJNI.java.jinja b/ntcore/src/generate/main/java/NetworkTablesJNI.java.jinja index 2553f5f0b23..06f69e292fe 100644 --- a/ntcore/src/generate/main/java/NetworkTablesJNI.java.jinja +++ b/ntcore/src/generate/main/java/NetworkTablesJNI.java.jinja @@ -6,8 +6,8 @@ package edu.wpi.first.networktables; -import edu.wpi.first.util.RuntimeLoader; import edu.wpi.first.datalog.DataLog; +import edu.wpi.first.util.RuntimeLoader; import java.io.IOException; import java.nio.ByteBuffer; import java.util.EnumSet; diff --git a/ntcore/src/generated/main/java/edu/wpi/first/networktables/NetworkTableInstance.java b/ntcore/src/generated/main/java/edu/wpi/first/networktables/NetworkTableInstance.java index 5f94eaf3ad0..d157c27d149 100644 --- a/ntcore/src/generated/main/java/edu/wpi/first/networktables/NetworkTableInstance.java +++ b/ntcore/src/generated/main/java/edu/wpi/first/networktables/NetworkTableInstance.java @@ -7,8 +7,8 @@ package edu.wpi.first.networktables; import edu.wpi.first.util.WPIUtilJNI; -import edu.wpi.first.util.concurrent.Event; import edu.wpi.first.datalog.DataLog; +import edu.wpi.first.util.concurrent.Event; import edu.wpi.first.util.protobuf.Protobuf; import edu.wpi.first.util.struct.Struct; import java.nio.charset.StandardCharsets; diff --git a/ntcore/src/generated/main/java/edu/wpi/first/networktables/NetworkTablesJNI.java b/ntcore/src/generated/main/java/edu/wpi/first/networktables/NetworkTablesJNI.java index 4cd6594844f..4cbcb895c44 100644 --- a/ntcore/src/generated/main/java/edu/wpi/first/networktables/NetworkTablesJNI.java +++ b/ntcore/src/generated/main/java/edu/wpi/first/networktables/NetworkTablesJNI.java @@ -6,8 +6,8 @@ package edu.wpi.first.networktables; -import edu.wpi.first.util.RuntimeLoader; import edu.wpi.first.datalog.DataLog; +import edu.wpi.first.util.RuntimeLoader; import java.io.IOException; import java.nio.ByteBuffer; import java.util.EnumSet; diff --git a/sysid/CMakeLists.txt b/sysid/CMakeLists.txt index 8bcb224d4dc..86069d1ff4a 100644 --- a/sysid/CMakeLists.txt +++ b/sysid/CMakeLists.txt @@ -25,7 +25,7 @@ endif() wpilib_link_macos_gui(sysid) wpilib_target_warnings(sysid) target_include_directories(sysid PRIVATE src/main/native/include) -target_link_libraries(sysid wpimath libglass) +target_link_libraries(sysid wpimath libglass libdatalog) if(WIN32) set_target_properties(sysid PROPERTIES WIN32_EXECUTABLE YES) @@ -42,5 +42,5 @@ if(WITH_TESTS) target_compile_options(sysid_test PRIVATE /utf-8) endif() target_include_directories(sysid_test PRIVATE src/main/native/cpp src/main/native/include) - target_link_libraries(sysid_test wpimath libglass googletest) + target_link_libraries(sysid_test wpimath libglass libdatalog googletest) endif() diff --git a/sysid/build.gradle b/sysid/build.gradle index d5e927b2845..22136ad23f9 100644 --- a/sysid/build.gradle +++ b/sysid/build.gradle @@ -100,6 +100,7 @@ model { lib project: ':wpimath', library: 'wpimath', linkage: 'static' lib project: ':wpiutil', library: 'wpiutil', linkage: 'static' lib project: ':wpigui', library: 'wpigui', linkage: 'static' + lib project: ':libdatalog', library: 'libdatalog', linkage: 'static' lib project: ':thirdparty:imgui_suite', library: 'imguiSuite', linkage: 'static' if (it.targetPlatform.operatingSystem.isWindows()) { it.linker.args << 'Gdi32.lib' << 'Shell32.lib' << 'd3d11.lib' << 'd3dcompiler.lib' diff --git a/wpilibc/CMakeLists.txt b/wpilibc/CMakeLists.txt index ec1016244d4..5ece089ffc1 100644 --- a/wpilibc/CMakeLists.txt +++ b/wpilibc/CMakeLists.txt @@ -35,7 +35,7 @@ else() ) endif() -target_link_libraries(wpilibc PUBLIC hal ntcore wpimath wpiutil) +target_link_libraries(wpilibc PUBLIC hal ntcore wpimath libdatalog) set_property(TARGET wpilibc PROPERTY FOLDER "libraries") diff --git a/wpilibc/build.gradle b/wpilibc/build.gradle index 4fa684ccfc5..2d8c6f961a7 100644 --- a/wpilibc/build.gradle +++ b/wpilibc/build.gradle @@ -112,6 +112,7 @@ model { lib project: ':wpinet', library: 'wpinet', linkage: 'shared' lib project: ':wpiutil', library: 'wpiutil', linkage: 'shared' lib project: ':wpimath', library: 'wpimath', linkage: 'shared' + lib project: ':libdatalog', library: 'libdatalog', linkage: 'shared' } } "${nativeName}"(NativeLibrarySpec) { diff --git a/wpilibj/CMakeLists.txt b/wpilibj/CMakeLists.txt index 5ea91bdee0f..cb60b313b95 100644 --- a/wpilibj/CMakeLists.txt +++ b/wpilibj/CMakeLists.txt @@ -41,6 +41,7 @@ if(WITH_JAVA) wpimath_jar wpiunits_jar wpiutil_jar + libdatalog_jar OUTPUT_NAME wpilibj OUTPUT_DIR ${WPILIB_BINARY_DIR}/${java_lib_dest} ) diff --git a/wpilibj/build.gradle b/wpilibj/build.gradle index 81642b195ee..058229163ec 100644 --- a/wpilibj/build.gradle +++ b/wpilibj/build.gradle @@ -69,6 +69,7 @@ dependencies { implementation project(':wpimath') implementation project(':ntcore') implementation project(':cscore') + api project(':libdatalog') implementation project(':cameraserver') testImplementation 'org.mockito:mockito-core:4.1.0' devImplementation sourceSets.main.output diff --git a/wpilibj/src/main/java/edu/wpi/first/wpilibj/DataLogManager.java b/wpilibj/src/main/java/edu/wpi/first/wpilibj/DataLogManager.java index e395493f9cc..e78df005a1f 100644 --- a/wpilibj/src/main/java/edu/wpi/first/wpilibj/DataLogManager.java +++ b/wpilibj/src/main/java/edu/wpi/first/wpilibj/DataLogManager.java @@ -8,7 +8,7 @@ import edu.wpi.first.hal.FRCNetComm.tResourceType; import edu.wpi.first.hal.HAL; import edu.wpi.first.networktables.NetworkTableInstance; -import edu.wpi.first.util.FileLogger; +import edu.wpi.first.datalog.FileLogger; import edu.wpi.first.util.WPIUtilJNI; import edu.wpi.first.util.concurrent.Event; import edu.wpi.first.datalog.DataLog; From 0a3ff89b63dd64e341ac0d0a191dac32af3da8c4 Mon Sep 17 00:00:00 2001 From: DeltaDizzy Date: Thu, 9 Jan 2025 16:18:21 -0600 Subject: [PATCH 28/64] add to new commands --- libdatalog/CMakeLists.txt | 39 -------------------------------- wpilibNewCommands/CMakeLists.txt | 1 + wpilibNewCommands/build.gradle | 1 + 3 files changed, 2 insertions(+), 39 deletions(-) diff --git a/libdatalog/CMakeLists.txt b/libdatalog/CMakeLists.txt index dca23e54938..d90fe3e79ab 100644 --- a/libdatalog/CMakeLists.txt +++ b/libdatalog/CMakeLists.txt @@ -49,45 +49,6 @@ endforeach() if(WITH_JAVA) include(UseJava) - # if(NOT EXISTS "${WPILIB_BINARY_DIR}/wpiutil/thirdparty/jackson/jackson-core-2.15.2.jar") - # set(BASE_URL "https://search.maven.org/remotecontent?filepath=") - # set(JAR_ROOT "${WPILIB_BINARY_DIR}/wpiutil/thirdparty/jackson") - - # message(STATUS "Downloading Jackson jarfiles...") - - # download_and_check( - # "${BASE_URL}com/fasterxml/jackson/core/jackson-core/2.15.2/jackson-core-2.15.2.jar" - # "${JAR_ROOT}/jackson-core-2.15.2.jar" - # ) - # download_and_check( - # "${BASE_URL}com/fasterxml/jackson/core/jackson-databind/2.15.2/jackson-databind-2.15.2.jar" - # "${JAR_ROOT}/jackson-databind-2.15.2.jar" - # ) - # download_and_check( - # "${BASE_URL}com/fasterxml/jackson/core/jackson-annotations/2.15.2/jackson-annotations-2.15.2.jar" - # "${JAR_ROOT}/jackson-annotations-2.15.2.jar" - # ) - - # message(STATUS "All files downloaded.") - # endif() - - # file(GLOB JACKSON_JARS ${WPILIB_BINARY_DIR}/wpiutil/thirdparty/jackson/*.jar) - - # if(NOT EXISTS "${WPILIB_BINARY_DIR}/wpiutil/thirdparty/quickbuf/quickbuf-runtime-1.3.3.jar") - # set(BASE_URL "https://search.maven.org/remotecontent?filepath=") - # set(JAR_ROOT "${WPILIB_BINARY_DIR}/wpiutil/thirdparty/quickbuf") - - # message(STATUS "Downloading Quickbuf jarfile...") - # download_and_check( - # "${BASE_URL}us/hebi/quickbuf/quickbuf-runtime/1.3.3/quickbuf-runtime-1.3.3.jar" - # "${JAR_ROOT}/quickbuf-runtime-1.3.3.jar" - # ) - - # message(STATUS "Downloaded.") - # endif() - - # file(GLOB QUICKBUF_JAR ${WPILIB_BINARY_DIR}/wpiutil/thirdparty/quickbuf/*.jar) - set(CMAKE_JNI_TARGET true) file(GLOB_RECURSE JAVA_SOURCES src/main/java/*.java) diff --git a/wpilibNewCommands/CMakeLists.txt b/wpilibNewCommands/CMakeLists.txt index f7c664802e6..9c06496928b 100644 --- a/wpilibNewCommands/CMakeLists.txt +++ b/wpilibNewCommands/CMakeLists.txt @@ -22,6 +22,7 @@ if(WITH_JAVA) wpiunits_jar wpiutil_jar wpilibj_jar + libdatalog_jar OUTPUT_NAME wpilibNewCommands OUTPUT_DIR ${WPILIB_BINARY_DIR}/${java_lib_dest} ) diff --git a/wpilibNewCommands/build.gradle b/wpilibNewCommands/build.gradle index 588c3113b36..1c0906bd7e8 100644 --- a/wpilibNewCommands/build.gradle +++ b/wpilibNewCommands/build.gradle @@ -21,6 +21,7 @@ dependencies { implementation project(':hal') implementation project(':wpimath') implementation project(':wpilibj') + api project(':libdatalog') testImplementation 'org.mockito:mockito-core:4.1.0' } From 5bb8275336f58baacb7f3b686c00baea862a0a81 Mon Sep 17 00:00:00 2001 From: DeltaDizzy Date: Thu, 9 Jan 2025 16:18:39 -0600 Subject: [PATCH 29/64] newline at end of build.bazel --- libdatalog/BUILD.bazel | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/libdatalog/BUILD.bazel b/libdatalog/BUILD.bazel index 0c987c8f982..1d1dcec7ab6 100644 --- a/libdatalog/BUILD.bazel +++ b/libdatalog/BUILD.bazel @@ -16,4 +16,4 @@ cc_library( deps = [ "//wpiutil:wpiutil.static", ] -) \ No newline at end of file +) From 803831b6bf62b91e5960ee73fd8119a654a84b84 Mon Sep 17 00:00:00 2001 From: DeltaDizzy Date: Thu, 9 Jan 2025 16:58:41 -0600 Subject: [PATCH 30/64] Revert "move kInvalidFile declaration to header" This reverts commit 79fb5a3954014fdc5003ce6b9f688eb89f070372. This error will require more invasive changes on another day. --- wpiutil/src/main/native/cpp/fs.cpp | 2 ++ 1 file changed, 2 insertions(+) diff --git a/wpiutil/src/main/native/cpp/fs.cpp b/wpiutil/src/main/native/cpp/fs.cpp index 82bd3857eed..4830d9e2318 100644 --- a/wpiutil/src/main/native/cpp/fs.cpp +++ b/wpiutil/src/main/native/cpp/fs.cpp @@ -59,6 +59,8 @@ namespace fs { #pragma warning(disable : 4244 4267 4146) #endif +const file_t kInvalidFile = INVALID_HANDLE_VALUE; + static DWORD nativeDisposition(CreationDisposition Disp, OpenFlags Flags) { switch (Disp) { case CD_CreateAlways: From eb2005af8a4a8c22339632607c5356a38d00faf5 Mon Sep 17 00:00:00 2001 From: DeltaDizzy Date: Sun, 12 Jan 2025 14:51:28 -0600 Subject: [PATCH 31/64] uni time --- datalogtool/CMakeLists.txt | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/datalogtool/CMakeLists.txt b/datalogtool/CMakeLists.txt index 9c7d1c5f3ba..0ac6bf017c1 100644 --- a/datalogtool/CMakeLists.txt +++ b/datalogtool/CMakeLists.txt @@ -25,7 +25,7 @@ add_executable( ${APP_ICON_MACOSX} ) wpilib_link_macos_gui(datalogtool) -target_link_libraries(datalogtool libglass ssh libdatalog) +target_link_libraries(datalogtool libglass ssh libdatalog wpiutil) if(WIN32) set_target_properties(datalogtool PROPERTIES WIN32_EXECUTABLE YES) From 1916e4c29daf9f855017ea5da25dbec85941ff56 Mon Sep 17 00:00:00 2001 From: DeltaDizzy Date: Thu, 16 Jan 2025 20:35:04 -0500 Subject: [PATCH 32/64] constexpr invalid file --- wpiutil/src/main/native/cpp/fs.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/wpiutil/src/main/native/cpp/fs.cpp b/wpiutil/src/main/native/cpp/fs.cpp index 4830d9e2318..4b5af969200 100644 --- a/wpiutil/src/main/native/cpp/fs.cpp +++ b/wpiutil/src/main/native/cpp/fs.cpp @@ -59,7 +59,7 @@ namespace fs { #pragma warning(disable : 4244 4267 4146) #endif -const file_t kInvalidFile = INVALID_HANDLE_VALUE; +#define kInvalidFile reinterpret_cast(-1) static DWORD nativeDisposition(CreationDisposition Disp, OpenFlags Flags) { switch (Disp) { From 84b7c0674c3b55da8b61e5f147e2a459ac1fbf79 Mon Sep 17 00:00:00 2001 From: DeltaDizzy Date: Thu, 16 Jan 2025 21:03:42 -0500 Subject: [PATCH 33/64] use macro in fs.h --- wpiutil/src/main/native/cpp/fs.cpp | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/wpiutil/src/main/native/cpp/fs.cpp b/wpiutil/src/main/native/cpp/fs.cpp index 4b5af969200..6ea69bfc195 100644 --- a/wpiutil/src/main/native/cpp/fs.cpp +++ b/wpiutil/src/main/native/cpp/fs.cpp @@ -21,6 +21,7 @@ #define _WIN32_WINNT 0x0601 #define _WIN32_IE 0x0800 // MinGW at it again. FIXME: verify if still needed. #define WIN32_LEAN_AND_MEAN +#define kInvalidFile reinterpret_cast(-1) #ifndef NOMINMAX #define NOMINMAX #endif @@ -59,8 +60,6 @@ namespace fs { #pragma warning(disable : 4244 4267 4146) #endif -#define kInvalidFile reinterpret_cast(-1) - static DWORD nativeDisposition(CreationDisposition Disp, OpenFlags Flags) { switch (Disp) { case CD_CreateAlways: From ad1875971f21a144e5a8d5fc3d5b59628c40a0ad Mon Sep 17 00:00:00 2001 From: DeltaDizzy Date: Fri, 24 Jan 2025 23:11:31 -0500 Subject: [PATCH 34/64] Add more DataLogJNI implementations Co-authored-by: Gold856 <117957790+Gold856@users.noreply.github.com> --- .../src/main/native/cpp/jni/DataLogJNI.cpp | 27 +++++++++++++++++++ 1 file changed, 27 insertions(+) diff --git a/libdatalog/src/main/native/cpp/jni/DataLogJNI.cpp b/libdatalog/src/main/native/cpp/jni/DataLogJNI.cpp index 0273ffd5a87..ae33e592c11 100644 --- a/libdatalog/src/main/native/cpp/jni/DataLogJNI.cpp +++ b/libdatalog/src/main/native/cpp/jni/DataLogJNI.cpp @@ -26,6 +26,33 @@ using namespace wpi::log; static bool mockTimeEnabled = false; static uint64_t mockNow = 0; +static JException illegalArgEx; +static JException indexOobEx; +static JException ioEx; +static JException nullPointerEx; + +static const JExceptionInit exceptions[] = { + {"java/lang/IllegalArgumentException", &illegalArgEx}, + {"java/lang/IndexOutOfBoundsException", &indexOobEx}, + {"java/io/IOException", &ioEx}, + {"java/lang/NullPointerException", &nullPointerEx}}; + +void wpi::ThrowIllegalArgumentException(JNIEnv* env, std::string_view msg) { + illegalArgEx.Throw(env, msg); +} + +void wpi::ThrowIndexOobException(JNIEnv* env, std::string_view msg) { + indexOobEx.Throw(env, msg); +} + +void wpi::ThrowIOException(JNIEnv* env, std::string_view msg) { + ioEx.Throw(env, msg); +} + +void wpi::ThrowNullPointerException(JNIEnv* env, std::string_view msg) { + nullPointerEx.Throw(env, msg); +} + namespace { class buf_ostream : public wpi::raw_uvector_ostream { private: From 4131ad21b19873463ae7342c87784a1b37b034ef Mon Sep 17 00:00:00 2001 From: DeltaDizzy Date: Sun, 26 Jan 2025 12:58:00 -0500 Subject: [PATCH 35/64] move jni load and add ntcore dependency --- .../src/main/native/cpp/jni/DataLogJNI.cpp | 27 +++++++++++++++++++ .../{include/wpi => cpp/jni}/DataLogJNI.h | 0 ntcore/build.gradle | 2 ++ 3 files changed, 29 insertions(+) rename libdatalog/src/main/native/{include/wpi => cpp/jni}/DataLogJNI.h (100%) diff --git a/libdatalog/src/main/native/cpp/jni/DataLogJNI.cpp b/libdatalog/src/main/native/cpp/jni/DataLogJNI.cpp index ae33e592c11..77237d62995 100644 --- a/libdatalog/src/main/native/cpp/jni/DataLogJNI.cpp +++ b/libdatalog/src/main/native/cpp/jni/DataLogJNI.cpp @@ -67,6 +67,33 @@ class buf_ostream : public wpi::raw_uvector_ostream { extern "C" { +JNIEXPORT jint JNICALL JNI_OnLoad(JavaVM* vm, void* reserved) { + JNIEnv* env; + if (vm->GetEnv(reinterpret_cast(&env), JNI_VERSION_1_6) != JNI_OK) { + return JNI_ERR; + } + + for (auto& c : exceptions) { + *c.cls = JException(env, c.name); + if (!*c.cls) { + return JNI_ERR; + } + } + + return JNI_VERSION_1_6; +} + +JNIEXPORT void JNICALL JNI_OnUnload(JavaVM* vm, void* reserved) { + JNIEnv* env; + if (vm->GetEnv(reinterpret_cast(&env), JNI_VERSION_1_6) != JNI_OK) { + return; + } + + for (auto& c : exceptions) { + c.cls->free(env); + } +} + /* * Class: edu_wpi_first_util_datalog_DataLogJNI * Method: bgCreate diff --git a/libdatalog/src/main/native/include/wpi/DataLogJNI.h b/libdatalog/src/main/native/cpp/jni/DataLogJNI.h similarity index 100% rename from libdatalog/src/main/native/include/wpi/DataLogJNI.h rename to libdatalog/src/main/native/cpp/jni/DataLogJNI.h diff --git a/ntcore/build.gradle b/ntcore/build.gradle index 81af9ceb667..3116b28b575 100644 --- a/ntcore/build.gradle +++ b/ntcore/build.gradle @@ -1,10 +1,12 @@ ext { addNtcoreDependency = { binary, shared-> binary.lib project: ':ntcore', library: 'ntcore', linkage: shared + binary.lib project: ':libdatalog', library: 'libdatalog', linkage: shared } addNtcoreJniDependency = { binary-> binary.lib project: ':ntcore', library: 'ntcoreJNIShared', linkage: 'shared' + binary.lib project: ':libdatalog', library: 'libdatalogJNIShared', linkage: 'shared' } nativeName = 'ntcore' From 76e85b84fca49efbf99df1390d42721ff3d9d560 Mon Sep 17 00:00:00 2001 From: DeltaDizzy Date: Sun, 26 Jan 2025 13:01:05 -0500 Subject: [PATCH 36/64] fix jni path --- libdatalog/src/main/native/cpp/jni/DataLogJNI.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/libdatalog/src/main/native/cpp/jni/DataLogJNI.cpp b/libdatalog/src/main/native/cpp/jni/DataLogJNI.cpp index 77237d62995..0f5b92d4ec1 100644 --- a/libdatalog/src/main/native/cpp/jni/DataLogJNI.cpp +++ b/libdatalog/src/main/native/cpp/jni/DataLogJNI.cpp @@ -4,7 +4,7 @@ #include -#include "wpi/DataLogJNI.h" +#include "DataLogJNI.h" #include "wpi/FileLogger.h" From 12ec8780f369f9170fc5d3aef84f5a981c162c46 Mon Sep 17 00:00:00 2001 From: DeltaDizzy Date: Sun, 26 Jan 2025 13:16:33 -0500 Subject: [PATCH 37/64] fix java jni and bazel --- libdatalog/BUILD.bazel | 3 +- .../edu/wpi/first/datalog/DataLogJNI.java | 59 ++++++++++++++++++- .../edu/wpi/first/wpilibj/DataLogManager.java | 10 ++-- .../edu/wpi/first/wpilibj/DriverStation.java | 10 ++-- .../first/wpilibj/sysid/SysIdRoutineLog.java | 4 +- 5 files changed, 70 insertions(+), 16 deletions(-) diff --git a/libdatalog/BUILD.bazel b/libdatalog/BUILD.bazel index 1d1dcec7ab6..b9f57737ed1 100644 --- a/libdatalog/BUILD.bazel +++ b/libdatalog/BUILD.bazel @@ -1,5 +1,4 @@ load("@rules_cc//cc:defs.bzl", "cc_library") -load("//shared/bazel/rules/gen:gen-resources.bzl", "generate_resources") cc_library( name = "libdatalog.static", @@ -15,5 +14,5 @@ cc_library( visibility = ["//visibility:public"], deps = [ "//wpiutil:wpiutil.static", - ] + ], ) diff --git a/libdatalog/src/main/java/edu/wpi/first/datalog/DataLogJNI.java b/libdatalog/src/main/java/edu/wpi/first/datalog/DataLogJNI.java index fab19c25ae4..eff7521de0e 100644 --- a/libdatalog/src/main/java/edu/wpi/first/datalog/DataLogJNI.java +++ b/libdatalog/src/main/java/edu/wpi/first/datalog/DataLogJNI.java @@ -4,16 +4,71 @@ package edu.wpi.first.datalog; -import edu.wpi.first.util.WPIUtilJNI; import java.io.IOException; import java.nio.ByteBuffer; +import java.util.concurrent.atomic.AtomicBoolean; + +import edu.wpi.first.util.RuntimeLoader; /** * DataLog wpiutil JNI Functions. * * @see "wpiutil/DataLog.h" */ -public class DataLogJNI extends WPIUtilJNI { +public class DataLogJNI { + static boolean libraryLoaded = false; + + /** Sets whether JNI should be loaded in the static block. */ + public static class Helper { + private static AtomicBoolean extractOnStaticLoad = new AtomicBoolean(true); + + /** + * Returns true if the JNI should be loaded in the static block. + * + * @return True if the JNI should be loaded in the static block. + */ + public static boolean getExtractOnStaticLoad() { + return extractOnStaticLoad.get(); + } + + /** + * Sets whether the JNI should be loaded in the static block. + * + * @param load Whether the JNI should be loaded in the static block. + */ + public static void setExtractOnStaticLoad(boolean load) { + extractOnStaticLoad.set(load); + } + + /** Utility class. */ + private Helper() {} + } + + static { + if (Helper.getExtractOnStaticLoad()) { + try { + RuntimeLoader.loadLibrary("datalogjni"); + } catch (Exception ex) { + ex.printStackTrace(); + System.exit(1); + } + libraryLoaded = true; + } + } + + /** + * Force load the library. + * + * @throws IOException if the library failed to load + */ + public static synchronized void forceLoad() throws IOException { + if (libraryLoaded) { + return; + } + RuntimeLoader.loadLibrary("datalogjni"); + libraryLoaded = true; + } + /** * Create a new Data Log background writer. The log will be initially created with a temporary * filename. diff --git a/wpilibj/src/main/java/edu/wpi/first/wpilibj/DataLogManager.java b/wpilibj/src/main/java/edu/wpi/first/wpilibj/DataLogManager.java index e78df005a1f..33fd32e0bfa 100644 --- a/wpilibj/src/main/java/edu/wpi/first/wpilibj/DataLogManager.java +++ b/wpilibj/src/main/java/edu/wpi/first/wpilibj/DataLogManager.java @@ -4,17 +4,17 @@ package edu.wpi.first.wpilibj; +import edu.wpi.first.datalog.DataLog; +import edu.wpi.first.datalog.DataLogBackgroundWriter; +import edu.wpi.first.datalog.FileLogger; +import edu.wpi.first.datalog.IntegerLogEntry; +import edu.wpi.first.datalog.StringLogEntry; import edu.wpi.first.hal.FRCNetComm.tInstances; import edu.wpi.first.hal.FRCNetComm.tResourceType; import edu.wpi.first.hal.HAL; import edu.wpi.first.networktables.NetworkTableInstance; -import edu.wpi.first.datalog.FileLogger; import edu.wpi.first.util.WPIUtilJNI; import edu.wpi.first.util.concurrent.Event; -import edu.wpi.first.datalog.DataLog; -import edu.wpi.first.datalog.DataLogBackgroundWriter; -import edu.wpi.first.datalog.IntegerLogEntry; -import edu.wpi.first.datalog.StringLogEntry; import java.io.File; import java.io.IOException; import java.nio.file.Files; diff --git a/wpilibj/src/main/java/edu/wpi/first/wpilibj/DriverStation.java b/wpilibj/src/main/java/edu/wpi/first/wpilibj/DriverStation.java index a29d6c661b5..eed127ce555 100644 --- a/wpilibj/src/main/java/edu/wpi/first/wpilibj/DriverStation.java +++ b/wpilibj/src/main/java/edu/wpi/first/wpilibj/DriverStation.java @@ -4,6 +4,11 @@ package edu.wpi.first.wpilibj; +import edu.wpi.first.datalog.BooleanArrayLogEntry; +import edu.wpi.first.datalog.BooleanLogEntry; +import edu.wpi.first.datalog.DataLog; +import edu.wpi.first.datalog.FloatArrayLogEntry; +import edu.wpi.first.datalog.IntegerArrayLogEntry; import edu.wpi.first.hal.AllianceStationID; import edu.wpi.first.hal.ControlWord; import edu.wpi.first.hal.DriverStationJNI; @@ -16,11 +21,6 @@ import edu.wpi.first.networktables.StringTopic; import edu.wpi.first.util.EventVector; import edu.wpi.first.util.WPIUtilJNI; -import edu.wpi.first.datalog.BooleanArrayLogEntry; -import edu.wpi.first.datalog.BooleanLogEntry; -import edu.wpi.first.datalog.DataLog; -import edu.wpi.first.datalog.FloatArrayLogEntry; -import edu.wpi.first.datalog.IntegerArrayLogEntry; import java.nio.ByteBuffer; import java.util.Map; import java.util.Optional; diff --git a/wpilibj/src/main/java/edu/wpi/first/wpilibj/sysid/SysIdRoutineLog.java b/wpilibj/src/main/java/edu/wpi/first/wpilibj/sysid/SysIdRoutineLog.java index 468e586bdcc..f80332a26be 100644 --- a/wpilibj/src/main/java/edu/wpi/first/wpilibj/sysid/SysIdRoutineLog.java +++ b/wpilibj/src/main/java/edu/wpi/first/wpilibj/sysid/SysIdRoutineLog.java @@ -12,6 +12,8 @@ import static edu.wpi.first.units.Units.Second; import static edu.wpi.first.units.Units.Volts; +import edu.wpi.first.datalog.DoubleLogEntry; +import edu.wpi.first.datalog.StringLogEntry; import edu.wpi.first.units.measure.Angle; import edu.wpi.first.units.measure.AngularAcceleration; import edu.wpi.first.units.measure.AngularVelocity; @@ -20,8 +22,6 @@ import edu.wpi.first.units.measure.LinearAcceleration; import edu.wpi.first.units.measure.LinearVelocity; import edu.wpi.first.units.measure.Voltage; -import edu.wpi.first.datalog.DoubleLogEntry; -import edu.wpi.first.datalog.StringLogEntry; import edu.wpi.first.wpilibj.DataLogManager; import java.util.HashMap; import java.util.Map; From 075211a0f70a338111614f67c078b7db7369d984 Mon Sep 17 00:00:00 2001 From: DeltaDizzy Date: Sun, 26 Jan 2025 13:25:37 -0500 Subject: [PATCH 38/64] re-add wpiutiljni to datalogjni --- .../src/main/java/edu/wpi/first/datalog/DataLogJNI.java | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/libdatalog/src/main/java/edu/wpi/first/datalog/DataLogJNI.java b/libdatalog/src/main/java/edu/wpi/first/datalog/DataLogJNI.java index eff7521de0e..c1500f8826d 100644 --- a/libdatalog/src/main/java/edu/wpi/first/datalog/DataLogJNI.java +++ b/libdatalog/src/main/java/edu/wpi/first/datalog/DataLogJNI.java @@ -9,13 +9,14 @@ import java.util.concurrent.atomic.AtomicBoolean; import edu.wpi.first.util.RuntimeLoader; +import edu.wpi.first.util.WPIUtilJNI; /** * DataLog wpiutil JNI Functions. * - * @see "wpiutil/DataLog.h" + * @see "libdatalog/DataLog.h" */ -public class DataLogJNI { +public class DataLogJNI extends WPIUtilJNI { static boolean libraryLoaded = false; /** Sets whether JNI should be loaded in the static block. */ From b945e369bbaa61b3a93ac019d635c3d547ff72c4 Mon Sep 17 00:00:00 2001 From: DeltaDizzy Date: Sun, 26 Jan 2025 13:52:45 -0500 Subject: [PATCH 39/64] wpiformat --- libdatalog/CMakeLists.txt | 20 +++--- libdatalog/examples/printlog/printlog.cpp | 9 ++- libdatalog/examples/writelog/writelog.cpp | 4 +- libdatalog/libdatalog-config.cmake.in | 2 +- libdatalog/src/main/native/cpp/DataLog.cpp | 13 ++-- .../native/cpp/DataLogBackgroundWriter.cpp | 2 +- .../src/main/native/cpp/DataLogReader.cpp | 7 +- .../main/native/cpp/DataLogReaderThread.cpp | 7 +- .../src/main/native/cpp/DataLogWriter.cpp | 5 +- libdatalog/src/main/native/cpp/FileLogger.cpp | 6 +- .../src/main/native/cpp/jni/DataLogJNI.cpp | 67 +++++++++---------- .../src/main/native/cpp/jni/DataLogJNI.h | 7 +- .../src/main/native/include/wpi/DataLog.h | 18 ++--- .../include/wpi/DataLogBackgroundWriter.h | 6 +- .../main/native/include/wpi/DataLogReader.h | 2 +- .../native/include/wpi/DataLogReaderThread.h | 12 ++-- .../main/native/include/wpi/DataLogWriter.h | 2 +- .../src/main/native/include/wpi/DataLog_c.h | 1 + .../src/main/native/include/wpi/FileLogger.h | 2 +- .../src/test/native/cpp/DataLogTest.cpp | 7 +- .../src/test/native/cpp/FileLoggerTest.cpp | 3 +- 21 files changed, 97 insertions(+), 105 deletions(-) diff --git a/libdatalog/CMakeLists.txt b/libdatalog/CMakeLists.txt index d90fe3e79ab..879fd5f2094 100644 --- a/libdatalog/CMakeLists.txt +++ b/libdatalog/CMakeLists.txt @@ -2,15 +2,9 @@ project(libdatalog) include(CompileWarnings) -file( - GLOB libdatalog_native_src - src/main/native/cpp/*.cpp -) +file(GLOB libdatalog_native_src src/main/native/cpp/*.cpp) -file( - GLOB libdatalog_jni_src - src/main/native/cpp/jni/DataLogJNI.cpp -) +file(GLOB libdatalog_jni_src src/main/native/cpp/jni/DataLogJNI.cpp) list(REMOVE_ITEM libdatalog_native_src ${libdatalog_jni_src}) add_library(libdatalog ${libdatalog_native_src}) @@ -28,8 +22,7 @@ wpilib_target_warnings(libdatalog) target_include_directories( libdatalog - PUBLIC - $ + PUBLIC $ ) target_link_libraries(libdatalog PRIVATE wpiutil) @@ -66,7 +59,11 @@ if(WITH_JAVA) set_property(TARGET libdatalog_jar PROPERTY FOLDER "java") install_jar(libdatalog_jar DESTINATION ${java_lib_dest}) - install_jar_exports(TARGETS libdatalog_jar FILE libdatalog_jar.cmake DESTINATION share/libdatalog) + install_jar_exports( + TARGETS libdatalog_jar + FILE libdatalog_jar.cmake + DESTINATION share/libdatalog + ) add_library(libdatalogjni ${libdatalog_jni_src}) wpilib_target_warnings(libdatalogjni) @@ -113,4 +110,3 @@ if(WITH_TESTS) target_compile_options(libdatalog_test PRIVATE /utf-8) endif() endif() - diff --git a/libdatalog/examples/printlog/printlog.cpp b/libdatalog/examples/printlog/printlog.cpp index a17d30b3852..68db716e2e5 100644 --- a/libdatalog/examples/printlog/printlog.cpp +++ b/libdatalog/examples/printlog/printlog.cpp @@ -9,11 +9,10 @@ #include #include #include - -#include "wpi/DataLogReader.h" -#include "wpi/DenseMap.h" -#include "wpi/MemoryBuffer.h" -#include "wpi/print.h" +#include +#include +#include +#include int main(int argc, const char** argv) { if (argc != 2) { diff --git a/libdatalog/examples/writelog/writelog.cpp b/libdatalog/examples/writelog/writelog.cpp index dd9f8fa33da..9546a959ef3 100644 --- a/libdatalog/examples/writelog/writelog.cpp +++ b/libdatalog/examples/writelog/writelog.cpp @@ -8,8 +8,8 @@ #include #include -#include "wpi/DataLogBackgroundWriter.h" -#include "wpi/print.h" +#include +#include int main(int argc, char** argv) { using std::chrono::duration_cast; diff --git a/libdatalog/libdatalog-config.cmake.in b/libdatalog/libdatalog-config.cmake.in index 04e55b994b7..eb26b9cb314 100644 --- a/libdatalog/libdatalog-config.cmake.in +++ b/libdatalog/libdatalog-config.cmake.in @@ -2,4 +2,4 @@ include(${SELF_DIR}/wpiutil.cmake) if(@WITH_JAVA@) include(${SELF_DIR}/wpiutil_jar.cmake) -endif() \ No newline at end of file +endif() diff --git a/libdatalog/src/main/native/cpp/DataLog.cpp b/libdatalog/src/main/native/cpp/DataLog.cpp index 16e66187f80..56c0ddfa900 100644 --- a/libdatalog/src/main/native/cpp/DataLog.cpp +++ b/libdatalog/src/main/native/cpp/DataLog.cpp @@ -2,8 +2,6 @@ // Open Source Software; you can modify and/or share it under the terms of // the WPILib BSD license file in the root directory of this project. -#include "wpi/DataLog.h" - #include #include #include @@ -13,11 +11,12 @@ #include #include -#include "wpi/Endian.h" -#include "wpi/Logger.h" -#include "wpi/SmallString.h" -#include "wpi/print.h" -#include "wpi/timestamp.h" +#include +#include +#include +#include +#include +#include using namespace wpi::log; diff --git a/libdatalog/src/main/native/cpp/DataLogBackgroundWriter.cpp b/libdatalog/src/main/native/cpp/DataLogBackgroundWriter.cpp index c8028af1289..98b10609ba9 100644 --- a/libdatalog/src/main/native/cpp/DataLogBackgroundWriter.cpp +++ b/libdatalog/src/main/native/cpp/DataLogBackgroundWriter.cpp @@ -2,7 +2,7 @@ // Open Source Software; you can modify and/or share it under the terms of // the WPILib BSD license file in the root directory of this project. -#include "wpi/DataLogBackgroundWriter.h" +#include #ifndef _WIN32 #include diff --git a/libdatalog/src/main/native/cpp/DataLogReader.cpp b/libdatalog/src/main/native/cpp/DataLogReader.cpp index 7eb88a6518b..5d4f1a89c4f 100644 --- a/libdatalog/src/main/native/cpp/DataLogReader.cpp +++ b/libdatalog/src/main/native/cpp/DataLogReader.cpp @@ -2,13 +2,12 @@ // Open Source Software; you can modify and/or share it under the terms of // the WPILib BSD license file in the root directory of this project. -#include "wpi/DataLogReader.h" - #include #include -#include "wpi/DataLog.h" -#include "wpi/Endian.h" +#include +#include +#include using namespace wpi::log; diff --git a/libdatalog/src/main/native/cpp/DataLogReaderThread.cpp b/libdatalog/src/main/native/cpp/DataLogReaderThread.cpp index 0fccaa22329..766f19bca94 100644 --- a/libdatalog/src/main/native/cpp/DataLogReaderThread.cpp +++ b/libdatalog/src/main/native/cpp/DataLogReaderThread.cpp @@ -2,14 +2,13 @@ // Open Source Software; you can modify and/or share it under the terms of // the WPILib BSD license file in the root directory of this project. -#include "wpi/DataLogReaderThread.h" +#include +#include +#include #include #include -#include -#include - using namespace wpi::log; DataLogReaderThread::~DataLogReaderThread() { diff --git a/libdatalog/src/main/native/cpp/DataLogWriter.cpp b/libdatalog/src/main/native/cpp/DataLogWriter.cpp index b33266f75b5..4c1befea86c 100644 --- a/libdatalog/src/main/native/cpp/DataLogWriter.cpp +++ b/libdatalog/src/main/native/cpp/DataLogWriter.cpp @@ -2,13 +2,12 @@ // Open Source Software; you can modify and/or share it under the terms of // the WPILib BSD license file in the root directory of this project. -#include "wpi/DataLogWriter.h" - #include #include #include -#include "wpi/raw_ostream.h" +#include +#include using namespace wpi::log; diff --git a/libdatalog/src/main/native/cpp/FileLogger.cpp b/libdatalog/src/main/native/cpp/FileLogger.cpp index 70ee9f95ec3..6a7dc5ced10 100644 --- a/libdatalog/src/main/native/cpp/FileLogger.cpp +++ b/libdatalog/src/main/native/cpp/FileLogger.cpp @@ -2,8 +2,6 @@ // Open Source Software; you can modify and/or share it under the terms of // the WPILib BSD license file in the root directory of this project. -#include "wpi/FileLogger.h" - #ifdef __linux__ #include #include @@ -18,8 +16,8 @@ #include #include - -#include "wpi/StringExtras.h" +#include +#include namespace wpi { FileLogger::FileLogger(std::string_view file, diff --git a/libdatalog/src/main/native/cpp/jni/DataLogJNI.cpp b/libdatalog/src/main/native/cpp/jni/DataLogJNI.cpp index 0f5b92d4ec1..f924c83f03b 100644 --- a/libdatalog/src/main/native/cpp/jni/DataLogJNI.cpp +++ b/libdatalog/src/main/native/cpp/jni/DataLogJNI.cpp @@ -2,23 +2,22 @@ // Open Source Software; you can modify and/or share it under the terms of // the WPILib BSD license file in the root directory of this project. -#include - #include "DataLogJNI.h" -#include "wpi/FileLogger.h" +#include #include #include #include #include +#include +#include +#include +#include +#include #include "edu_wpi_first_datalog_DataLogJNI.h" -#include "wpi/DataLog.h" -#include "wpi/DataLogBackgroundWriter.h" -#include "wpi/DataLogWriter.h" -#include "wpi/jni_util.h" using namespace wpi::java; using namespace wpi::log; @@ -95,7 +94,7 @@ JNIEXPORT void JNICALL JNI_OnUnload(JavaVM* vm, void* reserved) { } /* - * Class: edu_wpi_first_util_datalog_DataLogJNI + * Class: edu_wpi_first_datalog_DataLogJNI * Method: bgCreate * Signature: (Ljava/lang/String;Ljava/lang/String;DLjava/lang/String;)J */ @@ -122,7 +121,7 @@ Java_edu_wpi_first_datalog_DataLogJNI_bgCreate } /* - * Class: edu_wpi_first_util_datalog_DataLogJNI + * Class: edu_wpi_first_datalog_DataLogJNI * Method: bgSetFilename * Signature: (JLjava/lang/String;)V */ @@ -143,7 +142,7 @@ Java_edu_wpi_first_datalog_DataLogJNI_bgSetFilename } /* - * Class: edu_wpi_first_util_datalog_DataLogJNI + * Class: edu_wpi_first_datalog_DataLogJNI * Method: fgCreate * Signature: (Ljava/lang/String;Ljava/lang/String;)J */ @@ -187,7 +186,7 @@ Java_edu_wpi_first_util_WPIUtilJNI_now } /* - * Class: edu_wpi_first_util_datalog_DataLogJNI + * Class: edu_wpi_first_datalog_DataLogJNI * Method: fgCreateMemory * Signature: (Ljava/lang/String;)J */ @@ -205,7 +204,7 @@ Java_edu_wpi_first_datalog_DataLogJNI_fgCreateMemory } /* - * Class: edu_wpi_first_util_datalog_DataLogJNI + * Class: edu_wpi_first_datalog_DataLogJNI * Method: flush * Signature: (J)V */ @@ -221,7 +220,7 @@ Java_edu_wpi_first_datalog_DataLogJNI_flush } /* - * Class: edu_wpi_first_util_datalog_DataLogJNI + * Class: edu_wpi_first_datalog_DataLogJNI * Method: copyWriteBuffer * Signature: (J[BI)I */ @@ -248,7 +247,7 @@ Java_edu_wpi_first_datalog_DataLogJNI_copyWriteBuffer } /* - * Class: edu_wpi_first_util_datalog_DataLogJNI + * Class: edu_wpi_first_datalog_DataLogJNI * Method: pause * Signature: (J)V */ @@ -264,7 +263,7 @@ Java_edu_wpi_first_datalog_DataLogJNI_pause } /* - * Class: edu_wpi_first_util_datalog_DataLogJNI + * Class: edu_wpi_first_datalog_DataLogJNI * Method: resume * Signature: (J)V */ @@ -280,7 +279,7 @@ Java_edu_wpi_first_datalog_DataLogJNI_resume } /* - * Class: edu_wpi_first_util_datalog_DataLogJNI + * Class: edu_wpi_first_datalog_DataLogJNI * Method: stop * Signature: (J)V */ @@ -296,7 +295,7 @@ Java_edu_wpi_first_datalog_DataLogJNI_stop } /* - * Class: edu_wpi_first_util_datalog_DataLogJNI + * Class: edu_wpi_first_datalog_DataLogJNI * Method: addSchema * Signature: (JLjava/lang/String;Ljava/lang/String;[BJ)V */ @@ -315,7 +314,7 @@ Java_edu_wpi_first_datalog_DataLogJNI_addSchema } /* - * Class: edu_wpi_first_util_datalog_DataLogJNI + * Class: edu_wpi_first_datalog_DataLogJNI * Method: addSchemaString * Signature: (JLjava/lang/String;Ljava/lang/String;Ljava/lang/String;J)V */ @@ -337,7 +336,7 @@ Java_edu_wpi_first_datalog_DataLogJNI_addSchemaString } /* - * Class: edu_wpi_first_util_datalog_DataLogJNI + * Class: edu_wpi_first_datalog_DataLogJNI * Method: start * Signature: (JLjava/lang/String;Ljava/lang/String;Ljava/lang/String;J)I */ @@ -356,7 +355,7 @@ Java_edu_wpi_first_datalog_DataLogJNI_start } /* - * Class: edu_wpi_first_util_datalog_DataLogJNI + * Class: edu_wpi_first_datalog_DataLogJNI * Method: finish * Signature: (JIJ)V */ @@ -372,7 +371,7 @@ Java_edu_wpi_first_datalog_DataLogJNI_finish } /* - * Class: edu_wpi_first_util_datalog_DataLogJNI + * Class: edu_wpi_first_datalog_DataLogJNI * Method: setMetadata * Signature: (JILjava/lang/String;J)V */ @@ -390,7 +389,7 @@ Java_edu_wpi_first_datalog_DataLogJNI_setMetadata } /* - * Class: edu_wpi_first_util_datalog_DataLogJNI + * Class: edu_wpi_first_datalog_DataLogJNI * Method: close * Signature: (J)V */ @@ -402,7 +401,7 @@ Java_edu_wpi_first_datalog_DataLogJNI_close } /* - * Class: edu_wpi_first_util_datalog_DataLogJNI + * Class: edu_wpi_first_datalog_DataLogJNI * Method: appendRaw * Signature: (JI[BIIJ)V */ @@ -438,7 +437,7 @@ Java_edu_wpi_first_datalog_DataLogJNI_appendRaw } /* - * Class: edu_wpi_first_util_datalog_DataLogJNI + * Class: edu_wpi_first_datalog_DataLogJNI * Method: appendRawBuffer * Signature: (JILjava/lang/Object;IIJ)V */ @@ -474,7 +473,7 @@ Java_edu_wpi_first_datalog_DataLogJNI_appendRawBuffer } /* - * Class: edu_wpi_first_util_datalog_DataLogJNI + * Class: edu_wpi_first_datalog_DataLogJNI * Method: appendBoolean * Signature: (JIZJ)V */ @@ -490,7 +489,7 @@ Java_edu_wpi_first_datalog_DataLogJNI_appendBoolean } /* - * Class: edu_wpi_first_util_datalog_DataLogJNI + * Class: edu_wpi_first_datalog_DataLogJNI * Method: appendInteger * Signature: (JIJJ)V */ @@ -506,7 +505,7 @@ Java_edu_wpi_first_datalog_DataLogJNI_appendInteger } /* - * Class: edu_wpi_first_util_datalog_DataLogJNI + * Class: edu_wpi_first_datalog_DataLogJNI * Method: appendFloat * Signature: (JIFJ)V */ @@ -522,7 +521,7 @@ Java_edu_wpi_first_datalog_DataLogJNI_appendFloat } /* - * Class: edu_wpi_first_util_datalog_DataLogJNI + * Class: edu_wpi_first_datalog_DataLogJNI * Method: appendDouble * Signature: (JIDJ)V */ @@ -538,7 +537,7 @@ Java_edu_wpi_first_datalog_DataLogJNI_appendDouble } /* - * Class: edu_wpi_first_util_datalog_DataLogJNI + * Class: edu_wpi_first_datalog_DataLogJNI * Method: appendString * Signature: (JILjava/lang/String;J)V */ @@ -555,7 +554,7 @@ Java_edu_wpi_first_datalog_DataLogJNI_appendString } /* - * Class: edu_wpi_first_util_datalog_DataLogJNI + * Class: edu_wpi_first_datalog_DataLogJNI * Method: appendBooleanArray * Signature: (JI[ZJ)V */ @@ -577,7 +576,7 @@ Java_edu_wpi_first_datalog_DataLogJNI_appendBooleanArray } /* - * Class: edu_wpi_first_util_datalog_DataLogJNI + * Class: edu_wpi_first_datalog_DataLogJNI * Method: appendIntegerArray * Signature: (JI[JJ)V */ @@ -610,7 +609,7 @@ Java_edu_wpi_first_datalog_DataLogJNI_appendIntegerArray } /* - * Class: edu_wpi_first_util_datalog_DataLogJNI + * Class: edu_wpi_first_datalog_DataLogJNI * Method: appendFloatArray * Signature: (JI[FJ)V */ @@ -632,7 +631,7 @@ Java_edu_wpi_first_datalog_DataLogJNI_appendFloatArray } /* - * Class: edu_wpi_first_util_datalog_DataLogJNI + * Class: edu_wpi_first_datalog_DataLogJNI * Method: appendDoubleArray * Signature: (JI[DJ)V */ @@ -654,7 +653,7 @@ Java_edu_wpi_first_datalog_DataLogJNI_appendDoubleArray } /* - * Class: edu_wpi_first_util_datalog_DataLogJNI + * Class: edu_wpi_first_datalog_DataLogJNI * Method: appendStringArray * Signature: (JI[Ljava/lang/Object;J)V */ diff --git a/libdatalog/src/main/native/cpp/jni/DataLogJNI.h b/libdatalog/src/main/native/cpp/jni/DataLogJNI.h index b0561b91be8..4d08fdbf8bf 100644 --- a/libdatalog/src/main/native/cpp/jni/DataLogJNI.h +++ b/libdatalog/src/main/native/cpp/jni/DataLogJNI.h @@ -1,6 +1,11 @@ +// Copyright (c) FIRST and other WPILib contributors. +// Open Source Software; you can modify and/or share it under the terms of +// the WPILib BSD license file in the root directory of this project. + #pragma once #include + #include namespace wpi { @@ -10,4 +15,4 @@ void ThrowIndexOobException(JNIEnv* env, std::string_view msg); void ThrowIOException(JNIEnv* env, std::string_view msg); void ThrowNullPointerException(JNIEnv* env, std::string_view msg); -} // namespace wpi \ No newline at end of file +} // namespace wpi diff --git a/libdatalog/src/main/native/include/wpi/DataLog.h b/libdatalog/src/main/native/include/wpi/DataLog.h index 50c3aed8f13..2b42ad627eb 100644 --- a/libdatalog/src/main/native/include/wpi/DataLog.h +++ b/libdatalog/src/main/native/include/wpi/DataLog.h @@ -19,15 +19,15 @@ #include #include -#include "wpi/DataLog_c.h" -#include "wpi/DenseMap.h" -#include "wpi/SmallVector.h" -#include "wpi/StringMap.h" -#include "wpi/mutex.h" -#include "wpi/protobuf/Protobuf.h" -#include "wpi/string.h" -#include "wpi/struct/Struct.h" -#include "wpi/timestamp.h" +#include +#include +#include +#include +#include +#include +#include +#include +#include namespace wpi { class Logger; diff --git a/libdatalog/src/main/native/include/wpi/DataLogBackgroundWriter.h b/libdatalog/src/main/native/include/wpi/DataLogBackgroundWriter.h index 7926299ca13..ebf024e6659 100644 --- a/libdatalog/src/main/native/include/wpi/DataLogBackgroundWriter.h +++ b/libdatalog/src/main/native/include/wpi/DataLogBackgroundWriter.h @@ -12,9 +12,9 @@ #include #include -#include "wpi/DataLog.h" -#include "wpi/condition_variable.h" -#include "wpi/mutex.h" +#include +#include +#include namespace wpi { class Logger; diff --git a/libdatalog/src/main/native/include/wpi/DataLogReader.h b/libdatalog/src/main/native/include/wpi/DataLogReader.h index cb9a8cb8ffb..2a22725c7c4 100644 --- a/libdatalog/src/main/native/include/wpi/DataLogReader.h +++ b/libdatalog/src/main/native/include/wpi/DataLogReader.h @@ -12,7 +12,7 @@ #include #include -#include "wpi/MemoryBuffer.h" +#include namespace wpi::log { diff --git a/libdatalog/src/main/native/include/wpi/DataLogReaderThread.h b/libdatalog/src/main/native/include/wpi/DataLogReaderThread.h index aeb737ba24a..33fa8771966 100644 --- a/libdatalog/src/main/native/include/wpi/DataLogReaderThread.h +++ b/libdatalog/src/main/native/include/wpi/DataLogReaderThread.h @@ -4,12 +4,6 @@ #pragma once -#include -#include -#include -#include -#include - #include #include #include @@ -19,6 +13,12 @@ #include #include +#include +#include +#include +#include +#include + #ifndef NO_PROTOBUF #include #endif diff --git a/libdatalog/src/main/native/include/wpi/DataLogWriter.h b/libdatalog/src/main/native/include/wpi/DataLogWriter.h index f69c7b5b259..b9c7c9551e1 100644 --- a/libdatalog/src/main/native/include/wpi/DataLogWriter.h +++ b/libdatalog/src/main/native/include/wpi/DataLogWriter.h @@ -8,7 +8,7 @@ #include #include -#include "wpi/DataLog.h" +#include namespace wpi { class raw_ostream; diff --git a/libdatalog/src/main/native/include/wpi/DataLog_c.h b/libdatalog/src/main/native/include/wpi/DataLog_c.h index 654181a843a..21e66c6c43f 100644 --- a/libdatalog/src/main/native/include/wpi/DataLog_c.h +++ b/libdatalog/src/main/native/include/wpi/DataLog_c.h @@ -7,6 +7,7 @@ #include // NOLINT #include + #include #ifdef __cplusplus diff --git a/libdatalog/src/main/native/include/wpi/FileLogger.h b/libdatalog/src/main/native/include/wpi/FileLogger.h index c04cf5b7edc..4fe1c7f638d 100644 --- a/libdatalog/src/main/native/include/wpi/FileLogger.h +++ b/libdatalog/src/main/native/include/wpi/FileLogger.h @@ -8,7 +8,7 @@ #include #include -#include "wpi/DataLog.h" +#include namespace wpi { /** diff --git a/libdatalog/src/test/native/cpp/DataLogTest.cpp b/libdatalog/src/test/native/cpp/DataLogTest.cpp index 149d3a36b78..d8b71f4a7e7 100644 --- a/libdatalog/src/test/native/cpp/DataLogTest.cpp +++ b/libdatalog/src/test/native/cpp/DataLogTest.cpp @@ -8,10 +8,9 @@ #include #include - -#include "wpi/DataLogWriter.h" -#include "wpi/Logger.h" -#include "wpi/raw_ostream.h" +#include +#include +#include namespace { struct ThingA { diff --git a/libdatalog/src/test/native/cpp/FileLoggerTest.cpp b/libdatalog/src/test/native/cpp/FileLoggerTest.cpp index f402ef583dc..a60316ad805 100644 --- a/libdatalog/src/test/native/cpp/FileLoggerTest.cpp +++ b/libdatalog/src/test/native/cpp/FileLoggerTest.cpp @@ -7,8 +7,7 @@ #include #include - -#include "wpi/FileLogger.h" +#include TEST(FileLoggerTest, BufferSingleLine) { std::vector buf; From dd5359ee72020468fcf2b57657fb50f7ad4b335f Mon Sep 17 00:00:00 2001 From: DeltaDizzy Date: Sun, 26 Jan 2025 14:01:28 -0500 Subject: [PATCH 40/64] wpiutil format --- wpiutil/CMakeLists.txt | 7 ++----- 1 file changed, 2 insertions(+), 5 deletions(-) diff --git a/wpiutil/CMakeLists.txt b/wpiutil/CMakeLists.txt index 293425a4605..e0af46d8df3 100644 --- a/wpiutil/CMakeLists.txt +++ b/wpiutil/CMakeLists.txt @@ -6,10 +6,7 @@ include(CompileWarnings) include(AddTest) include(DownloadAndCheck) -file( - GLOB wpiutil_jni_src - src/main/native/cpp/jni/WPIUtilJNI.cpp -) +file(GLOB wpiutil_jni_src src/main/native/cpp/jni/WPIUtilJNI.cpp) # Java bindings if(WITH_JAVA) @@ -259,4 +256,4 @@ if(WITH_TESTS) if(MSVC) target_compile_options(wpiutil_test PRIVATE /utf-8) endif() -endif() \ No newline at end of file +endif() From 314f0bfcfead23ce95c99f2904f15aaaa0005fdf Mon Sep 17 00:00:00 2001 From: DeltaDizzy Date: Sun, 26 Jan 2025 14:06:43 -0500 Subject: [PATCH 41/64] make wpiutil link last --- glass/build.gradle | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/glass/build.gradle b/glass/build.gradle index 354036dec75..4ef5686b495 100644 --- a/glass/build.gradle +++ b/glass/build.gradle @@ -93,11 +93,12 @@ model { it.buildable = false return } - lib project: ':wpiutil', library: 'wpiutil', linkage: 'shared' + lib project: ':wpimath', library: 'wpimath', linkage: 'shared' lib project: ':wpigui', library: 'wpigui', linkage: 'static' lib project: ':fieldImages', library: 'fieldImages', linkage: 'shared' lib project: ':thirdparty:imgui_suite', library: 'imguiSuite', linkage: 'static' + lib project: ':wpiutil', library: 'wpiutil', linkage: 'shared' } appendDebugPathToBinaries(binaries) } @@ -123,11 +124,11 @@ model { lib library: nativeName, linkage: 'static' project(':ntcore').addNtcoreDependency(it, 'shared') lib project: ':wpinet', library: 'wpinet', linkage: 'shared' - lib project: ':wpiutil', library: 'wpiutil', linkage: 'shared' lib project: ':wpimath', library: 'wpimath', linkage: 'shared' lib project: ':wpigui', library: 'wpigui', linkage: 'static' lib project: ':fieldImages', library: 'fieldImages', linkage: 'shared' lib project: ':thirdparty:imgui_suite', library: 'imguiSuite', linkage: 'static' + lib project: ':wpiutil', library: 'wpiutil', linkage: 'shared' } appendDebugPathToBinaries(binaries) } @@ -162,12 +163,12 @@ model { lib library: nativeName, linkage: 'static' project(':ntcore').addNtcoreDependency(it, 'static') lib project: ':wpinet', library: 'wpinet', linkage: 'static' - lib project: ':wpiutil', library: 'wpiutil', linkage: 'static' lib project: ':wpimath', library: 'wpimath', linkage: 'static' lib project: ':wpigui', library: 'wpigui', linkage: 'static' lib project: ':fieldImages', library: 'fieldImages', linkage: 'static' nativeUtils.useRequiredLibrary(it, 'opencv_static') lib project: ':thirdparty:imgui_suite', library: 'imguiSuite', linkage: 'static' + lib project: ':wpiutil', library: 'wpiutil', linkage: 'static' if (it.targetPlatform.operatingSystem.isWindows()) { it.linker.args << 'Gdi32.lib' << 'Shell32.lib' << 'd3d11.lib' << 'd3dcompiler.lib' it.linker.args << '/DELAYLOAD:MF.dll' << '/DELAYLOAD:MFReadWrite.dll' << '/DELAYLOAD:MFPlat.dll' << '/delay:nobind' From ba4ad6e9a980ec9912c7d79d805dce7ede54c974 Mon Sep 17 00:00:00 2001 From: DeltaDizzy Date: Sun, 26 Jan 2025 14:24:25 -0500 Subject: [PATCH 42/64] reorder dlt deps --- datalogtool/build.gradle | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/datalogtool/build.gradle b/datalogtool/build.gradle index 34092745c83..3117cc05f6e 100644 --- a/datalogtool/build.gradle +++ b/datalogtool/build.gradle @@ -99,10 +99,10 @@ model { } it.cppCompiler.define("LIBSSH_STATIC") lib project: ':glass', library: 'glass', linkage: 'static' - lib project: ':wpiutil', library: 'wpiutil', linkage: 'static' lib project: ':wpigui', library: 'wpigui', linkage: 'static' lib project: ':libdatalog', library: 'libdatalog', linkage: 'static' lib project: ':thirdparty:imgui_suite', library: 'imguiSuite', linkage: 'static' + lib project: ':wpiutil', library: 'wpiutil', linkage: 'static' nativeUtils.useRequiredLibrary(it, 'libssh') if (it.targetPlatform.operatingSystem.isWindows()) { it.linker.args << 'Gdi32.lib' << 'Shell32.lib' << 'd3d11.lib' << 'd3dcompiler.lib' From c544b006f72499d3274005bb64f83921ddf1b507 Mon Sep 17 00:00:00 2001 From: DeltaDizzy Date: Sun, 26 Jan 2025 14:45:16 -0500 Subject: [PATCH 43/64] sysid deps --- sysid/build.gradle | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/sysid/build.gradle b/sysid/build.gradle index 22136ad23f9..253cf51376c 100644 --- a/sysid/build.gradle +++ b/sysid/build.gradle @@ -98,10 +98,10 @@ model { } lib project: ':glass', library: 'glass', linkage: 'static' lib project: ':wpimath', library: 'wpimath', linkage: 'static' - lib project: ':wpiutil', library: 'wpiutil', linkage: 'static' lib project: ':wpigui', library: 'wpigui', linkage: 'static' lib project: ':libdatalog', library: 'libdatalog', linkage: 'static' lib project: ':thirdparty:imgui_suite', library: 'imguiSuite', linkage: 'static' + lib project: ':wpiutil', library: 'wpiutil', linkage: 'static' if (it.targetPlatform.operatingSystem.isWindows()) { it.linker.args << 'Gdi32.lib' << 'Shell32.lib' << 'd3d11.lib' << 'd3dcompiler.lib' it.linker.args << '/DELAYLOAD:MF.dll' << '/DELAYLOAD:MFReadWrite.dll' << '/DELAYLOAD:MFPlat.dll' << '/delay:nobind' From c3ad8ce3ebc607691ac34d8156a8e7bc0cf60a9f Mon Sep 17 00:00:00 2001 From: DeltaDizzy Date: Sun, 26 Jan 2025 15:06:20 -0500 Subject: [PATCH 44/64] move filelogger from wpiutil to datalog (java) --- .../edu/wpi/first/datalog/DataLogJNI.java | 23 ++++++++++++++++--- .../main/java/NetworkTableInstance.java.jinja | 2 +- .../networktables/NetworkTableInstance.java | 2 +- .../java/edu/wpi/first/util/WPIUtilJNI.java | 18 --------------- 4 files changed, 22 insertions(+), 23 deletions(-) diff --git a/libdatalog/src/main/java/edu/wpi/first/datalog/DataLogJNI.java b/libdatalog/src/main/java/edu/wpi/first/datalog/DataLogJNI.java index c1500f8826d..dee8f3c4c8d 100644 --- a/libdatalog/src/main/java/edu/wpi/first/datalog/DataLogJNI.java +++ b/libdatalog/src/main/java/edu/wpi/first/datalog/DataLogJNI.java @@ -4,13 +4,12 @@ package edu.wpi.first.datalog; +import edu.wpi.first.util.RuntimeLoader; +import edu.wpi.first.util.WPIUtilJNI; import java.io.IOException; import java.nio.ByteBuffer; import java.util.concurrent.atomic.AtomicBoolean; -import edu.wpi.first.util.RuntimeLoader; -import edu.wpi.first.util.WPIUtilJNI; - /** * DataLog wpiutil JNI Functions. * @@ -354,6 +353,24 @@ private static native void appendRawBuffer( */ static native void appendStringArray(long impl, int entry, String[] value, long timestamp); + /** + * Create a native FileLogger. When the specified file is modified, appended data will be appended + * to the specified data log. + * + * @param file path to the file + * @param log data log implementation handle + * @param key log key to append data to + * @return The FileLogger handle. + */ + public static native long createFileLogger(String file, long log, String key); + + /** + * Free a native FileLogger. This causes the FileLogger to stop appending data to the log. + * + * @param fileTail The FileLogger handle. + */ + public static native void freeFileLogger(long fileTail); + /** Utility class. */ private DataLogJNI() {} } diff --git a/ntcore/src/generate/main/java/NetworkTableInstance.java.jinja b/ntcore/src/generate/main/java/NetworkTableInstance.java.jinja index a91ffed4ebf..28f8687cb95 100644 --- a/ntcore/src/generate/main/java/NetworkTableInstance.java.jinja +++ b/ntcore/src/generate/main/java/NetworkTableInstance.java.jinja @@ -6,8 +6,8 @@ package edu.wpi.first.networktables; -import edu.wpi.first.util.WPIUtilJNI; import edu.wpi.first.datalog.DataLog; +import edu.wpi.first.util.WPIUtilJNI; import edu.wpi.first.util.concurrent.Event; import edu.wpi.first.util.protobuf.Protobuf; import edu.wpi.first.util.struct.Struct; diff --git a/ntcore/src/generated/main/java/edu/wpi/first/networktables/NetworkTableInstance.java b/ntcore/src/generated/main/java/edu/wpi/first/networktables/NetworkTableInstance.java index d157c27d149..8f31e5d993e 100644 --- a/ntcore/src/generated/main/java/edu/wpi/first/networktables/NetworkTableInstance.java +++ b/ntcore/src/generated/main/java/edu/wpi/first/networktables/NetworkTableInstance.java @@ -6,8 +6,8 @@ package edu.wpi.first.networktables; -import edu.wpi.first.util.WPIUtilJNI; import edu.wpi.first.datalog.DataLog; +import edu.wpi.first.util.WPIUtilJNI; import edu.wpi.first.util.concurrent.Event; import edu.wpi.first.util.protobuf.Protobuf; import edu.wpi.first.util.struct.Struct; diff --git a/wpiutil/src/main/java/edu/wpi/first/util/WPIUtilJNI.java b/wpiutil/src/main/java/edu/wpi/first/util/WPIUtilJNI.java index 2818489c59d..acd93408e64 100644 --- a/wpiutil/src/main/java/edu/wpi/first/util/WPIUtilJNI.java +++ b/wpiutil/src/main/java/edu/wpi/first/util/WPIUtilJNI.java @@ -222,24 +222,6 @@ public static native boolean waitForObjectTimeout(int handle, double timeout) public static native int[] waitForObjectsTimeout(int[] handles, double timeout) throws InterruptedException; - /** - * Create a native FileLogger. When the specified file is modified, appended data will be appended - * to the specified data log. - * - * @param file path to the file - * @param log data log implementation handle - * @param key log key to append data to - * @return The FileLogger handle. - */ - public static native long createFileLogger(String file, long log, String key); - - /** - * Free a native FileLogger. This causes the FileLogger to stop appending data to the log. - * - * @param fileTail The FileLogger handle. - */ - public static native void freeFileLogger(long fileTail); - /** Utility class. */ protected WPIUtilJNI() {} } From 6bb30372be7f316fbee97539ec5e83a64819e93a Mon Sep 17 00:00:00 2001 From: DeltaDizzy Date: Sun, 26 Jan 2025 16:15:13 -0500 Subject: [PATCH 45/64] fix jni names --- libdatalog/src/main/native/cpp/jni/DataLogJNI.cpp | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/libdatalog/src/main/native/cpp/jni/DataLogJNI.cpp b/libdatalog/src/main/native/cpp/jni/DataLogJNI.cpp index f924c83f03b..e50258e1543 100644 --- a/libdatalog/src/main/native/cpp/jni/DataLogJNI.cpp +++ b/libdatalog/src/main/native/cpp/jni/DataLogJNI.cpp @@ -686,12 +686,12 @@ Java_edu_wpi_first_datalog_DataLogJNI_appendStringArray reinterpret_cast(impl)->AppendStringArray(entry, arr, timestamp); } /* - * Class: edu_wpi_first_util_WPIUtilJNI + * Class: edu_wpi_first_datalog_DataLogJNI * Method: createFileLogger * Signature: (Ljava/lang/String;JLjava/lang/String;)J */ JNIEXPORT jlong JNICALL -Java_edu_wpi_first_util_WPIUtilJNI_createFileLogger +Java_edu_wpi_first_datalog_DataLogJNI_createFileLogger (JNIEnv* env, jclass, jstring file, jlong log, jstring key) { if (!file) { @@ -712,12 +712,12 @@ Java_edu_wpi_first_util_WPIUtilJNI_createFileLogger } /* - * Class: edu_wpi_first_util_WPIUtilJNI + * Class: edu_wpi_first_datalog_DataLogJNI * Method: freeFileLogger * Signature: (J)V */ JNIEXPORT void JNICALL -Java_edu_wpi_first_util_WPIUtilJNI_freeFileLogger +Java_edu_wpi_first_datalog_DataLogJNI_freeFileLogger (JNIEnv* env, jclass, jlong fileTail) { delete reinterpret_cast(fileTail); From d9373c058fd40c93ff1b8f50c5a9ffe8ce7140e6 Mon Sep 17 00:00:00 2001 From: DeltaDizzy Date: Sun, 26 Jan 2025 18:21:24 -0500 Subject: [PATCH 46/64] Update libdatalog/BUILD.bazel Co-authored-by: Gold856 <117957790+Gold856@users.noreply.github.com> --- libdatalog/BUILD.bazel | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/libdatalog/BUILD.bazel b/libdatalog/BUILD.bazel index b9f57737ed1..8a207af257c 100644 --- a/libdatalog/BUILD.bazel +++ b/libdatalog/BUILD.bazel @@ -4,8 +4,9 @@ cc_library( name = "libdatalog.static", srcs = glob( ["src/main/native/cpp/**"], + exclude = ["src/main/native/cpp/jni/**"], ), - hdrs = glob(["src/main/native/include/*"]), + hdrs = glob(["src/main/native/include/**"]), includes = [ "src/main/native/cpp", "src/main/native/include", From 98b033210818d131d66a12e0154c65d9fcd17184 Mon Sep 17 00:00:00 2001 From: DeltaDizzy Date: Sun, 26 Jan 2025 18:49:08 -0500 Subject: [PATCH 47/64] dont extend wpiutiljni --- libdatalog/src/main/java/edu/wpi/first/datalog/DataLog.java | 5 +++-- .../src/main/java/edu/wpi/first/datalog/DataLogJNI.java | 5 ++--- 2 files changed, 5 insertions(+), 5 deletions(-) diff --git a/libdatalog/src/main/java/edu/wpi/first/datalog/DataLog.java b/libdatalog/src/main/java/edu/wpi/first/datalog/DataLog.java index 2d5e1908806..fed02a0a49d 100644 --- a/libdatalog/src/main/java/edu/wpi/first/datalog/DataLog.java +++ b/libdatalog/src/main/java/edu/wpi/first/datalog/DataLog.java @@ -4,6 +4,7 @@ package edu.wpi.first.datalog; +import edu.wpi.first.util.WPIUtilJNI; import edu.wpi.first.util.protobuf.Protobuf; import edu.wpi.first.util.struct.Struct; import java.nio.ByteBuffer; @@ -145,7 +146,7 @@ public void addSchema(String name, String type, String schema) { * @param timestamp Time stamp (0 to indicate now) */ public void addSchema(Protobuf proto, long timestamp) { - final long actualTimestamp = timestamp == 0 ? DataLogJNI.now() : timestamp; + final long actualTimestamp = timestamp == 0 ? WPIUtilJNI.now() : timestamp; proto.forEachDescriptor( this::hasSchema, (typeString, schema) -> @@ -170,7 +171,7 @@ public void addSchema(Protobuf proto) { * @param timestamp Time stamp (0 to indicate now) */ public void addSchema(Struct struct, long timestamp) { - addSchemaImpl(struct, timestamp == 0 ? DataLogJNI.now() : timestamp, new HashSet<>()); + addSchemaImpl(struct, timestamp == 0 ? WPIUtilJNI.now() : timestamp, new HashSet<>()); } /** diff --git a/libdatalog/src/main/java/edu/wpi/first/datalog/DataLogJNI.java b/libdatalog/src/main/java/edu/wpi/first/datalog/DataLogJNI.java index dee8f3c4c8d..458ab888372 100644 --- a/libdatalog/src/main/java/edu/wpi/first/datalog/DataLogJNI.java +++ b/libdatalog/src/main/java/edu/wpi/first/datalog/DataLogJNI.java @@ -5,17 +5,16 @@ package edu.wpi.first.datalog; import edu.wpi.first.util.RuntimeLoader; -import edu.wpi.first.util.WPIUtilJNI; import java.io.IOException; import java.nio.ByteBuffer; import java.util.concurrent.atomic.AtomicBoolean; /** - * DataLog wpiutil JNI Functions. + * DataLog JNI Functions. * * @see "libdatalog/DataLog.h" */ -public class DataLogJNI extends WPIUtilJNI { +public class DataLogJNI { static boolean libraryLoaded = false; /** Sets whether JNI should be loaded in the static block. */ From a079ab2fc6347cae7bcedc360e95c09d613236c0 Mon Sep 17 00:00:00 2001 From: DeltaDizzy Date: Sun, 26 Jan 2025 18:56:59 -0500 Subject: [PATCH 48/64] gradle tests fix --- libdatalog/build.gradle | 2 +- .../src/dev/java/edu/wpi/first/datalog/DevMain.java | 12 ++++++++++++ libdatalog/src/dev/native/cpp/main.cpp | 5 +++++ .../main/java/edu/wpi/first/datalog/DataLogJNI.java | 2 +- 4 files changed, 19 insertions(+), 2 deletions(-) create mode 100644 libdatalog/src/dev/java/edu/wpi/first/datalog/DevMain.java create mode 100644 libdatalog/src/dev/native/cpp/main.cpp diff --git a/libdatalog/build.gradle b/libdatalog/build.gradle index 0ff9c066ea2..c52bae7b95f 100644 --- a/libdatalog/build.gradle +++ b/libdatalog/build.gradle @@ -5,7 +5,7 @@ ext { groupId = 'edu.wpi.first.datalog' nativeName = 'libdatalog' - devMain = 'edu.wpi.first.math.DevMain' + devMain = 'edu.wpi.first.datalog.DevMain' } apply from: "${rootDir}/shared/jni/setupBuild.gradle" diff --git a/libdatalog/src/dev/java/edu/wpi/first/datalog/DevMain.java b/libdatalog/src/dev/java/edu/wpi/first/datalog/DevMain.java new file mode 100644 index 00000000000..2c424d6c84e --- /dev/null +++ b/libdatalog/src/dev/java/edu/wpi/first/datalog/DevMain.java @@ -0,0 +1,12 @@ +// Copyright (c) FIRST and other WPILib contributors. +// Open Source Software; you can modify and/or share it under the terms of +// the WPILib BSD license file in the root directory of this project. + +package edu.wpi.first.datalog; + +public final class DevMain { + /** Main entry point. */ + public static void main(String[] args) {} + + private DevMain() {} +} diff --git a/libdatalog/src/dev/native/cpp/main.cpp b/libdatalog/src/dev/native/cpp/main.cpp new file mode 100644 index 00000000000..a3e363efca0 --- /dev/null +++ b/libdatalog/src/dev/native/cpp/main.cpp @@ -0,0 +1,5 @@ +// Copyright (c) FIRST and other WPILib contributors. +// Open Source Software; you can modify and/or share it under the terms of +// the WPILib BSD license file in the root directory of this project. + +int main() {} diff --git a/libdatalog/src/main/java/edu/wpi/first/datalog/DataLogJNI.java b/libdatalog/src/main/java/edu/wpi/first/datalog/DataLogJNI.java index 458ab888372..b9a150d36b9 100644 --- a/libdatalog/src/main/java/edu/wpi/first/datalog/DataLogJNI.java +++ b/libdatalog/src/main/java/edu/wpi/first/datalog/DataLogJNI.java @@ -46,7 +46,7 @@ private Helper() {} static { if (Helper.getExtractOnStaticLoad()) { try { - RuntimeLoader.loadLibrary("datalogjni"); + RuntimeLoader.loadLibrary("libdatalogjni"); } catch (Exception ex) { ex.printStackTrace(); System.exit(1); From 43631bbcf0310347f3892dafd7dee22e5a9d94f4 Mon Sep 17 00:00:00 2001 From: DeltaDizzy Date: Sun, 26 Jan 2025 20:03:30 -0500 Subject: [PATCH 49/64] add datalog to sysid tests --- sysid/build.gradle | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/sysid/build.gradle b/sysid/build.gradle index 253cf51376c..72406b5e245 100644 --- a/sysid/build.gradle +++ b/sysid/build.gradle @@ -138,9 +138,10 @@ model { } lib project: ':glass', library: 'glass', linkage: 'static' lib project: ':wpimath', library: 'wpimath', linkage: 'static' - lib project: ':wpiutil', library: 'wpiutil', linkage: 'static' + lib project: ':libdatalog', library: 'libdatalog', linkage: 'static' lib project: ':wpigui', library: 'wpigui', linkage: 'static' lib project: ':thirdparty:imgui_suite', library: 'imguiSuite', linkage: 'static' + lib project: ':wpiutil', library: 'wpiutil', linkage: 'static' if (it.targetPlatform.operatingSystem.isWindows()) { it.linker.args << 'Gdi32.lib' << 'Shell32.lib' << 'd3d11.lib' << 'd3dcompiler.lib' it.linker.args << '/DELAYLOAD:MF.dll' << '/DELAYLOAD:MFReadWrite.dll' << '/DELAYLOAD:MFPlat.dll' << '/delay:nobind' From cf1348202592d51211b7def5bd29f797b53a1b60 Mon Sep 17 00:00:00 2001 From: DeltaDizzy Date: Sun, 26 Jan 2025 21:02:29 -0500 Subject: [PATCH 50/64] fix bazel build for libdatalog, epilogue, ntcore, wpiutil --- epilogue-runtime/BUILD.bazel | 1 + libdatalog/BUILD.bazel | 43 ++++++++++++++++++++++++++++++++++++ ntcore/BUILD.bazel | 2 ++ wpiutil/BUILD.bazel | 31 -------------------------- 4 files changed, 46 insertions(+), 31 deletions(-) diff --git a/epilogue-runtime/BUILD.bazel b/epilogue-runtime/BUILD.bazel index 6e02a5dfcb8..da2778a8196 100644 --- a/epilogue-runtime/BUILD.bazel +++ b/epilogue-runtime/BUILD.bazel @@ -9,6 +9,7 @@ java_library( "//ntcore:networktables-java", "//wpiunits", "//wpiutil:wpiutil-java", + "//libdatalog:datalog-java" ], ) diff --git a/libdatalog/BUILD.bazel b/libdatalog/BUILD.bazel index 8a207af257c..6de1e0a5a9f 100644 --- a/libdatalog/BUILD.bazel +++ b/libdatalog/BUILD.bazel @@ -17,3 +17,46 @@ cc_library( "//wpiutil:wpiutil.static", ], ) + +java_library( + name = "datalog-java", + srcs = glob(["src/main/java/**/*.java"]), + visibility = ["//visibility:public"], + deps = [ + "//wpiutil:wpiutil-java", + "@maven//:us_hebi_quickbuf_quickbuf_runtime", + ], +) + +py_binary( + name = "datalog", + srcs = ["examples/printlog/datalog.py"], + tags = ["manual"], +) + +cc_binary( + name = "printlog", + srcs = ["examples/printlog/printlog.cpp"], + deps = [ + "//wpiutil:wpiutil.static", + ":libdatalog.static" + ], +) + +cc_binary( + name = "writelog", + srcs = ["examples/writelog/writelog.cpp"], + deps = [ + "//wpiutil:wpiutil.static", + ":libdatalog.static" + ], +) + +java_binary( + name = "printlog-java", + srcs = ["src/printlog/java/printlog/PrintLog.java"], + main_class = "printlog.PrintLog", + deps = [ + ":datalog-java" + ], +) diff --git a/ntcore/BUILD.bazel b/ntcore/BUILD.bazel index 9b020297c59..d289bfc4c23 100644 --- a/ntcore/BUILD.bazel +++ b/ntcore/BUILD.bazel @@ -49,6 +49,7 @@ cc_library( ":generated_cc_headers", "//wpinet:wpinet.static", "//wpiutil:wpiutil.static", + "//libdatalog:libdatalog.static", ], ) @@ -69,6 +70,7 @@ wpilib_jni_java_library( visibility = ["//visibility:public"], deps = [ "//wpiutil:wpiutil-java", + "//libdatalog:datalog-java", "@maven//:us_hebi_quickbuf_quickbuf_runtime", ], ) diff --git a/wpiutil/BUILD.bazel b/wpiutil/BUILD.bazel index 646858441c5..ca2ee2b0f05 100644 --- a/wpiutil/BUILD.bazel +++ b/wpiutil/BUILD.bazel @@ -305,34 +305,3 @@ java_binary( ":wpiutil-java", ], ) - -py_binary( - name = "datalog", - srcs = ["examples/printlog/datalog.py"], - tags = ["manual"], -) - -cc_binary( - name = "printlog", - srcs = ["examples/printlog/printlog.cpp"], - deps = [ - ":wpiutil.static", - ], -) - -cc_binary( - name = "writelog", - srcs = ["examples/writelog/writelog.cpp"], - deps = [ - ":wpiutil.static", - ], -) - -java_binary( - name = "printlog-java", - srcs = ["src/printlog/java/printlog/PrintLog.java"], - main_class = "printlog.PrintLog", - deps = [ - ":wpiutil-java", - ], -) From dd0d9737073e16489a17b8f3ad3d6e9b3e9750d1 Mon Sep 17 00:00:00 2001 From: DeltaDizzy Date: Sun, 26 Jan 2025 21:11:18 -0500 Subject: [PATCH 51/64] rename to datalog --- CMakeLists.txt | 2 +- {libdatalog => datalog}/BUILD.bazel | 6 +- datalog/CMakeLists.txt | 112 ++++++++++++++++++ {libdatalog => datalog}/build.gradle | 6 +- .../datalog-config.cmake.in | 0 .../examples/printlog/datalog.py | 0 .../examples/printlog/printlog.cpp | 0 .../examples/writelog/writelog.cpp | 0 .../java/edu/wpi/first/datalog/DevMain.java | 0 .../src/dev/native/cpp/main.cpp | 0 .../first/datalog/BooleanArrayLogEntry.java | 0 .../wpi/first/datalog/BooleanLogEntry.java | 0 .../java/edu/wpi/first/datalog/DataLog.java | 0 .../datalog/DataLogBackgroundWriter.java | 0 .../edu/wpi/first/datalog/DataLogEntry.java | 0 .../wpi/first/datalog/DataLogIterator.java | 0 .../edu/wpi/first/datalog/DataLogJNI.java | 4 +- .../edu/wpi/first/datalog/DataLogReader.java | 0 .../edu/wpi/first/datalog/DataLogRecord.java | 0 .../edu/wpi/first/datalog/DataLogWriter.java | 0 .../first/datalog/DoubleArrayLogEntry.java | 0 .../edu/wpi/first/datalog/DoubleLogEntry.java | 0 .../edu/wpi/first/datalog/FileLogger.java | 0 .../wpi/first/datalog/FloatArrayLogEntry.java | 0 .../edu/wpi/first/datalog/FloatLogEntry.java | 0 .../first/datalog/IntegerArrayLogEntry.java | 0 .../wpi/first/datalog/IntegerLogEntry.java | 0 .../wpi/first/datalog/ProtobufLogEntry.java | 0 .../edu/wpi/first/datalog/RawLogEntry.java | 0 .../first/datalog/StringArrayLogEntry.java | 0 .../edu/wpi/first/datalog/StringLogEntry.java | 0 .../first/datalog/StructArrayLogEntry.java | 0 .../edu/wpi/first/datalog/StructLogEntry.java | 0 .../src/main/native/cpp/DataLog.cpp | 0 .../native/cpp/DataLogBackgroundWriter.cpp | 0 .../src/main/native/cpp/DataLogReader.cpp | 0 .../main/native/cpp/DataLogReaderThread.cpp | 0 .../src/main/native/cpp/DataLogWriter.cpp | 0 .../src/main/native/cpp/FileLogger.cpp | 0 .../src/main/native/cpp/jni/DataLogJNI.cpp | 0 .../src/main/native/cpp/jni/DataLogJNI.h | 0 .../src/main/native/include/wpi/DataLog.h | 0 .../include/wpi/DataLogBackgroundWriter.h | 0 .../main/native/include/wpi/DataLogReader.h | 0 .../native/include/wpi/DataLogReaderThread.h | 0 .../main/native/include/wpi/DataLogWriter.h | 0 .../src/main/native/include/wpi/DataLog_c.h | 0 .../src/main/native/include/wpi/FileLogger.h | 0 .../src/printlog/java/printlog/PrintLog.java | 0 .../edu/wpi/first/datalog/DataLogTest.java | 0 .../src/test/native/cpp/DataLogTest.cpp | 0 .../src/test/native/cpp/FileLoggerTest.cpp | 0 .../src/test/native/cpp/main.cpp | 0 datalogtool/CMakeLists.txt | 2 +- datalogtool/build.gradle | 2 +- epilogue-runtime/BUILD.bazel | 2 +- epilogue-runtime/build.gradle | 2 +- libdatalog/CMakeLists.txt | 112 ------------------ ntcore/BUILD.bazel | 4 +- ntcore/CMakeLists.txt | 4 +- ntcore/build.gradle | 10 +- settings.gradle | 2 +- sysid/CMakeLists.txt | 4 +- sysid/build.gradle | 4 +- wpilibNewCommands/CMakeLists.txt | 2 +- wpilibNewCommands/build.gradle | 2 +- wpilibc/CMakeLists.txt | 2 +- wpilibc/build.gradle | 2 +- wpilibj/CMakeLists.txt | 2 +- wpilibj/build.gradle | 2 +- 70 files changed, 145 insertions(+), 145 deletions(-) rename {libdatalog => datalog}/BUILD.bazel (93%) create mode 100644 datalog/CMakeLists.txt rename {libdatalog => datalog}/build.gradle (86%) rename libdatalog/libdatalog-config.cmake.in => datalog/datalog-config.cmake.in (100%) rename {libdatalog => datalog}/examples/printlog/datalog.py (100%) rename {libdatalog => datalog}/examples/printlog/printlog.cpp (100%) rename {libdatalog => datalog}/examples/writelog/writelog.cpp (100%) rename {libdatalog => datalog}/src/dev/java/edu/wpi/first/datalog/DevMain.java (100%) rename {libdatalog => datalog}/src/dev/native/cpp/main.cpp (100%) rename {libdatalog => datalog}/src/main/java/edu/wpi/first/datalog/BooleanArrayLogEntry.java (100%) rename {libdatalog => datalog}/src/main/java/edu/wpi/first/datalog/BooleanLogEntry.java (100%) rename {libdatalog => datalog}/src/main/java/edu/wpi/first/datalog/DataLog.java (100%) rename {libdatalog => datalog}/src/main/java/edu/wpi/first/datalog/DataLogBackgroundWriter.java (100%) rename {libdatalog => datalog}/src/main/java/edu/wpi/first/datalog/DataLogEntry.java (100%) rename {libdatalog => datalog}/src/main/java/edu/wpi/first/datalog/DataLogIterator.java (100%) rename {libdatalog => datalog}/src/main/java/edu/wpi/first/datalog/DataLogJNI.java (99%) rename {libdatalog => datalog}/src/main/java/edu/wpi/first/datalog/DataLogReader.java (100%) rename {libdatalog => datalog}/src/main/java/edu/wpi/first/datalog/DataLogRecord.java (100%) rename {libdatalog => datalog}/src/main/java/edu/wpi/first/datalog/DataLogWriter.java (100%) rename {libdatalog => datalog}/src/main/java/edu/wpi/first/datalog/DoubleArrayLogEntry.java (100%) rename {libdatalog => datalog}/src/main/java/edu/wpi/first/datalog/DoubleLogEntry.java (100%) rename {libdatalog => datalog}/src/main/java/edu/wpi/first/datalog/FileLogger.java (100%) rename {libdatalog => datalog}/src/main/java/edu/wpi/first/datalog/FloatArrayLogEntry.java (100%) rename {libdatalog => datalog}/src/main/java/edu/wpi/first/datalog/FloatLogEntry.java (100%) rename {libdatalog => datalog}/src/main/java/edu/wpi/first/datalog/IntegerArrayLogEntry.java (100%) rename {libdatalog => datalog}/src/main/java/edu/wpi/first/datalog/IntegerLogEntry.java (100%) rename {libdatalog => datalog}/src/main/java/edu/wpi/first/datalog/ProtobufLogEntry.java (100%) rename {libdatalog => datalog}/src/main/java/edu/wpi/first/datalog/RawLogEntry.java (100%) rename {libdatalog => datalog}/src/main/java/edu/wpi/first/datalog/StringArrayLogEntry.java (100%) rename {libdatalog => datalog}/src/main/java/edu/wpi/first/datalog/StringLogEntry.java (100%) rename {libdatalog => datalog}/src/main/java/edu/wpi/first/datalog/StructArrayLogEntry.java (100%) rename {libdatalog => datalog}/src/main/java/edu/wpi/first/datalog/StructLogEntry.java (100%) rename {libdatalog => datalog}/src/main/native/cpp/DataLog.cpp (100%) rename {libdatalog => datalog}/src/main/native/cpp/DataLogBackgroundWriter.cpp (100%) rename {libdatalog => datalog}/src/main/native/cpp/DataLogReader.cpp (100%) rename {libdatalog => datalog}/src/main/native/cpp/DataLogReaderThread.cpp (100%) rename {libdatalog => datalog}/src/main/native/cpp/DataLogWriter.cpp (100%) rename {libdatalog => datalog}/src/main/native/cpp/FileLogger.cpp (100%) rename {libdatalog => datalog}/src/main/native/cpp/jni/DataLogJNI.cpp (100%) rename {libdatalog => datalog}/src/main/native/cpp/jni/DataLogJNI.h (100%) rename {libdatalog => datalog}/src/main/native/include/wpi/DataLog.h (100%) rename {libdatalog => datalog}/src/main/native/include/wpi/DataLogBackgroundWriter.h (100%) rename {libdatalog => datalog}/src/main/native/include/wpi/DataLogReader.h (100%) rename {libdatalog => datalog}/src/main/native/include/wpi/DataLogReaderThread.h (100%) rename {libdatalog => datalog}/src/main/native/include/wpi/DataLogWriter.h (100%) rename {libdatalog => datalog}/src/main/native/include/wpi/DataLog_c.h (100%) rename {libdatalog => datalog}/src/main/native/include/wpi/FileLogger.h (100%) rename {libdatalog => datalog}/src/printlog/java/printlog/PrintLog.java (100%) rename {libdatalog => datalog}/src/test/java/edu/wpi/first/datalog/DataLogTest.java (100%) rename {libdatalog => datalog}/src/test/native/cpp/DataLogTest.cpp (100%) rename {libdatalog => datalog}/src/test/native/cpp/FileLoggerTest.cpp (100%) rename {libdatalog => datalog}/src/test/native/cpp/main.cpp (100%) delete mode 100644 libdatalog/CMakeLists.txt diff --git a/CMakeLists.txt b/CMakeLists.txt index 860167b2ed3..6b88f9e010a 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -291,7 +291,7 @@ set(WPIUNITS_DEP_REPLACE_IMPL "find_dependency(wpiunits)") set(WPIUTIL_DEP_REPLACE "find_dependency(wpiutil)") add_subdirectory(wpiutil) -add_subdirectory(libdatalog) +add_subdirectory(datalog) if(WITH_NTCORE) set(NTCORE_DEP_REPLACE "find_dependency(ntcore)") diff --git a/libdatalog/BUILD.bazel b/datalog/BUILD.bazel similarity index 93% rename from libdatalog/BUILD.bazel rename to datalog/BUILD.bazel index 6de1e0a5a9f..78e1b87a6ea 100644 --- a/libdatalog/BUILD.bazel +++ b/datalog/BUILD.bazel @@ -1,7 +1,7 @@ load("@rules_cc//cc:defs.bzl", "cc_library") cc_library( - name = "libdatalog.static", + name = "datalog.static", srcs = glob( ["src/main/native/cpp/**"], exclude = ["src/main/native/cpp/jni/**"], @@ -39,7 +39,7 @@ cc_binary( srcs = ["examples/printlog/printlog.cpp"], deps = [ "//wpiutil:wpiutil.static", - ":libdatalog.static" + ":datalog.static" ], ) @@ -48,7 +48,7 @@ cc_binary( srcs = ["examples/writelog/writelog.cpp"], deps = [ "//wpiutil:wpiutil.static", - ":libdatalog.static" + ":datalog.static" ], ) diff --git a/datalog/CMakeLists.txt b/datalog/CMakeLists.txt new file mode 100644 index 00000000000..91e5073bba4 --- /dev/null +++ b/datalog/CMakeLists.txt @@ -0,0 +1,112 @@ +project(datalog) + +include(CompileWarnings) + +file(GLOB datalog_native_src src/main/native/cpp/*.cpp) + +file(GLOB datalog_jni_src src/main/native/cpp/jni/DataLogJNI.cpp) +list(REMOVE_ITEM datalog_native_src ${datalog_jni_src}) + +add_library(datalog ${datalog_native_src}) +set_target_properties(datalog PROPERTIES DEBUG_POSTFIX "d") + +target_compile_features(datalog PUBLIC cxx_std_20) +if(MSVC) + target_compile_options( + datalog + PUBLIC /permissive- /Zc:preprocessor /Zc:__cplusplus /Zc:throwingNew /MP /bigobj /utf-8 + ) + target_compile_definitions(datalog PRIVATE -D_CRT_SECURE_NO_WARNINGS) +endif() +wpilib_target_warnings(datalog) + +target_include_directories( + datalog + PUBLIC $ +) + +target_link_libraries(datalog PRIVATE wpiutil) + +subdir_list(datalog_examples "${CMAKE_CURRENT_SOURCE_DIR}/examples") +foreach(example ${datalog_examples}) + file(GLOB datalog_example_src examples/${example}/*.cpp) + if(datalog_example_src) + add_executable(datalog_${example} ${datalog_example_src}) + wpilib_target_warnings(datalog_${example}) + target_link_libraries(datalog_${example} datalog wpiutil) + set_property(TARGET datalog_${example} PROPERTY FOLDER "examples") + endif() +endforeach() + +# Java bindings +if(WITH_JAVA) + include(UseJava) + + set(CMAKE_JNI_TARGET true) + + file(GLOB_RECURSE JAVA_SOURCES src/main/java/*.java) + file(GLOB QUICKBUF_JAR ${WPILIB_BINARY_DIR}/wpiutil/thirdparty/quickbuf/*.jar) + + add_jar( + datalog_jar + ${JAVA_SOURCES} + # INCLUDE_JARS ${JACKSON_JARS} ${QUICKBUF_JAR} + INCLUDE_JARS wpiutil_jar ${QUICKBUF_JAR} + OUTPUT_NAME datalog + OUTPUT_DIR ${WPILIB_BINARY_DIR}/${java_lib_dest} + GENERATE_NATIVE_HEADERS datalog_jni_headers + ) + set_property(TARGET datalog_jar PROPERTY FOLDER "java") + + install_jar(datalog_jar DESTINATION ${java_lib_dest}) + install_jar_exports( + TARGETS datalog_jar + FILE datalog_jar.cmake + DESTINATION share/datalog + ) + + add_library(datalogjni ${datalog_jni_src}) + wpilib_target_warnings(datalogjni) + target_link_libraries(datalogjni PUBLIC datalog wpiutil) + + set_property(TARGET datalogjni PROPERTY FOLDER "libraries") + + target_link_libraries(datalogjni PRIVATE datalog_jni_headers) + add_dependencies(datalogjni datalog_jar) + + install(TARGETS datalogjni EXPORT datalogjni) + export(TARGETS datalogjni FILE datalogjni.cmake NAMESPACE datalogjni::) +endif() + +if(WITH_JAVA_SOURCE) + include(UseJava) + include(CreateSourceJar) + add_source_jar( + datalog_src_jar + BASE_DIRECTORIES ${CMAKE_CURRENT_SOURCE_DIR}/src/main/java + OUTPUT_NAME datalog-sources + OUTPUT_DIR ${WPILIB_BINARY_DIR}/${java_lib_dest} + ) + set_property(TARGET datalog_src_jar PROPERTY FOLDER "java") + + install_jar(datalog_src_jar DESTINATION ${java_lib_dest}) +endif() + +install(TARGETS datalog EXPORT datalog) +export(TARGETS datalog FILE datalog.cmake NAMESPACE datalog::) + +configure_file(datalog-config.cmake.in ${WPILIB_BINARY_DIR}/datalog-config.cmake) +install(FILES ${WPILIB_BINARY_DIR}/datalog-config.cmake DESTINATION share/datalog) +install(EXPORT datalog DESTINATION share/datalog) + +if(WITH_TESTS) + file(GLOB_RECURSE datalog_testlib_src src/test/native/include/*.h) + add_library(datalog_testlib INTERFACE ${datalog_test_src}) + target_include_directories(datalog_testlib INTERFACE src/test/native/include) + + wpilib_add_test(datalog src/test/native/cpp) + target_link_libraries(datalog_test datalog googletest datalog_testlib wpiutil) + if(MSVC) + target_compile_options(datalog_test PRIVATE /utf-8) + endif() +endif() diff --git a/libdatalog/build.gradle b/datalog/build.gradle similarity index 86% rename from libdatalog/build.gradle rename to datalog/build.gradle index c52bae7b95f..211908a4d2b 100644 --- a/libdatalog/build.gradle +++ b/datalog/build.gradle @@ -1,17 +1,17 @@ ext { useJava = true useCpp = true - baseId = 'libdatalog' + baseId = 'datalog' groupId = 'edu.wpi.first.datalog' - nativeName = 'libdatalog' + nativeName = 'datalog' devMain = 'edu.wpi.first.datalog.DevMain' } apply from: "${rootDir}/shared/jni/setupBuild.gradle" nativeUtils.exportsConfigs { - libdatalog { + datalog { } } diff --git a/libdatalog/libdatalog-config.cmake.in b/datalog/datalog-config.cmake.in similarity index 100% rename from libdatalog/libdatalog-config.cmake.in rename to datalog/datalog-config.cmake.in diff --git a/libdatalog/examples/printlog/datalog.py b/datalog/examples/printlog/datalog.py similarity index 100% rename from libdatalog/examples/printlog/datalog.py rename to datalog/examples/printlog/datalog.py diff --git a/libdatalog/examples/printlog/printlog.cpp b/datalog/examples/printlog/printlog.cpp similarity index 100% rename from libdatalog/examples/printlog/printlog.cpp rename to datalog/examples/printlog/printlog.cpp diff --git a/libdatalog/examples/writelog/writelog.cpp b/datalog/examples/writelog/writelog.cpp similarity index 100% rename from libdatalog/examples/writelog/writelog.cpp rename to datalog/examples/writelog/writelog.cpp diff --git a/libdatalog/src/dev/java/edu/wpi/first/datalog/DevMain.java b/datalog/src/dev/java/edu/wpi/first/datalog/DevMain.java similarity index 100% rename from libdatalog/src/dev/java/edu/wpi/first/datalog/DevMain.java rename to datalog/src/dev/java/edu/wpi/first/datalog/DevMain.java diff --git a/libdatalog/src/dev/native/cpp/main.cpp b/datalog/src/dev/native/cpp/main.cpp similarity index 100% rename from libdatalog/src/dev/native/cpp/main.cpp rename to datalog/src/dev/native/cpp/main.cpp diff --git a/libdatalog/src/main/java/edu/wpi/first/datalog/BooleanArrayLogEntry.java b/datalog/src/main/java/edu/wpi/first/datalog/BooleanArrayLogEntry.java similarity index 100% rename from libdatalog/src/main/java/edu/wpi/first/datalog/BooleanArrayLogEntry.java rename to datalog/src/main/java/edu/wpi/first/datalog/BooleanArrayLogEntry.java diff --git a/libdatalog/src/main/java/edu/wpi/first/datalog/BooleanLogEntry.java b/datalog/src/main/java/edu/wpi/first/datalog/BooleanLogEntry.java similarity index 100% rename from libdatalog/src/main/java/edu/wpi/first/datalog/BooleanLogEntry.java rename to datalog/src/main/java/edu/wpi/first/datalog/BooleanLogEntry.java diff --git a/libdatalog/src/main/java/edu/wpi/first/datalog/DataLog.java b/datalog/src/main/java/edu/wpi/first/datalog/DataLog.java similarity index 100% rename from libdatalog/src/main/java/edu/wpi/first/datalog/DataLog.java rename to datalog/src/main/java/edu/wpi/first/datalog/DataLog.java diff --git a/libdatalog/src/main/java/edu/wpi/first/datalog/DataLogBackgroundWriter.java b/datalog/src/main/java/edu/wpi/first/datalog/DataLogBackgroundWriter.java similarity index 100% rename from libdatalog/src/main/java/edu/wpi/first/datalog/DataLogBackgroundWriter.java rename to datalog/src/main/java/edu/wpi/first/datalog/DataLogBackgroundWriter.java diff --git a/libdatalog/src/main/java/edu/wpi/first/datalog/DataLogEntry.java b/datalog/src/main/java/edu/wpi/first/datalog/DataLogEntry.java similarity index 100% rename from libdatalog/src/main/java/edu/wpi/first/datalog/DataLogEntry.java rename to datalog/src/main/java/edu/wpi/first/datalog/DataLogEntry.java diff --git a/libdatalog/src/main/java/edu/wpi/first/datalog/DataLogIterator.java b/datalog/src/main/java/edu/wpi/first/datalog/DataLogIterator.java similarity index 100% rename from libdatalog/src/main/java/edu/wpi/first/datalog/DataLogIterator.java rename to datalog/src/main/java/edu/wpi/first/datalog/DataLogIterator.java diff --git a/libdatalog/src/main/java/edu/wpi/first/datalog/DataLogJNI.java b/datalog/src/main/java/edu/wpi/first/datalog/DataLogJNI.java similarity index 99% rename from libdatalog/src/main/java/edu/wpi/first/datalog/DataLogJNI.java rename to datalog/src/main/java/edu/wpi/first/datalog/DataLogJNI.java index b9a150d36b9..bffd6ab3c3a 100644 --- a/libdatalog/src/main/java/edu/wpi/first/datalog/DataLogJNI.java +++ b/datalog/src/main/java/edu/wpi/first/datalog/DataLogJNI.java @@ -12,7 +12,7 @@ /** * DataLog JNI Functions. * - * @see "libdatalog/DataLog.h" + * @see "datalog/DataLog.h" */ public class DataLogJNI { static boolean libraryLoaded = false; @@ -46,7 +46,7 @@ private Helper() {} static { if (Helper.getExtractOnStaticLoad()) { try { - RuntimeLoader.loadLibrary("libdatalogjni"); + RuntimeLoader.loadLibrary("datalogjni"); } catch (Exception ex) { ex.printStackTrace(); System.exit(1); diff --git a/libdatalog/src/main/java/edu/wpi/first/datalog/DataLogReader.java b/datalog/src/main/java/edu/wpi/first/datalog/DataLogReader.java similarity index 100% rename from libdatalog/src/main/java/edu/wpi/first/datalog/DataLogReader.java rename to datalog/src/main/java/edu/wpi/first/datalog/DataLogReader.java diff --git a/libdatalog/src/main/java/edu/wpi/first/datalog/DataLogRecord.java b/datalog/src/main/java/edu/wpi/first/datalog/DataLogRecord.java similarity index 100% rename from libdatalog/src/main/java/edu/wpi/first/datalog/DataLogRecord.java rename to datalog/src/main/java/edu/wpi/first/datalog/DataLogRecord.java diff --git a/libdatalog/src/main/java/edu/wpi/first/datalog/DataLogWriter.java b/datalog/src/main/java/edu/wpi/first/datalog/DataLogWriter.java similarity index 100% rename from libdatalog/src/main/java/edu/wpi/first/datalog/DataLogWriter.java rename to datalog/src/main/java/edu/wpi/first/datalog/DataLogWriter.java diff --git a/libdatalog/src/main/java/edu/wpi/first/datalog/DoubleArrayLogEntry.java b/datalog/src/main/java/edu/wpi/first/datalog/DoubleArrayLogEntry.java similarity index 100% rename from libdatalog/src/main/java/edu/wpi/first/datalog/DoubleArrayLogEntry.java rename to datalog/src/main/java/edu/wpi/first/datalog/DoubleArrayLogEntry.java diff --git a/libdatalog/src/main/java/edu/wpi/first/datalog/DoubleLogEntry.java b/datalog/src/main/java/edu/wpi/first/datalog/DoubleLogEntry.java similarity index 100% rename from libdatalog/src/main/java/edu/wpi/first/datalog/DoubleLogEntry.java rename to datalog/src/main/java/edu/wpi/first/datalog/DoubleLogEntry.java diff --git a/libdatalog/src/main/java/edu/wpi/first/datalog/FileLogger.java b/datalog/src/main/java/edu/wpi/first/datalog/FileLogger.java similarity index 100% rename from libdatalog/src/main/java/edu/wpi/first/datalog/FileLogger.java rename to datalog/src/main/java/edu/wpi/first/datalog/FileLogger.java diff --git a/libdatalog/src/main/java/edu/wpi/first/datalog/FloatArrayLogEntry.java b/datalog/src/main/java/edu/wpi/first/datalog/FloatArrayLogEntry.java similarity index 100% rename from libdatalog/src/main/java/edu/wpi/first/datalog/FloatArrayLogEntry.java rename to datalog/src/main/java/edu/wpi/first/datalog/FloatArrayLogEntry.java diff --git a/libdatalog/src/main/java/edu/wpi/first/datalog/FloatLogEntry.java b/datalog/src/main/java/edu/wpi/first/datalog/FloatLogEntry.java similarity index 100% rename from libdatalog/src/main/java/edu/wpi/first/datalog/FloatLogEntry.java rename to datalog/src/main/java/edu/wpi/first/datalog/FloatLogEntry.java diff --git a/libdatalog/src/main/java/edu/wpi/first/datalog/IntegerArrayLogEntry.java b/datalog/src/main/java/edu/wpi/first/datalog/IntegerArrayLogEntry.java similarity index 100% rename from libdatalog/src/main/java/edu/wpi/first/datalog/IntegerArrayLogEntry.java rename to datalog/src/main/java/edu/wpi/first/datalog/IntegerArrayLogEntry.java diff --git a/libdatalog/src/main/java/edu/wpi/first/datalog/IntegerLogEntry.java b/datalog/src/main/java/edu/wpi/first/datalog/IntegerLogEntry.java similarity index 100% rename from libdatalog/src/main/java/edu/wpi/first/datalog/IntegerLogEntry.java rename to datalog/src/main/java/edu/wpi/first/datalog/IntegerLogEntry.java diff --git a/libdatalog/src/main/java/edu/wpi/first/datalog/ProtobufLogEntry.java b/datalog/src/main/java/edu/wpi/first/datalog/ProtobufLogEntry.java similarity index 100% rename from libdatalog/src/main/java/edu/wpi/first/datalog/ProtobufLogEntry.java rename to datalog/src/main/java/edu/wpi/first/datalog/ProtobufLogEntry.java diff --git a/libdatalog/src/main/java/edu/wpi/first/datalog/RawLogEntry.java b/datalog/src/main/java/edu/wpi/first/datalog/RawLogEntry.java similarity index 100% rename from libdatalog/src/main/java/edu/wpi/first/datalog/RawLogEntry.java rename to datalog/src/main/java/edu/wpi/first/datalog/RawLogEntry.java diff --git a/libdatalog/src/main/java/edu/wpi/first/datalog/StringArrayLogEntry.java b/datalog/src/main/java/edu/wpi/first/datalog/StringArrayLogEntry.java similarity index 100% rename from libdatalog/src/main/java/edu/wpi/first/datalog/StringArrayLogEntry.java rename to datalog/src/main/java/edu/wpi/first/datalog/StringArrayLogEntry.java diff --git a/libdatalog/src/main/java/edu/wpi/first/datalog/StringLogEntry.java b/datalog/src/main/java/edu/wpi/first/datalog/StringLogEntry.java similarity index 100% rename from libdatalog/src/main/java/edu/wpi/first/datalog/StringLogEntry.java rename to datalog/src/main/java/edu/wpi/first/datalog/StringLogEntry.java diff --git a/libdatalog/src/main/java/edu/wpi/first/datalog/StructArrayLogEntry.java b/datalog/src/main/java/edu/wpi/first/datalog/StructArrayLogEntry.java similarity index 100% rename from libdatalog/src/main/java/edu/wpi/first/datalog/StructArrayLogEntry.java rename to datalog/src/main/java/edu/wpi/first/datalog/StructArrayLogEntry.java diff --git a/libdatalog/src/main/java/edu/wpi/first/datalog/StructLogEntry.java b/datalog/src/main/java/edu/wpi/first/datalog/StructLogEntry.java similarity index 100% rename from libdatalog/src/main/java/edu/wpi/first/datalog/StructLogEntry.java rename to datalog/src/main/java/edu/wpi/first/datalog/StructLogEntry.java diff --git a/libdatalog/src/main/native/cpp/DataLog.cpp b/datalog/src/main/native/cpp/DataLog.cpp similarity index 100% rename from libdatalog/src/main/native/cpp/DataLog.cpp rename to datalog/src/main/native/cpp/DataLog.cpp diff --git a/libdatalog/src/main/native/cpp/DataLogBackgroundWriter.cpp b/datalog/src/main/native/cpp/DataLogBackgroundWriter.cpp similarity index 100% rename from libdatalog/src/main/native/cpp/DataLogBackgroundWriter.cpp rename to datalog/src/main/native/cpp/DataLogBackgroundWriter.cpp diff --git a/libdatalog/src/main/native/cpp/DataLogReader.cpp b/datalog/src/main/native/cpp/DataLogReader.cpp similarity index 100% rename from libdatalog/src/main/native/cpp/DataLogReader.cpp rename to datalog/src/main/native/cpp/DataLogReader.cpp diff --git a/libdatalog/src/main/native/cpp/DataLogReaderThread.cpp b/datalog/src/main/native/cpp/DataLogReaderThread.cpp similarity index 100% rename from libdatalog/src/main/native/cpp/DataLogReaderThread.cpp rename to datalog/src/main/native/cpp/DataLogReaderThread.cpp diff --git a/libdatalog/src/main/native/cpp/DataLogWriter.cpp b/datalog/src/main/native/cpp/DataLogWriter.cpp similarity index 100% rename from libdatalog/src/main/native/cpp/DataLogWriter.cpp rename to datalog/src/main/native/cpp/DataLogWriter.cpp diff --git a/libdatalog/src/main/native/cpp/FileLogger.cpp b/datalog/src/main/native/cpp/FileLogger.cpp similarity index 100% rename from libdatalog/src/main/native/cpp/FileLogger.cpp rename to datalog/src/main/native/cpp/FileLogger.cpp diff --git a/libdatalog/src/main/native/cpp/jni/DataLogJNI.cpp b/datalog/src/main/native/cpp/jni/DataLogJNI.cpp similarity index 100% rename from libdatalog/src/main/native/cpp/jni/DataLogJNI.cpp rename to datalog/src/main/native/cpp/jni/DataLogJNI.cpp diff --git a/libdatalog/src/main/native/cpp/jni/DataLogJNI.h b/datalog/src/main/native/cpp/jni/DataLogJNI.h similarity index 100% rename from libdatalog/src/main/native/cpp/jni/DataLogJNI.h rename to datalog/src/main/native/cpp/jni/DataLogJNI.h diff --git a/libdatalog/src/main/native/include/wpi/DataLog.h b/datalog/src/main/native/include/wpi/DataLog.h similarity index 100% rename from libdatalog/src/main/native/include/wpi/DataLog.h rename to datalog/src/main/native/include/wpi/DataLog.h diff --git a/libdatalog/src/main/native/include/wpi/DataLogBackgroundWriter.h b/datalog/src/main/native/include/wpi/DataLogBackgroundWriter.h similarity index 100% rename from libdatalog/src/main/native/include/wpi/DataLogBackgroundWriter.h rename to datalog/src/main/native/include/wpi/DataLogBackgroundWriter.h diff --git a/libdatalog/src/main/native/include/wpi/DataLogReader.h b/datalog/src/main/native/include/wpi/DataLogReader.h similarity index 100% rename from libdatalog/src/main/native/include/wpi/DataLogReader.h rename to datalog/src/main/native/include/wpi/DataLogReader.h diff --git a/libdatalog/src/main/native/include/wpi/DataLogReaderThread.h b/datalog/src/main/native/include/wpi/DataLogReaderThread.h similarity index 100% rename from libdatalog/src/main/native/include/wpi/DataLogReaderThread.h rename to datalog/src/main/native/include/wpi/DataLogReaderThread.h diff --git a/libdatalog/src/main/native/include/wpi/DataLogWriter.h b/datalog/src/main/native/include/wpi/DataLogWriter.h similarity index 100% rename from libdatalog/src/main/native/include/wpi/DataLogWriter.h rename to datalog/src/main/native/include/wpi/DataLogWriter.h diff --git a/libdatalog/src/main/native/include/wpi/DataLog_c.h b/datalog/src/main/native/include/wpi/DataLog_c.h similarity index 100% rename from libdatalog/src/main/native/include/wpi/DataLog_c.h rename to datalog/src/main/native/include/wpi/DataLog_c.h diff --git a/libdatalog/src/main/native/include/wpi/FileLogger.h b/datalog/src/main/native/include/wpi/FileLogger.h similarity index 100% rename from libdatalog/src/main/native/include/wpi/FileLogger.h rename to datalog/src/main/native/include/wpi/FileLogger.h diff --git a/libdatalog/src/printlog/java/printlog/PrintLog.java b/datalog/src/printlog/java/printlog/PrintLog.java similarity index 100% rename from libdatalog/src/printlog/java/printlog/PrintLog.java rename to datalog/src/printlog/java/printlog/PrintLog.java diff --git a/libdatalog/src/test/java/edu/wpi/first/datalog/DataLogTest.java b/datalog/src/test/java/edu/wpi/first/datalog/DataLogTest.java similarity index 100% rename from libdatalog/src/test/java/edu/wpi/first/datalog/DataLogTest.java rename to datalog/src/test/java/edu/wpi/first/datalog/DataLogTest.java diff --git a/libdatalog/src/test/native/cpp/DataLogTest.cpp b/datalog/src/test/native/cpp/DataLogTest.cpp similarity index 100% rename from libdatalog/src/test/native/cpp/DataLogTest.cpp rename to datalog/src/test/native/cpp/DataLogTest.cpp diff --git a/libdatalog/src/test/native/cpp/FileLoggerTest.cpp b/datalog/src/test/native/cpp/FileLoggerTest.cpp similarity index 100% rename from libdatalog/src/test/native/cpp/FileLoggerTest.cpp rename to datalog/src/test/native/cpp/FileLoggerTest.cpp diff --git a/libdatalog/src/test/native/cpp/main.cpp b/datalog/src/test/native/cpp/main.cpp similarity index 100% rename from libdatalog/src/test/native/cpp/main.cpp rename to datalog/src/test/native/cpp/main.cpp diff --git a/datalogtool/CMakeLists.txt b/datalogtool/CMakeLists.txt index 0ac6bf017c1..0c74557c57a 100644 --- a/datalogtool/CMakeLists.txt +++ b/datalogtool/CMakeLists.txt @@ -25,7 +25,7 @@ add_executable( ${APP_ICON_MACOSX} ) wpilib_link_macos_gui(datalogtool) -target_link_libraries(datalogtool libglass ssh libdatalog wpiutil) +target_link_libraries(datalogtool libglass ssh datalog wpiutil) if(WIN32) set_target_properties(datalogtool PROPERTIES WIN32_EXECUTABLE YES) diff --git a/datalogtool/build.gradle b/datalogtool/build.gradle index 3117cc05f6e..1cea1ef5ea7 100644 --- a/datalogtool/build.gradle +++ b/datalogtool/build.gradle @@ -100,7 +100,7 @@ model { it.cppCompiler.define("LIBSSH_STATIC") lib project: ':glass', library: 'glass', linkage: 'static' lib project: ':wpigui', library: 'wpigui', linkage: 'static' - lib project: ':libdatalog', library: 'libdatalog', linkage: 'static' + lib project: ':datalog', library: 'datalog', linkage: 'static' lib project: ':thirdparty:imgui_suite', library: 'imguiSuite', linkage: 'static' lib project: ':wpiutil', library: 'wpiutil', linkage: 'static' nativeUtils.useRequiredLibrary(it, 'libssh') diff --git a/epilogue-runtime/BUILD.bazel b/epilogue-runtime/BUILD.bazel index da2778a8196..0b837be7291 100644 --- a/epilogue-runtime/BUILD.bazel +++ b/epilogue-runtime/BUILD.bazel @@ -9,7 +9,7 @@ java_library( "//ntcore:networktables-java", "//wpiunits", "//wpiutil:wpiutil-java", - "//libdatalog:datalog-java" + "//datalog:datalog-java" ], ) diff --git a/epilogue-runtime/build.gradle b/epilogue-runtime/build.gradle index 615ab3e510b..ffcf6c096ff 100644 --- a/epilogue-runtime/build.gradle +++ b/epilogue-runtime/build.gradle @@ -13,5 +13,5 @@ dependencies { api(project(':ntcore')) api(project(':wpiutil')) api(project(':wpiunits')) - api(project(':libdatalog')) + api(project(':datalog')) } diff --git a/libdatalog/CMakeLists.txt b/libdatalog/CMakeLists.txt deleted file mode 100644 index 879fd5f2094..00000000000 --- a/libdatalog/CMakeLists.txt +++ /dev/null @@ -1,112 +0,0 @@ -project(libdatalog) - -include(CompileWarnings) - -file(GLOB libdatalog_native_src src/main/native/cpp/*.cpp) - -file(GLOB libdatalog_jni_src src/main/native/cpp/jni/DataLogJNI.cpp) -list(REMOVE_ITEM libdatalog_native_src ${libdatalog_jni_src}) - -add_library(libdatalog ${libdatalog_native_src}) -set_target_properties(libdatalog PROPERTIES DEBUG_POSTFIX "d") - -target_compile_features(libdatalog PUBLIC cxx_std_20) -if(MSVC) - target_compile_options( - libdatalog - PUBLIC /permissive- /Zc:preprocessor /Zc:__cplusplus /Zc:throwingNew /MP /bigobj /utf-8 - ) - target_compile_definitions(libdatalog PRIVATE -D_CRT_SECURE_NO_WARNINGS) -endif() -wpilib_target_warnings(libdatalog) - -target_include_directories( - libdatalog - PUBLIC $ -) - -target_link_libraries(libdatalog PRIVATE wpiutil) - -subdir_list(libdatalog_examples "${CMAKE_CURRENT_SOURCE_DIR}/examples") -foreach(example ${libdatalog_examples}) - file(GLOB libdatalog_example_src examples/${example}/*.cpp) - if(libdatalog_example_src) - add_executable(libdatalog_${example} ${libdatalog_example_src}) - wpilib_target_warnings(libdatalog_${example}) - target_link_libraries(libdatalog_${example} libdatalog wpiutil) - set_property(TARGET libdatalog_${example} PROPERTY FOLDER "examples") - endif() -endforeach() - -# Java bindings -if(WITH_JAVA) - include(UseJava) - - set(CMAKE_JNI_TARGET true) - - file(GLOB_RECURSE JAVA_SOURCES src/main/java/*.java) - file(GLOB QUICKBUF_JAR ${WPILIB_BINARY_DIR}/wpiutil/thirdparty/quickbuf/*.jar) - - add_jar( - libdatalog_jar - ${JAVA_SOURCES} - # INCLUDE_JARS ${JACKSON_JARS} ${QUICKBUF_JAR} - INCLUDE_JARS wpiutil_jar ${QUICKBUF_JAR} - OUTPUT_NAME libdatalog - OUTPUT_DIR ${WPILIB_BINARY_DIR}/${java_lib_dest} - GENERATE_NATIVE_HEADERS libdatalog_jni_headers - ) - set_property(TARGET libdatalog_jar PROPERTY FOLDER "java") - - install_jar(libdatalog_jar DESTINATION ${java_lib_dest}) - install_jar_exports( - TARGETS libdatalog_jar - FILE libdatalog_jar.cmake - DESTINATION share/libdatalog - ) - - add_library(libdatalogjni ${libdatalog_jni_src}) - wpilib_target_warnings(libdatalogjni) - target_link_libraries(libdatalogjni PUBLIC libdatalog wpiutil) - - set_property(TARGET libdatalogjni PROPERTY FOLDER "libraries") - - target_link_libraries(libdatalogjni PRIVATE libdatalog_jni_headers) - add_dependencies(libdatalogjni libdatalog_jar) - - install(TARGETS libdatalogjni EXPORT libdatalogjni) - export(TARGETS libdatalogjni FILE libdatalogjni.cmake NAMESPACE libdatalogjni::) -endif() - -if(WITH_JAVA_SOURCE) - include(UseJava) - include(CreateSourceJar) - add_source_jar( - libdatalog_src_jar - BASE_DIRECTORIES ${CMAKE_CURRENT_SOURCE_DIR}/src/main/java - OUTPUT_NAME libdatalog-sources - OUTPUT_DIR ${WPILIB_BINARY_DIR}/${java_lib_dest} - ) - set_property(TARGET libdatalog_src_jar PROPERTY FOLDER "java") - - install_jar(libdatalog_src_jar DESTINATION ${java_lib_dest}) -endif() - -install(TARGETS libdatalog EXPORT libdatalog) -export(TARGETS libdatalog FILE libdatalog.cmake NAMESPACE libdatalog::) - -configure_file(libdatalog-config.cmake.in ${WPILIB_BINARY_DIR}/libdatalog-config.cmake) -install(FILES ${WPILIB_BINARY_DIR}/libdatalog-config.cmake DESTINATION share/libdatalog) -install(EXPORT libdatalog DESTINATION share/libdatalog) - -if(WITH_TESTS) - file(GLOB_RECURSE libdatalog_testlib_src src/test/native/include/*.h) - add_library(libdatalog_testlib INTERFACE ${libdatalog_test_src}) - target_include_directories(libdatalog_testlib INTERFACE src/test/native/include) - - wpilib_add_test(libdatalog src/test/native/cpp) - target_link_libraries(libdatalog_test libdatalog googletest libdatalog_testlib wpiutil) - if(MSVC) - target_compile_options(libdatalog_test PRIVATE /utf-8) - endif() -endif() diff --git a/ntcore/BUILD.bazel b/ntcore/BUILD.bazel index d289bfc4c23..fd18641607e 100644 --- a/ntcore/BUILD.bazel +++ b/ntcore/BUILD.bazel @@ -49,7 +49,7 @@ cc_library( ":generated_cc_headers", "//wpinet:wpinet.static", "//wpiutil:wpiutil.static", - "//libdatalog:libdatalog.static", + "//datalog:datalog.static", ], ) @@ -70,7 +70,7 @@ wpilib_jni_java_library( visibility = ["//visibility:public"], deps = [ "//wpiutil:wpiutil-java", - "//libdatalog:datalog-java", + "//datalog:datalog-java", "@maven//:us_hebi_quickbuf_quickbuf_runtime", ], ) diff --git a/ntcore/CMakeLists.txt b/ntcore/CMakeLists.txt index 1dc9b6c806c..c248d532aaf 100644 --- a/ntcore/CMakeLists.txt +++ b/ntcore/CMakeLists.txt @@ -26,7 +26,7 @@ target_include_directories( ) wpilib_target_warnings(ntcore) target_compile_features(ntcore PUBLIC cxx_std_20) -target_link_libraries(ntcore PUBLIC wpinet wpiutil libdatalog) +target_link_libraries(ntcore PUBLIC wpinet wpiutil datalog) set_property(TARGET ntcore PROPERTY FOLDER "libraries") @@ -53,7 +53,7 @@ if(WITH_JAVA) add_jar( ntcore_jar ${JAVA_SOURCES} - INCLUDE_JARS wpiutil_jar ${QUICKBUF_JAR} libdatalog_jar + INCLUDE_JARS wpiutil_jar ${QUICKBUF_JAR} datalog_jar OUTPUT_NAME ntcore OUTPUT_DIR ${WPILIB_BINARY_DIR}/${java_lib_dest} GENERATE_NATIVE_HEADERS ntcore_jni_headers diff --git a/ntcore/build.gradle b/ntcore/build.gradle index 3116b28b575..e4c3da5673d 100644 --- a/ntcore/build.gradle +++ b/ntcore/build.gradle @@ -1,12 +1,12 @@ ext { addNtcoreDependency = { binary, shared-> binary.lib project: ':ntcore', library: 'ntcore', linkage: shared - binary.lib project: ':libdatalog', library: 'libdatalog', linkage: shared + binary.lib project: ':datalog', library: 'datalog', linkage: shared } addNtcoreJniDependency = { binary-> binary.lib project: ':ntcore', library: 'ntcoreJNIShared', linkage: 'shared' - binary.lib project: ':libdatalog', library: 'libdatalogJNIShared', linkage: 'shared' + binary.lib project: ':datalog', library: 'datalogJNIShared', linkage: 'shared' } nativeName = 'ntcore' @@ -36,11 +36,11 @@ model { if (it.component.name == "${nativeName}JNI") { lib project: ':wpinet', library: 'wpinet', linkage: 'static' lib project: ':wpiutil', library: 'wpiutil', linkage: 'static' - lib project: ':libdatalog', library: 'libdatalog', linkage: 'static' + lib project: ':datalog', library: 'datalog', linkage: 'static' } else { lib project: ':wpinet', library: 'wpinet', linkage: 'shared' lib project: ':wpiutil', library: 'wpiutil', linkage: 'shared' - lib project: ':libdatalog', library: 'libdatalog', linkage: 'shared' + lib project: ':datalog', library: 'datalog', linkage: 'shared' } } } @@ -67,5 +67,5 @@ nativeUtils.exportsConfigs { } dependencies { - api project(":libdatalog") + api project(":datalog") } diff --git a/settings.gradle b/settings.gradle index 3f9f00ae16a..8f55ab798e1 100644 --- a/settings.gradle +++ b/settings.gradle @@ -59,7 +59,7 @@ include 'epilogue-runtime' include 'thirdparty:googletest' include 'thirdparty:imgui_suite' include 'wpical' -include 'libdatalog' +include 'datalog' buildCache { def cred = { diff --git a/sysid/CMakeLists.txt b/sysid/CMakeLists.txt index 86069d1ff4a..389f8d06143 100644 --- a/sysid/CMakeLists.txt +++ b/sysid/CMakeLists.txt @@ -25,7 +25,7 @@ endif() wpilib_link_macos_gui(sysid) wpilib_target_warnings(sysid) target_include_directories(sysid PRIVATE src/main/native/include) -target_link_libraries(sysid wpimath libglass libdatalog) +target_link_libraries(sysid wpimath libglass datalog) if(WIN32) set_target_properties(sysid PROPERTIES WIN32_EXECUTABLE YES) @@ -42,5 +42,5 @@ if(WITH_TESTS) target_compile_options(sysid_test PRIVATE /utf-8) endif() target_include_directories(sysid_test PRIVATE src/main/native/cpp src/main/native/include) - target_link_libraries(sysid_test wpimath libglass libdatalog googletest) + target_link_libraries(sysid_test wpimath libglass datalog googletest) endif() diff --git a/sysid/build.gradle b/sysid/build.gradle index 72406b5e245..cb0964bfd3d 100644 --- a/sysid/build.gradle +++ b/sysid/build.gradle @@ -99,7 +99,7 @@ model { lib project: ':glass', library: 'glass', linkage: 'static' lib project: ':wpimath', library: 'wpimath', linkage: 'static' lib project: ':wpigui', library: 'wpigui', linkage: 'static' - lib project: ':libdatalog', library: 'libdatalog', linkage: 'static' + lib project: ':datalog', library: 'datalog', linkage: 'static' lib project: ':thirdparty:imgui_suite', library: 'imguiSuite', linkage: 'static' lib project: ':wpiutil', library: 'wpiutil', linkage: 'static' if (it.targetPlatform.operatingSystem.isWindows()) { @@ -138,7 +138,7 @@ model { } lib project: ':glass', library: 'glass', linkage: 'static' lib project: ':wpimath', library: 'wpimath', linkage: 'static' - lib project: ':libdatalog', library: 'libdatalog', linkage: 'static' + lib project: ':datalog', library: 'datalog', linkage: 'static' lib project: ':wpigui', library: 'wpigui', linkage: 'static' lib project: ':thirdparty:imgui_suite', library: 'imguiSuite', linkage: 'static' lib project: ':wpiutil', library: 'wpiutil', linkage: 'static' diff --git a/wpilibNewCommands/CMakeLists.txt b/wpilibNewCommands/CMakeLists.txt index 9c06496928b..d4107abb679 100644 --- a/wpilibNewCommands/CMakeLists.txt +++ b/wpilibNewCommands/CMakeLists.txt @@ -22,7 +22,7 @@ if(WITH_JAVA) wpiunits_jar wpiutil_jar wpilibj_jar - libdatalog_jar + datalog_jar OUTPUT_NAME wpilibNewCommands OUTPUT_DIR ${WPILIB_BINARY_DIR}/${java_lib_dest} ) diff --git a/wpilibNewCommands/build.gradle b/wpilibNewCommands/build.gradle index 1c0906bd7e8..dd5930e3eca 100644 --- a/wpilibNewCommands/build.gradle +++ b/wpilibNewCommands/build.gradle @@ -21,7 +21,7 @@ dependencies { implementation project(':hal') implementation project(':wpimath') implementation project(':wpilibj') - api project(':libdatalog') + api project(':datalog') testImplementation 'org.mockito:mockito-core:4.1.0' } diff --git a/wpilibc/CMakeLists.txt b/wpilibc/CMakeLists.txt index 5ece089ffc1..7f4907b2961 100644 --- a/wpilibc/CMakeLists.txt +++ b/wpilibc/CMakeLists.txt @@ -35,7 +35,7 @@ else() ) endif() -target_link_libraries(wpilibc PUBLIC hal ntcore wpimath libdatalog) +target_link_libraries(wpilibc PUBLIC hal ntcore wpimath datalog) set_property(TARGET wpilibc PROPERTY FOLDER "libraries") diff --git a/wpilibc/build.gradle b/wpilibc/build.gradle index 2d8c6f961a7..1bc014ee513 100644 --- a/wpilibc/build.gradle +++ b/wpilibc/build.gradle @@ -112,7 +112,7 @@ model { lib project: ':wpinet', library: 'wpinet', linkage: 'shared' lib project: ':wpiutil', library: 'wpiutil', linkage: 'shared' lib project: ':wpimath', library: 'wpimath', linkage: 'shared' - lib project: ':libdatalog', library: 'libdatalog', linkage: 'shared' + lib project: ':datalog', library: 'datalog', linkage: 'shared' } } "${nativeName}"(NativeLibrarySpec) { diff --git a/wpilibj/CMakeLists.txt b/wpilibj/CMakeLists.txt index cb60b313b95..e27bbbb21f9 100644 --- a/wpilibj/CMakeLists.txt +++ b/wpilibj/CMakeLists.txt @@ -41,7 +41,7 @@ if(WITH_JAVA) wpimath_jar wpiunits_jar wpiutil_jar - libdatalog_jar + datalog_jar OUTPUT_NAME wpilibj OUTPUT_DIR ${WPILIB_BINARY_DIR}/${java_lib_dest} ) diff --git a/wpilibj/build.gradle b/wpilibj/build.gradle index 058229163ec..07f5df67dad 100644 --- a/wpilibj/build.gradle +++ b/wpilibj/build.gradle @@ -69,7 +69,7 @@ dependencies { implementation project(':wpimath') implementation project(':ntcore') implementation project(':cscore') - api project(':libdatalog') + api project(':datalog') implementation project(':cameraserver') testImplementation 'org.mockito:mockito-core:4.1.0' devImplementation sourceSets.main.output From 016fb016ad9ebc373e96e577767b6d9e7c7b0ce2 Mon Sep 17 00:00:00 2001 From: DeltaDizzy Date: Sun, 26 Jan 2025 21:37:56 -0500 Subject: [PATCH 52/64] format datalog cmake --- datalog/CMakeLists.txt | 6 +----- 1 file changed, 1 insertion(+), 5 deletions(-) diff --git a/datalog/CMakeLists.txt b/datalog/CMakeLists.txt index 91e5073bba4..2e31dc10c40 100644 --- a/datalog/CMakeLists.txt +++ b/datalog/CMakeLists.txt @@ -59,11 +59,7 @@ if(WITH_JAVA) set_property(TARGET datalog_jar PROPERTY FOLDER "java") install_jar(datalog_jar DESTINATION ${java_lib_dest}) - install_jar_exports( - TARGETS datalog_jar - FILE datalog_jar.cmake - DESTINATION share/datalog - ) + install_jar_exports(TARGETS datalog_jar FILE datalog_jar.cmake DESTINATION share/datalog) add_library(datalogjni ${datalog_jni_src}) wpilib_target_warnings(datalogjni) From a65b87a5b2554e48ca64a60f07b452c4aa2b5eaa Mon Sep 17 00:00:00 2001 From: DeltaDizzy Date: Sun, 26 Jan 2025 21:46:27 -0500 Subject: [PATCH 53/64] format bazels --- datalog/BUILD.bazel | 11 +++++++---- epilogue-runtime/BUILD.bazel | 2 +- ntcore/BUILD.bazel | 4 ++-- 3 files changed, 10 insertions(+), 7 deletions(-) diff --git a/datalog/BUILD.bazel b/datalog/BUILD.bazel index 78e1b87a6ea..0107e7aa06f 100644 --- a/datalog/BUILD.bazel +++ b/datalog/BUILD.bazel @@ -1,4 +1,7 @@ -load("@rules_cc//cc:defs.bzl", "cc_library") +load("@rules_cc//cc:defs.bzl", "cc_binary", "cc_library") +load("@rules_java//java:java_binary.bzl", "java_binary") +load("@rules_java//java:java_library.bzl", "java_library") +load("@rules_python//python:defs.bzl", "py_binary") cc_library( name = "datalog.static", @@ -38,8 +41,8 @@ cc_binary( name = "printlog", srcs = ["examples/printlog/printlog.cpp"], deps = [ + ":datalog.static", "//wpiutil:wpiutil.static", - ":datalog.static" ], ) @@ -47,8 +50,8 @@ cc_binary( name = "writelog", srcs = ["examples/writelog/writelog.cpp"], deps = [ + ":datalog.static", "//wpiutil:wpiutil.static", - ":datalog.static" ], ) @@ -57,6 +60,6 @@ java_binary( srcs = ["src/printlog/java/printlog/PrintLog.java"], main_class = "printlog.PrintLog", deps = [ - ":datalog-java" + ":datalog-java", ], ) diff --git a/epilogue-runtime/BUILD.bazel b/epilogue-runtime/BUILD.bazel index 0b837be7291..0fe3a4f6dff 100644 --- a/epilogue-runtime/BUILD.bazel +++ b/epilogue-runtime/BUILD.bazel @@ -6,10 +6,10 @@ java_library( srcs = glob(["src/main/java/**/*.java"]), visibility = ["//visibility:public"], deps = [ + "//datalog:datalog-java", "//ntcore:networktables-java", "//wpiunits", "//wpiutil:wpiutil-java", - "//datalog:datalog-java" ], ) diff --git a/ntcore/BUILD.bazel b/ntcore/BUILD.bazel index fd18641607e..4147b8ef816 100644 --- a/ntcore/BUILD.bazel +++ b/ntcore/BUILD.bazel @@ -47,9 +47,9 @@ cc_library( visibility = ["//visibility:public"], deps = [ ":generated_cc_headers", + "//datalog:datalog.static", "//wpinet:wpinet.static", "//wpiutil:wpiutil.static", - "//datalog:datalog.static", ], ) @@ -69,8 +69,8 @@ wpilib_jni_java_library( native_libs = [":ntcorejni"], visibility = ["//visibility:public"], deps = [ - "//wpiutil:wpiutil-java", "//datalog:datalog-java", + "//wpiutil:wpiutil-java", "@maven//:us_hebi_quickbuf_quickbuf_runtime", ], ) From d23dd97042d40a9c9e8da7c5ada531806d29461b Mon Sep 17 00:00:00 2001 From: DeltaDizzy Date: Sun, 26 Jan 2025 21:46:39 -0500 Subject: [PATCH 54/64] add datalog to wpilibj --- wpilibj/BUILD.bazel | 1 + 1 file changed, 1 insertion(+) diff --git a/wpilibj/BUILD.bazel b/wpilibj/BUILD.bazel index e5b8b0dd993..b5f193f2c43 100644 --- a/wpilibj/BUILD.bazel +++ b/wpilibj/BUILD.bazel @@ -26,6 +26,7 @@ java_library( deps = [ "//cameraserver:cameraserver-java", "//cscore:cscore-java", + "//datalog:datalog-java", "//hal:hal-java", "//ntcore:networktables-java", "//wpimath:wpimath-java", From a0ba729704037c1aa863055abba5207f4ed4236f Mon Sep 17 00:00:00 2001 From: DeltaDizzy Date: Mon, 27 Jan 2025 12:04:12 -0500 Subject: [PATCH 55/64] fix java rules def --- datalog/BUILD.bazel | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/datalog/BUILD.bazel b/datalog/BUILD.bazel index 0107e7aa06f..e5a457998c5 100644 --- a/datalog/BUILD.bazel +++ b/datalog/BUILD.bazel @@ -1,6 +1,5 @@ load("@rules_cc//cc:defs.bzl", "cc_binary", "cc_library") -load("@rules_java//java:java_binary.bzl", "java_binary") -load("@rules_java//java:java_library.bzl", "java_library") +load("@rules_java//java:defs.bzl", "java_binary", "java_library") load("@rules_python//python:defs.bzl", "py_binary") cc_library( From d324f7279d4d12ccfcfdeb3ba6c3d92ba31e8fe4 Mon Sep 17 00:00:00 2001 From: DeltaDizzy Date: Mon, 27 Jan 2025 21:59:27 -0500 Subject: [PATCH 56/64] format bazels --- shared/bazel/rules/jni_rules.bzl | 1 + wpiutil/BUILD.bazel | 1 - 2 files changed, 1 insertion(+), 1 deletion(-) diff --git a/shared/bazel/rules/jni_rules.bzl b/shared/bazel/rules/jni_rules.bzl index dfc23dbb481..880973bb90d 100644 --- a/shared/bazel/rules/jni_rules.bzl +++ b/shared/bazel/rules/jni_rules.bzl @@ -1,6 +1,7 @@ load("@bazel_tools//tools/cpp:toolchain_utils.bzl", "find_cpp_toolchain") load("@rules_cc//cc:defs.bzl", "cc_library") load("@rules_java//java:defs.bzl", "java_library") +load("@rules_java//java/common:java_info.bzl", "JavaInfo") def _jni_headers_impl(ctx): include_dir = ctx.actions.declare_directory(ctx.attr.name + ".h") diff --git a/wpiutil/BUILD.bazel b/wpiutil/BUILD.bazel index ca2ee2b0f05..3fcfaecc2b4 100644 --- a/wpiutil/BUILD.bazel +++ b/wpiutil/BUILD.bazel @@ -1,6 +1,5 @@ load("@rules_cc//cc:defs.bzl", "cc_binary", "cc_library", "cc_test") load("@rules_java//java:defs.bzl", "java_binary") -load("@rules_python//python:defs.bzl", "py_binary") load("//shared/bazel/rules:java_rules.bzl", "wpilib_java_junit5_test") load("//shared/bazel/rules:jni_rules.bzl", "wpilib_jni_cc_library", "wpilib_jni_java_library") load("//shared/bazel/rules/gen:gen-resources.bzl", "generate_resources") From 3656435cbbc66bafbc91df019025e82ac02f2685 Mon Sep 17 00:00:00 2001 From: DeltaDizzy Date: Mon, 27 Jan 2025 22:46:42 -0500 Subject: [PATCH 57/64] add bazel tests --- datalog/BUILD.bazel | 48 ++++++++++++++++++++++++++++++-- shared/bazel/rules/jni_rules.bzl | 1 - wpilibc/BUILD.bazel | 1 + 3 files changed, 46 insertions(+), 4 deletions(-) diff --git a/datalog/BUILD.bazel b/datalog/BUILD.bazel index e5a457998c5..1e3c34c1171 100644 --- a/datalog/BUILD.bazel +++ b/datalog/BUILD.bazel @@ -1,6 +1,8 @@ -load("@rules_cc//cc:defs.bzl", "cc_binary", "cc_library") -load("@rules_java//java:defs.bzl", "java_binary", "java_library") +load("@rules_cc//cc:defs.bzl", "cc_binary", "cc_library", "cc_test") +load("@rules_java//java:defs.bzl", "java_binary") load("@rules_python//python:defs.bzl", "py_binary") +load("//shared/bazel/rules:java_rules.bzl", "wpilib_java_junit5_test") +load("//shared/bazel/rules:jni_rules.bzl", "wpilib_jni_cc_library", "wpilib_jni_java_library") cc_library( name = "datalog.static", @@ -20,9 +22,20 @@ cc_library( ], ) -java_library( +wpilib_jni_cc_library( + name = "datalogjni", + srcs = glob(["src/main/native/cpp/jni/**"]), + java_dep = ":datalog-java", + visibility = ["//visibility:public"], + deps = [ + ":datalog.static", + ], +) + +wpilib_jni_java_library( name = "datalog-java", srcs = glob(["src/main/java/**/*.java"]), + native_libs = [":datalogjni"], visibility = ["//visibility:public"], deps = [ "//wpiutil:wpiutil-java", @@ -62,3 +75,32 @@ java_binary( ":datalog-java", ], ) + +cc_test( + name = "datalog-cpp-test", + size = "small", + srcs = glob([ + "src/test/native/**/*.cpp", + "src/test/native/**/*.h", + ]), + tags = [ + "exclusive", + "no-asan", + "no-tsan", + ], + deps = [ + ":datalog.static", + "//thirdparty/googletest:googletest.static", + "//wpiutil:wpiutil-testlib", + ], +) + +wpilib_java_junit5_test( + name = "datalog-java-test", + srcs = glob(["src/test/java/**/*.java"]), + tags = ["exclusive"], + deps = [ + ":datalog-java", + "//wpiutil:wpiutil-java", + ], +) diff --git a/shared/bazel/rules/jni_rules.bzl b/shared/bazel/rules/jni_rules.bzl index 880973bb90d..dfc23dbb481 100644 --- a/shared/bazel/rules/jni_rules.bzl +++ b/shared/bazel/rules/jni_rules.bzl @@ -1,7 +1,6 @@ load("@bazel_tools//tools/cpp:toolchain_utils.bzl", "find_cpp_toolchain") load("@rules_cc//cc:defs.bzl", "cc_library") load("@rules_java//java:defs.bzl", "java_library") -load("@rules_java//java/common:java_info.bzl", "JavaInfo") def _jni_headers_impl(ctx): include_dir = ctx.actions.declare_directory(ctx.attr.name + ".h") diff --git a/wpilibc/BUILD.bazel b/wpilibc/BUILD.bazel index c11298d3d57..5feb0c97ccc 100644 --- a/wpilibc/BUILD.bazel +++ b/wpilibc/BUILD.bazel @@ -41,6 +41,7 @@ cc_library( "//cameraserver:cameraserver.static", "//cscore:cscore.static", "//hal:wpiHal.static", + "//datalog:datalog.static", "//ntcore:ntcore.static", "//wpimath:wpimath.static", "//wpinet:wpinet.static", From 5a64acde066214b42e8d6e8f73a558b0945a1973 Mon Sep 17 00:00:00 2001 From: DeltaDizzy Date: Mon, 27 Jan 2025 22:49:22 -0500 Subject: [PATCH 58/64] format wpilibc bazel --- wpilibc/BUILD.bazel | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/wpilibc/BUILD.bazel b/wpilibc/BUILD.bazel index 5feb0c97ccc..62e871af19c 100644 --- a/wpilibc/BUILD.bazel +++ b/wpilibc/BUILD.bazel @@ -40,8 +40,8 @@ cc_library( ":generated_cc_headers", "//cameraserver:cameraserver.static", "//cscore:cscore.static", - "//hal:wpiHal.static", "//datalog:datalog.static", + "//hal:wpiHal.static", "//ntcore:ntcore.static", "//wpimath:wpimath.static", "//wpinet:wpinet.static", From dfab205a54b8556965bfe4655ec1c02856b2f601 Mon Sep 17 00:00:00 2001 From: DeltaDizzy Date: Tue, 28 Jan 2025 14:39:26 -0500 Subject: [PATCH 59/64] move datalog headers to wpi/datalog --- datalog/examples/printlog/printlog.cpp | 2 +- datalog/examples/writelog/writelog.cpp | 2 +- datalog/src/main/native/cpp/DataLog.cpp | 2 +- datalog/src/main/native/cpp/DataLogBackgroundWriter.cpp | 2 +- datalog/src/main/native/cpp/DataLogReader.cpp | 4 ++-- datalog/src/main/native/cpp/DataLogReaderThread.cpp | 2 +- datalog/src/main/native/cpp/DataLogWriter.cpp | 2 +- datalog/src/main/native/cpp/FileLogger.cpp | 2 +- datalog/src/main/native/cpp/jni/DataLogJNI.cpp | 6 +++--- datalog/src/main/native/include/wpi/{ => datalog}/DataLog.h | 2 +- .../include/wpi/{ => datalog}/DataLogBackgroundWriter.h | 2 +- .../main/native/include/wpi/{ => datalog}/DataLogReader.h | 0 .../native/include/wpi/{ => datalog}/DataLogReaderThread.h | 2 +- .../main/native/include/wpi/{ => datalog}/DataLogWriter.h | 2 +- .../src/main/native/include/wpi/{ => datalog}/DataLog_c.h | 0 .../src/main/native/include/wpi/{ => datalog}/FileLogger.h | 2 +- datalog/src/test/native/cpp/DataLogTest.cpp | 2 +- datalogtool/src/main/native/cpp/Exporter.cpp | 2 +- ntcore/src/main/native/cpp/ConnectionList.h | 2 +- ntcore/src/main/native/cpp/local/LocalDataLogger.cpp | 2 +- ntcore/src/main/native/cpp/local/LocalDataLoggerEntry.h | 2 +- ntcore/src/main/native/cpp/local/LocalStorageImpl.cpp | 2 +- ntcoreffi/src/main/native/cpp/DataLogManager.cpp | 2 +- sysid/src/main/native/cpp/view/DataSelector.cpp | 4 ++-- sysid/src/main/native/cpp/view/LogLoader.cpp | 2 +- sysid/src/main/native/include/sysid/view/DataSelector.h | 2 +- wpilibc/src/main/native/cpp/DataLogManager.cpp | 4 ++-- wpilibc/src/main/native/cpp/DriverStation.cpp | 2 +- wpilibc/src/main/native/include/frc/sysid/SysIdRoutineLog.h | 2 +- 29 files changed, 32 insertions(+), 32 deletions(-) rename datalog/src/main/native/include/wpi/{ => datalog}/DataLog.h (99%) rename datalog/src/main/native/include/wpi/{ => datalog}/DataLogBackgroundWriter.h (99%) rename datalog/src/main/native/include/wpi/{ => datalog}/DataLogReader.h (100%) rename datalog/src/main/native/include/wpi/{ => datalog}/DataLogReaderThread.h (98%) rename datalog/src/main/native/include/wpi/{ => datalog}/DataLogWriter.h (98%) rename datalog/src/main/native/include/wpi/{ => datalog}/DataLog_c.h (100%) rename datalog/src/main/native/include/wpi/{ => datalog}/FileLogger.h (98%) diff --git a/datalog/examples/printlog/printlog.cpp b/datalog/examples/printlog/printlog.cpp index 68db716e2e5..c4eea6484bc 100644 --- a/datalog/examples/printlog/printlog.cpp +++ b/datalog/examples/printlog/printlog.cpp @@ -9,9 +9,9 @@ #include #include #include -#include #include #include +#include #include int main(int argc, const char** argv) { diff --git a/datalog/examples/writelog/writelog.cpp b/datalog/examples/writelog/writelog.cpp index 9546a959ef3..d6a2949282d 100644 --- a/datalog/examples/writelog/writelog.cpp +++ b/datalog/examples/writelog/writelog.cpp @@ -8,7 +8,7 @@ #include #include -#include +#include #include int main(int argc, char** argv) { diff --git a/datalog/src/main/native/cpp/DataLog.cpp b/datalog/src/main/native/cpp/DataLog.cpp index 56c0ddfa900..2d568274e7c 100644 --- a/datalog/src/main/native/cpp/DataLog.cpp +++ b/datalog/src/main/native/cpp/DataLog.cpp @@ -11,10 +11,10 @@ #include #include -#include #include #include #include +#include #include #include diff --git a/datalog/src/main/native/cpp/DataLogBackgroundWriter.cpp b/datalog/src/main/native/cpp/DataLogBackgroundWriter.cpp index 98b10609ba9..8ec2bf3b5c3 100644 --- a/datalog/src/main/native/cpp/DataLogBackgroundWriter.cpp +++ b/datalog/src/main/native/cpp/DataLogBackgroundWriter.cpp @@ -2,7 +2,7 @@ // Open Source Software; you can modify and/or share it under the terms of // the WPILib BSD license file in the root directory of this project. -#include +#include #ifndef _WIN32 #include diff --git a/datalog/src/main/native/cpp/DataLogReader.cpp b/datalog/src/main/native/cpp/DataLogReader.cpp index 5d4f1a89c4f..df0a326e3b3 100644 --- a/datalog/src/main/native/cpp/DataLogReader.cpp +++ b/datalog/src/main/native/cpp/DataLogReader.cpp @@ -5,9 +5,9 @@ #include #include -#include -#include #include +#include +#include using namespace wpi::log; diff --git a/datalog/src/main/native/cpp/DataLogReaderThread.cpp b/datalog/src/main/native/cpp/DataLogReaderThread.cpp index 766f19bca94..d045a02e678 100644 --- a/datalog/src/main/native/cpp/DataLogReaderThread.cpp +++ b/datalog/src/main/native/cpp/DataLogReaderThread.cpp @@ -5,8 +5,8 @@ #include #include -#include #include +#include #include using namespace wpi::log; diff --git a/datalog/src/main/native/cpp/DataLogWriter.cpp b/datalog/src/main/native/cpp/DataLogWriter.cpp index 4c1befea86c..65301e6b8b0 100644 --- a/datalog/src/main/native/cpp/DataLogWriter.cpp +++ b/datalog/src/main/native/cpp/DataLogWriter.cpp @@ -6,7 +6,7 @@ #include #include -#include +#include #include using namespace wpi::log; diff --git a/datalog/src/main/native/cpp/FileLogger.cpp b/datalog/src/main/native/cpp/FileLogger.cpp index 6a7dc5ced10..fc94284a0f1 100644 --- a/datalog/src/main/native/cpp/FileLogger.cpp +++ b/datalog/src/main/native/cpp/FileLogger.cpp @@ -16,8 +16,8 @@ #include #include -#include #include +#include namespace wpi { FileLogger::FileLogger(std::string_view file, diff --git a/datalog/src/main/native/cpp/jni/DataLogJNI.cpp b/datalog/src/main/native/cpp/jni/DataLogJNI.cpp index e50258e1543..1a012f8fad4 100644 --- a/datalog/src/main/native/cpp/jni/DataLogJNI.cpp +++ b/datalog/src/main/native/cpp/jni/DataLogJNI.cpp @@ -11,10 +11,10 @@ #include #include -#include -#include -#include #include +#include +#include +#include #include #include "edu_wpi_first_datalog_DataLogJNI.h" diff --git a/datalog/src/main/native/include/wpi/DataLog.h b/datalog/src/main/native/include/wpi/datalog/DataLog.h similarity index 99% rename from datalog/src/main/native/include/wpi/DataLog.h rename to datalog/src/main/native/include/wpi/datalog/DataLog.h index 2b42ad627eb..86db41d7e2a 100644 --- a/datalog/src/main/native/include/wpi/DataLog.h +++ b/datalog/src/main/native/include/wpi/datalog/DataLog.h @@ -19,10 +19,10 @@ #include #include -#include #include #include #include +#include #include #include #include diff --git a/datalog/src/main/native/include/wpi/DataLogBackgroundWriter.h b/datalog/src/main/native/include/wpi/datalog/DataLogBackgroundWriter.h similarity index 99% rename from datalog/src/main/native/include/wpi/DataLogBackgroundWriter.h rename to datalog/src/main/native/include/wpi/datalog/DataLogBackgroundWriter.h index ebf024e6659..c1662bf9fde 100644 --- a/datalog/src/main/native/include/wpi/DataLogBackgroundWriter.h +++ b/datalog/src/main/native/include/wpi/datalog/DataLogBackgroundWriter.h @@ -12,8 +12,8 @@ #include #include -#include #include +#include #include namespace wpi { diff --git a/datalog/src/main/native/include/wpi/DataLogReader.h b/datalog/src/main/native/include/wpi/datalog/DataLogReader.h similarity index 100% rename from datalog/src/main/native/include/wpi/DataLogReader.h rename to datalog/src/main/native/include/wpi/datalog/DataLogReader.h diff --git a/datalog/src/main/native/include/wpi/DataLogReaderThread.h b/datalog/src/main/native/include/wpi/datalog/DataLogReaderThread.h similarity index 98% rename from datalog/src/main/native/include/wpi/DataLogReaderThread.h rename to datalog/src/main/native/include/wpi/datalog/DataLogReaderThread.h index 33fa8771966..51eb837302e 100644 --- a/datalog/src/main/native/include/wpi/DataLogReaderThread.h +++ b/datalog/src/main/native/include/wpi/datalog/DataLogReaderThread.h @@ -13,9 +13,9 @@ #include #include -#include #include #include +#include #include #include diff --git a/datalog/src/main/native/include/wpi/DataLogWriter.h b/datalog/src/main/native/include/wpi/datalog/DataLogWriter.h similarity index 98% rename from datalog/src/main/native/include/wpi/DataLogWriter.h rename to datalog/src/main/native/include/wpi/datalog/DataLogWriter.h index b9c7c9551e1..189584c6cac 100644 --- a/datalog/src/main/native/include/wpi/DataLogWriter.h +++ b/datalog/src/main/native/include/wpi/datalog/DataLogWriter.h @@ -8,7 +8,7 @@ #include #include -#include +#include namespace wpi { class raw_ostream; diff --git a/datalog/src/main/native/include/wpi/DataLog_c.h b/datalog/src/main/native/include/wpi/datalog/DataLog_c.h similarity index 100% rename from datalog/src/main/native/include/wpi/DataLog_c.h rename to datalog/src/main/native/include/wpi/datalog/DataLog_c.h diff --git a/datalog/src/main/native/include/wpi/FileLogger.h b/datalog/src/main/native/include/wpi/datalog/FileLogger.h similarity index 98% rename from datalog/src/main/native/include/wpi/FileLogger.h rename to datalog/src/main/native/include/wpi/datalog/FileLogger.h index 4fe1c7f638d..1e5be5b9dab 100644 --- a/datalog/src/main/native/include/wpi/FileLogger.h +++ b/datalog/src/main/native/include/wpi/datalog/FileLogger.h @@ -8,7 +8,7 @@ #include #include -#include +#include namespace wpi { /** diff --git a/datalog/src/test/native/cpp/DataLogTest.cpp b/datalog/src/test/native/cpp/DataLogTest.cpp index d8b71f4a7e7..8c2aecc10f7 100644 --- a/datalog/src/test/native/cpp/DataLogTest.cpp +++ b/datalog/src/test/native/cpp/DataLogTest.cpp @@ -8,8 +8,8 @@ #include #include -#include #include +#include #include namespace { diff --git a/datalogtool/src/main/native/cpp/Exporter.cpp b/datalogtool/src/main/native/cpp/Exporter.cpp index d0b85d7a92b..eacee16d1e0 100644 --- a/datalogtool/src/main/native/cpp/Exporter.cpp +++ b/datalogtool/src/main/native/cpp/Exporter.cpp @@ -24,7 +24,7 @@ #include #include #include -#include +#include #include #include #include diff --git a/ntcore/src/main/native/cpp/ConnectionList.h b/ntcore/src/main/native/cpp/ConnectionList.h index c46266d5c18..1677d75c32f 100644 --- a/ntcore/src/main/native/cpp/ConnectionList.h +++ b/ntcore/src/main/native/cpp/ConnectionList.h @@ -13,7 +13,7 @@ #include #include -#include +#include #include #include diff --git a/ntcore/src/main/native/cpp/local/LocalDataLogger.cpp b/ntcore/src/main/native/cpp/local/LocalDataLogger.cpp index 121c99ab39b..6e39ab1d8a7 100644 --- a/ntcore/src/main/native/cpp/local/LocalDataLogger.cpp +++ b/ntcore/src/main/native/cpp/local/LocalDataLogger.cpp @@ -5,7 +5,7 @@ #include "LocalDataLogger.h" #include -#include +#include #include using namespace nt::local; diff --git a/ntcore/src/main/native/cpp/local/LocalDataLoggerEntry.h b/ntcore/src/main/native/cpp/local/LocalDataLoggerEntry.h index 53ff480b19b..0d86ea893c3 100644 --- a/ntcore/src/main/native/cpp/local/LocalDataLoggerEntry.h +++ b/ntcore/src/main/native/cpp/local/LocalDataLoggerEntry.h @@ -9,7 +9,7 @@ #include #include -#include +#include #include "ntcore_c.h" diff --git a/ntcore/src/main/native/cpp/local/LocalStorageImpl.cpp b/ntcore/src/main/native/cpp/local/LocalStorageImpl.cpp index 60a03c1c77c..01a9805e7ec 100644 --- a/ntcore/src/main/native/cpp/local/LocalStorageImpl.cpp +++ b/ntcore/src/main/native/cpp/local/LocalStorageImpl.cpp @@ -11,7 +11,7 @@ #include #include -#include +#include #include #include diff --git a/ntcoreffi/src/main/native/cpp/DataLogManager.cpp b/ntcoreffi/src/main/native/cpp/DataLogManager.cpp index d758c02a2ac..50a7a33eb08 100644 --- a/ntcoreffi/src/main/native/cpp/DataLogManager.cpp +++ b/ntcoreffi/src/main/native/cpp/DataLogManager.cpp @@ -13,7 +13,7 @@ #include #include #include -#include +#include #include #include #include diff --git a/sysid/src/main/native/cpp/view/DataSelector.cpp b/sysid/src/main/native/cpp/view/DataSelector.cpp index 7d8d8e572a6..16a467020e7 100644 --- a/sysid/src/main/native/cpp/view/DataSelector.cpp +++ b/sysid/src/main/native/cpp/view/DataSelector.cpp @@ -11,8 +11,8 @@ #include #include -#include -#include +#include +#include #include #include diff --git a/sysid/src/main/native/cpp/view/LogLoader.cpp b/sysid/src/main/native/cpp/view/LogLoader.cpp index 3289dea28ed..bfe9bd91e8b 100644 --- a/sysid/src/main/native/cpp/view/LogLoader.cpp +++ b/sysid/src/main/native/cpp/view/LogLoader.cpp @@ -15,7 +15,7 @@ #include #include #include -#include +#include #include #include #include diff --git a/sysid/src/main/native/include/sysid/view/DataSelector.h b/sysid/src/main/native/include/sysid/view/DataSelector.h index 60ba2da5b82..a4e01cd0fcd 100644 --- a/sysid/src/main/native/include/sysid/view/DataSelector.h +++ b/sysid/src/main/native/include/sysid/view/DataSelector.h @@ -12,7 +12,7 @@ #include #include -#include +#include #include #include "sysid/analysis/Storage.h" diff --git a/wpilibc/src/main/native/cpp/DataLogManager.cpp b/wpilibc/src/main/native/cpp/DataLogManager.cpp index 92035eb74b8..91998e542ff 100644 --- a/wpilibc/src/main/native/cpp/DataLogManager.cpp +++ b/wpilibc/src/main/native/cpp/DataLogManager.cpp @@ -15,8 +15,8 @@ #include #include #include -#include -#include +#include +#include #include #include #include diff --git a/wpilibc/src/main/native/cpp/DriverStation.cpp b/wpilibc/src/main/native/cpp/DriverStation.cpp index 6318c8899e8..744d1b271bc 100644 --- a/wpilibc/src/main/native/cpp/DriverStation.cpp +++ b/wpilibc/src/main/native/cpp/DriverStation.cpp @@ -23,7 +23,7 @@ #include #include #include -#include +#include #include #include #include diff --git a/wpilibc/src/main/native/include/frc/sysid/SysIdRoutineLog.h b/wpilibc/src/main/native/include/frc/sysid/SysIdRoutineLog.h index 5e727169068..9d53847e6b9 100644 --- a/wpilibc/src/main/native/include/frc/sysid/SysIdRoutineLog.h +++ b/wpilibc/src/main/native/include/frc/sysid/SysIdRoutineLog.h @@ -15,7 +15,7 @@ #include #include #include -#include +#include namespace frc::sysid { From 90249d0663bde4ea1d3091a11e8079e1dc33d43c Mon Sep 17 00:00:00 2001 From: DeltaDizzy Date: Fri, 31 Jan 2025 11:52:45 -0500 Subject: [PATCH 60/64] file file logger test includes --- datalog/src/test/native/cpp/FileLoggerTest.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/datalog/src/test/native/cpp/FileLoggerTest.cpp b/datalog/src/test/native/cpp/FileLoggerTest.cpp index a60316ad805..c9dc63c3d89 100644 --- a/datalog/src/test/native/cpp/FileLoggerTest.cpp +++ b/datalog/src/test/native/cpp/FileLoggerTest.cpp @@ -7,7 +7,7 @@ #include #include -#include +#include TEST(FileLoggerTest, BufferSingleLine) { std::vector buf; From 5a5416f0aaa65a2e7ec81877fb378db129bf633f Mon Sep 17 00:00:00 2001 From: DeltaDizzy Date: Fri, 31 Jan 2025 17:51:10 -0500 Subject: [PATCH 61/64] fix jni includes --- datalog/src/main/native/cpp/jni/DataLogJNI.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/datalog/src/main/native/cpp/jni/DataLogJNI.cpp b/datalog/src/main/native/cpp/jni/DataLogJNI.cpp index 1a012f8fad4..07e043c6551 100644 --- a/datalog/src/main/native/cpp/jni/DataLogJNI.cpp +++ b/datalog/src/main/native/cpp/jni/DataLogJNI.cpp @@ -11,7 +11,7 @@ #include #include -#include +#include #include #include #include From 96bcf877517fe45cca9cc1df0d635e0b309ab33e Mon Sep 17 00:00:00 2001 From: DeltaDizzy Date: Fri, 31 Jan 2025 18:21:23 -0500 Subject: [PATCH 62/64] filelogger namespaces --- datalog/src/main/native/cpp/FileLogger.cpp | 2 +- datalog/src/main/native/cpp/jni/DataLogJNI.cpp | 4 ++-- .../src/main/native/include/wpi/datalog/FileLogger.h | 2 +- datalog/src/test/native/cpp/FileLoggerTest.cpp | 10 +++++----- ntcoreffi/src/main/native/cpp/DataLogManager.cpp | 2 +- wpilibc/src/main/native/cpp/DataLogManager.cpp | 4 ++-- 6 files changed, 12 insertions(+), 12 deletions(-) diff --git a/datalog/src/main/native/cpp/FileLogger.cpp b/datalog/src/main/native/cpp/FileLogger.cpp index fc94284a0f1..e05a14671d6 100644 --- a/datalog/src/main/native/cpp/FileLogger.cpp +++ b/datalog/src/main/native/cpp/FileLogger.cpp @@ -19,7 +19,7 @@ #include #include -namespace wpi { +namespace wpi::log { FileLogger::FileLogger(std::string_view file, std::function callback) #ifdef __linux__ diff --git a/datalog/src/main/native/cpp/jni/DataLogJNI.cpp b/datalog/src/main/native/cpp/jni/DataLogJNI.cpp index 07e043c6551..5af58101db4 100644 --- a/datalog/src/main/native/cpp/jni/DataLogJNI.cpp +++ b/datalog/src/main/native/cpp/jni/DataLogJNI.cpp @@ -708,7 +708,7 @@ Java_edu_wpi_first_datalog_DataLogJNI_createFileLogger return 0; } return reinterpret_cast( - new wpi::FileLogger{JStringRef{env, file}, *f, JStringRef{env, key}}); + new wpi::log::FileLogger{JStringRef{env, file}, *f, JStringRef{env, key}}); } /* @@ -720,6 +720,6 @@ JNIEXPORT void JNICALL Java_edu_wpi_first_datalog_DataLogJNI_freeFileLogger (JNIEnv* env, jclass, jlong fileTail) { - delete reinterpret_cast(fileTail); + delete reinterpret_cast(fileTail); } } // extern "C" diff --git a/datalog/src/main/native/include/wpi/datalog/FileLogger.h b/datalog/src/main/native/include/wpi/datalog/FileLogger.h index 1e5be5b9dab..7089d1fc070 100644 --- a/datalog/src/main/native/include/wpi/datalog/FileLogger.h +++ b/datalog/src/main/native/include/wpi/datalog/FileLogger.h @@ -10,7 +10,7 @@ #include -namespace wpi { +namespace wpi::log { /** * A class version of `tail -f`, otherwise known as `tail -f` at home. Watches * a file and puts the data somewhere else. Only works on Linux-based platforms. diff --git a/datalog/src/test/native/cpp/FileLoggerTest.cpp b/datalog/src/test/native/cpp/FileLoggerTest.cpp index c9dc63c3d89..b0db3a9c4af 100644 --- a/datalog/src/test/native/cpp/FileLoggerTest.cpp +++ b/datalog/src/test/native/cpp/FileLoggerTest.cpp @@ -11,7 +11,7 @@ TEST(FileLoggerTest, BufferSingleLine) { std::vector buf; - auto func = wpi::FileLogger::Buffer( + auto func = wpi::log::FileLogger::Buffer( [&buf](std::string_view line) { buf.emplace_back(line); }); func("qwertyuiop\n"); EXPECT_EQ("qwertyuiop", buf[0]); @@ -19,7 +19,7 @@ TEST(FileLoggerTest, BufferSingleLine) { TEST(FileLoggerTest, BufferMultiLine) { std::vector buf; - auto func = wpi::FileLogger::Buffer( + auto func = wpi::log::FileLogger::Buffer( [&buf](std::string_view line) { buf.emplace_back(line); }); func("line 1\nline 2\nline 3\n"); EXPECT_EQ("line 1\nline 2\nline 3", buf[0]); @@ -27,7 +27,7 @@ TEST(FileLoggerTest, BufferMultiLine) { TEST(FileLoggerTest, BufferPartials) { std::vector buf; - auto func = wpi::FileLogger::Buffer( + auto func = wpi::log::FileLogger::Buffer( [&buf](std::string_view line) { buf.emplace_back(line); }); func("part 1"); func("part 2\npart 3"); @@ -38,7 +38,7 @@ TEST(FileLoggerTest, BufferPartials) { TEST(FileLoggerTest, BufferMultiplePartials) { std::vector buf; - auto func = wpi::FileLogger::Buffer( + auto func = wpi::log::FileLogger::Buffer( [&buf](std::string_view line) { buf.emplace_back(line); }); func("part 1"); func("part 2"); @@ -48,7 +48,7 @@ TEST(FileLoggerTest, BufferMultiplePartials) { } TEST(FileLoggerTest, BufferMultipleMultiLinePartials) { std::vector buf; - auto func = wpi::FileLogger::Buffer( + auto func = wpi::log::FileLogger::Buffer( [&buf](std::string_view line) { buf.emplace_back(line); }); func("part 1"); func("part 2\npart 3"); diff --git a/ntcoreffi/src/main/native/cpp/DataLogManager.cpp b/ntcoreffi/src/main/native/cpp/DataLogManager.cpp index 50a7a33eb08..5f1a0899d60 100644 --- a/ntcoreffi/src/main/native/cpp/DataLogManager.cpp +++ b/ntcoreffi/src/main/native/cpp/DataLogManager.cpp @@ -202,7 +202,7 @@ struct Thread final : public wpi::SafeThread { NT_DataLogger m_ntEntryLogger = 0; NT_ConnectionDataLogger m_ntConnLogger = 0; bool m_consoleLoggerEnabled = false; - wpi::FileLogger m_consoleLogger; + wpi::log::FileLogger m_consoleLogger; wpi::log::StringLogEntry m_messageLog; }; diff --git a/wpilibc/src/main/native/cpp/DataLogManager.cpp b/wpilibc/src/main/native/cpp/DataLogManager.cpp index 91998e542ff..60da8f972b6 100644 --- a/wpilibc/src/main/native/cpp/DataLogManager.cpp +++ b/wpilibc/src/main/native/cpp/DataLogManager.cpp @@ -17,7 +17,7 @@ #include #include #include -#include +#include #include #include #include @@ -51,7 +51,7 @@ struct Thread final : public wpi::SafeThread { NT_DataLogger m_ntEntryLogger = 0; NT_ConnectionDataLogger m_ntConnLogger = 0; bool m_consoleLoggerEnabled = false; - wpi::FileLogger m_consoleLogger; + wpi::log::FileLogger m_consoleLogger; wpi::log::StringLogEntry m_messageLog; }; From a3fe6e8fc0f6c1edfa7e1f76874387165dd0a440 Mon Sep 17 00:00:00 2001 From: DeltaDizzy Date: Fri, 31 Jan 2025 19:06:26 -0500 Subject: [PATCH 63/64] run wpiformat --- datalog/src/main/native/cpp/FileLogger.cpp | 2 +- datalog/src/main/native/cpp/jni/DataLogJNI.cpp | 6 +++--- datalog/src/main/native/include/wpi/datalog/FileLogger.h | 2 +- datalogtool/src/main/native/cpp/Exporter.cpp | 2 +- ntcore/src/main/native/cpp/ConnectionList.h | 2 +- ntcore/src/main/native/cpp/local/LocalDataLogger.cpp | 2 +- ntcore/src/main/native/cpp/local/LocalStorageImpl.cpp | 2 +- ntcoreffi/src/main/native/cpp/DataLogManager.cpp | 2 +- sysid/src/main/native/cpp/view/DataSelector.cpp | 4 ++-- sysid/src/main/native/cpp/view/LogLoader.cpp | 2 +- sysid/src/main/native/include/sysid/view/DataSelector.h | 2 +- wpilibc/src/main/native/cpp/DataLogManager.cpp | 4 ++-- wpilibc/src/main/native/cpp/DriverStation.cpp | 2 +- 13 files changed, 17 insertions(+), 17 deletions(-) diff --git a/datalog/src/main/native/cpp/FileLogger.cpp b/datalog/src/main/native/cpp/FileLogger.cpp index e05a14671d6..c535b857d9c 100644 --- a/datalog/src/main/native/cpp/FileLogger.cpp +++ b/datalog/src/main/native/cpp/FileLogger.cpp @@ -99,4 +99,4 @@ std::function FileLogger::Buffer( buf.append(leftover.begin(), leftover.end()); }; } -} // namespace wpi +} // namespace wpi::log diff --git a/datalog/src/main/native/cpp/jni/DataLogJNI.cpp b/datalog/src/main/native/cpp/jni/DataLogJNI.cpp index 5af58101db4..272689302b8 100644 --- a/datalog/src/main/native/cpp/jni/DataLogJNI.cpp +++ b/datalog/src/main/native/cpp/jni/DataLogJNI.cpp @@ -11,10 +11,10 @@ #include #include -#include #include #include #include +#include #include #include "edu_wpi_first_datalog_DataLogJNI.h" @@ -707,8 +707,8 @@ Java_edu_wpi_first_datalog_DataLogJNI_createFileLogger wpi::ThrowNullPointerException(env, "key is null"); return 0; } - return reinterpret_cast( - new wpi::log::FileLogger{JStringRef{env, file}, *f, JStringRef{env, key}}); + return reinterpret_cast(new wpi::log::FileLogger{ + JStringRef{env, file}, *f, JStringRef{env, key}}); } /* diff --git a/datalog/src/main/native/include/wpi/datalog/FileLogger.h b/datalog/src/main/native/include/wpi/datalog/FileLogger.h index 7089d1fc070..38dbab4c99e 100644 --- a/datalog/src/main/native/include/wpi/datalog/FileLogger.h +++ b/datalog/src/main/native/include/wpi/datalog/FileLogger.h @@ -58,4 +58,4 @@ class FileLogger { std::thread m_thread; #endif }; -} // namespace wpi +} // namespace wpi::log diff --git a/datalogtool/src/main/native/cpp/Exporter.cpp b/datalogtool/src/main/native/cpp/Exporter.cpp index eacee16d1e0..2cf399b71c2 100644 --- a/datalogtool/src/main/native/cpp/Exporter.cpp +++ b/datalogtool/src/main/native/cpp/Exporter.cpp @@ -24,12 +24,12 @@ #include #include #include -#include #include #include #include #include #include +#include #include #include #include diff --git a/ntcore/src/main/native/cpp/ConnectionList.h b/ntcore/src/main/native/cpp/ConnectionList.h index 1677d75c32f..6551ee468c5 100644 --- a/ntcore/src/main/native/cpp/ConnectionList.h +++ b/ntcore/src/main/native/cpp/ConnectionList.h @@ -13,8 +13,8 @@ #include #include -#include #include +#include #include #include "Handle.h" diff --git a/ntcore/src/main/native/cpp/local/LocalDataLogger.cpp b/ntcore/src/main/native/cpp/local/LocalDataLogger.cpp index 6e39ab1d8a7..3ae62f60b18 100644 --- a/ntcore/src/main/native/cpp/local/LocalDataLogger.cpp +++ b/ntcore/src/main/native/cpp/local/LocalDataLogger.cpp @@ -5,8 +5,8 @@ #include "LocalDataLogger.h" #include -#include #include +#include using namespace nt::local; diff --git a/ntcore/src/main/native/cpp/local/LocalStorageImpl.cpp b/ntcore/src/main/native/cpp/local/LocalStorageImpl.cpp index 01a9805e7ec..fd00bc9aa68 100644 --- a/ntcore/src/main/native/cpp/local/LocalStorageImpl.cpp +++ b/ntcore/src/main/native/cpp/local/LocalStorageImpl.cpp @@ -11,9 +11,9 @@ #include #include -#include #include #include +#include #include "IListenerStorage.h" #include "Log.h" diff --git a/ntcoreffi/src/main/native/cpp/DataLogManager.cpp b/ntcoreffi/src/main/native/cpp/DataLogManager.cpp index 5f1a0899d60..3ae2f39afd7 100644 --- a/ntcoreffi/src/main/native/cpp/DataLogManager.cpp +++ b/ntcoreffi/src/main/native/cpp/DataLogManager.cpp @@ -13,10 +13,10 @@ #include #include #include -#include #include #include #include +#include #include #include diff --git a/sysid/src/main/native/cpp/view/DataSelector.cpp b/sysid/src/main/native/cpp/view/DataSelector.cpp index 16a467020e7..17b2ab27e2e 100644 --- a/sysid/src/main/native/cpp/view/DataSelector.cpp +++ b/sysid/src/main/native/cpp/view/DataSelector.cpp @@ -11,10 +11,10 @@ #include #include -#include -#include #include #include +#include +#include #include "sysid/Util.h" #include "sysid/analysis/AnalysisType.h" diff --git a/sysid/src/main/native/cpp/view/LogLoader.cpp b/sysid/src/main/native/cpp/view/LogLoader.cpp index bfe9bd91e8b..b21bea46158 100644 --- a/sysid/src/main/native/cpp/view/LogLoader.cpp +++ b/sysid/src/main/native/cpp/view/LogLoader.cpp @@ -15,10 +15,10 @@ #include #include #include -#include #include #include #include +#include #include using namespace sysid; diff --git a/sysid/src/main/native/include/sysid/view/DataSelector.h b/sysid/src/main/native/include/sysid/view/DataSelector.h index a4e01cd0fcd..1020bc563a4 100644 --- a/sysid/src/main/native/include/sysid/view/DataSelector.h +++ b/sysid/src/main/native/include/sysid/view/DataSelector.h @@ -12,8 +12,8 @@ #include #include -#include #include +#include #include "sysid/analysis/Storage.h" diff --git a/wpilibc/src/main/native/cpp/DataLogManager.cpp b/wpilibc/src/main/native/cpp/DataLogManager.cpp index 60da8f972b6..2a671366902 100644 --- a/wpilibc/src/main/native/cpp/DataLogManager.cpp +++ b/wpilibc/src/main/native/cpp/DataLogManager.cpp @@ -15,11 +15,11 @@ #include #include #include +#include +#include #include #include #include -#include -#include #include #include #include diff --git a/wpilibc/src/main/native/cpp/DriverStation.cpp b/wpilibc/src/main/native/cpp/DriverStation.cpp index 744d1b271bc..001f6ff81f1 100644 --- a/wpilibc/src/main/native/cpp/DriverStation.cpp +++ b/wpilibc/src/main/native/cpp/DriverStation.cpp @@ -23,9 +23,9 @@ #include #include #include -#include #include #include +#include #include #include #include From ac28657ce320f848233ff142b899b42199125179 Mon Sep 17 00:00:00 2001 From: DeltaDizzy Date: Fri, 31 Jan 2025 19:26:49 -0500 Subject: [PATCH 64/64] last include --- ntcoreffi/src/main/native/cpp/DataLogManager.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/ntcoreffi/src/main/native/cpp/DataLogManager.cpp b/ntcoreffi/src/main/native/cpp/DataLogManager.cpp index 3ae2f39afd7..96377feef2c 100644 --- a/ntcoreffi/src/main/native/cpp/DataLogManager.cpp +++ b/ntcoreffi/src/main/native/cpp/DataLogManager.cpp @@ -13,10 +13,10 @@ #include #include #include -#include #include #include #include +#include #include #include