diff --git a/client/browseZeroConf/browse_avahi.hpp b/client/browseZeroConf/browse_avahi.hpp index 5507f9c6..631a71f2 100644 --- a/client/browseZeroConf/browse_avahi.hpp +++ b/client/browseZeroConf/browse_avahi.hpp @@ -1,6 +1,6 @@ /*** This file is part of snapcast - Copyright (C) 2014-2024 Johannes Pohl + Copyright (C) 2014-2025 Johannes Pohl This program is free software: you can redistribute it and/or modify it under the terms of the GNU General Public License as published by @@ -18,8 +18,6 @@ #pragma once -class BrowseAvahi; - // local headers #include "browse_mdns.hpp" @@ -31,11 +29,15 @@ class BrowseAvahi; #include +/// Avahi based mDNS browser class BrowseAvahi : public BrowsemDNS { public: + /// c'tor BrowseAvahi(); + /// d'tor ~BrowseAvahi(); + bool browse(const std::string& serviceName, mDNSResult& result, int timeout) override; private: diff --git a/client/browseZeroConf/browse_bonjour.cpp b/client/browseZeroConf/browse_bonjour.cpp index 05a3fb49..786092d0 100644 --- a/client/browseZeroConf/browse_bonjour.cpp +++ b/client/browseZeroConf/browse_bonjour.cpp @@ -40,6 +40,7 @@ using namespace std; static constexpr auto LOG_TAG = "Bonjour"; +/// DNSServiceRefDeleter struct DNSServiceRefDeleter { void operator()(DNSServiceRef* ref) @@ -51,6 +52,7 @@ struct DNSServiceRefDeleter using DNSServiceHandle = std::unique_ptr; +/// @return @p error as string string BonjourGetError(DNSServiceErrorType error) { switch (error) @@ -154,11 +156,13 @@ string BonjourGetError(DNSServiceErrorType error) } } +/// mDNS reply struct mDNSReply { string name, regtype, domain; }; +/// mDNS resolve struct mDNSResolve { string fullName; @@ -169,6 +173,7 @@ struct mDNSResolve if ((err) != kDNSServiceErr_NoError) \ throw SnapException(BonjourGetError(err) + ":" + to_string(__LINE__)); +/// run service @p service void runService(const DNSServiceHandle& service) { if (!*service) diff --git a/client/browseZeroConf/browse_bonjour.hpp b/client/browseZeroConf/browse_bonjour.hpp index e92333c1..3b58b737 100644 --- a/client/browseZeroConf/browse_bonjour.hpp +++ b/client/browseZeroConf/browse_bonjour.hpp @@ -1,6 +1,6 @@ /*** This file is part of snapcast - Copyright (C) 2014-2024 Johannes Pohl + Copyright (C) 2014-2025 Johannes Pohl This program is free software: you can redistribute it and/or modify it under the terms of the GNU General Public License as published by @@ -18,7 +18,6 @@ #pragma once -class BrowseBonjour; // local headers #include "browse_mdns.hpp" @@ -27,6 +26,7 @@ class BrowseBonjour; #include +/// Bonjour based mDNS browser class BrowseBonjour : public BrowsemDNS { public: diff --git a/client/browseZeroConf/browse_mdns.hpp b/client/browseZeroConf/browse_mdns.hpp index 67959bc3..0d8034f6 100644 --- a/client/browseZeroConf/browse_mdns.hpp +++ b/client/browseZeroConf/browse_mdns.hpp @@ -1,6 +1,6 @@ /*** This file is part of snapcast - Copyright (C) 2014-2024 Johannes Pohl + Copyright (C) 2014-2025 Johannes Pohl This program is free software: you can redistribute it and/or modify it under the terms of the GNU General Public License as published by @@ -22,37 +22,28 @@ #include #include -enum IPVersion +/// IP versions IPv4 and IPv6 +enum class IPVersion { - IPv4 = 0, - IPv6 = 1 + IPv4 = 0, ///< IPv4 + IPv6 = 1 ///< IPv6 }; - +/// mDNS record struct mDNSResult { - mDNSResult() : ip_version(IPv4), iface_idx(0), port(0), valid(false) - { - } - - IPVersion ip_version; - int iface_idx; - std::string ip; - std::string host; - uint16_t port; - bool valid; + IPVersion ip_version{IPVersion::IPv4}; ///< IP version + int iface_idx{0}; ///< interface index + std::string ip; ///< IP address + std::string host; ///< host + uint16_t port{0}; ///< port + bool valid{false}; ///< valid }; +/// mDNS browser interface class BrowsemDNS { public: + /// get mDNS record for @p serviceName virtual bool browse(const std::string& serviceName, mDNSResult& result, int timeout) = 0; }; - -#if defined(HAS_AVAHI) -#include "browse_avahi.hpp" -using BrowseZeroConf = BrowseAvahi; -#elif defined(HAS_BONJOUR) -#include "browse_bonjour.hpp" -using BrowseZeroConf = BrowseBonjour; -#endif diff --git a/client/browseZeroConf/browse_zeroconf.hpp b/client/browseZeroConf/browse_zeroconf.hpp new file mode 100644 index 00000000..235bac7f --- /dev/null +++ b/client/browseZeroConf/browse_zeroconf.hpp @@ -0,0 +1,27 @@ +/*** + This file is part of snapcast + Copyright (C) 2014-2024 Johannes Pohl + + This program is free software: you can redistribute it and/or modify + it under the terms of the GNU General Public License as published by + the Free Software Foundation, either version 3 of the License, or + (at your option) any later version. + + This program is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + GNU General Public License for more details. + + You should have received a copy of the GNU General Public License + along with this program. If not, see . +***/ + +#pragma once + +#if defined(HAS_AVAHI) +#include "browse_avahi.hpp" +using BrowseZeroConf = BrowseAvahi; +#elif defined(HAS_BONJOUR) +#include "browse_bonjour.hpp" +using BrowseZeroConf = BrowseBonjour; +#endif diff --git a/client/controller.cpp b/client/controller.cpp index e1812788..c888ff1c 100644 --- a/client/controller.cpp +++ b/client/controller.cpp @@ -56,7 +56,7 @@ #endif #include "player/file_player.hpp" -#include "browseZeroConf/browse_mdns.hpp" +#include "browseZeroConf/browse_zeroconf.hpp" #include "common/aixlog.hpp" #include "common/message/client_info.hpp" #include "common/message/error.hpp"