OLD | NEW |
(Empty) | |
| 1 // Copyright (c) 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_DEVICE_EXPERIMENTAL_CHROMEOS_H |
| 6 #define DEVICE_BLUETOOTH_BLUETOOTH_DEVICE_EXPERIMENTAL_CHROMEOS_H |
| 7 |
| 8 #include <string> |
| 9 |
| 10 #include "base/memory/scoped_ptr.h" |
| 11 #include "base/memory/weak_ptr.h" |
| 12 #include "chromeos/dbus/experimental_bluetooth_agent_service_provider.h" |
| 13 #include "chromeos/dbus/experimental_bluetooth_device_client.h" |
| 14 #include "dbus/object_path.h" |
| 15 #include "device/bluetooth/bluetooth_device.h" |
| 16 |
| 17 namespace chromeos { |
| 18 |
| 19 class BluetoothAdapterExperimentalChromeOS; |
| 20 |
| 21 // The BluetoothDeviceExperimentalChromeOS class is an alternate implementation |
| 22 // of BluetoothDevice for the Chrome OS platform using the Bluetooth Smart |
| 23 // capable backend. It will become the sole implementation for Chrome OS, and |
| 24 // be renamed to BluetoothDeviceChromeOS, once the backend is switched. |
| 25 class BluetoothDeviceExperimentalChromeOS |
| 26 : public device::BluetoothDevice, |
| 27 private chromeos::ExperimentalBluetoothAgentServiceProvider::Delegate { |
| 28 public: |
| 29 // BluetoothDevice override |
| 30 virtual std::string GetAddress() const OVERRIDE; |
| 31 virtual bool IsPaired() const OVERRIDE; |
| 32 virtual bool IsConnected() const OVERRIDE; |
| 33 virtual bool IsConnectable() const OVERRIDE; |
| 34 virtual bool IsConnecting() const OVERRIDE; |
| 35 virtual ServiceList GetServices() const OVERRIDE; |
| 36 virtual void GetServiceRecords( |
| 37 const ServiceRecordsCallback& callback, |
| 38 const ErrorCallback& error_callback) OVERRIDE; |
| 39 virtual void ProvidesServiceWithName( |
| 40 const std::string& name, |
| 41 const ProvidesServiceCallback& callback) OVERRIDE; |
| 42 virtual bool ExpectingPinCode() const OVERRIDE; |
| 43 virtual bool ExpectingPasskey() const OVERRIDE; |
| 44 virtual bool ExpectingConfirmation() const OVERRIDE; |
| 45 virtual void Connect( |
| 46 device::BluetoothDevice::PairingDelegate* pairing_delegate, |
| 47 const base::Closure& callback, |
| 48 const ConnectErrorCallback& error_callback) OVERRIDE; |
| 49 virtual void SetPinCode(const std::string& pincode) OVERRIDE; |
| 50 virtual void SetPasskey(uint32 passkey) OVERRIDE; |
| 51 virtual void ConfirmPairing() OVERRIDE; |
| 52 virtual void RejectPairing() OVERRIDE; |
| 53 virtual void CancelPairing() OVERRIDE; |
| 54 virtual void Disconnect( |
| 55 const base::Closure& callback, |
| 56 const ErrorCallback& error_callback) OVERRIDE; |
| 57 virtual void Forget(const ErrorCallback& error_callback) OVERRIDE; |
| 58 virtual void ConnectToService( |
| 59 const std::string& service_uuid, |
| 60 const SocketCallback& callback) OVERRIDE; |
| 61 virtual void SetOutOfBandPairingData( |
| 62 const device::BluetoothOutOfBandPairingData& data, |
| 63 const base::Closure& callback, |
| 64 const ErrorCallback& error_callback) OVERRIDE; |
| 65 virtual void ClearOutOfBandPairingData( |
| 66 const base::Closure& callback, |
| 67 const ErrorCallback& error_callback) OVERRIDE; |
| 68 |
| 69 protected: |
| 70 // BluetoothDevice override |
| 71 virtual uint32 GetBluetoothClass() const OVERRIDE; |
| 72 virtual std::string GetDeviceName() const OVERRIDE; |
| 73 |
| 74 private: |
| 75 friend class BluetoothAdapterExperimentalChromeOS; |
| 76 |
| 77 BluetoothDeviceExperimentalChromeOS( |
| 78 BluetoothAdapterExperimentalChromeOS* adapter, |
| 79 const dbus::ObjectPath& object_path); |
| 80 virtual ~BluetoothDeviceExperimentalChromeOS(); |
| 81 |
| 82 // ExperimentalBluetoothAgentServiceProvider::Delegate override. |
| 83 virtual void Release() OVERRIDE; |
| 84 virtual void RequestPinCode(const dbus::ObjectPath& device_path, |
| 85 const PinCodeCallback& callback) OVERRIDE; |
| 86 virtual void DisplayPinCode(const dbus::ObjectPath& device_path, |
| 87 const std::string& pincode) OVERRIDE; |
| 88 virtual void RequestPasskey(const dbus::ObjectPath& device_path, |
| 89 const PasskeyCallback& callback) OVERRIDE; |
| 90 virtual void DisplayPasskey(const dbus::ObjectPath& device_path, |
| 91 uint32 passkey, int16 entered) OVERRIDE; |
| 92 virtual void RequestConfirmation(const dbus::ObjectPath& device_path, |
| 93 uint32 passkey, |
| 94 const ConfirmationCallback& callback) |
| 95 OVERRIDE; |
| 96 virtual void RequestAuthorization(const dbus::ObjectPath& device_path, |
| 97 const ConfirmationCallback& callback) |
| 98 OVERRIDE; |
| 99 virtual void AuthorizeService(const dbus::ObjectPath& device_path, |
| 100 const std::string& uuid, |
| 101 const ConfirmationCallback& callback) OVERRIDE; |
| 102 virtual void Cancel() OVERRIDE; |
| 103 |
| 104 // Internal method to initiate a connection to this device, and methods called |
| 105 // by dbus:: on completion of the D-Bus method call. |
| 106 void ConnectInternal(const base::Closure& callback, |
| 107 const ConnectErrorCallback& error_callback); |
| 108 void OnConnect(const base::Closure& callback); |
| 109 void OnConnectError(const ConnectErrorCallback& error_callback, |
| 110 const std::string& error_name, |
| 111 const std::string& error_message); |
| 112 |
| 113 // Called by dbus:: on completion of the D-Bus method call to register the |
| 114 // pairing agent. |
| 115 void OnRegisterAgent(const base::Closure& callback, |
| 116 const ConnectErrorCallback& error_callback); |
| 117 void OnRegisterAgentError(const ConnectErrorCallback& error_callback, |
| 118 const std::string& error_name, |
| 119 const std::string& error_message); |
| 120 |
| 121 // Called by dbus:: on completion of the D-Bus method call to pair the device. |
| 122 void OnPair(const base::Closure& callback, |
| 123 const ConnectErrorCallback& error_callback); |
| 124 void OnPairError(const ConnectErrorCallback& error_callback, |
| 125 const std::string& error_name, |
| 126 const std::string& error_message); |
| 127 |
| 128 // Called by dbus:: on failure of the D-Bus method call to cancel pairing, |
| 129 // there is no matching completion call since we don't do anything special |
| 130 // in that case. |
| 131 void OnCancelPairingError(const std::string& error_name, |
| 132 const std::string& error_message); |
| 133 |
| 134 // Called by dbus:: on completion of the trusted property change. |
| 135 void OnSetTrusted(bool success); |
| 136 |
| 137 // Internal method to unregister the pairing agent and method called by dbus:: |
| 138 // on failure of the D-Bus method call. No completion call as success is |
| 139 // ignored. |
| 140 void UnregisterAgent(); |
| 141 void OnUnregisterAgentError(const std::string& error_name, |
| 142 const std::string& error_message); |
| 143 |
| 144 // Called by dbus:: on completion of the D-Bus method call to disconnect the |
| 145 // device. |
| 146 void OnDisconnect(const base::Closure& callback); |
| 147 void OnDisconnectError(const ErrorCallback& error_callback, |
| 148 const std::string& error_name, |
| 149 const std::string& error_message); |
| 150 |
| 151 // Called by dbus:: on failure of the D-Bus method call to unpair the device; |
| 152 // there is no matching completion call since this object is deleted in the |
| 153 // process of unpairing. |
| 154 void OnForgetError(const ErrorCallback& error_callback, |
| 155 const std::string& error_name, |
| 156 const std::string& error_message); |
| 157 |
| 158 // Run any outstanding pairing callbacks passing |status| as the result of |
| 159 // pairing. Returns true if any callbacks were run, false if not. |
| 160 bool RunPairingCallbacks(Status status); |
| 161 |
| 162 // Return the object path of the device; used by |
| 163 // BluetoothAdapterExperimentalChromeOS |
| 164 const dbus::ObjectPath& object_path() const { return object_path_; } |
| 165 |
| 166 // The adapter that owns this device instance. |
| 167 BluetoothAdapterExperimentalChromeOS* adapter_; |
| 168 |
| 169 // The dbus object path of the device object. |
| 170 dbus::ObjectPath object_path_; |
| 171 |
| 172 // Number of ongoing calls to Connect(). |
| 173 int num_connecting_calls_; |
| 174 |
| 175 // During pairing this is set to an object that we don't own, but on which |
| 176 // we can make method calls to request, display or confirm PIN Codes and |
| 177 // Passkeys. Generally it is the object that owns this one. |
| 178 PairingDelegate* pairing_delegate_; |
| 179 |
| 180 // During pairing this is set to an instance of a D-Bus agent object |
| 181 // intialized with our own class as its delegate. |
| 182 scoped_ptr<ExperimentalBluetoothAgentServiceProvider> agent_; |
| 183 |
| 184 // During pairing these callbacks are set to those provided by method calls |
| 185 // made on us by |agent_| and are called by our own method calls such as |
| 186 // SetPinCode() and SetPasskey(). |
| 187 PinCodeCallback pincode_callback_; |
| 188 PasskeyCallback passkey_callback_; |
| 189 ConfirmationCallback confirmation_callback_; |
| 190 |
| 191 // Note: This should remain the last member so it'll be destroyed and |
| 192 // invalidate its weak pointers before any other members are destroyed. |
| 193 base::WeakPtrFactory<BluetoothDeviceExperimentalChromeOS> weak_ptr_factory_; |
| 194 |
| 195 DISALLOW_COPY_AND_ASSIGN(BluetoothDeviceExperimentalChromeOS); |
| 196 }; |
| 197 |
| 198 } // namespace chromeos |
| 199 |
| 200 #endif /* DEVICE_BLUETOOTH_BLUETOOTH_DEVICE_EXPERIMENTAL_CHROMEOS_H */ |
OLD | NEW |