// // Created by Johnathon Slightham on 2025-06-10. // #ifndef MDNSDISCOVERYSERVICE_H #define MDNSDISCOVERYSERVICE_H #include #include #include "BlockingQueue.h" #include "ICommunicationClient.h" #include "IDiscoveryService.h" #include "mDNSRobotModule.h" #ifdef _WIN32 #include #include #define CLOSE_SOCKET closesocket #pragma comment(lib, "ws2_32.lib") typedef SOCKET socket_t; #else #include #include #include #include #define CLOSE_SOCKET close typedef int socket_t; #endif class mDNSDiscoveryService final : public IDiscoveryService { public: mDNSDiscoveryService(); ~mDNSDiscoveryService() override; std::unordered_set find_modules(std::chrono::duration wait_time) override; std::unordered_map> get_lossy_clients( const std::shared_ptr>>> &rx_queue, std::vector &skip_modules) override; std::unordered_map> get_lossless_clients( const std::shared_ptr>>> &rx_queue, std::vector &skip_modules) override; private: template std::unordered_map> create_clients( const std::shared_ptr>>> &rx_queue, std::vector &skip_modules); static void send_mdns_query(socket_t sock, const sockaddr_in &addr); static std::optional parse_response(uint8_t *buffer, int size); static std::tuple read_mdns_name(const uint8_t *buffer, int size, int ptr); std::unordered_map module_to_mdns{}; }; #endif // MDNSDISCOVERYSERVICE_H