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.
5 #ifndef DEVICE_BLUETOOTH_BLUETOOTH_REMOTE_GATT_CHARACTERISTIC_CHROMEOS_H_
6 #define DEVICE_BLUETOOTH_BLUETOOTH_REMOTE_GATT_CHARACTERISTIC_CHROMEOS_H_
12 #include "base/memory/weak_ptr.h"
13 #include "chromeos/dbus/bluetooth_gatt_descriptor_client.h"
14 #include "dbus/object_path.h"
15 #include "device/bluetooth/bluetooth_gatt_characteristic.h"
16 #include "device/bluetooth/bluetooth_uuid.h"
20 class BluetoothGattDescriptor
;
21 class BluetoothGattService
;
27 class BluetoothRemoteGattDescriptorChromeOS
;
28 class BluetoothRemoteGattServiceChromeOS
;
30 // The BluetoothRemoteGattCharacteristicChromeOS class implements
31 // BluetoothGattCharacteristic for remote GATT characteristics on the Chrome OS
33 class BluetoothRemoteGattCharacteristicChromeOS
34 : public device::BluetoothGattCharacteristic
,
35 public BluetoothGattDescriptorClient::Observer
{
37 // device::BluetoothGattCharacteristic overrides.
38 virtual std::string
GetIdentifier() const OVERRIDE
;
39 virtual device::BluetoothUUID
GetUUID() const OVERRIDE
;
40 virtual bool IsLocal() const OVERRIDE
;
41 virtual const std::vector
<uint8
>& GetValue() const OVERRIDE
;
42 virtual device::BluetoothGattService
* GetService() const OVERRIDE
;
43 virtual Properties
GetProperties() const OVERRIDE
;
44 virtual Permissions
GetPermissions() const OVERRIDE
;
45 virtual std::vector
<device::BluetoothGattDescriptor
*>
46 GetDescriptors() const OVERRIDE
;
47 virtual bool AddDescriptor(
48 device::BluetoothGattDescriptor
* descriptor
) OVERRIDE
;
49 virtual bool UpdateValue(const std::vector
<uint8
>& value
) OVERRIDE
;
50 virtual void ReadRemoteCharacteristic(
51 const ValueCallback
& callback
,
52 const ErrorCallback
& error_callback
) OVERRIDE
;
53 virtual void WriteRemoteCharacteristic(
54 const std::vector
<uint8
>& new_value
,
55 const base::Closure
& callback
,
56 const ErrorCallback
& error_callback
) OVERRIDE
;
58 // Object path of the underlying D-Bus characteristic.
59 const dbus::ObjectPath
& object_path() const { return object_path_
; }
62 friend class BluetoothRemoteGattServiceChromeOS
;
64 BluetoothRemoteGattCharacteristicChromeOS(
65 BluetoothRemoteGattServiceChromeOS
* service
,
66 const dbus::ObjectPath
& object_path
);
67 virtual ~BluetoothRemoteGattCharacteristicChromeOS();
69 // BluetoothGattDescriptorClient::Observer overrides.
70 virtual void GattDescriptorAdded(
71 const dbus::ObjectPath
& object_path
) OVERRIDE
;
72 virtual void GattDescriptorRemoved(
73 const dbus::ObjectPath
& object_path
) OVERRIDE
;
74 virtual void GattDescriptorPropertyChanged(
75 const dbus::ObjectPath
& object_path
,
76 const std::string
& property_name
) OVERRIDE
;
78 // Called by dbus:: on completion of the request to get the characteristic
80 void OnGetValue(const ValueCallback
& callback
,
81 const ErrorCallback
& error_callback
,
84 // Called by dbus:: on completion of the request to set the characteristic
86 void OnSetValue(const base::Closure
& callback
,
87 const ErrorCallback
& error_callback
,
90 // Object path of the D-Bus characteristic object.
91 dbus::ObjectPath object_path_
;
93 // The GATT service this GATT characteristic belongs to.
94 BluetoothRemoteGattServiceChromeOS
* service_
;
96 // Mapping from GATT descriptor object paths to descriptor objects owned by
97 // this characteristic. Since the Chrome OS implementation uses object paths
98 // as unique identifiers, we also use this mapping to return descriptors by
100 typedef std::map
<dbus::ObjectPath
, BluetoothRemoteGattDescriptorChromeOS
*>
102 DescriptorMap descriptors_
;
104 // Note: This should remain the last member so it'll be destroyed and
105 // invalidate its weak pointers before any other members are destroyed.
106 base::WeakPtrFactory
<BluetoothRemoteGattCharacteristicChromeOS
>
109 DISALLOW_COPY_AND_ASSIGN(BluetoothRemoteGattCharacteristicChromeOS
);
112 } // namespace chromeos
114 #endif // DEVICE_BLUETOOTH_BLUETOOTH_REMOTE_GATT_CHARACTERISTIC_CHROMEOS_H_