Split Sendable into NT and non-NT portions (#3432)

The non-NT portion has been moved to wpiutil.
The NT portion has been moved to ntcore (as NTSendable).

SendableBuilder similarly split and moved.

SendableRegistry moved to wpiutil.

In C++, SendableHelper also moved to wpiutil.

This enables use of Sendable from wpimath and also enables
moving several classes from wpilib to wpimath.
This commit is contained in:
Peter Johnson
2021-06-13 16:38:05 -07:00
committed by GitHub
parent ef4ea84cb5
commit b417d961ec
196 changed files with 1147 additions and 891 deletions

View File

@@ -0,0 +1,28 @@
// Copyright (c) FIRST and other WPILib contributors.
// Open Source Software; you can modify and/or share it under the terms of
// the WPILib BSD license file in the root directory of this project.
#pragma once
#include <wpi/sendable/Sendable.h>
namespace nt {
class NTSendableBuilder;
/**
* Interface for NetworkTable Sendable objects.
*/
class NTSendable : public wpi::Sendable {
public:
/**
* Initializes this Sendable object.
*
* @param builder sendable builder
*/
virtual void InitSendable(NTSendableBuilder& builder) = 0;
void InitSendable(wpi::SendableBuilder& builder) override;
};
} // namespace nt

View File

@@ -0,0 +1,65 @@
// Copyright (c) FIRST and other WPILib contributors.
// Open Source Software; you can modify and/or share it under the terms of
// the WPILib BSD license file in the root directory of this project.
#pragma once
#include <functional>
#include <memory>
#include <string_view>
#include <wpi/sendable/SendableBuilder.h>
#include "networktables/NetworkTable.h"
#include "networktables/NetworkTableEntry.h"
#include "networktables/NetworkTableValue.h"
namespace nt {
class NTSendableBuilder : public wpi::SendableBuilder {
public:
/**
* 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
*/
virtual NetworkTableEntry GetEntry(std::string_view key) = 0;
/**
* 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(
std::string_view key, std::function<std::shared_ptr<Value>()> getter,
std::function<void(std::shared_ptr<Value>)> setter) = 0;
/**
* Get the network table.
* @return The network table
*/
virtual std::shared_ptr<NetworkTable> GetTable() = 0;
/**
* Gets the kind of backend being used.
*
* @return Backend kind
*/
BackendKind GetBackendKind() const override;
};
} // namespace nt