Vitaly Buka | 7042c58 | 2015-07-30 17:02:14 -0700 | [diff] [blame] | 1 | // 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 Buka | 58a288b | 2015-07-31 00:33:31 -0700 | [diff] [blame] | 5 | #ifndef BUFFET_PEERD_CLIENT_H_ |
| 6 | #define BUFFET_PEERD_CLIENT_H_ |
Vitaly Buka | 7042c58 | 2015-07-30 17:02:14 -0700 | [diff] [blame] | 7 | |
Vitaly Buka | 7042c58 | 2015-07-30 17:02:14 -0700 | [diff] [blame] | 8 | #include <memory> |
| 9 | #include <string> |
Alex Vakulenko | e32375b | 2015-09-28 08:55:40 -0700 | [diff] [blame] | 10 | #include <vector> |
Vitaly Buka | 7042c58 | 2015-07-30 17:02:14 -0700 | [diff] [blame] | 11 | |
| 12 | #include <base/callback.h> |
| 13 | #include <base/memory/ref_counted.h> |
Alex Vakulenko | e32375b | 2015-09-28 08:55:40 -0700 | [diff] [blame] | 14 | #include <weave/provider/dns_service_discovery.h> |
Vitaly Buka | 7042c58 | 2015-07-30 17:02:14 -0700 | [diff] [blame] | 15 | |
| 16 | #include "peerd/dbus-proxies.h" |
Vitaly Buka | 7042c58 | 2015-07-30 17:02:14 -0700 | [diff] [blame] | 17 | |
| 18 | namespace dbus { |
| 19 | class Bus; |
| 20 | } // namespace dbus |
| 21 | |
| 22 | namespace buffet { |
| 23 | |
| 24 | // Publishes privet service on mDns using peerd. |
Alex Vakulenko | e32375b | 2015-09-28 08:55:40 -0700 | [diff] [blame] | 25 | class PeerdClient : public weave::provider::DnsServiceDiscovery { |
Vitaly Buka | 7042c58 | 2015-07-30 17:02:14 -0700 | [diff] [blame] | 26 | public: |
| 27 | explicit PeerdClient(const scoped_refptr<dbus::Bus>& bus); |
| 28 | ~PeerdClient() override; |
| 29 | |
| 30 | // Mdns implementation. |
Alex Vakulenko | e32375b | 2015-09-28 08:55:40 -0700 | [diff] [blame] | 31 | void PublishService(const std::string& service_type, |
Vitaly Buka | 7042c58 | 2015-07-30 17:02:14 -0700 | [diff] [blame] | 32 | uint16_t port, |
Alex Vakulenko | e32375b | 2015-09-28 08:55:40 -0700 | [diff] [blame] | 33 | const std::vector<std::string>& txt) override; |
| 34 | void StopPublishing(const std::string& service_type) override; |
Vitaly Buka | 7042c58 | 2015-07-30 17:02:14 -0700 | [diff] [blame] | 35 | |
| 36 | private: |
| 37 | void OnPeerdOnline(org::chromium::peerd::ManagerProxy* manager_proxy); |
| 38 | void OnPeerdOffline(const dbus::ObjectPath& object_path); |
Vitaly Buka | 7042c58 | 2015-07-30 17:02:14 -0700 | [diff] [blame] | 39 | |
| 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 Vakulenko | e32375b | 2015-09-28 08:55:40 -0700 | [diff] [blame] | 52 | bool published_{false}; |
Vitaly Buka | 7042c58 | 2015-07-30 17:02:14 -0700 | [diff] [blame] | 53 | uint16_t port_{0}; |
Alex Vakulenko | e32375b | 2015-09-28 08:55:40 -0700 | [diff] [blame] | 54 | std::vector<std::string> txt_; |
Vitaly Buka | 7042c58 | 2015-07-30 17:02:14 -0700 | [diff] [blame] | 55 | |
| 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 Buka | 58a288b | 2015-07-31 00:33:31 -0700 | [diff] [blame] | 64 | #endif // BUFFET_PEERD_CLIENT_H_ |