mirror of
https://github.com/wpilibsuite/allwpilib
synced 2026-06-25 01:41:43 +00:00
[ntcore] Various fixes (#4469)
* Fix C++ Publisher and Subscriber move assignment * Fix Publisher comment typo. * Publish: check that properties is an object. Print a warning, but still publish, just with empty properties. Add error print for unassigned type publish. * Return boolean from SetProperties * Document exception-throw in Java for invalid JSON.
This commit is contained in:
@@ -149,8 +149,9 @@ class Topic {
|
||||
* of the corresponding property.
|
||||
*
|
||||
* @param properties JSON object with keys to add/update/delete
|
||||
* @return False if properties is not an object
|
||||
*/
|
||||
void SetProperties(const wpi::json& properties);
|
||||
bool SetProperties(const wpi::json& properties);
|
||||
|
||||
/**
|
||||
* Gets combined information about the topic.
|
||||
@@ -340,7 +341,7 @@ class Subscriber {
|
||||
NT_Subscriber m_subHandle{0};
|
||||
};
|
||||
|
||||
/** NetworkTables pubscriber. */
|
||||
/** NetworkTables publisher. */
|
||||
class Publisher {
|
||||
public:
|
||||
virtual ~Publisher();
|
||||
|
||||
@@ -54,8 +54,8 @@ 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 bool Topic::SetProperties(const wpi::json& properties) {
|
||||
return ::nt::SetTopicProperties(m_handle, properties);
|
||||
}
|
||||
|
||||
inline TopicInfo Topic::GetInfo() const {
|
||||
@@ -71,6 +71,9 @@ inline Subscriber::Subscriber(Subscriber&& rhs) : m_subHandle{rhs.m_subHandle} {
|
||||
}
|
||||
|
||||
inline Subscriber& Subscriber::operator=(Subscriber&& rhs) {
|
||||
if (m_subHandle != 0) {
|
||||
::nt::Release(m_subHandle);
|
||||
}
|
||||
m_subHandle = rhs.m_subHandle;
|
||||
rhs.m_subHandle = 0;
|
||||
return *this;
|
||||
@@ -97,6 +100,9 @@ inline Publisher::Publisher(Publisher&& rhs) : m_pubHandle{rhs.m_pubHandle} {
|
||||
}
|
||||
|
||||
inline Publisher& Publisher::operator=(Publisher&& rhs) {
|
||||
if (m_pubHandle != 0) {
|
||||
::nt::Release(m_pubHandle);
|
||||
}
|
||||
m_pubHandle = rhs.m_pubHandle;
|
||||
rhs.m_pubHandle = 0;
|
||||
return *this;
|
||||
|
||||
@@ -671,6 +671,7 @@ char* NT_GetTopicProperties(NT_Topic topic, size_t* len);
|
||||
*
|
||||
* @param topic topic handle
|
||||
* @param properties JSON object string with keys to add/update/delete
|
||||
* @return False if properties are not a valid JSON object
|
||||
*/
|
||||
NT_Bool NT_SetTopicProperties(NT_Topic topic, const char* properties);
|
||||
|
||||
|
||||
@@ -651,8 +651,9 @@ wpi::json GetTopicProperties(NT_Topic topic);
|
||||
*
|
||||
* @param topic topic handle
|
||||
* @param update JSON object with keys to add/update/delete
|
||||
* @return False if update is not a JSON object
|
||||
*/
|
||||
void SetTopicProperties(NT_Topic topic, const wpi::json& update);
|
||||
bool SetTopicProperties(NT_Topic topic, const wpi::json& update);
|
||||
|
||||
/**
|
||||
* Creates a new subscriber to value changes on a topic.
|
||||
|
||||
Reference in New Issue
Block a user