WPILibC++  2020.3.2-60-g3011ebe
frc::SendableRegistry Class Reference

The SendableRegistry class is the public interface for registering sensors and actuators for use on dashboards and LiveWindow. More...

#include <SendableRegistry.h>

Classes

struct  CallbackData
 Data passed to ForeachLiveWindow() callback function. More...
 

Public Types

using UID = size_t
 

Public Member Functions

 SendableRegistry (const SendableRegistry &)=delete
 
SendableRegistryoperator= (const SendableRegistry &)=delete
 
void Add (Sendable *sendable, const wpi::Twine &name)
 Adds an object to the registry. More...
 
void Add (Sendable *sendable, const wpi::Twine &moduleType, int channel)
 Adds an object to the registry. More...
 
void Add (Sendable *sendable, const wpi::Twine &moduleType, int moduleNumber, int channel)
 Adds an object to the registry. More...
 
void Add (Sendable *sendable, const wpi::Twine &subsystem, const wpi::Twine &name)
 Adds an object to the registry. More...
 
void AddLW (Sendable *sendable, const wpi::Twine &name)
 Adds an object to the registry and LiveWindow. More...
 
void AddLW (Sendable *sendable, const wpi::Twine &moduleType, int channel)
 Adds an object to the registry and LiveWindow. More...
 
void AddLW (Sendable *sendable, const wpi::Twine &moduleType, int moduleNumber, int channel)
 Adds an object to the registry and LiveWindow. More...
 
void AddLW (Sendable *sendable, const wpi::Twine &subsystem, const wpi::Twine &name)
 Adds an object to the registry and LiveWindow. More...
 
void AddChild (Sendable *parent, Sendable *child)
 Adds a child object to an object. More...
 
void AddChild (Sendable *parent, void *child)
 Adds a child object to an object. More...
 
bool Remove (Sendable *sendable)
 Removes an object from the registry. More...
 
void Move (Sendable *to, Sendable *from)
 Moves an object in the registry (for use in move constructors/assignments). More...
 
bool Contains (const Sendable *sendable) const
 Determines if an object is in the registry. More...
 
std::string GetName (const Sendable *sendable) const
 Gets the name of an object. More...
 
void SetName (Sendable *sendable, const wpi::Twine &name)
 Sets the name of an object. More...
 
void SetName (Sendable *sendable, const wpi::Twine &moduleType, int channel)
 Sets the name of an object with a channel number. More...
 
void SetName (Sendable *sendable, const wpi::Twine &moduleType, int moduleNumber, int channel)
 Sets the name of an object with a module and channel number. More...
 
void SetName (Sendable *sendable, const wpi::Twine &subsystem, const wpi::Twine &name)
 Sets both the subsystem name and device name of an object. More...
 
std::string GetSubsystem (const Sendable *sendable) const
 Gets the subsystem name of an object. More...
 
void SetSubsystem (Sendable *sendable, const wpi::Twine &subsystem)
 Sets the subsystem name of an object. More...
 
int GetDataHandle ()
 Gets a unique handle for setting/getting data with SetData() and GetData(). More...
 
std::shared_ptr< void > SetData (Sendable *sendable, int handle, std::shared_ptr< void > data)
 Associates arbitrary data with an object in the registry. More...
 
std::shared_ptr< void > GetData (Sendable *sendable, int handle)
 Gets arbitrary data associated with an object in the registry. More...
 
void EnableLiveWindow (Sendable *sendable)
 Enables LiveWindow for an object. More...
 
void DisableLiveWindow (Sendable *sendable)
 Disables LiveWindow for an object. More...
 
UID GetUniqueId (Sendable *sendable)
 Get unique id for an object. More...
 
SendableGetSendable (UID uid)
 Get sendable object for a given unique id. More...
 
void Publish (UID sendableUid, std::shared_ptr< NetworkTable > table)
 Publishes an object in the registry to a network table. More...
 
void Update (UID sendableUid)
 Updates network table information from an object. More...
 
void ForeachLiveWindow (int dataHandle, wpi::function_ref< void(CallbackData &cbdata)> callback) const
 Iterates over LiveWindow-enabled objects in the registry. More...
 

