1//
2// Copyright (C) 2015 The Android Open Source Project
3//
4// Licensed under the Apache License, Version 2.0 (the "License");
5// you may not use this file except in compliance with the License.
6// You may obtain a copy of the License at
7//
8//      http://www.apache.org/licenses/LICENSE-2.0
9//
10// Unless required by applicable law or agreed to in writing, software
11// distributed under the License is distributed on an "AS IS" BASIS,
12// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13// See the License for the specific language governing permissions and
14// limitations under the License.
15//
16
17#ifndef SHILL_DBUS_CHROMEOS_WIMAX_MANAGER_PROXY_H_
18#define SHILL_DBUS_CHROMEOS_WIMAX_MANAGER_PROXY_H_
19
20#include <string>
21#include <vector>
22
23#include <base/macros.h>
24#include <wimax_manager/dbus-proxies.h>
25
26#include "shill/wimax/wimax_manager_proxy_interface.h"
27
28namespace shill {
29
30class EventDispatcher;
31
32class ChromeosWiMaxManagerProxy : public WiMaxManagerProxyInterface {
33 public:
34  explicit ChromeosWiMaxManagerProxy(
35      EventDispatcher* dispatcher,
36      const scoped_refptr<dbus::Bus>& bus,
37      const base::Closure& service_appeared_callback,
38      const base::Closure& service_vanished_callback);
39  ~ChromeosWiMaxManagerProxy() override;
40
41  // Inherited from WiMaxManagerProxyInterface.
42  void set_devices_changed_callback(
43      const DevicesChangedCallback& callback) override;
44  RpcIdentifiers Devices(Error* error) override;
45
46 private:
47  class PropertySet : public dbus::PropertySet {
48   public:
49    PropertySet(dbus::ObjectProxy* object_proxy,
50                const std::string& interface_name,
51                const PropertyChangedCallback& callback);
52    brillo::dbus_utils::Property<std::vector<dbus::ObjectPath>> devices;
53
54   private:
55    DISALLOW_COPY_AND_ASSIGN(PropertySet);
56  };
57
58  static const char kPropertyDevices[];
59
60  // Called when service appeared or vanished.
61  void OnServiceAvailable(bool available);
62
63  // Service name owner changed handler.
64  void OnServiceOwnerChanged(const std::string& old_owner,
65                             const std::string& new_owner);
66
67  // Signal callbacks inherited from WiMaxManager_proxy.
68  void DevicesChanged(const std::vector<dbus::ObjectPath>& devices);
69
70  // Callback invoked when the value of property |property_name| is changed.
71  void OnPropertyChanged(const std::string& property_name);
72
73  // Called when signal is connected to the ObjectProxy.
74  void OnSignalConnected(const std::string& interface_name,
75                         const std::string& signal_name,
76                         bool success);
77
78  std::unique_ptr<org::chromium::WiMaxManagerProxy> proxy_;
79  std::unique_ptr<PropertySet> properties_;
80  EventDispatcher* dispatcher_;
81  base::Closure service_appeared_callback_;
82  base::Closure service_vanished_callback_;
83  bool service_available_;
84  DevicesChangedCallback devices_changed_callback_;
85
86  base::WeakPtrFactory<ChromeosWiMaxManagerProxy> weak_factory_{this};
87  DISALLOW_COPY_AND_ASSIGN(ChromeosWiMaxManagerProxy);
88};
89
90}  // namespace shill
91
92#endif  // SHILL_DBUS_CHROMEOS_WIMAX_MANAGER_PROXY_H_
93