[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:
Peter Johnson
2022-10-14 20:50:55 -07:00
committed by GitHub
parent d9d6c425e7
commit 574cb41c18
10 changed files with 48 additions and 17 deletions

View File

@@ -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();

View File

@@ -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;

View File

@@ -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);

View File

@@ -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.