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

Side by Side Diff: components/arc/bluetooth/arc_bluetooth_bridge.cc

Issue 2204263003: arc: bluetooth: Use UUID 16 bits in advertising data (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Created 4 years, 4 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
« no previous file with comments | « no previous file | components/arc/common/bluetooth.mojom » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
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 "components/arc/bluetooth/arc_bluetooth_bridge.h" 5 #include "components/arc/bluetooth/arc_bluetooth_bridge.h"
6 6
7 #include <bluetooth/bluetooth.h> 7 #include <bluetooth/bluetooth.h>
8 #include <fcntl.h> 8 #include <fcntl.h>
9 #include <stddef.h> 9 #include <stddef.h>
10 #include <sys/socket.h> 10 #include <sys/socket.h>
(...skipping 155 matching lines...) Expand 10 before | Expand all | Expand 10 after
166 if (status == arc::mojom::BluetoothGattStatus::GATT_SUCCESS) 166 if (status == arc::mojom::BluetoothGattStatus::GATT_SUCCESS)
167 success_callback.Run(); 167 success_callback.Run();
168 else 168 else
169 error_callback.Run(); 169 error_callback.Run();
170 } 170 }
171 171
172 bool IsGattOffsetValid(int offset) { 172 bool IsGattOffsetValid(int offset) {
173 return 0 <= offset && offset < kMaxGattAttributeLength; 173 return 0 <= offset && offset < kMaxGattAttributeLength;
174 } 174 }
175 175
176 uint16_t GetUuid16(const BluetoothUUID& uuid) {
rkc 2016/08/04 20:01:57 GetUUID16 to keep it consistent with the casing of
puthik_chromium 2016/08/10 19:07:27 Done.
177 // Convert xxxxyyyy-xxxx-xxxx-xxxx-xxxxxxxxxxxx to int16 yyyy
178 return std::stoi(uuid.canonical_value().substr(4, 4), nullptr, 16);
179 }
180
176 } // namespace 181 } // namespace
177 182
178 namespace arc { 183 namespace arc {
179 184
180 ArcBluetoothBridge::ArcBluetoothBridge(ArcBridgeService* bridge_service) 185 ArcBluetoothBridge::ArcBluetoothBridge(ArcBridgeService* bridge_service)
181 : ArcService(bridge_service), binding_(this), weak_factory_(this) { 186 : ArcService(bridge_service), binding_(this), weak_factory_(this) {
182 if (BluetoothAdapterFactory::IsBluetoothAdapterAvailable()) { 187 if (BluetoothAdapterFactory::IsBluetoothAdapterAvailable()) {
183 VLOG(1) << "registering bluetooth adapter"; 188 VLOG(1) << "registering bluetooth adapter";
184 BluetoothAdapterFactory::GetAdapter(base::Bind( 189 BluetoothAdapterFactory::GetAdapter(base::Bind(
185 &ArcBluetoothBridge::OnAdapterInitialized, weak_factory_.GetWeakPtr())); 190 &ArcBluetoothBridge::OnAdapterInitialized, weak_factory_.GetWeakPtr()));
(...skipping 1331 matching lines...) Expand 10 before | Expand all | Expand 10 after
1517 // LocalName 1522 // LocalName
1518 mojom::BluetoothAdvertisingDataPtr local_name = 1523 mojom::BluetoothAdvertisingDataPtr local_name =
1519 mojom::BluetoothAdvertisingData::New(); 1524 mojom::BluetoothAdvertisingData::New();
1520 local_name->set_local_name(device->GetName() ? device->GetName().value() 1525 local_name->set_local_name(device->GetName() ? device->GetName().value()
1521 : nullptr); 1526 : nullptr);
1522 advertising_data.push_back(std::move(local_name)); 1527 advertising_data.push_back(std::move(local_name));
1523 1528
1524 // ServiceUuid 1529 // ServiceUuid
1525 BluetoothDevice::UUIDList uuid_list = device->GetServiceDataUUIDs(); 1530 BluetoothDevice::UUIDList uuid_list = device->GetServiceDataUUIDs();
1526 if (uuid_list.size() > 0) { 1531 if (uuid_list.size() > 0) {
1527 mojom::BluetoothAdvertisingDataPtr service_uuids = 1532 mojom::BluetoothAdvertisingDataPtr service_uuids_16 =
1528 mojom::BluetoothAdvertisingData::New(); 1533 mojom::BluetoothAdvertisingData::New();
1529 service_uuids->set_service_uuids( 1534 mojo::Array<uint16_t> uuid16s =
1530 mojo::Array<mojom::BluetoothUUIDPtr>::From(uuid_list)); 1535 mojo::Array<uint16_t>::New(uuid_list.size());
Luis Héctor Chávez 2016/08/08 14:41:37 This would cause |uuid_list.size()| zeroes to be a
puthik_chromium 2016/08/10 19:07:27 Done.
1531 advertising_data.push_back(std::move(service_uuids)); 1536 for (auto& uuid : uuid_list) {
1537 uuid16s.push_back(GetUuid16(uuid));
1538 }
1539 service_uuids_16->set_service_uuids_16(std::move(uuid16s));
1540 advertising_data.push_back(std::move(service_uuids_16));
1532 } 1541 }
1533 1542
1534 // Service data 1543 // Service data
1535 for (auto& uuid : uuid_list) { 1544 for (auto& uuid : uuid_list) {
1536 base::BinaryValue* data = device->GetServiceData(uuid); 1545 base::BinaryValue* data = device->GetServiceData(uuid);
1537 if (data->GetSize() == 0) 1546 if (data->GetSize() == 0)
1538 continue; 1547 continue;
1539 std::string data_str; 1548 std::string data_str;
1540 if (!data->GetAsString(&data_str)) 1549 if (!data->GetAsString(&data_str))
1541 continue; 1550 continue;
1542 1551
1543 mojom::BluetoothAdvertisingDataPtr service_data_element = 1552 mojom::BluetoothAdvertisingDataPtr service_data_element =
1544 mojom::BluetoothAdvertisingData::New(); 1553 mojom::BluetoothAdvertisingData::New();
1545 mojom::BluetoothServiceDataPtr service_data = 1554 mojom::BluetoothServiceDataPtr service_data =
1546 mojom::BluetoothServiceData::New(); 1555 mojom::BluetoothServiceData::New();
1547 1556
1548 std::string uuid_str = uuid.canonical_value(); 1557 service_data->uuid_16bit = GetUuid16(uuid);
1549 // Convert xxxxyyyy-xxxx-xxxx-xxxx-xxxxxxxxxxxx to int16 yyyy
1550 service_data->uuid_16bit = std::stoi(uuid_str.substr(4, 4), nullptr, 16);
1551 for (auto& c : data_str) { 1558 for (auto& c : data_str) {
1552 service_data->data.push_back(c); 1559 service_data->data.push_back(c);
1553 } 1560 }
1554 service_data_element->set_service_data(std::move(service_data)); 1561 service_data_element->set_service_data(std::move(service_data));
1555 advertising_data.push_back(std::move(service_data_element)); 1562 advertising_data.push_back(std::move(service_data_element));
1556 } 1563 }
1557 1564
1558 return advertising_data; 1565 return advertising_data;
1559 } 1566 }
1560 1567
(...skipping 79 matching lines...) Expand 10 before | Expand all | Expand 10 after
1640 LOG(WARNING) << "Bluetooth instance is too old (version " << version 1647 LOG(WARNING) << "Bluetooth instance is too old (version " << version
1641 << ") need version " << version_need; 1648 << ") need version " << version_need;
1642 return false; 1649 return false;
1643 } 1650 }
1644 1651
1645 bool ArcBluetoothBridge::CalledOnValidThread() { 1652 bool ArcBluetoothBridge::CalledOnValidThread() {
1646 return thread_checker_.CalledOnValidThread(); 1653 return thread_checker_.CalledOnValidThread();
1647 } 1654 }
1648 1655
1649 } // namespace arc 1656 } // namespace arc
OLDNEW
« no previous file with comments | « no previous file | components/arc/common/bluetooth.mojom » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698