mirror of
https://github.com/wpilibsuite/allwpilib
synced 2026-06-20 00:51:42 +00:00
[wpinet] Add callback for mDNS service resolver (#7986)
This commit is contained in:
@@ -4,6 +4,8 @@
|
||||
|
||||
#include "wpinet/MulticastServiceResolver.h"
|
||||
|
||||
#include <arpa/inet.h>
|
||||
|
||||
#include <memory>
|
||||
#include <string>
|
||||
#include <utility>
|
||||
@@ -44,6 +46,26 @@ bool MulticastServiceResolver::HasImplementation() const {
|
||||
return pImpl->table.IsValid();
|
||||
}
|
||||
|
||||
bool MulticastServiceResolver::SetCopyCallback(
|
||||
std::function<bool(const ServiceData&)> callback) {
|
||||
std::scoped_lock lock{*pImpl->thread};
|
||||
if (pImpl->client) {
|
||||
return false;
|
||||
}
|
||||
copyCallback = std::move(callback);
|
||||
return true;
|
||||
}
|
||||
|
||||
bool MulticastServiceResolver::SetMoveCallback(
|
||||
std::function<void(ServiceData&&)> callback) {
|
||||
std::scoped_lock lock{*pImpl->thread};
|
||||
if (pImpl->client) {
|
||||
return false;
|
||||
}
|
||||
moveCallback = std::move(callback);
|
||||
return true;
|
||||
}
|
||||
|
||||
static void ResolveCallback(AvahiServiceResolver* r, AvahiIfIndex interface,
|
||||
AvahiProtocol protocol, AvahiResolverEvent event,
|
||||
const char* name, const char* type,
|
||||
@@ -83,8 +105,8 @@ static void ResolveCallback(AvahiServiceResolver* r, AvahiIfIndex interface,
|
||||
outputHostName.append(".");
|
||||
} while (true);
|
||||
|
||||
data.ipv4Address = address->data.ipv4.address;
|
||||
data.port = port;
|
||||
data.ipv4Address = ntohl(address->data.ipv4.address);
|
||||
data.port = ntohs(port);
|
||||
data.serviceName = name;
|
||||
data.hostName = std::string{outputHostName};
|
||||
|
||||
|
||||
Reference in New Issue
Block a user