Static Public Member Functions

static SendableRegistryGetInstance ()
 Gets an instance of the SendableRegistry class. More...
 

Detailed Description

The SendableRegistry class is the public interface for registering sensors and actuators for use on dashboards and LiveWindow.

Member Function Documentation

◆ Add() [1/4]

void frc::SendableRegistry::Add ( Sendable sendable,
const wpi::Twine moduleType,
int  channel 
)

Adds an object to the registry.

Parameters
sendableobject to add
moduleTypeA string that defines the module name in the label for the value
channelThe channel number the device is plugged into

◆ Add() [2/4]

void frc::SendableRegistry::Add ( Sendable sendable,
const wpi::Twine moduleType,
int  moduleNumber,
int  channel 
)

Adds an object to the registry.

Parameters
sendableobject to add
moduleTypeA string that defines the module name in the label for the value
moduleNumberThe number of the particular module type
channelThe channel number the device is plugged into

◆ Add() [3/4]

void frc::SendableRegistry::Add ( Sendable sendable,
const wpi::Twine name 
)

Adds an object to the registry.

Parameters
sendableobject to add
namecomponent name

◆ Add() [4/4]

void frc::SendableRegistry::Add ( Sendable sendable,
const wpi::Twine subsystem,
const wpi::Twine name 
)

Adds an object to the registry.

Parameters
sendableobject to add
subsystemsubsystem name
namecomponent name

◆ AddChild() [1/2]

void frc::SendableRegistry::AddChild ( Sendable parent,
Sendable child 
)

Adds a child object to an object.

Adds the child object to the registry if it's not already present.

Parameters
parentparent object
childchild object

◆ AddChild() [2/2]

void frc::SendableRegistry::AddChild ( Sendable parent,
void *  child 
)

Adds a child object to an object.

Adds the child object to the registry if it's not already present.

Parameters
parentparent object
childchild object

◆ AddLW() [1/4]

void frc::SendableRegistry::AddLW ( Sendable sendable,
const wpi::Twine moduleType,
int  channel 
)

Adds an object to the registry and LiveWindow.

Parameters
sendableobject to add
moduleTypeA string that defines the module name in the label for the value
channelThe channel number the device is plugged into

◆ AddLW() [2/4]

void frc::SendableRegistry::AddLW ( Sendable sendable,
const wpi::Twine moduleType,
int  moduleNumber,
int  channel 
)

Adds an object to the registry and LiveWindow.

Parameters
sendableobject to add
moduleTypeA string that defines the module name in the label for the value
moduleNumberThe number of the particular module type
channelThe channel number the device is plugged into

◆ AddLW() [3/4]

void frc::SendableRegistry::AddLW ( Sendable sendable,
const wpi::Twine name 
)

Adds an object to the registry and LiveWindow.

Parameters
sendableobject to add
namecomponent name

◆ AddLW() [4/4]

void frc::SendableRegistry::AddLW ( Sendable sendable,
const wpi::Twine subsystem,
const wpi::Twine name 
)

Adds an object to the registry and LiveWindow.

Parameters
sendableobject to add
subsystemsubsystem name
namecomponent name

◆ Contains()

bool frc::SendableRegistry::Contains ( const Sendable sendable) const

Determines if an object is in the registry.

Parameters
sendableobject to check
Returns
True if in registry, false if not.

◆ DisableLiveWindow()

void frc::SendableRegistry::DisableLiveWindow ( Sendable sendable)

Disables LiveWindow for an object.

Parameters
sendableobject

◆ EnableLiveWindow()

void frc::SendableRegistry::EnableLiveWindow ( Sendable sendable)

Enables LiveWindow for an object.

Parameters
sendableobject

◆ ForeachLiveWindow()

void frc::SendableRegistry::ForeachLiveWindow ( int  dataHandle,
wpi::function_ref< void(CallbackData &cbdata)>  callback 
) const

Iterates over LiveWindow-enabled objects in the registry.

It is not safe to call other SendableRegistry functions from the callback (this will likely deadlock).

Parameters
dataHandledata handle to get data pointer passed to callback
callbackfunction to call for each object

◆ GetData()

