OLD | NEW |
---|---|
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 "base/mac/scoped_nsobject.h" | 10 #include "base/mac/scoped_nsobject.h" |
11 #include "base/memory/weak_ptr.h" | |
11 | 12 |
12 #if defined(__OBJC__) | 13 #if defined(__OBJC__) |
13 #import <CoreBluetooth/CoreBluetooth.h> | 14 #import <CoreBluetooth/CoreBluetooth.h> |
14 #else | 15 #else |
15 @class CBCharacteristic; | 16 @class CBCharacteristic; |
16 typedef NS_ENUM(NSInteger, CBCharacteristicWriteType); | 17 typedef NS_ENUM(NSInteger, CBCharacteristicWriteType); |
17 #endif // defined(__OBJC__) | 18 #endif // defined(__OBJC__) |
18 | 19 |
19 namespace device { | 20 namespace device { |
20 | 21 |
(...skipping 32 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
53 | 54 |
54 DISALLOW_COPY_AND_ASSIGN(BluetoothRemoteGattCharacteristicMac); | 55 DISALLOW_COPY_AND_ASSIGN(BluetoothRemoteGattCharacteristicMac); |
55 | 56 |
56 private: | 57 private: |
57 friend class BluetoothRemoteGattServiceMac; | 58 friend class BluetoothRemoteGattServiceMac; |
58 friend class BluetoothTestMac; | 59 friend class BluetoothTestMac; |
59 | 60 |
60 // Called by the BluetoothRemoteGattServiceMac instance when the | 61 // Called by the BluetoothRemoteGattServiceMac instance when the |
61 // characteristics value has been read. | 62 // characteristics value has been read. |
62 void DidUpdateValue(NSError* error); | 63 void DidUpdateValue(NSError* error); |
64 // Updates the value_ and send notify the mac adapter for the new value | |
ortuno
2016/06/28 19:18:58
grammar nit: Updates value_ and notifies the adapt
jlebel
2016/06/28 21:09:33
Done.
| |
65 void UpdateValueAndNotify(); | |
63 // Called by the BluetoothRemoteGattServiceMac instance when the | 66 // Called by the BluetoothRemoteGattServiceMac instance when the |
64 // characteristics value has been written. | 67 // characteristics value has been written. |
65 void DidWriteValue(NSError* error); | 68 void DidWriteValue(NSError* error); |
69 // Called by the BluetoothRemoteGattServiceMac instance when the notify | |
70 // session has been started or failed. | |
71 void DidUpdateNotificationState(NSError* error); | |
66 // Returns true if the characteristic is readable. | 72 // Returns true if the characteristic is readable. |
67 bool IsReadable() const; | 73 bool IsReadable() const; |
68 // Returns true if the characteristic is writable. | 74 // Returns true if the characteristic is writable. |
69 bool IsWritable() const; | 75 bool IsWritable() const; |
76 // Returns true if the characteristic supports notifications or indications. | |
77 bool SupportsNotificationsOrIndications() const; | |
70 // Returns the write type (with or without responses). | 78 // Returns the write type (with or without responses). |
71 CBCharacteristicWriteType GetCBWriteType() const; | 79 CBCharacteristicWriteType GetCBWriteType() const; |
72 // Returns CoreBluetooth characteristic. | 80 // Returns CoreBluetooth characteristic. |
73 CBCharacteristic* GetCBCharacteristic() const; | 81 CBCharacteristic* GetCBCharacteristic() const; |
74 | 82 |
75 // gatt_service_ owns instances of this class. | 83 // gatt_service_ owns instances of this class. |
76 BluetoothRemoteGattServiceMac* gatt_service_; | 84 BluetoothRemoteGattServiceMac* gatt_service_; |
77 // A characteristic from CBPeripheral.services.characteristics. | 85 // A characteristic from CBPeripheral.services.characteristics. |
78 base::scoped_nsobject<CBCharacteristic> cb_characteristic_; | 86 base::scoped_nsobject<CBCharacteristic> cb_characteristic_; |
79 // Characteristic identifier. | 87 // Characteristic identifier. |
80 std::string identifier_; | 88 std::string identifier_; |
81 // Service UUID. | 89 // Service UUID. |
82 BluetoothUUID uuid_; | 90 BluetoothUUID uuid_; |
83 // Characteristic value. | 91 // Characteristic value. |
84 std::vector<uint8_t> value_; | 92 std::vector<uint8_t> value_; |
85 // True if a gatt read or write request is in progress. | 93 // True if a gatt read or write request is in progress. |
86 bool characteristic_value_read_or_write_in_progress_; | 94 bool characteristic_value_read_or_write_in_progress_; |
87 // ReadRemoteCharacteristic request callbacks. | 95 // ReadRemoteCharacteristic request callbacks. |
88 std::pair<ValueCallback, ErrorCallback> read_characteristic_value_callbacks_; | 96 std::pair<ValueCallback, ErrorCallback> read_characteristic_value_callbacks_; |
89 // WriteRemoteCharacteristic request callbacks. | 97 // WriteRemoteCharacteristic request callbacks. |
90 std::pair<base::Closure, ErrorCallback> write_characteristic_value_callbacks_; | 98 std::pair<base::Closure, ErrorCallback> write_characteristic_value_callbacks_; |
99 // Stores StartNotifySession request callbacks. | |
100 typedef std::pair<NotifySessionCallback, ErrorCallback> | |
101 PendingStartNotifyCall; | |
102 std::vector<PendingStartNotifyCall> start_notify_session_callbacks_; | |
103 // Flag indicates if GATT event registration is in progress. | |
104 bool start_notifications_in_progress_; | |
105 base::WeakPtrFactory<BluetoothRemoteGattCharacteristicMac> weak_ptr_factory_; | |
91 }; | 106 }; |
92 | 107 |
93 } // namespace device | 108 } // namespace device |
94 | 109 |
95 #endif // DEVICE_BLUETOOTH_BLUETOOTH_REMOTE_GATT_CHARACTERISTIC_MAC_H_ | 110 #endif // DEVICE_BLUETOOTH_BLUETOOTH_REMOTE_GATT_CHARACTERISTIC_MAC_H_ |
OLD | NEW |