1 /***
2     This file is part of snapcast
3     Copyright (C) 2014-2020  Johannes Pohl
4 
5     This program is free software: you can redistribute it and/or modify
6     it under the terms of the GNU General Public License as published by
7     the Free Software Foundation, either version 3 of the License, or
8     (at your option) any later version.
9 
10     This program is distributed in the hope that it will be useful,
11     but WITHOUT ANY WARRANTY; without even the implied warranty of
12     MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
13     GNU General Public License for more details.
14 
15     You should have received a copy of the GNU General Public License
16     along with this program.  If not, see <http://www.gnu.org/licenses/>.
17 ***/
18 #ifndef BROWSEAVAHI_H
19 #define BROWSEAVAHI_H
20 
21 #include <avahi-client/client.h>
22 #include <avahi-client/lookup.h>
23 
24 #include <avahi-common/error.h>
25 #include <avahi-common/malloc.h>
26 #include <avahi-common/simple-watch.h>
27 
28 class BrowseAvahi;
29 
30 #include "browse_mdns.hpp"
31 
32 class BrowseAvahi : public BrowsemDNS
33 {
34 public:
35     BrowseAvahi();
36     ~BrowseAvahi();
37     bool browse(const std::string& serviceName, mDNSResult& result, int timeout) override;
38 
39 private:
40     void cleanUp();
41     static void resolve_callback(AvahiServiceResolver* r, AVAHI_GCC_UNUSED AvahiIfIndex interface, AVAHI_GCC_UNUSED AvahiProtocol protocol,
42                                  AvahiResolverEvent event, const char* name, const char* type, const char* domain, const char* host_name,
43                                  const AvahiAddress* address, uint16_t port, AvahiStringList* txt, AvahiLookupResultFlags flags,
44                                  AVAHI_GCC_UNUSED void* userdata);
45     static void browse_callback(AvahiServiceBrowser* b, AvahiIfIndex interface, AvahiProtocol protocol, AvahiBrowserEvent event, const char* name,
46                                 const char* type, const char* domain, AVAHI_GCC_UNUSED AvahiLookupResultFlags flags, void* userdata);
47     static void client_callback(AvahiClient* c, AvahiClientState state, AVAHI_GCC_UNUSED void* userdata);
48     AvahiClient* client_;
49     mDNSResult result_;
50     AvahiServiceBrowser* sb_;
51 };
52 
53 #endif
54