1 // Copyright 2015 The Weave Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file.
4 
5 #ifndef LIBWEAVE_EXAMPLES_PROVIDER_AVAHI_CLIENT_H_
6 #define LIBWEAVE_EXAMPLES_PROVIDER_AVAHI_CLIENT_H_
7 
8 #include <map>
9 #include <string>
10 
11 #include <avahi-client/client.h>
12 #include <avahi-client/publish.h>
13 #include <avahi-common/thread-watch.h>
14 
15 #include <weave/provider/dns_service_discovery.h>
16 
17 namespace weave {
18 namespace examples {
19 
20 // Example of provider::DnsServiceDiscovery implemented with avahi.
21 class AvahiClient : public provider::DnsServiceDiscovery {
22  public:
23   AvahiClient();
24 
25   ~AvahiClient() override;
26   void PublishService(const std::string& service_type,
27                       uint16_t port,
28                       const std::vector<std::string>& txt) override;
29   void StopPublishing(const std::string& service_name) override;
30 
31   uint16_t prev_port_{0};
32   std::string prev_type_;
33 
34   std::unique_ptr<AvahiThreadedPoll, decltype(&avahi_threaded_poll_free)>
35       thread_pool_{nullptr, &avahi_threaded_poll_free};
36 
37   std::unique_ptr< ::AvahiClient, decltype(&avahi_client_free)> client_{
38       nullptr, &avahi_client_free};
39 
40   std::unique_ptr<AvahiEntryGroup, decltype(&avahi_entry_group_free)> group_{
41       nullptr, &avahi_entry_group_free};
42 };
43 
44 }  // namespace examples
45 }  // namespace weave
46 
47 #endif  // LIBWEAVE_EXAMPLES_PROVIDER_AVAHI_CLIENT_H_
48