Skip to content

Commit

Permalink
[ntcore] Refactor local topic
Browse files Browse the repository at this point in the history
  • Loading branch information
PeterJohnson committed Nov 2, 2024
1 parent c76ad73 commit bc37c6c
Show file tree
Hide file tree
Showing 9 changed files with 308 additions and 213 deletions.
8 changes: 4 additions & 4 deletions ntcore/src/main/native/cpp/LocalStorage.h
Original file line number Diff line number Diff line change
Expand Up @@ -134,7 +134,7 @@ class LocalStorage final : public net::ILocalStorage {
bool GetTopicPersistent(NT_Topic topicHandle) {
std::scoped_lock lock{m_mutex};
if (auto topic = m_impl.GetTopicByHandle(topicHandle)) {
return (topic->flags & NT_PERSISTENT) != 0;
return (topic->GetFlags() & NT_PERSISTENT) != 0;
} else {
return false;
}
Expand All @@ -150,7 +150,7 @@ class LocalStorage final : public net::ILocalStorage {
bool GetTopicRetained(NT_Topic topicHandle) {
std::scoped_lock lock{m_mutex};
if (auto topic = m_impl.GetTopicByHandle(topicHandle)) {
return (topic->flags & NT_RETAINED) != 0;
return (topic->GetFlags() & NT_RETAINED) != 0;
} else {
return false;
}
Expand All @@ -166,7 +166,7 @@ class LocalStorage final : public net::ILocalStorage {
bool GetTopicCached(NT_Topic topicHandle) {
std::scoped_lock lock{m_mutex};
if (auto topic = m_impl.GetTopicByHandle(topicHandle)) {
return (topic->flags & NT_UNCACHED) == 0;
return (topic->GetFlags() & NT_UNCACHED) == 0;
} else {
return false;
}
Expand Down Expand Up @@ -392,7 +392,7 @@ class LocalStorage final : public net::ILocalStorage {
unsigned int GetEntryFlags(NT_Entry entryHandle) {
std::scoped_lock lock{m_mutex};
if (auto entry = m_impl.GetEntryByHandle(entryHandle)) {
return entry->subscriber->topic->flags;
return entry->subscriber->topic->GetFlags();
} else {
return 0;
}
Expand Down
15 changes: 5 additions & 10 deletions ntcore/src/main/native/cpp/local/LocalDataLogger.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -8,22 +8,17 @@
#include <wpi/DataLog.h>
#include <wpi/StringExtras.h>

#include "local/LocalDataLoggerEntry.h"
#include "local/LocalTopic.h"

using namespace nt::local;

int LocalDataLogger::Start(LocalTopic* topic, int64_t time) {
std::string_view typeStr = topic->typeStr;
int LocalDataLogger::Start(std::string_view name, std::string_view typeStr,
std::string_view metadata, int64_t time) {
// NT and DataLog use different standard representations for int and int[]
if (typeStr == "int") {
typeStr = "int64";
} else if (typeStr == "int[]") {
typeStr = "int64[]";
}
return log.Start(
fmt::format(
"{}{}", logPrefix,
wpi::remove_prefix(topic->name, prefix).value_or(topic->name)),
typeStr, LocalDataLoggerEntry::MakeMetadata(topic->propertiesStr), time);
return log.Start(fmt::format("{}{}", logPrefix,
wpi::remove_prefix(name, prefix).value_or(name)),
typeStr, metadata, time);
}
3 changes: 2 additions & 1 deletion ntcore/src/main/native/cpp/local/LocalDataLogger.h
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,8 @@ struct LocalDataLogger {
std::string_view prefix, std::string_view logPrefix)
: handle{handle}, log{log}, prefix{prefix}, logPrefix{logPrefix} {}

int Start(LocalTopic* topic, int64_t time);
int Start(std::string_view name, std::string_view typeStr,
std::string_view metadata, int64_t time);

NT_DataLogger handle;
wpi::log::DataLog& log;
Expand Down
1 change: 0 additions & 1 deletion ntcore/src/main/native/cpp/local/LocalDataLoggerEntry.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,6 @@
#include <string_view>

#include <fmt/format.h>
#include <wpi/DataLog.h>
#include <wpi/StringExtras.h>

#include "networktables/NetworkTableValue.h"
Expand Down
8 changes: 8 additions & 0 deletions ntcore/src/main/native/cpp/local/LocalDataLoggerEntry.h
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,13 @@

#pragma once

#include <stdint.h>

#include <string>
#include <string_view>

#include <wpi/DataLog.h>

#include "ntcore_c.h"

namespace wpi::log {
Expand All @@ -28,6 +32,10 @@ struct LocalDataLoggerEntry {
static std::string MakeMetadata(std::string_view properties);

void Append(const Value& v);
void Finish(int64_t timestamp) { log->Finish(entry, timestamp); }
void SetMetadata(std::string_view metadata, int64_t timestamp) {
log->SetMetadata(entry, metadata, timestamp);
}

wpi::log::DataLog* log;
int entry;
Expand Down
Loading

0 comments on commit bc37c6c

Please sign in to comment.