Vitaly Buka | 4615e0d | 2015-10-14 15:35:12 -0700 | [diff] [blame] | 1 | // Copyright 2015 The Weave Authors. All rights reserved. |
Vitaly Buka | 17b0a8a | 2015-08-31 19:12:35 -0700 | [diff] [blame] | 2 | // Use of this source code is governed by a BSD-style license that can be |
| 3 | // found in the LICENSE file. |
| 4 | |
Johan Euphrosine | 3523fdd | 2015-10-14 20:46:05 -0700 | [diff] [blame] | 5 | #ifndef LIBWEAVE_EXAMPLES_PROVIDER_AVAHI_CLIENT_H_ |
| 6 | #define LIBWEAVE_EXAMPLES_PROVIDER_AVAHI_CLIENT_H_ |
Vitaly Buka | 17b0a8a | 2015-08-31 19:12:35 -0700 | [diff] [blame] | 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 | |
Vitaly Buka | 1e36367 | 2015-09-25 14:01:16 -0700 | [diff] [blame] | 15 | #include <weave/provider/dns_service_discovery.h> |
Vitaly Buka | 17b0a8a | 2015-08-31 19:12:35 -0700 | [diff] [blame] | 16 | |
| 17 | namespace weave { |
| 18 | namespace examples { |
| 19 | |
Vitaly Buka | 1e36367 | 2015-09-25 14:01:16 -0700 | [diff] [blame] | 20 | // Example of provider::DnsServiceDiscovery implemented with avahi. |
| 21 | class AvahiClient : public provider::DnsServiceDiscovery { |
Vitaly Buka | 17b0a8a | 2015-08-31 19:12:35 -0700 | [diff] [blame] | 22 | public: |
Vitaly Buka | beddc60 | 2015-09-24 15:28:03 -0700 | [diff] [blame] | 23 | AvahiClient(); |
Vitaly Buka | 17b0a8a | 2015-08-31 19:12:35 -0700 | [diff] [blame] | 24 | |
Vitaly Buka | beddc60 | 2015-09-24 15:28:03 -0700 | [diff] [blame] | 25 | ~AvahiClient() override; |
Vitaly Buka | 3dc2f53 | 2015-09-08 18:01:32 -0700 | [diff] [blame] | 26 | void PublishService(const std::string& service_type, |
Vitaly Buka | 17b0a8a | 2015-08-31 19:12:35 -0700 | [diff] [blame] | 27 | uint16_t port, |
Vitaly Buka | 3dc2f53 | 2015-09-08 18:01:32 -0700 | [diff] [blame] | 28 | const std::vector<std::string>& txt) override; |
Vitaly Buka | 17b0a8a | 2015-08-31 19:12:35 -0700 | [diff] [blame] | 29 | void StopPublishing(const std::string& service_name) override; |
Vitaly Buka | 17b0a8a | 2015-08-31 19:12:35 -0700 | [diff] [blame] | 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 | |
Vitaly Buka | beddc60 | 2015-09-24 15:28:03 -0700 | [diff] [blame] | 37 | std::unique_ptr<::AvahiClient, decltype(&avahi_client_free)> client_{ |
Vitaly Buka | 17b0a8a | 2015-08-31 19:12:35 -0700 | [diff] [blame] | 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 | |
Johan Euphrosine | 3523fdd | 2015-10-14 20:46:05 -0700 | [diff] [blame] | 47 | #endif // LIBWEAVE_EXAMPLES_PROVIDER_AVAHI_CLIENT_H_ |