Skip to content

Commit 405791b

Browse files
committed
Move datalog backend to datalog library
1 parent 7455343 commit 405791b

File tree

2 files changed

+35
-45
lines changed

2 files changed

+35
-45
lines changed

wpiutil/src/main/native/cpp/datalog/DataLogTelemetryBackend.cpp renamed to datalog/src/main/native/cpp/DataLogTelemetryBackend.cpp

Lines changed: 26 additions & 34 deletions
Original file line numberDiff line numberDiff line change
@@ -10,16 +10,16 @@
1010
#include <variant>
1111

1212
#include <fmt/format.h>
13+
#include <wpi/mutex.h>
14+
#include <wpi/telemetry/TelemetryEntry.h>
1315

14-
#include "wpi/mutex.h"
15-
#include "wpi/telemetry/TelemetryEntry.h"
16-
#include "wpi/DataLog.h"
16+
#include "wpi/datalog/DataLog.h"
1717

18-
using namespace wpi;
18+
using namespace wpi::log;
1919

20-
class DataLogTelemetryBackend::Entry : public TelemetryEntry {
20+
class DataLogTelemetryBackend::Entry : public wpi::TelemetryEntry {
2121
public:
22-
Entry(wpi::log::DataLog& log, std::string_view prefix, std::string_view path)
22+
Entry(DataLog& log, std::string_view prefix, std::string_view path)
2323
: m_log{log}, m_path{fmt::format("{}{}", prefix, path)} {}
2424

2525
void KeepDuplicates() override { m_keepDuplicates = true; }
@@ -70,30 +70,24 @@ class DataLogTelemetryBackend::Entry : public TelemetryEntry {
7070
}
7171
}
7272

73-
void LogBoolean(bool value) override {
74-
Log<wpi::log::BooleanLogEntry>(value);
75-
}
73+
void LogBoolean(bool value) override { Log<BooleanLogEntry>(value); }
7674

77-
void LogInt64(int64_t value) override {
78-
Log<wpi::log::IntegerLogEntry>(value);
79-
}
75+
void LogInt64(int64_t value) override { Log<IntegerLogEntry>(value); }
8076

81-
void LogFloat(float value) override { Log<wpi::log::FloatLogEntry>(value); }
77+
void LogFloat(float value) override { Log<FloatLogEntry>(value); }
8278

83-
void LogDouble(double value) override {
84-
Log<wpi::log::DoubleLogEntry>(value);
85-
}
79+
void LogDouble(double value) override { Log<DoubleLogEntry>(value); }
8680

8781
void LogString(std::string_view value, std::string_view typeString) override {
88-
LogTypeString<wpi::log::StringLogEntry>(value, typeString);
82+
LogTypeString<StringLogEntry>(value, typeString);
8983
}
9084

9185
void LogBooleanArray(std::span<const bool> value) override {
92-
Log<wpi::log::BooleanArrayLogEntry>(value);
86+
Log<BooleanArrayLogEntry>(value);
9387
}
9488

9589
void LogBooleanArray(std::span<const int> value) override {
96-
Log<wpi::log::BooleanArrayLogEntry>(value);
90+
Log<BooleanArrayLogEntry>(value);
9791
}
9892

9993
void LogInt16Array(std::span<const int16_t> value) override {
@@ -105,54 +99,52 @@ class DataLogTelemetryBackend::Entry : public TelemetryEntry {
10599
}
106100

107101
void LogInt64Array(std::span<const int64_t> value) override {
108-
Log<wpi::log::IntegerArrayLogEntry>(value);
102+
Log<IntegerArrayLogEntry>(value);
109103
}
110104

111105
void LogFloatArray(std::span<const float> value) override {
112-
Log<wpi::log::FloatArrayLogEntry>(value);
106+
Log<FloatArrayLogEntry>(value);
113107
}
114108

115109
void LogDoubleArray(std::span<const double> value) override {
116-
Log<wpi::log::DoubleArrayLogEntry>(value);
110+
Log<DoubleArrayLogEntry>(value);
117111
}
118112

119113
void LogStringArray(std::span<const std::string> value) override {
120-
Log<wpi::log::StringArrayLogEntry>(value);
114+
Log<StringArrayLogEntry>(value);
121115
}
122116

123117
void LogStringArray(std::span<const std::string_view> value) override {
124-
Log<wpi::log::StringArrayLogEntry>(value);
118+
Log<StringArrayLogEntry>(value);
125119
}
126120

127121
void LogRaw(std::span<const uint8_t> value,
128122
std::string_view typeString) override {
129-
LogTypeString<wpi::log::RawLogEntry>(value, typeString);
123+
LogTypeString<RawLogEntry>(value, typeString);
130124
}
131125

132126
private:
133-
wpi::log::DataLog& m_log;
127+
DataLog& m_log;
134128
std::string m_path;
135129
wpi::mutex m_mutex;
136-
std::variant<std::monostate, wpi::log::BooleanLogEntry,
137-
wpi::log::IntegerLogEntry, wpi::log::FloatLogEntry,
138-
wpi::log::DoubleLogEntry, wpi::log::StringLogEntry,
139-
wpi::log::BooleanArrayLogEntry, wpi::log::IntegerArrayLogEntry,
140-
wpi::log::FloatArrayLogEntry, wpi::log::DoubleArrayLogEntry,
141-
wpi::log::StringArrayLogEntry, wpi::log::RawLogEntry>
130+
std::variant<std::monostate, BooleanLogEntry, IntegerLogEntry, FloatLogEntry,
131+
DoubleLogEntry, StringLogEntry, BooleanArrayLogEntry,
132+
IntegerArrayLogEntry, FloatArrayLogEntry, DoubleArrayLogEntry,
133+
StringArrayLogEntry, RawLogEntry>
142134
m_entry;
143135
std::string m_typeString;
144136
std::atomic_bool m_keepDuplicates{false};
145137
wpi::StringMap<std::string> m_propertiesMap;
146138
std::string m_properties = "{}";
147139
};
148140

149-
DataLogTelemetryBackend::DataLogTelemetryBackend(wpi::log::DataLog& log,
141+
DataLogTelemetryBackend::DataLogTelemetryBackend(DataLog& log,
150142
std::string_view prefix)
151143
: m_log{log}, m_prefix{prefix} {}
152144

153145
DataLogTelemetryBackend::~DataLogTelemetryBackend() = default;
154146

155-
TelemetryEntry& DataLogTelemetryBackend::GetEntry(std::string_view path) {
147+
wpi::TelemetryEntry& DataLogTelemetryBackend::GetEntry(std::string_view path) {
156148
std::scoped_lock lock{m_mutex};
157149
return m_entries.try_emplace(path, m_log, m_prefix, path).first->second;
158150
}

wpiutil/src/main/native/include/wpi/datalog/DataLogTelemetryBackend.h renamed to datalog/src/main/native/include/wpi/datalog/DataLogTelemetryBackend.h

Lines changed: 9 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -4,26 +4,24 @@
44

55
#pragma once
66

7-
#include "wpi/mutex.h"
8-
#include "wpi/telemetry/TelemetryBackend.h"
9-
#include "wpi/StringMap.h"
7+
#include <wpi/mutex.h>
8+
#include <wpi/telemetry/TelemetryBackend.h>
9+
#include <wpi/StringMap.h>
1010

11-
namespace wpi {
11+
namespace wpi::log {
1212

13-
namespace log {
1413
class DataLog;
15-
} // namespace log
1614

1715
/** A telemetry backend that sends logged data to a DataLog. */
18-
class DataLogTelemetryBackend : public TelemetryBackend {
16+
class DataLogTelemetryBackend : public wpi::TelemetryBackend {
1917
public:
2018
/**
2119
* Construct.
2220
*
2321
* @param log datalog
2422
* @param prefix prefix to put in front of logged path in data log
2523
*/
26-
DataLogTelemetryBackend(wpi::log::DataLog& log, std::string_view prefix);
24+
DataLogTelemetryBackend(DataLog& log, std::string_view prefix);
2725

2826
~DataLogTelemetryBackend() override;
2927

@@ -33,7 +31,7 @@ class DataLogTelemetryBackend : public TelemetryBackend {
3331
* @param path full name
3432
* @return telemetry entry
3533
*/
36-
TelemetryEntry& GetEntry(std::string_view path) override;
34+
wpi::TelemetryEntry& GetEntry(std::string_view path) override;
3735

3836
/**
3937
* Returns whether there is a data schema already registered with the given
@@ -83,10 +81,10 @@ class DataLogTelemetryBackend : public TelemetryBackend {
8381
private:
8482
class Entry;
8583

86-
wpi::log::DataLog& m_log;
84+
DataLog& m_log;
8785
std::string m_prefix;
8886
wpi::mutex m_mutex;
8987
wpi::StringMap<Entry> m_entries;
9088
};
9189

92-
} // namespace wpi
90+
} // namespace wpi::log

0 commit comments

Comments
 (0)