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

Side by Side Diff: device/bluetooth/bluetooth_remote_gatt_service_mac.mm

Issue 1950033002: bluetooth: mac: Initial BluetoothRemoteGattCharacteristicMac implementation (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@servicescan_cleanup
Patch Set: Updating the characteristic property conversion Created 4 years, 6 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 #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() {}
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 (BluetoothRemoteGattCharacteristic*)(iter.second);
scheib 2016/06/10 21:59:31 use static_cast<> instead of C-style cast. But, in
jlebel 2016/06/10 23:02:46 Done.
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::DidDiscoverCharacteristics() {
scheib 2016/06/10 21:59:31 Are we sure this is called only once? DCHECK(!is_d
jlebel 2016/06/10 23:02:46 Done.
77 for (CBCharacteristic* cb_characteristic in GetService().characteristics) {
78 BluetoothRemoteGattCharacteristicMac* gatt_characteristic_mac =
79 new BluetoothRemoteGattCharacteristicMac(this, cb_characteristic);
80 gatt_characteristic_macs_.add(gatt_characteristic_mac->GetIdentifier(),
81 base::WrapUnique(gatt_characteristic_mac));
82 }
83 is_discovery_complete_ = true;
84 }
85
86 bool BluetoothRemoteGattServiceMac::IsDiscoveryComplete() {
87 return is_discovery_complete_;
66 } 88 }
67 89
68 CBService* BluetoothRemoteGattServiceMac::GetService() const { 90 CBService* BluetoothRemoteGattServiceMac::GetService() const {
69 return service_.get(); 91 return service_.get();
70 } 92 }
71 93
72 } // namespace device 94 } // namespace device
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698