1 // Copyright 2014 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_REMOTE_GATT_DESCRIPTOR_CHROMEOS_H_ 6 #define DEVICE_BLUETOOTH_BLUETOOTH_REMOTE_GATT_DESCRIPTOR_CHROMEOS_H_ 7 8 #include <string> 9 #include <vector> 10 11 #include "base/memory/weak_ptr.h" 12 #include "dbus/object_path.h" 13 #include "device/bluetooth/bluetooth_gatt_descriptor.h" 14 #include "device/bluetooth/bluetooth_uuid.h" 15 16 namespace device { 17 18 class BluetoothGattCharacteristic; 19 20 } // namespace device 21 22 namespace chromeos { 23 24 class BluetoothRemoteGattCharacteristicChromeOS; 25 26 // The BluetoothRemoteGattDescriptorChromeOS class implements 27 // BluetoothGattDescriptor for remote GATT characteristic descriptors on the 28 // Chrome OS platform. 29 class BluetoothRemoteGattDescriptorChromeOS 30 : public device::BluetoothGattDescriptor { 31 public: 32 // device::BluetoothGattDescriptor overrides. 33 virtual std::string GetIdentifier() const OVERRIDE; 34 virtual device::BluetoothUUID GetUUID() const OVERRIDE; 35 virtual bool IsLocal() const OVERRIDE; 36 virtual const std::vector<uint8>& GetValue() const OVERRIDE; 37 virtual device::BluetoothGattCharacteristic* 38 GetCharacteristic() const OVERRIDE; 39 virtual device::BluetoothGattCharacteristic::Permissions 40 GetPermissions() const OVERRIDE; 41 virtual void ReadRemoteDescriptor( 42 const ValueCallback& callback, 43 const ErrorCallback& error_callback) OVERRIDE; 44 virtual void WriteRemoteDescriptor( 45 const std::vector<uint8>& new_value, 46 const base::Closure& callback, 47 const ErrorCallback& error_callback) OVERRIDE; 48 49 // Object path of the underlying D-Bus characteristic. object_path()50 const dbus::ObjectPath& object_path() const { return object_path_; } 51 52 private: 53 friend class BluetoothRemoteGattCharacteristicChromeOS; 54 55 BluetoothRemoteGattDescriptorChromeOS( 56 BluetoothRemoteGattCharacteristicChromeOS* characteristic, 57 const dbus::ObjectPath& object_path); 58 virtual ~BluetoothRemoteGattDescriptorChromeOS(); 59 60 // Called by dbus:: on successful completion of a request to read 61 // the descriptor value. 62 void OnValueSuccess(const ValueCallback& callback, 63 const std::vector<uint8>& value); 64 65 // Called by dbus:: on unsuccessful completion of a request to read or write 66 // the descriptor value. 67 void OnError(const ErrorCallback& error_callback, 68 const std::string& error_name, 69 const std::string& error_message); 70 71 // Object path of the D-Bus descriptor object. 72 dbus::ObjectPath object_path_; 73 74 // The GATT characteristic this descriptor belongs to. 75 BluetoothRemoteGattCharacteristicChromeOS* characteristic_; 76 77 // The cached characteristic value based on the most recent read request. 78 std::vector<uint8> cached_value_; 79 80 // Note: This should remain the last member so it'll be destroyed and 81 // invalidate its weak pointers before any other members are destroyed. 82 base::WeakPtrFactory<BluetoothRemoteGattDescriptorChromeOS> weak_ptr_factory_; 83 84 DISALLOW_COPY_AND_ASSIGN(BluetoothRemoteGattDescriptorChromeOS); 85 }; 86 87 } // namespace chromeos 88 89 #endif // DEVICE_BLUETOOTH_BLUETOOTH_REMOTE_GATT_DESCRIPTOR_CHROMEOS_H_ 90