blob: b2cda27cc6f7f4ac548281e03177f0f911a846bf [file] [log] [blame]
Vitaly Buka7042c582015-07-30 17:02:14 -07001// Copyright 2014 The Chromium OS 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
Vitaly Buka58a288b2015-07-31 00:33:31 -07005#ifndef BUFFET_PEERD_CLIENT_H_
6#define BUFFET_PEERD_CLIENT_H_
Vitaly Buka7042c582015-07-30 17:02:14 -07007
Vitaly Buka7042c582015-07-30 17:02:14 -07008#include <memory>
9#include <string>
Alex Vakulenkoe32375b2015-09-28 08:55:40 -070010#include <vector>
Vitaly Buka7042c582015-07-30 17:02:14 -070011
12#include <base/callback.h>
13#include <base/memory/ref_counted.h>
Alex Vakulenkoe32375b2015-09-28 08:55:40 -070014#include <weave/provider/dns_service_discovery.h>
Vitaly Buka7042c582015-07-30 17:02:14 -070015
16#include "peerd/dbus-proxies.h"
Vitaly Buka7042c582015-07-30 17:02:14 -070017
18namespace dbus {
19class Bus;
20} // namespace dbus
21
22namespace buffet {
23
24// Publishes privet service on mDns using peerd.
Alex Vakulenkoe32375b2015-09-28 08:55:40 -070025class PeerdClient : public weave::provider::DnsServiceDiscovery {
Vitaly Buka7042c582015-07-30 17:02:14 -070026 public:
27 explicit PeerdClient(const scoped_refptr<dbus::Bus>& bus);
28 ~PeerdClient() override;
29
30 // Mdns implementation.
Alex Vakulenkoe32375b2015-09-28 08:55:40 -070031 void PublishService(const std::string& service_type,
Vitaly Buka7042c582015-07-30 17:02:14 -070032 uint16_t port,
Alex Vakulenkoe32375b2015-09-28 08:55:40 -070033 const std::vector<std::string>& txt) override;
34 void StopPublishing(const std::string& service_type) override;
Vitaly Buka7042c582015-07-30 17:02:14 -070035
36 private:
37 void OnPeerdOnline(org::chromium::peerd::ManagerProxy* manager_proxy);
38 void OnPeerdOffline(const dbus::ObjectPath& object_path);
Vitaly Buka7042c582015-07-30 17:02:14 -070039
40 // Updates published information. Removes service if HTTP is not alive.
41 void Update();
42
43 void ExposeService();
44 void RemoveService();
45
46 void UpdateImpl();
47
48 org::chromium::peerd::ObjectManagerProxy peerd_object_manager_proxy_;
49 // |peerd_manager_proxy_| is owned by |peerd_object_manager_proxy_|.
50 org::chromium::peerd::ManagerProxy* peerd_manager_proxy_{nullptr};
51
Alex Vakulenkoe32375b2015-09-28 08:55:40 -070052 bool published_{false};
Vitaly Buka7042c582015-07-30 17:02:14 -070053 uint16_t port_{0};
Alex Vakulenkoe32375b2015-09-28 08:55:40 -070054 std::vector<std::string> txt_;
Vitaly Buka7042c582015-07-30 17:02:14 -070055
56 base::WeakPtrFactory<PeerdClient> restart_weak_ptr_factory_{this};
57 base::WeakPtrFactory<PeerdClient> weak_ptr_factory_{this};
58
59 DISALLOW_COPY_AND_ASSIGN(PeerdClient);
60};
61
62} // namespace buffet
63
Vitaly Buka58a288b2015-07-31 00:33:31 -070064#endif // BUFFET_PEERD_CLIENT_H_