16 #include <networktables/NetworkTable.h>
17 #include <networktables/NetworkTableEntry.h>
18 #include <networktables/NetworkTableValue.h>
19 #include <wpi/ArrayRef.h>
20 #include <wpi/SmallVector.h>
21 #include <wpi/Twine.h>
23 #include "frc/smartdashboard/SendableBuilder.h"
41 void SetTable(std::shared_ptr<nt::NetworkTable> table);
47 std::shared_ptr<nt::NetworkTable>
GetTable();
89 std::function<
void(
bool)> setter)
override;
92 std::function<
void(
double)> setter)
override;
95 std::function<std::string()> getter,
99 const wpi::Twine& key, std::function<std::vector<int>()> getter,
103 const wpi::Twine& key, std::function<std::vector<double>()> getter,
107 const wpi::Twine& key, std::function<std::vector<std::string>()> getter,
111 std::function<std::string()> getter,
115 const wpi::Twine& key, std::function<std::shared_ptr<nt::Value>()> getter,
116 std::function<
void(std::shared_ptr<nt::Value>)> setter)
override;
149 : entry(table.GetEntry(key)) {}
151 Property(
const Property&) =
delete;
152 Property& operator=(
const Property&) =
delete;
154 Property(Property&& other) noexcept
155 : entry(other.entry),
156 listener(other.listener),
157 update(std::move(other.update)),
158 createListener(std::move(other.createListener)) {
163 Property& operator=(Property&& other) noexcept {
165 listener = other.listener;
168 update = std::move(other.update);
169 createListener = std::move(other.createListener);
173 ~Property() { StopListener(); }
175 void StartListener() {
176 if (entry && listener == 0 && createListener)
177 listener = createListener(entry);
180 void StopListener() {
181 if (entry && listener != 0) {
182 entry.RemoveListener(listener);
188 NT_EntryListener listener = 0;
189 std::function<void(nt::NetworkTableEntry entry, uint64_t time)> update;
190 std::function<NT_EntryListener(nt::NetworkTableEntry entry)> createListener;
193 std::vector<Property> m_properties;
194 std::function<void()> m_safeState;
195 std::function<void()> m_updateTable;
196 std::shared_ptr<nt::NetworkTable> m_table;
198 bool m_actuator =
false;
void SetUpdateTable(std::function< void()> func) override
Set the function that should be called to update the network table for things other than properties...
void AddDoubleArrayProperty(const wpi::Twine &key, std::function< std::vector< double >()> getter, std::function< void(wpi::ArrayRef< double >)> setter) override
Add a double array property.
WPILib FRC namespace.
Definition: SPIAccelerometerSim.h:18
void StartListeners()
Hook setters for all properties.
void AddStringProperty(const wpi::Twine &key, std::function< std::string()> getter, std::function< void(wpi::StringRef)> setter) override
Add a string property.
void SetTable(std::shared_ptr< nt::NetworkTable > table)
Set the network table.
ArrayRef - Represent a constant reference to an array (0 or more elements consecutively in memory)...
Definition: ArrayRef.h:41
void SetSafeState(std::function< void()> func) override
Set the function that should be called to set the Sendable into a safe state.
void AddSmallRawProperty(const wpi::Twine &key, std::function< wpi::StringRef(wpi::SmallVectorImpl< char > &buf)> getter, std::function< void(wpi::StringRef)> setter) override
Add a raw property (SmallVector form).
void UpdateTable()
Update the network table values by calling the getters for all properties.
void AddSmallDoubleArrayProperty(const wpi::Twine &key, std::function< wpi::ArrayRef< double >(wpi::SmallVectorImpl< double > &buf)> getter, std::function< void(wpi::ArrayRef< double >)> setter) override
Add a double array property (SmallVector form).
void AddBooleanArrayProperty(const wpi::Twine &key, std::function< std::vector< int >()> getter, std::function< void(wpi::ArrayRef< int >)> setter) override
Add a boolean array property.
nt::NetworkTableEntry GetEntry(const wpi::Twine &key) override
Add a property without getters or setters.
void AddValueProperty(const wpi::Twine &key, std::function< std::shared_ptr< nt::Value >()> getter, std::function< void(std::shared_ptr< nt::Value >)> setter) override
Add a NetworkTableValue property.
void StopListeners()
Unhook setters for all properties.
Definition: SendableBuilderImpl.h:27
void StartLiveWindowMode()
Start LiveWindow mode by hooking the setters for all properties.
void AddSmallStringProperty(const wpi::Twine &key, std::function< wpi::StringRef(wpi::SmallVectorImpl< char > &buf)> getter, std::function< void(wpi::StringRef)> setter) override
Add a string property (SmallString form).
void AddSmallBooleanArrayProperty(const wpi::Twine &key, std::function< wpi::ArrayRef< int >(wpi::SmallVectorImpl< int > &buf)> getter, std::function< void(wpi::ArrayRef< int >)> setter) override
Add a boolean array property (SmallVector form).
StringRef - Represent a constant reference to a string, i.e.
Definition: StringRef.h:49
void AddDoubleProperty(const wpi::Twine &key, std::function< double()> getter, std::function< void(double)> setter) override
Add a double property.
Definition: SendableBuilder.h:23
NetworkTables Entry.
Definition: NetworkTableEntry.h:38
bool IsActuator() const
Return whether this sendable should be treated as an actuator.
A network table that knows its subtable path.
Definition: NetworkTable.h:51
Twine - A lightweight data structure for efficiently representing the concatenation of temporary valu...
Definition: Twine.h:79
void StopLiveWindowMode()
Stop LiveWindow mode by unhooking the setters for all properties.
void SetActuator(bool value) override
Set a flag indicating if this sendable should be treated as an actuator.
void AddBooleanProperty(const wpi::Twine &key, std::function< bool()> getter, std::function< void(bool)> setter) override
Add a boolean property.
std::shared_ptr< nt::NetworkTable > GetTable()
Get the network table.
void SetSmartDashboardType(const wpi::Twine &type) override
Set the string representation of the named data type that will be used by the smart dashboard for thi...
void AddSmallStringArrayProperty(const wpi::Twine &key, std::function< wpi::ArrayRef< std::string >(wpi::SmallVectorImpl< std::string > &buf)> getter, std::function< void(wpi::ArrayRef< std::string >)> setter) override
Add a string array property (SmallVector form).
void AddStringArrayProperty(const wpi::Twine &key, std::function< std::vector< std::string >()> getter, std::function< void(wpi::ArrayRef< std::string >)> setter) override
Add a string array property.
void AddRawProperty(const wpi::Twine &key, std::function< std::string()> getter, std::function< void(wpi::StringRef)> setter) override
Add a raw property.