[ntcore] NetworkTables 4 (#3217)

This commit is contained in:
Peter Johnson
2022-10-08 10:01:31 -07:00
committed by GitHub
parent 90cfa00115
commit 77301b126c
380 changed files with 34573 additions and 22095 deletions

View File

@@ -0,0 +1,116 @@
// 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 <vector>
#include <wpi/span.h>
#include "ntcore_cpp.h"
namespace nt {
class NetworkTableInstance;
/**
* Connection listener. This calls back to a callback function when a connection
* change occurs.
*/
class ConnectionListener final {
public:
ConnectionListener() = default;
/**
* Create a listener for connection changes.
*
* @param inst Instance
* @param immediateNotify if notification should be immediately created for
* existing connections
* @param listener Listener function
*/
ConnectionListener(
NetworkTableInstance inst, bool immediateNotify,
std::function<void(const ConnectionNotification&)> listener);
ConnectionListener(const ConnectionListener&) = delete;
ConnectionListener& operator=(const ConnectionListener&) = delete;
ConnectionListener(ConnectionListener&& rhs);
ConnectionListener& operator=(ConnectionListener&& rhs);
~ConnectionListener();
explicit operator bool() const { return m_handle != 0; }
/**
* Gets the native handle.
*
* @return Handle
*/
NT_ConnectionListener GetHandle() const { return m_handle; }
private:
NT_ConnectionListener m_handle{0};
};
/**
* A connection listener. This queues connection notifications. Code using
* the listener must periodically call readQueue() to read the notifications.
*/
class ConnectionListenerPoller final {
public:
ConnectionListenerPoller() = default;
/**
* Construct a connection listener poller.
*
* @param inst Instance
*/
explicit ConnectionListenerPoller(NetworkTableInstance inst);
ConnectionListenerPoller(const ConnectionListenerPoller&) = delete;
ConnectionListenerPoller& operator=(const ConnectionListenerPoller&) = delete;
ConnectionListenerPoller(ConnectionListenerPoller&& rhs);
ConnectionListenerPoller& operator=(ConnectionListenerPoller&& rhs);
~ConnectionListenerPoller();
explicit operator bool() const { return m_handle != 0; }
/**
* Gets the native handle.
*
* @return Handle
*/
NT_ConnectionListenerPoller GetHandle() const { return m_handle; }
/**
* Create a connection listener.
*
* @param immediateNotify if notification should be immediately created for
* existing connections
* @return Listener handle
*/
NT_ConnectionListener Add(bool immediateNotify);
/**
* Remove a connection listener.
*
* @param listener Listener handle
*/
void Remove(NT_ConnectionListener listener);
/**
* Read connection notifications.
*
* @return Connection notifications since the previous call to readQueue()
*/
std::vector<ConnectionNotification> ReadQueue();
private:
NT_ConnectionListenerPoller m_handle{0};
};
} // namespace nt
#include "ConnectionListener.inc"

View File

@@ -0,0 +1,77 @@
// 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 <utility>
#include <vector>
#include <wpi/span.h>
#include "networktables/ConnectionListener.h"
#include "networktables/NetworkTableInstance.h"
#include "ntcore_cpp.h"
namespace nt {
inline ConnectionListener::ConnectionListener(
NetworkTableInstance inst, bool immediateNotify,
std::function<void(const ConnectionNotification&)> listener)
: m_handle{
AddConnectionListener(inst.GetHandle(), listener, immediateNotify)} {}
inline ConnectionListener::ConnectionListener(ConnectionListener&& rhs)
: m_handle(rhs.m_handle) {
rhs.m_handle = 0;
}
inline ConnectionListener& ConnectionListener::operator=(
ConnectionListener&& rhs) {
std::swap(m_handle, rhs.m_handle);
return *this;
}
inline ConnectionListener::~ConnectionListener() {
if (m_handle != 0) {
nt::RemoveConnectionListener(m_handle);
}
}
inline ConnectionListenerPoller::ConnectionListenerPoller(
NetworkTableInstance inst)
: m_handle(nt::CreateConnectionListenerPoller(inst.GetHandle())) {}
inline ConnectionListenerPoller::ConnectionListenerPoller(
ConnectionListenerPoller&& rhs)
: m_handle(rhs.m_handle) {
rhs.m_handle = 0;
}
inline ConnectionListenerPoller& ConnectionListenerPoller::operator=(
ConnectionListenerPoller&& rhs) {
std::swap(m_handle, rhs.m_handle);
return *this;
}
inline ConnectionListenerPoller::~ConnectionListenerPoller() {
if (m_handle != 0) {
nt::DestroyConnectionListenerPoller(m_handle);
}
}
inline NT_ConnectionListener ConnectionListenerPoller::Add(
bool immediateNotify) {
return nt::AddPolledConnectionListener(m_handle, immediateNotify);
}
inline void ConnectionListenerPoller::Remove(NT_ConnectionListener listener) {
nt::RemoveConnectionListener(listener);
}
inline std::vector<ConnectionNotification>
ConnectionListenerPoller::ReadQueue() {
return nt::ReadConnectionListenerQueue(m_handle);
}
} // namespace nt

View File

@@ -1,75 +0,0 @@
// 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.
#ifndef NTCORE_NETWORKTABLES_ENTRYLISTENERFLAGS_H_
#define NTCORE_NETWORKTABLES_ENTRYLISTENERFLAGS_H_
#include "ntcore_c.h"
/** Entry listener flags */
namespace nt::EntryListenerFlags {
/**
* Flag values for use with entry listeners.
*
* The flags are a bitmask and must be OR'ed together to indicate the
* combination of events desired to be received.
*
* The constants kNew, kDelete, kUpdate, and kFlags represent different events
* that can occur to entries.
*
* By default, notifications are only generated for remote changes occurring
* after the listener is created. The constants kImmediate and kLocal are
* modifiers that cause notifications to be generated at other times.
*
* @ingroup ntcore_cpp_api
*/
enum {
/**
* Initial listener addition.
* Set this flag to receive immediate notification of entries matching the
* flag criteria (generally only useful when combined with kNew).
*/
kImmediate = NT_NOTIFY_IMMEDIATE,
/**
* Changed locally.
* Set this flag to receive notification of both local changes and changes
* coming from remote nodes. By default, notifications are only generated
* for remote changes. Must be combined with some combination of kNew,
* kDelete, kUpdate, and kFlags to receive notifications of those respective
* events.
*/
kLocal = NT_NOTIFY_LOCAL,
/**
* Newly created entry.
* Set this flag to receive a notification when an entry is created.
*/
kNew = NT_NOTIFY_NEW,
/**
* Entry was deleted.
* Set this flag to receive a notification when an entry is deleted.
*/
kDelete = NT_NOTIFY_DELETE,
/**
* Entry's value changed.
* Set this flag to receive a notification when an entry's value (or type)
* changes.
*/
kUpdate = NT_NOTIFY_UPDATE,
/**
* Entry's flags changed.
* Set this flag to receive a notification when an entry's flags value
* changes.
*/
kFlags = NT_NOTIFY_FLAGS
};
} // namespace nt::EntryListenerFlags
#endif // NTCORE_NETWORKTABLES_ENTRYLISTENERFLAGS_H_

View File

@@ -0,0 +1,482 @@
// 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 <stdint.h>
#include <string>
#include <string_view>
#include <utility>
#include <vector>
#include "networktables/Topic.h"
namespace nt {
class Value;
/**
* NetworkTables generic subscriber.
*/
class GenericSubscriber : public Subscriber {
public:
using TopicType = Topic;
using ValueType = Value;
using ParamType = const Value&;
using TimestampedValueType = Value;
GenericSubscriber() = default;
/**
* Construct from a subscriber handle; recommended to use
* Topic::GenericSubscribe() instead.
*
* @param handle Native handle
*/
explicit GenericSubscriber(NT_Subscriber handle);
/**
* Get the last published value.
* If no value has been published, returns a value with unassigned type.
*
* @return value
*/
ValueType Get() const;
/**
* Gets the entry's value as a boolean. If the entry does not exist or is of
* different type, it will return the default value.
*
* @param defaultValue the value to be returned if no value is found
* @return the entry's value or the given default value
*/
bool GetBoolean(bool defaultValue) const;
/**
* Gets the entry's value as a integer. If the entry does not exist or is of
* different type, it will return the default value.
*
* @param defaultValue the value to be returned if no value is found
* @return the entry's value or the given default value
*/
int64_t GetInteger(int64_t defaultValue) const;
/**
* Gets the entry's value as a float. If the entry does not exist or is of
* different type, it will return the default value.
*
* @param defaultValue the value to be returned if no value is found
* @return the entry's value or the given default value
*/
float GetFloat(float defaultValue) const;
/**
* Gets the entry's value as a double. If the entry does not exist or is of
* different type, it will return the default value.
*
* @param defaultValue the value to be returned if no value is found
* @return the entry's value or the given default value
*/
double GetDouble(double defaultValue) const;
/**
* Gets the entry's value as a string. If the entry does not exist or is of
* different type, it will return the default value.
*
* @param defaultValue the value to be returned if no value is found
* @return the entry's value or the given default value
*/
std::string GetString(std::string_view defaultValue) const;
/**
* Gets the entry's value as a raw. If the entry does not exist or is of
* different type, it will return the default value.
*
* @param defaultValue the value to be returned if no value is found
* @return the entry's value or the given default value
*/
std::vector<uint8_t> GetRaw(wpi::span<const uint8_t> defaultValue) const;
/**
* Gets the entry's value as a boolean array. If the entry does not exist
* or is of different type, it will return the default value.
*
* @param defaultValue the value to be returned if no value is found
* @return the entry's value or the given default value
*
* @note This makes a copy of the array. If the overhead of this is a
* concern, use GetValue() instead.
*
* @note The returned array is std::vector<int> instead of std::vector<bool>
* because std::vector<bool> is special-cased in C++. 0 is false, any
* non-zero value is true.
*/
std::vector<int> GetBooleanArray(wpi::span<const int> defaultValue) const;
/**
* Gets the entry's value as a integer array. If the entry does not exist
* or is of different type, it will return the default value.
*
* @param defaultValue the value to be returned if no value is found
* @return the entry's value or the given default value
*
* @note This makes a copy of the array. If the overhead of this is a
* concern, use GetValue() instead.
*/
std::vector<int64_t> GetIntegerArray(
wpi::span<const int64_t> defaultValue) const;
/**
* Gets the entry's value as a float array. If the entry does not exist
* or is of different type, it will return the default value.
*
* @param defaultValue the value to be returned if no value is found
* @return the entry's value or the given default value
*
* @note This makes a copy of the array. If the overhead of this is a
* concern, use GetValue() instead.
*/
std::vector<float> GetFloatArray(wpi::span<const float> defaultValue) const;
/**
* Gets the entry's value as a double array. If the entry does not exist
* or is of different type, it will return the default value.
*
* @param defaultValue the value to be returned if no value is found
* @return the entry's value or the given default value
*
* @note This makes a copy of the array. If the overhead of this is a
* concern, use GetValue() instead.
*/
std::vector<double> GetDoubleArray(
wpi::span<const double> defaultValue) const;
/**
* Gets the entry's value as a string array. If the entry does not exist
* or is of different type, it will return the default value.
*
* @param defaultValue the value to be returned if no value is found
* @return the entry's value or the given default value
*
* @note This makes a copy of the array. If the overhead of this is a
* concern, use GetValue() instead.
*/
std::vector<std::string> GetStringArray(
wpi::span<const std::string> defaultValue) const;
/**
* Get an array of all value changes since the last call to ReadQueue.
* Also provides a timestamp for each value.
*
* @note The "poll storage" subscribe option can be used to set the queue
* depth.
*
* @return Array of timestamped values; empty array if no new changes have
* been published since the previous call.
*/
std::vector<TimestampedValueType> ReadQueue();
/**
* Get the corresponding topic.
*
* @return Topic
*/
TopicType GetTopic() const;
};
/**
* NetworkTables generic publisher.
*/
class GenericPublisher : public Publisher {
public:
using TopicType = Topic;
using ValueType = Value;
using ParamType = const Value&;
using TimestampedValueType = Value;
GenericPublisher() = default;
/**
* Construct from a publisher handle; recommended to use
* Topic::GenericPublish() instead.
*
* @param handle Native handle
*/
explicit GenericPublisher(NT_Publisher handle);
/**
* Publish a new value.
*
* @param value value to publish
*/
void Set(ParamType value);
/**
* Sets the entry's value.
*
* @param value the value to set
* @param time the timestamp to set (0 = nt::Now())
* @return False if the entry exists with a different type
*/
bool SetBoolean(bool value, int64_t time = 0);
/**
* Sets the entry's value.
*
* @param value the value to set
* @param time the timestamp to set (0 = nt::Now())
* @return False if the entry exists with a different type
*/
bool SetInteger(int64_t value, int64_t time = 0);
/**
* Sets the entry's value.
*
* @param value the value to set
* @param time the timestamp to set (0 = nt::Now())
* @return False if the entry exists with a different type
*/
bool SetFloat(float value, int64_t time = 0);
/**
* Sets the entry's value.
*
* @param value the value to set
* @param time the timestamp to set (0 = nt::Now())
* @return False if the entry exists with a different type
*/
bool SetDouble(double value, int64_t time = 0);
/**
* Sets the entry's value.
*
* @param value the value to set
* @param time the timestamp to set (0 = nt::Now())
* @return False if the entry exists with a different type
*/
bool SetString(std::string_view value, int64_t time = 0);
/**
* Sets the entry's value.
*
* @param value the value to set
* @param time the timestamp to set (0 = nt::Now())
* @return False if the entry exists with a different type
*/
bool SetRaw(wpi::span<const uint8_t> value, int64_t time = 0);
/**
* Sets the entry's value.
*
* @param value the value to set
* @param time the timestamp to set (0 = nt::Now())
* @return False if the entry exists with a different type
*/
bool SetBooleanArray(wpi::span<const bool> value, int64_t time = 0);
/**
* Sets the entry's value.
*
* @param value the value to set
* @param time the timestamp to set (0 = nt::Now())
* @return False if the entry exists with a different type
*/
bool SetBooleanArray(wpi::span<const int> value, int64_t time = 0);
/**
* Sets the entry's value.
*
* @param value the value to set
* @param time the timestamp to set (0 = nt::Now())
* @return False if the entry exists with a different type
*/
bool SetIntegerArray(wpi::span<const int64_t> value, int64_t time = 0);
/**
* Sets the entry's value.
*
* @param value the value to set
* @param time the timestamp to set (0 = nt::Now())
* @return False if the entry exists with a different type
*/
bool SetFloatArray(wpi::span<const float> value, int64_t time = 0);
/**
* Sets the entry's value.
*
* @param value the value to set
* @param time the timestamp to set (0 = nt::Now())
* @return False if the entry exists with a different type
*/
bool SetDoubleArray(wpi::span<const double> value, int64_t time = 0);
/**
* Sets the entry's value.
*
* @param value the value to set
* @param time the timestamp to set (0 = nt::Now())
* @return False if the entry exists with a different type
*/
bool SetStringArray(wpi::span<const std::string> value, int64_t time = 0);
/**
* Publish a default value.
* On reconnect, a default value will never be used in preference to a
* published value.
*
* @param value value
*/
void SetDefault(ParamType value);
/**
* Sets the entry's value if it does not exist.
*
* @param defaultValue the default value to set
* @return False if the entry exists with a different type
*/
bool SetDefaultBoolean(bool defaultValue);
/**
* Sets the entry's value if it does not exist.
*
* @param defaultValue the default value to set
* @return False if the entry exists with a different type
*/
bool SetDefaultInteger(int64_t defaultValue);
/**
* Sets the entry's value if it does not exist.
*
* @param defaultValue the default value to set
* @return False if the entry exists with a different type
*/
bool SetDefaultFloat(float defaultValue);
/**
* Sets the entry's value if it does not exist.
*
* @param defaultValue the default value to set
* @return False if the entry exists with a different type
*/
bool SetDefaultDouble(double defaultValue);
/**
* Sets the entry's value if it does not exist.
*
* @param defaultValue the default value to set
* @return False if the entry exists with a different type
*/
bool SetDefaultString(std::string_view defaultValue);
/**
* Sets the entry's value if it does not exist.
*
* @param defaultValue the default value to set
* @return False if the entry exists with a different type
*/
bool SetDefaultRaw(wpi::span<const uint8_t> defaultValue);
/**
* Sets the entry's value if it does not exist.
*
* @param defaultValue the default value to set
* @return False if the entry exists with a different type
*/
bool SetDefaultBooleanArray(wpi::span<const int> defaultValue);
/**
* Sets the entry's value if it does not exist.
*
* @param defaultValue the default value to set
* @return False if the entry exists with a different type
*/
bool SetDefaultIntegerArray(wpi::span<const int64_t> defaultValue);
/**
* Sets the entry's value if it does not exist.
*
* @param defaultValue the default value to set
* @return False if the entry exists with a different type
*/
bool SetDefaultFloatArray(wpi::span<const float> defaultValue);
/**
* Sets the entry's value if it does not exist.
*
* @param defaultValue the default value to set
* @return False if the entry exists with a different type
*/
bool SetDefaultDoubleArray(wpi::span<const double> defaultValue);
/**
* Sets the entry's value if it does not exist.
*
* @param defaultValue the default value to set
* @return False if the entry exists with a different type
*/
bool SetDefaultStringArray(wpi::span<const std::string> defaultValue);
/**
* Get the corresponding topic.
*
* @return Topic
*/
TopicType GetTopic() const;
};
/**
* NetworkTables generic entry.
*
* @note Unlike NetworkTableEntry, the entry goes away when this is destroyed.
*/
class GenericEntry final : public GenericSubscriber, public GenericPublisher {
public:
using SubscriberType = GenericSubscriber;
using PublisherType = GenericPublisher;
using TopicType = Topic;
using ValueType = Value;
using ParamType = const Value&;
using TimestampedValueType = Value;
GenericEntry() = default;
/**
* Construct from an entry handle; recommended to use
* RawTopic::GetEntry() instead.
*
* @param handle Native handle
*/
explicit GenericEntry(NT_Entry handle);
/**
* Determines if the native handle is valid.
*
* @return True if the native handle is valid, false otherwise.
*/
explicit operator bool() const { return m_subHandle != 0; }
/**
* Gets the native handle for the entry.
*
* @return Native handle
*/
NT_Entry GetHandle() const { return m_subHandle; }
/**
* Get the corresponding topic.
*
* @return Topic
*/
TopicType GetTopic() const;
/**
* Stops publishing the entry if it's published.
*/
void Unpublish();
};
} // namespace nt
#include "networktables/GenericEntry.inc"

View File

@@ -0,0 +1,213 @@
// 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 <string>
#include <string_view>
#include <vector>
#include "networktables/GenericEntry.h"
#include "networktables/NetworkTableType.h"
#include "ntcore_cpp.h"
namespace nt {
inline GenericSubscriber::GenericSubscriber(NT_Subscriber handle)
: Subscriber{handle} {}
inline Value GenericSubscriber::Get() const {
return ::nt::GetEntryValue(m_subHandle);
}
inline bool GenericSubscriber::GetBoolean(bool defaultValue) const {
return ::nt::GetBoolean(m_subHandle, defaultValue);
}
inline int64_t GenericSubscriber::GetInteger(int64_t defaultValue) const {
return ::nt::GetInteger(m_subHandle, defaultValue);
}
inline float GenericSubscriber::GetFloat(float defaultValue) const {
return ::nt::GetFloat(m_subHandle, defaultValue);
}
inline double GenericSubscriber::GetDouble(double defaultValue) const {
return ::nt::GetDouble(m_subHandle, defaultValue);
}
inline std::string GenericSubscriber::GetString(
std::string_view defaultValue) const {
return ::nt::GetString(m_subHandle, defaultValue);
}
inline std::vector<uint8_t> GenericSubscriber::GetRaw(
wpi::span<const uint8_t> defaultValue) const {
return ::nt::GetRaw(m_subHandle, defaultValue);
}
inline std::vector<int> GenericSubscriber::GetBooleanArray(
wpi::span<const int> defaultValue) const {
return ::nt::GetBooleanArray(m_subHandle, defaultValue);
}
inline std::vector<int64_t> GenericSubscriber::GetIntegerArray(
wpi::span<const int64_t> defaultValue) const {
return ::nt::GetIntegerArray(m_subHandle, defaultValue);
}
inline std::vector<float> GenericSubscriber::GetFloatArray(
wpi::span<const float> defaultValue) const {
return ::nt::GetFloatArray(m_subHandle, defaultValue);
}
inline std::vector<double> GenericSubscriber::GetDoubleArray(
wpi::span<const double> defaultValue) const {
return ::nt::GetDoubleArray(m_subHandle, defaultValue);
}
inline std::vector<std::string> GenericSubscriber::GetStringArray(
wpi::span<const std::string> defaultValue) const {
return ::nt::GetStringArray(m_subHandle, defaultValue);
}
inline std::vector<Value> GenericSubscriber::ReadQueue() {
return ::nt::ReadQueueValue(m_subHandle);
}
inline Topic GenericSubscriber::GetTopic() const {
return Topic{::nt::GetTopicFromHandle(m_subHandle)};
}
inline GenericPublisher::GenericPublisher(NT_Publisher handle)
: Publisher{handle} {}
inline void GenericPublisher::Set(const Value& value) {
::nt::SetEntryValue(m_pubHandle, value);
}
inline bool GenericPublisher::SetBoolean(bool value, int64_t time) {
return nt::SetBoolean(m_pubHandle, value, time);
}
inline bool GenericPublisher::SetInteger(int64_t value, int64_t time) {
return nt::SetInteger(m_pubHandle, value, time);
}
inline bool GenericPublisher::SetFloat(float value, int64_t time) {
return nt::SetFloat(m_pubHandle, value, time);
}
inline bool GenericPublisher::SetDouble(double value, int64_t time) {
return nt::SetDouble(m_pubHandle, value, time);
}
inline bool GenericPublisher::SetString(std::string_view value, int64_t time) {
return nt::SetString(m_pubHandle, value, time);
}
inline bool GenericPublisher::SetRaw(wpi::span<const uint8_t> value,
int64_t time) {
return nt::SetRaw(m_pubHandle, value, time);
}
inline bool GenericPublisher::SetBooleanArray(wpi::span<const bool> value,
int64_t time) {
return SetEntryValue(m_pubHandle, Value::MakeBooleanArray(value, time));
}
inline bool GenericPublisher::SetBooleanArray(wpi::span<const int> value,
int64_t time) {
return nt::SetBooleanArray(m_pubHandle, value, time);
}
inline bool GenericPublisher::SetIntegerArray(wpi::span<const int64_t> value,
int64_t time) {
return nt::SetIntegerArray(m_pubHandle, value, time);
}
inline bool GenericPublisher::SetFloatArray(wpi::span<const float> value,
int64_t time) {
return nt::SetFloatArray(m_pubHandle, value, time);
}
inline bool GenericPublisher::SetDoubleArray(wpi::span<const double> value,
int64_t time) {
return nt::SetDoubleArray(m_pubHandle, value, time);
}
inline bool GenericPublisher::SetStringArray(wpi::span<const std::string> value,
int64_t time) {
return nt::SetStringArray(m_pubHandle, value, time);
}
inline void GenericPublisher::SetDefault(const Value& value) {
::nt::SetDefaultEntryValue(m_pubHandle, value);
}
inline bool GenericPublisher::SetDefaultBoolean(bool defaultValue) {
return nt::SetDefaultBoolean(m_pubHandle, defaultValue);
}
inline bool GenericPublisher::SetDefaultInteger(int64_t defaultValue) {
return nt::SetDefaultInteger(m_pubHandle, defaultValue);
}
inline bool GenericPublisher::SetDefaultFloat(float defaultValue) {
return nt::SetDefaultFloat(m_pubHandle, defaultValue);
}
inline bool GenericPublisher::SetDefaultDouble(double defaultValue) {
return nt::SetDefaultDouble(m_pubHandle, defaultValue);
}
inline bool GenericPublisher::SetDefaultString(std::string_view defaultValue) {
return nt::SetDefaultString(m_pubHandle, defaultValue);
}
inline bool GenericPublisher::SetDefaultRaw(
wpi::span<const uint8_t> defaultValue) {
return nt::SetDefaultRaw(m_pubHandle, defaultValue);
}
inline bool GenericPublisher::SetDefaultBooleanArray(
wpi::span<const int> defaultValue) {
return nt::SetDefaultBooleanArray(m_pubHandle, defaultValue);
}
inline bool GenericPublisher::SetDefaultIntegerArray(
wpi::span<const int64_t> defaultValue) {
return nt::SetDefaultIntegerArray(m_pubHandle, defaultValue);
}
inline bool GenericPublisher::SetDefaultFloatArray(
wpi::span<const float> defaultValue) {
return nt::SetDefaultFloatArray(m_pubHandle, defaultValue);
}
inline bool GenericPublisher::SetDefaultDoubleArray(
wpi::span<const double> defaultValue) {
return nt::SetDefaultDoubleArray(m_pubHandle, defaultValue);
}
inline bool GenericPublisher::SetDefaultStringArray(
wpi::span<const std::string> defaultValue) {
return nt::SetDefaultStringArray(m_pubHandle, defaultValue);
}
inline Topic GenericPublisher::GetTopic() const {
return Topic{::nt::GetTopicFromHandle(m_pubHandle)};
}
inline GenericEntry::GenericEntry(NT_Entry handle)
: GenericSubscriber{handle}, GenericPublisher{handle} {}
inline Topic GenericEntry::GetTopic() const {
return Topic{::nt::GetTopicFromHandle(m_subHandle)};
}
inline void GenericEntry::Unpublish() {
::nt::Unpublish(m_pubHandle);
}
} // namespace nt

View File

@@ -0,0 +1,62 @@
// 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 <string_view>
#include <wpi/span.h>
#include "networktables/NetworkTableInstance.h"
#include "ntcore_cpp.h"
namespace nt {
/**
* Subscribe to multiple topics based on one or more topic name prefixes. Can be
* used in combination with ValueListenerPoller to listen for value changes
* across all matching topics.
*/
class MultiSubscriber final {
public:
MultiSubscriber() = default;
/**
* Create a multiple subscriber.
*
* @param inst instance
* @param prefixes topic name prefixes
* @param options subscriber options
*/
MultiSubscriber(NetworkTableInstance inst,
wpi::span<const std::string_view> prefixes,
wpi::span<const PubSubOption> options = {});
MultiSubscriber(const MultiSubscriber&) = delete;
MultiSubscriber& operator=(const MultiSubscriber&) = delete;
MultiSubscriber(MultiSubscriber&& rhs);
MultiSubscriber& operator=(MultiSubscriber&& rhs);
~MultiSubscriber();
/**
* Determines if the native handle is valid.
*
* @return True if the native handle is valid, false otherwise.
*/
explicit operator bool() const { return m_handle != 0; }
/**
* Gets the native handle.
*
* @return Handle
*/
NT_MultiSubscriber GetHandle() const { return m_handle; }
private:
NT_MultiSubscriber m_handle{0};
};
} // namespace nt
#include "MultiSubscriber.inc"

View File

@@ -0,0 +1,36 @@
// 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 "networktables/MultiSubscriber.h"
namespace nt {
inline MultiSubscriber::MultiSubscriber(
NetworkTableInstance inst, wpi::span<const std::string_view> prefixes,
wpi::span<const PubSubOption> options)
: m_handle{::nt::SubscribeMultiple(inst.GetHandle(), prefixes, options)} {}
inline MultiSubscriber::MultiSubscriber(MultiSubscriber&& rhs)
: m_handle{rhs.m_handle} {
rhs.m_handle = 0;
}
inline MultiSubscriber& MultiSubscriber::operator=(MultiSubscriber&& rhs) {
if (m_handle != 0) {
::nt::UnsubscribeMultiple(m_handle);
}
m_handle = rhs.m_handle;
rhs.m_handle = 0;
return *this;
}
inline MultiSubscriber::~MultiSubscriber() {
if (m_handle != 0) {
::nt::UnsubscribeMultiple(m_handle);
}
}
} // namespace nt

View File

@@ -4,15 +4,14 @@
#pragma once
#include <functional>
#include <memory>
#include <string_view>
#include <wpi/FunctionExtras.h>
#include <wpi/sendable/SendableBuilder.h>
#include "networktables/NetworkTable.h"
#include "networktables/NetworkTableEntry.h"
#include "networktables/NetworkTableValue.h"
#include "networktables/Topic.h"
namespace nt {
@@ -26,27 +25,16 @@ class NTSendableBuilder : public wpi::SendableBuilder {
*
* @param func function
*/
virtual void SetUpdateTable(std::function<void()> func) = 0;
virtual void SetUpdateTable(wpi::unique_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
* @return Network table topic
*/
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;
virtual Topic GetTopic(std::string_view key) = 0;
/**
* Get the network table.

View File

@@ -2,8 +2,7 @@
// 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.
#ifndef NTCORE_NETWORKTABLES_NETWORKTABLE_H_
#define NTCORE_NETWORKTABLES_NETWORKTABLE_H_
#pragma once
#include <functional>
#include <memory>
@@ -17,13 +16,23 @@
#include <wpi/span.h>
#include "networktables/NetworkTableEntry.h"
#include "networktables/TableEntryListener.h"
#include "networktables/TableListener.h"
#include "ntcore_c.h"
namespace nt {
class BooleanArrayTopic;
class BooleanTopic;
class DoubleArrayTopic;
class DoubleTopic;
class FloatArrayTopic;
class FloatTopic;
class IntegerArrayTopic;
class IntegerTopic;
class NetworkTableInstance;
class RawTopic;
class StringArrayTopic;
class StringTopic;
class Topic;
/**
* @defgroup ntcore_cpp_api ntcore C++ object-oriented API
@@ -41,7 +50,6 @@ class NetworkTable final {
std::string m_path;
mutable wpi::mutex m_mutex;
mutable wpi::StringMap<NT_Entry> m_entries;
std::vector<NT_EntryListener> m_listeners;
struct private_init {};
friend class NetworkTableInstance;
@@ -94,7 +102,7 @@ class NetworkTable final {
* instead.
*/
NetworkTable(NT_Inst inst, std::string_view path, const private_init&);
virtual ~NetworkTable();
~NetworkTable();
/**
* Gets the instance for the table.
@@ -117,52 +125,100 @@ class NetworkTable final {
NetworkTableEntry GetEntry(std::string_view key) const;
/**
* Listen to keys only within this table.
* Get (generic) topic.
*
* @param listener listener to add
* @param flags EntryListenerFlags bitmask
* @return Listener handle
* @param name topic name
* @return Topic
*/
NT_EntryListener AddEntryListener(TableEntryListener listener,
unsigned int flags) const;
Topic GetTopic(std::string_view name) const;
/**
* Listen to a single key.
* Get boolean topic.
*
* @param key the key name
* @param listener listener to add
* @param flags EntryListenerFlags bitmask
* @return Listener handle
* @param name topic name
* @return BooleanTopic
*/
NT_EntryListener AddEntryListener(std::string_view key,
TableEntryListener listener,
unsigned int flags) const;
BooleanTopic GetBooleanTopic(std::string_view name) const;
/**
* Remove an entry listener.
* Get integer topic.
*
* @param listener listener handle
* @param name topic name
* @return IntegerTopic
*/
void RemoveEntryListener(NT_EntryListener listener) const;
IntegerTopic GetIntegerTopic(std::string_view name) const;
/**
* Listen for sub-table creation.
* This calls the listener once for each newly created sub-table.
* It immediately calls the listener for any existing sub-tables.
* Get float topic.
*
* @param listener listener to add
* @param localNotify notify local changes as well as remote
* @return Listener handle
* @param name topic name
* @return FloatTopic
*/
NT_EntryListener AddSubTableListener(TableListener listener,
bool localNotify = false);
FloatTopic GetFloatTopic(std::string_view name) const;
/**
* Remove a sub-table listener.
* Get double topic.
*
* @param listener listener handle
* @param name topic name
* @return DoubleTopic
*/
void RemoveTableListener(NT_EntryListener listener);
DoubleTopic GetDoubleTopic(std::string_view name) const;
/**
* Get String topic.
*
* @param name topic name
* @return StringTopic
*/
StringTopic GetStringTopic(std::string_view name) const;
/**
* Get raw topic.
*
* @param name topic name
* @return BooleanArrayTopic
*/
RawTopic GetRawTopic(std::string_view name) const;
/**
* Get boolean[] topic.
*
* @param name topic name
* @return BooleanArrayTopic
*/
BooleanArrayTopic GetBooleanArrayTopic(std::string_view name) const;
/**
* Get integer[] topic.
*
* @param name topic name
* @return IntegerArrayTopic
*/
IntegerArrayTopic GetIntegerArrayTopic(std::string_view name) const;
/**
* Get float[] topic.
*
* @param name topic name
* @return FloatArrayTopic
*/
FloatArrayTopic GetFloatArrayTopic(std::string_view name) const;
/**
* Get double[] topic.
*
* @param name topic name
* @return DoubleArrayTopic
*/
DoubleArrayTopic GetDoubleArrayTopic(std::string_view name) const;
/**
* Get String[] topic.
*
* @param name topic name
* @return StringArrayTopic
*/
StringArrayTopic GetStringArrayTopic(std::string_view name) const;
/**
* Returns the table at the specified key. If there is no table at the
@@ -191,6 +247,23 @@ class NetworkTable final {
*/
bool ContainsSubTable(std::string_view key) const;
/**
* Gets topic information for all keys in the table (not including
* sub-tables).
*
* @param types bitmask of types; 0 is treated as a "don't care".
* @return topic information for keys currently in the table
*/
std::vector<TopicInfo> GetTopicInfo(int types = 0) const;
/**
* Gets all topics in the table (not including sub-tables).
*
* @param types bitmask of types; 0 is treated as a "don't care".
* @return topic for keys currently in the table
*/
std::vector<Topic> GetTopics(int types = 0) const;
/**
* Gets all keys in the table (not including sub-tables).
*
@@ -229,39 +302,6 @@ class NetworkTable final {
*/
bool IsPersistent(std::string_view key) const;
/**
* Sets flags on the specified key in this table. The key can
* not be null.
*
* @param key the key name
* @param flags the flags to set (bitmask)
*/
void SetFlags(std::string_view key, unsigned int flags);
/**
* Clears flags on the specified key in this table. The key can
* not be null.
*
* @param key the key name
* @param flags the flags to clear (bitmask)
*/
void ClearFlags(std::string_view key, unsigned int flags);
/**
* Returns the flags for the specified key.
*
* @param key the key name
* @return the flags, or 0 if the key is not defined
*/
unsigned int GetFlags(std::string_view key) const;
/**
* Deletes the specified key in this table.
*
* @param key the key name
*/
void Delete(std::string_view key);
/**
* Put a number in the table
*
@@ -466,7 +506,7 @@ class NetworkTable final {
* @param value the value that will be assigned
* @return False if the table key already exists with a different type
*/
bool PutRaw(std::string_view key, std::string_view value);
bool PutRaw(std::string_view key, wpi::span<const uint8_t> value);
/**
* Gets the current value in the table, setting it if it does not exist.
@@ -475,7 +515,8 @@ class NetworkTable final {
* @param defaultValue the default value to set if key doesn't exist.
* @return False if the table key exists with a different type
*/
bool SetDefaultRaw(std::string_view key, std::string_view defaultValue);
bool SetDefaultRaw(std::string_view key,
wpi::span<const uint8_t> defaultValue);
/**
* Returns the raw value (byte array) the key maps to. If the key does not
@@ -489,7 +530,8 @@ class NetworkTable final {
* @note This makes a copy of the raw contents. If the overhead of this is a
* concern, use GetValue() instead.
*/
std::string GetRaw(std::string_view key, std::string_view defaultValue) const;
std::vector<uint8_t> GetRaw(std::string_view key,
wpi::span<const uint8_t> defaultValue) const;
/**
* Put a value in the table
@@ -498,7 +540,7 @@ class NetworkTable final {
* @param value the value that will be assigned
* @return False if the table key already exists with a different type
*/
bool PutValue(std::string_view key, std::shared_ptr<Value> value);
bool PutValue(std::string_view key, const Value& value);
/**
* Gets the current value in the table, setting it if it does not exist.
@@ -507,8 +549,7 @@ class NetworkTable final {
* @param defaultValue the default value to set if key doesn't exist.
* @return False if the table key exists with a different type
*/
bool SetDefaultValue(std::string_view key,
std::shared_ptr<Value> defaultValue);
bool SetDefaultValue(std::string_view key, const Value& defaultValue);
/**
* Gets the value associated with a key as an object
@@ -517,7 +558,7 @@ class NetworkTable final {
* @return the value associated with the given key, or nullptr if the key
* does not exist
*/
std::shared_ptr<Value> GetValue(std::string_view key) const;
Value GetValue(std::string_view key) const;
/**
* Gets the full path of this table. Does not include the trailing "/".
@@ -525,29 +566,6 @@ class NetworkTable final {
* @return The path (e.g "", "/foo").
*/
std::string_view GetPath() const;
/**
* Save table values to a file. The file format used is identical to
* that used for SavePersistent.
*
* @param filename filename
* @return error string, or nullptr if successful
*/
const char* SaveEntries(std::string_view filename) const;
/**
* Load table values from a file. The file format used is identical to
* that used for SavePersistent / LoadPersistent.
*
* @param filename filename
* @param warn callback function for warnings
* @return error string, or nullptr if successful
*/
const char* LoadEntries(
std::string_view filename,
std::function<void(size_t line, const char* msg)> warn);
};
} // namespace nt
#endif // NTCORE_NETWORKTABLES_NETWORKTABLE_H_

View File

@@ -2,8 +2,7 @@
// 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.
#ifndef NTCORE_NETWORKTABLES_NETWORKTABLEENTRY_H_
#define NTCORE_NETWORKTABLES_NETWORKTABLEENTRY_H_
#pragma once
#include <stdint.h>
@@ -13,26 +12,32 @@
#include <string_view>
#include <vector>
#include <wpi/deprecated.h>
#include <wpi/span.h>
#include "networktables/NetworkTableType.h"
#include "networktables/NetworkTableValue.h"
#include "networktables/RpcCall.h"
#include "ntcore_c.h"
#include "ntcore_cpp.h"
namespace nt {
class NetworkTableInstance;
class Topic;
/**
* NetworkTables Entry
*
* @note For backwards compatibility, the NetworkTableEntry destructor does not
* release the entry.
*
* @ingroup ntcore_cpp_api
*/
class NetworkTableEntry final {
public:
/**
* Flag values (as returned by GetFlags()).
* @deprecated Use IsPersistent() instead.
*/
enum Flags { kPersistent = NT_PERSISTENT };
@@ -94,7 +99,9 @@ class NetworkTableEntry final {
* Returns the flags.
*
* @return the flags (bitmask)
* @deprecated Use IsPersistent() or topic properties instead
*/
WPI_DEPRECATED("Use IsPersistent() or topic properties instead")
unsigned int GetFlags() const;
/**
@@ -102,21 +109,14 @@ class NetworkTableEntry final {
*
* @return Entry last change time
*/
uint64_t GetLastChange() const;
/**
* Gets combined information about the entry.
*
* @return Entry information
*/
EntryInfo GetInfo() const;
int64_t GetLastChange() const;
/**
* Gets the entry's value. If the entry does not exist, returns nullptr.
*
* @return the entry's value or nullptr if it does not exist.
*/
std::shared_ptr<Value> GetValue() const;
Value GetValue() const;
/**
* Gets the entry's value as a boolean. If the entry does not exist or is of
@@ -127,6 +127,24 @@ class NetworkTableEntry final {
*/
bool GetBoolean(bool defaultValue) const;
/**
* Gets the entry's value as a integer. If the entry does not exist or is of
* different type, it will return the default value.
*
* @param defaultValue the value to be returned if no value is found
* @return the entry's value or the given default value
*/
int64_t GetInteger(int64_t defaultValue) const;
/**
* Gets the entry's value as a float. If the entry does not exist or is of
* different type, it will return the default value.
*
* @param defaultValue the value to be returned if no value is found
* @return the entry's value or the given default value
*/
float GetFloat(float defaultValue) const;
/**
* Gets the entry's value as a double. If the entry does not exist or is of
* different type, it will return the default value.
@@ -152,7 +170,7 @@ class NetworkTableEntry final {
* @param defaultValue the value to be returned if no value is found
* @return the entry's value or the given default value
*/
std::string GetRaw(std::string_view defaultValue) const;
std::vector<uint8_t> GetRaw(wpi::span<const uint8_t> defaultValue) const;
/**
* Gets the entry's value as a boolean array. If the entry does not exist
@@ -171,7 +189,7 @@ class NetworkTableEntry final {
std::vector<int> GetBooleanArray(wpi::span<const int> defaultValue) const;
/**
* Gets the entry's value as a boolean array. If the entry does not exist
* Gets the entry's value as a integer array. If the entry does not exist
* or is of different type, it will return the default value.
*
* @param defaultValue the value to be returned if no value is found
@@ -179,13 +197,21 @@ class NetworkTableEntry final {
*
* @note This makes a copy of the array. If the overhead of this is a
* concern, use GetValue() instead.
*
* @note The returned array is std::vector<int> instead of std::vector<bool>
* because std::vector<bool> is special-cased in C++. 0 is false, any
* non-zero value is true.
*/
std::vector<int> GetBooleanArray(
std::initializer_list<int> defaultValue) const;
std::vector<int64_t> GetIntegerArray(
wpi::span<const int64_t> defaultValue) const;
/**
* Gets the entry's value as a float array. If the entry does not exist
* or is of different type, it will return the default value.
*
* @param defaultValue the value to be returned if no value is found
* @return the entry's value or the given default value
*
* @note This makes a copy of the array. If the overhead of this is a
* concern, use GetValue() instead.
*/
std::vector<float> GetFloatArray(wpi::span<const float> defaultValue) const;
/**
* Gets the entry's value as a double array. If the entry does not exist
@@ -200,19 +226,6 @@ class NetworkTableEntry final {
std::vector<double> GetDoubleArray(
wpi::span<const double> defaultValue) const;
/**
* Gets the entry's value as a double array. If the entry does not exist
* or is of different type, it will return the default value.
*
* @param defaultValue the value to be returned if no value is found
* @return the entry's value or the given default value
*
* @note This makes a copy of the array. If the overhead of this is a
* concern, use GetValue() instead.
*/
std::vector<double> GetDoubleArray(
std::initializer_list<double> defaultValue) const;
/**
* Gets the entry's value as a string array. If the entry does not exist
* or is of different type, it will return the default value.
@@ -227,25 +240,22 @@ class NetworkTableEntry final {
wpi::span<const std::string> defaultValue) const;
/**
* Gets the entry's value as a string array. If the entry does not exist
* or is of different type, it will return the default value.
* Get an array of all value changes since the last call to ReadQueue.
*
* @param defaultValue the value to be returned if no value is found
* @return the entry's value or the given default value
* The "poll storage" subscribe option can be used to set the queue depth.
*
* @note This makes a copy of the array. If the overhead of this is a
* concern, use GetValue() instead.
* @return Array of values; empty array if no new changes have been
* published since the previous call.
*/
std::vector<std::string> GetStringArray(
std::initializer_list<std::string> defaultValue) const;
std::vector<NetworkTableValue> ReadQueue();
/**
* Sets the entry's value if it does not exist.
*
* @param value the default value to set
* @param defaultValue the default value to set
* @return False if the entry exists with a different type
*/
bool SetDefaultValue(std::shared_ptr<Value> value);
bool SetDefaultValue(const Value& defaultValue);
/**
* Sets the entry's value if it does not exist.
@@ -255,6 +265,22 @@ class NetworkTableEntry final {
*/
bool SetDefaultBoolean(bool defaultValue);
/**
* Sets the entry's value if it does not exist.
*
* @param defaultValue the default value to set
* @return False if the entry exists with a different type
*/
bool SetDefaultInteger(int64_t defaultValue);
/**
* Sets the entry's value if it does not exist.
*
* @param defaultValue the default value to set
* @return False if the entry exists with a different type
*/
bool SetDefaultFloat(float defaultValue);
/**
* Sets the entry's value if it does not exist.
*
@@ -277,7 +303,7 @@ class NetworkTableEntry final {
* @param defaultValue the default value to set
* @return False if the entry exists with a different type
*/
bool SetDefaultRaw(std::string_view defaultValue);
bool SetDefaultRaw(wpi::span<const uint8_t> defaultValue);
/**
* Sets the entry's value if it does not exist.
@@ -293,7 +319,15 @@ class NetworkTableEntry final {
* @param defaultValue the default value to set
* @return False if the entry exists with a different type
*/
bool SetDefaultBooleanArray(std::initializer_list<int> defaultValue);
bool SetDefaultIntegerArray(wpi::span<const int64_t> defaultValue);
/**
* Sets the entry's value if it does not exist.
*
* @param defaultValue the default value to set
* @return False if the entry exists with a different type
*/
bool SetDefaultFloatArray(wpi::span<const float> defaultValue);
/**
* Sets the entry's value if it does not exist.
@@ -303,14 +337,6 @@ class NetworkTableEntry final {
*/
bool SetDefaultDoubleArray(wpi::span<const double> defaultValue);
/**
* Sets the entry's value if it does not exist.
*
* @param defaultValue the default value to set
* @return False if the entry exists with a different type
*/
bool SetDefaultDoubleArray(std::initializer_list<double> defaultValue);
/**
* Sets the entry's value if it does not exist.
*
@@ -319,234 +345,138 @@ class NetworkTableEntry final {
*/
bool SetDefaultStringArray(wpi::span<const std::string> defaultValue);
/**
* Sets the entry's value if it does not exist.
*
* @param defaultValue the default value to set
* @return False if the entry exists with a different type
*/
bool SetDefaultStringArray(std::initializer_list<std::string> defaultValue);
/**
* Sets the entry's value.
*
* @param value the value to set
* @return False if the entry exists with a different type
*/
bool SetValue(std::shared_ptr<Value> value);
bool SetValue(const Value& value);
/**
* Sets the entry's value.
*
* @param value the value to set
* @param time the timestamp to set (0 = nt::Now())
* @return False if the entry exists with a different type
*/
bool SetBoolean(bool value);
bool SetBoolean(bool value, int64_t time = 0);
/**
* Sets the entry's value.
*
* @param value the value to set
* @param time the timestamp to set (0 = nt::Now())
* @return False if the entry exists with a different type
*/
bool SetDouble(double value);
bool SetInteger(int64_t value, int64_t time = 0);
/**
* Sets the entry's value.
*
* @param value the value to set
* @param time the timestamp to set (0 = nt::Now())
* @return False if the entry exists with a different type
*/
bool SetString(std::string_view value);
bool SetFloat(float value, int64_t time = 0);
/**
* Sets the entry's value.
*
* @param value the value to set
* @param time the timestamp to set (0 = nt::Now())
* @return False if the entry exists with a different type
*/
bool SetRaw(std::string_view value);
bool SetDouble(double value, int64_t time = 0);
/**
* Sets the entry's value.
*
* @param value the value to set
* @param time the timestamp to set (0 = nt::Now())
* @return False if the entry exists with a different type
*/
bool SetBooleanArray(wpi::span<const bool> value);
bool SetString(std::string_view value, int64_t time = 0);
/**
* Sets the entry's value.
*
* @param value the value to set
* @param time the timestamp to set (0 = nt::Now())
* @return False if the entry exists with a different type
*/
bool SetBooleanArray(std::initializer_list<bool> value);
bool SetRaw(wpi::span<const uint8_t> value, int64_t time = 0);
/**
* Sets the entry's value.
*
* @param value the value to set
* @param time the timestamp to set (0 = nt::Now())
* @return False if the entry exists with a different type
*/
bool SetBooleanArray(wpi::span<const int> value);
bool SetBooleanArray(wpi::span<const bool> value, int64_t time = 0);
/**
* Sets the entry's value.
*
* @param value the value to set
* @param time the timestamp to set (0 = nt::Now())
* @return False if the entry exists with a different type
*/
bool SetBooleanArray(std::initializer_list<int> value);
bool SetBooleanArray(wpi::span<const int> value, int64_t time = 0);
/**
* Sets the entry's value.
*
* @param value the value to set
* @param time the timestamp to set (0 = nt::Now())
* @return False if the entry exists with a different type
*/
bool SetDoubleArray(wpi::span<const double> value);
bool SetIntegerArray(wpi::span<const int64_t> value, int64_t time = 0);
/**
* Sets the entry's value.
*
* @param value the value to set
* @param time the timestamp to set (0 = nt::Now())
* @return False if the entry exists with a different type
*/
bool SetDoubleArray(std::initializer_list<double> value);
bool SetFloatArray(wpi::span<const float> value, int64_t time = 0);
/**
* Sets the entry's value.
*
* @param value the value to set
* @param time the timestamp to set (0 = nt::Now())
* @return False if the entry exists with a different type
*/
bool SetStringArray(wpi::span<const std::string> value);
bool SetDoubleArray(wpi::span<const double> value, int64_t time = 0);
/**
* Sets the entry's value.
*
* @param value the value to set
* @param time the timestamp to set (0 = nt::Now())
* @return False if the entry exists with a different type
*/
bool SetStringArray(std::initializer_list<std::string> value);
/**
* Sets the entry's value. If the value is of different type, the type is
* changed to match the new value.
*
* @param value the value to set
*/
void ForceSetValue(std::shared_ptr<Value> value);
/**
* Sets the entry's value. If the value is of different type, the type is
* changed to match the new value.
*
* @param value the value to set
*/
void ForceSetBoolean(bool value);
/**
* Sets the entry's value. If the value is of different type, the type is
* changed to match the new value.
*
* @param value the value to set
*/
void ForceSetDouble(double value);
/**
* Sets the entry's value. If the value is of different type, the type is
* changed to match the new value.
*
* @param value the value to set
*/
void ForceSetString(std::string_view value);
/**
* Sets the entry's value. If the value is of different type, the type is
* changed to match the new value.
*
* @param value the value to set
*/
void ForceSetRaw(std::string_view value);
/**
* Sets the entry's value. If the value is of different type, the type is
* changed to match the new value.
*
* @param value the value to set
*/
void ForceSetBooleanArray(wpi::span<const bool> value);
/**
* Sets the entry's value. If the value is of different type, the type is
* changed to match the new value.
*
* @param value the value to set
*/
void ForceSetBooleanArray(std::initializer_list<bool> value);
/**
* Sets the entry's value. If the value is of different type, the type is
* changed to match the new value.
*
* @param value the value to set
*/
void ForceSetBooleanArray(wpi::span<const int> value);
/**
* Sets the entry's value. If the value is of different type, the type is
* changed to match the new value.
*
* @param value the value to set
*/
void ForceSetBooleanArray(std::initializer_list<int> value);
/**
* Sets the entry's value. If the value is of different type, the type is
* changed to match the new value.
*
* @param value the value to set
*/
void ForceSetDoubleArray(wpi::span<const double> value);
/**
* Sets the entry's value. If the value is of different type, the type is
* changed to match the new value.
*
* @param value the value to set
*/
void ForceSetDoubleArray(std::initializer_list<double> value);
/**
* Sets the entry's value. If the value is of different type, the type is
* changed to match the new value.
*
* @param value the value to set
*/
void ForceSetStringArray(wpi::span<const std::string> value);
/**
* Sets the entry's value. If the value is of different type, the type is
* changed to match the new value.
*
* @param value the value to set
*/
void ForceSetStringArray(std::initializer_list<std::string> value);
bool SetStringArray(wpi::span<const std::string> value, int64_t time = 0);
/**
* Sets flags.
*
* @param flags the flags to set (bitmask)
* @deprecated Use SetPersistent() or topic properties instead
*/
WPI_DEPRECATED("Use SetPersistent() or topic properties instead")
void SetFlags(unsigned int flags);
/**
* Clears flags.
*
* @param flags the flags to clear (bitmask)
* @deprecated Use SetPersistent() or topic properties instead
*/
WPI_DEPRECATED("Use SetPersistent() or topic properties instead")
void ClearFlags(unsigned int flags);
/**
@@ -567,55 +497,23 @@ class NetworkTableEntry final {
bool IsPersistent() const;
/**
* Deletes the entry.
* Stops publishing the entry if it's been published.
*/
void Unpublish();
/**
* Deletes the entry.
* @deprecated Use Unpublish() instead.
*/
WPI_DEPRECATED("Use Unpublish() instead")
void Delete();
/**
* Create a callback-based RPC entry point. Only valid to use on the server.
* The callback function will be called when the RPC is called.
* This function creates RPC version 0 definitions (raw data in and out).
* Gets the entry's topic.
*
* @param callback callback function
* @return Topic
*/
void CreateRpc(std::function<void(const RpcAnswer& answer)> callback);
/**
* Create a polled RPC entry point. Only valid to use on the server.
* The caller is responsible for calling NetworkTableInstance::PollRpc()
* to poll for servicing incoming RPC calls.
* This function creates RPC version 0 definitions (raw data in and out).
*/
void CreatePolledRpc();
/**
* Call a RPC function. May be used on either the client or server.
* This function is non-blocking. Either RpcCall::GetResult() or
* RpcCall::CancelResult() must be called on the return value to either
* get or ignore the result of the call.
*
* @param params parameter
* @return RPC call object.
*/
RpcCall CallRpc(std::string_view params);
/**
* Add a listener for changes to this entry.
*
* @param callback listener to add
* @param flags NotifyKind bitmask
* @return Listener handle
*/
NT_EntryListener AddListener(
std::function<void(const EntryNotification& event)> callback,
unsigned int flags) const;
/**
* Remove an entry listener.
*
* @param entry_listener Listener handle to remove
*/
void RemoveListener(NT_EntryListener entry_listener);
Topic GetTopic() const;
/**
* Equality operator. Returns true if both instances refer to the same
@@ -638,5 +536,3 @@ class NetworkTableEntry final {
} // namespace nt
#include "networktables/NetworkTableEntry.inc"
#endif // NTCORE_NETWORKTABLES_NETWORKTABLEENTRY_H_

View File

@@ -2,8 +2,7 @@
// 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.
#ifndef NTCORE_NETWORKTABLES_NETWORKTABLEENTRY_INC_
#define NTCORE_NETWORKTABLES_NETWORKTABLEENTRY_INC_
#pragma once
#include <memory>
#include <string>
@@ -11,6 +10,8 @@
#include <vector>
#include "networktables/NetworkTableEntry.h"
#include "ntcore_cpp.h"
#include "ntcore_cpp_types.h"
namespace nt {
@@ -39,307 +40,208 @@ inline unsigned int NetworkTableEntry::GetFlags() const {
return GetEntryFlags(m_handle);
}
inline uint64_t NetworkTableEntry::GetLastChange() const {
inline int64_t NetworkTableEntry::GetLastChange() const {
return GetEntryLastChange(m_handle);
}
inline EntryInfo NetworkTableEntry::GetInfo() const {
return GetEntryInfo(m_handle);
}
inline std::shared_ptr<Value> NetworkTableEntry::GetValue() const {
inline Value NetworkTableEntry::GetValue() const {
return GetEntryValue(m_handle);
}
inline bool NetworkTableEntry::GetBoolean(bool defaultValue) const {
auto value = GetEntryValue(m_handle);
if (!value || value->type() != NT_BOOLEAN) {
return defaultValue;
}
return value->GetBoolean();
return nt::GetBoolean(m_handle, defaultValue);
}
inline int64_t NetworkTableEntry::GetInteger(int64_t defaultValue) const {
return nt::GetInteger(m_handle, defaultValue);
}
inline float NetworkTableEntry::GetFloat(float defaultValue) const {
return nt::GetFloat(m_handle, defaultValue);
}
inline double NetworkTableEntry::GetDouble(double defaultValue) const {
auto value = GetEntryValue(m_handle);
if (!value || value->type() != NT_DOUBLE) {
return defaultValue;
}
return value->GetDouble();
return nt::GetDouble(m_handle, defaultValue);
}
inline std::string NetworkTableEntry::GetString(
std::string_view defaultValue) const {
auto value = GetEntryValue(m_handle);
if (!value || value->type() != NT_STRING) {
return std::string{defaultValue};
}
return std::string{value->GetString()};
return nt::GetString(m_handle, defaultValue);
}
inline std::string NetworkTableEntry::GetRaw(
std::string_view defaultValue) const {
auto value = GetEntryValue(m_handle);
if (!value || value->type() != NT_RAW) {
return std::string{defaultValue};
}
return std::string{value->GetRaw()};
inline std::vector<uint8_t> NetworkTableEntry::GetRaw(
wpi::span<const uint8_t> defaultValue) const {
return nt::GetRaw(m_handle, defaultValue);
}
inline std::vector<int> NetworkTableEntry::GetBooleanArray(
wpi::span<const int> defaultValue) const {
auto value = GetEntryValue(m_handle);
if (!value || value->type() != NT_BOOLEAN_ARRAY) {
return {defaultValue.begin(), defaultValue.end()};
}
auto arr = value->GetBooleanArray();
return {arr.begin(), arr.end()};
return nt::GetBooleanArray(m_handle, defaultValue);
}
inline std::vector<int> NetworkTableEntry::GetBooleanArray(
std::initializer_list<int> defaultValue) const {
return GetBooleanArray({defaultValue.begin(), defaultValue.end()});
inline std::vector<int64_t> NetworkTableEntry::GetIntegerArray(
wpi::span<const int64_t> defaultValue) const {
return nt::GetIntegerArray(m_handle, defaultValue);
}
inline std::vector<float> NetworkTableEntry::GetFloatArray(
wpi::span<const float> defaultValue) const {
return nt::GetFloatArray(m_handle, defaultValue);
}
inline std::vector<double> NetworkTableEntry::GetDoubleArray(
wpi::span<const double> defaultValue) const {
auto value = GetEntryValue(m_handle);
if (!value || value->type() != NT_DOUBLE_ARRAY) {
return {defaultValue.begin(), defaultValue.end()};
}
auto arr = value->GetDoubleArray();
return {arr.begin(), arr.end()};
}
inline std::vector<double> NetworkTableEntry::GetDoubleArray(
std::initializer_list<double> defaultValue) const {
return GetDoubleArray({defaultValue.begin(), defaultValue.end()});
return nt::GetDoubleArray(m_handle, defaultValue);
}
inline std::vector<std::string> NetworkTableEntry::GetStringArray(
wpi::span<const std::string> defaultValue) const {
auto value = GetEntryValue(m_handle);
if (!value || value->type() != NT_STRING_ARRAY) {
return {defaultValue.begin(), defaultValue.end()};
}
auto arr = value->GetStringArray();
return {arr.begin(), arr.end()};
return nt::GetStringArray(m_handle, defaultValue);
}
inline std::vector<std::string> NetworkTableEntry::GetStringArray(
std::initializer_list<std::string> defaultValue) const {
return GetStringArray({defaultValue.begin(), defaultValue.end()});
inline std::vector<NetworkTableValue> NetworkTableEntry::ReadQueue() {
return nt::ReadQueueValue(m_handle);
}
inline bool NetworkTableEntry::SetDefaultValue(std::shared_ptr<Value> value) {
return SetDefaultEntryValue(m_handle, value);
inline bool NetworkTableEntry::SetDefaultValue(const Value& defaultValue) {
return SetDefaultEntryValue(m_handle, defaultValue);
}
inline bool NetworkTableEntry::SetDefaultBoolean(bool defaultValue) {
return SetDefaultEntryValue(m_handle, Value::MakeBoolean(defaultValue));
return nt::SetDefaultBoolean(m_handle, defaultValue);
}
inline bool NetworkTableEntry::SetDefaultInteger(int64_t defaultValue) {
return nt::SetDefaultInteger(m_handle, defaultValue);
}
inline bool NetworkTableEntry::SetDefaultFloat(float defaultValue) {
return nt::SetDefaultFloat(m_handle, defaultValue);
}
inline bool NetworkTableEntry::SetDefaultDouble(double defaultValue) {
return SetDefaultEntryValue(m_handle, Value::MakeDouble(defaultValue));
return nt::SetDefaultDouble(m_handle, defaultValue);
}
inline bool NetworkTableEntry::SetDefaultString(std::string_view defaultValue) {
return SetDefaultEntryValue(m_handle, Value::MakeString(defaultValue));
return nt::SetDefaultString(m_handle, defaultValue);
}
inline bool NetworkTableEntry::SetDefaultRaw(std::string_view defaultValue) {
return SetDefaultEntryValue(m_handle, Value::MakeRaw(defaultValue));
inline bool NetworkTableEntry::SetDefaultRaw(
wpi::span<const uint8_t> defaultValue) {
return nt::SetDefaultRaw(m_handle, defaultValue);
}
inline bool NetworkTableEntry::SetDefaultBooleanArray(
wpi::span<const int> defaultValue) {
return SetDefaultEntryValue(m_handle, Value::MakeBooleanArray(defaultValue));
return nt::SetDefaultBooleanArray(m_handle, defaultValue);
}
inline bool NetworkTableEntry::SetDefaultBooleanArray(
std::initializer_list<int> defaultValue) {
return SetDefaultEntryValue(m_handle, Value::MakeBooleanArray(defaultValue));
inline bool NetworkTableEntry::SetDefaultIntegerArray(
wpi::span<const int64_t> defaultValue) {
return nt::SetDefaultIntegerArray(m_handle, defaultValue);
}
inline bool NetworkTableEntry::SetDefaultFloatArray(
wpi::span<const float> defaultValue) {
return nt::SetDefaultFloatArray(m_handle, defaultValue);
}
inline bool NetworkTableEntry::SetDefaultDoubleArray(
wpi::span<const double> defaultValue) {
return SetDefaultEntryValue(m_handle, Value::MakeDoubleArray(defaultValue));
}
inline bool NetworkTableEntry::SetDefaultDoubleArray(
std::initializer_list<double> value) {
return SetDefaultEntryValue(m_handle, Value::MakeDoubleArray(value));
return nt::SetDefaultDoubleArray(m_handle, defaultValue);
}
inline bool NetworkTableEntry::SetDefaultStringArray(
wpi::span<const std::string> defaultValue) {
return SetDefaultEntryValue(m_handle, Value::MakeStringArray(defaultValue));
return nt::SetDefaultStringArray(m_handle, defaultValue);
}
inline bool NetworkTableEntry::SetDefaultStringArray(
std::initializer_list<std::string> defaultValue) {
return SetDefaultEntryValue(m_handle, Value::MakeStringArray(defaultValue));
}
inline bool NetworkTableEntry::SetValue(std::shared_ptr<Value> value) {
inline bool NetworkTableEntry::SetValue(const Value& value) {
return SetEntryValue(m_handle, value);
}
inline bool NetworkTableEntry::SetBoolean(bool value) {
return SetEntryValue(m_handle, Value::MakeBoolean(value));
inline bool NetworkTableEntry::SetBoolean(bool value, int64_t time) {
return nt::SetBoolean(m_handle, value, time);
}
inline bool NetworkTableEntry::SetDouble(double value) {
return SetEntryValue(m_handle, Value::MakeDouble(value));
inline bool NetworkTableEntry::SetInteger(int64_t value, int64_t time) {
return nt::SetInteger(m_handle, value, time);
}
inline bool NetworkTableEntry::SetString(std::string_view value) {
return SetEntryValue(m_handle, Value::MakeString(value));
inline bool NetworkTableEntry::SetFloat(float value, int64_t time) {
return nt::SetFloat(m_handle, value, time);
}
inline bool NetworkTableEntry::SetRaw(std::string_view value) {
return SetEntryValue(m_handle, Value::MakeRaw(value));
inline bool NetworkTableEntry::SetDouble(double value, int64_t time) {
return nt::SetDouble(m_handle, value, time);
}
inline bool NetworkTableEntry::SetBooleanArray(wpi::span<const bool> value) {
return SetEntryValue(m_handle, Value::MakeBooleanArray(value));
inline bool NetworkTableEntry::SetString(std::string_view value, int64_t time) {
return nt::SetString(m_handle, value, time);
}
inline bool NetworkTableEntry::SetBooleanArray(
std::initializer_list<bool> value) {
return SetEntryValue(m_handle, Value::MakeBooleanArray(value));
inline bool NetworkTableEntry::SetRaw(wpi::span<const uint8_t> value,
int64_t time) {
return nt::SetRaw(m_handle, value, time);
}
inline bool NetworkTableEntry::SetBooleanArray(wpi::span<const int> value) {
return SetEntryValue(m_handle, Value::MakeBooleanArray(value));
inline bool NetworkTableEntry::SetBooleanArray(wpi::span<const bool> value,
int64_t time) {
return SetEntryValue(m_handle, Value::MakeBooleanArray(value, time));
}
inline bool NetworkTableEntry::SetBooleanArray(
std::initializer_list<int> value) {
return SetEntryValue(m_handle, Value::MakeBooleanArray(value));
inline bool NetworkTableEntry::SetBooleanArray(wpi::span<const int> value,
int64_t time) {
return nt::SetBooleanArray(m_handle, value, time);
}
inline bool NetworkTableEntry::SetDoubleArray(wpi::span<const double> value) {
return SetEntryValue(m_handle, Value::MakeDoubleArray(value));
inline bool NetworkTableEntry::SetIntegerArray(wpi::span<const int64_t> value,
int64_t time) {
return nt::SetIntegerArray(m_handle, value, time);
}
inline bool NetworkTableEntry::SetDoubleArray(
std::initializer_list<double> value) {
return SetEntryValue(m_handle, Value::MakeDoubleArray(value));
inline bool NetworkTableEntry::SetFloatArray(wpi::span<const float> value,
int64_t time) {
return nt::SetFloatArray(m_handle, value, time);
}
inline bool NetworkTableEntry::SetDoubleArray(wpi::span<const double> value,
int64_t time) {
return nt::SetDoubleArray(m_handle, value, time);
}
inline bool NetworkTableEntry::SetStringArray(
wpi::span<const std::string> value) {
return SetEntryValue(m_handle, Value::MakeStringArray(value));
}
inline bool NetworkTableEntry::SetStringArray(
std::initializer_list<std::string> value) {
return SetEntryValue(m_handle, Value::MakeStringArray(value));
}
inline void NetworkTableEntry::ForceSetValue(std::shared_ptr<Value> value) {
SetEntryTypeValue(m_handle, value);
}
inline void NetworkTableEntry::ForceSetBoolean(bool value) {
SetEntryTypeValue(m_handle, Value::MakeBoolean(value));
}
inline void NetworkTableEntry::ForceSetDouble(double value) {
SetEntryTypeValue(m_handle, Value::MakeDouble(value));
}
inline void NetworkTableEntry::ForceSetString(std::string_view value) {
SetEntryTypeValue(m_handle, Value::MakeString(value));
}
inline void NetworkTableEntry::ForceSetRaw(std::string_view value) {
SetEntryTypeValue(m_handle, Value::MakeRaw(value));
}
inline void NetworkTableEntry::ForceSetBooleanArray(
wpi::span<const bool> value) {
SetEntryTypeValue(m_handle, Value::MakeBooleanArray(value));
}
inline void NetworkTableEntry::ForceSetBooleanArray(
std::initializer_list<bool> value) {
SetEntryTypeValue(m_handle, Value::MakeBooleanArray(value));
}
inline void NetworkTableEntry::ForceSetBooleanArray(
wpi::span<const int> value) {
SetEntryTypeValue(m_handle, Value::MakeBooleanArray(value));
}
inline void NetworkTableEntry::ForceSetBooleanArray(
std::initializer_list<int> value) {
SetEntryTypeValue(m_handle, Value::MakeBooleanArray(value));
}
inline void NetworkTableEntry::ForceSetDoubleArray(
wpi::span<const double> value) {
SetEntryTypeValue(m_handle, Value::MakeDoubleArray(value));
}
inline void NetworkTableEntry::ForceSetDoubleArray(
std::initializer_list<double> value) {
SetEntryTypeValue(m_handle, Value::MakeDoubleArray(value));
}
inline void NetworkTableEntry::ForceSetStringArray(
wpi::span<const std::string> value) {
SetEntryTypeValue(m_handle, Value::MakeStringArray(value));
}
inline void NetworkTableEntry::ForceSetStringArray(
std::initializer_list<std::string> value) {
SetEntryTypeValue(m_handle, Value::MakeStringArray(value));
wpi::span<const std::string> value, int64_t time) {
return nt::SetStringArray(m_handle, value, time);
}
inline void NetworkTableEntry::SetFlags(unsigned int flags) {
SetEntryFlags(m_handle, GetFlags() | flags);
SetEntryFlags(m_handle, GetEntryFlags(m_handle) | flags);
}
inline void NetworkTableEntry::ClearFlags(unsigned int flags) {
SetEntryFlags(m_handle, GetFlags() & ~flags);
SetEntryFlags(m_handle, GetEntryFlags(m_handle) & ~flags);
}
inline void NetworkTableEntry::SetPersistent() {
SetFlags(kPersistent);
nt::SetTopicPersistent(nt::GetTopicFromHandle(m_handle), true);
}
inline void NetworkTableEntry::ClearPersistent() {
ClearFlags(kPersistent);
nt::SetTopicPersistent(nt::GetTopicFromHandle(m_handle), false);
}
inline bool NetworkTableEntry::IsPersistent() const {
return (GetFlags() & kPersistent) != 0;
return nt::GetTopicPersistent(nt::GetTopicFromHandle(m_handle));
}
inline void NetworkTableEntry::Unpublish() {
return nt::Unpublish(m_handle);
}
inline void NetworkTableEntry::Delete() {
DeleteEntry(m_handle);
}
inline void NetworkTableEntry::CreateRpc(
std::function<void(const RpcAnswer& answer)> callback) {
::nt::CreateRpc(m_handle, std::string_view("\0", 1), callback);
}
inline RpcCall NetworkTableEntry::CallRpc(std::string_view params) {
return RpcCall{m_handle, ::nt::CallRpc(m_handle, params)};
}
inline NT_EntryListener NetworkTableEntry::AddListener(
std::function<void(const EntryNotification& event)> callback,
unsigned int flags) const {
return AddEntryListener(m_handle, callback, flags);
}
inline void NetworkTableEntry::RemoveListener(NT_EntryListener entry_listener) {
RemoveEntryListener(entry_listener);
Unpublish();
}
} // namespace nt
#endif // NTCORE_NETWORKTABLES_NETWORKTABLEENTRY_INC_

View File

@@ -2,8 +2,7 @@
// 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.
#ifndef NTCORE_NETWORKTABLES_NETWORKTABLEINSTANCE_H_
#define NTCORE_NETWORKTABLES_NETWORKTABLEINSTANCE_H_
#pragma once
#include <functional>
#include <memory>
@@ -21,6 +20,19 @@
namespace nt {
class BooleanArrayTopic;
class BooleanTopic;
class DoubleArrayTopic;
class DoubleTopic;
class FloatArrayTopic;
class FloatTopic;
class IntegerArrayTopic;
class IntegerTopic;
class RawTopic;
class StringArrayTopic;
class StringTopic;
class Topic;
/**
* NetworkTables Instance.
*
@@ -51,9 +63,8 @@ class NetworkTableInstance final {
enum NetworkMode {
kNetModeNone = NT_NET_MODE_NONE,
kNetModeServer = NT_NET_MODE_SERVER,
kNetModeClient = NT_NET_MODE_CLIENT,
kNetModeStarting = NT_NET_MODE_STARTING,
kNetModeFailure = NT_NET_MODE_FAILURE,
kNetModeClient3 = NT_NET_MODE_CLIENT3,
kNetModeClient4 = NT_NET_MODE_CLIENT4,
kNetModeLocal = NT_NET_MODE_LOCAL
};
@@ -73,9 +84,14 @@ class NetworkTableInstance final {
};
/**
* The default port that network tables operates on.
* The default port that network tables operates on for NT3.
*/
enum { kDefaultPort = NT_DEFAULT_PORT };
static constexpr unsigned int kDefaultPort3 = NT_DEFAULT_PORT3;
/**
* The default port that network tables operates on for NT4.
*/
static constexpr unsigned int kDefaultPort4 = NT_DEFAULT_PORT4;
/**
* Construct invalid instance.
@@ -124,6 +140,204 @@ class NetworkTableInstance final {
*/
NT_Inst GetHandle() const;
/**
* Gets a "generic" (untyped) topic.
*
* @param name topic name
* @return Topic
*/
Topic GetTopic(std::string_view name) const;
/**
* Gets a boolean topic.
*
* @param name topic name
* @return Topic
*/
BooleanTopic GetBooleanTopic(std::string_view name) const;
/**
* Gets an integer topic.
*
* @param name topic name
* @return Topic
*/
IntegerTopic GetIntegerTopic(std::string_view name) const;
/**
* Gets a float topic.
*
* @param name topic name
* @return Topic
*/
FloatTopic GetFloatTopic(std::string_view name) const;
/**
* Gets a double topic.
*
* @param name topic name
* @return Topic
*/
DoubleTopic GetDoubleTopic(std::string_view name) const;
/**
* Gets a string topic.
*
* @param name topic name
* @return Topic
*/
StringTopic GetStringTopic(std::string_view name) const;
/**
* Gets a raw topic.
*
* @param name topic name
* @return Topic
*/
RawTopic GetRawTopic(std::string_view name) const;
/**
* Gets a boolean array topic.
*
* @param name topic name
* @return Topic
*/
BooleanArrayTopic GetBooleanArrayTopic(std::string_view name) const;
/**
* Gets an integer array topic.
*
* @param name topic name
* @return Topic
*/
IntegerArrayTopic GetIntegerArrayTopic(std::string_view name) const;
/**
* Gets a float array topic.
*
* @param name topic name
* @return Topic
*/
FloatArrayTopic GetFloatArrayTopic(std::string_view name) const;
/**
* Gets a double array topic.
*
* @param name topic name
* @return Topic
*/
DoubleArrayTopic GetDoubleArrayTopic(std::string_view name) const;
/**
* Gets a string array topic.
*
* @param name topic name
* @return Topic
*/
StringArrayTopic GetStringArrayTopic(std::string_view name) const;
/**
* Get Published Topics.
*
* Returns an array of topics.
*
* @return Array of topics.
*/
std::vector<Topic> GetTopics();
/**
* Get Published Topics.
*
* Returns an array of topics. The results are filtered by
* string prefix to only return a subset of all topics.
*
* @param prefix name required prefix; only topics whose name
* starts with this string are returned
* @return Array of topics.
*/
std::vector<Topic> GetTopics(std::string_view prefix);
/**
* Get Published Topics.
*
* Returns an array of topics. The results are filtered by
* string prefix and type to only return a subset of all topics.
*
* @param prefix name required prefix; only topics whose name
* starts with this string are returned
* @param types bitmask of NT_Type values; 0 is treated specially
* as a "don't care"
* @return Array of topics.
*/
std::vector<Topic> GetTopics(std::string_view prefix, unsigned int types);
/**
* Get Published Topics.
*
* Returns an array of topics. The results are filtered by
* string prefix and type to only return a subset of all topics.
*
* @param prefix name required prefix; only topics whose name
* starts with this string are returned
* @param types array of type strings
* @return Array of topic handles.
*/
std::vector<Topic> GetTopics(std::string_view prefix,
wpi::span<std::string_view> types);
/**
* Get Topic Information about multiple topics.
*
* Returns an array of topic information (handle, name, type, and properties).
*
* @return Array of topic information.
*/
std::vector<TopicInfo> GetTopicInfo();
/**
* Get Topic Information about multiple topics.
*
* Returns an array of topic information (handle, name, type, and properties).
* The results are filtered by string prefix to only
* return a subset of all topics.
*
* @param prefix name required prefix; only topics whose name
* starts with this string are returned
* @return Array of topic information.
*/
std::vector<TopicInfo> GetTopicInfo(std::string_view prefix);
/**
* Get Topic Information about multiple topics.
*
* Returns an array of topic information (handle, name, type, and properties).
* The results are filtered by string prefix and type to only
* return a subset of all topics.
*
* @param prefix name required prefix; only topics whose name
* starts with this string are returned
* @param types bitmask of NT_Type values; 0 is treated specially
* as a "don't care"
* @return Array of topic information.
*/
std::vector<TopicInfo> GetTopicInfo(std::string_view prefix,
unsigned int types);
/**
* Get Topic Information about multiple topics.
*
* Returns an array of topic information (handle, name, type, and properties).
* The results are filtered by string prefix and type to only
* return a subset of all topics.
*
* @param prefix name required prefix; only topics whose name
* starts with this string are returned
* @param types array of type strings
* @return Array of topic information.
*/
std::vector<TopicInfo> GetTopicInfo(std::string_view prefix,
wpi::span<std::string_view> types);
/**
* Gets the entry for a key.
*
@@ -132,34 +346,6 @@ class NetworkTableInstance final {
*/
NetworkTableEntry GetEntry(std::string_view name);
/**
* Get entries starting with the given prefix.
*
* The results are optionally filtered by string prefix and entry type to
* only return a subset of all entries.
*
* @param prefix entry name required prefix; only entries whose name
* starts with this string are returned
* @param types bitmask of types; 0 is treated as a "don't care"
* @return Array of entries.
*/
std::vector<NetworkTableEntry> GetEntries(std::string_view prefix,
unsigned int types);
/**
* Get information about entries starting with the given prefix.
*
* The results are optionally filtered by string prefix and entry type to
* only return a subset of all entries.
*
* @param prefix entry name required prefix; only entries whose name
* starts with this string are returned
* @param types bitmask of types; 0 is treated as a "don't care"
* @return Array of entry information.
*/
std::vector<EntryInfo> GetEntryInfo(std::string_view prefix,
unsigned int types) const;
/**
* Gets the table with the specified key.
*
@@ -168,51 +354,6 @@ class NetworkTableInstance final {
*/
std::shared_ptr<NetworkTable> GetTable(std::string_view key) const;
/**
* Deletes ALL keys in ALL subtables (except persistent values).
* Use with caution!
*/
void DeleteAllEntries();
/**
* @{
* @name Entry Listener Functions
*/
/**
* Add a listener for all entries starting with a certain prefix.
*
* @param prefix UTF-8 string prefix
* @param callback listener to add
* @param flags EntryListenerFlags bitmask
* @return Listener handle
*/
NT_EntryListener AddEntryListener(
std::string_view prefix,
std::function<void(const EntryNotification& event)> callback,
unsigned int flags) const;
/**
* Remove an entry listener.
*
* @param entry_listener Listener handle to remove
*/
static void RemoveEntryListener(NT_EntryListener entry_listener);
/**
* Wait for the entry listener queue to be empty. This is primarily useful
* for deterministic testing. This blocks until either the entry listener
* queue is empty (e.g. there are no more events that need to be passed along
* to callbacks or poll queues) or the timeout expires.
*
* @param timeout timeout, in seconds. Set to 0 for non-blocking behavior,
* or a negative value to block indefinitely
* @return False if timed out, otherwise true.
*/
bool WaitForEntryListenerQueue(double timeout);
/** @} */
/**
* @{
* @name Connection Listener Functions
@@ -236,37 +377,6 @@ class NetworkTableInstance final {
*/
static void RemoveConnectionListener(NT_ConnectionListener conn_listener);
/**
* Wait for the connection listener queue to be empty. This is primarily
* useful for deterministic testing. This blocks until either the connection
* listener queue is empty (e.g. there are no more events that need to be
* passed along to callbacks or poll queues) or the timeout expires.
*
* @param timeout timeout, in seconds. Set to 0 for non-blocking behavior,
* or a negative value to block indefinitely
* @return False if timed out, otherwise true.
*/
bool WaitForConnectionListenerQueue(double timeout);
/** @} */
/**
* @{
* @name Remote Procedure Call Functions
*/
/**
* Wait for the incoming RPC call queue to be empty. This is primarily useful
* for deterministic testing. This blocks until either the RPC call
* queue is empty (e.g. there are no more events that need to be passed along
* to callbacks or poll queues) or the timeout expires.
*
* @param timeout timeout, in seconds. Set to 0 for non-blocking behavior,
* or a negative value to block indefinitely
* @return False if timed out, otherwise true.
*/
bool WaitForRpcCallQueue(double timeout);
/** @} */
/**
@@ -311,11 +421,13 @@ class NetworkTableInstance final {
* null terminated)
* @param listen_address the address to listen on, or null to listen on any
* address (UTF-8 string, null terminated)
* @param port port to communicate over
* @param port3 port to communicate over (NT3)
* @param port4 port to communicate over (NT4)
*/
void StartServer(std::string_view persist_filename = "networktables.ini",
void StartServer(std::string_view persist_filename = "networktables.json",
const char* listen_address = "",
unsigned int port = kDefaultPort);
unsigned int port3 = kDefaultPort3,
unsigned int port4 = kDefaultPort4);
/**
* Stops the server if it is running.
@@ -323,45 +435,16 @@ class NetworkTableInstance final {
void StopServer();
/**
* Starts a client. Use SetServer to set the server name and port.
* Starts a NT3 client. Use SetServer or SetServerTeam to set the server name
* and port.
*/
void StartClient();
void StartClient3();
/**
* Starts a client using the specified server and port
*
* @param server_name server name (UTF-8 string, null terminated)
* @param port port to communicate over
* Starts a NT4 client. Use SetServer or SetServerTeam to set the server name
* and port.
*/
void StartClient(const char* server_name, unsigned int port = kDefaultPort);
/**
* Starts a client using the specified (server, port) combinations. The
* client will attempt to connect to each server in round robin fashion.
*
* @param servers array of server name and port pairs
*/
void StartClient(
wpi::span<const std::pair<std::string_view, unsigned int>> servers);
/**
* Starts a client using the specified servers and port. The
* client will attempt to connect to each server in round robin fashion.
*
* @param servers array of server names
* @param port port to communicate over
*/
void StartClient(wpi::span<const std::string_view> servers,
unsigned int port = kDefaultPort);
/**
* Starts a client using commonly known robot addresses for the specified
* team.
*
* @param team team number
* @param port port to communicate over
*/
void StartClientTeam(unsigned int team, unsigned int port = kDefaultPort);
void StartClient4();
/**
* Stops the client if it is running.
@@ -372,15 +455,15 @@ class NetworkTableInstance final {
* Sets server address and port for client (without restarting client).
*
* @param server_name server name (UTF-8 string, null terminated)
* @param port port to communicate over
* @param port port to communicate over (0 = default)
*/
void SetServer(const char* server_name, unsigned int port = kDefaultPort);
void SetServer(const char* server_name, unsigned int port = 0);
/**
* Sets server addresses and ports for client (without restarting client).
* The client will attempt to connect to each server in round robin fashion.
*
* @param servers array of server name and port pairs
* @param servers array of server address and port pairs
*/
void SetServer(
wpi::span<const std::pair<std::string_view, unsigned int>> servers);
@@ -390,28 +473,28 @@ class NetworkTableInstance final {
* The client will attempt to connect to each server in round robin fashion.
*
* @param servers array of server names
* @param port port to communicate over
* @param port port to communicate over (0 = default)
*/
void SetServer(wpi::span<const std::string_view> servers,
unsigned int port = kDefaultPort);
unsigned int port = 0);
/**
* Sets server addresses and port for client (without restarting client).
* Connects using commonly known robot addresses for the specified team.
*
* @param team team number
* @param port port to communicate over
* @param port port to communicate over (0 = default)
*/
void SetServerTeam(unsigned int team, unsigned int port = kDefaultPort);
void SetServerTeam(unsigned int team, unsigned int port = 0);
/**
* Starts requesting server address from Driver Station.
* This connects to the Driver Station running on localhost to obtain the
* server IP address.
*
* @param port server port to use in combination with IP from DS
* @param port server port to use in combination with IP from DS (0 = default)
*/
void StartDSClient(unsigned int port = kDefaultPort);
void StartDSClient(unsigned int port = 0);
/**
* Stops requesting server address from Driver Station.
@@ -419,12 +502,10 @@ class NetworkTableInstance final {
void StopDSClient();
/**
* Set the periodic update rate.
* Sets how frequently updates are sent to other nodes over the network.
*
* @param interval update interval in seconds (range 0.01 to 1.0)
* Flushes all updated values immediately to the local client/server. This
* does not flush to the network.
*/
void SetUpdateRate(double interval);
void FlushLocal() const;
/**
* Flushes all updated values immediately to the network.
@@ -451,60 +532,6 @@ class NetworkTableInstance final {
/** @} */
/**
* @{
* @name File Save/Load Functions
*/
/**
* Save persistent values to a file. The server automatically does this,
* but this function provides a way to save persistent values in the same
* format to a file on either a client or a server.
*
* @param filename filename
* @return error string, or nullptr if successful
*/
const char* SavePersistent(std::string_view filename) const;
/**
* Load persistent values from a file. The server automatically does this
* at startup, but this function provides a way to restore persistent values
* in the same format from a file at any time on either a client or a server.
*
* @param filename filename
* @param warn callback function for warnings
* @return error string, or nullptr if successful
*/
const char* LoadPersistent(
std::string_view filename,
std::function<void(size_t line, const char* msg)> warn);
/**
* Save table values to a file. The file format used is identical to
* that used for SavePersistent.
*
* @param filename filename
* @param prefix save only keys starting with this prefix
* @return error string, or nullptr if successful
*/
const char* SaveEntries(std::string_view filename,
std::string_view prefix) const;
/**
* Load table values from a file. The file format used is identical to
* that used for SavePersistent / LoadPersistent.
*
* @param filename filename
* @param prefix load only keys starting with this prefix
* @param warn callback function for warnings
* @return error string, or nullptr if successful
*/
const char* LoadEntries(
std::string_view filename, std::string_view prefix,
std::function<void(size_t line, const char* msg)> warn);
/** @} */
/**
* @{
* @name Data Logger Functions
@@ -578,18 +605,6 @@ class NetworkTableInstance final {
*/
static void RemoveLogger(NT_Logger logger);
/**
* Wait for the incoming log event queue to be empty. This is primarily
* useful for deterministic testing. This blocks until either the log event
* queue is empty (e.g. there are no more events that need to be passed along
* to callbacks or poll queues) or the timeout expires.
*
* @param timeout timeout, in seconds. Set to 0 for non-blocking behavior,
* or a negative value to block indefinitely
* @return False if timed out, otherwise true.
*/
bool WaitForLoggerQueue(double timeout);
/** @} */
/**
@@ -613,5 +628,3 @@ class NetworkTableInstance final {
} // namespace nt
#include "networktables/NetworkTableInstance.inc"
#endif // NTCORE_NETWORKTABLES_NETWORKTABLEINSTANCE_H_

View File

@@ -2,15 +2,14 @@
// 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.
#ifndef NTCORE_NETWORKTABLES_NETWORKTABLEINSTANCE_INC_
#define NTCORE_NETWORKTABLES_NETWORKTABLEINSTANCE_INC_
#pragma once
#include <string_view>
#include <utility>
#include <vector>
#include "networktables/NetworkTableInstance.h"
#include "ntcore_cpp.h"
#include "networktables/Topic.h"
namespace nt {
@@ -37,51 +36,57 @@ inline NT_Inst NetworkTableInstance::GetHandle() const {
return m_handle;
}
inline std::vector<Topic> NetworkTableInstance::GetTopics() {
auto handles = ::nt::GetTopics(m_handle, "", 0);
return {handles.begin(), handles.end()};
}
inline std::vector<Topic> NetworkTableInstance::GetTopics(
std::string_view prefix) {
auto handles = ::nt::GetTopics(m_handle, prefix, 0);
return {handles.begin(), handles.end()};
}
inline std::vector<Topic> NetworkTableInstance::GetTopics(
std::string_view prefix, unsigned int types) {
auto handles = ::nt::GetTopics(m_handle, prefix, types);
return {handles.begin(), handles.end()};
}
inline std::vector<Topic> NetworkTableInstance::GetTopics(
std::string_view prefix, wpi::span<std::string_view> types) {
auto handles = ::nt::GetTopics(m_handle, prefix, types);
return {handles.begin(), handles.end()};
}
inline std::vector<TopicInfo> NetworkTableInstance::GetTopicInfo() {
return ::nt::GetTopicInfo(m_handle, "", 0);
}
inline std::vector<TopicInfo> NetworkTableInstance::GetTopicInfo(
std::string_view prefix) {
return ::nt::GetTopicInfo(m_handle, prefix, 0);
}
inline std::vector<TopicInfo> NetworkTableInstance::GetTopicInfo(
std::string_view prefix, unsigned int types) {
return ::nt::GetTopicInfo(m_handle, prefix, types);
}
inline std::vector<TopicInfo> NetworkTableInstance::GetTopicInfo(
std::string_view prefix, wpi::span<std::string_view> types) {
return ::nt::GetTopicInfo(m_handle, prefix, types);
}
inline NetworkTableEntry NetworkTableInstance::GetEntry(std::string_view name) {
return NetworkTableEntry{::nt::GetEntry(m_handle, name)};
}
inline std::vector<NetworkTableEntry> NetworkTableInstance::GetEntries(
std::string_view prefix, unsigned int types) {
std::vector<NetworkTableEntry> entries;
for (auto entry : ::nt::GetEntries(m_handle, prefix, types)) {
entries.emplace_back(entry);
}
return entries;
}
inline std::vector<EntryInfo> NetworkTableInstance::GetEntryInfo(
std::string_view prefix, unsigned int types) const {
return ::nt::GetEntryInfo(m_handle, prefix, types);
}
inline void NetworkTableInstance::DeleteAllEntries() {
::nt::DeleteAllEntries(m_handle);
}
inline void NetworkTableInstance::RemoveEntryListener(
NT_EntryListener entry_listener) {
::nt::RemoveEntryListener(entry_listener);
}
inline bool NetworkTableInstance::WaitForEntryListenerQueue(double timeout) {
return ::nt::WaitForEntryListenerQueue(m_handle, timeout);
}
inline void NetworkTableInstance::RemoveConnectionListener(
NT_ConnectionListener conn_listener) {
::nt::RemoveConnectionListener(conn_listener);
}
inline bool NetworkTableInstance::WaitForConnectionListenerQueue(
double timeout) {
return ::nt::WaitForConnectionListenerQueue(m_handle, timeout);
}
inline bool NetworkTableInstance::WaitForRpcCallQueue(double timeout) {
return ::nt::WaitForRpcCallQueue(m_handle, timeout);
}
inline void NetworkTableInstance::SetNetworkIdentity(std::string_view name) {
::nt::SetNetworkIdentity(m_handle, name);
}
@@ -100,31 +105,21 @@ inline void NetworkTableInstance::StopLocal() {
inline void NetworkTableInstance::StartServer(std::string_view persist_filename,
const char* listen_address,
unsigned int port) {
::nt::StartServer(m_handle, persist_filename, listen_address, port);
unsigned int port3,
unsigned int port4) {
::nt::StartServer(m_handle, persist_filename, listen_address, port3, port4);
}
inline void NetworkTableInstance::StopServer() {
::nt::StopServer(m_handle);
}
inline void NetworkTableInstance::StartClient() {
::nt::StartClient(m_handle);
inline void NetworkTableInstance::StartClient3() {
::nt::StartClient3(m_handle);
}
inline void NetworkTableInstance::StartClient(const char* server_name,
unsigned int port) {
::nt::StartClient(m_handle, server_name, port);
}
inline void NetworkTableInstance::StartClient(
wpi::span<const std::pair<std::string_view, unsigned int>> servers) {
::nt::StartClient(m_handle, servers);
}
inline void NetworkTableInstance::StartClientTeam(unsigned int team,
unsigned int port) {
::nt::StartClientTeam(m_handle, team, port);
inline void NetworkTableInstance::StartClient4() {
::nt::StartClient4(m_handle);
}
inline void NetworkTableInstance::StopClient() {
@@ -154,8 +149,8 @@ inline void NetworkTableInstance::StopDSClient() {
::nt::StopDSClient(m_handle);
}
inline void NetworkTableInstance::SetUpdateRate(double interval) {
::nt::SetUpdateRate(m_handle, interval);
inline void NetworkTableInstance::FlushLocal() const {
::nt::FlushLocal(m_handle);
}
inline void NetworkTableInstance::Flush() const {
@@ -171,28 +166,6 @@ inline bool NetworkTableInstance::IsConnected() const {
return ::nt::IsConnected(m_handle);
}
inline const char* NetworkTableInstance::SavePersistent(
std::string_view filename) const {
return ::nt::SavePersistent(m_handle, filename);
}
inline const char* NetworkTableInstance::LoadPersistent(
std::string_view filename,
std::function<void(size_t line, const char* msg)> warn) {
return ::nt::LoadPersistent(m_handle, filename, warn);
}
inline const char* NetworkTableInstance::SaveEntries(
std::string_view filename, std::string_view prefix) const {
return ::nt::SaveEntries(m_handle, filename, prefix);
}
inline const char* NetworkTableInstance::LoadEntries(
std::string_view filename, std::string_view prefix,
std::function<void(size_t line, const char* msg)> warn) {
return ::nt::LoadEntries(m_handle, filename, prefix, warn);
}
inline NT_DataLogger NetworkTableInstance::StartEntryDataLog(
wpi::log::DataLog& log, std::string_view prefix,
std::string_view logPrefix) {
@@ -223,10 +196,4 @@ inline void NetworkTableInstance::RemoveLogger(NT_Logger logger) {
::nt::RemoveLogger(logger);
}
inline bool NetworkTableInstance::WaitForLoggerQueue(double timeout) {
return ::nt::WaitForLoggerQueue(m_handle, timeout);
}
} // namespace nt
#endif // NTCORE_NETWORKTABLES_NETWORKTABLEINSTANCE_INC_

View File

@@ -2,8 +2,7 @@
// 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.
#ifndef NTCORE_NETWORKTABLES_NETWORKTABLETYPE_H_
#define NTCORE_NETWORKTABLES_NETWORKTABLETYPE_H_
#pragma once
#include "ntcore_c.h"
@@ -22,9 +21,10 @@ enum class NetworkTableType {
kBooleanArray = NT_BOOLEAN_ARRAY,
kDoubleArray = NT_DOUBLE_ARRAY,
kStringArray = NT_STRING_ARRAY,
kRpc = NT_RPC
kInteger = NT_INTEGER,
kFloat = NT_FLOAT,
kIntegerArray = NT_INTEGER_ARRAY,
kFloatArray = NT_FLOAT_ARRAY
};
} // namespace nt
#endif // NTCORE_NETWORKTABLES_NETWORKTABLETYPE_H_

View File

@@ -2,8 +2,7 @@
// 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.
#ifndef NTCORE_NETWORKTABLES_NETWORKTABLEVALUE_H_
#define NTCORE_NETWORKTABLES_NETWORKTABLEVALUE_H_
#pragma once
#include <stdint.h>
@@ -31,8 +30,10 @@ class Value final {
public:
Value();
Value(NT_Type type, uint64_t time, const private_init&);
~Value();
Value(NT_Type type, int64_t time, const private_init&);
Value(NT_Type type, int64_t time, int64_t serverTime, const private_init&);
explicit operator bool() const { return m_val.type != NT_UNASSIGNED; }
/**
* Get the data type.
@@ -49,18 +50,39 @@ class Value final {
const NT_Value& value() const { return m_val; }
/**
* Get the creation time of the value.
* Get the creation time of the value, in local time.
*
* @return The time, in the units returned by nt::Now().
*/
uint64_t last_change() const { return m_val.last_change; }
int64_t last_change() const { return m_val.last_change; }
/**
* Get the creation time of the value.
* Get the creation time of the value, in local time.
*
* @return The time, in the units returned by nt::Now().
*/
uint64_t time() const { return m_val.last_change; }
int64_t time() const { return m_val.last_change; }
/**
* Set the local creation time of the value.
*
* @param time The time.
*/
void SetTime(int64_t time) { m_val.last_change = time; }
/**
* Get the creation time of the value, in server time.
*
* @return The server time.
*/
int64_t server_time() const { return m_val.server_time; }
/**
* Set the creation time of the value, in server time.
*
* @param time The server time.
*/
void SetServerTime(int64_t time) { m_val.server_time = time; }
/**
* @{
@@ -81,6 +103,20 @@ class Value final {
*/
bool IsBoolean() const { return m_val.type == NT_BOOLEAN; }
/**
* Determine if entry value contains an integer.
*
* @return True if the entry value is of integer type.
*/
bool IsInteger() const { return m_val.type == NT_INTEGER; }
/**
* Determine if entry value contains a float.
*
* @return True if the entry value is of float type.
*/
bool IsFloat() const { return m_val.type == NT_FLOAT; }
/**
* Determine if entry value contains a double.
*
@@ -102,13 +138,6 @@ class Value final {
*/
bool IsRaw() const { return m_val.type == NT_RAW; }
/**
* Determine if entry value contains a rpc definition.
*
* @return True if the entry value is of rpc definition type.
*/
bool IsRpc() const { return m_val.type == NT_RPC; }
/**
* Determine if entry value contains a boolean array.
*
@@ -116,6 +145,20 @@ class Value final {
*/
bool IsBooleanArray() const { return m_val.type == NT_BOOLEAN_ARRAY; }
/**
* Determine if entry value contains an integer array.
*
* @return True if the entry value is of integer array type.
*/
bool IsIntegerArray() const { return m_val.type == NT_INTEGER_ARRAY; }
/**
* Determine if entry value contains a float array.
*
* @return True if the entry value is of float array type.
*/
bool IsFloatArray() const { return m_val.type == NT_FLOAT_ARRAY; }
/**
* Determine if entry value contains a double array.
*
@@ -147,6 +190,26 @@ class Value final {
return m_val.data.v_boolean != 0;
}
/**
* Get the entry's integer value.
*
* @return The integer value.
*/
int64_t GetInteger() const {
assert(m_val.type == NT_INTEGER);
return m_val.data.v_int;
}
/**
* Get the entry's float value.
*
* @return The float value.
*/
float GetFloat() const {
assert(m_val.type == NT_FLOAT);
return m_val.data.v_float;
}
/**
* Get the entry's double value.
*
@@ -164,7 +227,7 @@ class Value final {
*/
std::string_view GetString() const {
assert(m_val.type == NT_STRING);
return m_string;
return {m_val.data.v_string.str, m_val.data.v_string.len};
}
/**
@@ -172,19 +235,9 @@ class Value final {
*
* @return The raw value.
*/
std::string_view GetRaw() const {
wpi::span<const uint8_t> GetRaw() const {
assert(m_val.type == NT_RAW);
return m_string;
}
/**
* Get the entry's rpc definition value.
*
* @return The rpc definition value.
*/
std::string_view GetRpc() const {
assert(m_val.type == NT_RPC);
return m_string;
return {m_val.data.v_raw.data, m_val.data.v_raw.size};
}
/**
@@ -197,6 +250,26 @@ class Value final {
return {m_val.data.arr_boolean.arr, m_val.data.arr_boolean.size};
}
/**
* Get the entry's integer array value.
*
* @return The integer array value.
*/
wpi::span<const int64_t> GetIntegerArray() const {
assert(m_val.type == NT_INTEGER_ARRAY);
return {m_val.data.arr_int.arr, m_val.data.arr_int.size};
}
/**
* Get the entry's float array value.
*
* @return The float array value.
*/
wpi::span<const float> GetFloatArray() const {
assert(m_val.type == NT_FLOAT_ARRAY);
return {m_val.data.arr_float.arr, m_val.data.arr_float.size};
}
/**
* Get the entry's double array value.
*
@@ -214,7 +287,7 @@ class Value final {
*/
wpi::span<const std::string> GetStringArray() const {
assert(m_val.type == NT_STRING_ARRAY);
return m_string_array;
return *static_cast<std::vector<std::string>*>(m_storage.get());
}
/** @} */
@@ -232,9 +305,37 @@ class Value final {
* time)
* @return The entry value
*/
static std::shared_ptr<Value> MakeBoolean(bool value, uint64_t time = 0) {
auto val = std::make_shared<Value>(NT_BOOLEAN, time, private_init());
val->m_val.data.v_boolean = value;
static Value MakeBoolean(bool value, int64_t time = 0) {
Value val{NT_BOOLEAN, time, private_init{}};
val.m_val.data.v_boolean = value;
return val;
}
/**
* Creates an integer entry value.
*
* @param value the value
* @param time if nonzero, the creation time to use (instead of the current
* time)
* @return The entry value
*/
static Value MakeInteger(int64_t value, int64_t time = 0) {
Value val{NT_INTEGER, time, private_init{}};
val.m_val.data.v_int = value;
return val;
}
/**
* Creates a float entry value.
*
* @param value the value
* @param time if nonzero, the creation time to use (instead of the current
* time)
* @return The entry value
*/
static Value MakeFloat(float value, int64_t time = 0) {
Value val{NT_FLOAT, time, private_init{}};
val.m_val.data.v_float = value;
return val;
}
@@ -246,9 +347,9 @@ class Value final {
* time)
* @return The entry value
*/
static std::shared_ptr<Value> MakeDouble(double value, uint64_t time = 0) {
auto val = std::make_shared<Value>(NT_DOUBLE, time, private_init());
val->m_val.data.v_double = value;
static Value MakeDouble(double value, int64_t time = 0) {
Value val{NT_DOUBLE, time, private_init{}};
val.m_val.data.v_double = value;
return val;
}
@@ -260,12 +361,12 @@ class Value final {
* time)
* @return The entry value
*/
static std::shared_ptr<Value> MakeString(std::string_view value,
uint64_t time = 0) {
auto val = std::make_shared<Value>(NT_STRING, time, private_init());
val->m_string = value;
val->m_val.data.v_string.str = const_cast<char*>(val->m_string.c_str());
val->m_val.data.v_string.len = val->m_string.size();
static Value MakeString(std::string_view value, int64_t time = 0) {
Value val{NT_STRING, time, private_init{}};
auto data = std::make_shared<std::string>(value);
val.m_val.data.v_string.str = const_cast<char*>(data->c_str());
val.m_val.data.v_string.len = data->size();
val.m_storage = std::move(data);
return val;
}
@@ -279,11 +380,12 @@ class Value final {
*/
template <typename T,
typename std::enable_if<std::is_same<T, std::string>::value>::type>
static std::shared_ptr<Value> MakeString(T&& value, uint64_t time = 0) {
auto val = std::make_shared<Value>(NT_STRING, time, private_init());
val->m_string = std::forward<T>(value);
val->m_val.data.v_string.str = const_cast<char*>(val->m_string.c_str());
val->m_val.data.v_string.len = val->m_string.size();
static Value MakeString(T&& value, int64_t time = 0) {
Value val{NT_STRING, time, private_init{}};
auto data = std::make_shared<std::string>(std::forward(value));
val.m_val.data.v_string.str = const_cast<char*>(data->c_str());
val.m_val.data.v_string.len = data->size();
val.m_storage = std::move(data);
return val;
}
@@ -295,12 +397,13 @@ class Value final {
* time)
* @return The entry value
*/
static std::shared_ptr<Value> MakeRaw(std::string_view value,
uint64_t time = 0) {
auto val = std::make_shared<Value>(NT_RAW, time, private_init());
val->m_string = value;
val->m_val.data.v_raw.str = const_cast<char*>(val->m_string.c_str());
val->m_val.data.v_raw.len = val->m_string.size();
static Value MakeRaw(wpi::span<const uint8_t> value, int64_t time = 0) {
Value val{NT_RAW, time, private_init{}};
auto data =
std::make_shared<std::vector<uint8_t>>(value.begin(), value.end());
val.m_val.data.v_raw.data = const_cast<uint8_t*>(data->data());
val.m_val.data.v_raw.size = data->size();
val.m_storage = std::move(data);
return val;
}
@@ -312,47 +415,14 @@ class Value final {
* time)
* @return The entry value
*/
template <typename T,
typename std::enable_if<std::is_same<T, std::string>::value>::type>
static std::shared_ptr<Value> MakeRaw(T&& value, uint64_t time = 0) {
auto val = std::make_shared<Value>(NT_RAW, time, private_init());
val->m_string = std::forward<T>(value);
val->m_val.data.v_raw.str = const_cast<char*>(val->m_string.c_str());
val->m_val.data.v_raw.len = val->m_string.size();
return val;
}
/**
* Creates a rpc entry value.
*
* @param value the value
* @param time if nonzero, the creation time to use (instead of the current
* time)
* @return The entry value
*/
static std::shared_ptr<Value> MakeRpc(std::string_view value,
uint64_t time = 0) {
auto val = std::make_shared<Value>(NT_RPC, time, private_init());
val->m_string = value;
val->m_val.data.v_raw.str = const_cast<char*>(val->m_string.c_str());
val->m_val.data.v_raw.len = val->m_string.size();
return val;
}
/**
* Creates a rpc entry value.
*
* @param value the value
* @param time if nonzero, the creation time to use (instead of the current
* time)
* @return The entry value
*/
template <typename T>
static std::shared_ptr<Value> MakeRpc(T&& value, uint64_t time = 0) {
auto val = std::make_shared<Value>(NT_RPC, time, private_init());
val->m_string = std::forward<T>(value);
val->m_val.data.v_raw.str = const_cast<char*>(val->m_string.c_str());
val->m_val.data.v_raw.len = val->m_string.size();
template <typename T, typename std::enable_if<
std::is_same<T, std::vector<uint8_t>>::value>::type>
static Value MakeRaw(T&& value, int64_t time = 0) {
Value val{NT_RAW, time, private_init{}};
auto data = std::make_shared<std::vector<uint8_t>>(std::forward(value));
val.m_val.data.v_raw.data = const_cast<uint8_t*>(data->data());
val.m_val.data.v_raw.size = data->size();
val.m_storage = std::move(data);
return val;
}
@@ -364,8 +434,7 @@ class Value final {
* time)
* @return The entry value
*/
static std::shared_ptr<Value> MakeBooleanArray(wpi::span<const bool> value,
uint64_t time = 0);
static Value MakeBooleanArray(wpi::span<const bool> value, int64_t time = 0);
/**
* Creates a boolean array entry value.
@@ -375,8 +444,8 @@ class Value final {
* time)
* @return The entry value
*/
static std::shared_ptr<Value> MakeBooleanArray(
std::initializer_list<bool> value, uint64_t time = 0) {
static Value MakeBooleanArray(std::initializer_list<bool> value,
int64_t time = 0) {
return MakeBooleanArray(wpi::span(value.begin(), value.end()), time);
}
@@ -388,8 +457,7 @@ class Value final {
* time)
* @return The entry value
*/
static std::shared_ptr<Value> MakeBooleanArray(wpi::span<const int> value,
uint64_t time = 0);
static Value MakeBooleanArray(wpi::span<const int> value, int64_t time = 0);
/**
* Creates a boolean array entry value.
@@ -399,11 +467,58 @@ class Value final {
* time)
* @return The entry value
*/
static std::shared_ptr<Value> MakeBooleanArray(
std::initializer_list<int> value, uint64_t time = 0) {
static Value MakeBooleanArray(std::initializer_list<int> value,
int64_t time = 0) {
return MakeBooleanArray(wpi::span(value.begin(), value.end()), time);
}
/**
* Creates an integer array entry value.
*
* @param value the value
* @param time if nonzero, the creation time to use (instead of the current
* time)
* @return The entry value
*/
static Value MakeIntegerArray(wpi::span<const int64_t> value,
int64_t time = 0);
/**
* Creates an integer array entry value.
*
* @param value the value
* @param time if nonzero, the creation time to use (instead of the current
* time)
* @return The entry value
*/
static Value MakeIntegerArray(std::initializer_list<int64_t> value,
int64_t time = 0) {
return MakeIntegerArray(wpi::span(value.begin(), value.end()), time);
}
/**
* Creates a float array entry value.
*
* @param value the value
* @param time if nonzero, the creation time to use (instead of the current
* time)
* @return The entry value
*/
static Value MakeFloatArray(wpi::span<const float> value, int64_t time = 0);
/**
* Creates a float array entry value.
*
* @param value the value
* @param time if nonzero, the creation time to use (instead of the current
* time)
* @return The entry value
*/
static Value MakeFloatArray(std::initializer_list<float> value,
int64_t time = 0) {
return MakeFloatArray(wpi::span(value.begin(), value.end()), time);
}
/**
* Creates a double array entry value.
*
@@ -412,8 +527,7 @@ class Value final {
* time)
* @return The entry value
*/
static std::shared_ptr<Value> MakeDoubleArray(wpi::span<const double> value,
uint64_t time = 0);
static Value MakeDoubleArray(wpi::span<const double> value, int64_t time = 0);
/**
* Creates a double array entry value.
@@ -423,8 +537,8 @@ class Value final {
* time)
* @return The entry value
*/
static std::shared_ptr<Value> MakeDoubleArray(
std::initializer_list<double> value, uint64_t time = 0) {
static Value MakeDoubleArray(std::initializer_list<double> value,
int64_t time = 0) {
return MakeDoubleArray(wpi::span(value.begin(), value.end()), time);
}
@@ -436,8 +550,8 @@ class Value final {
* time)
* @return The entry value
*/
static std::shared_ptr<Value> MakeStringArray(
wpi::span<const std::string> value, uint64_t time = 0);
static Value MakeStringArray(wpi::span<const std::string> value,
int64_t time = 0);
/**
* Creates a string array entry value.
@@ -447,8 +561,8 @@ class Value final {
* time)
* @return The entry value
*/
static std::shared_ptr<Value> MakeStringArray(
std::initializer_list<std::string> value, uint64_t time = 0) {
static Value MakeStringArray(std::initializer_list<std::string> value,
int64_t time = 0) {
return MakeStringArray(wpi::span(value.begin(), value.end()), time);
}
@@ -462,19 +576,16 @@ class Value final {
*
* @note This function moves the values out of the vector.
*/
static std::shared_ptr<Value> MakeStringArray(
std::vector<std::string>&& value, uint64_t time = 0);
static Value MakeStringArray(std::vector<std::string>&& value,
int64_t time = 0);
/** @} */
Value(const Value&) = delete;
Value& operator=(const Value&) = delete;
friend bool operator==(const Value& lhs, const Value& rhs);
private:
NT_Value m_val;
std::string m_string;
std::vector<std::string> m_string_array;
std::shared_ptr<void> m_storage;
};
bool operator==(const Value& lhs, const Value& rhs);
@@ -489,5 +600,3 @@ inline bool operator!=(const Value& lhs, const Value& rhs) {
using NetworkTableValue = Value;
} // namespace nt
#endif // NTCORE_NETWORKTABLES_NETWORKTABLEVALUE_H_

View File

@@ -1,106 +0,0 @@
// 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.
#ifndef NTCORE_NETWORKTABLES_RPCCALL_H_
#define NTCORE_NETWORKTABLES_RPCCALL_H_
#include <string>
#include <utility>
#include "ntcore_c.h"
namespace nt {
class NetworkTableEntry;
/**
* NetworkTables Remote Procedure Call
* @ingroup ntcore_cpp_api
*/
class RpcCall final {
public:
/**
* Construct invalid instance.
*/
RpcCall() = default;
/**
* Construct from native handles.
*
* @param entry Entry handle
* @param call Call handle
*/
RpcCall(NT_Entry entry, NT_RpcCall call) : m_entry(entry), m_call(call) {}
RpcCall(RpcCall&& other) noexcept;
RpcCall(const RpcCall&) = delete;
RpcCall& operator=(const RpcCall&) = delete;
/**
* Destructor. Cancels the result if no other action taken.
*/
~RpcCall();
/**
* Determines if the native handle is valid.
*
* @return True if the native handle is valid, false otherwise.
*/
explicit operator bool() const { return m_call != 0; }
/**
* Get the RPC entry.
*
* @return NetworkTableEntry for the RPC.
*/
NetworkTableEntry GetEntry() const;
/**
* Get the call native handle.
*
* @return Native handle.
*/
NT_RpcCall GetCall() const { return m_call; }
/**
* Get the result (return value). This function blocks until
* the result is received.
*
* @param result received result (output)
* @return False on error, true otherwise.
*/
bool GetResult(std::string* result);
/**
* Get the result (return value). This function blocks until
* the result is received or it times out.
*
* @param result received result (output)
* @param timeout timeout, in seconds
* @param timed_out true if the timeout period elapsed (output)
* @return False on error or timeout, true otherwise.
*/
bool GetResult(std::string* result, double timeout, bool* timed_out);
/**
* Ignore the result. This function is non-blocking.
*/
void CancelResult();
friend void swap(RpcCall& first, RpcCall& second) {
using std::swap;
swap(first.m_entry, second.m_entry);
swap(first.m_call, second.m_call);
}
private:
NT_Entry m_entry{0};
NT_RpcCall m_call{0};
};
} // namespace nt
#include "networktables/RpcCall.inc"
#endif // NTCORE_NETWORKTABLES_RPCCALL_H_

View File

@@ -1,51 +0,0 @@
// 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.
#ifndef NTCORE_NETWORKTABLES_RPCCALL_INC_
#define NTCORE_NETWORKTABLES_RPCCALL_INC_
#include <string>
#include <utility>
#include "networktables/RpcCall.h"
#include "ntcore_cpp.h"
namespace nt {
inline RpcCall::RpcCall(RpcCall&& other) noexcept : RpcCall() {
swap(*this, other);
}
inline RpcCall::~RpcCall() {
// automatically cancel result if user didn't request it
if (m_call != 0) {
CancelResult();
}
}
inline bool RpcCall::GetResult(std::string* result) {
if (GetRpcResult(m_entry, m_call, result)) {
m_call = 0;
return true;
}
return false;
}
inline bool RpcCall::GetResult(std::string* result, double timeout,
bool* timed_out) {
if (GetRpcResult(m_entry, m_call, result, timeout, timed_out)) {
m_call = 0;
return true;
}
return false;
}
inline void RpcCall::CancelResult() {
CancelRpcResult(m_entry, m_call);
m_call = 0;
}
} // namespace nt
#endif // NTCORE_NETWORKTABLES_RPCCALL_INC_

View File

@@ -1,38 +0,0 @@
// 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.
#ifndef NTCORE_NETWORKTABLES_TABLEENTRYLISTENER_H_
#define NTCORE_NETWORKTABLES_TABLEENTRYLISTENER_H_
#include <functional>
#include <memory>
#include <string_view>
namespace nt {
class NetworkTable;
class NetworkTableEntry;
class Value;
/**
* A listener that listens to changes in values in a NetworkTable.
*
* Called when a key-value pair is changed in a NetworkTable.
*
* @param table the table the key-value pair exists in
* @param key the key associated with the value that changed
* @param entry the entry associated with the value that changed
* @param value the new value
* @param flags update flags; for example, EntryListenerFlags.kNew if the key
* did not previously exist
*
* @ingroup ntcore_cpp_api
*/
using TableEntryListener = std::function<void(
NetworkTable* table, std::string_view name, NetworkTableEntry entry,
std::shared_ptr<Value> value, int flags)>;
} // namespace nt
#endif // NTCORE_NETWORKTABLES_TABLEENTRYLISTENER_H_

View File

@@ -1,33 +0,0 @@
// 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.
#ifndef NTCORE_NETWORKTABLES_TABLELISTENER_H_
#define NTCORE_NETWORKTABLES_TABLELISTENER_H_
#include <functional>
#include <memory>
#include <string_view>
namespace nt {
class NetworkTable;
/**
* A listener that listens to new sub-tables in a NetworkTable.
*
* Called when a new table is created.
*
* @param parent the parent of the table
* @param name the name of the new table
* @param table the new table
*
* @ingroup ntcore_cpp_api
*/
using TableListener =
std::function<void(NetworkTable* parent, std::string_view name,
std::shared_ptr<NetworkTable> table)>;
} // namespace nt
#endif // NTCORE_NETWORKTABLES_TABLELISTENER_H_

View File

@@ -0,0 +1,384 @@
// 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 <stdint.h>
#include <string>
#include <string_view>
#include <utility>
#include <vector>
#include "networktables/NetworkTableType.h"
#include "ntcore_c.h"
#include "ntcore_cpp.h"
namespace wpi {
class json;
} // namespace wpi
namespace nt {
class GenericEntry;
class GenericPublisher;
class GenericSubscriber;
class NetworkTableInstance;
/** NetworkTables Topic. */
class Topic {
public:
Topic() = default;
explicit Topic(NT_Topic handle) : m_handle{handle} {}
/**
* Determines if the native handle is valid.
*
* @return True if the native handle is valid, false otherwise.
*/
explicit operator bool() const { return m_handle != 0; }
/**
* Gets the native handle for the topic.
*
* @return Native handle
*/
NT_Topic GetHandle() const { return m_handle; }
/**
* Gets the instance for the topic.
*
* @return Instance
*/
NetworkTableInstance GetInstance() const;
/**
* Gets the name of the topic.
*
* @return the topic's name
*/
std::string GetName() const;
/**
* Gets the type of the topic.
*
* @return the topic's type
*/
NetworkTableType GetType() const;
/**
* Gets the type string of the topic. This may have more information
* than the numeric type (especially for raw values).
*
* @return the topic's type
*/
std::string GetTypeString() const;
/**
* Make value persistent through server restarts.
*
* @param persistent True for persistent, false for not persistent.
*/
void SetPersistent(bool persistent);
/**
* Returns whether the value is persistent through server restarts.
*
* @return True if the value is persistent.
*/
bool IsPersistent() const;
/**
* Make the server retain the topic even when there are no publishers.
*
* @param retained True for retained, false for not retained.
*/
void SetRetained(bool retained);
/**
* Returns whether the topic is retained by server when there are no
* publishers.
*
* @return True if the topic is retained.
*/
bool IsRetained() const;
/**
* Determines if the topic is currently being published.
*
* @return True if the topic exists, false otherwise.
*/
bool Exists() const;
/**
* Gets the current value of a property (as a JSON object).
*
* @param name property name
* @return JSON object; null object if the property does not exist.
*/
wpi::json GetProperty(std::string_view name) const;
/**
* Sets a property value.
*
* @param name property name
* @param value property value
*/
void SetProperty(std::string_view name, const wpi::json& value);
/**
* Deletes a property. Has no effect if the property does not exist.
*
* @param name property name
*/
void DeleteProperty(std::string_view name);
/**
* Gets all topic properties as a JSON object. Each key in the object
* is the property name, and the corresponding value is the property value.
*
* @return JSON object
*/
wpi::json GetProperties() const;
/**
* Updates multiple topic properties. Each key in the passed-in object is
* the name of the property to add/update, and the corresponding value is the
* property value to set for that property. Null values result in deletion
* of the corresponding property.
*
* @param properties JSON object with keys to add/update/delete
*/
void SetProperties(const wpi::json& properties);
/**
* Gets combined information about the topic.
*
* @return Topic information
*/
TopicInfo GetInfo() const;
/**
* Create a new subscriber to the topic.
*
* <p>The subscriber is only active as long as the returned object
* is not destroyed.
*
* @param options subscribe options
* @return subscriber
*/
[[nodiscard]] GenericSubscriber GenericSubscribe(
wpi::span<const PubSubOption> options = {});
/**
* Create a new subscriber to the topic.
*
* <p>The subscriber is only active as long as the returned object
* is not destroyed.
*
* @note Subscribers that do not match the published data type do not return
* any values. To determine if the data type matches, use the appropriate
* Topic functions.
*
* @param typeString type string
* @param options subscribe options
* @return subscriber
*/
[[nodiscard]] GenericSubscriber GenericSubscribe(
std::string_view typeString, wpi::span<const PubSubOption> options = {});
/**
* Create a new publisher to the topic.
*
* The publisher is only active as long as the returned object
* is not destroyed.
*
* @note It is not possible to publish two different data types to the same
* topic. Conflicts between publishers are typically resolved by the
* server on a first-come, first-served basis. Any published values that
* do not match the topic's data type are dropped (ignored). To determine
* if the data type matches, use the appropriate Topic functions.
*
* @param typeString type string
* @param options publish options
* @return publisher
*/
[[nodiscard]] GenericPublisher GenericPublish(
std::string_view typeString, wpi::span<const PubSubOption> options = {});
/**
* Create a new publisher to the topic, with type string and initial
* properties.
*
* The publisher is only active as long as the returned object
* is not destroyed.
*
* @note It is not possible to publish two different data types to the same
* topic. Conflicts between publishers are typically resolved by the
* server on a first-come, first-served basis. Any published values that
* do not match the topic's data type are dropped (ignored). To determine
* if the data type matches, use the appropriate Topic functions.
*
* @param typeString type string
* @param properties JSON properties
* @param options publish options
* @return publisher
*/
[[nodiscard]] GenericPublisher GenericPublishEx(
std::string_view typeString, const wpi::json& properties,
wpi::span<const PubSubOption> options = {});
/**
* Create a new generic entry for the topic.
*
* Entries act as a combination of a subscriber and a weak publisher. The
* subscriber is active as long as the entry is not destroyed. The publisher
* is created when the entry is first written to, and remains active until
* either Unpublish() is called or the entry is destroyed.
*
* @note It is not possible to use two different data types with the same
* topic. Conflicts between publishers are typically resolved by the
* server on a first-come, first-served basis. Any published values that
* do not match the topic's data type are dropped (ignored), and the entry
* will show no new values if the data type does not match. To determine
* if the data type matches, use the appropriate Topic functions.
*
* @param options publish and/or subscribe options
* @return entry
*/
[[nodiscard]] GenericEntry GetGenericEntry(
wpi::span<const PubSubOption> options = {});
/**
* Create a new generic entry for the topic.
*
* Entries act as a combination of a subscriber and a weak publisher. The
* subscriber is active as long as the entry is not destroyed. The publisher
* is created when the entry is first written to, and remains active until
* either Unpublish() is called or the entry is destroyed.
*
* @note It is not possible to use two different data types with the same
* topic. Conflicts between publishers are typically resolved by the
* server on a first-come, first-served basis. Any published values that
* do not match the topic's data type are dropped (ignored), and the entry
* will show no new values if the data type does not match. To determine
* if the data type matches, use the appropriate Topic functions.
*
* @param typeString type string
* @param options publish and/or subscribe options
* @return entry
*/
[[nodiscard]] GenericEntry GetGenericEntry(
std::string_view typeString, wpi::span<const PubSubOption> options = {});
/**
* Equality operator. Returns true if both instances refer to the same
* native handle.
*/
bool operator==(const Topic& oth) const { return m_handle == oth.m_handle; }
/** Inequality operator. */
bool operator!=(const Topic& oth) const { return !(*this == oth); }
protected:
NT_Topic m_handle{0};
};
/** NetworkTables subscriber. */
class Subscriber {
public:
virtual ~Subscriber();
Subscriber(const Subscriber&) = delete;
Subscriber& operator=(const Subscriber&) = delete;
Subscriber(Subscriber&&);
Subscriber& operator=(Subscriber&&);
/**
* Determines if the native handle is valid.
*
* @return True if the native handle is valid, false otherwise.
*/
explicit operator bool() const { return m_subHandle != 0; }
/**
* Gets the native handle for the subscriber.
*
* @return Native handle
*/
NT_Subscriber GetHandle() const { return m_subHandle; }
/**
* Determines if the topic is currently being published.
*
* @return True if the topic exists, false otherwise.
*/
bool Exists() const;
/**
* Gets the last time the value was changed.
* Note: this is not atomic with Get(); use GetAtomic() to get
* both the value and last change as an atomic operation.
*
* @return Topic last change time
*/
int64_t GetLastChange() const;
/**
* Gets the subscribed-to topic.
*
* @return Topic
*/
Topic GetTopic() const;
protected:
Subscriber() = default;
explicit Subscriber(NT_Subscriber handle) : m_subHandle{handle} {}
NT_Subscriber m_subHandle{0};
};
/** NetworkTables pubscriber. */
class Publisher {
public:
virtual ~Publisher();
Publisher(const Publisher&) = delete;
Publisher& operator=(const Publisher&) = delete;
Publisher(Publisher&&);
Publisher& operator=(Publisher&&);
/**
* Determines if the native handle is valid.
*
* @return True if the native handle is valid, false otherwise.
*/
explicit operator bool() const { return m_pubHandle != 0; }
/**
* Gets the native handle for the publisher.
*
* @return Native handle
*/
NT_Publisher GetHandle() const { return m_pubHandle; }
/**
* Gets the published-to topic.
*
* @return Topic
*/
Topic GetTopic() const;
protected:
Publisher() = default;
explicit Publisher(NT_Publisher handle) : m_pubHandle{handle} {}
NT_Publisher m_pubHandle{0};
};
} // namespace nt
#include "networktables/Topic.inc"

View File

@@ -0,0 +1,109 @@
// 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 <string>
#include "networktables/NetworkTableInstance.h"
#include "networktables/NetworkTableType.h"
#include "networktables/Topic.h"
#include "ntcore_c.h"
#include "ntcore_cpp.h"
namespace nt {
inline NetworkTableInstance Topic::GetInstance() const {
return NetworkTableInstance{GetInstanceFromHandle(m_handle)};
}
inline std::string Topic::GetName() const {
return ::nt::GetTopicName(m_handle);
}
inline NetworkTableType Topic::GetType() const {
return static_cast<NetworkTableType>(::nt::GetTopicType(m_handle));
}
inline std::string Topic::GetTypeString() const {
return ::nt::GetTopicTypeString(m_handle);
}
inline void Topic::SetPersistent(bool persistent) {
::nt::SetTopicPersistent(m_handle, persistent);
}
inline bool Topic::IsPersistent() const {
return ::nt::GetTopicPersistent(m_handle);
}
inline void Topic::SetRetained(bool retained) {
::nt::SetTopicRetained(m_handle, retained);
}
inline bool Topic::IsRetained() const {
return ::nt::GetTopicRetained(m_handle);
}
inline bool Topic::Exists() const {
return nt::GetTopicExists(m_handle);
}
inline void Topic::DeleteProperty(std::string_view name) {
::nt::DeleteTopicProperty(m_handle, name);
}
inline void Topic::SetProperties(const wpi::json& properties) {
::nt::SetTopicProperties(m_handle, properties);
}
inline TopicInfo Topic::GetInfo() const {
return ::nt::GetTopicInfo(m_handle);
}
inline Subscriber::~Subscriber() {
::nt::Release(m_subHandle);
}
inline Subscriber::Subscriber(Subscriber&& rhs) : m_subHandle{rhs.m_subHandle} {
rhs.m_subHandle = 0;
}
inline Subscriber& Subscriber::operator=(Subscriber&& rhs) {
m_subHandle = rhs.m_subHandle;
rhs.m_subHandle = 0;
return *this;
}
inline bool Subscriber::Exists() const {
return nt::GetTopicExists(m_subHandle);
}
inline int64_t Subscriber::GetLastChange() const {
return ::nt::GetEntryLastChange(m_subHandle);
}
inline Topic Subscriber::GetTopic() const {
return Topic{::nt::GetTopicFromHandle(m_subHandle)};
}
inline Publisher::~Publisher() {
::nt::Release(m_pubHandle);
}
inline Publisher::Publisher(Publisher&& rhs) : m_pubHandle{rhs.m_pubHandle} {
rhs.m_pubHandle = 0;
}
inline Publisher& Publisher::operator=(Publisher&& rhs) {
m_pubHandle = rhs.m_pubHandle;
rhs.m_pubHandle = 0;
return *this;
}
inline Topic Publisher::GetTopic() const {
return Topic{::nt::GetTopicFromHandle(m_pubHandle)};
}
} // namespace nt

View File

@@ -0,0 +1,246 @@
// 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 <string_view>
#include <vector>
#include <wpi/span.h>
#include "ntcore_cpp.h"
namespace nt {
class MultiSubscriber;
class NetworkTableEntry;
class NetworkTableInstance;
class Subscriber;
class Topic;
/**
* Flag values for use with topic listeners.
*
* The flags are a bitmask and must be OR'ed together to indicate the
* combination of events desired to be received.
*
* The constants kPublish, kUnpublish, and kProperties represent different
* events that can occur to entries.
*
* @ingroup ntcore_cpp_api
*/
struct TopicListenerFlags {
TopicListenerFlags() = delete;
/**
* Initial listener addition.
* Set this flag to receive immediate notification of entries matching the
* flag criteria (generally only useful when combined with kPublish).
*/
static constexpr unsigned int kImmediate = NT_TOPIC_NOTIFY_IMMEDIATE;
/**
* Newly published topic.
*
* Set this flag to receive a notification when a topic is initially
* published.
*/
static constexpr unsigned int kPublish = NT_TOPIC_NOTIFY_PUBLISH;
/**
* Topic has no more publishers.
*
* Set this flag to receive a notification when a topic has no more
* publishers.
*/
static constexpr unsigned int kUnpublish = NT_TOPIC_NOTIFY_UNPUBLISH;
/**
* Topic's properties changed.
*
* Set this flag to receive a notification when an topic's properties change.
*/
static constexpr unsigned int kProperties = NT_TOPIC_NOTIFY_PROPERTIES;
};
/**
* Topic change listener. This calls back to a callback function when a topic
* change matching the specified mask occurs.
*/
class TopicListener final {
public:
TopicListener() = default;
/**
* Create a listener for changes to topics with names that start with any of
* the given prefixes.
*
* @param inst Instance
* @param prefixes Topic name string prefixes
* @param mask Bitmask of TopicListenerFlags values
* @param listener Listener function
*/
TopicListener(NetworkTableInstance inst,
wpi::span<const std::string_view> prefixes, unsigned int mask,
std::function<void(const TopicNotification&)> listener);
/**
* Create a listener for changes on a particular topic.
*
* @param topic Topic
* @param mask Bitmask of TopicListenerFlags values
* @param listener Listener function
*/
TopicListener(Topic topic, unsigned int mask,
std::function<void(const TopicNotification&)> listener);
/**
* Create a listener for topic changes on a subscriber.
*
* @param subscriber Subscriber
* @param mask Bitmask of TopicListenerFlags values
* @param listener Listener function
*/
TopicListener(const Subscriber& subscriber, unsigned int mask,
std::function<void(const TopicNotification&)> listener);
/**
* Create a listener for topic changes on a subscriber.
*
* @param subscriber Subscriber
* @param mask Bitmask of TopicListenerFlags values
* @param listener Listener function
*/
TopicListener(const MultiSubscriber& subscriber, unsigned int mask,
std::function<void(const TopicNotification&)> listener);
/**
* Create a listener for topic changes on an entry.
*
* @param entry Entry
* @param mask Bitmask of TopicListenerFlags values
* @param listener Listener function
*/
TopicListener(const NetworkTableEntry& entry, unsigned int mask,
std::function<void(const TopicNotification&)> listener);
TopicListener(const TopicListener&) = delete;
TopicListener& operator=(const TopicListener&) = delete;
TopicListener(TopicListener&& rhs);
TopicListener& operator=(TopicListener&& rhs);
~TopicListener();
explicit operator bool() const { return m_handle != 0; }
/**
* Gets the native handle.
*
* @return Handle
*/
NT_TopicListener GetHandle() const { return m_handle; }
private:
NT_TopicListener m_handle{0};
};
/**
* Topic change listener. This queues topic change events matching the specified
* mask. Code using the listener must periodically call readQueue() to read the
* events.
*/
class TopicListenerPoller final {
public:
TopicListenerPoller() = default;
/**
* Construct a topic listener poller.
*
* @param inst Instance
*/
explicit TopicListenerPoller(NetworkTableInstance inst);
TopicListenerPoller(const TopicListenerPoller&) = delete;
TopicListenerPoller& operator=(const TopicListenerPoller&) = delete;
TopicListenerPoller(TopicListenerPoller&& rhs);
TopicListenerPoller& operator=(TopicListenerPoller&& rhs);
~TopicListenerPoller();
explicit operator bool() const { return m_handle != 0; }
/**
* Gets the native handle.
*
* @return Handle
*/
NT_TopicListenerPoller GetHandle() const { return m_handle; }
/**
* Start listening to changes to a particular topic.
*
* @param prefixes Topic name string prefixes
* @param mask Bitmask of TopicListenerFlags values
* @return Listener handle
*/
NT_TopicListener Add(wpi::span<const std::string_view> prefixes,
unsigned int mask);
/**
* Start listening to topic changes for topics with names that start with any
* of the given prefixes.
*
* @param topic Topic
* @param mask Bitmask of TopicListenerFlags values
* @return Listener handle
*/
NT_TopicListener Add(Topic topic, unsigned int mask);
/**
* Start listening to topic changes on a subscriber.
*
* @param subscriber Subscriber
* @param mask Bitmask of TopicListenerFlags values
* @return Listener handle
*/
NT_ValueListener Add(const Subscriber& subscriber, unsigned int mask);
/**
* Start listening to topic changes on a subscriber.
*
* @param subscriber Subscriber
* @param mask Bitmask of TopicListenerFlags values
* @return Listener handle
*/
NT_ValueListener Add(const MultiSubscriber& subscriber, unsigned int mask);
/**
* Start listening to topic changes on an entry.
*
* @param entry Entry
* @param mask Bitmask of TopicListenerFlags values
* @return Listener handle
*/
NT_ValueListener Add(const NetworkTableEntry& entry, unsigned int mask);
/**
* Remove a listener.
*
* @param listener Listener handle
*/
void Remove(NT_TopicListener listener);
/**
* Read topic notifications.
*
* @return Topic notifications since the previous call to readQueue()
*/
std::vector<TopicNotification> ReadQueue();
private:
NT_TopicListenerPoller m_handle{0};
};
} // namespace nt
#include "TopicListener.inc"

View File

@@ -0,0 +1,116 @@
// 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 <string_view>
#include <utility>
#include <vector>
#include <wpi/span.h>
#include "networktables/MultiSubscriber.h"
#include "networktables/NetworkTableEntry.h"
#include "networktables/NetworkTableInstance.h"
#include "networktables/Topic.h"
#include "networktables/TopicListener.h"
#include "ntcore_cpp.h"
namespace nt {
inline TopicListener::TopicListener(
NetworkTableInstance inst, wpi::span<const std::string_view> prefixes,
unsigned int mask, std::function<void(const TopicNotification&)> listener)
: m_handle{AddTopicListener(inst.GetHandle(), prefixes, mask, listener)} {}
inline TopicListener::TopicListener(
Topic topic, unsigned int mask,
std::function<void(const TopicNotification&)> listener)
: m_handle{AddTopicListener(topic.GetHandle(), mask, listener)} {}
inline TopicListener::TopicListener(
const Subscriber& subscriber, unsigned int mask,
std::function<void(const TopicNotification&)> listener)
: m_handle{AddTopicListener(subscriber.GetHandle(), mask, listener)} {}
inline TopicListener::TopicListener(
const MultiSubscriber& subscriber, unsigned int mask,
std::function<void(const TopicNotification&)> listener)
: m_handle{AddTopicListener(subscriber.GetHandle(), mask, listener)} {}
inline TopicListener::TopicListener(
const NetworkTableEntry& entry, unsigned int mask,
std::function<void(const TopicNotification&)> listener)
: m_handle{AddTopicListener(entry.GetHandle(), mask, listener)} {}
inline TopicListener::TopicListener(TopicListener&& rhs)
: m_handle(rhs.m_handle) {
rhs.m_handle = 0;
}
inline TopicListener& TopicListener::operator=(TopicListener&& rhs) {
std::swap(m_handle, rhs.m_handle);
return *this;
}
inline TopicListener::~TopicListener() {
if (m_handle != 0) {
nt::RemoveTopicListener(m_handle);
}
}
inline TopicListenerPoller::TopicListenerPoller(NetworkTableInstance inst)
: m_handle(nt::CreateTopicListenerPoller(inst.GetHandle())) {}
inline TopicListenerPoller::TopicListenerPoller(TopicListenerPoller&& rhs)
: m_handle(rhs.m_handle) {
rhs.m_handle = 0;
}
inline TopicListenerPoller& TopicListenerPoller::operator=(
TopicListenerPoller&& rhs) {
std::swap(m_handle, rhs.m_handle);
return *this;
}
inline TopicListenerPoller::~TopicListenerPoller() {
if (m_handle != 0) {
nt::DestroyTopicListenerPoller(m_handle);
}
}
inline NT_TopicListener TopicListenerPoller::Add(
wpi::span<const std::string_view> prefixes, unsigned int mask) {
return nt::AddPolledTopicListener(m_handle, prefixes, mask);
}
inline NT_TopicListener TopicListenerPoller::Add(Topic topic,
unsigned int mask) {
return nt::AddPolledTopicListener(m_handle, topic.GetHandle(), mask);
}
inline NT_TopicListener TopicListenerPoller::Add(const Subscriber& subscriber,
unsigned int mask) {
return nt::AddPolledTopicListener(m_handle, subscriber.GetHandle(), mask);
}
inline NT_TopicListener TopicListenerPoller::Add(
const MultiSubscriber& subscriber, unsigned int mask) {
return nt::AddPolledTopicListener(m_handle, subscriber.GetHandle(), mask);
}
inline NT_TopicListener TopicListenerPoller::Add(const NetworkTableEntry& entry,
unsigned int mask) {
return nt::AddPolledTopicListener(m_handle, entry.GetHandle(), mask);
}
inline void TopicListenerPoller::Remove(NT_TopicListener listener) {
nt::RemoveTopicListener(listener);
}
inline std::vector<TopicNotification> TopicListenerPoller::ReadQueue() {
return nt::ReadTopicListenerQueue(m_handle);
}
} // namespace nt

View File

@@ -0,0 +1,204 @@
// 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 <vector>
#include "ntcore_cpp.h"
namespace nt {
class MultiSubscriber;
class NetworkTableEntry;
class NetworkTableInstance;
class Subscriber;
/**
* Flag values for use with value listeners.
*
* The flags are a bitmask and must be OR'ed together to indicate the
* combination of events desired to be received.
*
* By default, notifications are only generated for remote changes occurring
* after the listener is created. The constants kImmediate and kLocal are
* modifiers that cause notifications to be generated at other times.
*/
struct ValueListenerFlags {
ValueListenerFlags() = delete;
/**
* Initial listener addition.
*
* Set this flag to receive immediate notification of the current value.
*/
static constexpr unsigned int kImmediate = NT_VALUE_NOTIFY_IMMEDIATE;
/**
* Changed locally.
*
* Set this flag to receive notification of both local changes and changes
* coming from remote nodes. By default, notifications are only generated for
* remote changes.
*/
static constexpr unsigned int kLocal = NT_VALUE_NOTIFY_LOCAL;
};
/**
* Value change listener. This calls back to a callback function when a value
* change matching the specified mask occurs.
*/
class ValueListener final {
public:
ValueListener() = default;
/**
* Create a listener for value changes on a subscriber.
*
* @param subscriber Subscriber
* @param mask Bitmask of ValueListenerFlags values
* @param listener Listener function
*/
ValueListener(const Subscriber& subscriber, unsigned int mask,
std::function<void(const ValueNotification&)> listener);
/**
* Create a listener for value changes on a subscriber.
*
* @param subscriber Subscriber
* @param mask Bitmask of ValueListenerFlags values
* @param listener Listener function
*/
ValueListener(const MultiSubscriber& subscriber, unsigned int mask,
std::function<void(const ValueNotification&)> listener);
/**
* Create a listener for value changes on an entry.
*
* @param entry Entry
* @param mask Bitmask of ValueListenerFlags values
* @param listener Listener function
*/
ValueListener(const NetworkTableEntry& entry, unsigned int mask,
std::function<void(const ValueNotification&)> listener);
/**
* Create a listener for value changes on a subscriber/entry handle.
*
* @param subentry Subscriber/entry handle
* @param mask Bitmask of ValueListenerFlags values
* @param listener Listener function
*/
ValueListener(NT_Handle subentry, unsigned int mask,
std::function<void(const ValueNotification&)> listener);
ValueListener(const ValueListener&) = delete;
ValueListener& operator=(const ValueListener&) = delete;
ValueListener(ValueListener&& rhs);
ValueListener& operator=(ValueListener&& rhs);
~ValueListener();
explicit operator bool() const { return m_handle != 0; }
/**
* Gets the native handle.
*
* @return Handle
*/
NT_ValueListener GetHandle() const { return m_handle; }
private:
NT_ValueListener m_handle{0};
};
/**
* Value change listener. This queues value change events matching the specified
* mask. Code using the listener must periodically call readQueue() to read the
* events.
*/
class ValueListenerPoller final {
public:
ValueListenerPoller();
/**
* Construct a value listener poller.
*
* @param inst Instance
*/
explicit ValueListenerPoller(NetworkTableInstance inst);
ValueListenerPoller(const ValueListenerPoller&) = delete;
ValueListenerPoller& operator=(const ValueListenerPoller&) = delete;
ValueListenerPoller(ValueListenerPoller&& rhs);
ValueListenerPoller& operator=(ValueListenerPoller&& rhs);
~ValueListenerPoller();
explicit operator bool() const { return m_handle != 0; }
/**
* Gets the native handle.
*
* @return Handle
*/
NT_ValueListenerPoller GetHandle() const { return m_handle; }
/**
* Start listening to value changes on a subscriber.
*
* @param subscriber Subscriber
* @param mask Bitmask of ValueListenerFlags values
* @return Listener handle
*/
NT_ValueListener Add(const Subscriber& subscriber, unsigned int mask);
/**
* Start listening to value changes on a subscriber.
*
* @param subscriber Subscriber
* @param mask Bitmask of ValueListenerFlags values
* @return Listener handle
*/
NT_ValueListener Add(const MultiSubscriber& subscriber, unsigned int mask);
/**
* Start listening to value changes on an entry.
*
* @param entry Entry
* @param mask Bitmask of ValueListenerFlags values
* @return Listener handle
*/
NT_ValueListener Add(const NetworkTableEntry& entry, unsigned int mask);
/**
* Start listening to value changes on a subscriber/entry handle.
*
* @param subentry Subscriber/entry handle
* @param mask Bitmask of ValueListenerFlags values
* @return Listener handle
*/
NT_ValueListener Add(NT_Handle subentry, unsigned int mask);
/**
* Remove a listener.
*
* @param listener Listener handle
*/
void Remove(NT_ValueListener listener);
/**
* Reads value listener queue (all value changes since last call).
*
* @param poller poller handle
* @return Array of value notifications.
*/
std::vector<ValueNotification> ReadQueue();
private:
NT_ValueListenerPoller m_handle;
};
} // namespace nt
#include "ValueListener.inc"

View File

@@ -0,0 +1,103 @@
// 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 <utility>
#include <vector>
#include "networktables/MultiSubscriber.h"
#include "networktables/NetworkTableEntry.h"
#include "networktables/NetworkTableInstance.h"
#include "networktables/Topic.h"
#include "networktables/ValueListener.h"
#include "ntcore_cpp.h"
namespace nt {
inline ValueListener::ValueListener(
const Subscriber& subscriber, unsigned int mask,
std::function<void(const ValueNotification&)> listener)
: m_handle{AddValueListener(subscriber.GetHandle(), mask, listener)} {}
inline ValueListener::ValueListener(
const MultiSubscriber& subscriber, unsigned int mask,
std::function<void(const ValueNotification&)> listener)
: m_handle{AddValueListener(subscriber.GetHandle(), mask, listener)} {}
inline ValueListener::ValueListener(
const NetworkTableEntry& entry, unsigned int mask,
std::function<void(const ValueNotification&)> listener)
: m_handle{AddValueListener(entry.GetHandle(), mask, listener)} {}
inline ValueListener::ValueListener(
NT_Handle subentry, unsigned int mask,
std::function<void(const ValueNotification&)> listener)
: m_handle{AddValueListener(subentry, mask, listener)} {}
inline ValueListener::ValueListener(ValueListener&& rhs)
: m_handle(rhs.m_handle) {
rhs.m_handle = 0;
}
inline ValueListener& ValueListener::operator=(ValueListener&& rhs) {
std::swap(m_handle, rhs.m_handle);
return *this;
}
inline ValueListener::~ValueListener() {
if (m_handle != 0) {
nt::RemoveValueListener(m_handle);
}
}
inline ValueListenerPoller::ValueListenerPoller(NetworkTableInstance inst)
: m_handle(nt::CreateValueListenerPoller(inst.GetHandle())) {}
inline ValueListenerPoller::ValueListenerPoller(ValueListenerPoller&& rhs)
: m_handle(rhs.m_handle) {
rhs.m_handle = 0;
}
inline ValueListenerPoller& ValueListenerPoller::operator=(
ValueListenerPoller&& rhs) {
std::swap(m_handle, rhs.m_handle);
return *this;
}
inline ValueListenerPoller::~ValueListenerPoller() {
if (m_handle != 0) {
nt::DestroyValueListenerPoller(m_handle);
}
}
inline NT_ValueListener ValueListenerPoller::Add(const Subscriber& subscriber,
unsigned int mask) {
return Add(subscriber.GetHandle(), mask);
}
inline NT_ValueListener ValueListenerPoller::Add(
const MultiSubscriber& subscriber, unsigned int mask) {
return Add(subscriber.GetHandle(), mask);
}
inline NT_ValueListener ValueListenerPoller::Add(const NetworkTableEntry& entry,
unsigned int mask) {
return Add(entry.GetHandle(), mask);
}
inline NT_ValueListener ValueListenerPoller::Add(NT_Handle subentry,
unsigned int mask) {
return nt::AddPolledValueListener(m_handle, subentry, mask);
}
inline void ValueListenerPoller::Remove(NT_ValueListener listener) {
nt::RemoveValueListener(listener);
}
inline std::vector<ValueNotification> ValueListenerPoller::ReadQueue() {
return nt::ReadValueListenerQueue(m_handle);
}
} // namespace nt

View File

@@ -2,8 +2,7 @@
// 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.
#ifndef NTCORE_NTCORE_H_
#define NTCORE_NTCORE_H_
#pragma once
/* C API */
#include "ntcore_c.h"
@@ -12,5 +11,3 @@
/* C++ API */
#include "ntcore_cpp.h"
#endif /* __cplusplus */
#endif // NTCORE_NTCORE_H_

File diff suppressed because it is too large Load Diff

File diff suppressed because it is too large Load Diff

View File

@@ -2,8 +2,7 @@
// 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.
#ifndef NTCORE_NTCORE_TEST_H_
#define NTCORE_NTCORE_TEST_H_
#pragma once
#include <stdint.h>
@@ -82,5 +81,3 @@ struct NT_RpcCallInfo* NT_GetRpcCallInfoForTesting(
const char* params, size_t params_len, int* struct_size);
// No need for free as one already exists in the main library
} // extern "C"
#endif // NTCORE_NTCORE_TEST_H_