blob: 0ca28db71f1123b916713fc34af9358370c5c390 [file] [log] [blame]
Vitaly Buka4615e0d2015-10-14 15:35:12 -07001// Copyright 2015 The Weave Authors. All rights reserved.
Vitaly Buka17b0a8a2015-08-31 19:12:35 -07002// Use of this source code is governed by a BSD-style license that can be
3// found in the LICENSE file.
4
Johan Euphrosine3523fdd2015-10-14 20:46:05 -07005#ifndef LIBWEAVE_EXAMPLES_PROVIDER_AVAHI_CLIENT_H_
6#define LIBWEAVE_EXAMPLES_PROVIDER_AVAHI_CLIENT_H_
Vitaly Buka17b0a8a2015-08-31 19:12:35 -07007
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 Buka1e363672015-09-25 14:01:16 -070015#include <weave/provider/dns_service_discovery.h>
Vitaly Buka17b0a8a2015-08-31 19:12:35 -070016
17namespace weave {
18namespace examples {
19
Vitaly Buka1e363672015-09-25 14:01:16 -070020// Example of provider::DnsServiceDiscovery implemented with avahi.
21class AvahiClient : public provider::DnsServiceDiscovery {
Vitaly Buka17b0a8a2015-08-31 19:12:35 -070022 public:
Vitaly Bukabeddc602015-09-24 15:28:03 -070023 AvahiClient();
Vitaly Buka17b0a8a2015-08-31 19:12:35 -070024
Vitaly Bukabeddc602015-09-24 15:28:03 -070025 ~AvahiClient() override;
Vitaly Buka3dc2f532015-09-08 18:01:32 -070026 void PublishService(const std::string& service_type,
Vitaly Buka17b0a8a2015-08-31 19:12:35 -070027 uint16_t port,
Vitaly Buka3dc2f532015-09-08 18:01:32 -070028 const std::vector<std::string>& txt) override;
Vitaly Buka17b0a8a2015-08-31 19:12:35 -070029 void StopPublishing(const std::string& service_name) override;
Vitaly Buka17b0a8a2015-08-31 19:12:35 -070030
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 Bukabeddc602015-09-24 15:28:03 -070037 std::unique_ptr<::AvahiClient, decltype(&avahi_client_free)> client_{
Vitaly Buka17b0a8a2015-08-31 19:12:35 -070038 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 Euphrosine3523fdd2015-10-14 20:46:05 -070047#endif // LIBWEAVE_EXAMPLES_PROVIDER_AVAHI_CLIENT_H_