Upstream version 5.34.104.0
[platform/framework/web/crosswalk.git] / src / device / bluetooth / bluetooth_adapter_chromeos.h
1 // Copyright 2013 The Chromium 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
5 #ifndef DEVICE_BLUETOOTH_BLUETOOTH_ADAPTER_CHROMEOS_H_
6 #define DEVICE_BLUETOOTH_BLUETOOTH_ADAPTER_CHROMEOS_H_
7
8 #include <string>
9
10 #include "base/memory/weak_ptr.h"
11 #include "chromeos/dbus/bluetooth_adapter_client.h"
12 #include "chromeos/dbus/bluetooth_device_client.h"
13 #include "chromeos/dbus/bluetooth_input_client.h"
14 #include "dbus/object_path.h"
15 #include "device/bluetooth/bluetooth_adapter.h"
16
17 namespace device {
18
19 class BluetoothAdapterFactory;
20
21 }  // namespace device
22
23 namespace chromeos {
24
25 class BluetoothChromeOSTest;
26 class BluetoothDeviceChromeOS;
27
28 // The BluetoothAdapterChromeOS class implements BluetoothAdapter for the
29 // Chrome OS platform.
30 class BluetoothAdapterChromeOS
31     : public device::BluetoothAdapter,
32       private chromeos::BluetoothAdapterClient::Observer,
33       private chromeos::BluetoothDeviceClient::Observer,
34       private chromeos::BluetoothInputClient::Observer {
35  public:
36   // BluetoothAdapter override
37   virtual void AddObserver(
38       device::BluetoothAdapter::Observer* observer) OVERRIDE;
39   virtual void RemoveObserver(
40       device::BluetoothAdapter::Observer* observer) OVERRIDE;
41   virtual std::string GetAddress() const OVERRIDE;
42   virtual std::string GetName() const OVERRIDE;
43   virtual void SetName(const std::string& name,
44                        const base::Closure& callback,
45                        const ErrorCallback& error_callback) OVERRIDE;
46   virtual bool IsInitialized() const OVERRIDE;
47   virtual bool IsPresent() const OVERRIDE;
48   virtual bool IsPowered() const OVERRIDE;
49   virtual void SetPowered(
50       bool powered,
51       const base::Closure& callback,
52       const ErrorCallback& error_callback) OVERRIDE;
53   virtual bool IsDiscoverable() const OVERRIDE;
54   virtual void SetDiscoverable(
55       bool discoverable,
56       const base::Closure& callback,
57       const ErrorCallback& error_callback) OVERRIDE;
58   virtual bool IsDiscovering() const OVERRIDE;
59   virtual void StartDiscovering(
60       const base::Closure& callback,
61       const ErrorCallback& error_callback) OVERRIDE;
62   virtual void StopDiscovering(
63       const base::Closure& callback,
64       const ErrorCallback& error_callback) OVERRIDE;
65   virtual void ReadLocalOutOfBandPairingData(
66       const device::BluetoothAdapter::BluetoothOutOfBandPairingDataCallback&
67           callback,
68       const ErrorCallback& error_callback) OVERRIDE;
69
70  private:
71   friend class device::BluetoothAdapterFactory;
72   friend class BluetoothChromeOSTest;
73   friend class BluetoothDeviceChromeOS;
74   friend class BluetoothProfileChromeOS;
75   friend class BluetoothProfileChromeOSTest;
76
77   BluetoothAdapterChromeOS();
78   virtual ~BluetoothAdapterChromeOS();
79
80   // BluetoothAdapterClient::Observer override.
81   virtual void AdapterAdded(const dbus::ObjectPath& object_path) OVERRIDE;
82   virtual void AdapterRemoved(const dbus::ObjectPath& object_path) OVERRIDE;
83   virtual void AdapterPropertyChanged(
84       const dbus::ObjectPath& object_path,
85       const std::string& property_name) OVERRIDE;
86
87   // BluetoothDeviceClient::Observer override.
88   virtual void DeviceAdded(const dbus::ObjectPath& object_path) OVERRIDE;
89   virtual void DeviceRemoved(const dbus::ObjectPath& object_path) OVERRIDE;
90   virtual void DevicePropertyChanged(const dbus::ObjectPath& object_path,
91                                      const std::string& property_name) OVERRIDE;
92
93   // BluetoothInputClient::Observer override.
94   virtual void InputPropertyChanged(const dbus::ObjectPath& object_path,
95                                     const std::string& property_name) OVERRIDE;
96
97   // Internal method used to locate the device object by object path
98   // (the devices map and BluetoothDevice methods are by address)
99   BluetoothDeviceChromeOS* GetDeviceWithPath(
100       const dbus::ObjectPath& object_path);
101
102   // Set the tracked adapter to the one in |object_path|, this object will
103   // subsequently operate on that adapter until it is removed.
104   void SetAdapter(const dbus::ObjectPath& object_path);
105
106   // Set the adapter name to one chosen from the system information.
107   void SetDefaultAdapterName();
108
109   // Remove the currently tracked adapter. IsPresent() will return false after
110   // this is called.
111   void RemoveAdapter();
112
113   // Announce to observers a change in the adapter state.
114   void PoweredChanged(bool powered);
115   void DiscoverableChanged(bool discoverable);
116   void DiscoveringChanged(bool discovering);
117   void PresentChanged(bool present);
118
119   // Announce to observers a change in device state that is not reflected by
120   // its D-Bus properties.
121   void NotifyDeviceChanged(BluetoothDeviceChromeOS* device);
122
123   // Called by dbus:: on completion of the discoverable property change.
124   void OnSetDiscoverable(const base::Closure& callback,
125                          const ErrorCallback& error_callback,
126                          bool success);
127
128   // Called by dbus:: on completion of an adapter property change.
129   void OnPropertyChangeCompleted(const base::Closure& callback,
130                                  const ErrorCallback& error_callback,
131                                  bool success);
132
133   // Called by dbus:: on completion of the D-Bus method call to start discovery.
134   void OnStartDiscovery(const base::Closure& callback);
135   void OnStartDiscoveryError(const ErrorCallback& error_callback,
136                              const std::string& error_name,
137                              const std::string& error_message);
138
139   // Called by dbus:: on completion of the D-Bus method call to stop discovery.
140   void OnStopDiscovery(const base::Closure& callback);
141   void OnStopDiscoveryError(const ErrorCallback& error_callback,
142                             const std::string& error_name,
143                             const std::string& error_message);
144
145   // Object path of the adapter we track.
146   dbus::ObjectPath object_path_;
147
148   // List of observers interested in event notifications from us.
149   ObserverList<device::BluetoothAdapter::Observer> observers_;
150
151   // Note: This should remain the last member so it'll be destroyed and
152   // invalidate its weak pointers before any other members are destroyed.
153   base::WeakPtrFactory<BluetoothAdapterChromeOS> weak_ptr_factory_;
154
155   DISALLOW_COPY_AND_ASSIGN(BluetoothAdapterChromeOS);
156 };
157
158 }  // namespace chromeos
159
160 #endif  // DEVICE_BLUETOOTH_BLUETOOTH_ADAPTER_CHROMEOS_H_