mirror of
https://github.com/wpilibsuite/allwpilib
synced 2026-06-30 02:31:44 +00:00
Fix move handling of C++ Sendable in SmartDashboard and LiveWindow
This commit is contained in:
@@ -10,12 +10,14 @@
|
||||
#include <memory>
|
||||
#include <string>
|
||||
|
||||
#include <networktables/NetworkTable.h>
|
||||
#include <wpi/STLExtras.h>
|
||||
#include <wpi/Twine.h>
|
||||
|
||||
namespace frc {
|
||||
|
||||
class Sendable;
|
||||
class SendableBuilderImpl;
|
||||
|
||||
/**
|
||||
* The SendableRegistry class is the public interface for registering sensors
|
||||
@@ -26,6 +28,8 @@ class SendableRegistry {
|
||||
SendableRegistry(const SendableRegistry&) = delete;
|
||||
SendableRegistry& operator=(const SendableRegistry&) = delete;
|
||||
|
||||
using UID = size_t;
|
||||
|
||||
/**
|
||||
* Gets an instance of the SendableRegistry class.
|
||||
*
|
||||
@@ -252,6 +256,60 @@ class SendableRegistry {
|
||||
*/
|
||||
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.
|
||||
*
|
||||
* @param sendable object
|
||||
* @return unique id
|
||||
*/
|
||||
UID GetUniqueId(Sendable* sendable);
|
||||
|
||||
/**
|
||||
* Get sendable object for a given unique id.
|
||||
*
|
||||
* @param uid unique id
|
||||
* @return sendable object (may be null)
|
||||
*/
|
||||
Sendable* GetSendable(UID uid);
|
||||
|
||||
/**
|
||||
* Publishes an object in the registry to a network table.
|
||||
*
|
||||
* @param sendableUid sendable unique id
|
||||
* @param table network table
|
||||
*/
|
||||
void Publish(UID sendableUid, std::shared_ptr<NetworkTable> table);
|
||||
|
||||
/**
|
||||
* Updates network table information from an object.
|
||||
*
|
||||
* @param sendableUid sendable unique id
|
||||
*/
|
||||
void Update(UID sendableUid);
|
||||
|
||||
/**
|
||||
* Data passed to ForeachLiveWindow() callback function
|
||||
*/
|
||||
struct CallbackData {
|
||||
CallbackData(Sendable* sendable_, wpi::StringRef name_,
|
||||
wpi::StringRef subsystem_, Sendable* parent_,
|
||||
std::shared_ptr<void>& data_, SendableBuilderImpl& builder_)
|
||||
: sendable(sendable_),
|
||||
name(name_),
|
||||
subsystem(subsystem_),
|
||||
parent(parent_),
|
||||
data(data_),
|
||||
builder(builder_) {}
|
||||
|
||||
Sendable* sendable;
|
||||
wpi::StringRef name;
|
||||
wpi::StringRef subsystem;
|
||||
Sendable* parent;
|
||||
std::shared_ptr<void>& data;
|
||||
SendableBuilderImpl& builder;
|
||||
};
|
||||
|
||||
/**
|
||||
* Iterates over LiveWindow-enabled objects in the registry.
|
||||
* It is *not* safe to call other SendableRegistry functions from the
|
||||
@@ -262,10 +320,7 @@ class SendableRegistry {
|
||||
*/
|
||||
void ForeachLiveWindow(
|
||||
int dataHandle,
|
||||
wpi::function_ref<void(Sendable* sendable, wpi::StringRef name,
|
||||
wpi::StringRef subsystem, Sendable* parent,
|
||||
std::shared_ptr<void>& data)>
|
||||
callback) const;
|
||||
wpi::function_ref<void(CallbackData& cbdata)> callback) const;
|
||||
|
||||
private:
|
||||
SendableRegistry();
|
||||
|
||||
Reference in New Issue
Block a user