blob: 8a783f06b6a9fa3eec640dd4914b6994a0708d55 [file] [log] [blame]
Vitaly Bukacad20f02015-10-16 17:27:15 -07001// 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 Buka7042c582015-07-30 17:02:14 -070014
Vitaly Buka58a288b2015-07-31 00:33:31 -070015#ifndef BUFFET_PEERD_CLIENT_H_
16#define BUFFET_PEERD_CLIENT_H_
Vitaly Buka7042c582015-07-30 17:02:14 -070017
Vitaly Buka7042c582015-07-30 17:02:14 -070018#include <memory>
19#include <string>
Alex Vakulenkoe32375b2015-09-28 08:55:40 -070020#include <vector>
Vitaly Buka7042c582015-07-30 17:02:14 -070021
22#include <base/callback.h>
23#include <base/memory/ref_counted.h>
Alex Vakulenkoe32375b2015-09-28 08:55:40 -070024#include <weave/provider/dns_service_discovery.h>
Vitaly Buka7042c582015-07-30 17:02:14 -070025
26#include "peerd/dbus-proxies.h"
Vitaly Buka7042c582015-07-30 17:02:14 -070027
28namespace dbus {
29class Bus;
30} // namespace dbus
31
32namespace buffet {
33
34// Publishes privet service on mDns using peerd.
Alex Vakulenkoe32375b2015-09-28 08:55:40 -070035class PeerdClient : public weave::provider::DnsServiceDiscovery {
Vitaly Buka7042c582015-07-30 17:02:14 -070036 public:
37 explicit PeerdClient(const scoped_refptr<dbus::Bus>& bus);
38 ~PeerdClient() override;
39
40 // Mdns implementation.
Alex Vakulenkoe32375b2015-09-28 08:55:40 -070041 void PublishService(const std::string& service_type,
Vitaly Buka7042c582015-07-30 17:02:14 -070042 uint16_t port,
Alex Vakulenkoe32375b2015-09-28 08:55:40 -070043 const std::vector<std::string>& txt) override;
44 void StopPublishing(const std::string& service_type) override;
Vitaly Buka7042c582015-07-30 17:02:14 -070045
46 private:
47 void OnPeerdOnline(org::chromium::peerd::ManagerProxy* manager_proxy);
48 void OnPeerdOffline(const dbus::ObjectPath& object_path);
Vitaly Buka7042c582015-07-30 17:02:14 -070049
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 Vakulenkoe32375b2015-09-28 08:55:40 -070062 bool published_{false};
Vitaly Buka7042c582015-07-30 17:02:14 -070063 uint16_t port_{0};
Alex Vakulenkoe32375b2015-09-28 08:55:40 -070064 std::vector<std::string> txt_;
Vitaly Buka7042c582015-07-30 17:02:14 -070065
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 Buka58a288b2015-07-31 00:33:31 -070074#endif // BUFFET_PEERD_CLIENT_H_