Chromium Code Reviews| 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 ConnectToProfile( | |
| 62 device::BluetoothProfile* profile, | |
| 63 const ErrorCallback& error_callback) OVERRIDE; | |
| 64 virtual void SetOutOfBandPairingData( | |
| 65 const device::BluetoothOutOfBandPairingData& data, | |
| 66 const base::Closure& callback, | |
| 67 const ErrorCallback& error_callback) OVERRIDE; | |
| 68 virtual void ClearOutOfBandPairingData( | |
| 69 const base::Closure& callback, | |
| 70 const ErrorCallback& error_callback) OVERRIDE; | |
| 71 | |
| 72 protected: | |
| 73 // BluetoothDevice override | |
| 74 virtual uint32 GetBluetoothClass() const OVERRIDE; | |
| 75 virtual std::string GetDeviceName() const OVERRIDE; | |
| 76 | |
| 77 private: | |
| 78 friend class BluetoothAdapterExperimentalChromeOS; | |
| 79 | |
| 80 BluetoothDeviceExperimentalChromeOS( | |
| 81 BluetoothAdapterExperimentalChromeOS* adapter, | |
| 82 const dbus::ObjectPath& object_path); | |
| 83 virtual ~BluetoothDeviceExperimentalChromeOS(); | |
| 84 | |
| 85 // ExperimentalBluetoothAgentServiceProvider::Delegate override. | |
| 86 virtual void Release() OVERRIDE; | |
| 87 virtual void RequestPinCode(const dbus::ObjectPath& device_path, | |
| 88 const PinCodeCallback& callback) OVERRIDE; | |
| 89 virtual void DisplayPinCode(const dbus::ObjectPath& device_path, | |
| 90 const std::string& pincode) OVERRIDE; | |
| 91 virtual void RequestPasskey(const dbus::ObjectPath& device_path, | |
| 92 const PasskeyCallback& callback) OVERRIDE; | |
| 93 virtual void DisplayPasskey(const dbus::ObjectPath& device_path, | |
| 94 uint32 passkey, int16 entered) OVERRIDE; | |
| 95 virtual void RequestConfirmation(const dbus::ObjectPath& device_path, | |
| 96 uint32 passkey, | |
| 97 const ConfirmationCallback& callback) | |
| 98 OVERRIDE; | |
| 99 virtual void RequestAuthorization(const dbus::ObjectPath& device_path, | |
| 100 const ConfirmationCallback& callback) | |
| 101 OVERRIDE; | |
| 102 virtual void AuthorizeService(const dbus::ObjectPath& device_path, | |
| 103 const std::string& uuid, | |
| 104 const ConfirmationCallback& callback) OVERRIDE; | |
| 105 virtual void Cancel() OVERRIDE; | |
| 106 | |
| 107 void ConnectInternal(const base::Closure& callback, | |
| 108 const ConnectErrorCallback& error_callback); | |
| 109 void OnConnect(const base::Closure& callback); | |
| 110 void OnConnectError(const ConnectErrorCallback& error_callback, | |
| 111 const std::string& error_name, | |
| 112 const std::string& error_message); | |
| 113 | |
| 114 void OnRegisterAgent(const base::Closure& callback, | |
| 115 const ConnectErrorCallback& error_callback); | |
| 116 void OnRegisterAgentError(const ConnectErrorCallback& error_callback, | |
| 117 const std::string& error_name, | |
| 118 const std::string& error_message); | |
| 119 | |
| 120 void OnPair(const base::Closure& callback, | |
| 121 const ConnectErrorCallback& error_callback); | |
| 122 void OnPairError(const ConnectErrorCallback& error_callback, | |
| 123 const std::string& error_name, | |
| 124 const std::string& error_message); | |
| 125 | |
| 126 void OnCancelPairingError(const std::string& error_name, | |
| 127 const std::string& error_message); | |
| 128 | |
| 129 void OnSetTrusted(bool success); | |
| 130 | |
| 131 void UnregisterAgent(); | |
| 132 void OnUnregisterAgentError(const std::string& error_name, | |
| 133 const std::string& error_message); | |
| 134 | |
| 135 void OnDisconnect(const base::Closure& callback); | |
| 136 void OnDisconnectError(const ErrorCallback& error_callback, | |
| 137 const std::string& error_name, | |
| 138 const std::string& error_message); | |
| 139 | |
| 140 void OnForgetError(const ErrorCallback& error_callback, | |
| 141 const std::string& error_name, | |
| 142 const std::string& error_message); | |
| 143 | |
| 144 const dbus::ObjectPath& object_path() const { return object_path_; } | |
| 145 | |
| 146 // The adapter that owns this device instance. | |
| 147 BluetoothAdapterExperimentalChromeOS* adapter_; | |
| 148 | |
| 149 // The dbus object path of the device object. | |
| 150 dbus::ObjectPath object_path_; | |
| 151 | |
| 152 // Number of ongoing calls to Connect(). | |
| 153 int connecting_calls_; | |
|
satorux1
2013/04/16 06:30:45
maybe: num_connecting_calls_
keybuk
2013/04/16 23:19:13
Done.
| |
| 154 | |
| 155 // During pairing this is set to an object that we don't own, but on which | |
| 156 // we can make method calls to request, display or confirm PIN Codes and | |
| 157 // Passkeys. Generally it is the object that owns this one. | |
| 158 PairingDelegate* pairing_delegate_; | |
| 159 | |
| 160 // During pairing this is set to an instance of a D-Bus agent object | |
| 161 // intialized with our own class as its delegate. | |
| 162 scoped_ptr<ExperimentalBluetoothAgentServiceProvider> agent_; | |
| 163 | |
| 164 // During pairing these callbacks are set to those provided by method calls | |
| 165 // made on us by |agent_| and are called by our own method calls such as | |
| 166 // SetPinCode() and SetPasskey(). | |
| 167 PinCodeCallback pincode_callback_; | |
| 168 PasskeyCallback passkey_callback_; | |
| 169 ConfirmationCallback confirmation_callback_; | |
| 170 | |
| 171 // Note: This should remain the last member so it'll be destroyed and | |
| 172 // invalidate its weak pointers before any other members are destroyed. | |
| 173 base::WeakPtrFactory<BluetoothDeviceExperimentalChromeOS> weak_ptr_factory_; | |
| 174 | |
| 175 DISALLOW_COPY_AND_ASSIGN(BluetoothDeviceExperimentalChromeOS); | |
| 176 }; | |
| 177 | |
| 178 } // namespace chromeos | |
| 179 | |
| 180 #endif /* DEVICE_BLUETOOTH_BLUETOOTH_DEVICE_EXPERIMENTAL_CHROMEOS_H */ | |
| OLD | NEW |