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

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

Issue 1246913006: Bringing 4 more BluetoothTest.* unit tests to Mac (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@scheibtest
Patch Set: Created 5 years, 5 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 2015 The Chromium Authors. All rights reserved. 1 // Copyright 2015 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_low_energy_device_mac.h" 5 #include "device/bluetooth/bluetooth_low_energy_device_mac.h"
6 6
7 #import <CoreFoundation/CoreFoundation.h> 7 #import <CoreFoundation/CoreFoundation.h>
8 8
9 #include "base/mac/mac_util.h" 9 #include "base/mac/mac_util.h"
10 #include "base/mac/scoped_cftyperef.h" 10 #include "base/mac/scoped_cftyperef.h"
(...skipping 13 matching lines...) Expand all
24 // UUIDString only available OS X >= 10.8. 24 // UUIDString only available OS X >= 10.8.
25 DCHECK(base::mac::IsOSMountainLionOrLater()); 25 DCHECK(base::mac::IsOSMountainLionOrLater());
26 std::string uuid_c_string = base::SysNSStringToUTF8([uuid UUIDString]); 26 std::string uuid_c_string = base::SysNSStringToUTF8([uuid UUIDString]);
27 return device::BluetoothUUID(uuid_c_string); 27 return device::BluetoothUUID(uuid_c_string);
28 } 28 }
29 29
30 } // namespace 30 } // namespace
31 31
32 BluetoothLowEnergyDeviceMac::BluetoothLowEnergyDeviceMac( 32 BluetoothLowEnergyDeviceMac::BluetoothLowEnergyDeviceMac(
33 CBPeripheral* peripheral, 33 CBPeripheral* peripheral,
34 NSDictionary* advertisementData, 34 NSDictionary* advertisement_data,
35 int rssi) { 35 int rssi) {
36 DCHECK(BluetoothAdapterMac::IsLowEnergyAvailable()); 36 DCHECK(BluetoothAdapterMac::IsLowEnergyAvailable());
37 identifier_ = GetPeripheralIdentifier(peripheral); 37 identifier_ = GetPeripheralIdentifier(peripheral);
38 hash_address_ = GetPeripheralHashAddress(peripheral); 38 hash_address_ = GetPeripheralHashAddress(peripheral);
39 Update(peripheral, advertisementData, rssi); 39 Update(peripheral, advertisement_data, rssi);
40 } 40 }
41 41
42 BluetoothLowEnergyDeviceMac::~BluetoothLowEnergyDeviceMac() { 42 BluetoothLowEnergyDeviceMac::~BluetoothLowEnergyDeviceMac() {
43 } 43 }
44 44
45 void BluetoothLowEnergyDeviceMac::Update(CBPeripheral* peripheral, 45 void BluetoothLowEnergyDeviceMac::Update(CBPeripheral* peripheral,
46 NSDictionary* advertisementData, 46 NSDictionary* advertisement_data,
47 int rssi) { 47 int rssi) {
48 last_update_time_.reset([[NSDate date] retain]); 48 last_update_time_.reset([[NSDate date] retain]);
49 peripheral_.reset([peripheral retain]); 49 peripheral_.reset([peripheral retain]);
50 rssi_ = rssi; 50 rssi_ = rssi;
51 ClearServiceData(); 51 ClearServiceData();
52 NSNumber* nbConnectable = 52 NSNumber* connectable =
53 [advertisementData objectForKey:CBAdvertisementDataIsConnectable]; 53 [advertisement_data objectForKey:CBAdvertisementDataIsConnectable];
54 connectable_ = [nbConnectable boolValue]; 54 connectable_ = [connectable boolValue];
55 NSDictionary* serviceData = 55 NSDictionary* service_data =
56 [advertisementData objectForKey:CBAdvertisementDataServiceDataKey]; 56 [advertisement_data objectForKey:CBAdvertisementDataServiceDataKey];
57 for (CBUUID* uuid in serviceData) { 57 for (CBUUID* uuid in service_data) {
scheib 2015/07/23 18:15:25 ClearServiceData(); before setting values, so that
krstnmnlsn 2015/07/23 22:03:29 The call was further above. Moved it down for cla
scheib 2015/07/23 22:15:39 Oh! great. Hmm, yeah, line breaks for sections wou
58 NSData* data = [serviceData objectForKey:uuid]; 58 NSData* data = [service_data objectForKey:uuid];
59 BluetoothUUID serviceUUID = BluetoothUUIDWithCBUUID(uuid); 59 BluetoothUUID service_UUID = BluetoothUUIDWithCBUUID(uuid);
60 SetServiceData(serviceUUID, (const char*)[data bytes], [data length]); 60 SetServiceData(service_UUID, (const char*)[data bytes], [data length]);
61 }
62 uuids_.clear();
63 NSArray* service_uuids =
64 [advertisement_data objectForKey:@"CBAdvertisementDataServiceUUIDsKey"];
65 for (CBUUID* uuid in service_uuids) {
66 uuids_.push_back(
67 BluetoothUUID(std::string([[uuid UUIDString] UTF8String])));
61 } 68 }
62 } 69 }
63 70
64 std::string BluetoothLowEnergyDeviceMac::GetIdentifier() const { 71 std::string BluetoothLowEnergyDeviceMac::GetIdentifier() const {
65 return identifier_; 72 return identifier_;
66 } 73 }
67 74
68 uint32 BluetoothLowEnergyDeviceMac::GetBluetoothClass() const { 75 uint32 BluetoothLowEnergyDeviceMac::GetBluetoothClass() const {
69 return 0; 76 return 0;
70 } 77 }
(...skipping 33 matching lines...) Expand 10 before | Expand all | Expand 10 after
104 111
105 bool BluetoothLowEnergyDeviceMac::IsConnectable() const { 112 bool BluetoothLowEnergyDeviceMac::IsConnectable() const {
106 return connectable_; 113 return connectable_;
107 } 114 }
108 115
109 bool BluetoothLowEnergyDeviceMac::IsConnecting() const { 116 bool BluetoothLowEnergyDeviceMac::IsConnecting() const {
110 return false; 117 return false;
111 } 118 }
112 119
113 BluetoothDevice::UUIDList BluetoothLowEnergyDeviceMac::GetUUIDs() const { 120 BluetoothDevice::UUIDList BluetoothLowEnergyDeviceMac::GetUUIDs() const {
114 return std::vector<device::BluetoothUUID>(); 121 return uuids_;
115 } 122 }
116 123
117 int16 BluetoothLowEnergyDeviceMac::GetInquiryRSSI() const { 124 int16 BluetoothLowEnergyDeviceMac::GetInquiryRSSI() const {
118 return kUnknownPower; 125 return kUnknownPower;
119 } 126 }
120 127
121 int16 BluetoothLowEnergyDeviceMac::GetInquiryTxPower() const { 128 int16 BluetoothLowEnergyDeviceMac::GetInquiryTxPower() const {
122 NOTIMPLEMENTED(); 129 NOTIMPLEMENTED();
123 return kUnknownPower; 130 return kUnknownPower;
124 } 131 }
(...skipping 106 matching lines...) Expand 10 before | Expand all | Expand 10 after
231 instanceMethodSignatureForSelector:@selector(state)] retain]); 238 instanceMethodSignatureForSelector:@selector(state)] retain]);
232 base::scoped_nsobject<NSInvocation> invocation( 239 base::scoped_nsobject<NSInvocation> invocation(
233 [[NSInvocation invocationWithMethodSignature:signature] retain]); 240 [[NSInvocation invocationWithMethodSignature:signature] retain]);
234 [invocation setTarget:peripheral_]; 241 [invocation setTarget:peripheral_];
235 [invocation setSelector:@selector(state)]; 242 [invocation setSelector:@selector(state)];
236 [invocation invoke]; 243 [invocation invoke];
237 CBPeripheralState state = CBPeripheralStateDisconnected; 244 CBPeripheralState state = CBPeripheralStateDisconnected;
238 [invocation getReturnValue:&state]; 245 [invocation getReturnValue:&state];
239 return state; 246 return state;
240 } 247 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698