std::shared_ptr<void> frc::SendableRegistry::GetData ( Sendable sendable,
int  handle 
)

Gets arbitrary data associated with an object in the registry.

Parameters
sendableobject
handledata handle returned by GetDataHandle()
Returns
data (may be null if none associated)

◆ GetDataHandle()

int frc::SendableRegistry::GetDataHandle ( )

Gets a unique handle for setting/getting data with SetData() and GetData().

Returns
Handle

◆ GetInstance()

static SendableRegistry& frc::SendableRegistry::GetInstance ( )
static

Gets an instance of the SendableRegistry class.

This is a singleton to guarantee that there is only a single instance regardless of how many times GetInstance is called.

◆ GetName()

std::string frc::SendableRegistry::GetName ( const Sendable sendable) const

Gets the name of an object.

Parameters
sendableobject
Returns
Name (empty if object is not in registry)

◆ GetSendable()

Sendable* frc::SendableRegistry::GetSendable ( UID  uid)

Get sendable object for a given unique id.

Parameters
uidunique id
Returns
sendable object (may be null)

◆ GetSubsystem()

std::string frc::SendableRegistry::GetSubsystem ( const Sendable sendable) const

Gets the subsystem name of an object.

Parameters
sendableobject
Returns
Subsystem name (empty if object is not in registry)

◆ GetUniqueId()

UID frc::SendableRegistry::GetUniqueId ( Sendable sendable)

Get unique id for an object.

Since objects can move, use this instead of storing Sendable* directly if ownership is in question.

Parameters
sendableobject
Returns
unique id

◆ Move()

void frc::SendableRegistry::Move ( Sendable to,
Sendable from 
)

Moves an object in the registry (for use in move constructors/assignments).

Parameters
tonew object
fromold object

◆ Publish()

void frc::SendableRegistry::Publish ( UID  sendableUid,
std::shared_ptr< NetworkTable table 
)

Publishes an object in the registry to a network table.

Parameters
sendableUidsendable unique id
tablenetwork table

◆ Remove()

bool frc::SendableRegistry::Remove ( Sendable sendable)

Removes an object from the registry.

Parameters
sendableobject to remove
Returns
true if the object was removed; false if it was not present

◆ SetData()

std::shared_ptr<void> frc::SendableRegistry::SetData ( Sendable sendable,
int  handle,
std::shared_ptr< void >  data 
)

Associates arbitrary data with an object in the registry.

Parameters
sendableobject
handledata handle returned by GetDataHandle()
datadata to set
Returns
Previous data (may be null)

◆ SetName() [1/4]

void frc::SendableRegistry::SetName ( Sendable sendable,
const wpi::Twine moduleType,
int  channel 
)

Sets the name of an object with a channel number.

Parameters
sendableobject
moduleTypeA string that defines the module name in the label for the value
channelThe channel number the device is plugged into

◆ SetName() [2/4]

void frc::SendableRegistry::SetName ( Sendable sendable,
const wpi::Twine moduleType,
int  moduleNumber,
int  channel 
)

Sets the name of an object with a module and channel number.

Parameters
sendableobject
moduleTypeA string that defines the module name in the label for the value
moduleNumberThe number of the particular module type
channelThe channel number the device is plugged into

◆ SetName() [3/4]

void frc::SendableRegistry::SetName ( Sendable sendable,
const wpi::Twine name 
)

Sets the name of an object.

Parameters
sendableobject
namename

◆ SetName() [4/4]

void frc::SendableRegistry::SetName ( Sendable sendable,
const wpi::Twine subsystem,
const wpi::Twine name 
)

Sets both the subsystem name and device name of an object.

Parameters
sendableobject
subsystemsubsystem name
namedevice name

◆ SetSubsystem()

void frc::SendableRegistry::SetSubsystem ( Sendable sendable,
const wpi::Twine subsystem 
)

Sets the subsystem name of an object.

Parameters
sendableobject
subsystemsubsystem name

◆ Update()

void frc::SendableRegistry::Update ( UID  sendableUid)

Updates network table information from an object.

Parameters
sendableUidsendable unique id

The documentation for this class was generated from the following file: