mirror of
https://github.com/wpilibsuite/allwpilib
synced 2026-06-26 01:51:41 +00:00
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:
28
ntcore/src/main/native/include/networktables/NTSendable.h
Normal file
28
ntcore/src/main/native/include/networktables/NTSendable.h
Normal 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
|
||||
@@ -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
|
||||
Reference in New Issue
Block a user