SCRIPT: wpiformat

This commit is contained in:
PJ Reiniger
2025-11-07 20:01:58 -05:00
committed by Peter Johnson
parent ae6bdc9d25
commit 2109161534
749 changed files with 5504 additions and 3936 deletions

View File

@@ -72,9 +72,12 @@ void PrintTimes(std::vector<int64_t>& times) {
std::inner_product(times.begin(), times.end(), times.begin(), 0);
double stdev = std::sqrt(sq_sum / times.size() - mean * mean);
wpi::util::print("min: {} max: {}, mean: {}, stdev: {}\n", min, max, mean, stdev);
wpi::util::print("min 10: {}\n", fmt::join(times.begin(), times.begin() + 10, ","));
wpi::util::print("max 10: {}\n", fmt::join(times.end() - 10, times.end(), ","));
wpi::util::print("min: {} max: {}, mean: {}, stdev: {}\n", min, max, mean,
stdev);
wpi::util::print("min 10: {}\n",
fmt::join(times.begin(), times.begin() + 10, ","));
wpi::util::print("max 10: {}\n",
fmt::join(times.end() - 10, times.end(), ","));
}
// benchmark
@@ -94,9 +97,10 @@ void bench() {
// add "typical" set of subscribers on client and server
wpi::nt::SubscribeMultiple(client, {{std::string_view{}}});
wpi::nt::Subscribe(wpi::nt::GetTopic(client, "highrate"), NT_DOUBLE, "double",
{.sendAll = true, .keepDuplicates = true});
{.sendAll = true, .keepDuplicates = true});
wpi::nt::SubscribeMultiple(server, {{std::string_view{}}});
auto pub = wpi::nt::Publish(wpi::nt::GetTopic(server, "highrate"), NT_DOUBLE, "double");
auto pub = wpi::nt::Publish(wpi::nt::GetTopic(server, "highrate"), NT_DOUBLE,
"double");
wpi::nt::SetDouble(pub, 0);
// warm up
@@ -130,9 +134,10 @@ void bench() {
}
auto stop = std::chrono::high_resolution_clock::now();
wpi::util::print("total time: {}us\n",
std::chrono::duration_cast<std::chrono::microseconds>(stop - start)
.count());
wpi::util::print(
"total time: {}us\n",
std::chrono::duration_cast<std::chrono::microseconds>(stop - start)
.count());
PrintTimes(times);
wpi::util::print("-- Flush --\n");
PrintTimes(flushTimes);
@@ -163,8 +168,8 @@ void bench2() {
std::array<NT_Entry, 1000> pubs;
for (int i = 0; i < 1000; ++i) {
pubs[i] = wpi::nt::GetEntry(
wpi::nt::GetTopic(server,
fmt::format("/some/long/name/with/lots/of/slashes/{}", i)),
wpi::nt::GetTopic(
server, fmt::format("/some/long/name/with/lots/of/slashes/{}", i)),
NT_DOUBLE_ARRAY, "double[]");
}
@@ -203,9 +208,10 @@ void bench2() {
}
auto stop = std::chrono::high_resolution_clock::now();
wpi::util::print("total time: {}us\n",
std::chrono::duration_cast<std::chrono::microseconds>(stop - start)
.count());
wpi::util::print(
"total time: {}us\n",
std::chrono::duration_cast<std::chrono::microseconds>(stop - start)
.count());
PrintTimes(times);
wpi::util::print("-- Flush --\n");
PrintTimes(flushTimes);
@@ -251,9 +257,9 @@ void stress() {
// create publishers
NT_Publisher pub[30];
for (int i = 0; i < 30; ++i) {
pub[i] =
wpi::nt::Publish(wpi::nt::GetTopic(server, fmt::format("{}_{}", count, i)),
NT_DOUBLE, "double", {});
pub[i] = wpi::nt::Publish(
wpi::nt::GetTopic(server, fmt::format("{}_{}", count, i)),
NT_DOUBLE, "double", {});
}
// publish values
@@ -348,13 +354,13 @@ void latency() {
std::this_thread::sleep_for(1s);
// create publishers and subscribers
auto pub =
wpi::nt::Publish(wpi::nt::GetTopic(client1, "highrate"), NT_DOUBLE, "double");
auto pub = wpi::nt::Publish(wpi::nt::GetTopic(client1, "highrate"), NT_DOUBLE,
"double");
wpi::nt::SubscribeMultiple(server, {{std::string_view{}}});
auto sub =
wpi::nt::Subscribe(wpi::nt::GetTopic(server, "highrate"), NT_DOUBLE, "double");
auto sub2 =
wpi::nt::Subscribe(wpi::nt::GetTopic(client2, "highrate"), NT_DOUBLE, "double");
auto sub = wpi::nt::Subscribe(wpi::nt::GetTopic(server, "highrate"),
NT_DOUBLE, "double");
auto sub2 = wpi::nt::Subscribe(wpi::nt::GetTopic(client2, "highrate"),
NT_DOUBLE, "double");
std::this_thread::sleep_for(1s);

View File

@@ -23,7 +23,7 @@
namespace wpi::util {
class Logger;
} // namespace wpi
} // namespace wpi::util
namespace wpi::nt {
@@ -31,7 +31,8 @@ class IListenerStorage;
class LocalStorage final : public net::ILocalStorage {
public:
LocalStorage(int inst, IListenerStorage& listenerStorage, wpi::util::Logger& logger)
LocalStorage(int inst, IListenerStorage& listenerStorage,
wpi::util::Logger& logger)
: m_impl{inst, listenerStorage, logger} {}
LocalStorage(const LocalStorage&) = delete;
LocalStorage& operator=(const LocalStorage&) = delete;
@@ -51,8 +52,8 @@ class LocalStorage final : public net::ILocalStorage {
m_impl.RemoveNetworkPublisher(m_impl.GetOrCreateTopic(name));
}
void ServerPropertiesUpdate(std::string_view name, const wpi::util::json& update,
bool ack) final {
void ServerPropertiesUpdate(std::string_view name,
const wpi::util::json& update, bool ack) final {
std::scoped_lock lock{m_mutex};
if (auto topic = m_impl.GetTopicByName(name)) {
m_impl.NetworkPropertiesUpdate(topic, update, ack);
@@ -177,7 +178,8 @@ class LocalStorage final : public net::ILocalStorage {
return topic && topic->Exists();
}
wpi::util::json GetTopicProperty(NT_Topic topicHandle, std::string_view name) {
wpi::util::json GetTopicProperty(NT_Topic topicHandle,
std::string_view name) {
std::scoped_lock lock{m_mutex};
if (auto topic = m_impl.GetTopicByHandle(topicHandle)) {
return topic->properties.value(name, wpi::util::json{});
@@ -262,7 +264,8 @@ class LocalStorage final : public net::ILocalStorage {
}
NT_Publisher Publish(NT_Topic topicHandle, NT_Type type,
std::string_view typeStr, const wpi::util::json& properties,
std::string_view typeStr,
const wpi::util::json& properties,
const PubSubOptions& options) {
std::scoped_lock lock{m_mutex};
if (auto topic = m_impl.GetTopicByHandle(topicHandle)) {

View File

@@ -71,31 +71,40 @@ static unsigned int LevelToFlag(unsigned int level) {
static unsigned int LevelsToEventMask(unsigned int minLevel,
unsigned int maxLevel) {
unsigned int mask = 0;
if (minLevel <= wpi::util::WPI_LOG_CRITICAL && maxLevel >= wpi::util::WPI_LOG_CRITICAL) {
if (minLevel <= wpi::util::WPI_LOG_CRITICAL &&
maxLevel >= wpi::util::WPI_LOG_CRITICAL) {
mask |= kFlagCritical;
}
if (minLevel <= wpi::util::WPI_LOG_ERROR && maxLevel >= wpi::util::WPI_LOG_ERROR) {
if (minLevel <= wpi::util::WPI_LOG_ERROR &&
maxLevel >= wpi::util::WPI_LOG_ERROR) {
mask |= kFlagError;
}
if (minLevel <= wpi::util::WPI_LOG_WARNING && maxLevel >= wpi::util::WPI_LOG_WARNING) {
if (minLevel <= wpi::util::WPI_LOG_WARNING &&
maxLevel >= wpi::util::WPI_LOG_WARNING) {
mask |= kFlagWarning;
}
if (minLevel <= wpi::util::WPI_LOG_INFO && maxLevel >= wpi::util::WPI_LOG_INFO) {
if (minLevel <= wpi::util::WPI_LOG_INFO &&
maxLevel >= wpi::util::WPI_LOG_INFO) {
mask |= kFlagInfo;
}
if (minLevel <= wpi::util::WPI_LOG_DEBUG && maxLevel >= wpi::util::WPI_LOG_DEBUG) {
if (minLevel <= wpi::util::WPI_LOG_DEBUG &&
maxLevel >= wpi::util::WPI_LOG_DEBUG) {
mask |= kFlagDebug;
}
if (minLevel <= wpi::util::WPI_LOG_DEBUG1 && maxLevel >= wpi::util::WPI_LOG_DEBUG1) {
if (minLevel <= wpi::util::WPI_LOG_DEBUG1 &&
maxLevel >= wpi::util::WPI_LOG_DEBUG1) {
mask |= kFlagDebug1;
}
if (minLevel <= wpi::util::WPI_LOG_DEBUG2 && maxLevel >= wpi::util::WPI_LOG_DEBUG2) {
if (minLevel <= wpi::util::WPI_LOG_DEBUG2 &&
maxLevel >= wpi::util::WPI_LOG_DEBUG2) {
mask |= kFlagDebug2;
}
if (minLevel <= wpi::util::WPI_LOG_DEBUG3 && maxLevel >= wpi::util::WPI_LOG_DEBUG3) {
if (minLevel <= wpi::util::WPI_LOG_DEBUG3 &&
maxLevel >= wpi::util::WPI_LOG_DEBUG3) {
mask |= kFlagDebug3;
}
if (minLevel <= wpi::util::WPI_LOG_DEBUG4 && maxLevel >= wpi::util::WPI_LOG_DEBUG4) {
if (minLevel <= wpi::util::WPI_LOG_DEBUG4 &&
maxLevel >= wpi::util::WPI_LOG_DEBUG4) {
mask |= kFlagDebug4;
}
if (mask == 0) {

View File

@@ -27,7 +27,7 @@
namespace wpi::util {
class Logger;
} // namespace wpi
} // namespace wpi::util
namespace wpi::nt::net {
class ILocalStorage;

View File

@@ -126,7 +126,7 @@ void NetworkServer::ServerConnection::ConnectionClosed() {
void NetworkServer::ServerConnection4::ProcessRequest() {
DEBUG1("HTTP request: '{}'", m_request.GetUrl());
wpi::net::UrlParser url{m_request.GetUrl(),
m_request.GetMethod() == wpi::net::HTTP_CONNECT};
m_request.GetMethod() == wpi::net::HTTP_CONNECT};
if (!url.IsValid()) {
// failed to parse URL
SendError(400);
@@ -255,7 +255,8 @@ void NetworkServer::ServerConnection4::ProcessWsUpgrade() {
NetworkServer::NetworkServer(std::string_view persistentFilename,
std::string_view listenAddress, unsigned int port,
net::ILocalStorage& localStorage,
IConnectionList& connList, wpi::util::Logger& logger,
IConnectionList& connList,
wpi::util::Logger& logger,
std::function<void()> initDone)
: m_localStorage{localStorage},
m_connList{connList},

View File

@@ -22,7 +22,7 @@
namespace wpi::util {
class Logger;
} // namespace wpi
} // namespace wpi::util
namespace wpi::nt::net {
class ILocalStorage;

View File

@@ -184,7 +184,8 @@ void wpi::nt::ConvertToC(const Value& in, NT_Value* out) {
break;
case NT_RAW: {
auto v = in.GetRaw();
out->data.v_raw.data = static_cast<uint8_t*>(wpi::util::safe_malloc(v.size()));
out->data.v_raw.data =
static_cast<uint8_t*>(wpi::util::safe_malloc(v.size()));
out->data.v_raw.size = v.size();
std::memcpy(out->data.v_raw.data, v.data(), v.size());
break;
@@ -199,8 +200,8 @@ void wpi::nt::ConvertToC(const Value& in, NT_Value* out) {
}
case NT_INTEGER_ARRAY: {
auto v = in.GetIntegerArray();
out->data.arr_int.arr =
static_cast<int64_t*>(wpi::util::safe_malloc(v.size() * sizeof(int64_t)));
out->data.arr_int.arr = static_cast<int64_t*>(
wpi::util::safe_malloc(v.size() * sizeof(int64_t)));
out->data.arr_int.size = v.size();
std::copy(v.begin(), v.end(), out->data.arr_int.arr);
break;
@@ -215,8 +216,8 @@ void wpi::nt::ConvertToC(const Value& in, NT_Value* out) {
}
case NT_DOUBLE_ARRAY: {
auto v = in.GetDoubleArray();
out->data.arr_double.arr =
static_cast<double*>(wpi::util::safe_malloc(v.size() * sizeof(double)));
out->data.arr_double.arr = static_cast<double*>(
wpi::util::safe_malloc(v.size() * sizeof(double)));
out->data.arr_double.size = v.size();
std::copy(v.begin(), v.end(), out->data.arr_double.arr);
break;

View File

@@ -122,7 +122,8 @@ JNIEXPORT void JNICALL JNI_OnUnload(JavaVM* vm, void* reserved) {
// Conversions from Java objects to C++
//
static wpi::nt::PubSubOptions FromJavaPubSubOptions(JNIEnv* env, jobject joptions) {
static wpi::nt::PubSubOptions FromJavaPubSubOptions(JNIEnv* env,
jobject joptions) {
if (!joptions) {
return {};
}
@@ -299,7 +300,8 @@ static jobject MakeJObject(JNIEnv* env, jobject inst,
static_cast<jint>(data.subentry), value.obj());
}
static jobject MakeJObject(JNIEnv* env, const wpi::nt::TimeSyncEventData& data) {
static jobject MakeJObject(JNIEnv* env,
const wpi::nt::TimeSyncEventData& data) {
static jmethodID constructor =
env->GetMethodID(timeSyncEventDataCls, "<init>", "(JJZ)V");
return env->NewObject(timeSyncEventDataCls, constructor,
@@ -308,7 +310,8 @@ static jobject MakeJObject(JNIEnv* env, const wpi::nt::TimeSyncEventData& data)
static_cast<jboolean>(data.valid));
}
static jobject MakeJObject(JNIEnv* env, jobject inst, const wpi::nt::Event& event) {
static jobject MakeJObject(JNIEnv* env, jobject inst,
const wpi::nt::Event& event) {
static jmethodID constructor =
env->GetMethodID(eventCls, "<init>",
"(Lorg/wpilib/networktables/NetworkTableInstance;II"
@@ -339,7 +342,8 @@ static jobject MakeJObject(JNIEnv* env, jobject inst, const wpi::nt::Event& even
valueData.obj(), logMessage.obj(), timeSyncData.obj());
}
static jobjectArray MakeJObject(JNIEnv* env, std::span<const wpi::nt::Value> arr) {
static jobjectArray MakeJObject(JNIEnv* env,
std::span<const wpi::nt::Value> arr) {
jobjectArray jarr = env->NewObjectArray(arr.size(), valueCls, nullptr);
if (!jarr) {
return nullptr;
@@ -580,7 +584,8 @@ Java_org_wpilib_networktables_NetworkTablesJNI_getTopicInfosStr
typeStrs.emplace_back(typeStrData.back());
}
auto arr = wpi::nt::GetTopicInfo(inst, JStringRef{env, prefix}.str(), typeStrs);
auto arr =
wpi::nt::GetTopicInfo(inst, JStringRef{env, prefix}.str(), typeStrs);
jobjectArray jarr = env->NewObjectArray(arr.size(), topicInfoCls, nullptr);
if (!jarr) {
return nullptr;
@@ -733,8 +738,8 @@ JNIEXPORT jstring JNICALL
Java_org_wpilib_networktables_NetworkTablesJNI_getTopicProperty
(JNIEnv* env, jclass, jint topic, jstring name)
{
return MakeJString(env,
wpi::nt::GetTopicProperty(topic, JStringRef{env, name}).dump());
return MakeJString(
env, wpi::nt::GetTopicProperty(topic, JStringRef{env, name}).dump());
}
/*
@@ -815,8 +820,8 @@ Java_org_wpilib_networktables_NetworkTablesJNI_subscribe
(JNIEnv* env, jclass, jint topic, jint type, jstring typeStr, jobject options)
{
return wpi::nt::Subscribe(topic, static_cast<NT_Type>(type),
JStringRef{env, typeStr},
FromJavaPubSubOptions(env, options));
JStringRef{env, typeStr},
FromJavaPubSubOptions(env, options));
}
/*
@@ -841,8 +846,8 @@ Java_org_wpilib_networktables_NetworkTablesJNI_publish
(JNIEnv* env, jclass, jint topic, jint type, jstring typeStr, jobject options)
{
return wpi::nt::Publish(topic, static_cast<NT_Type>(type),
JStringRef{env, typeStr},
FromJavaPubSubOptions(env, options));
JStringRef{env, typeStr},
FromJavaPubSubOptions(env, options));
}
/*
@@ -868,8 +873,8 @@ Java_org_wpilib_networktables_NetworkTablesJNI_publishEx
return 0;
}
return wpi::nt::PublishEx(topic, static_cast<NT_Type>(type),
JStringRef{env, typeStr}, j,
FromJavaPubSubOptions(env, options));
JStringRef{env, typeStr}, j,
FromJavaPubSubOptions(env, options));
}
/*
@@ -894,8 +899,8 @@ Java_org_wpilib_networktables_NetworkTablesJNI_getEntryImpl
(JNIEnv* env, jclass, jint topic, jint type, jstring typeStr, jobject options)
{
return wpi::nt::GetEntry(topic, static_cast<NT_Type>(type),
JStringRef{env, typeStr},
FromJavaPubSubOptions(env, options));
JStringRef{env, typeStr},
FromJavaPubSubOptions(env, options));
}
/*
@@ -965,7 +970,7 @@ Java_org_wpilib_networktables_NetworkTablesJNI_subscribeMultiple
}
return wpi::nt::SubscribeMultiple(inst, prefixStringViews,
FromJavaPubSubOptions(env, options));
FromJavaPubSubOptions(env, options));
}
/*
@@ -1189,7 +1194,7 @@ Java_org_wpilib_networktables_NetworkTablesJNI_startServer
return;
}
wpi::nt::StartServer(inst, JStringRef{env, persistFilename}.str(),
JStringRef{env, listenAddress}.c_str(), port);
JStringRef{env, listenAddress}.c_str(), port);
}
/*
@@ -1433,9 +1438,9 @@ JNIEXPORT jint JNICALL
Java_org_wpilib_networktables_NetworkTablesJNI_startEntryDataLog
(JNIEnv* env, jclass, jint inst, jlong log, jstring prefix, jstring logPrefix)
{
return wpi::nt::StartEntryDataLog(inst, *reinterpret_cast<wpi::log::DataLog*>(log),
JStringRef{env, prefix},
JStringRef{env, logPrefix});
return wpi::nt::StartEntryDataLog(
inst, *reinterpret_cast<wpi::log::DataLog*>(log), JStringRef{env, prefix},
JStringRef{env, logPrefix});
}
/*

View File

@@ -19,7 +19,8 @@ int LocalDataLogger::Start(std::string_view name, std::string_view typeStr,
} else if (typeStr == "int[]") {
typeStr = "int64[]";
}
return log.Start(fmt::format("{}{}", logPrefix,
wpi::util::remove_prefix(name, prefix).value_or(name)),
typeStr, metadata, time);
return log.Start(
fmt::format("{}{}", logPrefix,
wpi::util::remove_prefix(name, prefix).value_or(name)),
typeStr, metadata, time);
}

View File

@@ -110,7 +110,8 @@ void StorageImpl::RemoveNetworkPublisher(LocalTopic* topic) {
}
void StorageImpl::NetworkPropertiesUpdate(LocalTopic* topic,
const wpi::util::json& update, bool ack) {
const wpi::util::json& update,
bool ack) {
DEBUG4("NetworkPropertiesUpdate({},{})", topic->name, ack);
if (ack) {
return; // ignore acks
@@ -215,7 +216,8 @@ void StorageImpl::SetProperty(LocalTopic* topic, std::string_view name,
true);
}
bool StorageImpl::SetProperties(LocalTopic* topic, const wpi::util::json& update,
bool StorageImpl::SetProperties(LocalTopic* topic,
const wpi::util::json& update,
bool sendNetwork) {
DEBUG4("SetProperties({},{})", topic->name, sendNetwork);
if (!topic->SetProperties(update)) {
@@ -864,7 +866,8 @@ void StorageImpl::NotifyValue(LocalTopic* topic, const Value& value,
}
}
void StorageImpl::PropertiesUpdated(LocalTopic* topic, const wpi::util::json& update,
void StorageImpl::PropertiesUpdated(LocalTopic* topic,
const wpi::util::json& update,
unsigned int eventFlags, bool sendNetwork,
bool updateFlags) {
DEBUG4("PropertiesUpdated({}, {}, {}, {}, {})", topic->name, update.dump(),
@@ -901,9 +904,9 @@ void StorageImpl::RefreshPubSubActive(LocalTopic* topic,
}
}
LocalPublisher* StorageImpl::AddLocalPublisher(LocalTopic* topic,
const wpi::util::json& properties,
const PubSubConfig& config) {
LocalPublisher* StorageImpl::AddLocalPublisher(
LocalTopic* topic, const wpi::util::json& properties,
const PubSubConfig& config) {
bool didExist = topic->Exists();
auto publisher = m_publishers.Add(m_inst, topic, config);
topic->localPublishers.Add(publisher);

View File

@@ -26,7 +26,7 @@
namespace wpi::util {
class Logger;
} // namespace wpi
} // namespace wpi::util
namespace wpi::nt {
class IListenerStorage;
@@ -41,7 +41,8 @@ namespace wpi::nt::local {
// inner struct to protect against accidentally deadlocking on the mutex
class StorageImpl {
public:
StorageImpl(int inst, IListenerStorage& listenerStorage, wpi::util::Logger& logger);
StorageImpl(int inst, IListenerStorage& listenerStorage,
wpi::util::Logger& logger);
wpi::util::Logger& GetLogger() { return m_logger; }
@@ -50,7 +51,8 @@ class StorageImpl {
//
void NetworkAnnounce(LocalTopic* topic, std::string_view typeStr,
const wpi::util::json& properties, std::optional<int> pubuid);
const wpi::util::json& properties,
std::optional<int> pubuid);
void RemoveNetworkPublisher(LocalTopic* topic);
void NetworkPropertiesUpdate(LocalTopic* topic, const wpi::util::json& update,
bool ack);
@@ -156,7 +158,8 @@ class StorageImpl {
const PubSubOptions& options);
LocalPublisher* Publish(LocalTopic* topic, NT_Type type,
std::string_view typeStr, const wpi::util::json& properties,
std::string_view typeStr,
const wpi::util::json& properties,
const PubSubOptions& options);
LocalEntry* GetEntry(LocalTopic* topicHandle, NT_Type type,

View File

@@ -115,7 +115,7 @@ wpi::util::json LocalTopic::SetCached(bool value) {
}
wpi::util::json LocalTopic::SetProperty(std::string_view name,
const wpi::util::json& value) {
const wpi::util::json& value) {
if (value.is_null()) {
properties.erase(name);
} else {

View File

@@ -52,7 +52,8 @@ struct LocalTopic {
wpi::util::json SetPersistent(bool value);
wpi::util::json SetRetained(bool value);
wpi::util::json SetCached(bool value);
wpi::util::json SetProperty(std::string_view name, const wpi::util::json& value);
wpi::util::json SetProperty(std::string_view name,
const wpi::util::json& value);
wpi::util::json DeleteProperty(std::string_view name);
// returns false if not object

View File

@@ -28,7 +28,8 @@ using namespace wpi::nt;
using namespace wpi::nt::net;
ClientImpl::ClientImpl(
uint64_t curTimeMs, WireConnection& wire, bool local, wpi::util::Logger& logger,
uint64_t curTimeMs, WireConnection& wire, bool local,
wpi::util::Logger& logger,
std::function<void(int64_t serverTimeOffset, int64_t rtt2, bool valid)>
timeSyncUpdated,
std::function<void(uint32_t repeatMs)> setPeriodic)
@@ -165,7 +166,8 @@ void ClientImpl::UpdatePeriodic() {
}
void ClientImpl::Publish(int32_t pubuid, std::string_view name,
std::string_view typeStr, const wpi::util::json& properties,
std::string_view typeStr,
const wpi::util::json& properties,
const PubSubOptionsImpl& options) {
if (static_cast<uint32_t>(pubuid) >= m_publishers.size()) {
m_publishers.resize(pubuid + 1);
@@ -239,7 +241,8 @@ void ClientImpl::ServerUnannounce(std::string_view name, int id) {
}
void ClientImpl::ServerPropertiesUpdate(std::string_view name,
const wpi::util::json& update, bool ack) {
const wpi::util::json& update,
bool ack) {
DEBUG4("ServerProperties({}, {}, {})", name, update.dump(), ack);
assert(m_local);
m_local->ServerPropertiesUpdate(name, update, ack);

View File

@@ -22,7 +22,7 @@
namespace wpi::util {
class Logger;
} // namespace wpi
} // namespace wpi::util
namespace wpi::nt {
class PubSubOptionsImpl;
@@ -37,7 +37,8 @@ class WireConnection;
class ClientImpl final : private ServerMessageHandler {
public:
ClientImpl(
uint64_t curTimeMs, WireConnection& wire, bool local, wpi::util::Logger& logger,
uint64_t curTimeMs, WireConnection& wire, bool local,
wpi::util::Logger& logger,
std::function<void(int64_t serverTimeOffset, int64_t rtt2, bool valid)>
timeSyncUpdated,
std::function<void(uint32_t repeatMs)> setPeriodic);
@@ -66,12 +67,13 @@ class ClientImpl final : private ServerMessageHandler {
const wpi::util::json& properties,
std::optional<int> pubuid) final;
void ServerUnannounce(std::string_view name, int id) final;
void ServerPropertiesUpdate(std::string_view name, const wpi::util::json& update,
bool ack) final;
void ServerPropertiesUpdate(std::string_view name,
const wpi::util::json& update, bool ack) final;
void ServerSetValue(int topicId, const Value& value) final;
void Publish(int pubuid, std::string_view name, std::string_view typeStr,
const wpi::util::json& properties, const PubSubOptionsImpl& options);
const wpi::util::json& properties,
const PubSubOptionsImpl& options);
void Unpublish(int pubuid, ClientMessage&& msg);
void SetValue(int pubuid, const Value& value);

View File

@@ -15,7 +15,7 @@
namespace wpi::util {
class Logger;
} // namespace wpi
} // namespace wpi::util
namespace wpi::nt::net {
@@ -35,7 +35,8 @@ class ClientMessageQueueImpl final : public ClientMessageHandler,
public:
static constexpr size_t kBlockSize = 64;
explicit ClientMessageQueueImpl(wpi::util::Logger& logger) : m_logger{logger} {}
explicit ClientMessageQueueImpl(wpi::util::Logger& logger)
: m_logger{logger} {}
bool empty() const { return m_queue.empty(); }
@@ -71,7 +72,8 @@ class ClientMessageQueueImpl final : public ClientMessageHandler,
// ClientMessageHandler - calls to these append to the queue
void ClientPublish(int pubuid, std::string_view name,
std::string_view typeStr, const wpi::util::json& properties,
std::string_view typeStr,
const wpi::util::json& properties,
const PubSubOptionsImpl& options) final {
std::scoped_lock lock{m_mutex};
m_queue.enqueue(ClientMessage{PublishMsg{

View File

@@ -45,7 +45,8 @@ class ServerMessageHandler {
std::optional<int> pubuid) = 0;
virtual void ServerUnannounce(std::string_view name, int id) = 0;
virtual void ServerPropertiesUpdate(std::string_view name,
const wpi::util::json& update, bool ack) = 0;
const wpi::util::json& update,
bool ack) = 0;
virtual void ServerSetValue(int topicuid, const Value& value) = 0;
};

View File

@@ -124,7 +124,8 @@ void WebSocketConnection::SendPing(uint64_t time) {
WPI_DEBUG4(m_logger, "conn: sending ping {}", time);
auto buf = AllocBuf();
buf.len = 8;
wpi::util::support::endian::write64<wpi::util::endianness::native>(buf.base, time);
wpi::util::support::endian::write64<wpi::util::endianness::native>(buf.base,
time);
m_ws.SendPing({buf}, [selfweak = weak_from_this()](auto bufs, auto err) {
if (auto self = selfweak.lock()) {
self->m_err = err;
@@ -153,7 +154,8 @@ void WebSocketConnection::FinishText() {
}
int WebSocketConnection::Write(
State kind, wpi::util::function_ref<void(wpi::util::raw_ostream& os)> writer) {
State kind,
wpi::util::function_ref<void(wpi::util::raw_ostream& os)> writer) {
bool first = false;
if (m_state != kind ||
(m_state == kind && m_framePos >= kNewFrameThresholdBytes)) {
@@ -243,7 +245,8 @@ int WebSocketConnection::Flush() {
}
void WebSocketConnection::Send(
uint8_t opcode, wpi::util::function_ref<void(wpi::util::raw_ostream& os)> writer) {
uint8_t opcode,
wpi::util::function_ref<void(wpi::util::raw_ostream& os)> writer) {
wpi::util::SmallVector<wpi::net::uv::Buffer, 4> bufs;
wpi::net::raw_uv_ostream os{bufs, [this] { return AllocBuf(); }};
if (opcode == wpi::net::WebSocket::Frame::kText) {

View File

@@ -17,7 +17,7 @@
namespace wpi::util {
class Logger;
} // namespace wpi
} // namespace wpi::util
namespace wpi::nt::net {
@@ -37,18 +37,22 @@ class WebSocketConnection final
bool Ready() const final { return !m_ws.IsWriteInProgress(); }
int WriteText(wpi::util::function_ref<void(wpi::util::raw_ostream& os)> writer) final {
int WriteText(
wpi::util::function_ref<void(wpi::util::raw_ostream& os)> writer) final {
return Write(kText, writer);
}
int WriteBinary(wpi::util::function_ref<void(wpi::util::raw_ostream& os)> writer) final {
int WriteBinary(
wpi::util::function_ref<void(wpi::util::raw_ostream& os)> writer) final {
return Write(kBinary, writer);
}
int Flush() final;
void SendText(wpi::util::function_ref<void(wpi::util::raw_ostream& os)> writer) final {
void SendText(
wpi::util::function_ref<void(wpi::util::raw_ostream& os)> writer) final {
Send(wpi::net::WebSocket::Frame::kText, writer);
}
void SendBinary(wpi::util::function_ref<void(wpi::util::raw_ostream& os)> writer) final {
void SendBinary(
wpi::util::function_ref<void(wpi::util::raw_ostream& os)> writer) final {
Send(wpi::net::WebSocket::Frame::kBinary, writer);
}
@@ -78,7 +82,8 @@ class WebSocketConnection final
private:
enum State { kEmpty, kText, kBinary };
int Write(State kind, wpi::util::function_ref<void(wpi::util::raw_ostream& os)> writer);
int Write(State kind,
wpi::util::function_ref<void(wpi::util::raw_ostream& os)> writer);
void Send(uint8_t opcode,
wpi::util::function_ref<void(wpi::util::raw_ostream& os)> writer);

View File

@@ -12,7 +12,7 @@
namespace wpi::util {
class raw_ostream;
} // namespace wpi
} // namespace wpi::util
namespace wpi::nt::net {

View File

@@ -47,8 +47,8 @@ static bool GetNumber(wpi::util::json& val, int64_t* num) {
return true;
}
static std::string* ObjGetString(wpi::util::json::object_t& obj, std::string_view key,
std::string* error) {
static std::string* ObjGetString(wpi::util::json::object_t& obj,
std::string_view key, std::string* error) {
auto it = obj.find(key);
if (it == obj.end()) {
*error = fmt::format("no {} key", key);
@@ -75,8 +75,8 @@ static bool ObjGetNumber(wpi::util::json::object_t& obj, std::string_view key,
return true;
}
static bool ObjGetStringArray(wpi::util::json::object_t& obj, std::string_view key,
std::string* error,
static bool ObjGetStringArray(wpi::util::json::object_t& obj,
std::string_view key, std::string* error,
std::vector<std::string>* out) {
// prefixes
auto it = obj.find(key);
@@ -174,7 +174,8 @@ static bool WireDecodeTextImpl(std::string_view in, T& out,
goto err;
}
// limit to 32-bit range and exclude endpoints used by wpi::util::DenseMap
// limit to 32-bit range and exclude endpoints used by
// wpi::util::DenseMap
if (pubuid >= 0x7fffffffLL || pubuid <= (-0x7fffffffLL - 1)) {
error = "pubuid out of range";
goto err;
@@ -206,7 +207,8 @@ static bool WireDecodeTextImpl(std::string_view in, T& out,
goto err;
}
// limit to 32-bit range and exclude endpoints used by wpi::util::DenseMap
// limit to 32-bit range and exclude endpoints used by
// wpi::util::DenseMap
if (pubuid >= 0x7fffffffLL || pubuid <= (-0x7fffffffLL - 1)) {
error = "pubuid out of range";
goto err;
@@ -243,7 +245,8 @@ static bool WireDecodeTextImpl(std::string_view in, T& out,
goto err;
}
// limit to 32-bit range and exclude endpoints used by wpi::util::DenseMap
// limit to 32-bit range and exclude endpoints used by
// wpi::util::DenseMap
if (subuid >= 0x7fffffffLL || subuid <= (-0x7fffffffLL - 1)) {
error = "subuid out of range";
goto err;
@@ -253,7 +256,8 @@ static bool WireDecodeTextImpl(std::string_view in, T& out,
PubSubOptionsImpl options;
auto optionsIt = params->find("options");
if (optionsIt != params->end()) {
auto joptions = optionsIt->second.get_ptr<wpi::util::json::object_t*>();
auto joptions =
optionsIt->second.get_ptr<wpi::util::json::object_t*>();
if (!joptions) {
error = "options must be an object";
goto err;
@@ -321,7 +325,8 @@ static bool WireDecodeTextImpl(std::string_view in, T& out,
goto err;
}
// limit to 32-bit range and exclude endpoints used by wpi::util::DenseMap
// limit to 32-bit range and exclude endpoints used by
// wpi::util::DenseMap
if (subuid >= 0x7fffffffLL || subuid <= (-0x7fffffffLL - 1)) {
error = "pubuid out of range";
goto err;
@@ -348,7 +353,8 @@ static bool WireDecodeTextImpl(std::string_view in, T& out,
goto err;
}
// limit to 32-bit range and exclude endpoints used by wpi::util::DenseMap
// limit to 32-bit range and exclude endpoints used by
// wpi::util::DenseMap
if (id >= 0x7fffffffLL || id <= (-0x7fffffffLL - 1)) {
error = "id out of range";
goto err;
@@ -370,7 +376,8 @@ static bool WireDecodeTextImpl(std::string_view in, T& out,
goto err;
}
// limit to 32-bit range and exclude endpoints used by wpi::util::DenseMap
// limit to 32-bit range and exclude endpoints used by
// wpi::util::DenseMap
if (val >= 0x7fffffffLL || val <= (-0x7fffffffLL - 1)) {
error = "pubuid out of range";
goto err;
@@ -406,7 +413,8 @@ static bool WireDecodeTextImpl(std::string_view in, T& out,
goto err;
}
// limit to 32-bit range and exclude endpoints used by wpi::util::DenseMap
// limit to 32-bit range and exclude endpoints used by
// wpi::util::DenseMap
if (id >= 0x7fffffffLL || id <= (-0x7fffffffLL - 1)) {
error = "id out of range";
goto err;
@@ -464,19 +472,21 @@ static bool WireDecodeTextImpl(std::string_view in, T& out,
#pragma clang diagnostic pop
#endif
bool wpi::nt::net::WireDecodeText(std::string_view in, ClientMessageHandler& out,
wpi::util::Logger& logger) {
bool wpi::nt::net::WireDecodeText(std::string_view in,
ClientMessageHandler& out,
wpi::util::Logger& logger) {
return ::WireDecodeTextImpl(in, out, logger);
}
void wpi::nt::net::WireDecodeText(std::string_view in, ServerMessageHandler& out,
wpi::util::Logger& logger) {
void wpi::nt::net::WireDecodeText(std::string_view in,
ServerMessageHandler& out,
wpi::util::Logger& logger) {
::WireDecodeTextImpl(in, out, logger);
}
bool wpi::nt::net::WireDecodeBinary(std::span<const uint8_t>* in, int* outId,
Value* outValue, std::string* error,
int64_t localTimeOffset) {
Value* outValue, std::string* error,
int64_t localTimeOffset) {
mpack_reader_t reader;
mpack_reader_init_data(&reader, reinterpret_cast<const char*>(in->data()),
in->size());

View File

@@ -12,7 +12,7 @@
namespace wpi::util {
class Logger;
} // namespace wpi
} // namespace wpi::util
namespace wpi::nt {
class Value;

View File

@@ -19,8 +19,9 @@ using namespace wpi::nt::net;
using namespace mpack;
void wpi::nt::net::WireEncodePublish(wpi::util::raw_ostream& os, int pubuid,
std::string_view name, std::string_view typeStr,
const wpi::util::json& properties) {
std::string_view name,
std::string_view typeStr,
const wpi::util::json& properties) {
wpi::util::json::serializer s{os, ' ', 0};
os << "{\"method\":\"" << PublishMsg::kMethodStr << "\",\"params\":{";
os << "\"name\":\"";
@@ -43,8 +44,8 @@ void wpi::nt::net::WireEncodeUnpublish(wpi::util::raw_ostream& os, int pubuid) {
}
void wpi::nt::net::WireEncodeSetProperties(wpi::util::raw_ostream& os,
std::string_view name,
const wpi::util::json& update) {
std::string_view name,
const wpi::util::json& update) {
wpi::util::json::serializer s{os, ' ', 0};
os << "{\"method\":\"" << SetPropertiesMsg::kMethodStr << "\",\"params\":{";
os << "\"name\":\"";
@@ -55,7 +56,8 @@ void wpi::nt::net::WireEncodeSetProperties(wpi::util::raw_ostream& os,
}
template <typename T>
static void EncodePrefixes(wpi::util::raw_ostream& os, std::span<const T> topicNames,
static void EncodePrefixes(wpi::util::raw_ostream& os,
std::span<const T> topicNames,
wpi::util::json::serializer& s) {
os << '[';
bool first = true;
@@ -112,19 +114,21 @@ static void WireEncodeSubscribeImpl(wpi::util::raw_ostream& os, int subuid,
os << "}}";
}
void wpi::nt::net::WireEncodeSubscribe(wpi::util::raw_ostream& os, int subuid,
std::span<const std::string_view> topicNames,
const PubSubOptionsImpl& options) {
void wpi::nt::net::WireEncodeSubscribe(
wpi::util::raw_ostream& os, int subuid,
std::span<const std::string_view> topicNames,
const PubSubOptionsImpl& options) {
WireEncodeSubscribeImpl(os, subuid, topicNames, options);
}
void wpi::nt::net::WireEncodeSubscribe(wpi::util::raw_ostream& os, int subuid,
std::span<const std::string> topicNames,
const PubSubOptionsImpl& options) {
std::span<const std::string> topicNames,
const PubSubOptionsImpl& options) {
WireEncodeSubscribeImpl(os, subuid, topicNames, options);
}
void wpi::nt::net::WireEncodeUnsubscribe(wpi::util::raw_ostream& os, int subuid) {
void wpi::nt::net::WireEncodeUnsubscribe(wpi::util::raw_ostream& os,
int subuid) {
wpi::util::json::serializer s{os, ' ', 0};
os << "{\"method\":\"" << UnsubscribeMsg::kMethodStr << "\",\"params\":{";
os << "\"subuid\":";
@@ -132,7 +136,8 @@ void wpi::nt::net::WireEncodeUnsubscribe(wpi::util::raw_ostream& os, int subuid)
os << "}}";
}
bool wpi::nt::net::WireEncodeText(wpi::util::raw_ostream& os, const ClientMessage& msg) {
bool wpi::nt::net::WireEncodeText(wpi::util::raw_ostream& os,
const ClientMessage& msg) {
if (auto m = std::get_if<PublishMsg>(&msg.contents)) {
WireEncodePublish(os, m->pubuid, m->name, m->typeStr, m->properties);
} else if (auto m = std::get_if<UnpublishMsg>(&msg.contents)) {
@@ -149,10 +154,11 @@ bool wpi::nt::net::WireEncodeText(wpi::util::raw_ostream& os, const ClientMessag
return true;
}
void wpi::nt::net::WireEncodeAnnounce(wpi::util::raw_ostream& os, std::string_view name,
int id, std::string_view typeStr,
const wpi::util::json& properties,
std::optional<int> pubuid) {
void wpi::nt::net::WireEncodeAnnounce(wpi::util::raw_ostream& os,
std::string_view name, int id,
std::string_view typeStr,
const wpi::util::json& properties,
std::optional<int> pubuid) {
wpi::util::json::serializer s{os, ' ', 0};
os << "{\"method\":\"" << AnnounceMsg::kMethodStr << "\",\"params\":{";
os << "\"id\":";
@@ -170,8 +176,8 @@ void wpi::nt::net::WireEncodeAnnounce(wpi::util::raw_ostream& os, std::string_vi
os << "\"}}";
}
void wpi::nt::net::WireEncodeUnannounce(wpi::util::raw_ostream& os, std::string_view name,
int64_t id) {
void wpi::nt::net::WireEncodeUnannounce(wpi::util::raw_ostream& os,
std::string_view name, int64_t id) {
wpi::util::json::serializer s{os, ' ', 0};
os << "{\"method\":\"" << UnannounceMsg::kMethodStr << "\",\"params\":{";
os << "\"id\":";
@@ -182,8 +188,9 @@ void wpi::nt::net::WireEncodeUnannounce(wpi::util::raw_ostream& os, std::string_
}
void wpi::nt::net::WireEncodePropertiesUpdate(wpi::util::raw_ostream& os,
std::string_view name,
const wpi::util::json& update, bool ack) {
std::string_view name,
const wpi::util::json& update,
bool ack) {
wpi::util::json::serializer s{os, ' ', 0};
os << "{\"method\":\"" << PropertiesUpdateMsg::kMethodStr
<< "\",\"params\":{";
@@ -197,7 +204,8 @@ void wpi::nt::net::WireEncodePropertiesUpdate(wpi::util::raw_ostream& os,
os << "}}";
}
bool wpi::nt::net::WireEncodeText(wpi::util::raw_ostream& os, const ServerMessage& msg) {
bool wpi::nt::net::WireEncodeText(wpi::util::raw_ostream& os,
const ServerMessage& msg) {
if (auto m = std::get_if<AnnounceMsg>(&msg.contents)) {
WireEncodeAnnounce(os, m->name, m->id, m->typeStr, m->properties,
m->pubuid);
@@ -211,16 +219,16 @@ bool wpi::nt::net::WireEncodeText(wpi::util::raw_ostream& os, const ServerMessag
return true;
}
bool wpi::nt::net::WireEncodeBinary(wpi::util::raw_ostream& os, int id, int64_t time,
const Value& value) {
bool wpi::nt::net::WireEncodeBinary(wpi::util::raw_ostream& os, int id,
int64_t time, const Value& value) {
char buf[128];
mpack_writer_t writer;
mpack_writer_init(&writer, buf, sizeof(buf));
mpack_writer_set_context(&writer, &os);
mpack_writer_set_flush(
&writer, [](mpack_writer_t* writer, const char* buffer, size_t count) {
static_cast<wpi::util::raw_ostream*>(writer->context)->write(buffer, count);
});
mpack_writer_set_flush(&writer, [](mpack_writer_t* writer, const char* buffer,
size_t count) {
static_cast<wpi::util::raw_ostream*>(writer->context)->write(buffer, count);
});
mpack_start_array(&writer, 4);
mpack_write_int(&writer, id);
mpack_write_int(&writer, time);

View File

@@ -13,7 +13,7 @@
namespace wpi::util {
class raw_ostream;
} // namespace wpi
} // namespace wpi::util
namespace wpi::nt {
class PubSubOptionsImpl;
@@ -26,8 +26,9 @@ struct ClientMessage;
struct ServerMessage;
// encoders for client text messages (avoids need to construct a Message struct)
void WireEncodePublish(wpi::util::raw_ostream& os, int pubuid, std::string_view name,
std::string_view typeStr, const wpi::util::json& properties);
void WireEncodePublish(wpi::util::raw_ostream& os, int pubuid,
std::string_view name, std::string_view typeStr,
const wpi::util::json& properties);
void WireEncodeUnpublish(wpi::util::raw_ostream& os, int pubuid);
void WireEncodeSetProperties(wpi::util::raw_ostream& os, std::string_view name,
const wpi::util::json& update);
@@ -40,12 +41,14 @@ void WireEncodeSubscribe(wpi::util::raw_ostream& os, int subuid,
void WireEncodeUnsubscribe(wpi::util::raw_ostream& os, int subuid);
// encoders for server text messages (avoids need to construct a Message struct)
void WireEncodeAnnounce(wpi::util::raw_ostream& os, std::string_view name, int id,
std::string_view typeStr, const wpi::util::json& properties,
void WireEncodeAnnounce(wpi::util::raw_ostream& os, std::string_view name,
int id, std::string_view typeStr,
const wpi::util::json& properties,
std::optional<int> pubuid);
void WireEncodeUnannounce(wpi::util::raw_ostream& os, std::string_view name,
int64_t id);
void WireEncodePropertiesUpdate(wpi::util::raw_ostream& os, std::string_view name,
void WireEncodePropertiesUpdate(wpi::util::raw_ostream& os,
std::string_view name,
const wpi::util::json& update, bool ack);
// Encode a single message; note text messages must be put into a

View File

@@ -46,9 +46,9 @@ std::string NetworkTable::NormalizeKey(std::string_view key,
return std::string{NormalizeKey(key, buf, withLeadingSlash)};
}
std::string_view NetworkTable::NormalizeKey(std::string_view key,
wpi::util::SmallVectorImpl<char>& buf,
bool withLeadingSlash) {
std::string_view NetworkTable::NormalizeKey(
std::string_view key, wpi::util::SmallVectorImpl<char>& buf,
bool withLeadingSlash) {
buf.clear();
if (withLeadingSlash) {
buf.push_back(PATH_SEPARATOR_CHAR);
@@ -412,7 +412,8 @@ NT_Listener NetworkTable::AddSubTableListener(SubTableListener listener) {
if (!topicInfo) {
return;
}
auto relative_key = wpi::util::substr(topicInfo->name, m_path.size() + 1);
auto relative_key =
wpi::util::substr(topicInfo->name, m_path.size() + 1);
auto end_sub_table = relative_key.find(PATH_SEPARATOR_CHAR);
if (end_sub_table == std::string_view::npos) {
return;

View File

@@ -112,18 +112,20 @@ NT_Listener NetworkTableInstance::AddListener(Topic topic,
wpi::util::print(stderr, "AddListener: topic is not from this instance\n");
return 0;
}
return ::wpi::nt::AddListener(topic.GetHandle(), eventMask, std::move(listener));
return ::wpi::nt::AddListener(topic.GetHandle(), eventMask,
std::move(listener));
}
NT_Listener NetworkTableInstance::AddListener(Subscriber& subscriber,
unsigned int eventMask,
ListenerCallback listener) {
if (::wpi::nt::GetInstanceFromHandle(subscriber.GetHandle()) != m_handle) {
wpi::util::print(stderr, "AddListener: subscriber is not from this instance\n");
wpi::util::print(stderr,
"AddListener: subscriber is not from this instance\n");
return 0;
}
return ::wpi::nt::AddListener(subscriber.GetHandle(), eventMask,
std::move(listener));
std::move(listener));
}
NT_Listener NetworkTableInstance::AddListener(const NetworkTableEntry& entry,
@@ -133,16 +135,18 @@ NT_Listener NetworkTableInstance::AddListener(const NetworkTableEntry& entry,
wpi::util::print(stderr, "AddListener: entry is not from this instance\n");
return 0;
}
return ::wpi::nt::AddListener(entry.GetHandle(), eventMask, std::move(listener));
return ::wpi::nt::AddListener(entry.GetHandle(), eventMask,
std::move(listener));
}
NT_Listener NetworkTableInstance::AddListener(MultiSubscriber& subscriber,
int eventMask,
ListenerCallback listener) {
if (::wpi::nt::GetInstanceFromHandle(subscriber.GetHandle()) != m_handle) {
wpi::util::print(stderr, "AddListener: subscriber is not from this instance\n");
wpi::util::print(stderr,
"AddListener: subscriber is not from this instance\n");
return 0;
}
return ::wpi::nt::AddListener(subscriber.GetHandle(), eventMask,
std::move(listener));
std::move(listener));
}

View File

@@ -45,9 +45,9 @@ GenericPublisher Topic::GenericPublish(std::string_view typeString,
GenericPublisher Topic::GenericPublishEx(std::string_view typeString,
const wpi::util::json& properties,
const PubSubOptions& options) {
return GenericPublisher{::wpi::nt::PublishEx(m_handle,
::wpi::nt::GetTypeFromString(typeString),
typeString, properties, options)};
return GenericPublisher{
::wpi::nt::PublishEx(m_handle, ::wpi::nt::GetTypeFromString(typeString),
typeString, properties, options)};
}
GenericEntry Topic::GetGenericEntry(const PubSubOptions& options) {

View File

@@ -218,7 +218,8 @@ struct NT_Value* NT_ReadQueueValueType(NT_Handle subentry, unsigned int types,
NT_Topic* NT_GetTopics(NT_Inst inst, const struct WPI_String* prefix,
unsigned int types, size_t* count) {
auto info_v = wpi::nt::GetTopics(inst, wpi::util::to_string_view(prefix), types);
auto info_v =
wpi::nt::GetTopics(inst, wpi::util::to_string_view(prefix), types);
return ConvertToC<NT_Topic>(info_v, count);
}
@@ -230,14 +231,16 @@ NT_Topic* NT_GetTopicsStr(NT_Inst inst, const struct WPI_String* prefix,
for (size_t i = 0; i < types_len; ++i) {
typesCpp.emplace_back(wpi::util::to_string_view(&types[i]));
}
auto info_v = wpi::nt::GetTopics(inst, wpi::util::to_string_view(prefix), typesCpp);
auto info_v =
wpi::nt::GetTopics(inst, wpi::util::to_string_view(prefix), typesCpp);
return ConvertToC<NT_Topic>(info_v, count);
}
struct NT_TopicInfo* NT_GetTopicInfos(NT_Inst inst,
const struct WPI_String* prefix,
unsigned int types, size_t* count) {
auto info_v = wpi::nt::GetTopicInfo(inst, wpi::util::to_string_view(prefix), types);
auto info_v =
wpi::nt::GetTopicInfo(inst, wpi::util::to_string_view(prefix), types);
return ConvertToC<NT_TopicInfo>(info_v, count);
}
@@ -250,7 +253,8 @@ struct NT_TopicInfo* NT_GetTopicInfosStr(NT_Inst inst,
for (size_t i = 0; i < types_len; ++i) {
typesCpp.emplace_back(wpi::util::to_string_view(&types[i]));
}
auto info_v = wpi::nt::GetTopicInfo(inst, wpi::util::to_string_view(prefix), typesCpp);
auto info_v =
wpi::nt::GetTopicInfo(inst, wpi::util::to_string_view(prefix), typesCpp);
return ConvertToC<NT_TopicInfo>(info_v, count);
}
@@ -309,7 +313,8 @@ NT_Bool NT_GetTopicExists(NT_Handle handle) {
void NT_GetTopicProperty(NT_Topic topic, const struct WPI_String* name,
struct WPI_String* prop) {
wpi::util::json j = wpi::nt::GetTopicProperty(topic, wpi::util::to_string_view(name));
wpi::util::json j =
wpi::nt::GetTopicProperty(topic, wpi::util::to_string_view(name));
wpi::nt::ConvertToC(j.dump(), prop);
}
@@ -349,7 +354,7 @@ NT_Subscriber NT_Subscribe(NT_Topic topic, NT_Type type,
const struct WPI_String* typeStr,
const struct NT_PubSubOptions* options) {
return wpi::nt::Subscribe(topic, type, wpi::util::to_string_view(typeStr),
ConvertToCpp(options));
ConvertToCpp(options));
}
void NT_Unsubscribe(NT_Subscriber sub) {
@@ -360,7 +365,7 @@ NT_Publisher NT_Publish(NT_Topic topic, NT_Type type,
const struct WPI_String* typeStr,
const struct NT_PubSubOptions* options) {
return wpi::nt::Publish(topic, type, wpi::util::to_string_view(typeStr),
ConvertToCpp(options));
ConvertToCpp(options));
}
NT_Publisher NT_PublishEx(NT_Topic topic, NT_Type type,
@@ -380,7 +385,7 @@ NT_Publisher NT_PublishEx(NT_Topic topic, NT_Type type,
}
return wpi::nt::PublishEx(topic, type, wpi::util::to_string_view(typeStr), j,
ConvertToCpp(options));
ConvertToCpp(options));
}
void NT_Unpublish(NT_Handle pubentry) {
@@ -391,7 +396,7 @@ NT_Entry NT_GetEntryEx(NT_Topic topic, NT_Type type,
const struct WPI_String* typeStr,
const struct NT_PubSubOptions* options) {
return wpi::nt::GetEntry(topic, type, wpi::util::to_string_view(typeStr),
ConvertToCpp(options));
ConvertToCpp(options));
}
void NT_ReleaseEntry(NT_Entry entry) {
@@ -529,7 +534,7 @@ void NT_StartServer(NT_Inst inst, const struct WPI_String* persist_filename,
const struct WPI_String* listen_address,
unsigned int port) {
wpi::nt::StartServer(inst, wpi::util::to_string_view(persist_filename),
wpi::util::to_string_view(listen_address), port);
wpi::util::to_string_view(listen_address), port);
}
void NT_StopServer(NT_Inst inst) {
@@ -619,9 +624,9 @@ void NT_SetNow(int64_t timestamp) {
NT_DataLogger NT_StartEntryDataLog(NT_Inst inst, struct WPI_DataLog* log,
const struct WPI_String* prefix,
const struct WPI_String* logPrefix) {
return wpi::nt::StartEntryDataLog(inst, *reinterpret_cast<wpi::log::DataLog*>(log),
wpi::util::to_string_view(prefix),
wpi::util::to_string_view(logPrefix));
return wpi::nt::StartEntryDataLog(
inst, *reinterpret_cast<wpi::log::DataLog*>(log),
wpi::util::to_string_view(prefix), wpi::util::to_string_view(logPrefix));
}
void NT_StopEntryDataLog(NT_DataLogger logger) {
@@ -630,9 +635,9 @@ void NT_StopEntryDataLog(NT_DataLogger logger) {
NT_ConnectionDataLogger NT_StartConnectionDataLog(
NT_Inst inst, struct WPI_DataLog* log, const struct WPI_String* name) {
return wpi::nt::StartConnectionDataLog(inst,
*reinterpret_cast<wpi::log::DataLog*>(log),
wpi::util::to_string_view(name));
return wpi::nt::StartConnectionDataLog(
inst, *reinterpret_cast<wpi::log::DataLog*>(log),
wpi::util::to_string_view(name));
}
void NT_StopConnectionDataLog(NT_ConnectionDataLogger logger) {
@@ -662,8 +667,8 @@ NT_Bool NT_HasSchema(NT_Inst inst, const struct WPI_String* name) {
void NT_AddSchema(NT_Inst inst, const struct WPI_String* name,
const struct WPI_String* type, const uint8_t* schema,
size_t schemaSize) {
wpi::nt::AddSchema(inst, wpi::util::to_string_view(name), wpi::util::to_string_view(type),
{schema, schemaSize});
wpi::nt::AddSchema(inst, wpi::util::to_string_view(name),
wpi::util::to_string_view(type), {schema, schemaSize});
}
void NT_DisposeValue(NT_Value* value) {
@@ -754,7 +759,8 @@ void NT_DisposeEvent(NT_Event* event) {
/* Array and Struct Allocations */
char* NT_AllocateCharArray(size_t size) {
char* retVal = static_cast<char*>(wpi::util::safe_malloc(size * sizeof(char)));
char* retVal =
static_cast<char*>(wpi::util::safe_malloc(size * sizeof(char)));
return retVal;
}
@@ -770,7 +776,8 @@ int64_t* NT_AllocateIntegerArray(size_t size) {
}
float* NT_AllocateFloatArray(size_t size) {
float* retVal = static_cast<float*>(wpi::util::safe_malloc(size * sizeof(float)));
float* retVal =
static_cast<float*>(wpi::util::safe_malloc(size * sizeof(float)));
return retVal;
}

View File

@@ -39,8 +39,8 @@ static SubscriberOptions DecodeSubscriberOptions(mpack_reader_t& r) {
return options;
}
std::optional<std::vector<ClientPublisher>> wpi::nt::meta::DecodeClientPublishers(
std::span<const uint8_t> data) {
std::optional<std::vector<ClientPublisher>>
wpi::nt::meta::DecodeClientPublishers(std::span<const uint8_t> data) {
mpack_reader_t r;
mpack_reader_init_data(&r, data);
uint32_t numPub = mpack_expect_array_max(&r, 10000);
@@ -71,8 +71,8 @@ std::optional<std::vector<ClientPublisher>> wpi::nt::meta::DecodeClientPublisher
}
}
std::optional<std::vector<ClientSubscriber>> wpi::nt::meta::DecodeClientSubscribers(
std::span<const uint8_t> data) {
std::optional<std::vector<ClientSubscriber>>
wpi::nt::meta::DecodeClientSubscribers(std::span<const uint8_t> data) {
mpack_reader_t r;
mpack_reader_init_data(&r, data);
uint32_t numSub = mpack_expect_array_max(&r, 10000);
@@ -145,8 +145,8 @@ std::optional<std::vector<TopicPublisher>> wpi::nt::meta::DecodeTopicPublishers(
}
}
std::optional<std::vector<TopicSubscriber>> wpi::nt::meta::DecodeTopicSubscribers(
std::span<const uint8_t> data) {
std::optional<std::vector<TopicSubscriber>>
wpi::nt::meta::DecodeTopicSubscribers(std::span<const uint8_t> data) {
mpack_reader_t r;
mpack_reader_init_data(&r, data);
uint32_t numSub = mpack_expect_array_max(&r, 1000);

View File

@@ -22,8 +22,8 @@ struct NT_TopicInfo* NT_GetTopicInfoForTesting(const char* name,
enum NT_Type type,
const char* type_str,
int* struct_size) {
struct NT_TopicInfo* topic_info =
static_cast<NT_TopicInfo*>(wpi::util::safe_calloc(1, sizeof(NT_TopicInfo)));
struct NT_TopicInfo* topic_info = static_cast<NT_TopicInfo*>(
wpi::util::safe_calloc(1, sizeof(NT_TopicInfo)));
wpi::nt::ConvertToC(name, &topic_info->name);
topic_info->type = type;
wpi::nt::ConvertToC(type_str, &topic_info->type_str);

View File

@@ -17,10 +17,10 @@ struct Writer : public mpack::mpack_writer_t {
Writer() {
mpack::mpack_writer_init(this, buf, sizeof(buf));
mpack::mpack_writer_set_context(this, &os);
mpack::mpack_writer_set_flush(
this, [](mpack::mpack_writer_t* w, const char* buffer, size_t count) {
static_cast<wpi::util::raw_ostream*>(w->context)->write(buffer, count);
});
mpack::mpack_writer_set_flush(this, [](mpack::mpack_writer_t* w,
const char* buffer, size_t count) {
static_cast<wpi::util::raw_ostream*>(w->context)->write(buffer, count);
});
}
std::vector<uint8_t> bytes;

View File

@@ -23,7 +23,7 @@ namespace wpi::util {
class Logger;
template <typename T>
class SmallVectorImpl;
} // namespace wpi
} // namespace wpi::util
namespace wpi::nt::server {
@@ -55,7 +55,8 @@ class ServerClient {
net::ValueSendMode mode) = 0;
virtual void SendAnnounce(ServerTopic* topic, std::optional<int> pubuid) = 0;
virtual void SendUnannounce(ServerTopic* topic) = 0;
virtual void SendPropertiesUpdate(ServerTopic* topic, const wpi::util::json& update,
virtual void SendPropertiesUpdate(ServerTopic* topic,
const wpi::util::json& update,
bool ack) = 0;
virtual void SendOutgoing(uint64_t curTimeMs, bool flush) = 0;
virtual void Flush() = 0;

View File

@@ -142,7 +142,8 @@ void ServerClient4::SendUnannounce(ServerTopic* topic) {
}
void ServerClient4::SendPropertiesUpdate(ServerTopic* topic,
const wpi::util::json& update, bool ack) {
const wpi::util::json& update,
bool ack) {
if (!m_announceSent.lookup(topic)) {
return;
}

View File

@@ -25,7 +25,8 @@ class ServerClient4Base : public ServerClient,
protected:
// ClientMessageHandler interface
void ClientPublish(int pubuid, std::string_view name,
std::string_view typeStr, const wpi::util::json& properties,
std::string_view typeStr,
const wpi::util::json& properties,
const PubSubOptionsImpl& options) final;
void ClientUnpublish(int pubuid) final;
void ClientSetProperties(std::string_view name,

View File

@@ -19,7 +19,7 @@
namespace wpi::util {
class Logger;
} // namespace wpi
} // namespace wpi::util
namespace wpi::nt::net {
class ClientMessageQueue;

View File

@@ -372,8 +372,8 @@ void ServerStorage::DumpPersistent(wpi::util::raw_ostream& os) {
os << "\n]\n";
}
static std::string* ObjGetString(wpi::util::json::object_t& obj, std::string_view key,
std::string* error) {
static std::string* ObjGetString(wpi::util::json::object_t& obj,
std::string_view key, std::string* error) {
auto it = obj.find(key);
if (it == obj.end()) {
*error = fmt::format("no {} key", key);

View File

@@ -17,7 +17,7 @@
namespace wpi::util {
class Logger;
class raw_ostream;
} // namespace wpi
} // namespace wpi::util
namespace wpi::nt::server {
@@ -34,7 +34,8 @@ class ServerStorage final {
ServerTopic* CreateTopic(ServerClient* client, std::string_view name,
std::string_view typeStr,
const wpi::util::json& properties, bool special = false);
const wpi::util::json& properties,
bool special = false);
ServerTopic* CreateMetaTopic(std::string_view name);
void DeleteTopic(ServerTopic* topic);
void SetProperties(ServerClient* client, ServerTopic* topic,

View File

@@ -18,7 +18,7 @@
namespace wpi::util {
class Logger;
} // namespace wpi
} // namespace wpi::util
namespace wpi::nt::server {

View File

@@ -31,8 +31,8 @@ class MultiSubscriber final {
MultiSubscriber(NetworkTableInstance inst,
std::span<const std::string_view> prefixes,
const PubSubOptions& options = kDefaultPubSubOptions)
: m_handle{::wpi::nt::SubscribeMultiple(inst.GetHandle(), prefixes, options)} {
}
: m_handle{::wpi::nt::SubscribeMultiple(inst.GetHandle(), prefixes,
options)} {}
MultiSubscriber(const MultiSubscriber&) = delete;
MultiSubscriber& operator=(const MultiSubscriber&) = delete;

View File

@@ -567,7 +567,7 @@ class NetworkTableInstance final {
NT_Listener AddListener(std::span<const std::string_view> prefixes,
int eventMask, ListenerCallback listener) {
return ::wpi::nt::AddListener(m_handle, prefixes, eventMask,
std::move(listener));
std::move(listener));
}
/** @} */
@@ -582,7 +582,9 @@ class NetworkTableInstance final {
*
* @return Bitmask of NetworkMode.
*/
unsigned int GetNetworkMode() const { return ::wpi::nt::GetNetworkMode(m_handle); }
unsigned int GetNetworkMode() const {
return ::wpi::nt::GetNetworkMode(m_handle);
}
/**
* Starts local-only operation. Prevents calls to StartServer or StartClient

View File

@@ -47,8 +47,8 @@ class NetworkTableListener final {
static NetworkTableListener CreateListener(
NetworkTableInstance inst, std::span<const std::string_view> prefixes,
unsigned int mask, ListenerCallback listener) {
return NetworkTableListener{::wpi::nt::AddListener(inst.GetHandle(), prefixes,
mask, std::move(listener))};
return NetworkTableListener{::wpi::nt::AddListener(
inst.GetHandle(), prefixes, mask, std::move(listener))};
}
/**
@@ -78,8 +78,8 @@ class NetworkTableListener final {
static NetworkTableListener CreateListener(Subscriber& subscriber,
unsigned int mask,
ListenerCallback listener) {
return NetworkTableListener{
::wpi::nt::AddListener(subscriber.GetHandle(), mask, std::move(listener))};
return NetworkTableListener{::wpi::nt::AddListener(
subscriber.GetHandle(), mask, std::move(listener))};
}
/**
@@ -94,8 +94,8 @@ class NetworkTableListener final {
static NetworkTableListener CreateListener(MultiSubscriber& subscriber,
unsigned int mask,
ListenerCallback listener) {
return NetworkTableListener{
::wpi::nt::AddListener(subscriber.GetHandle(), mask, std::move(listener))};
return NetworkTableListener{::wpi::nt::AddListener(
subscriber.GetHandle(), mask, std::move(listener))};
}
/**
@@ -166,8 +166,8 @@ class NetworkTableListener final {
unsigned int minLevel,
unsigned int maxLevel,
ListenerCallback listener) {
return NetworkTableListener{::wpi::nt::AddLogger(inst.GetHandle(), minLevel,
maxLevel, std::move(listener))};
return NetworkTableListener{::wpi::nt::AddLogger(
inst.GetHandle(), minLevel, maxLevel, std::move(listener))};
}
NetworkTableListener(const NetworkTableListener&) = delete;
@@ -386,14 +386,18 @@ class NetworkTableListenerPoller final {
*
* @param listener Listener handle
*/
void RemoveListener(NT_Listener listener) { ::wpi::nt::RemoveListener(listener); }
void RemoveListener(NT_Listener listener) {
::wpi::nt::RemoveListener(listener);
}
/**
* Read events.
*
* @return Events since the previous call to ReadQueue()
*/
std::vector<Event> ReadQueue() { return ::wpi::nt::ReadListenerQueue(m_handle); }
std::vector<Event> ReadQueue() {
return ::wpi::nt::ReadListenerQueue(m_handle);
}
private:
NT_ListenerPoller m_handle{0};

View File

@@ -195,7 +195,8 @@ class ProtobufPublisher : public Publisher {
* @param handle Native handle
* @param msg Protobuf message
*/
explicit ProtobufPublisher(NT_Publisher handle, wpi::util::ProtobufMessage<T> msg)
explicit ProtobufPublisher(NT_Publisher handle,
wpi::util::ProtobufMessage<T> msg)
: Publisher{handle}, m_msg{std::move(msg)} {}
ProtobufPublisher(const ProtobufPublisher&) = delete;
@@ -294,7 +295,8 @@ class ProtobufEntry final : public ProtobufSubscriber<T>,
* @param msg Protobuf message
* @param defaultValue Default value
*/
ProtobufEntry(NT_Entry handle, wpi::util::ProtobufMessage<T> msg, T defaultValue)
ProtobufEntry(NT_Entry handle, wpi::util::ProtobufMessage<T> msg,
T defaultValue)
: ProtobufSubscriber<T>{handle, std::move(msg), std::move(defaultValue)},
ProtobufPublisher<T>{handle, wpi::util::ProtobufMessage<T>{}} {}
@@ -378,8 +380,8 @@ class ProtobufTopic final : public Topic {
wpi::util::ProtobufMessage<T> msg;
auto typeString = msg.GetTypeString();
return ProtobufSubscriber<T>{
::wpi::nt::Subscribe(m_handle, NT_RAW, typeString, options), std::move(msg),
std::move(defaultValue)};
::wpi::nt::Subscribe(m_handle, NT_RAW, typeString, options),
std::move(msg), std::move(defaultValue)};
}
/**
@@ -402,7 +404,8 @@ class ProtobufTopic final : public Topic {
wpi::util::ProtobufMessage<T> msg;
auto typeString = msg.GetTypeString();
return ProtobufPublisher<T>{
::wpi::nt::Publish(m_handle, NT_RAW, typeString, options), std::move(msg)};
::wpi::nt::Publish(m_handle, NT_RAW, typeString, options),
std::move(msg)};
}
/**
@@ -459,8 +462,8 @@ class ProtobufTopic final : public Topic {
wpi::util::ProtobufMessage<T> msg;
auto typeString = msg.GetTypeString();
return ProtobufEntry<T>{
::wpi::nt::GetEntry(m_handle, NT_RAW, typeString, options), std::move(msg),
std::move(defaultValue)};
::wpi::nt::GetEntry(m_handle, NT_RAW, typeString, options),
std::move(msg), std::move(defaultValue)};
}
};

View File

@@ -171,8 +171,8 @@ class StructSubscriber : public Subscriber {
TopicType GetTopic() const {
return std::apply(
[&](const I&... info) {
return StructTopic<T, I...>{::wpi::nt::GetTopicFromHandle(m_subHandle),
info...};
return StructTopic<T, I...>{
::wpi::nt::GetTopicFromHandle(m_subHandle), info...};
},
m_info);
}
@@ -293,8 +293,8 @@ class StructPublisher : public Publisher {
TopicType GetTopic() const {
return std::apply(
[&](const I&... info) {
return StructTopic<T, I...>{::wpi::nt::GetTopicFromHandle(m_pubHandle),
info...};
return StructTopic<T, I...>{
::wpi::nt::GetTopicFromHandle(m_pubHandle), info...};
},
m_info);
}
@@ -420,9 +420,9 @@ class StructTopic final : public Topic {
return std::apply(
[&](const I&... info) {
return StructSubscriber<T, I...>{
::wpi::nt::Subscribe(m_handle, NT_RAW,
wpi::util::GetStructTypeString<T, I...>(info...),
options),
::wpi::nt::Subscribe(
m_handle, NT_RAW,
wpi::util::GetStructTypeString<T, I...>(info...), options),
std::move(defaultValue), info...};
},
m_info);
@@ -448,9 +448,9 @@ class StructTopic final : public Topic {
return std::apply(
[&](const I&... info) {
return StructPublisher<T, I...>{
::wpi::nt::Publish(m_handle, NT_RAW,
wpi::util::GetStructTypeString<T, I...>(info...),
options),
::wpi::nt::Publish(
m_handle, NT_RAW,
wpi::util::GetStructTypeString<T, I...>(info...), options),
info...};
},
m_info);
@@ -480,9 +480,10 @@ class StructTopic final : public Topic {
return std::apply(
[&](const I&... info) {
return StructPublisher<T, I...>{
::wpi::nt::PublishEx(m_handle, NT_RAW,
wpi::util::GetStructTypeString<T, I...>(info...),
properties, options),
::wpi::nt::PublishEx(
m_handle, NT_RAW,
wpi::util::GetStructTypeString<T, I...>(info...), properties,
options),
info...};
},
m_info);
@@ -514,9 +515,9 @@ class StructTopic final : public Topic {
return std::apply(
[&](const I&... info) {
return StructEntry<T, I...>{
::wpi::nt::GetEntry(m_handle, NT_RAW,
wpi::util::GetStructTypeString<T, I...>(info...),
options),
::wpi::nt::GetEntry(
m_handle, NT_RAW,
wpi::util::GetStructTypeString<T, I...>(info...), options),
std::move(defaultValue), info...};
},
m_info);

View File

@@ -107,7 +107,8 @@ class UnitSubscriber : public Subscriber {
* @return timestamped value
*/
TimestampedValueType GetAtomic(ParamType defaultValue) const {
auto doubleVal = ::wpi::nt::GetAtomicDouble(m_subHandle, defaultValue.value());
auto doubleVal =
::wpi::nt::GetAtomicDouble(m_subHandle, defaultValue.value());
return {doubleVal.time, doubleVal.serverTime, doubleVal.value};
}
@@ -320,7 +321,8 @@ class UnitTopic final : public Topic {
ParamType defaultValue,
const PubSubOptions& options = kDefaultPubSubOptions) {
return UnitSubscriber<T>{
::wpi::nt::Subscribe(m_handle, NT_DOUBLE, "double", options), defaultValue};
::wpi::nt::Subscribe(m_handle, NT_DOUBLE, "double", options),
defaultValue};
}
/**
@@ -365,8 +367,8 @@ class UnitTopic final : public Topic {
*/
[[nodiscard]]
PublisherType Publish(const PubSubOptions& options = kDefaultPubSubOptions) {
return UnitPublisher<T>{::wpi::nt::PublishEx(m_handle, NT_DOUBLE, "double",
{{"unit", T{}.name()}}, options)};
return UnitPublisher<T>{::wpi::nt::PublishEx(
m_handle, NT_DOUBLE, "double", {{"unit", T{}.name()}}, options)};
}
/**
@@ -420,8 +422,9 @@ class UnitTopic final : public Topic {
[[nodiscard]]
EntryType GetEntry(ParamType defaultValue,
const PubSubOptions& options = kDefaultPubSubOptions) {
return UnitEntry<T>{::wpi::nt::GetEntry(m_handle, NT_DOUBLE, "double", options),
defaultValue};
return UnitEntry<T>{
::wpi::nt::GetEntry(m_handle, NT_DOUBLE, "double", options),
defaultValue};
}
/**
@@ -449,7 +452,8 @@ class UnitTopic final : public Topic {
EntryType GetEntryEx(std::string_view typeString, ParamType defaultValue,
const PubSubOptions& options = kDefaultPubSubOptions) {
return UnitEntry<T>{
::wpi::nt::GetEntry(m_handle, NT_DOUBLE, typeString, options), defaultValue};
::wpi::nt::GetEntry(m_handle, NT_DOUBLE, typeString, options),
defaultValue};
}
};

View File

@@ -25,7 +25,7 @@
namespace wpi::util {
template <typename T>
class SmallVectorImpl;
} // namespace wpi
} // namespace wpi::util
namespace wpi::log {
class DataLog;

View File

@@ -16,7 +16,8 @@
class ConnectionListenerTest : public ::testing::Test {
public:
ConnectionListenerTest()
: server_inst(wpi::nt::CreateInstance()), client_inst(wpi::nt::CreateInstance()) {}
: server_inst(wpi::nt::CreateInstance()),
client_inst(wpi::nt::CreateInstance()) {}
~ConnectionListenerTest() override {
wpi::nt::DestroyInstance(server_inst);
@@ -31,7 +32,8 @@ class ConnectionListenerTest : public ::testing::Test {
};
void ConnectionListenerTest::Connect(const char* address, unsigned int port4) {
wpi::nt::StartServer(server_inst, "connectionlistenertest.ini", address, port4);
wpi::nt::StartServer(server_inst, "connectionlistenertest.ini", address,
port4);
wpi::nt::StartClient(client_inst, "client");
wpi::nt::SetServer(client_inst, address, port4);
@@ -50,8 +52,8 @@ TEST_F(ConnectionListenerTest, Polled) {
// set up the poller
NT_ListenerPoller poller = wpi::nt::CreateListenerPoller(server_inst);
ASSERT_NE(poller, 0u);
NT_Listener handle =
wpi::nt::AddPolledListener(poller, server_inst, wpi::nt::EventFlags::kConnection);
NT_Listener handle = wpi::nt::AddPolledListener(
poller, server_inst, wpi::nt::EventFlags::kConnection);
ASSERT_NE(handle, 0u);
// trigger a connect event
@@ -89,11 +91,11 @@ class ConnectionListenerVariantTest
TEST_P(ConnectionListenerVariantTest, Threaded) {
wpi::util::mutex m;
std::vector<wpi::nt::Event> result;
auto handle = wpi::nt::AddListener(server_inst, wpi::nt::EventFlags::kConnection,
[&](auto& event) {
std::scoped_lock lock{m};
result.push_back(event);
});
auto handle = wpi::nt::AddListener(
server_inst, wpi::nt::EventFlags::kConnection, [&](auto& event) {
std::scoped_lock lock{m};
result.push_back(event);
});
// trigger a connect event
Connect(GetParam().first, 20001 + GetParam().second);

View File

@@ -80,8 +80,9 @@ TEST_F(LocalStorageTest, GetEntryEmptyName) {
}
TEST_F(LocalStorageTest, GetEntryCached) {
EXPECT_CALL(network, ClientSubscribe(_, wpi::util::SpanEq({std::string{"tocache"}}),
IsDefaultPubSubOptions()));
EXPECT_CALL(network,
ClientSubscribe(_, wpi::util::SpanEq({std::string{"tocache"}}),
IsDefaultPubSubOptions()));
auto entry1 = storage.GetEntry("tocache");
EXPECT_EQ(entry1, storage.GetEntry("tocache"));
@@ -110,7 +111,8 @@ TEST_F(LocalStorageTest, DefaultProps) {
network,
ClientPublish(_, std::string_view{"foo"}, std::string_view{"boolean"},
wpi::util::json::object(), IsDefaultPubSubOptions()));
storage.Publish(fooTopic, NT_BOOLEAN, "boolean", wpi::util::json::object(), {});
storage.Publish(fooTopic, NT_BOOLEAN, "boolean", wpi::util::json::object(),
{});
EXPECT_FALSE(storage.GetTopicPersistent(fooTopic));
EXPECT_FALSE(storage.GetTopicRetained(fooTopic));
@@ -122,7 +124,8 @@ TEST_F(LocalStorageTest, PublishNewNoProps) {
network,
ClientPublish(_, std::string_view{"foo"}, std::string_view{"boolean"},
wpi::util::json::object(), IsDefaultPubSubOptions()));
storage.Publish(fooTopic, NT_BOOLEAN, "boolean", wpi::util::json::object(), {});
storage.Publish(fooTopic, NT_BOOLEAN, "boolean", wpi::util::json::object(),
{});
auto info = storage.GetTopicInfo(fooTopic);
EXPECT_EQ(info.properties, "{}");
@@ -159,8 +162,9 @@ TEST_F(LocalStorageTest, PublishNew) {
}
TEST_F(LocalStorageTest, SubscribeNoTypeLocalPubPost) {
EXPECT_CALL(network, ClientSubscribe(_, wpi::util::SpanEq({std::string{"foo"}}),
IsDefaultPubSubOptions()));
EXPECT_CALL(network,
ClientSubscribe(_, wpi::util::SpanEq({std::string{"foo"}}),
IsDefaultPubSubOptions()));
auto sub = storage.Subscribe(fooTopic, NT_UNASSIGNED, "", {});
EXPECT_CALL(
@@ -206,8 +210,9 @@ TEST_F(LocalStorageTest, SubscribeNoTypeLocalPubPre) {
EXPECT_CALL(network, ClientSetValue(Handle{pub}.GetIndex(), val));
storage.SetEntryValue(pub, val);
EXPECT_CALL(network, ClientSubscribe(_, wpi::util::SpanEq({std::string{"foo"}}),
IsDefaultPubSubOptions()));
EXPECT_CALL(network,
ClientSubscribe(_, wpi::util::SpanEq({std::string{"foo"}}),
IsDefaultPubSubOptions()));
auto sub = storage.Subscribe(fooTopic, NT_UNASSIGNED, "", {});
EXPECT_EQ(storage.GetTopicType(fooTopic), NT_BOOLEAN);
@@ -221,8 +226,9 @@ TEST_F(LocalStorageTest, SubscribeNoTypeLocalPubPre) {
}
TEST_F(LocalStorageTest, EntryNoTypeLocalSet) {
EXPECT_CALL(network, ClientSubscribe(_, wpi::util::SpanEq({std::string{"foo"}}),
IsDefaultPubSubOptions()));
EXPECT_CALL(network,
ClientSubscribe(_, wpi::util::SpanEq({std::string{"foo"}}),
IsDefaultPubSubOptions()));
auto entry = storage.GetEntry(fooTopic, NT_UNASSIGNED, "", {});
// results in a publish and value set
@@ -268,8 +274,9 @@ TEST_F(LocalStorageTest, EntryNoTypeLocalSet) {
}
TEST_F(LocalStorageTest, PubUnpubPub) {
EXPECT_CALL(network, ClientSubscribe(_, wpi::util::SpanEq({std::string{"foo"}}),
IsDefaultPubSubOptions()));
EXPECT_CALL(network,
ClientSubscribe(_, wpi::util::SpanEq({std::string{"foo"}}),
IsDefaultPubSubOptions()));
auto sub = storage.Subscribe(fooTopic, NT_INTEGER, "int", {});
EXPECT_CALL(
@@ -300,9 +307,10 @@ TEST_F(LocalStorageTest, PubUnpubPub) {
EXPECT_EQ(storage.GetTopicTypeString(fooTopic), "");
EXPECT_FALSE(storage.GetTopicExists(fooTopic));
EXPECT_CALL(network,
ClientPublish(_, std::string_view{"foo"}, std::string_view{"int"},
wpi::util::json::object(), IsDefaultPubSubOptions()));
EXPECT_CALL(
network,
ClientPublish(_, std::string_view{"foo"}, std::string_view{"int"},
wpi::util::json::object(), IsDefaultPubSubOptions()));
pub = storage.Publish(fooTopic, NT_INTEGER, "int", {}, {});
val = Value::MakeInteger(3, 5);
@@ -341,9 +349,10 @@ TEST_F(LocalStorageTest, LocalPubConflict) {
// unpublishing pub1 will publish pub2 to the network
EXPECT_CALL(network, ClientUnpublish(Handle{pub1}.GetIndex()));
EXPECT_CALL(network,
ClientPublish(_, std::string_view{"foo"}, std::string_view{"int"},
wpi::util::json::object(), IsDefaultPubSubOptions()));
EXPECT_CALL(
network,
ClientPublish(_, std::string_view{"foo"}, std::string_view{"int"},
wpi::util::json::object(), IsDefaultPubSubOptions()));
storage.Unpublish(pub1);
EXPECT_EQ(storage.GetTopicType(fooTopic), NT_INTEGER);
@@ -363,8 +372,9 @@ TEST_F(LocalStorageTest, LocalSubConflict) {
wpi::util::json::object(), IsDefaultPubSubOptions()));
storage.Publish(fooTopic, NT_BOOLEAN, "boolean", {}, {});
EXPECT_CALL(network, ClientSubscribe(_, wpi::util::SpanEq({std::string{"foo"}}),
IsDefaultPubSubOptions()));
EXPECT_CALL(network,
ClientSubscribe(_, wpi::util::SpanEq({std::string{"foo"}}),
IsDefaultPubSubOptions()));
EXPECT_CALL(logger,
Call(NT_LOG_INFO, _, _,
std::string_view{
@@ -409,15 +419,17 @@ TEST_F(LocalStorageTest, RemotePubConflict) {
TEST_F(LocalStorageTest, SubNonExist) {
// makes sure no warning is emitted
EXPECT_CALL(network, ClientSubscribe(_, wpi::util::SpanEq({std::string{"foo"}}),
IsDefaultPubSubOptions()));
EXPECT_CALL(network,
ClientSubscribe(_, wpi::util::SpanEq({std::string{"foo"}}),
IsDefaultPubSubOptions()));
storage.Subscribe(fooTopic, NT_BOOLEAN, "boolean", {});
}
TEST_F(LocalStorageTest, SetDefaultSubscribe) {
// no publish, no value on wire, this is just handled locally
EXPECT_CALL(network, ClientSubscribe(_, wpi::util::SpanEq({std::string{"foo"}}),
IsDefaultPubSubOptions()));
EXPECT_CALL(network,
ClientSubscribe(_, wpi::util::SpanEq({std::string{"foo"}}),
IsDefaultPubSubOptions()));
auto sub = storage.Subscribe(fooTopic, NT_BOOLEAN, "boolean", {});
EXPECT_TRUE(storage.SetDefaultEntryValue(sub, Value::MakeBoolean(true)));
auto val = storage.GetEntryValue(sub);
@@ -447,8 +459,9 @@ TEST_F(LocalStorageTest, SetDefaultPublish) {
}
TEST_F(LocalStorageTest, SetDefaultEntry) {
EXPECT_CALL(network, ClientSubscribe(_, wpi::util::SpanEq({std::string{"foo"}}),
IsDefaultPubSubOptions()));
EXPECT_CALL(network,
ClientSubscribe(_, wpi::util::SpanEq({std::string{"foo"}}),
IsDefaultPubSubOptions()));
auto entry = storage.GetEntry(fooTopic, NT_BOOLEAN, "boolean", {});
// expect a publish and value
@@ -467,8 +480,9 @@ TEST_F(LocalStorageTest, SetDefaultEntry) {
}
TEST_F(LocalStorageTest, SetDefaultEntryUnassigned) {
EXPECT_CALL(network, ClientSubscribe(_, wpi::util::SpanEq({std::string{"foo"}}),
IsDefaultPubSubOptions()));
EXPECT_CALL(network,
ClientSubscribe(_, wpi::util::SpanEq({std::string{"foo"}}),
IsDefaultPubSubOptions()));
auto entry = storage.GetEntry(fooTopic, NT_UNASSIGNED, "", {});
// expect a publish and value
@@ -509,8 +523,9 @@ TEST_F(LocalStorageTest, SetValueEmptyValue) {
}
TEST_F(LocalStorageTest, SetValueEmptyUntypedEntry) {
EXPECT_CALL(network, ClientSubscribe(_, wpi::util::SpanEq({std::string{"foo"}}),
IsDefaultPubSubOptions()));
EXPECT_CALL(network,
ClientSubscribe(_, wpi::util::SpanEq({std::string{"foo"}}),
IsDefaultPubSubOptions()));
auto entry = storage.GetEntry(fooTopic, NT_UNASSIGNED, "", {});
EXPECT_FALSE(storage.SetEntryValue(entry, {}));
}
@@ -553,8 +568,9 @@ void LocalStorageDuplicatesTest::SetupPubSub(bool keepPub, bool keepSub) {
PubSubOptionsImpl subOptions;
subOptions.pollStorage = 10;
subOptions.keepDuplicates = keepSub;
EXPECT_CALL(network, ClientSubscribe(_, wpi::util::SpanEq({std::string{"foo"}}),
IsPubSubOptions(subOptions)));
EXPECT_CALL(network,
ClientSubscribe(_, wpi::util::SpanEq({std::string{"foo"}}),
IsPubSubOptions(subOptions)));
sub = storage.Subscribe(fooTopic, NT_DOUBLE, "double",
{.pollStorage = 10, .keepDuplicates = keepSub});
}
@@ -942,8 +958,8 @@ TEST_F(LocalStorageTest, MultiSubSpecial) {
TEST_F(LocalStorageTest, NetworkDuplicateDetect) {
EXPECT_CALL(network, ClientPublish(_, _, _, _, _));
auto pub = storage.Publish(fooTopic, NT_DOUBLE, "double", {}, {});
auto remoteTopic = storage.ServerAnnounce("foo", 0, "double",
wpi::util::json::object(), std::nullopt);
auto remoteTopic = storage.ServerAnnounce(
"foo", 0, "double", wpi::util::json::object(), std::nullopt);
// local set
EXPECT_CALL(network, ClientSetValue(_, _));
@@ -968,8 +984,8 @@ TEST_F(LocalStorageTest, ReadQueueLocalRemote) {
auto subRemote =
storage.Subscribe(fooTopic, NT_DOUBLE, "double", {.disableLocal = true});
auto pub = storage.Publish(fooTopic, NT_DOUBLE, "double", {}, {});
auto remoteTopic = storage.ServerAnnounce("foo", 0, "double",
wpi::util::json::object(), std::nullopt);
auto remoteTopic = storage.ServerAnnounce(
"foo", 0, "double", wpi::util::json::object(), std::nullopt);
// local set
EXPECT_CALL(network, ClientSetValue(_, _));
@@ -997,8 +1013,8 @@ TEST_F(LocalStorageTest, SubExcludePub) {
auto subActive = storage.Subscribe(fooTopic, NT_DOUBLE, "double", {});
auto subExclude = storage.Subscribe(fooTopic, NT_DOUBLE, "double",
{.excludePublisher = pub});
auto remoteTopic = storage.ServerAnnounce("foo", 0, "double",
wpi::util::json::object(), std::nullopt);
auto remoteTopic = storage.ServerAnnounce(
"foo", 0, "double", wpi::util::json::object(), std::nullopt);
// local set
EXPECT_CALL(network, ClientSetValue(_, _));
@@ -1020,8 +1036,8 @@ TEST_F(LocalStorageTest, EntryExcludeSelf) {
auto entry =
storage.GetEntry(fooTopic, NT_DOUBLE, "double", {.excludeSelf = true});
auto remoteTopic = storage.ServerAnnounce("foo", 0, "double",
wpi::util::json::object(), std::nullopt);
auto remoteTopic = storage.ServerAnnounce(
"foo", 0, "double", wpi::util::json::object(), std::nullopt);
// local set
EXPECT_CALL(network, ClientPublish(_, _, _, _, _));
@@ -1060,8 +1076,8 @@ TEST_F(LocalStorageTest, ReadQueueInitialLocal) {
TEST_F(LocalStorageTest, ReadQueueInitialRemote) {
EXPECT_CALL(network, ClientSubscribe(_, _, _)).Times(3);
auto remoteTopic = storage.ServerAnnounce("foo", 0, "double",
wpi::util::json::object(), std::nullopt);
auto remoteTopic = storage.ServerAnnounce(
"foo", 0, "double", wpi::util::json::object(), std::nullopt);
storage.ServerSetValue(remoteTopic, Value::MakeDouble(2.0, 60));
auto subBoth =

View File

@@ -30,12 +30,13 @@ void LoggerTest::Generate() {
wpi::nt::StartClient(m_inst, "");
// generate error message
wpi::nt::Publish(wpi::nt::Handle(wpi::nt::Handle{m_inst}.GetInst(), 5, wpi::nt::Handle::kTopic),
NT_DOUBLE, "");
wpi::nt::Publish(wpi::nt::Handle(wpi::nt::Handle{m_inst}.GetInst(), 5,
wpi::nt::Handle::kTopic),
NT_DOUBLE, "");
}
void LoggerTest::Check(const std::vector<wpi::nt::Event>& events, NT_Listener handle,
bool infoMsg, bool errMsg) {
void LoggerTest::Check(const std::vector<wpi::nt::Event>& events,
NT_Listener handle, bool infoMsg, bool errMsg) {
size_t count = (infoMsg ? 1u : 0u) + (errMsg ? 1u : 0u);
ASSERT_EQ(events.size(), count);
for (size_t i = 0; i < count; ++i) {
@@ -59,8 +60,8 @@ void LoggerTest::Check(const std::vector<wpi::nt::Event>& events, NT_Listener ha
TEST_F(LoggerTest, DefaultLogRange) {
auto poller = wpi::nt::CreateListenerPoller(m_inst);
auto handle =
wpi::nt::AddPolledListener(poller, m_inst, wpi::nt::EventFlags::kLogMessage);
auto handle = wpi::nt::AddPolledListener(poller, m_inst,
wpi::nt::EventFlags::kLogMessage);
Generate();

View File

@@ -15,14 +15,16 @@ class NetworkTableTest : public ::testing::Test {};
TEST_F(NetworkTableTest, BasenameKey) {
EXPECT_EQ("simple", wpi::nt::NetworkTable::BasenameKey("simple"));
EXPECT_EQ("simple", wpi::nt::NetworkTable::BasenameKey("one/two/many/simple"));
EXPECT_EQ("simple",
wpi::nt::NetworkTable::BasenameKey("//////an/////awful/key////simple"));
wpi::nt::NetworkTable::BasenameKey("one/two/many/simple"));
EXPECT_EQ("simple", wpi::nt::NetworkTable::BasenameKey(
"//////an/////awful/key////simple"));
}
TEST_F(NetworkTableTest, NormalizeKeySlash) {
EXPECT_EQ("/", wpi::nt::NetworkTable::NormalizeKey("///"));
EXPECT_EQ("/no/normal/req", wpi::nt::NetworkTable::NormalizeKey("/no/normal/req"));
EXPECT_EQ("/no/normal/req",
wpi::nt::NetworkTable::NormalizeKey("/no/normal/req"));
EXPECT_EQ("/no/leading/slash",
wpi::nt::NetworkTable::NormalizeKey("no/leading/slash"));
EXPECT_EQ("/what/an/awful/key/", wpi::nt::NetworkTable::NormalizeKey(
@@ -37,8 +39,8 @@ TEST_F(NetworkTableTest, NormalizeKeyNoSlash) {
EXPECT_EQ("no/leading/slash",
wpi::nt::NetworkTable::NormalizeKey("no/leading/slash", false));
EXPECT_EQ("what/an/awful/key/",
wpi::nt::NetworkTable::NormalizeKey("//////what////an/awful/////key///",
false));
wpi::nt::NetworkTable::NormalizeKey(
"//////what////an/awful/////key///", false));
}
TEST_F(NetworkTableTest, GetHierarchyEmpty) {

View File

@@ -63,7 +63,9 @@ struct wpi::util::Struct<Inner> {
template <>
struct wpi::util::Struct<Outer> {
static constexpr std::string_view GetTypeName() { return "Outer"; }
static constexpr size_t GetSize() { return wpi::util::GetStructSize<Inner>() + 4; }
static constexpr size_t GetSize() {
return wpi::util::GetStructSize<Inner>() + 4;
}
static constexpr std::string_view GetSchema() {
return "Inner inner; int32 c";
}
@@ -283,7 +285,8 @@ TEST_F(StructTest, OuterNonconstexpr) {
}
TEST_F(StructTest, InnerArrayConstexpr) {
wpi::nt::StructArrayTopic<Inner> topic = inst.GetStructArrayTopic<Inner>("innerA");
wpi::nt::StructArrayTopic<Inner> topic =
inst.GetStructArrayTopic<Inner>("innerA");
wpi::nt::StructArrayPublisher<Inner> pub = topic.Publish();
wpi::nt::StructArraySubscriber<Inner> sub = topic.Subscribe({});
@@ -353,7 +356,8 @@ TEST_F(StructTest, StructA) {
}
TEST_F(StructTest, StructArrayA) {
wpi::nt::StructArrayTopic<ThingA> topic = inst.GetStructArrayTopic<ThingA>("a");
wpi::nt::StructArrayTopic<ThingA> topic =
inst.GetStructArrayTopic<ThingA>("a");
wpi::nt::StructArrayPublisher<ThingA> pub = topic.Publish();
wpi::nt::StructArrayPublisher<ThingA> pub2 = topic.PublishEx({{}});
wpi::nt::StructArraySubscriber<ThingA> sub = topic.Subscribe({});
@@ -433,7 +437,8 @@ TEST_F(StructTest, StructFixedArrayB) {
wpi::nt::StructPublisher<std::array<ThingB, 2>, Info1> pub = topic.Publish();
wpi::nt::StructPublisher<std::array<ThingB, 2>, Info1> pub2 =
topic.PublishEx({{}});
wpi::nt::StructSubscriber<std::array<ThingB, 2>, Info1> sub = topic.Subscribe({});
wpi::nt::StructSubscriber<std::array<ThingB, 2>, Info1> sub =
topic.Subscribe({});
wpi::nt::StructEntry<std::array<ThingB, 2>, Info1> entry = topic.GetEntry({});
std::array<ThingB, 2> arr;
pub.SetDefault(arr);

View File

@@ -15,16 +15,19 @@
using ::testing::_;
using MockTableEventListener = testing::MockFunction<void(
wpi::nt::NetworkTable* table, std::string_view key, const wpi::nt::Event& event)>;
using MockSubTableListener =
testing::MockFunction<void(wpi::nt::NetworkTable* parent, std::string_view name,
std::shared_ptr<wpi::nt::NetworkTable> table)>;
wpi::nt::NetworkTable* table, std::string_view key,
const wpi::nt::Event& event)>;
using MockSubTableListener = testing::MockFunction<void(
wpi::nt::NetworkTable* parent, std::string_view name,
std::shared_ptr<wpi::nt::NetworkTable> table)>;
class TableListenerTest : public ::testing::Test {
public:
TableListenerTest() : m_inst(wpi::nt::NetworkTableInstance::Create()) {}
~TableListenerTest() override { wpi::nt::NetworkTableInstance::Destroy(m_inst); }
~TableListenerTest() override {
wpi::nt::NetworkTableInstance::Destroy(m_inst);
}
void PublishTopics();

View File

@@ -19,7 +19,8 @@
class TopicListenerTest : public ::testing::Test {
public:
TopicListenerTest()
: m_serverInst(wpi::nt::CreateInstance()), m_clientInst(wpi::nt::CreateInstance()) {
: m_serverInst(wpi::nt::CreateInstance()),
m_clientInst(wpi::nt::CreateInstance()) {
#if 0
wpi::nt::AddLogger(m_serverInst, 0, UINT_MAX, [](auto& event) {
if (auto msg = event.GetLogMessage()) {
@@ -41,8 +42,9 @@ class TopicListenerTest : public ::testing::Test {
void Connect(unsigned int port);
static void PublishTopics(NT_Inst inst);
void CheckEvents(const std::vector<wpi::nt::Event>& events, NT_Listener handle,
unsigned int flags, std::string_view topicName = "/foo/bar");
void CheckEvents(const std::vector<wpi::nt::Event>& events,
NT_Listener handle, unsigned int flags,
std::string_view topicName = "/foo/bar");
protected:
NT_Inst m_serverInst;
@@ -50,13 +52,15 @@ class TopicListenerTest : public ::testing::Test {
};
void TopicListenerTest::Connect(unsigned int port) {
wpi::nt::StartServer(m_serverInst, "topiclistenertest.json", "127.0.0.1", port);
wpi::nt::StartServer(m_serverInst, "topiclistenertest.json", "127.0.0.1",
port);
wpi::nt::StartClient(m_clientInst, "client");
wpi::nt::SetServer(m_clientInst, "127.0.0.1", port);
// Use connection listener to ensure we've connected
NT_ListenerPoller poller = wpi::nt::CreateListenerPoller(m_clientInst);
wpi::nt::AddPolledListener(poller, m_clientInst, wpi::nt::EventFlags::kConnected);
wpi::nt::AddPolledListener(poller, m_clientInst,
wpi::nt::EventFlags::kConnected);
bool timedOut = false;
if (!wpi::util::WaitForObject(poller, 1.0, &timedOut)) {
FAIL() << "client didn't connect to server";
@@ -84,7 +88,8 @@ void TopicListenerTest::CheckEvents(const std::vector<wpi::nt::Event>& events,
TEST_F(TopicListenerTest, TopicNewLocal) {
auto poller = wpi::nt::CreateListenerPoller(m_serverInst);
auto handle = wpi::nt::AddPolledListener(
poller, wpi::nt::GetTopic(m_serverInst, "/foo"), wpi::nt::EventFlags::kPublish);
poller, wpi::nt::GetTopic(m_serverInst, "/foo"),
wpi::nt::EventFlags::kPublish);
PublishTopics(m_serverInst);
@@ -101,7 +106,8 @@ TEST_F(TopicListenerTest, DISABLED_TopicNewRemote) {
}
auto poller = wpi::nt::CreateListenerPoller(m_serverInst);
auto handle = wpi::nt::AddPolledListener(
poller, wpi::nt::GetTopic(m_serverInst, "/foo"), wpi::nt::EventFlags::kPublish);
poller, wpi::nt::GetTopic(m_serverInst, "/foo"),
wpi::nt::EventFlags::kPublish);
PublishTopics(m_clientInst);
@@ -126,7 +132,8 @@ TEST_F(TopicListenerTest, TopicPublishImm) {
ASSERT_TRUE(wpi::util::WaitForObject(poller, 1.0, &timedOut));
auto events = wpi::nt::ReadListenerQueue(poller);
CheckEvents(events, handle,
wpi::nt::EventFlags::kPublish | wpi::nt::EventFlags::kImmediate, "/foo");
wpi::nt::EventFlags::kPublish | wpi::nt::EventFlags::kImmediate,
"/foo");
}
TEST_F(TopicListenerTest, TopicUnpublishPropsImm) {
@@ -134,9 +141,9 @@ TEST_F(TopicListenerTest, TopicUnpublishPropsImm) {
auto poller = wpi::nt::CreateListenerPoller(m_serverInst);
wpi::nt::AddPolledListener(poller, wpi::nt::GetTopic(m_serverInst, "/foo"),
wpi::nt::EventFlags::kUnpublish |
wpi::nt::EventFlags::kProperties |
wpi::nt::EventFlags::kImmediate);
wpi::nt::EventFlags::kUnpublish |
wpi::nt::EventFlags::kProperties |
wpi::nt::EventFlags::kImmediate);
bool timedOut = false;
ASSERT_FALSE(wpi::util::WaitForObject(poller, 0.02, &timedOut));
@@ -148,8 +155,8 @@ TEST_F(TopicListenerTest, TopicUnpublishLocal) {
auto topic = wpi::nt::GetTopic(m_serverInst, "/foo");
auto poller = wpi::nt::CreateListenerPoller(m_serverInst);
auto handle =
wpi::nt::AddPolledListener(poller, topic, wpi::nt::EventFlags::kUnpublish);
auto handle = wpi::nt::AddPolledListener(poller, topic,
wpi::nt::EventFlags::kUnpublish);
auto pub = wpi::nt::Publish(topic, NT_DOUBLE, "double");
wpi::nt::Unpublish(pub);
@@ -167,10 +174,11 @@ TEST_F(TopicListenerTest, DISABLED_TopicUnpublishRemote) {
}
auto poller = wpi::nt::CreateListenerPoller(m_serverInst);
auto handle = wpi::nt::AddPolledListener(
poller, wpi::nt::GetTopic(m_serverInst, "/foo"), wpi::nt::EventFlags::kUnpublish);
poller, wpi::nt::GetTopic(m_serverInst, "/foo"),
wpi::nt::EventFlags::kUnpublish);
auto pub =
wpi::nt::Publish(wpi::nt::GetTopic(m_clientInst, "/foo"), NT_DOUBLE, "double");
auto pub = wpi::nt::Publish(wpi::nt::GetTopic(m_clientInst, "/foo"),
NT_DOUBLE, "double");
wpi::nt::Flush(m_clientInst);
std::this_thread::sleep_for(std::chrono::milliseconds(100));
@@ -189,8 +197,8 @@ TEST_F(TopicListenerTest, TopicPropertiesLocal) {
auto topic = wpi::nt::GetTopic(m_serverInst, "/foo");
auto poller = wpi::nt::CreateListenerPoller(m_serverInst);
auto handle =
wpi::nt::AddPolledListener(poller, topic, wpi::nt::EventFlags::kProperties);
auto handle = wpi::nt::AddPolledListener(poller, topic,
wpi::nt::EventFlags::kProperties);
wpi::nt::SetTopicProperty(topic, "foo", 5);
@@ -206,11 +214,13 @@ TEST_F(TopicListenerTest, DISABLED_TopicPropertiesRemote) {
return;
}
// the topic needs to actually exist
wpi::nt::Publish(wpi::nt::GetTopic(m_serverInst, "/foo"), NT_BOOLEAN, "boolean");
wpi::nt::Publish(wpi::nt::GetTopic(m_serverInst, "/foo"), NT_BOOLEAN,
"boolean");
auto poller = wpi::nt::CreateListenerPoller(m_serverInst);
auto handle = wpi::nt::AddPolledListener(
poller, wpi::nt::GetTopic(m_serverInst, "/foo"), wpi::nt::EventFlags::kProperties);
poller, wpi::nt::GetTopic(m_serverInst, "/foo"),
wpi::nt::EventFlags::kProperties);
wpi::nt::FlushLocal(m_serverInst);
wpi::nt::SetTopicProperty(wpi::nt::GetTopic(m_clientInst, "/foo"), "foo", 5);
@@ -225,8 +235,8 @@ TEST_F(TopicListenerTest, DISABLED_TopicPropertiesRemote) {
TEST_F(TopicListenerTest, PrefixPublishLocal) {
auto poller = wpi::nt::CreateListenerPoller(m_serverInst);
auto handle =
wpi::nt::AddPolledListener(poller, {{"/foo/"}}, wpi::nt::EventFlags::kPublish);
auto handle = wpi::nt::AddPolledListener(poller, {{"/foo/"}},
wpi::nt::EventFlags::kPublish);
PublishTopics(m_serverInst);
@@ -242,8 +252,8 @@ TEST_F(TopicListenerTest, DISABLED_PrefixPublishRemote) {
return;
}
auto poller = wpi::nt::CreateListenerPoller(m_serverInst);
auto handle =
wpi::nt::AddPolledListener(poller, {{"/foo/"}}, wpi::nt::EventFlags::kPublish);
auto handle = wpi::nt::AddPolledListener(poller, {{"/foo/"}},
wpi::nt::EventFlags::kPublish);
PublishTopics(m_clientInst);
@@ -276,9 +286,9 @@ TEST_F(TopicListenerTest, PrefixUnpublishPropsImm) {
auto poller = wpi::nt::CreateListenerPoller(m_serverInst);
wpi::nt::AddPolledListener(poller, {{"/foo/"}},
wpi::nt::EventFlags::kUnpublish |
wpi::nt::EventFlags::kProperties |
wpi::nt::EventFlags::kImmediate);
wpi::nt::EventFlags::kUnpublish |
wpi::nt::EventFlags::kProperties |
wpi::nt::EventFlags::kImmediate);
bool timedOut = false;
ASSERT_FALSE(wpi::util::WaitForObject(poller, 0.02, &timedOut));

View File

@@ -37,9 +37,12 @@ TEST_F(ValueListenerTest, MultiPollSub) {
auto poller1 = wpi::nt::CreateListenerPoller(m_inst);
auto poller2 = wpi::nt::CreateListenerPoller(m_inst);
auto poller3 = wpi::nt::CreateListenerPoller(m_inst);
auto h1 = wpi::nt::AddPolledListener(poller1, sub, wpi::nt::EventFlags::kValueLocal);
auto h2 = wpi::nt::AddPolledListener(poller2, sub, wpi::nt::EventFlags::kValueLocal);
auto h3 = wpi::nt::AddPolledListener(poller3, sub, wpi::nt::EventFlags::kValueLocal);
auto h1 = wpi::nt::AddPolledListener(poller1, sub,
wpi::nt::EventFlags::kValueLocal);
auto h2 = wpi::nt::AddPolledListener(poller2, sub,
wpi::nt::EventFlags::kValueLocal);
auto h3 = wpi::nt::AddPolledListener(poller3, sub,
wpi::nt::EventFlags::kValueLocal);
wpi::nt::SetDouble(pub, 0);
@@ -89,8 +92,10 @@ TEST_F(ValueListenerTest, PollMultiSub) {
auto sub2 = wpi::nt::Subscribe(topic, NT_DOUBLE, "double");
auto poller = wpi::nt::CreateListenerPoller(m_inst);
auto h1 = wpi::nt::AddPolledListener(poller, sub1, wpi::nt::EventFlags::kValueLocal);
auto h2 = wpi::nt::AddPolledListener(poller, sub2, wpi::nt::EventFlags::kValueLocal);
auto h1 = wpi::nt::AddPolledListener(poller, sub1,
wpi::nt::EventFlags::kValueLocal);
auto h2 = wpi::nt::AddPolledListener(poller, sub2,
wpi::nt::EventFlags::kValueLocal);
wpi::nt::SetDouble(pub, 0);
@@ -126,8 +131,10 @@ TEST_F(ValueListenerTest, PollMultiSubTopic) {
auto sub2 = wpi::nt::Subscribe(topic2, NT_DOUBLE, "double");
auto poller = wpi::nt::CreateListenerPoller(m_inst);
auto h1 = wpi::nt::AddPolledListener(poller, sub1, wpi::nt::EventFlags::kValueLocal);
auto h2 = wpi::nt::AddPolledListener(poller, sub2, wpi::nt::EventFlags::kValueLocal);
auto h1 = wpi::nt::AddPolledListener(poller, sub1,
wpi::nt::EventFlags::kValueLocal);
auto h2 = wpi::nt::AddPolledListener(poller, sub2,
wpi::nt::EventFlags::kValueLocal);
wpi::nt::SetDouble(pub1, 0);
wpi::nt::SetDouble(pub2, 1);
@@ -163,7 +170,8 @@ TEST_F(ValueListenerTest, PollSubMultiple) {
auto sub = wpi::nt::SubscribeMultiple(m_inst, {{"foo"}});
auto poller = wpi::nt::CreateListenerPoller(m_inst);
auto h = wpi::nt::AddPolledListener(poller, sub, wpi::nt::EventFlags::kValueLocal);
auto h =
wpi::nt::AddPolledListener(poller, sub, wpi::nt::EventFlags::kValueLocal);
wpi::nt::SetDouble(pub1, 0);
wpi::nt::SetDouble(pub2, 1);
@@ -193,8 +201,8 @@ TEST_F(ValueListenerTest, PollSubMultiple) {
TEST_F(ValueListenerTest, PollSubPrefixCreated) {
auto poller = wpi::nt::CreateListenerPoller(m_inst);
auto h =
wpi::nt::AddPolledListener(poller, {{"foo"}}, wpi::nt::EventFlags::kValueLocal);
auto h = wpi::nt::AddPolledListener(poller, {{"foo"}},
wpi::nt::EventFlags::kValueLocal);
auto topic1 = wpi::nt::GetTopic(m_inst, "foo/1");
auto topic2 = wpi::nt::GetTopic(m_inst, "foo/2");
@@ -232,7 +240,8 @@ TEST_F(ValueListenerTest, PollEntry) {
auto entry = wpi::nt::GetEntry(m_inst, "foo");
auto poller = wpi::nt::CreateListenerPoller(m_inst);
auto h = wpi::nt::AddPolledListener(poller, entry, wpi::nt::EventFlags::kValueLocal);
auto h = wpi::nt::AddPolledListener(poller, entry,
wpi::nt::EventFlags::kValueLocal);
ASSERT_TRUE(wpi::nt::SetDouble(entry, 0));
@@ -257,7 +266,8 @@ TEST_F(ValueListenerTest, PollImmediate) {
auto poller = wpi::nt::CreateListenerPoller(m_inst);
auto h = wpi::nt::AddPolledListener(
poller, entry, wpi::nt::EventFlags::kValueLocal | wpi::nt::EventFlags::kImmediate);
poller, entry,
wpi::nt::EventFlags::kValueLocal | wpi::nt::EventFlags::kImmediate);
bool timedOut = false;
ASSERT_TRUE(wpi::util::WaitForObject(poller, 1.0, &timedOut));
@@ -265,8 +275,8 @@ TEST_F(ValueListenerTest, PollImmediate) {
auto results = wpi::nt::ReadListenerQueue(poller);
ASSERT_EQ(results.size(), 1u);
EXPECT_EQ(results[0].flags &
(wpi::nt::EventFlags::kValueLocal | wpi::nt::EventFlags::kImmediate),
EXPECT_EQ(results[0].flags & (wpi::nt::EventFlags::kValueLocal |
wpi::nt::EventFlags::kImmediate),
wpi::nt::EventFlags::kValueLocal | wpi::nt::EventFlags::kImmediate);
EXPECT_EQ(results[0].listener, h);
auto valueData = results[0].GetValueEventData();
@@ -281,7 +291,8 @@ TEST_F(ValueListenerTest, PollImmediateNoValue) {
auto poller = wpi::nt::CreateListenerPoller(m_inst);
auto h = wpi::nt::AddPolledListener(
poller, entry, wpi::nt::EventFlags::kValueLocal | wpi::nt::EventFlags::kImmediate);
poller, entry,
wpi::nt::EventFlags::kValueLocal | wpi::nt::EventFlags::kImmediate);
bool timedOut = false;
ASSERT_FALSE(wpi::util::WaitForObject(poller, 0.02, &timedOut));
@@ -317,7 +328,8 @@ TEST_F(ValueListenerTest, PollImmediateSubMultiple) {
auto poller = wpi::nt::CreateListenerPoller(m_inst);
auto h = wpi::nt::AddPolledListener(
poller, sub, wpi::nt::EventFlags::kValueLocal | wpi::nt::EventFlags::kImmediate);
poller, sub,
wpi::nt::EventFlags::kValueLocal | wpi::nt::EventFlags::kImmediate);
bool timedOut = false;
ASSERT_TRUE(wpi::util::WaitForObject(poller, 1.0, &timedOut));
@@ -325,8 +337,8 @@ TEST_F(ValueListenerTest, PollImmediateSubMultiple) {
auto results = wpi::nt::ReadListenerQueue(poller);
ASSERT_EQ(results.size(), 2u);
EXPECT_EQ(results[0].flags &
(wpi::nt::EventFlags::kValueLocal | wpi::nt::EventFlags::kImmediate),
EXPECT_EQ(results[0].flags & (wpi::nt::EventFlags::kValueLocal |
wpi::nt::EventFlags::kImmediate),
wpi::nt::EventFlags::kValueLocal | wpi::nt::EventFlags::kImmediate);
EXPECT_EQ(results[0].listener, h);
auto valueData = results[0].GetValueEventData();
@@ -335,8 +347,8 @@ TEST_F(ValueListenerTest, PollImmediateSubMultiple) {
EXPECT_EQ(valueData->topic, topic1);
EXPECT_EQ(valueData->value, wpi::nt::Value::MakeDouble(0.0));
EXPECT_EQ(results[1].flags &
(wpi::nt::EventFlags::kValueLocal | wpi::nt::EventFlags::kImmediate),
EXPECT_EQ(results[1].flags & (wpi::nt::EventFlags::kValueLocal |
wpi::nt::EventFlags::kImmediate),
wpi::nt::EventFlags::kValueLocal | wpi::nt::EventFlags::kImmediate);
EXPECT_EQ(results[1].listener, h);
valueData = results[1].GetValueEventData();
@@ -354,7 +366,8 @@ TEST_F(ValueListenerTest, TwoSubOneListener) {
auto sub3 = wpi::nt::SubscribeMultiple(m_inst, {{"foo"}});
auto poller = wpi::nt::CreateListenerPoller(m_inst);
auto h = wpi::nt::AddPolledListener(poller, sub1, wpi::nt::EventFlags::kValueLocal);
auto h = wpi::nt::AddPolledListener(poller, sub1,
wpi::nt::EventFlags::kValueLocal);
(void)sub2;
(void)sub3;
@@ -384,7 +397,8 @@ TEST_F(ValueListenerTest, TwoSubOneMultiListener) {
auto sub3 = wpi::nt::SubscribeMultiple(m_inst, {{"foo"}});
auto poller = wpi::nt::CreateListenerPoller(m_inst);
auto h = wpi::nt::AddPolledListener(poller, sub3, wpi::nt::EventFlags::kValueLocal);
auto h = wpi::nt::AddPolledListener(poller, sub3,
wpi::nt::EventFlags::kValueLocal);
(void)sub1;
(void)sub2;

View File

@@ -10,12 +10,13 @@
#include "wpi/util/timestamp.h"
int main(int argc, char** argv) {
wpi::nt::AddLogger(wpi::nt::GetDefaultInstance(), 0, UINT_MAX, [](auto& event) {
if (auto msg = event.GetLogMessage()) {
std::fputs(msg->message.c_str(), stderr);
std::fputc('\n', stderr);
}
});
wpi::nt::AddLogger(wpi::nt::GetDefaultInstance(), 0, UINT_MAX,
[](auto& event) {
if (auto msg = event.GetLogMessage()) {
std::fputs(msg->message.c_str(), stderr);
std::fputc('\n', stderr);
}
});
::testing::InitGoogleMock(&argc, argv);
int ret = RUN_ALL_TESTS();
return ret;

View File

@@ -17,11 +17,13 @@ class MockClientMessageHandler : public net::ClientMessageHandler {
public:
MOCK_METHOD(void, ClientPublish,
(int pubuid, std::string_view name, std::string_view typeStr,
const wpi::util::json& properties, const PubSubOptionsImpl& options),
const wpi::util::json& properties,
const PubSubOptionsImpl& options),
(override));
MOCK_METHOD(void, ClientUnpublish, (int pubuid), (override));
MOCK_METHOD(void, ClientSetProperties,
(std::string_view name, const wpi::util::json& update), (override));
(std::string_view name, const wpi::util::json& update),
(override));
MOCK_METHOD(void, ClientSubscribe,
(int subuid, std::span<const std::string> prefixes,
const PubSubOptionsImpl& options),

View File

@@ -25,28 +25,30 @@ class MockWireConnection : public WireConnection {
MOCK_METHOD(bool, Ready, (), (const, override));
int WriteText(wpi::util::function_ref<void(wpi::util::raw_ostream& os)> writer) override {
int WriteText(wpi::util::function_ref<void(wpi::util::raw_ostream& os)>
writer) override {
std::string text;
wpi::util::raw_string_ostream os{text};
writer(os);
return DoWriteText(text);
}
int WriteBinary(
wpi::util::function_ref<void(wpi::util::raw_ostream& os)> writer) override {
int WriteBinary(wpi::util::function_ref<void(wpi::util::raw_ostream& os)>
writer) override {
std::vector<uint8_t> binary;
wpi::util::raw_uvector_ostream os{binary};
writer(os);
return DoWriteBinary(binary);
}
void SendText(wpi::util::function_ref<void(wpi::util::raw_ostream& os)> writer) override {
void SendText(wpi::util::function_ref<void(wpi::util::raw_ostream& os)>
writer) override {
std::string text;
wpi::util::raw_string_ostream os{text};
writer(os);
DoSendText(text);
}
void SendBinary(
wpi::util::function_ref<void(wpi::util::raw_ostream& os)> writer) override {
void SendBinary(wpi::util::function_ref<void(wpi::util::raw_ostream& os)>
writer) override {
std::vector<uint8_t> binary;
wpi::util::raw_uvector_ostream os{binary};
writer(os);

View File

@@ -108,17 +108,19 @@ TEST_F(WireDecodeTextClientTest, ErrorUnknownMethod) {
}
TEST_F(WireDecodeTextClientTest, PublishPropsEmpty) {
EXPECT_CALL(handler, ClientPublish(5, std::string_view{"test"},
std::string_view{"double"},
wpi::util::json::object(), PubSubOptionsEq({})));
EXPECT_CALL(
handler,
ClientPublish(5, std::string_view{"test"}, std::string_view{"double"},
wpi::util::json::object(), PubSubOptionsEq({})));
net::WireDecodeText(
"[{\"method\":\"publish\",\"params\":{"
"\"name\":\"test\",\"properties\":{},\"pubuid\":5,\"type\":\"double\"}}]",
handler, logger);
EXPECT_CALL(handler, ClientPublish(5, std::string_view{"test"},
std::string_view{"double"},
wpi::util::json::object(), PubSubOptionsEq({})));
EXPECT_CALL(
handler,
ClientPublish(5, std::string_view{"test"}, std::string_view{"double"},
wpi::util::json::object(), PubSubOptionsEq({})));
net::WireDecodeText(
"[{\"method\":\"publish\",\"params\":{"
"\"name\":\"test\",\"pubuid\":5,\"type\":\"double\"}}]",

View File

@@ -128,7 +128,8 @@ TEST_F(WireEncoderTextTest, AnnounceProperties) {
}
TEST_F(WireEncoderTextTest, AnnouncePubuid) {
net::WireEncodeAnnounce(os, "test", 5, "double", wpi::util::json::object(), 6);
net::WireEncodeAnnounce(os, "test", 5, "double", wpi::util::json::object(),
6);
ASSERT_EQ(os.str(),
"{\"method\":\"announce\",\"params\":{\"id\":5,\"name\":\"test\","
"\"properties\":{},\"pubuid\":6,\"type\":\"double\"}}");
@@ -179,8 +180,8 @@ TEST_F(WireEncoderTextTest, MessageUnsubscribe) {
}
TEST_F(WireEncoderTextTest, MessageAnnounce) {
net::ServerMessage msg{
net::AnnounceMsg{"test", 5, "double", std::nullopt, wpi::util::json::object()}};
net::ServerMessage msg{net::AnnounceMsg{"test", 5, "double", std::nullopt,
wpi::util::json::object()}};
ASSERT_TRUE(net::WireEncodeText(os, msg));
ASSERT_EQ(os.str(),
"{\"method\":\"announce\",\"params\":{\"id\":5,\"name\":\"test\","
@@ -234,14 +235,15 @@ TEST_F(WireEncoderBinaryTest, Integer) {
TEST_F(WireEncoderBinaryTest, Float) {
net::WireEncodeBinary(os, 5, 6, Value::MakeFloat(2.5));
ASSERT_THAT(out, wpi::util::SpanEq("\x94\x05\x06\x03\xca\x40\x20\x00\x00"_us));
ASSERT_THAT(out,
wpi::util::SpanEq("\x94\x05\x06\x03\xca\x40\x20\x00\x00"_us));
}
TEST_F(WireEncoderBinaryTest, Double) {
net::WireEncodeBinary(os, 5, 6, Value::MakeDouble(2.5));
ASSERT_THAT(
out,
wpi::util::SpanEq("\x94\x05\x06\x01\xcb\x40\x04\x00\x00\x00\x00\x00\x00"_us));
ASSERT_THAT(out,
wpi::util::SpanEq(
"\x94\x05\x06\x01\xcb\x40\x04\x00\x00\x00\x00\x00\x00"_us));
}
TEST_F(WireEncoderBinaryTest, String) {
@@ -267,23 +269,24 @@ TEST_F(WireEncoderBinaryTest, IntegerArray) {
TEST_F(WireEncoderBinaryTest, FloatArray) {
net::WireEncodeBinary(os, 5, 6, Value::MakeFloatArray({1, 2, 3}));
ASSERT_THAT(out, wpi::util::SpanEq("\x94\x05\x06\x13\x93"
"\xca\x3f\x80\x00\x00"
"\xca\x40\x00\x00\x00"
"\xca\x40\x40\x00\x00"_us));
"\xca\x3f\x80\x00\x00"
"\xca\x40\x00\x00\x00"
"\xca\x40\x40\x00\x00"_us));
}
TEST_F(WireEncoderBinaryTest, DoubleArray) {
net::WireEncodeBinary(os, 5, 6, Value::MakeDoubleArray({1, 2, 3}));
ASSERT_THAT(out, wpi::util::SpanEq("\x94\x05\x06\x11\x93"
"\xcb\x3f\xf0\x00\x00\x00\x00\x00\x00"
"\xcb\x40\x00\x00\x00\x00\x00\x00\x00"
"\xcb\x40\x08\x00\x00\x00\x00\x00\x00"_us));
ASSERT_THAT(out,
wpi::util::SpanEq("\x94\x05\x06\x11\x93"
"\xcb\x3f\xf0\x00\x00\x00\x00\x00\x00"
"\xcb\x40\x00\x00\x00\x00\x00\x00\x00"
"\xcb\x40\x08\x00\x00\x00\x00\x00\x00"_us));
}
TEST_F(WireEncoderBinaryTest, StringArray) {
net::WireEncodeBinary(os, 5, 6, Value::MakeStringArray({"hello", "bye"}));
ASSERT_THAT(out, wpi::util::SpanEq("\x94\x05\x06\x14\x92\xa5hello\xa3"
"bye"_us));
"bye"_us));
}
} // namespace wpi::nt

View File

@@ -167,8 +167,8 @@ TEST_F(ServerImplTest, PublishLocal) {
}
{
queue.msgs.emplace_back(net::ClientMessage{
net::PublishMsg{pubuid, "test", "double", wpi::util::json::object(), {}}});
queue.msgs.emplace_back(net::ClientMessage{net::PublishMsg{
pubuid, "test", "double", wpi::util::json::object(), {}}});
EXPECT_FALSE(server.ProcessLocalMessages(UINT_MAX));
}
@@ -186,18 +186,21 @@ TEST_F(ServerImplTest, PublishLocal) {
EXPECT_CALL(wire, SendPing(100));
EXPECT_CALL(wire, Ready()).WillOnce(Return(true)); // SendControl()
EXPECT_CALL(
wire, DoWriteText(StrEq(EncodeText1(net::ServerMessage{net::AnnounceMsg{
"test", 3, "double", std::nullopt, wpi::util::json::object()}}))))
wire,
DoWriteText(StrEq(EncodeText1(net::ServerMessage{net::AnnounceMsg{
"test", 3, "double", std::nullopt, wpi::util::json::object()}}))))
.WillOnce(Return(0));
EXPECT_CALL(
wire, DoWriteText(StrEq(EncodeText1(net::ServerMessage{net::AnnounceMsg{
"test2", 8, "double", std::nullopt, wpi::util::json::object()}}))))
wire,
DoWriteText(StrEq(EncodeText1(net::ServerMessage{net::AnnounceMsg{
"test2", 8, "double", std::nullopt, wpi::util::json::object()}}))))
.WillOnce(Return(0));
EXPECT_CALL(wire, Flush()).WillOnce(Return(0)); // SendControl()
EXPECT_CALL(wire, Ready()).WillOnce(Return(true)); // SendControl()
EXPECT_CALL(
wire, DoWriteText(StrEq(EncodeText1(net::ServerMessage{net::AnnounceMsg{
"test3", 11, "double", std::nullopt, wpi::util::json::object()}}))))
wire,
DoWriteText(StrEq(EncodeText1(net::ServerMessage{net::AnnounceMsg{
"test3", 11, "double", std::nullopt, wpi::util::json::object()}}))))
.WillOnce(Return(0));
EXPECT_CALL(wire, Flush()).WillOnce(Return(0)); // SendControl()
}
@@ -214,8 +217,8 @@ TEST_F(ServerImplTest, PublishLocal) {
// publish before send control
{
queue.msgs.emplace_back(net::ClientMessage{
net::PublishMsg{pubuid2, "test2", "double", wpi::util::json::object(), {}}});
queue.msgs.emplace_back(net::ClientMessage{net::PublishMsg{
pubuid2, "test2", "double", wpi::util::json::object(), {}}});
EXPECT_FALSE(server.ProcessLocalMessages(UINT_MAX));
}
@@ -223,8 +226,8 @@ TEST_F(ServerImplTest, PublishLocal) {
// publish after send control
{
queue.msgs.emplace_back(net::ClientMessage{
net::PublishMsg{pubuid3, "test3", "double", wpi::util::json::object(), {}}});
queue.msgs.emplace_back(net::ClientMessage{net::PublishMsg{
pubuid3, "test3", "double", wpi::util::json::object(), {}}});
EXPECT_FALSE(server.ProcessLocalMessages(UINT_MAX));
}
@@ -241,8 +244,8 @@ TEST_F(ServerImplTest, ClientSubTopicOnlyThenValue) {
wpi::util::json::object(), std::optional<int>{pubuid}));
{
queue.msgs.emplace_back(net::ClientMessage{
net::PublishMsg{pubuid, "test", "double", wpi::util::json::object(), {}}});
queue.msgs.emplace_back(net::ClientMessage{net::PublishMsg{
pubuid, "test", "double", wpi::util::json::object(), {}}});
queue.msgs.emplace_back(net::ClientMessage{
net::ClientValueMsg{pubuid, Value::MakeDouble(1.0, 10)}});
EXPECT_FALSE(server.ProcessLocalMessages(UINT_MAX));
@@ -260,16 +263,18 @@ TEST_F(ServerImplTest, ClientSubTopicOnlyThenValue) {
EXPECT_CALL(wire, SendPing(100));
EXPECT_CALL(wire, Ready()).WillOnce(Return(true)); // SendValues()
EXPECT_CALL(
wire, DoWriteText(StrEq(EncodeText1(net::ServerMessage{net::AnnounceMsg{
"test", 3, "double", std::nullopt, wpi::util::json::object()}}))))
wire,
DoWriteText(StrEq(EncodeText1(net::ServerMessage{net::AnnounceMsg{
"test", 3, "double", std::nullopt, wpi::util::json::object()}}))))
.WillOnce(Return(0));
EXPECT_CALL(wire, Flush()).WillOnce(Return(0)); // SendValues()
EXPECT_CALL(setPeriodic, Call(100)); // ClientSubscribe()
// EXPECT_CALL(wire, Flush()).WillOnce(Return(0)); // ClientSubscribe()
EXPECT_CALL(wire, Ready()).WillOnce(Return(true)); // SendValues()
EXPECT_CALL(
wire, DoWriteBinary(wpi::util::SpanEq(EncodeServerBinary1(net::ServerMessage{
net::ServerValueMsg{3, Value::MakeDouble(1.0, 10)}}))))
wire,
DoWriteBinary(wpi::util::SpanEq(EncodeServerBinary1(net::ServerMessage{
net::ServerValueMsg{3, Value::MakeDouble(1.0, 10)}}))))
.WillOnce(Return(0));
EXPECT_CALL(wire, Flush()); // SendValues()
}
@@ -309,10 +314,10 @@ TEST_F(ServerImplTest, ClientDisconnectUnpublish) {
constexpr int subuid = 1;
{
::testing::InSequence seq;
EXPECT_CALL(
local,
ServerAnnounce(std::string_view{"test2"}, 0, std::string_view{"double"},
wpi::util::json::object(), std::optional<int>{pubuidLocal}));
EXPECT_CALL(local, ServerAnnounce(std::string_view{"test2"}, 0,
std::string_view{"double"},
wpi::util::json::object(),
std::optional<int>{pubuidLocal}));
EXPECT_CALL(
local,
ServerAnnounce(std::string_view{"test"}, 0, std::string_view{"double"},
@@ -357,8 +362,8 @@ TEST_F(ServerImplTest, ClientDisconnectUnpublish) {
{
constexpr int pubuid = 1;
std::vector<net::ClientMessage> msgs;
msgs.emplace_back(net::ClientMessage{
net::PublishMsg{pubuid, "test", "double", wpi::util::json::object(), {}}});
msgs.emplace_back(net::ClientMessage{net::PublishMsg{
pubuid, "test", "double", wpi::util::json::object(), {}}});
server.ProcessIncomingText(id, EncodeText(msgs));
}
@@ -390,8 +395,8 @@ TEST_F(ServerImplTest, ZeroTimestampNegativeTime) {
}
{
queue.msgs.emplace_back(net::ClientMessage{
net::PublishMsg{pubuid, "test", "double", wpi::util::json::object(), {}}});
queue.msgs.emplace_back(net::ClientMessage{net::PublishMsg{
pubuid, "test", "double", wpi::util::json::object(), {}}});
queue.msgs.emplace_back(
net::ClientMessage{net::ClientValueMsg{pubuid, defaultValue}});
queue.msgs.emplace_back(
@@ -414,8 +419,8 @@ TEST_F(ServerImplTest, ZeroTimestampNegativeTime) {
{
constexpr int pubuid2 = 2;
std::vector<net::ClientMessage> msgs;
msgs.emplace_back(net::ClientMessage{
net::PublishMsg{pubuid2, "test", "double", wpi::util::json::object(), {}}});
msgs.emplace_back(net::ClientMessage{net::PublishMsg{
pubuid2, "test", "double", wpi::util::json::object(), {}}});
server.ProcessIncomingText(id, EncodeText(msgs));
msgs.clear();
msgs.emplace_back(net::ClientMessage{net::ClientValueMsg{pubuid2, value}});