OLD | NEW |
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 Loading... |
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 NSNumber* connectable = |
| 52 [advertisement_data objectForKey:CBAdvertisementDataIsConnectable]; |
| 53 connectable_ = [connectable boolValue]; |
51 ClearServiceData(); | 54 ClearServiceData(); |
52 NSNumber* nbConnectable = | 55 NSDictionary* service_data = |
53 [advertisementData objectForKey:CBAdvertisementDataIsConnectable]; | 56 [advertisement_data objectForKey:@"CBAdvertisementDataServiceDataKey"]; |
54 connectable_ = [nbConnectable boolValue]; | 57 for (CBUUID* uuid in service_data) { |
55 NSDictionary* serviceData = | 58 NSData* data = [service_data objectForKey:uuid]; |
56 [advertisementData objectForKey:CBAdvertisementDataServiceDataKey]; | 59 BluetoothUUID service_uuid = BluetoothUUIDWithCBUUID(uuid); |
57 for (CBUUID* uuid in serviceData) { | 60 SetServiceData(service_uuid, static_cast<const char*>([data bytes]), |
58 NSData* data = [serviceData objectForKey:uuid]; | 61 [data length]); |
59 BluetoothUUID serviceUUID = BluetoothUUIDWithCBUUID(uuid); | 62 } |
60 SetServiceData(serviceUUID, (const char*)[data bytes], [data length]); | 63 advertised_uuids_.clear(); |
| 64 NSArray* service_uuids = |
| 65 [advertisement_data objectForKey:@"CBAdvertisementDataServiceUUIDsKey"]; |
| 66 for (CBUUID* uuid in service_uuids) { |
| 67 advertised_uuids_.push_back( |
| 68 BluetoothUUID(std::string([[uuid UUIDString] UTF8String]))); |
61 } | 69 } |
62 } | 70 } |
63 | 71 |
64 std::string BluetoothLowEnergyDeviceMac::GetIdentifier() const { | 72 std::string BluetoothLowEnergyDeviceMac::GetIdentifier() const { |
65 return identifier_; | 73 return identifier_; |
66 } | 74 } |
67 | 75 |
68 uint32 BluetoothLowEnergyDeviceMac::GetBluetoothClass() const { | 76 uint32 BluetoothLowEnergyDeviceMac::GetBluetoothClass() const { |
69 return 0; | 77 return 0; |
70 } | 78 } |
(...skipping 33 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
104 | 112 |
105 bool BluetoothLowEnergyDeviceMac::IsConnectable() const { | 113 bool BluetoothLowEnergyDeviceMac::IsConnectable() const { |
106 return connectable_; | 114 return connectable_; |
107 } | 115 } |
108 | 116 |
109 bool BluetoothLowEnergyDeviceMac::IsConnecting() const { | 117 bool BluetoothLowEnergyDeviceMac::IsConnecting() const { |
110 return false; | 118 return false; |
111 } | 119 } |
112 | 120 |
113 BluetoothDevice::UUIDList BluetoothLowEnergyDeviceMac::GetUUIDs() const { | 121 BluetoothDevice::UUIDList BluetoothLowEnergyDeviceMac::GetUUIDs() const { |
114 return std::vector<device::BluetoothUUID>(); | 122 return advertised_uuids_; |
115 } | 123 } |
116 | 124 |
117 int16 BluetoothLowEnergyDeviceMac::GetInquiryRSSI() const { | 125 int16 BluetoothLowEnergyDeviceMac::GetInquiryRSSI() const { |
118 return kUnknownPower; | 126 return kUnknownPower; |
119 } | 127 } |
120 | 128 |
121 int16 BluetoothLowEnergyDeviceMac::GetInquiryTxPower() const { | 129 int16 BluetoothLowEnergyDeviceMac::GetInquiryTxPower() const { |
122 NOTIMPLEMENTED(); | 130 NOTIMPLEMENTED(); |
123 return kUnknownPower; | 131 return kUnknownPower; |
124 } | 132 } |
(...skipping 106 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
231 instanceMethodSignatureForSelector:@selector(state)] retain]); | 239 instanceMethodSignatureForSelector:@selector(state)] retain]); |
232 base::scoped_nsobject<NSInvocation> invocation( | 240 base::scoped_nsobject<NSInvocation> invocation( |
233 [[NSInvocation invocationWithMethodSignature:signature] retain]); | 241 [[NSInvocation invocationWithMethodSignature:signature] retain]); |
234 [invocation setTarget:peripheral_]; | 242 [invocation setTarget:peripheral_]; |
235 [invocation setSelector:@selector(state)]; | 243 [invocation setSelector:@selector(state)]; |
236 [invocation invoke]; | 244 [invocation invoke]; |
237 CBPeripheralState state = CBPeripheralStateDisconnected; | 245 CBPeripheralState state = CBPeripheralStateDisconnected; |
238 [invocation getReturnValue:&state]; | 246 [invocation getReturnValue:&state]; |
239 return state; | 247 return state; |
240 } | 248 } |
OLD | NEW |