mirror of
https://github.com/wpilibsuite/allwpilib
synced 2026-06-30 02:31:44 +00:00
ConnectionListener: Use bool instead of int for connected parameter.
This commit is contained in:
@@ -184,7 +184,7 @@ typedef std::function<void(unsigned int uid, StringRef name,
|
||||
std::shared_ptr<Value> value, bool is_new)>
|
||||
EntryListenerCallback;
|
||||
|
||||
typedef std::function<void(unsigned int uid, int connected,
|
||||
typedef std::function<void(unsigned int uid, bool connected,
|
||||
const ConnectionInfo& conn)>
|
||||
ConnectionListenerCallback;
|
||||
|
||||
|
||||
@@ -99,7 +99,7 @@ void NetworkConnection::ReadThreadMain() {
|
||||
}
|
||||
|
||||
m_state = static_cast<int>(kActive);
|
||||
m_notifier.NotifyConnection(1, info());
|
||||
m_notifier.NotifyConnection(true, info());
|
||||
while (m_active) {
|
||||
if (!m_stream)
|
||||
break;
|
||||
@@ -118,7 +118,7 @@ void NetworkConnection::ReadThreadMain() {
|
||||
m_process_incoming(std::move(msg), this);
|
||||
}
|
||||
DEBUG3("read thread died");
|
||||
if (m_state != kDead) m_notifier.NotifyConnection(0, info());
|
||||
if (m_state != kDead) m_notifier.NotifyConnection(false, info());
|
||||
m_state = static_cast<int>(kDead);
|
||||
m_active = false;
|
||||
m_outgoing.push(Outgoing()); // also kill write thread
|
||||
@@ -149,7 +149,7 @@ void NetworkConnection::WriteThreadMain() {
|
||||
DEBUG4("sent " << encoder.size() << " bytes");
|
||||
}
|
||||
DEBUG3("write thread died");
|
||||
if (m_state != kDead) m_notifier.NotifyConnection(0, info());
|
||||
if (m_state != kDead) m_notifier.NotifyConnection(false, info());
|
||||
m_state = static_cast<int>(kDead);
|
||||
m_active = false;
|
||||
if (m_stream) m_stream->close(); // also kill read thread
|
||||
|
||||
@@ -116,7 +116,7 @@ void Notifier::RemoveConnectionListener(unsigned int conn_listener_uid) {
|
||||
m_conn_listeners[conn_listener_uid] = nullptr;
|
||||
}
|
||||
|
||||
void Notifier::NotifyConnection(int connected,
|
||||
void Notifier::NotifyConnection(bool connected,
|
||||
const ConnectionInfo& conn_info) {
|
||||
if (!m_active) return;
|
||||
std::unique_lock<std::mutex> lock(m_mutex);
|
||||
|
||||
@@ -44,7 +44,7 @@ class Notifier {
|
||||
unsigned int AddConnectionListener(ConnectionListenerCallback callback);
|
||||
void RemoveConnectionListener(unsigned int conn_listener_uid);
|
||||
|
||||
void NotifyConnection(int connected, const ConnectionInfo& conn_info);
|
||||
void NotifyConnection(bool connected, const ConnectionInfo& conn_info);
|
||||
|
||||
private:
|
||||
Notifier();
|
||||
@@ -70,10 +70,10 @@ class Notifier {
|
||||
std::queue<EntryNotification> m_entry_notifications;
|
||||
|
||||
struct ConnectionNotification {
|
||||
ConnectionNotification(int connected_, const ConnectionInfo& conn_info_)
|
||||
ConnectionNotification(bool connected_, const ConnectionInfo& conn_info_)
|
||||
: connected(connected_), conn_info(conn_info_) {}
|
||||
|
||||
int connected;
|
||||
bool connected;
|
||||
ConnectionInfo conn_info;
|
||||
};
|
||||
std::queue<ConnectionNotification> m_conn_notifications;
|
||||
|
||||
@@ -182,10 +182,10 @@ void NT_RemoveEntryListener(unsigned int entry_listener_uid) {
|
||||
unsigned int NT_AddConnectionListener(void *data,
|
||||
NT_ConnectionListenerCallback callback) {
|
||||
return nt::AddConnectionListener(
|
||||
[=](unsigned int uid, int connected, const ConnectionInfo &conn) {
|
||||
[=](unsigned int uid, bool connected, const ConnectionInfo &conn) {
|
||||
NT_ConnectionInfo conn_c;
|
||||
ConvertToC(conn, &conn_c);
|
||||
callback(uid, data, connected, &conn_c);
|
||||
callback(uid, data, connected ? 1 : 0, &conn_c);
|
||||
DisposeConnectionInfo(&conn_c);
|
||||
});
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user