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 35 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
46 NSDictionary* advertisement_data, | 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 = | 51 NSNumber* connectable = |
52 [advertisement_data objectForKey:CBAdvertisementDataIsConnectable]; | 52 [advertisement_data objectForKey:CBAdvertisementDataIsConnectable]; |
53 connectable_ = [connectable boolValue]; | 53 connectable_ = [connectable boolValue]; |
54 ClearServiceData(); | 54 ClearServiceData(); |
55 NSDictionary* service_data = | 55 NSDictionary* service_data = |
56 [advertisement_data objectForKey:@"CBAdvertisementDataServiceDataKey"]; | 56 [advertisement_data objectForKey:CBAdvertisementDataServiceDataKey]; |
57 for (CBUUID* uuid in service_data) { | 57 for (CBUUID* uuid in service_data) { |
58 NSData* data = [service_data objectForKey:uuid]; | 58 NSData* data = [service_data objectForKey:uuid]; |
59 BluetoothUUID service_uuid = BluetoothUUIDWithCBUUID(uuid); | 59 BluetoothUUID service_uuid = BluetoothUUIDWithCBUUID(uuid); |
60 SetServiceData(service_uuid, static_cast<const char*>([data bytes]), | 60 SetServiceData(service_uuid, static_cast<const char*>([data bytes]), |
61 [data length]); | 61 [data length]); |
62 } | 62 } |
63 advertised_uuids_.clear(); | |
64 NSArray* service_uuids = | 63 NSArray* service_uuids = |
65 [advertisement_data objectForKey:@"CBAdvertisementDataServiceUUIDsKey"]; | 64 [advertisement_data objectForKey:CBAdvertisementDataServiceUUIDsKey]; |
66 for (CBUUID* uuid in service_uuids) { | 65 for (CBUUID* uuid in service_uuids) { |
67 advertised_uuids_.push_back( | 66 advertised_uuids_.insert( |
67 BluetoothUUID(std::string([[uuid UUIDString] UTF8String]))); | |
68 } | |
69 NSArray* overflow_service_uuids = [advertisement_data | |
70 objectForKey:CBAdvertisementDataOverflowServiceUUIDsKey]; | |
71 for (CBUUID* uuid in overflow_service_uuids) { | |
72 advertised_uuids_.insert( | |
68 BluetoothUUID(std::string([[uuid UUIDString] UTF8String]))); | 73 BluetoothUUID(std::string([[uuid UUIDString] UTF8String]))); |
69 } | 74 } |
70 } | 75 } |
71 | 76 |
72 std::string BluetoothLowEnergyDeviceMac::GetIdentifier() const { | 77 std::string BluetoothLowEnergyDeviceMac::GetIdentifier() const { |
73 return identifier_; | 78 return identifier_; |
74 } | 79 } |
75 | 80 |
76 uint32 BluetoothLowEnergyDeviceMac::GetBluetoothClass() const { | 81 uint32 BluetoothLowEnergyDeviceMac::GetBluetoothClass() const { |
77 return 0x1F00; // Unspecified Device Class | 82 return 0x1F00; // Unspecified Device Class |
(...skipping 34 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
112 | 117 |
113 bool BluetoothLowEnergyDeviceMac::IsConnectable() const { | 118 bool BluetoothLowEnergyDeviceMac::IsConnectable() const { |
114 return connectable_; | 119 return connectable_; |
115 } | 120 } |
116 | 121 |
117 bool BluetoothLowEnergyDeviceMac::IsConnecting() const { | 122 bool BluetoothLowEnergyDeviceMac::IsConnecting() const { |
118 return false; | 123 return false; |
119 } | 124 } |
120 | 125 |
121 BluetoothDevice::UUIDList BluetoothLowEnergyDeviceMac::GetUUIDs() const { | 126 BluetoothDevice::UUIDList BluetoothLowEnergyDeviceMac::GetUUIDs() const { |
122 return advertised_uuids_; | 127 BluetoothDevice::UUIDList advertised_uuids_list; |
scheib
2015/08/05 00:04:35
Hmm.. yep, have to either make copies here... or k
krstnmnlsn
2015/08/05 16:44:09
Done.
| |
128 for (BluetoothUUID uuid : advertised_uuids_) | |
129 advertised_uuids_list.push_back(uuid); | |
130 return advertised_uuids_list; | |
123 } | 131 } |
124 | 132 |
125 int16 BluetoothLowEnergyDeviceMac::GetInquiryRSSI() const { | 133 int16 BluetoothLowEnergyDeviceMac::GetInquiryRSSI() const { |
126 return kUnknownPower; | 134 return kUnknownPower; |
127 } | 135 } |
128 | 136 |
129 int16 BluetoothLowEnergyDeviceMac::GetInquiryTxPower() const { | 137 int16 BluetoothLowEnergyDeviceMac::GetInquiryTxPower() const { |
130 NOTIMPLEMENTED(); | 138 NOTIMPLEMENTED(); |
131 return kUnknownPower; | 139 return kUnknownPower; |
132 } | 140 } |
(...skipping 106 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
239 instanceMethodSignatureForSelector:@selector(state)] retain]); | 247 instanceMethodSignatureForSelector:@selector(state)] retain]); |
240 base::scoped_nsobject<NSInvocation> invocation( | 248 base::scoped_nsobject<NSInvocation> invocation( |
241 [[NSInvocation invocationWithMethodSignature:signature] retain]); | 249 [[NSInvocation invocationWithMethodSignature:signature] retain]); |
242 [invocation setTarget:peripheral_]; | 250 [invocation setTarget:peripheral_]; |
243 [invocation setSelector:@selector(state)]; | 251 [invocation setSelector:@selector(state)]; |
244 [invocation invoke]; | 252 [invocation invoke]; |
245 CBPeripheralState state = CBPeripheralStateDisconnected; | 253 CBPeripheralState state = CBPeripheralStateDisconnected; |
246 [invocation getReturnValue:&state]; | 254 [invocation getReturnValue:&state]; |
247 return state; | 255 return state; |
248 } | 256 } |
OLD | NEW |