2017-12-04 23:28:33 -08:00
|
|
|
/*----------------------------------------------------------------------------*/
|
2020-10-26 00:15:21 -07:00
|
|
|
/* Copyright (c) 2017-2020 FIRST. All Rights Reserved. */
|
2017-12-04 23:28:33 -08:00
|
|
|
/* Open Source Software - may be modified and shared by FRC teams. The code */
|
|
|
|
|
/* must be accompanied by the FIRST BSD license file in the root directory of */
|
|
|
|
|
/* the project. */
|
|
|
|
|
/*----------------------------------------------------------------------------*/
|
|
|
|
|
|
|
|
|
|
#pragma once
|
|
|
|
|
|
|
|
|
|
#include <functional>
|
|
|
|
|
#include <memory>
|
|
|
|
|
#include <string>
|
|
|
|
|
#include <vector>
|
|
|
|
|
|
2020-10-26 00:15:21 -07:00
|
|
|
#include <networktables/NetworkTable.h>
|
2017-12-07 23:34:29 -08:00
|
|
|
#include <networktables/NetworkTableEntry.h>
|
|
|
|
|
#include <networktables/NetworkTableValue.h>
|
2018-04-29 23:33:19 -07:00
|
|
|
#include <wpi/ArrayRef.h>
|
|
|
|
|
#include <wpi/SmallVector.h>
|
|
|
|
|
#include <wpi/Twine.h>
|
2017-12-04 23:28:33 -08:00
|
|
|
|
|
|
|
|
namespace frc {
|
|
|
|
|
|
|
|
|
|
class SendableBuilder {
|
|
|
|
|
public:
|
|
|
|
|
virtual ~SendableBuilder() = default;
|
|
|
|
|
|
2020-10-26 00:15:21 -07:00
|
|
|
/**
|
|
|
|
|
* Get the network table.
|
|
|
|
|
* @return The network table
|
|
|
|
|
*/
|
|
|
|
|
virtual std::shared_ptr<nt::NetworkTable> GetTable() = 0;
|
|
|
|
|
|
2017-12-04 23:28:33 -08:00
|
|
|
/**
|
|
|
|
|
* Set the string representation of the named data type that will be used
|
|
|
|
|
* by the smart dashboard for this sendable.
|
|
|
|
|
*
|
|
|
|
|
* @param type data type
|
|
|
|
|
*/
|
2018-04-29 23:33:19 -07:00
|
|
|
virtual void SetSmartDashboardType(const wpi::Twine& type) = 0;
|
2017-12-04 23:28:33 -08:00
|
|
|
|
2018-07-28 14:04:46 -07:00
|
|
|
/**
|
|
|
|
|
* Set a flag indicating if this sendable should be treated as an actuator.
|
|
|
|
|
* By default this flag is false.
|
|
|
|
|
*
|
|
|
|
|
* @param value true if actuator, false if not
|
|
|
|
|
*/
|
|
|
|
|
virtual void SetActuator(bool value) = 0;
|
|
|
|
|
|
2017-12-04 23:28:33 -08:00
|
|
|
/**
|
|
|
|
|
* 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;
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* Set the function that should be called to update the network table
|
|
|
|
|
* for things other than properties. Note this function is not passed
|
|
|
|
|
* the network table object; instead it should use the entry handles
|
|
|
|
|
* returned by GetEntry().
|
|
|
|
|
*
|
|
|
|
|
* @param func function
|
|
|
|
|
*/
|
|
|
|
|
virtual void SetUpdateTable(std::function<void()> func) = 0;
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* Add a property without getters or setters. This can be used to get
|
|
|
|
|
* entry handles for the function called by SetUpdateTable().
|
|
|
|
|
*
|
|
|
|
|
* @param key property name
|
|
|
|
|
* @return Network table entry
|
|
|
|
|
*/
|
2018-04-29 23:33:19 -07:00
|
|
|
virtual nt::NetworkTableEntry GetEntry(const wpi::Twine& key) = 0;
|
2017-12-04 23:28:33 -08:00
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* Add a boolean property.
|
|
|
|
|
*
|
|
|
|
|
* @param key property name
|
|
|
|
|
* @param getter getter function (returns current value)
|
|
|
|
|
* @param setter setter function (sets new value)
|
|
|
|
|
*/
|
2018-04-29 23:33:19 -07:00
|
|
|
virtual void AddBooleanProperty(const wpi::Twine& key,
|
2017-12-04 23:28:33 -08:00
|
|
|
std::function<bool()> getter,
|
|
|
|
|
std::function<void(bool)> setter) = 0;
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* Add a double property.
|
|
|
|
|
*
|
|
|
|
|
* @param key property name
|
|
|
|
|
* @param getter getter function (returns current value)
|
|
|
|
|
* @param setter setter function (sets new value)
|
|
|
|
|
*/
|
2018-04-29 23:33:19 -07:00
|
|
|
virtual void AddDoubleProperty(const wpi::Twine& key,
|
2017-12-04 23:28:33 -08:00
|
|
|
std::function<double()> getter,
|
|
|
|
|
std::function<void(double)> setter) = 0;
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* Add a string property.
|
|
|
|
|
*
|
|
|
|
|
* @param key property name
|
|
|
|
|
* @param getter getter function (returns current value)
|
|
|
|
|
* @param setter setter function (sets new value)
|
|
|
|
|
*/
|
|
|
|
|
virtual void AddStringProperty(
|
2018-04-29 23:33:19 -07:00
|
|
|
const wpi::Twine& key, std::function<std::string()> getter,
|
|
|
|
|
std::function<void(wpi::StringRef)> setter) = 0;
|
2017-12-04 23:28:33 -08:00
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* Add a boolean array property.
|
|
|
|
|
*
|
|
|
|
|
* @param key property name
|
|
|
|
|
* @param getter getter function (returns current value)
|
|
|
|
|
* @param setter setter function (sets new value)
|
|
|
|
|
*/
|
|
|
|
|
virtual void AddBooleanArrayProperty(
|
2018-04-29 23:33:19 -07:00
|
|
|
const wpi::Twine& key, std::function<std::vector<int>()> getter,
|
|
|
|
|
std::function<void(wpi::ArrayRef<int>)> setter) = 0;
|
2017-12-04 23:28:33 -08:00
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* Add a double array property.
|
|
|
|
|
*
|
|
|
|
|
* @param key property name
|
|
|
|
|
* @param getter getter function (returns current value)
|
|
|
|
|
* @param setter setter function (sets new value)
|
|
|
|
|
*/
|
|
|
|
|
virtual void AddDoubleArrayProperty(
|
2018-04-29 23:33:19 -07:00
|
|
|
const wpi::Twine& key, std::function<std::vector<double>()> getter,
|
|
|
|
|
std::function<void(wpi::ArrayRef<double>)> setter) = 0;
|
2017-12-04 23:28:33 -08:00
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* Add a string array property.
|
|
|
|
|
*
|
|
|
|
|
* @param key property name
|
|
|
|
|
* @param getter getter function (returns current value)
|
|
|
|
|
* @param setter setter function (sets new value)
|
|
|
|
|
*/
|
|
|
|
|
virtual void AddStringArrayProperty(
|
2018-04-29 23:33:19 -07:00
|
|
|
const wpi::Twine& key, std::function<std::vector<std::string>()> getter,
|
|
|
|
|
std::function<void(wpi::ArrayRef<std::string>)> setter) = 0;
|
2017-12-04 23:28:33 -08:00
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* Add a raw property.
|
|
|
|
|
*
|
|
|
|
|
* @param key property name
|
|
|
|
|
* @param getter getter function (returns current value)
|
|
|
|
|
* @param setter setter function (sets new value)
|
|
|
|
|
*/
|
2018-04-29 23:33:19 -07:00
|
|
|
virtual void AddRawProperty(const wpi::Twine& key,
|
2017-12-04 23:28:33 -08:00
|
|
|
std::function<std::string()> getter,
|
2018-04-29 23:33:19 -07:00
|
|
|
std::function<void(wpi::StringRef)> setter) = 0;
|
2017-12-04 23:28:33 -08:00
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* Add a NetworkTableValue property.
|
|
|
|
|
*
|
|
|
|
|
* @param key property name
|
|
|
|
|
* @param getter getter function (returns current value)
|
|
|
|
|
* @param setter setter function (sets new value)
|
|
|
|
|
*/
|
|
|
|
|
virtual void AddValueProperty(
|
2018-05-13 17:09:56 -07:00
|
|
|
const wpi::Twine& key, std::function<std::shared_ptr<nt::Value>()> getter,
|
2017-12-04 23:28:33 -08:00
|
|
|
std::function<void(std::shared_ptr<nt::Value>)> setter) = 0;
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* Add a string property (SmallString form).
|
|
|
|
|
*
|
|
|
|
|
* @param key property name
|
|
|
|
|
* @param getter getter function (returns current value)
|
|
|
|
|
* @param setter setter function (sets new value)
|
|
|
|
|
*/
|
|
|
|
|
virtual void AddSmallStringProperty(
|
2018-04-29 23:33:19 -07:00
|
|
|
const wpi::Twine& key,
|
|
|
|
|
std::function<wpi::StringRef(wpi::SmallVectorImpl<char>& buf)> getter,
|
|
|
|
|
std::function<void(wpi::StringRef)> setter) = 0;
|
2017-12-04 23:28:33 -08:00
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* Add a boolean array property (SmallVector form).
|
|
|
|
|
*
|
|
|
|
|
* @param key property name
|
|
|
|
|
* @param getter getter function (returns current value)
|
|
|
|
|
* @param setter setter function (sets new value)
|
|
|
|
|
*/
|
|
|
|
|
virtual void AddSmallBooleanArrayProperty(
|
2018-04-29 23:33:19 -07:00
|
|
|
const wpi::Twine& key,
|
2018-05-13 17:09:56 -07:00
|
|
|
std::function<wpi::ArrayRef<int>(wpi::SmallVectorImpl<int>& buf)> getter,
|
2018-04-29 23:33:19 -07:00
|
|
|
std::function<void(wpi::ArrayRef<int>)> setter) = 0;
|
2017-12-04 23:28:33 -08:00
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* Add a double array property (SmallVector form).
|
|
|
|
|
*
|
|
|
|
|
* @param key property name
|
|
|
|
|
* @param getter getter function (returns current value)
|
|
|
|
|
* @param setter setter function (sets new value)
|
|
|
|
|
*/
|
|
|
|
|
virtual void AddSmallDoubleArrayProperty(
|
2018-04-29 23:33:19 -07:00
|
|
|
const wpi::Twine& key,
|
|
|
|
|
std::function<wpi::ArrayRef<double>(wpi::SmallVectorImpl<double>& buf)>
|
2017-12-04 23:28:33 -08:00
|
|
|
getter,
|
2018-04-29 23:33:19 -07:00
|
|
|
std::function<void(wpi::ArrayRef<double>)> setter) = 0;
|
2017-12-04 23:28:33 -08:00
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* Add a string array property (SmallVector form).
|
|
|
|
|
*
|
|
|
|
|
* @param key property name
|
|
|
|
|
* @param getter getter function (returns current value)
|
|
|
|
|
* @param setter setter function (sets new value)
|
|
|
|
|
*/
|
|
|
|
|
virtual void AddSmallStringArrayProperty(
|
2018-04-29 23:33:19 -07:00
|
|
|
const wpi::Twine& key,
|
2017-12-04 23:28:33 -08:00
|
|
|
std::function<
|
2018-04-29 23:33:19 -07:00
|
|
|
wpi::ArrayRef<std::string>(wpi::SmallVectorImpl<std::string>& buf)>
|
2017-12-04 23:28:33 -08:00
|
|
|
getter,
|
2018-04-29 23:33:19 -07:00
|
|
|
std::function<void(wpi::ArrayRef<std::string>)> setter) = 0;
|
2017-12-04 23:28:33 -08:00
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* Add a raw property (SmallVector form).
|
|
|
|
|
*
|
|
|
|
|
* @param key property name
|
|
|
|
|
* @param getter getter function (returns current value)
|
|
|
|
|
* @param setter setter function (sets new value)
|
|
|
|
|
*/
|
|
|
|
|
virtual void AddSmallRawProperty(
|
2018-04-29 23:33:19 -07:00
|
|
|
const wpi::Twine& key,
|
|
|
|
|
std::function<wpi::StringRef(wpi::SmallVectorImpl<char>& buf)> getter,
|
|
|
|
|
std::function<void(wpi::StringRef)> setter) = 0;
|
2017-12-04 23:28:33 -08:00
|
|
|
};
|
|
|
|
|
|
|
|
|
|
} // namespace frc
|