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