Vitaly Buka | cad20f0 | 2015-10-16 17:27:15 -0700 | [diff] [blame] | 1 | // Copyright 2015 The Android Open Source Project |
| 2 | // |
| 3 | // Licensed under the Apache License, Version 2.0 (the "License"); |
| 4 | // you may not use this file except in compliance with the License. |
| 5 | // You may obtain a copy of the License at |
| 6 | // |
| 7 | // http://www.apache.org/licenses/LICENSE-2.0 |
| 8 | // |
| 9 | // Unless required by applicable law or agreed to in writing, software |
| 10 | // distributed under the License is distributed on an "AS IS" BASIS, |
| 11 | // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
| 12 | // See the License for the specific language governing permissions and |
| 13 | // limitations under the License. |
Vitaly Buka | 7042c58 | 2015-07-30 17:02:14 -0700 | [diff] [blame] | 14 | |
Vitaly Buka | 58a288b | 2015-07-31 00:33:31 -0700 | [diff] [blame] | 15 | #ifndef BUFFET_PEERD_CLIENT_H_ |
| 16 | #define BUFFET_PEERD_CLIENT_H_ |
Vitaly Buka | 7042c58 | 2015-07-30 17:02:14 -0700 | [diff] [blame] | 17 | |
Vitaly Buka | 7042c58 | 2015-07-30 17:02:14 -0700 | [diff] [blame] | 18 | #include <memory> |
| 19 | #include <string> |
Alex Vakulenko | e32375b | 2015-09-28 08:55:40 -0700 | [diff] [blame] | 20 | #include <vector> |
Vitaly Buka | 7042c58 | 2015-07-30 17:02:14 -0700 | [diff] [blame] | 21 | |
| 22 | #include <base/callback.h> |
| 23 | #include <base/memory/ref_counted.h> |
Alex Vakulenko | e32375b | 2015-09-28 08:55:40 -0700 | [diff] [blame] | 24 | #include <weave/provider/dns_service_discovery.h> |
Vitaly Buka | 7042c58 | 2015-07-30 17:02:14 -0700 | [diff] [blame] | 25 | |
| 26 | #include "peerd/dbus-proxies.h" |
Vitaly Buka | 7042c58 | 2015-07-30 17:02:14 -0700 | [diff] [blame] | 27 | |
| 28 | namespace dbus { |
| 29 | class Bus; |
| 30 | } // namespace dbus |
| 31 | |
| 32 | namespace buffet { |
| 33 | |
| 34 | // Publishes privet service on mDns using peerd. |
Alex Vakulenko | e32375b | 2015-09-28 08:55:40 -0700 | [diff] [blame] | 35 | class PeerdClient : public weave::provider::DnsServiceDiscovery { |
Vitaly Buka | 7042c58 | 2015-07-30 17:02:14 -0700 | [diff] [blame] | 36 | public: |
| 37 | explicit PeerdClient(const scoped_refptr<dbus::Bus>& bus); |
| 38 | ~PeerdClient() override; |
| 39 | |
| 40 | // Mdns implementation. |
Alex Vakulenko | e32375b | 2015-09-28 08:55:40 -0700 | [diff] [blame] | 41 | void PublishService(const std::string& service_type, |
Vitaly Buka | 7042c58 | 2015-07-30 17:02:14 -0700 | [diff] [blame] | 42 | uint16_t port, |
Alex Vakulenko | e32375b | 2015-09-28 08:55:40 -0700 | [diff] [blame] | 43 | const std::vector<std::string>& txt) override; |
| 44 | void StopPublishing(const std::string& service_type) override; |
Vitaly Buka | 7042c58 | 2015-07-30 17:02:14 -0700 | [diff] [blame] | 45 | |
| 46 | private: |
| 47 | void OnPeerdOnline(org::chromium::peerd::ManagerProxy* manager_proxy); |
| 48 | void OnPeerdOffline(const dbus::ObjectPath& object_path); |
Vitaly Buka | 7042c58 | 2015-07-30 17:02:14 -0700 | [diff] [blame] | 49 | |
| 50 | // Updates published information. Removes service if HTTP is not alive. |
| 51 | void Update(); |
| 52 | |
| 53 | void ExposeService(); |
| 54 | void RemoveService(); |
| 55 | |
| 56 | void UpdateImpl(); |
| 57 | |
| 58 | org::chromium::peerd::ObjectManagerProxy peerd_object_manager_proxy_; |
| 59 | // |peerd_manager_proxy_| is owned by |peerd_object_manager_proxy_|. |
| 60 | org::chromium::peerd::ManagerProxy* peerd_manager_proxy_{nullptr}; |
| 61 | |
Alex Vakulenko | e32375b | 2015-09-28 08:55:40 -0700 | [diff] [blame] | 62 | bool published_{false}; |
Vitaly Buka | 7042c58 | 2015-07-30 17:02:14 -0700 | [diff] [blame] | 63 | uint16_t port_{0}; |
Alex Vakulenko | e32375b | 2015-09-28 08:55:40 -0700 | [diff] [blame] | 64 | std::vector<std::string> txt_; |
Vitaly Buka | 7042c58 | 2015-07-30 17:02:14 -0700 | [diff] [blame] | 65 | |
| 66 | base::WeakPtrFactory<PeerdClient> restart_weak_ptr_factory_{this}; |
| 67 | base::WeakPtrFactory<PeerdClient> weak_ptr_factory_{this}; |
| 68 | |
| 69 | DISALLOW_COPY_AND_ASSIGN(PeerdClient); |
| 70 | }; |
| 71 | |
| 72 | } // namespace buffet |
| 73 | |
Vitaly Buka | 58a288b | 2015-07-31 00:33:31 -0700 | [diff] [blame] | 74 | #endif // BUFFET_PEERD_CLIENT_H_ |