SCRIPT namespace replacements

This commit is contained in:
PJ Reiniger
2025-11-07 20:00:05 -05:00
committed by Peter Johnson
parent ae6c043632
commit 9aca8e0fd6
2622 changed files with 22275 additions and 22275 deletions

View File

@@ -25,14 +25,14 @@ static constexpr size_t kRecordMaxHeaderSize = 17;
static void DefaultLog(unsigned int level, const char* file, unsigned int line,
const char* msg) {
if (level > wpi::WPI_LOG_INFO) {
wpi::print(stderr, "DataLog: {}\n", msg);
} else if (level == wpi::WPI_LOG_INFO) {
wpi::print("DataLog: {}\n", msg);
if (level > wpi::util::WPI_LOG_INFO) {
wpi::util::print(stderr, "DataLog: {}\n", msg);
} else if (level == wpi::util::WPI_LOG_INFO) {
wpi::util::print("DataLog: {}\n", msg);
}
}
wpi::Logger DataLog::s_defaultMessageLog{DefaultLog};
wpi::util::Logger DataLog::s_defaultMessageLog{DefaultLog};
template <typename T>
static unsigned int WriteVarInt(uint8_t* buf, T val) {
@@ -56,7 +56,7 @@ static unsigned int WriteRecordHeader(uint8_t* buf, uint32_t entry,
unsigned int payloadLen = WriteVarInt(buf, payloadSize);
buf += payloadLen;
unsigned int timestampLen =
WriteVarInt(buf, timestamp == 0 ? wpi::Now() : timestamp);
WriteVarInt(buf, timestamp == 0 ? wpi::util::Now() : timestamp);
buf += timestampLen;
*origbuf =
((timestampLen - 1) << 4) | ((payloadLen - 1) << 2) | (entryLen - 1);
@@ -78,7 +78,7 @@ void DataLog::StartFile() {
uint8_t* buf = Reserve(m_extraHeader.size() + 12);
static const uint8_t header[] = {'W', 'P', 'I', 'L', 'O', 'G', 0, 1};
std::memcpy(buf, header, 8);
support::endian::write32le(buf + 8, m_extraHeader.size());
wpi::util::support::endian::write32le(buf + 8, m_extraHeader.size());
std::memcpy(buf + 12, m_extraHeader.data(), m_extraHeader.size());
// Existing start and schema data records
@@ -145,7 +145,7 @@ void DataLog::AddSchema(std::string_view name, std::string_view type,
return; // don't add duplicates
}
schemaInfo.data.assign(schema.begin(), schema.end());
wpi::SmallString<128> fullName{"/.schema/"};
wpi::util::SmallString<128> fullName{"/.schema/"};
fullName += name;
int entry = StartImpl(fullName, type, {}, timestamp);
@@ -206,7 +206,7 @@ void DataLog::AppendStartRecord(int id, std::string_view name,
size_t strsize = name.size() + type.size() + metadata.size();
uint8_t* buf = StartRecord(0, timestamp, 5 + 12 + strsize, 5);
*buf++ = impl::kControlStart;
wpi::support::endian::write32le(buf, id);
wpi::util::support::endian::write32le(buf, id);
AppendStringImpl(name);
AppendStringImpl(type);
AppendStringImpl(metadata);
@@ -241,7 +241,7 @@ void DataLog::Finish(int entry, int64_t timestamp) {
}
uint8_t* buf = StartRecord(0, timestamp, 5, 5);
*buf++ = impl::kControlFinish;
wpi::support::endian::write32le(buf, entry);
wpi::util::support::endian::write32le(buf, entry);
}
void DataLog::SetMetadata(int entry, std::string_view metadata,
@@ -256,7 +256,7 @@ void DataLog::SetMetadata(int entry, std::string_view metadata,
}
uint8_t* buf = StartRecord(0, timestamp, 5 + 4 + metadata.size(), 5);
*buf++ = impl::kControlSetMetadata;
wpi::support::endian::write32le(buf, entry);
wpi::util::support::endian::write32le(buf, entry);
AppendStringImpl(metadata);
}
@@ -305,7 +305,7 @@ void DataLog::AppendImpl(std::span<const uint8_t> data) {
void DataLog::AppendStringImpl(std::string_view str) {
uint8_t* buf = Reserve(4);
wpi::support::endian::write32le(buf, str.size());
wpi::util::support::endian::write32le(buf, str.size());
AppendImpl({reinterpret_cast<const uint8_t*>(str.data()), str.size()});
}
@@ -363,7 +363,7 @@ void DataLog::AppendInteger(int entry, int64_t value, int64_t timestamp) {
[[unlikely]] return;
}
uint8_t* buf = StartRecord(entry, timestamp, 8, 8);
wpi::support::endian::write64le(buf, value);
wpi::util::support::endian::write64le(buf, value);
}
void DataLog::AppendFloat(int entry, float value, int64_t timestamp) {
@@ -378,7 +378,7 @@ void DataLog::AppendFloat(int entry, float value, int64_t timestamp) {
if constexpr (std::endian::native == std::endian::little) {
std::memcpy(buf, &value, 4);
} else {
wpi::support::endian::write32le(buf, std::bit_cast<uint32_t>(value));
wpi::util::support::endian::write32le(buf, std::bit_cast<uint32_t>(value));
}
}
@@ -394,7 +394,7 @@ void DataLog::AppendDouble(int entry, double value, int64_t timestamp) {
if constexpr (std::endian::native == std::endian::little) {
std::memcpy(buf, &value, 8);
} else {
wpi::support::endian::write64le(buf, std::bit_cast<uint64_t>(value));
wpi::util::support::endian::write64le(buf, std::bit_cast<uint64_t>(value));
}
}
@@ -477,14 +477,14 @@ void DataLog::AppendIntegerArray(int entry, std::span<const int64_t> arr,
while ((arr.size() * 8) > kBlockSize) {
buf = Reserve(kBlockSize);
for (auto val : arr.subspan(0, kBlockSize / 8)) {
wpi::support::endian::write64le(buf, val);
wpi::util::support::endian::write64le(buf, val);
buf += 8;
}
arr = arr.subspan(kBlockSize / 8);
}
buf = Reserve(arr.size() * 8);
for (auto val : arr) {
wpi::support::endian::write64le(buf, val);
wpi::util::support::endian::write64le(buf, val);
buf += 8;
}
}
@@ -509,14 +509,14 @@ void DataLog::AppendFloatArray(int entry, std::span<const float> arr,
while ((arr.size() * 4) > kBlockSize) {
buf = Reserve(kBlockSize);
for (auto val : arr.subspan(0, kBlockSize / 4)) {
wpi::support::endian::write32le(buf, std::bit_cast<uint32_t>(val));
wpi::util::support::endian::write32le(buf, std::bit_cast<uint32_t>(val));
buf += 4;
}
arr = arr.subspan(kBlockSize / 4);
}
buf = Reserve(arr.size() * 4);
for (auto val : arr) {
wpi::support::endian::write32le(buf, std::bit_cast<uint32_t>(val));
wpi::util::support::endian::write32le(buf, std::bit_cast<uint32_t>(val));
buf += 4;
}
}
@@ -541,14 +541,14 @@ void DataLog::AppendDoubleArray(int entry, std::span<const double> arr,
while ((arr.size() * 8) > kBlockSize) {
buf = Reserve(kBlockSize);
for (auto val : arr.subspan(0, kBlockSize / 8)) {
wpi::support::endian::write64le(buf, std::bit_cast<uint64_t>(val));
wpi::util::support::endian::write64le(buf, std::bit_cast<uint64_t>(val));
buf += 8;
}
arr = arr.subspan(kBlockSize / 8);
}
buf = Reserve(arr.size() * 8);
for (auto val : arr) {
wpi::support::endian::write64le(buf, std::bit_cast<uint64_t>(val));
wpi::util::support::endian::write64le(buf, std::bit_cast<uint64_t>(val));
buf += 8;
}
}
@@ -570,7 +570,7 @@ void DataLog::AppendStringArray(int entry, std::span<const std::string> arr,
[[unlikely]] return;
}
uint8_t* buf = StartRecord(entry, timestamp, size, 4);
wpi::support::endian::write32le(buf, arr.size());
wpi::util::support::endian::write32le(buf, arr.size());
for (auto&& str : arr) {
AppendStringImpl(str);
}
@@ -593,7 +593,7 @@ void DataLog::AppendStringArray(int entry,
[[unlikely]] return;
}
uint8_t* buf = StartRecord(entry, timestamp, size, 4);
wpi::support::endian::write32le(buf, arr.size());
wpi::util::support::endian::write32le(buf, arr.size());
for (auto&& sv : arr) {
AppendStringImpl(sv);
}
@@ -616,7 +616,7 @@ void DataLog::AppendStringArray(int entry,
[[unlikely]] return;
}
uint8_t* buf = StartRecord(entry, timestamp, size, 4);
wpi::support::endian::write32le(buf, arr.size());
wpi::util::support::endian::write32le(buf, arr.size());
for (auto&& sv : arr) {
AppendStringImpl(sv.str);
}
@@ -750,8 +750,8 @@ int WPI_DataLog_Start(struct WPI_DataLog* datalog,
const struct WPI_String* type,
const struct WPI_String* metadata, int64_t timestamp) {
return reinterpret_cast<DataLog*>(datalog)->Start(
wpi::to_string_view(name), wpi::to_string_view(type),
wpi::to_string_view(metadata), timestamp);
wpi::util::to_string_view(name), wpi::util::to_string_view(type),
wpi::util::to_string_view(metadata), timestamp);
}
void WPI_DataLog_Finish(struct WPI_DataLog* datalog, int entry,
@@ -763,7 +763,7 @@ void WPI_DataLog_SetMetadata(struct WPI_DataLog* datalog, int entry,
const struct WPI_String* metadata,
int64_t timestamp) {
reinterpret_cast<DataLog*>(datalog)->SetMetadata(
entry, wpi::to_string_view(metadata), timestamp);
entry, wpi::util::to_string_view(metadata), timestamp);
}
void WPI_DataLog_AppendRaw(struct WPI_DataLog* datalog, int entry,
@@ -846,8 +846,8 @@ void WPI_DataLog_AddSchemaString(struct WPI_DataLog* datalog,
const struct WPI_String* schema,
int64_t timestamp) {
reinterpret_cast<DataLog*>(datalog)->AddSchema(
wpi::to_string_view(name), wpi::to_string_view(type),
wpi::to_string_view(schema), timestamp);
wpi::util::to_string_view(name), wpi::util::to_string_view(type),
wpi::util::to_string_view(schema), timestamp);
}
void WPI_DataLog_AddSchema(struct WPI_DataLog* datalog,
@@ -855,7 +855,7 @@ void WPI_DataLog_AddSchema(struct WPI_DataLog* datalog,
const struct WPI_String* type, const uint8_t* schema,
size_t schema_len, int64_t timestamp) {
reinterpret_cast<DataLog*>(datalog)->AddSchema(
wpi::to_string_view(name), wpi::to_string_view(type),
wpi::util::to_string_view(name), wpi::util::to_string_view(type),
std::span<const uint8_t>{schema, schema_len}, timestamp);
}

View File

@@ -53,7 +53,7 @@ DataLogBackgroundWriter::DataLogBackgroundWriter(std::string_view dir,
: DataLogBackgroundWriter{s_defaultMessageLog, dir, filename, period,
extraHeader} {}
DataLogBackgroundWriter::DataLogBackgroundWriter(wpi::Logger& msglog,
DataLogBackgroundWriter::DataLogBackgroundWriter(wpi::util::Logger& msglog,
std::string_view dir,
std::string_view filename,
double period,
@@ -70,7 +70,7 @@ DataLogBackgroundWriter::DataLogBackgroundWriter(
extraHeader} {}
DataLogBackgroundWriter::DataLogBackgroundWriter(
wpi::Logger& msglog,
wpi::util::Logger& msglog,
std::function<void(std::span<const uint8_t> data)> write, double period,
std::string_view extraHeader)
: DataLog{msglog, extraHeader},
@@ -132,7 +132,7 @@ void DataLogBackgroundWriter::Stop() {
}
static void WriteToFile(fs::file_t f, std::span<const uint8_t> data,
std::string_view filename, wpi::Logger& msglog) {
std::string_view filename, wpi::util::Logger& msglog) {
do {
#ifdef _WIN32
DWORD ret;
@@ -469,8 +469,8 @@ struct WPI_DataLog* WPI_DataLog_CreateBackgroundWriter(
const struct WPI_String* dir, const struct WPI_String* filename,
double period, const struct WPI_String* extraHeader) {
return reinterpret_cast<WPI_DataLog*>(new DataLogBackgroundWriter{
wpi::to_string_view(dir), wpi::to_string_view(filename), period,
wpi::to_string_view(extraHeader)});
wpi::util::to_string_view(dir), wpi::util::to_string_view(filename), period,
wpi::util::to_string_view(extraHeader)});
}
struct WPI_DataLog* WPI_DataLog_CreateBackgroundWriter_Func(
@@ -478,13 +478,13 @@ struct WPI_DataLog* WPI_DataLog_CreateBackgroundWriter_Func(
double period, const struct WPI_String* extraHeader) {
return reinterpret_cast<WPI_DataLog*>(new DataLogBackgroundWriter{
[=](auto data) { write(ptr, data.data(), data.size()); }, period,
wpi::to_string_view(extraHeader)});
wpi::util::to_string_view(extraHeader)});
}
void WPI_DataLog_SetBackgroundWriterFilename(
struct WPI_DataLog* datalog, const struct WPI_String* filename) {
reinterpret_cast<DataLogBackgroundWriter*>(datalog)->SetFilename(
wpi::to_string_view(filename));
wpi::util::to_string_view(filename));
}
} // extern "C"

View File

@@ -17,7 +17,7 @@ static bool ReadString(std::span<const uint8_t>* buf, std::string_view* str) {
*str = {};
return false;
}
uint32_t len = wpi::support::endian::read32le(buf->data());
uint32_t len = wpi::util::support::endian::read32le(buf->data());
if (len > (buf->size() - 4)) {
*str = {};
return false;
@@ -46,7 +46,7 @@ bool DataLogRecord::GetStartData(StartRecordData* out) const {
if (!IsStart()) {
return false;
}
out->entry = wpi::support::endian::read32le(&m_data[1]);
out->entry = wpi::util::support::endian::read32le(&m_data[1]);
auto buf = m_data.subspan(5);
if (!ReadString(&buf, &out->name)) {
return false;
@@ -64,7 +64,7 @@ bool DataLogRecord::GetFinishEntry(int* out) const {
if (!IsFinish()) {
return false;
}
*out = wpi::support::endian::read32le(&m_data[1]);
*out = wpi::util::support::endian::read32le(&m_data[1]);
return true;
}
@@ -72,7 +72,7 @@ bool DataLogRecord::GetSetMetadataData(MetadataRecordData* out) const {
if (!IsSetMetadata()) {
return false;
}
out->entry = wpi::support::endian::read32le(&m_data[1]);
out->entry = wpi::util::support::endian::read32le(&m_data[1]);
auto buf = m_data.subspan(5);
return ReadString(&buf, &out->metadata);
}
@@ -89,7 +89,7 @@ bool DataLogRecord::GetInteger(int64_t* value) const {
if (m_data.size() != 8) {
return false;
}
*value = wpi::support::endian::read64le(m_data.data());
*value = wpi::util::support::endian::read64le(m_data.data());
return true;
}
@@ -97,7 +97,7 @@ bool DataLogRecord::GetFloat(float* value) const {
if (m_data.size() != 4) {
return false;
}
*value = std::bit_cast<float>(wpi::support::endian::read32le(m_data.data()));
*value = std::bit_cast<float>(wpi::util::support::endian::read32le(m_data.data()));
return true;
}
@@ -105,7 +105,7 @@ bool DataLogRecord::GetDouble(double* value) const {
if (m_data.size() != 8) {
return false;
}
*value = std::bit_cast<double>(wpi::support::endian::read64le(m_data.data()));
*value = std::bit_cast<double>(wpi::util::support::endian::read64le(m_data.data()));
return true;
}
@@ -130,7 +130,7 @@ bool DataLogRecord::GetIntegerArray(std::vector<int64_t>* arr) const {
}
arr->reserve(m_data.size() / 8);
for (size_t pos = 0; pos < m_data.size(); pos += 8) {
arr->push_back(wpi::support::endian::read64le(&m_data[pos]));
arr->push_back(wpi::util::support::endian::read64le(&m_data[pos]));
}
return true;
}
@@ -143,7 +143,7 @@ bool DataLogRecord::GetFloatArray(std::vector<float>* arr) const {
arr->reserve(m_data.size() / 4);
for (size_t pos = 0; pos < m_data.size(); pos += 4) {
arr->push_back(
std::bit_cast<float>(wpi::support::endian::read32le(&m_data[pos])));
std::bit_cast<float>(wpi::util::support::endian::read32le(&m_data[pos])));
}
return true;
}
@@ -156,7 +156,7 @@ bool DataLogRecord::GetDoubleArray(std::vector<double>* arr) const {
arr->reserve(m_data.size() / 8);
for (size_t pos = 0; pos < m_data.size(); pos += 8) {
arr->push_back(
std::bit_cast<double>(wpi::support::endian::read64le(&m_data[pos])));
std::bit_cast<double>(wpi::util::support::endian::read64le(&m_data[pos])));
}
return true;
}
@@ -166,7 +166,7 @@ bool DataLogRecord::GetStringArray(std::vector<std::string_view>* arr) const {
if (m_data.size() < 4) {
return false;
}
uint32_t size = wpi::support::endian::read32le(m_data.data());
uint32_t size = wpi::util::support::endian::read32le(m_data.data());
// sanity check size
if (size > ((m_data.size() - 4) / 4)) {
return false;
@@ -189,7 +189,7 @@ bool DataLogRecord::GetStringArray(std::vector<std::string_view>* arr) const {
return true;
}
DataLogReader::DataLogReader(std::unique_ptr<MemoryBuffer> buffer)
DataLogReader::DataLogReader(std::unique_ptr<wpi::util::MemoryBuffer> buffer)
: m_buf{std::move(buffer)} {}
bool DataLogReader::IsValid() const {
@@ -200,7 +200,7 @@ bool DataLogReader::IsValid() const {
return buf.size() >= 12 &&
std::string_view{reinterpret_cast<const char*>(buf.data()), 6} ==
"WPILOG" &&
wpi::support::endian::read16le(&buf[6]) >= 0x0100;
wpi::util::support::endian::read16le(&buf[6]) >= 0x0100;
}
uint16_t DataLogReader::GetVersion() const {
@@ -211,7 +211,7 @@ uint16_t DataLogReader::GetVersion() const {
if (buf.size() < 12) {
return 0;
}
return wpi::support::endian::read16le(&buf[6]);
return wpi::util::support::endian::read16le(&buf[6]);
}
std::string_view DataLogReader::GetExtraHeader() const {
@@ -236,7 +236,7 @@ DataLogReader::iterator DataLogReader::begin() const {
if (buf.size() < 12) {
return end();
}
uint32_t size = wpi::support::endian::read32le(&buf[8]);
uint32_t size = wpi::util::support::endian::read32le(&buf[8]);
if (buf.size() < (12 + size)) {
return end();
}

View File

@@ -20,7 +20,7 @@ DataLogReaderThread::~DataLogReaderThread() {
}
void DataLogReaderThread::ReadMain() {
wpi::SmallDenseMap<
wpi::util::SmallDenseMap<
int, std::pair<DataLogReaderEntry*, std::span<const uint8_t>>, 8>
schemaEntries;
@@ -37,7 +37,7 @@ void DataLogReaderThread::ReadMain() {
std::scoped_lock lock{m_mutex};
auto& entryPtr = m_entriesById[data.entry];
if (entryPtr) {
wpi::print("...DUPLICATE entry ID, overriding\n");
wpi::util::print("...DUPLICATE entry ID, overriding\n");
}
auto [it, isNew] = m_entriesByName.emplace(data.name, data);
if (isNew) {
@@ -51,7 +51,7 @@ void DataLogReaderThread::ReadMain() {
}
sigEntryAdded(data);
} else {
wpi::print("Start(INVALID)\n");
wpi::util::print("Start(INVALID)\n");
}
} else if (record.IsFinish()) {
int entry;
@@ -59,13 +59,13 @@ void DataLogReaderThread::ReadMain() {
std::scoped_lock lock{m_mutex};
auto it = m_entriesById.find(entry);
if (it == m_entriesById.end()) {
wpi::print("...ID not found\n");
wpi::util::print("...ID not found\n");
} else {
it->second->ranges.back().m_end = recordIt;
m_entriesById.erase(it);
}
} else {
wpi::print("Finish(INVALID)\n");
wpi::util::print("Finish(INVALID)\n");
}
} else if (record.IsSetMetadata()) {
wpi::log::MetadataRecordData data;
@@ -73,15 +73,15 @@ void DataLogReaderThread::ReadMain() {
std::scoped_lock lock{m_mutex};
auto it = m_entriesById.find(data.entry);
if (it == m_entriesById.end()) {
wpi::print("...ID not found\n");
wpi::util::print("...ID not found\n");
} else {
it->second->metadata = data.metadata;
}
} else {
wpi::print("SetMetadata(INVALID)\n");
wpi::util::print("SetMetadata(INVALID)\n");
}
} else if (record.IsControl()) {
wpi::print("Unrecognized control record\n");
wpi::util::print("Unrecognized control record\n");
} else {
auto it = schemaEntries.find(record.GetEntry());
if (it != schemaEntries.end()) {
@@ -97,19 +97,19 @@ void DataLogReaderThread::ReadMain() {
if (data.empty()) {
continue;
}
if (auto strippedName = wpi::remove_prefix(name, "NT:")) {
if (auto strippedName = wpi::util::remove_prefix(name, "NT:")) {
name = *strippedName;
}
if (auto typeStr = wpi::remove_prefix(name, "/.schema/struct:")) {
if (auto typeStr = wpi::util::remove_prefix(name, "/.schema/struct:")) {
std::string_view schema{reinterpret_cast<const char*>(data.data()),
data.size()};
std::string err;
auto desc = m_structDb.Add(*typeStr, schema, &err);
if (!desc) {
wpi::print("could not decode struct '{}' schema '{}': {}\n", name,
wpi::util::print("could not decode struct '{}' schema '{}': {}\n", name,
schema, err);
}
} else if (auto filename = wpi::remove_prefix(name, "/.schema/proto:")) {
} else if (auto filename = wpi::util::remove_prefix(name, "/.schema/proto:")) {
// protobuf descriptor handling
upb_Status status;
status.ok = true;
@@ -119,7 +119,7 @@ void DataLogReaderThread::ReadMain() {
reinterpret_cast<const char*>(data.data()), data.size(), m_arena),
&status);
if (!status.ok) {
wpi::print("could not decode protobuf '{}' filename '{}'\n", name,
wpi::util::print("could not decode protobuf '{}' filename '{}'\n", name,
*filename);
}
}

View File

@@ -12,9 +12,9 @@
using namespace wpi::log;
static std::unique_ptr<wpi::raw_ostream> CheckOpen(std::string_view filename,
static std::unique_ptr<wpi::util::raw_ostream> CheckOpen(std::string_view filename,
std::error_code& ec) {
auto rv = std::make_unique<wpi::raw_fd_ostream>(filename, ec);
auto rv = std::make_unique<wpi::util::raw_fd_ostream>(filename, ec);
if (ec) {
return nullptr;
}
@@ -25,7 +25,7 @@ DataLogWriter::DataLogWriter(std::string_view filename, std::error_code& ec,
std::string_view extraHeader)
: DataLogWriter{s_defaultMessageLog, filename, ec, extraHeader} {}
DataLogWriter::DataLogWriter(wpi::Logger& msglog, std::string_view filename,
DataLogWriter::DataLogWriter(wpi::util::Logger& msglog, std::string_view filename,
std::error_code& ec, std::string_view extraHeader)
: DataLogWriter{msglog, CheckOpen(filename, ec), extraHeader} {
if (ec) {
@@ -33,12 +33,12 @@ DataLogWriter::DataLogWriter(wpi::Logger& msglog, std::string_view filename,
}
}
DataLogWriter::DataLogWriter(std::unique_ptr<wpi::raw_ostream> os,
DataLogWriter::DataLogWriter(std::unique_ptr<wpi::util::raw_ostream> os,
std::string_view extraHeader)
: DataLogWriter{s_defaultMessageLog, std::move(os), extraHeader} {}
DataLogWriter::DataLogWriter(wpi::Logger& msglog,
std::unique_ptr<wpi::raw_ostream> os,
DataLogWriter::DataLogWriter(wpi::util::Logger& msglog,
std::unique_ptr<wpi::util::raw_ostream> os,
std::string_view extraHeader)
: DataLog{msglog, extraHeader}, m_os{std::move(os)} {
StartFile();
@@ -80,7 +80,7 @@ struct WPI_DataLog* WPI_DataLog_CreateWriter(
const struct WPI_String* extraHeader) {
std::error_code ec;
auto rv = reinterpret_cast<WPI_DataLog*>(new DataLogWriter{
wpi::to_string_view(filename), ec, wpi::to_string_view(extraHeader)});
wpi::util::to_string_view(filename), ec, wpi::util::to_string_view(extraHeader)});
*errorCode = ec.value();
return rv;
}

View File

@@ -88,12 +88,12 @@ FileLogger::~FileLogger() {
std::function<void(std::string_view)> FileLogger::Buffer(
std::function<void(std::string_view)> callback) {
return [callback,
buf = wpi::SmallVector<char, 64>{}](std::string_view data) mutable {
buf = wpi::util::SmallVector<char, 64>{}](std::string_view data) mutable {
buf.append(data.begin(), data.end());
if (!wpi::contains({data.data(), data.size()}, "\n")) {
if (!wpi::util::contains({data.data(), data.size()}, "\n")) {
return;
}
auto [wholeData, extra] = wpi::rsplit({buf.data(), buf.size()}, "\n");
auto [wholeData, extra] = wpi::util::rsplit({buf.data(), buf.size()}, "\n");
std::string leftover{extra};
callback(wholeData);

View File

@@ -19,7 +19,7 @@
#include "wpi/datalog/FileLogger.hpp"
#include "wpi/util/jni_util.hpp"
using namespace wpi::java;
using namespace wpi::util::java;
using namespace wpi::log;
static bool mockTimeEnabled = false;
@@ -53,12 +53,12 @@ void wpi::ThrowNullPointerException(JNIEnv* env, std::string_view msg) {
}
namespace {
class buf_ostream : public wpi::raw_uvector_ostream {
class buf_ostream : public wpi::util::raw_uvector_ostream {
private:
std::vector<uint8_t> data;
public:
buf_ostream() : raw_uvector_ostream{data} {}
buf_ostream() : wpi::util::raw_uvector_ostream{data} {}
void clear() { data.clear(); }
};
@@ -181,7 +181,7 @@ Java_org_wpilib_util_WPIUtilJNI_now
if (mockTimeEnabled) {
return mockNow;
} else {
return wpi::Now();
return wpi::util::Now();
}
}
@@ -599,7 +599,7 @@ Java_org_wpilib_datalog_DataLogJNI_appendIntegerArray
entry, {reinterpret_cast<const int64_t*>(jarr.data()), jarr.size()},
timestamp);
} else {
wpi::SmallVector<int64_t, 16> arr;
wpi::util::SmallVector<int64_t, 16> arr;
arr.reserve(jarr.size());
for (auto v : jarr) {
arr.push_back(v);

View File

@@ -29,7 +29,7 @@
#include "wpi/util/struct/Struct.hpp"
#include "wpi/util/timestamp.h"
namespace wpi {
namespace wpi::util {
class Logger;
} // namespace wpi
@@ -158,8 +158,8 @@ class DataLog {
* @param msg protobuf message
* @param timestamp Time stamp (0 to indicate now)
*/
template <ProtobufSerializable T>
void AddProtobufSchema(ProtobufMessage<T>& msg, int64_t timestamp = 0) {
template <wpi::util::ProtobufSerializable T>
void AddProtobufSchema(wpi::util::ProtobufMessage<T>& msg, int64_t timestamp = 0) {
if (timestamp == 0) {
timestamp = Now();
}
@@ -179,12 +179,12 @@ class DataLog {
* @param timestamp Time stamp (0 to indicate now)
*/
template <typename T, typename... I>
requires StructSerializable<T, I...>
requires wpi::util::StructSerializable<T, I...>
void AddStructSchema(const I&... info, int64_t timestamp = 0) {
if (timestamp == 0) {
timestamp = Now();
}
ForEachStructSchema<T>(
wpi::util::ForEachStructSchema<T>(
[this, timestamp](auto typeString, auto schema) {
this->AddSchema(typeString, "structschema", schema, timestamp);
},
@@ -381,7 +381,7 @@ class DataLog {
protected:
static constexpr size_t kBlockSize = 16 * 1024;
static wpi::Logger s_defaultMessageLog;
static wpi::util::Logger s_defaultMessageLog;
class Buffer {
public:
@@ -441,7 +441,7 @@ class DataLog {
* @param msglog message logger (will be called from separate thread)
* @param extraHeader extra header metadata
*/
explicit DataLog(wpi::Logger& msglog, std::string_view extraHeader = "")
explicit DataLog(wpi::util::Logger& msglog, std::string_view extraHeader = "")
: m_msglog{msglog}, m_extraHeader{extraHeader} {}
/**
@@ -503,10 +503,10 @@ class DataLog {
void DoReleaseBufs(std::vector<Buffer>* bufs);
protected:
wpi::Logger& m_msglog;
wpi::util::Logger& m_msglog;
private:
mutable wpi::mutex m_mutex;
mutable wpi::util::mutex m_mutex;
bool m_active = false;
bool m_paused = false;
std::string m_extraHeader;
@@ -516,17 +516,17 @@ class DataLog {
std::string type;
int id{0};
};
wpi::StringMap<EntryInfo> m_entries;
wpi::util::StringMap<EntryInfo> m_entries;
struct SchemaInfo {
std::vector<uint8_t> data;
int id{0};
};
wpi::StringMap<SchemaInfo> m_schemas;
wpi::util::StringMap<SchemaInfo> m_schemas;
struct EntryInfo2 {
std::string metadata;
unsigned int count;
};
wpi::DenseMap<int, EntryInfo2> m_entryIds;
wpi::util::DenseMap<int, EntryInfo2> m_entryIds;
int m_lastId = 0;
};
@@ -627,7 +627,7 @@ class DataLogValueEntryImpl : public DataLogEntry {
}
protected:
mutable wpi::mutex m_mutex;
mutable wpi::util::mutex m_mutex;
std::optional<T> m_lastValue;
};
@@ -1299,9 +1299,9 @@ class StringArrayLogEntry
* Log raw struct serializable objects.
*/
template <typename T, typename... I>
requires StructSerializable<T, I...>
requires wpi::util::StructSerializable<T, I...>
class StructLogEntry : public DataLogEntry {
using S = Struct<T, I...>;
using S = wpi::util::Struct<T, I...>;
public:
StructLogEntry() = default;
@@ -1314,7 +1314,7 @@ class StructLogEntry : public DataLogEntry {
m_log = &log;
log.AddStructSchema<T, I...>(info..., timestamp);
m_entry =
log.Start(name, GetStructTypeString<T>(info...), metadata, timestamp);
log.Start(name, wpi::util::GetStructTypeString<T>(info...), metadata, timestamp);
}
StructLogEntry(StructLogEntry&& rhs)
@@ -1338,14 +1338,14 @@ class StructLogEntry : public DataLogEntry {
*/
void Append(const T& data, int64_t timestamp = 0) {
if constexpr (sizeof...(I) == 0) {
if constexpr (wpi::is_constexpr([] { S::GetSize(); })) {
if constexpr (wpi::util::is_constexpr([] { S::GetSize(); })) {
uint8_t buf[S::GetSize()];
S::Pack(buf, data);
m_log->AppendRaw(m_entry, buf, timestamp);
return;
}
}
wpi::SmallVector<uint8_t, 128> buf;
wpi::util::SmallVector<uint8_t, 128> buf;
buf.resize_for_overwrite(std::apply(S::GetSize, m_info));
std::apply([&](const I&... info) { S::Pack(buf, data, info...); }, m_info);
m_log->AppendRaw(m_entry, buf, timestamp);
@@ -1363,7 +1363,7 @@ class StructLogEntry : public DataLogEntry {
*/
void Update(const T& data, int64_t timestamp = 0) {
if constexpr (sizeof...(I) == 0) {
if constexpr (wpi::is_constexpr([] { S::GetSize(); })) {
if constexpr (wpi::util::is_constexpr([] { S::GetSize(); })) {
uint8_t buf[S::GetSize()];
S::Pack(buf, data);
std::scoped_lock lock{m_mutex};
@@ -1376,7 +1376,7 @@ class StructLogEntry : public DataLogEntry {
return;
}
}
wpi::SmallVector<uint8_t, 128> buf;
wpi::util::SmallVector<uint8_t, 128> buf;
buf.resize_for_overwrite(std::apply(S::GetSize, m_info));
std::apply([&](const I&... info) { S::Pack(buf, data, info...); }, m_info);
std::scoped_lock lock{m_mutex};
@@ -1417,7 +1417,7 @@ class StructLogEntry : public DataLogEntry {
}
private:
mutable wpi::mutex m_mutex;
mutable wpi::util::mutex m_mutex;
std::vector<uint8_t> m_lastValue;
[[no_unique_address]]
std::tuple<I...> m_info;
@@ -1427,9 +1427,9 @@ class StructLogEntry : public DataLogEntry {
* Log raw struct serializable array of objects.
*/
template <typename T, typename... I>
requires StructSerializable<T, I...>
requires wpi::util::StructSerializable<T, I...>
class StructArrayLogEntry : public DataLogEntry {
using S = Struct<T, I...>;
using S = wpi::util::Struct<T, I...>;
public:
StructArrayLogEntry() = default;
@@ -1443,7 +1443,7 @@ class StructArrayLogEntry : public DataLogEntry {
m_log = &log;
log.AddStructSchema<T, I...>(info..., timestamp);
m_entry = log.Start(
name, MakeStructArrayTypeString<T, std::dynamic_extent>(info...),
name, wpi::util::MakeStructArrayTypeString<T, std::dynamic_extent>(info...),
metadata, timestamp);
}
@@ -1574,8 +1574,8 @@ class StructArrayLogEntry : public DataLogEntry {
}
private:
mutable wpi::mutex m_mutex;
StructArrayBuffer<T, I...> m_buf;
mutable wpi::util::mutex m_mutex;
wpi::util::StructArrayBuffer<T, I...> m_buf;
std::optional<std::vector<uint8_t>> m_lastValue;
[[no_unique_address]]
std::tuple<I...> m_info;
@@ -1584,9 +1584,9 @@ class StructArrayLogEntry : public DataLogEntry {
/**
* Log protobuf serializable objects.
*/
template <ProtobufSerializable T>
template <wpi::util::ProtobufSerializable T>
class ProtobufLogEntry : public DataLogEntry {
using P = Protobuf<T>;
using P = wpi::util::Protobuf<T>;
public:
ProtobufLogEntry() = default;
@@ -1606,7 +1606,7 @@ class ProtobufLogEntry : public DataLogEntry {
* @param timestamp Time stamp (may be 0 to indicate now)
*/
void Append(const T& data, int64_t timestamp = 0) {
SmallVector<uint8_t, 128> buf;
wpi::util::SmallVector<uint8_t, 128> buf;
{
std::scoped_lock lock{m_mutex};
m_msg.Pack(buf, data);
@@ -1626,7 +1626,7 @@ class ProtobufLogEntry : public DataLogEntry {
*/
void Update(const T& data, int64_t timestamp = 0) {
std::scoped_lock lock{m_mutex};
wpi::SmallVector<uint8_t, 128> buf;
wpi::util::SmallVector<uint8_t, 128> buf;
m_msg.Pack(buf, data);
if (!m_lastValue.has_value()) {
m_lastValue = std::vector(buf.begin(), buf.end());
@@ -1665,8 +1665,8 @@ class ProtobufLogEntry : public DataLogEntry {
}
private:
mutable wpi::mutex m_mutex;
ProtobufMessage<T> m_msg;
mutable wpi::util::mutex m_mutex;
wpi::util::ProtobufMessage<T> m_msg;
std::optional<std::vector<uint8_t>> m_lastValue;
};

View File

@@ -16,7 +16,7 @@
#include "wpi/util/condition_variable.hpp"
#include "wpi/util/mutex.hpp"
namespace wpi {
namespace wpi::util {
class Logger;
} // namespace wpi
@@ -65,7 +65,7 @@ class DataLogBackgroundWriter final : public DataLog {
* this is a time/storage tradeoff
* @param extraHeader extra header data
*/
explicit DataLogBackgroundWriter(wpi::Logger& msglog,
explicit DataLogBackgroundWriter(wpi::util::Logger& msglog,
std::string_view dir = "",
std::string_view filename = "",
double period = 0.25,
@@ -99,7 +99,7 @@ class DataLogBackgroundWriter final : public DataLog {
* @param extraHeader extra header data
*/
explicit DataLogBackgroundWriter(
wpi::Logger& msglog,
wpi::util::Logger& msglog,
std::function<void(std::span<const uint8_t> data)> write,
double period = 0.25, std::string_view extraHeader = "");
@@ -152,8 +152,8 @@ class DataLogBackgroundWriter final : public DataLog {
void WriterThreadMain(
std::function<void(std::span<const uint8_t> data)> write);
mutable wpi::mutex m_mutex;
wpi::condition_variable m_cond;
mutable wpi::util::mutex m_mutex;
wpi::util::condition_variable m_cond;
bool m_doFlush{false};
bool m_shutdown{false};
enum State {

View File

@@ -303,7 +303,7 @@ class DataLogReader {
using iterator = DataLogIterator;
/** Constructs from a memory buffer. */
explicit DataLogReader(std::unique_ptr<MemoryBuffer> buffer);
explicit DataLogReader(std::unique_ptr<wpi::util::MemoryBuffer> buffer);
/** Returns true if the data log is valid (e.g. has a valid header). */
explicit operator bool() const { return IsValid(); }
@@ -342,7 +342,7 @@ class DataLogReader {
iterator end() const { return DataLogIterator{this, SIZE_MAX}; }
private:
std::unique_ptr<MemoryBuffer> m_buf;
std::unique_ptr<wpi::util::MemoryBuffer> m_buf;
bool GetRecord(size_t* pos, DataLogRecord* out) const;
bool GetNextRecord(size_t* pos) const;

View File

@@ -85,27 +85,27 @@ class DataLogReaderThread {
return it->second;
}
wpi::StructDescriptorDatabase& GetStructDatabase() { return m_structDb; }
wpi::util::StructDescriptorDatabase& GetStructDatabase() { return m_structDb; }
upb_DefPool* GetProtobufDatabase() { return m_protoPool; }
upb_Arena* GetProtobufArena() { return m_arena; }
const wpi::log::DataLogReader& GetReader() const { return m_reader; }
// note: these are called on separate thread
wpi::sig::Signal_mt<const DataLogReaderEntry&> sigEntryAdded;
wpi::sig::Signal_mt<> sigDone;
wpi::util::sig::Signal_mt<const DataLogReaderEntry&> sigEntryAdded;
wpi::util::sig::Signal_mt<> sigDone;
private:
void ReadMain();
wpi::log::DataLogReader m_reader;
mutable wpi::mutex m_mutex;
mutable wpi::util::mutex m_mutex;
std::atomic_bool m_active{true};
std::atomic_bool m_done{false};
std::atomic<unsigned int> m_numRecords{0};
std::map<std::string, DataLogReaderEntry, std::less<>> m_entriesByName;
wpi::DenseMap<int, DataLogReaderEntry*> m_entriesById;
wpi::StructDescriptorDatabase m_structDb;
wpi::util::DenseMap<int, DataLogReaderEntry*> m_entriesById;
wpi::util::StructDescriptorDatabase m_structDb;
upb_DefPool* m_protoPool = upb_DefPool_New();
upb_Arena* m_arena = upb_Arena_New();
std::thread m_thread;

View File

@@ -10,7 +10,7 @@
#include "wpi/datalog/DataLog.hpp"
namespace wpi {
namespace wpi::util {
class raw_ostream;
class Logger;
} // namespace wpi
@@ -43,7 +43,7 @@ class DataLogWriter final : public DataLog {
* @param ec error code if failed to open file (output)
* @param extraHeader extra header data
*/
DataLogWriter(wpi::Logger& msglog, std::string_view filename,
DataLogWriter(wpi::util::Logger& msglog, std::string_view filename,
std::error_code& ec, std::string_view extraHeader = "");
/**
@@ -52,7 +52,7 @@ class DataLogWriter final : public DataLog {
* @param os output stream
* @param extraHeader extra header data
*/
explicit DataLogWriter(std::unique_ptr<wpi::raw_ostream> os,
explicit DataLogWriter(std::unique_ptr<wpi::util::raw_ostream> os,
std::string_view extraHeader = "");
/**
@@ -62,7 +62,7 @@ class DataLogWriter final : public DataLog {
* @param os output stream
* @param extraHeader extra header data
*/
DataLogWriter(wpi::Logger& msglog, std::unique_ptr<wpi::raw_ostream> os,
DataLogWriter(wpi::util::Logger& msglog, std::unique_ptr<wpi::util::raw_ostream> os,
std::string_view extraHeader = "");
~DataLogWriter() final;
@@ -86,12 +86,12 @@ class DataLogWriter final : public DataLog {
*
* @return output stream
*/
wpi::raw_ostream& GetStream() { return *m_os; }
wpi::util::raw_ostream& GetStream() { return *m_os; }
private:
bool BufferFull() final;
std::unique_ptr<wpi::raw_ostream> m_os;
std::unique_ptr<wpi::util::raw_ostream> m_os;
};
} // namespace wpi::log