WPILibC++ 2023.4.3
MulticastServiceResolver.h
Go to the documentation of this file.
1// Copyright (c) FIRST and other WPILib contributors.
2// Open Source Software; you can modify and/or share it under the terms of
3// the WPILib BSD license file in the root directory of this project.
4
5#pragma once
6
8
9#ifdef __cplusplus
10#include <functional>
11#include <memory>
12#include <string>
13#include <string_view>
14#include <utility>
15#include <vector>
16
17#include <wpi/mutex.h>
18namespace wpi {
19class MulticastServiceResolver {
20 public:
21 explicit MulticastServiceResolver(std::string_view serviceType);
22 ~MulticastServiceResolver() noexcept;
23 struct ServiceData {
24 unsigned int ipv4Address;
25 int port;
26 std::string serviceName;
27 std::string hostName;
28 std::vector<std::pair<std::string, std::string>> txt;
29 };
30 void Start();
31 void Stop();
32 WPI_EventHandle GetEventHandle() const { return event.GetHandle(); }
33 std::vector<ServiceData> GetData() {
34 std::scoped_lock lock{mutex};
35 event.Reset();
36 if (queue.empty()) {
37 return {};
38 }
39 std::vector<ServiceData> ret;
40 queue.swap(ret);
41 return ret;
42 }
43 bool HasImplementation() const;
44 struct Impl;
45
46 private:
47 void PushData(ServiceData&& data) {
48 std::scoped_lock lock{mutex};
49 queue.emplace_back(std::forward<ServiceData>(data));
50 event.Set();
51 }
52 wpi::Event event{true};
53 std::vector<ServiceData> queue;
55 std::unique_ptr<Impl> pImpl;
56};
57} // namespace wpi
58extern "C" {
59#endif
60
61typedef unsigned int WPI_MulticastServiceResolverHandle; // NOLINT
62
64 const char* serviceType);
65
68
71
74
77
80
81typedef struct WPI_ServiceData { // NOLINT
84 const char* serviceName;
85 const char* hostName;
87 const char** txtKeys;
88 const char** txtValues;
90
93
94void WPI_FreeServiceData(WPI_ServiceData* serviceData, int32_t length);
95
96#ifdef __cplusplus
97} // extern "C"
98#endif
unsigned int WPI_MulticastServiceResolverHandle
Definition: MulticastServiceResolver.h:61
void WPI_StopMulticastServiceResolver(WPI_MulticastServiceResolverHandle handle)
void WPI_FreeMulticastServiceResolver(WPI_MulticastServiceResolverHandle handle)
WPI_MulticastServiceResolverHandle WPI_CreateMulticastServiceResolver(const char *serviceType)
void WPI_StartMulticastServiceResolver(WPI_MulticastServiceResolverHandle handle)
WPI_EventHandle WPI_GetMulticastServiceResolverEventHandle(WPI_MulticastServiceResolverHandle handle)
int32_t WPI_GetMulticastServiceResolverHasImplementation(WPI_MulticastServiceResolverHandle handle)
struct WPI_ServiceData WPI_ServiceData
void WPI_FreeServiceData(WPI_ServiceData *serviceData, int32_t length)
WPI_ServiceData * WPI_GetMulticastServiceResolverData(WPI_MulticastServiceResolverHandle handle, int32_t *dataCount)
WPI_Handle WPI_EventHandle
An event handle.
Definition: Synchronization.h:25
basic_string_view< char > string_view
Definition: core.h:520
::uint32_t uint32_t
Definition: Meta.h:56
::int32_t int32_t
Definition: Meta.h:57
/file This file defines the SmallVector class.
Definition: AprilTagFieldLayout.h:18
::std::mutex mutex
Definition: mutex.h:17
Definition: MulticastServiceResolver.h:81
const char ** txtValues
Definition: MulticastServiceResolver.h:88
uint32_t ipv4Address
Definition: MulticastServiceResolver.h:82
const char * hostName
Definition: MulticastServiceResolver.h:85
int32_t txtCount
Definition: MulticastServiceResolver.h:86
const char ** txtKeys
Definition: MulticastServiceResolver.h:87
const char * serviceName
Definition: MulticastServiceResolver.h:84
int32_t port
Definition: MulticastServiceResolver.h:83
Definition: format.h:1544