mirror of
https://github.com/wpilibsuite/allwpilib
synced 2026-07-06 03:31:43 +00:00
SCRIPT: wpiformat
This commit is contained in:
committed by
Peter Johnson
parent
ae6bdc9d25
commit
2109161534
@@ -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)) {
|
||||
|
||||
@@ -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) {
|
||||
|
||||
@@ -27,7 +27,7 @@
|
||||
|
||||
namespace wpi::util {
|
||||
class Logger;
|
||||
} // namespace wpi
|
||||
} // namespace wpi::util
|
||||
|
||||
namespace wpi::nt::net {
|
||||
class ILocalStorage;
|
||||
|
||||
@@ -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},
|
||||
|
||||
@@ -22,7 +22,7 @@
|
||||
|
||||
namespace wpi::util {
|
||||
class Logger;
|
||||
} // namespace wpi
|
||||
} // namespace wpi::util
|
||||
|
||||
namespace wpi::nt::net {
|
||||
class ILocalStorage;
|
||||
|
||||
@@ -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;
|
||||
|
||||
@@ -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});
|
||||
}
|
||||
|
||||
/*
|
||||
|
||||
@@ -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);
|
||||
}
|
||||
|
||||
@@ -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);
|
||||
|
||||
@@ -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,
|
||||
|
||||
@@ -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 {
|
||||
|
||||
@@ -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
|
||||
|
||||
@@ -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);
|
||||
|
||||
@@ -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);
|
||||
|
||||
|
||||
@@ -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{
|
||||
|
||||
@@ -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;
|
||||
};
|
||||
|
||||
|
||||
@@ -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) {
|
||||
|
||||
@@ -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);
|
||||
|
||||
|
||||
@@ -12,7 +12,7 @@
|
||||
|
||||
namespace wpi::util {
|
||||
class raw_ostream;
|
||||
} // namespace wpi
|
||||
} // namespace wpi::util
|
||||
|
||||
namespace wpi::nt::net {
|
||||
|
||||
|
||||
@@ -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());
|
||||
|
||||
@@ -12,7 +12,7 @@
|
||||
|
||||
namespace wpi::util {
|
||||
class Logger;
|
||||
} // namespace wpi
|
||||
} // namespace wpi::util
|
||||
|
||||
namespace wpi::nt {
|
||||
class Value;
|
||||
|
||||
@@ -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);
|
||||
|
||||
@@ -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
|
||||
|
||||
@@ -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;
|
||||
|
||||
@@ -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));
|
||||
}
|
||||
|
||||
@@ -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) {
|
||||
|
||||
@@ -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;
|
||||
}
|
||||
|
||||
|
||||
@@ -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);
|
||||
|
||||
@@ -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);
|
||||
|
||||
@@ -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;
|
||||
|
||||
@@ -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;
|
||||
|
||||
@@ -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;
|
||||
}
|
||||
|
||||
@@ -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,
|
||||
|
||||
@@ -19,7 +19,7 @@
|
||||
|
||||
namespace wpi::util {
|
||||
class Logger;
|
||||
} // namespace wpi
|
||||
} // namespace wpi::util
|
||||
|
||||
namespace wpi::nt::net {
|
||||
class ClientMessageQueue;
|
||||
|
||||
@@ -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);
|
||||
|
||||
@@ -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,
|
||||
|
||||
@@ -18,7 +18,7 @@
|
||||
|
||||
namespace wpi::util {
|
||||
class Logger;
|
||||
} // namespace wpi
|
||||
} // namespace wpi::util
|
||||
|
||||
namespace wpi::nt::server {
|
||||
|
||||
|
||||
@@ -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;
|
||||
|
||||
@@ -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
|
||||
|
||||
@@ -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};
|
||||
|
||||
@@ -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)};
|
||||
}
|
||||
};
|
||||
|
||||
|
||||
@@ -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);
|
||||
|
||||
@@ -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};
|
||||
}
|
||||
};
|
||||
|
||||
|
||||
@@ -25,7 +25,7 @@
|
||||
namespace wpi::util {
|
||||
template <typename T>
|
||||
class SmallVectorImpl;
|
||||
} // namespace wpi
|
||||
} // namespace wpi::util
|
||||
|
||||
namespace wpi::log {
|
||||
class DataLog;
|
||||
|
||||
Reference in New Issue
Block a user