Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(709)

Side by Side Diff: device/bluetooth/bluetooth_remote_gatt_characteristic_mac.h

Issue 2595373003: Bluetooth: mac: Working on macOS descriptor implementation. (Closed)
Patch Set: Fixes Created 3 years, 11 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
1 // Copyright 2016 The Chromium Authors. All rights reserved. 1 // Copyright 2016 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_MAC_H_ 5 #ifndef DEVICE_BLUETOOTH_BLUETOOTH_REMOTE_GATT_CHARACTERISTIC_MAC_H_
6 #define DEVICE_BLUETOOTH_BLUETOOTH_REMOTE_GATT_CHARACTERISTIC_MAC_H_ 6 #define DEVICE_BLUETOOTH_BLUETOOTH_REMOTE_GATT_CHARACTERISTIC_MAC_H_
7 7
8 #include "device/bluetooth/bluetooth_remote_gatt_characteristic.h" 8 #include "device/bluetooth/bluetooth_remote_gatt_characteristic.h"
9 9
10 #include <unordered_map>
11
10 #include "base/mac/scoped_nsobject.h" 12 #include "base/mac/scoped_nsobject.h"
11 #include "base/memory/weak_ptr.h" 13 #include "base/memory/weak_ptr.h"
12 14
13 #if defined(__OBJC__) 15 #if defined(__OBJC__)
14 #import <CoreBluetooth/CoreBluetooth.h> 16 #import <CoreBluetooth/CoreBluetooth.h>
15 #else 17 #else
16 @class CBCharacteristic; 18 @class CBCharacteristic;
17 typedef NS_ENUM(NSInteger, CBCharacteristicWriteType); 19 typedef NS_ENUM(NSInteger, CBCharacteristicWriteType);
18 #endif // defined(__OBJC__) 20 #endif // defined(__OBJC__)
19 21
20 namespace device { 22 namespace device {
21 23
24 class BluetoothAdapterMac;
25 class BluetoothRemoteGattDescriptorMac;
22 class BluetoothRemoteGattServiceMac; 26 class BluetoothRemoteGattServiceMac;
23 27
24 // The BluetoothRemoteGattCharacteristicMac class implements 28 // The BluetoothRemoteGattCharacteristicMac class implements
25 // BluetoothRemoteGattCharacteristic for remote GATT services on OS X. 29 // BluetoothRemoteGattCharacteristic for remote GATT services on OS X.
26 class DEVICE_BLUETOOTH_EXPORT BluetoothRemoteGattCharacteristicMac 30 class DEVICE_BLUETOOTH_EXPORT BluetoothRemoteGattCharacteristicMac
27 : public BluetoothRemoteGattCharacteristic { 31 : public BluetoothRemoteGattCharacteristic {
28 public: 32 public:
29 BluetoothRemoteGattCharacteristicMac( 33 BluetoothRemoteGattCharacteristicMac(
30 BluetoothRemoteGattServiceMac* gatt_service, 34 BluetoothRemoteGattServiceMac* gatt_service,
31 CBCharacteristic* cb_characteristic); 35 CBCharacteristic* cb_characteristic);
(...skipping 27 matching lines...) Expand all
59 protected: 63 protected:
60 void SubscribeToNotifications(BluetoothRemoteGattDescriptor* ccc_descriptor, 64 void SubscribeToNotifications(BluetoothRemoteGattDescriptor* ccc_descriptor,
61 const base::Closure& callback, 65 const base::Closure& callback,
62 const ErrorCallback& error_callback) override; 66 const ErrorCallback& error_callback) override;
63 void UnsubscribeFromNotifications( 67 void UnsubscribeFromNotifications(
64 BluetoothRemoteGattDescriptor* ccc_descriptor, 68 BluetoothRemoteGattDescriptor* ccc_descriptor,
65 const base::Closure& callback, 69 const base::Closure& callback,
66 const ErrorCallback& error_callback) override; 70 const ErrorCallback& error_callback) override;
67 71
68 private: 72 private:
73 friend class BluetoothRemoteGattDescriptorMac;
69 friend class BluetoothRemoteGattServiceMac; 74 friend class BluetoothRemoteGattServiceMac;
70 friend class BluetoothTestMac; 75 friend class BluetoothTestMac;
71 76
77 void DiscoverDescriptors();
72 // Called by the BluetoothRemoteGattServiceMac instance when the 78 // Called by the BluetoothRemoteGattServiceMac instance when the
73 // characteristics value has been read. 79 // characteristics value has been read.
74 void DidUpdateValue(NSError* error); 80 void DidUpdateValue(NSError* error);
75 // Updates value_ and notifies the adapter of the new value. 81 // Updates value_ and notifies the adapter of the new value.
76 void UpdateValueAndNotify(); 82 void UpdateValueAndNotify();
77 // Called by the BluetoothRemoteGattServiceMac instance when the 83 // Called by the BluetoothRemoteGattServiceMac instance when the
78 // characteristics value has been written. 84 // characteristics value has been written.
79 void DidWriteValue(NSError* error); 85 void DidWriteValue(NSError* error);
80 // Called by the BluetoothRemoteGattServiceMac instance when the notify 86 // Called by the BluetoothRemoteGattServiceMac instance when the notify
81 // session has been started or failed to be started. 87 // session has been started or failed to be started.
82 void DidUpdateNotificationState(NSError* error); 88 void DidUpdateNotificationState(NSError* error);
89 // Called by the BluetoothRemoteGattServiceMac instance when the descriptors
90 // has been discovered.
91 void DidDiscoverDescriptors();
83 // Returns true if the characteristic is readable. 92 // Returns true if the characteristic is readable.
84 bool IsReadable() const; 93 bool IsReadable() const;
85 // Returns true if the characteristic is writable. 94 // Returns true if the characteristic is writable.
86 bool IsWritable() const; 95 bool IsWritable() const;
87 // Returns true if the characteristic supports notifications or indications. 96 // Returns true if the characteristic supports notifications or indications.
88 bool SupportsNotificationsOrIndications() const; 97 bool SupportsNotificationsOrIndications() const;
89 // Returns the write type (with or without responses). 98 // Returns the write type (with or without responses).
90 CBCharacteristicWriteType GetCBWriteType() const; 99 CBCharacteristicWriteType GetCBWriteType() const;
91 // Returns CoreBluetooth characteristic. 100 // Returns CoreBluetooth characteristic.
92 CBCharacteristic* GetCBCharacteristic() const; 101 CBCharacteristic* GetCBCharacteristic() const;
102 // Returns the mac adapter.
103 BluetoothAdapterMac* GetMacAdapter() const;
104 // Returns CoreBluetooth peripheral.
105 CBPeripheral* GetCBPeripheral() const;
93 // Returns true if this characteristic has been fully discovered. 106 // Returns true if this characteristic has been fully discovered.
94 bool IsDiscoveryComplete() const; 107 bool IsDiscoveryComplete() const;
95 108 // Returns BluetoothRemoteGattDescriptorMac from CBDescriptor.
109 BluetoothRemoteGattDescriptorMac* GetBluetoothRemoteGattDescriptorMac(
110 CBDescriptor* cb_descriptor) const;
111 // Is true if the characteristic has been discovered with all its descriptors.
112 bool is_discovery_complete_;
96 // gatt_service_ owns instances of this class. 113 // gatt_service_ owns instances of this class.
97 BluetoothRemoteGattServiceMac* gatt_service_; 114 BluetoothRemoteGattServiceMac* gatt_service_;
98 // A characteristic from CBPeripheral.services.characteristics. 115 // A characteristic from CBPeripheral.services.characteristics.
99 base::scoped_nsobject<CBCharacteristic> cb_characteristic_; 116 base::scoped_nsobject<CBCharacteristic> cb_characteristic_;
100 // Characteristic identifier. 117 // Characteristic identifier.
101 std::string identifier_; 118 std::string identifier_;
102 // Service UUID. 119 // Service UUID.
103 BluetoothUUID uuid_; 120 BluetoothUUID uuid_;
104 // Characteristic value. 121 // Characteristic value.
105 std::vector<uint8_t> value_; 122 std::vector<uint8_t> value_;
106 // True if a gatt read or write request is in progress. 123 // True if a gatt read or write request is in progress.
107 bool characteristic_value_read_or_write_in_progress_; 124 bool characteristic_value_read_or_write_in_progress_;
108 // ReadRemoteCharacteristic request callbacks. 125 // ReadRemoteCharacteristic request callbacks.
109 std::pair<ValueCallback, ErrorCallback> read_characteristic_value_callbacks_; 126 std::pair<ValueCallback, ErrorCallback> read_characteristic_value_callbacks_;
110 // WriteRemoteCharacteristic request callbacks. 127 // WriteRemoteCharacteristic request callbacks.
111 std::pair<base::Closure, ErrorCallback> write_characteristic_value_callbacks_; 128 std::pair<base::Closure, ErrorCallback> write_characteristic_value_callbacks_;
112 // Stores StartNotifySession request callbacks. 129 // Stores StartNotifySession request callbacks.
113 typedef std::pair<NotifySessionCallback, ErrorCallback> 130 typedef std::pair<NotifySessionCallback, ErrorCallback>
114 PendingStartNotifyCall; 131 PendingStartNotifyCall;
115 std::vector<PendingStartNotifyCall> start_notify_session_callbacks_; 132 std::vector<PendingStartNotifyCall> start_notify_session_callbacks_;
116 // Flag indicates if GATT event registration is in progress. 133 // Flag indicates if GATT event registration is in progress.
117 bool start_notifications_in_progress_; 134 bool start_notifications_in_progress_;
135 // Map of descriptors, keyed by descriptor identifier.
136 std::unordered_map<std::string,
137 std::unique_ptr<BluetoothRemoteGattDescriptorMac>>
138 gatt_descriptor_macs_;
118 base::WeakPtrFactory<BluetoothRemoteGattCharacteristicMac> weak_ptr_factory_; 139 base::WeakPtrFactory<BluetoothRemoteGattCharacteristicMac> weak_ptr_factory_;
119 }; 140 };
120 141
121 } // namespace device 142 } // namespace device
122 143
123 #endif // DEVICE_BLUETOOTH_BLUETOOTH_REMOTE_GATT_CHARACTERISTIC_MAC_H_ 144 #endif // DEVICE_BLUETOOTH_BLUETOOTH_REMOTE_GATT_CHARACTERISTIC_MAC_H_
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698