[wpilib] Remove LiveWindow (#7733)

This will be replaced by a different mechanism, but removing it eases
the initial implementation burden of a new Telemetry/Sendable framework.
This commit is contained in:
Peter Johnson
2025-01-25 10:52:19 -08:00
committed by GitHub
parent adbe95e610
commit eee30c49e2
88 changed files with 85 additions and 1356 deletions

View File

@@ -26,7 +26,6 @@ struct Component {
std::string name;
std::string subsystem = "Ungrouped";
Sendable* parent = nullptr;
bool liveWindow = false;
wpi::SmallVector<std::shared_ptr<void>, 2> data;
void SetName(std::string_view moduleType, int channel) {
@@ -41,7 +40,6 @@ struct Component {
struct SendableRegistryInst {
wpi::recursive_mutex mutex;
std::function<std::unique_ptr<SendableBuilder>()> liveWindowFactory;
wpi::UidVector<std::unique_ptr<Component>, 32> components;
wpi::DenseMap<void*, SendableRegistry::UID> componentMap;
int nextDataHandle = 0;
@@ -85,11 +83,6 @@ void SendableRegistry::EnsureInitialized() {
GetInstance();
}
void SendableRegistry::SetLiveWindowBuilderFactory(
std::function<std::unique_ptr<SendableBuilder>()> factory) {
GetInstance().liveWindowFactory = std::move(factory);
}
void SendableRegistry::Add(Sendable* sendable, std::string_view name) {
auto& inst = GetInstance();
std::scoped_lock lock(inst.mutex);
@@ -126,58 +119,6 @@ void SendableRegistry::Add(Sendable* sendable, std::string_view subsystem,
comp.subsystem = subsystem;
}
void SendableRegistry::AddLW(Sendable* sendable, std::string_view name) {
auto& inst = GetInstance();
std::scoped_lock lock(inst.mutex);
auto& comp = inst.GetOrAdd(sendable);
comp.sendable = sendable;
if (inst.liveWindowFactory) {
comp.builder = inst.liveWindowFactory();
}
comp.liveWindow = true;
comp.name = name;
}
void SendableRegistry::AddLW(Sendable* sendable, std::string_view moduleType,
int channel) {
auto& inst = GetInstance();
std::scoped_lock lock(inst.mutex);
auto& comp = inst.GetOrAdd(sendable);
comp.sendable = sendable;
if (inst.liveWindowFactory) {
comp.builder = inst.liveWindowFactory();
}
comp.liveWindow = true;
comp.SetName(moduleType, channel);
}
void SendableRegistry::AddLW(Sendable* sendable, std::string_view moduleType,
int moduleNumber, int channel) {
auto& inst = GetInstance();
std::scoped_lock lock(inst.mutex);
auto& comp = inst.GetOrAdd(sendable);
comp.sendable = sendable;
if (inst.liveWindowFactory) {
comp.builder = inst.liveWindowFactory();
}
comp.liveWindow = true;
comp.SetName(moduleType, moduleNumber, channel);
}
void SendableRegistry::AddLW(Sendable* sendable, std::string_view subsystem,
std::string_view name) {
auto& inst = GetInstance();
std::scoped_lock lock(inst.mutex);
auto& comp = inst.GetOrAdd(sendable);
comp.sendable = sendable;
if (inst.liveWindowFactory) {
comp.builder = inst.liveWindowFactory();
}
comp.liveWindow = true;
comp.name = name;
comp.subsystem = subsystem;
}
void SendableRegistry::AddChild(Sendable* parent, Sendable* child) {
auto& inst = GetInstance();
std::scoped_lock lock(inst.mutex);
@@ -361,26 +302,6 @@ std::shared_ptr<void> SendableRegistry::GetData(Sendable* sendable,
return comp.data[handle];
}
void SendableRegistry::EnableLiveWindow(Sendable* sendable) {
auto& inst = GetInstance();
std::scoped_lock lock(inst.mutex);
auto it = inst.componentMap.find(sendable);
if (it == inst.componentMap.end() || !inst.components[it->getSecond() - 1]) {
return;
}
inst.components[it->getSecond() - 1]->liveWindow = true;
}
void SendableRegistry::DisableLiveWindow(Sendable* sendable) {
auto& inst = GetInstance();
std::scoped_lock lock(inst.mutex);
auto it = inst.componentMap.find(sendable);
if (it == inst.componentMap.end() || !inst.components[it->getSecond() - 1]) {
return;
}
inst.components[it->getSecond() - 1]->liveWindow = false;
}
SendableRegistry::UID SendableRegistry::GetUniqueId(Sendable* sendable) {
auto& inst = GetInstance();
std::scoped_lock lock(inst.mutex);
@@ -430,25 +351,3 @@ void SendableRegistry::Update(UID sendableUid) {
inst.components[sendableUid - 1]->builder->Update();
}
}
void SendableRegistry::ForeachLiveWindow(
int dataHandle, wpi::function_ref<void(CallbackData& data)> callback) {
auto& inst = GetInstance();
assert(dataHandle >= 0);
std::scoped_lock lock(inst.mutex);
wpi::SmallVector<Component*, 128> components;
for (auto&& comp : inst.components) {
components.emplace_back(comp.get());
}
for (auto comp : components) {
if (comp && comp->builder && comp->sendable && comp->liveWindow) {
if (static_cast<size_t>(dataHandle) >= comp->data.size()) {
comp->data.resize(dataHandle + 1);
}
CallbackData cbdata{comp->sendable, comp->name,
comp->subsystem, comp->parent,
comp->data[dataHandle], *comp->builder};
callback(cbdata);
}
}
}

View File

@@ -48,14 +48,6 @@ class SendableBuilder {
*/
virtual void SetActuator(bool value) = 0;
/**
* Set the function that should be called to set the Sendable into a safe
* state. This is called when entering and exiting Live Window mode.
*
* @param func function
*/
virtual void SetSafeState(std::function<void()> func) = 0;
/**
* Add a boolean property.
*

View File

@@ -4,13 +4,10 @@
#pragma once
#include <functional>
#include <memory>
#include <string>
#include <string_view>
#include "wpi/function_ref.h"
namespace wpi {
class Sendable;
@@ -18,7 +15,7 @@ class SendableBuilder;
/**
* The SendableRegistry class is the public interface for registering sensors
* and actuators for use on dashboards and LiveWindow.
* and actuators for use on dashboards.
*/
class SendableRegistry final {
public:
@@ -32,14 +29,6 @@ class SendableRegistry final {
*/
static void EnsureInitialized();
/**
* Sets the factory for LiveWindow builders.
*
* @param factory factory function
*/
static void SetLiveWindowBuilderFactory(
std::function<std::unique_ptr<SendableBuilder>()> factory);
/**
* Adds an object to the registry.
*
@@ -80,47 +69,6 @@ class SendableRegistry final {
static void Add(Sendable* sendable, std::string_view subsystem,
std::string_view name);
/**
* Adds an object to the registry and LiveWindow.
*
* @param sendable object to add
* @param name component name
*/
static void AddLW(Sendable* sendable, std::string_view name);
/**
* Adds an object to the registry and LiveWindow.
*
* @param sendable object to add
* @param moduleType A string that defines the module name in the label for
* the value
* @param channel The channel number the device is plugged into
*/
static void AddLW(Sendable* sendable, std::string_view moduleType,
int channel);
/**
* Adds an object to the registry and LiveWindow.
*
* @param sendable object to add
* @param moduleType A string that defines the module name in the label for
* the value
* @param moduleNumber The number of the particular module type
* @param channel The channel number the device is plugged into
*/
static void AddLW(Sendable* sendable, std::string_view moduleType,
int moduleNumber, int channel);
/**
* Adds an object to the registry and LiveWindow.
*
* @param sendable object to add
* @param subsystem subsystem name
* @param name component name
*/
static void AddLW(Sendable* sendable, std::string_view subsystem,
std::string_view name);
/**
* Adds a child object to an object. Adds the child object to the registry
* if it's not already present.
@@ -255,20 +203,6 @@ class SendableRegistry final {
*/
static std::shared_ptr<void> GetData(Sendable* sendable, int handle);
/**
* Enables LiveWindow for an object.
*
* @param sendable object
*/
static void EnableLiveWindow(Sendable* sendable);
/**
* Disables LiveWindow for an object.
*
* @param sendable object
*/
static void DisableLiveWindow(Sendable* sendable);
/**
* Get unique id for an object. Since objects can move, use this instead
* of storing Sendable* directly if ownership is in question.
@@ -301,39 +235,6 @@ class SendableRegistry final {
* @param sendableUid sendable unique id
*/
static void Update(UID sendableUid);
/**
* Data passed to ForeachLiveWindow() callback function
*/
struct CallbackData {
CallbackData(Sendable* sendable_, std::string_view name_,
std::string_view subsystem_, wpi::Sendable* parent_,
std::shared_ptr<void>& data_, SendableBuilder& builder_)
: sendable(sendable_),
name(name_),
subsystem(subsystem_),
parent(parent_),
data(data_),
builder(builder_) {}
Sendable* sendable;
std::string_view name;
std::string_view subsystem;
Sendable* parent;
std::shared_ptr<void>& data;
SendableBuilder& builder;
};
/**
* Iterates over LiveWindow-enabled objects in the registry.
* It is *not* safe to call other SendableRegistry functions from the
* callback (this will likely deadlock).
*
* @param dataHandle data handle to get data pointer passed to callback
* @param callback function to call for each object
*/
static void ForeachLiveWindow(
int dataHandle, wpi::function_ref<void(CallbackData& cbdata)> callback);
};
} // namespace wpi