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"
40 void SetTable(std::shared_ptr<nt::NetworkTable> table);
46 std::shared_ptr<nt::NetworkTable>
GetTable();
88 std::function<
void(
bool)> setter)
override;
91 std::function<
void(
double)> setter)
override;
94 std::function<std::string()> getter,
98 const wpi::Twine& key, std::function<std::vector<int>()> getter,
102 const wpi::Twine& key, std::function<std::vector<double>()> getter,
106 const wpi::Twine& key, std::function<std::vector<std::string>()> getter,
110 std::function<std::string()> getter,
114 const wpi::Twine& key, std::function<std::shared_ptr<nt::Value>()> getter,
115 std::function<
void(std::shared_ptr<nt::Value>)> setter)
override;
148 : entry(table.GetEntry(key)) {}
150 Property(
const Property&) =
delete;
151 Property& operator=(
const Property&) =
delete;
153 Property(Property&& other) noexcept
154 : entry(other.entry),
155 listener(other.listener),
156 update(std::move(other.update)),
157 createListener(std::move(other.createListener)) {
162 Property& operator=(Property&& other) noexcept {
164 listener = other.listener;
167 update = std::move(other.update);
168 createListener = std::move(other.createListener);
172 ~Property() { StopListener(); }
174 void StartListener() {
175 if (entry && listener == 0 && createListener)
176 listener = createListener(entry);
179 void StopListener() {
180 if (entry && listener != 0) {
181 entry.RemoveListener(listener);
187 NT_EntryListener listener = 0;
188 std::function<void(nt::NetworkTableEntry entry, uint64_t time)> update;
189 std::function<NT_EntryListener(nt::NetworkTableEntry entry)> createListener;
192 std::vector<Property> m_properties;
193 std::function<void()> m_safeState;
194 std::function<void()> m_updateTable;
195 std::shared_ptr<nt::NetworkTable> m_table;
197 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.