OLD | NEW |
1 // Copyright 2014 The Chromium Authors. All rights reserved. | 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 | 2 // Use of this source code is governed by a BSD-style license that can be |
3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
4 | 4 |
5 #ifndef DEVICE_BLUETOOTH_BLUETOOTH_REMOTE_GATT_CHARACTERISTIC_CHROMEOS_H_ | 5 #ifndef DEVICE_BLUETOOTH_BLUETOOTH_REMOTE_GATT_CHARACTERISTIC_CHROMEOS_H_ |
6 #define DEVICE_BLUETOOTH_BLUETOOTH_REMOTE_GATT_CHARACTERISTIC_CHROMEOS_H_ | 6 #define DEVICE_BLUETOOTH_BLUETOOTH_REMOTE_GATT_CHARACTERISTIC_CHROMEOS_H_ |
7 | 7 |
8 #include <map> | 8 #include <map> |
9 #include <string> | 9 #include <string> |
10 #include <vector> | 10 #include <vector> |
11 | 11 |
12 #include "base/memory/weak_ptr.h" | 12 #include "base/memory/weak_ptr.h" |
| 13 #include "chromeos/dbus/bluetooth_gatt_characteristic_client.h" |
13 #include "chromeos/dbus/bluetooth_gatt_descriptor_client.h" | 14 #include "chromeos/dbus/bluetooth_gatt_descriptor_client.h" |
14 #include "dbus/object_path.h" | 15 #include "dbus/object_path.h" |
15 #include "device/bluetooth/bluetooth_gatt_characteristic.h" | 16 #include "device/bluetooth/bluetooth_gatt_characteristic.h" |
16 #include "device/bluetooth/bluetooth_uuid.h" | 17 #include "device/bluetooth/bluetooth_uuid.h" |
17 | 18 |
18 namespace device { | 19 namespace device { |
19 | 20 |
20 class BluetoothGattDescriptor; | 21 class BluetoothGattDescriptor; |
21 class BluetoothGattService; | 22 class BluetoothGattService; |
22 | 23 |
23 } // namespace device | 24 } // namespace device |
24 | 25 |
25 namespace chromeos { | 26 namespace chromeos { |
26 | 27 |
27 class BluetoothRemoteGattDescriptorChromeOS; | 28 class BluetoothRemoteGattDescriptorChromeOS; |
28 class BluetoothRemoteGattServiceChromeOS; | 29 class BluetoothRemoteGattServiceChromeOS; |
29 | 30 |
30 // The BluetoothRemoteGattCharacteristicChromeOS class implements | 31 // The BluetoothRemoteGattCharacteristicChromeOS class implements |
31 // BluetoothGattCharacteristic for remote GATT characteristics on the Chrome OS | 32 // BluetoothGattCharacteristic for remote GATT characteristics on the Chrome OS |
32 // platform. | 33 // platform. |
33 class BluetoothRemoteGattCharacteristicChromeOS | 34 class BluetoothRemoteGattCharacteristicChromeOS |
34 : public device::BluetoothGattCharacteristic, | 35 : public device::BluetoothGattCharacteristic, |
| 36 public BluetoothGattCharacteristicClient::Observer, |
35 public BluetoothGattDescriptorClient::Observer { | 37 public BluetoothGattDescriptorClient::Observer { |
36 public: | 38 public: |
37 // device::BluetoothGattCharacteristic overrides. | 39 // device::BluetoothGattCharacteristic overrides. |
38 virtual std::string GetIdentifier() const OVERRIDE; | 40 virtual std::string GetIdentifier() const OVERRIDE; |
39 virtual device::BluetoothUUID GetUUID() const OVERRIDE; | 41 virtual device::BluetoothUUID GetUUID() const OVERRIDE; |
40 virtual bool IsLocal() const OVERRIDE; | 42 virtual bool IsLocal() const OVERRIDE; |
41 virtual const std::vector<uint8>& GetValue() const OVERRIDE; | 43 virtual const std::vector<uint8>& GetValue() const OVERRIDE; |
42 virtual device::BluetoothGattService* GetService() const OVERRIDE; | 44 virtual device::BluetoothGattService* GetService() const OVERRIDE; |
43 virtual Properties GetProperties() const OVERRIDE; | 45 virtual Properties GetProperties() const OVERRIDE; |
44 virtual Permissions GetPermissions() const OVERRIDE; | 46 virtual Permissions GetPermissions() const OVERRIDE; |
(...skipping 16 matching lines...) Expand all Loading... |
61 const dbus::ObjectPath& object_path() const { return object_path_; } | 63 const dbus::ObjectPath& object_path() const { return object_path_; } |
62 | 64 |
63 private: | 65 private: |
64 friend class BluetoothRemoteGattServiceChromeOS; | 66 friend class BluetoothRemoteGattServiceChromeOS; |
65 | 67 |
66 BluetoothRemoteGattCharacteristicChromeOS( | 68 BluetoothRemoteGattCharacteristicChromeOS( |
67 BluetoothRemoteGattServiceChromeOS* service, | 69 BluetoothRemoteGattServiceChromeOS* service, |
68 const dbus::ObjectPath& object_path); | 70 const dbus::ObjectPath& object_path); |
69 virtual ~BluetoothRemoteGattCharacteristicChromeOS(); | 71 virtual ~BluetoothRemoteGattCharacteristicChromeOS(); |
70 | 72 |
| 73 // BluetoothGattCharacteristicClient::Observer overrides. |
| 74 virtual void GattCharacteristicValueUpdated( |
| 75 const dbus::ObjectPath& object_path, |
| 76 const std::vector<uint8>& value) OVERRIDE; |
| 77 |
71 // BluetoothGattDescriptorClient::Observer overrides. | 78 // BluetoothGattDescriptorClient::Observer overrides. |
72 virtual void GattDescriptorAdded( | 79 virtual void GattDescriptorAdded( |
73 const dbus::ObjectPath& object_path) OVERRIDE; | 80 const dbus::ObjectPath& object_path) OVERRIDE; |
74 virtual void GattDescriptorRemoved( | 81 virtual void GattDescriptorRemoved( |
75 const dbus::ObjectPath& object_path) OVERRIDE; | 82 const dbus::ObjectPath& object_path) OVERRIDE; |
76 virtual void GattDescriptorPropertyChanged( | 83 virtual void GattDescriptorPropertyChanged( |
77 const dbus::ObjectPath& object_path, | 84 const dbus::ObjectPath& object_path, |
78 const std::string& property_name) OVERRIDE; | 85 const std::string& property_name) OVERRIDE; |
79 | 86 |
80 // Called by dbus:: on completion of the request to get the characteristic | 87 // Called by dbus:: on successful completion of a request to read |
81 // value. | 88 // the characteristic value. |
82 void OnGetValue(const ValueCallback& callback, | 89 void OnValueSuccess(const ValueCallback& callback, |
83 const ErrorCallback& error_callback, | 90 const std::vector<uint8>& value); |
84 bool success); | |
85 | 91 |
86 // Called by dbus:: on completion of the request to set the characteristic | 92 // Called by dbus:: on unsuccessful completion of a request to read or write |
87 // value. | 93 // the characteristic value. |
88 void OnSetValue(const base::Closure& callback, | 94 void OnError(const ErrorCallback& error_callback, |
89 const ErrorCallback& error_callback, | 95 const std::string& error_name, |
90 bool success); | 96 const std::string& error_message); |
91 | 97 |
92 // Object path of the D-Bus characteristic object. | 98 // Object path of the D-Bus characteristic object. |
93 dbus::ObjectPath object_path_; | 99 dbus::ObjectPath object_path_; |
94 | 100 |
95 // The GATT service this GATT characteristic belongs to. | 101 // The GATT service this GATT characteristic belongs to. |
96 BluetoothRemoteGattServiceChromeOS* service_; | 102 BluetoothRemoteGattServiceChromeOS* service_; |
97 | 103 |
| 104 // The cached characteristic value based on the most recent read or |
| 105 // notification. |
| 106 std::vector<uint8> cached_value_; |
| 107 |
98 // Mapping from GATT descriptor object paths to descriptor objects owned by | 108 // Mapping from GATT descriptor object paths to descriptor objects owned by |
99 // this characteristic. Since the Chrome OS implementation uses object paths | 109 // this characteristic. Since the Chrome OS implementation uses object paths |
100 // as unique identifiers, we also use this mapping to return descriptors by | 110 // as unique identifiers, we also use this mapping to return descriptors by |
101 // identifier. | 111 // identifier. |
102 typedef std::map<dbus::ObjectPath, BluetoothRemoteGattDescriptorChromeOS*> | 112 typedef std::map<dbus::ObjectPath, BluetoothRemoteGattDescriptorChromeOS*> |
103 DescriptorMap; | 113 DescriptorMap; |
104 DescriptorMap descriptors_; | 114 DescriptorMap descriptors_; |
105 | 115 |
106 // Note: This should remain the last member so it'll be destroyed and | 116 // Note: This should remain the last member so it'll be destroyed and |
107 // invalidate its weak pointers before any other members are destroyed. | 117 // invalidate its weak pointers before any other members are destroyed. |
108 base::WeakPtrFactory<BluetoothRemoteGattCharacteristicChromeOS> | 118 base::WeakPtrFactory<BluetoothRemoteGattCharacteristicChromeOS> |
109 weak_ptr_factory_; | 119 weak_ptr_factory_; |
110 | 120 |
111 DISALLOW_COPY_AND_ASSIGN(BluetoothRemoteGattCharacteristicChromeOS); | 121 DISALLOW_COPY_AND_ASSIGN(BluetoothRemoteGattCharacteristicChromeOS); |
112 }; | 122 }; |
113 | 123 |
114 } // namespace chromeos | 124 } // namespace chromeos |
115 | 125 |
116 #endif // DEVICE_BLUETOOTH_BLUETOOTH_REMOTE_GATT_CHARACTERISTIC_CHROMEOS_H_ | 126 #endif // DEVICE_BLUETOOTH_BLUETOOTH_REMOTE_GATT_CHARACTERISTIC_CHROMEOS_H_ |
OLD | NEW |