Chromium Code Reviews| 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 #include "device/bluetooth/bluetooth_remote_gatt_service_mac.h" | 5 #include "device/bluetooth/bluetooth_remote_gatt_service_mac.h" |
| 6 | 6 |
| 7 #import <CoreBluetooth/CoreBluetooth.h> | 7 #import <CoreBluetooth/CoreBluetooth.h> |
| 8 #include <vector> | 8 #include <vector> |
| 9 | 9 |
| 10 #include "base/logging.h" | 10 #include "base/logging.h" |
| 11 #include "base/memory/ptr_util.h" | |
| 11 #include "device/bluetooth/bluetooth_adapter_mac.h" | 12 #include "device/bluetooth/bluetooth_adapter_mac.h" |
| 12 #include "device/bluetooth/bluetooth_low_energy_device_mac.h" | 13 #include "device/bluetooth/bluetooth_low_energy_device_mac.h" |
| 14 #include "device/bluetooth/bluetooth_remote_gatt_characteristic_mac.h" | |
| 13 #include "device/bluetooth/bluetooth_uuid.h" | 15 #include "device/bluetooth/bluetooth_uuid.h" |
| 14 | 16 |
| 15 namespace device { | 17 namespace device { |
| 16 | 18 |
| 17 BluetoothRemoteGattServiceMac::BluetoothRemoteGattServiceMac( | 19 BluetoothRemoteGattServiceMac::BluetoothRemoteGattServiceMac( |
| 18 BluetoothLowEnergyDeviceMac* bluetooth_device_mac, | 20 BluetoothLowEnergyDeviceMac* bluetooth_device_mac, |
| 19 CBService* service, | 21 CBService* service, |
| 20 bool is_primary) | 22 bool is_primary) |
| 21 : bluetooth_device_mac_(bluetooth_device_mac), | 23 : bluetooth_device_mac_(bluetooth_device_mac), |
| 22 service_(service, base::scoped_policy::RETAIN), | 24 service_(service, base::scoped_policy::RETAIN), |
| 23 is_primary_(is_primary) { | 25 is_primary_(is_primary), |
| 26 is_discovery_complete_(false) { | |
| 24 uuid_ = BluetoothAdapterMac::BluetoothUUIDWithCBUUID([service_.get() UUID]); | 27 uuid_ = BluetoothAdapterMac::BluetoothUUIDWithCBUUID([service_.get() UUID]); |
| 25 identifier_ = | 28 identifier_ = |
| 26 [NSString stringWithFormat:@"%s-%p", uuid_.canonical_value().c_str(), | 29 [NSString stringWithFormat:@"%s-%p", uuid_.canonical_value().c_str(), |
| 27 (void*)service_] | 30 (void*)service_] |
| 28 .UTF8String; | 31 .UTF8String; |
| 29 } | 32 } |
| 30 | 33 |
| 31 BluetoothRemoteGattServiceMac::~BluetoothRemoteGattServiceMac() {} | 34 BluetoothRemoteGattServiceMac::~BluetoothRemoteGattServiceMac() {} |
|
ortuno
2016/06/13 20:51:19
Also you need to call NotifyGattCharacteristicRemo
| |
| 32 | 35 |
| 33 std::string BluetoothRemoteGattServiceMac::GetIdentifier() const { | 36 std::string BluetoothRemoteGattServiceMac::GetIdentifier() const { |
| 34 return identifier_; | 37 return identifier_; |
| 35 } | 38 } |
| 36 | 39 |
| 37 BluetoothUUID BluetoothRemoteGattServiceMac::GetUUID() const { | 40 BluetoothUUID BluetoothRemoteGattServiceMac::GetUUID() const { |
| 38 return uuid_; | 41 return uuid_; |
| 39 } | 42 } |
| 40 | 43 |
| 41 bool BluetoothRemoteGattServiceMac::IsPrimary() const { | 44 bool BluetoothRemoteGattServiceMac::IsPrimary() const { |
| 42 return is_primary_; | 45 return is_primary_; |
| 43 } | 46 } |
| 44 | 47 |
| 45 BluetoothDevice* BluetoothRemoteGattServiceMac::GetDevice() const { | 48 BluetoothDevice* BluetoothRemoteGattServiceMac::GetDevice() const { |
| 46 return bluetooth_device_mac_; | 49 return bluetooth_device_mac_; |
| 47 } | 50 } |
| 48 | 51 |
| 49 std::vector<BluetoothRemoteGattCharacteristic*> | 52 std::vector<BluetoothRemoteGattCharacteristic*> |
| 50 BluetoothRemoteGattServiceMac::GetCharacteristics() const { | 53 BluetoothRemoteGattServiceMac::GetCharacteristics() const { |
| 51 NOTIMPLEMENTED(); | 54 std::vector<BluetoothRemoteGattCharacteristic*> gatt_characteristics; |
| 52 return std::vector<BluetoothRemoteGattCharacteristic*>(); | 55 for (const auto& iter : gatt_characteristic_macs_) { |
| 56 BluetoothRemoteGattCharacteristic* gatt_characteristic = | |
| 57 static_cast<BluetoothRemoteGattCharacteristic*>(iter.second); | |
| 58 gatt_characteristics.push_back(gatt_characteristic); | |
| 59 } | |
| 60 return gatt_characteristics; | |
| 53 } | 61 } |
| 54 | 62 |
| 55 std::vector<BluetoothRemoteGattService*> | 63 std::vector<BluetoothRemoteGattService*> |
| 56 BluetoothRemoteGattServiceMac::GetIncludedServices() const { | 64 BluetoothRemoteGattServiceMac::GetIncludedServices() const { |
| 57 NOTIMPLEMENTED(); | 65 NOTIMPLEMENTED(); |
| 58 return std::vector<BluetoothRemoteGattService*>(); | 66 return std::vector<BluetoothRemoteGattService*>(); |
| 59 } | 67 } |
| 60 | 68 |
| 61 BluetoothRemoteGattCharacteristic* | 69 BluetoothRemoteGattCharacteristic* |
| 62 BluetoothRemoteGattServiceMac::GetCharacteristic( | 70 BluetoothRemoteGattServiceMac::GetCharacteristic( |
| 63 const std::string& identifier) const { | 71 const std::string& identifier) const { |
| 64 NOTIMPLEMENTED(); | 72 return (BluetoothRemoteGattCharacteristic*)(gatt_characteristic_macs_.get( |
| 65 return nullptr; | 73 identifier)); |
| 74 } | |
| 75 | |
| 76 void BluetoothRemoteGattServiceMac::DiscoverCharacteristics() { | |
| 77 is_discovery_complete_ = false; | |
| 78 gatt_characteristic_macs_.clear(); | |
|
ortuno
2016/06/13 20:51:19
Why do you need to clear the map of characteristic
jlebel
2016/06/15 16:16:37
To remove the characteristics each time we do disc
| |
| 79 [GetPeripheral() discoverCharacteristics:nil forService:GetService()]; | |
|
ortuno
2016/06/13 20:51:19
Does OSX queue calls to discoverCharacteristics? I
jlebel
2016/06/15 16:16:37
OS X doesn't care. It will continue connecting to
| |
| 80 } | |
| 81 | |
| 82 void BluetoothRemoteGattServiceMac::DidDiscoverCharacteristics() { | |
| 83 DCHECK(!is_discovery_complete_); | |
| 84 for (CBCharacteristic* cb_characteristic in GetService().characteristics) { | |
| 85 BluetoothRemoteGattCharacteristicMac* gatt_characteristic_mac = | |
| 86 new BluetoothRemoteGattCharacteristicMac(this, cb_characteristic); | |
| 87 gatt_characteristic_macs_.add(gatt_characteristic_mac->GetIdentifier(), | |
|
ortuno
2016/06/13 20:51:19
You also need to call GattCharacteristicAdded. I'm
jlebel
2016/06/15 16:16:37
https://codereview.chromium.org/2068203002/
Done.
| |
| 88 base::WrapUnique(gatt_characteristic_mac)); | |
|
ortuno
2016/06/13 20:51:19
It's a bit dangerous to call functions on the obje
jlebel
2016/06/15 16:16:37
Done.
| |
| 89 } | |
| 90 is_discovery_complete_ = true; | |
| 91 } | |
| 92 | |
| 93 bool BluetoothRemoteGattServiceMac::IsDiscoveryComplete() { | |
| 94 return is_discovery_complete_; | |
| 95 } | |
| 96 | |
| 97 CBPeripheral* BluetoothRemoteGattServiceMac::GetPeripheral() const { | |
| 98 return bluetooth_device_mac_->GetPeripheral(); | |
| 66 } | 99 } |
| 67 | 100 |
| 68 CBService* BluetoothRemoteGattServiceMac::GetService() const { | 101 CBService* BluetoothRemoteGattServiceMac::GetService() const { |
| 69 return service_.get(); | 102 return service_.get(); |
| 70 } | 103 } |
| 71 | 104 |
| 72 } // namespace device | 105 } // namespace device |
| OLD | NEW |