OLD | NEW |
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2012 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_task_manager_win.h" | 5 #include "device/bluetooth/bluetooth_task_manager_win.h" |
6 | 6 |
7 #include <stddef.h> | 7 #include <stddef.h> |
8 #include <winsock2.h> | 8 #include <winsock2.h> |
9 | 9 |
10 #include <memory> | 10 #include <memory> |
(...skipping 360 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
371 observer.DiscoveryStarted(success); | 371 observer.DiscoveryStarted(success); |
372 } | 372 } |
373 | 373 |
374 void BluetoothTaskManagerWin::OnDiscoveryStopped() { | 374 void BluetoothTaskManagerWin::OnDiscoveryStopped() { |
375 DCHECK(ui_task_runner_->RunsTasksOnCurrentThread()); | 375 DCHECK(ui_task_runner_->RunsTasksOnCurrentThread()); |
376 for (auto& observer : observers_) | 376 for (auto& observer : observers_) |
377 observer.DiscoveryStopped(); | 377 observer.DiscoveryStopped(); |
378 } | 378 } |
379 | 379 |
380 void BluetoothTaskManagerWin::OnDevicesPolled( | 380 void BluetoothTaskManagerWin::OnDevicesPolled( |
381 const ScopedVector<DeviceState>* devices) { | 381 const std::vector<std::unique_ptr<DeviceState>>& devices) { |
382 DCHECK(ui_task_runner_->RunsTasksOnCurrentThread()); | 382 DCHECK(ui_task_runner_->RunsTasksOnCurrentThread()); |
383 for (auto& observer : observers_) | 383 for (auto& observer : observers_) |
384 observer.DevicesPolled(*devices); | 384 observer.DevicesPolled(*devices); |
385 } | 385 } |
386 | 386 |
387 void BluetoothTaskManagerWin::PollAdapter() { | 387 void BluetoothTaskManagerWin::PollAdapter() { |
388 DCHECK(bluetooth_task_runner_->RunsTasksOnCurrentThread()); | 388 DCHECK(bluetooth_task_runner_->RunsTasksOnCurrentThread()); |
389 | 389 |
390 // Skips updating the adapter info if the adapter is in discovery mode. | 390 // Skips updating the adapter info if the adapter is in discovery mode. |
391 if (!discovering_) { | 391 if (!discovering_) { |
(...skipping 77 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
469 | 469 |
470 void BluetoothTaskManagerWin::DiscoverDevices(int timeout_multiplier) { | 470 void BluetoothTaskManagerWin::DiscoverDevices(int timeout_multiplier) { |
471 DCHECK(bluetooth_task_runner_->RunsTasksOnCurrentThread()); | 471 DCHECK(bluetooth_task_runner_->RunsTasksOnCurrentThread()); |
472 if (!discovering_ || !adapter_handle_) { | 472 if (!discovering_ || !adapter_handle_) { |
473 ui_task_runner_->PostTask( | 473 ui_task_runner_->PostTask( |
474 FROM_HERE, | 474 FROM_HERE, |
475 base::Bind(&BluetoothTaskManagerWin::OnDiscoveryStopped, this)); | 475 base::Bind(&BluetoothTaskManagerWin::OnDiscoveryStopped, this)); |
476 return; | 476 return; |
477 } | 477 } |
478 | 478 |
479 std::unique_ptr<ScopedVector<DeviceState>> device_list( | 479 std::unique_ptr<std::vector<std::unique_ptr<DeviceState>>> device_list( |
480 new ScopedVector<DeviceState>()); | 480 new std::vector<std::unique_ptr<DeviceState>>()); |
481 if (SearchDevices(timeout_multiplier, false, device_list.get())) { | 481 if (SearchDevices(timeout_multiplier, false, device_list.get())) { |
482 ui_task_runner_->PostTask( | 482 ui_task_runner_->PostTask( |
483 FROM_HERE, | 483 FROM_HERE, |
484 base::Bind(&BluetoothTaskManagerWin::OnDevicesPolled, | 484 base::Bind(&BluetoothTaskManagerWin::OnDevicesPolled, |
485 this, | 485 this, |
486 base::Owned(device_list.release()))); | 486 base::Owned(device_list.release()))); |
487 } | 487 } |
488 | 488 |
489 if (timeout_multiplier < kMaxDeviceDiscoveryTimeoutMultiplier) | 489 if (timeout_multiplier < kMaxDeviceDiscoveryTimeoutMultiplier) |
490 ++timeout_multiplier; | 490 ++timeout_multiplier; |
491 bluetooth_task_runner_->PostTask( | 491 bluetooth_task_runner_->PostTask( |
492 FROM_HERE, | 492 FROM_HERE, |
493 base::Bind( | 493 base::Bind( |
494 &BluetoothTaskManagerWin::DiscoverDevices, this, timeout_multiplier)); | 494 &BluetoothTaskManagerWin::DiscoverDevices, this, timeout_multiplier)); |
495 } | 495 } |
496 | 496 |
497 void BluetoothTaskManagerWin::GetKnownDevices() { | 497 void BluetoothTaskManagerWin::GetKnownDevices() { |
498 std::unique_ptr<ScopedVector<DeviceState>> device_list( | 498 std::unique_ptr<std::vector<std::unique_ptr<DeviceState>>> device_list( |
499 new ScopedVector<DeviceState>()); | 499 new std::vector<std::unique_ptr<DeviceState>>()); |
500 if (SearchDevices(1, true, device_list.get())) { | 500 if (SearchDevices(1, true, device_list.get())) { |
501 ui_task_runner_->PostTask( | 501 ui_task_runner_->PostTask( |
502 FROM_HERE, | 502 FROM_HERE, |
503 base::Bind(&BluetoothTaskManagerWin::OnDevicesPolled, | 503 base::Bind(&BluetoothTaskManagerWin::OnDevicesPolled, |
504 this, | 504 this, |
505 base::Owned(device_list.release()))); | 505 base::Owned(device_list.release()))); |
506 } | 506 } |
507 } | 507 } |
508 | 508 |
509 bool BluetoothTaskManagerWin::SearchDevices( | 509 bool BluetoothTaskManagerWin::SearchDevices( |
510 int timeout_multiplier, | 510 int timeout_multiplier, |
511 bool search_cached_devices_only, | 511 bool search_cached_devices_only, |
512 ScopedVector<DeviceState>* device_list) { | 512 std::vector<std::unique_ptr<DeviceState>>& device_list) { |
513 return SearchClassicDevices( | 513 return SearchClassicDevices( |
514 timeout_multiplier, search_cached_devices_only, device_list) && | 514 timeout_multiplier, search_cached_devices_only, device_list) && |
515 SearchLowEnergyDevices(device_list) && | 515 SearchLowEnergyDevices(device_list) && |
516 DiscoverServices(device_list, search_cached_devices_only); | 516 DiscoverServices(device_list, search_cached_devices_only); |
517 } | 517 } |
518 | 518 |
519 bool BluetoothTaskManagerWin::SearchClassicDevices( | 519 bool BluetoothTaskManagerWin::SearchClassicDevices( |
520 int timeout_multiplier, | 520 int timeout_multiplier, |
521 bool search_cached_devices_only, | 521 bool search_cached_devices_only, |
522 ScopedVector<DeviceState>* device_list) { | 522 std::vector<std::unique_ptr<DeviceState>>& device_list) { |
523 // Issues a device inquiry and waits for |timeout_multiplier| * 1.28 seconds. | 523 // Issues a device inquiry and waits for |timeout_multiplier| * 1.28 seconds. |
524 BLUETOOTH_DEVICE_SEARCH_PARAMS device_search_params; | 524 BLUETOOTH_DEVICE_SEARCH_PARAMS device_search_params; |
525 ZeroMemory(&device_search_params, sizeof(device_search_params)); | 525 ZeroMemory(&device_search_params, sizeof(device_search_params)); |
526 device_search_params.dwSize = sizeof(BLUETOOTH_DEVICE_SEARCH_PARAMS); | 526 device_search_params.dwSize = sizeof(BLUETOOTH_DEVICE_SEARCH_PARAMS); |
527 device_search_params.fReturnAuthenticated = 1; | 527 device_search_params.fReturnAuthenticated = 1; |
528 device_search_params.fReturnRemembered = 1; | 528 device_search_params.fReturnRemembered = 1; |
529 device_search_params.fReturnUnknown = (search_cached_devices_only ? 0 : 1); | 529 device_search_params.fReturnUnknown = (search_cached_devices_only ? 0 : 1); |
530 device_search_params.fReturnConnected = 1; | 530 device_search_params.fReturnConnected = 1; |
531 device_search_params.fIssueInquiry = (search_cached_devices_only ? 0 : 1); | 531 device_search_params.fIssueInquiry = (search_cached_devices_only ? 0 : 1); |
532 device_search_params.cTimeoutMultiplier = timeout_multiplier; | 532 device_search_params.cTimeoutMultiplier = timeout_multiplier; |
(...skipping 35 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
568 | 568 |
569 if (!win::BluetoothClassicWrapper::GetInstance()->FindDeviceClose(handle)) { | 569 if (!win::BluetoothClassicWrapper::GetInstance()->FindDeviceClose(handle)) { |
570 LogPollingError("Error calling BluetoothFindDeviceClose", | 570 LogPollingError("Error calling BluetoothFindDeviceClose", |
571 win::BluetoothClassicWrapper::GetInstance()->LastError()); | 571 win::BluetoothClassicWrapper::GetInstance()->LastError()); |
572 return false; | 572 return false; |
573 } | 573 } |
574 return true; | 574 return true; |
575 } | 575 } |
576 | 576 |
577 bool BluetoothTaskManagerWin::SearchLowEnergyDevices( | 577 bool BluetoothTaskManagerWin::SearchLowEnergyDevices( |
578 ScopedVector<DeviceState>* device_list) { | 578 std::vector<std::unique_ptr<DeviceState>>& device_list) { |
579 if (!win::BluetoothLowEnergyWrapper::GetInstance() | 579 if (!win::BluetoothLowEnergyWrapper::GetInstance() |
580 ->IsBluetoothLowEnergySupported()) { | 580 ->IsBluetoothLowEnergySupported()) { |
581 return true; // Bluetooth LE not supported is not an error. | 581 return true; // Bluetooth LE not supported is not an error. |
582 } | 582 } |
583 | 583 |
584 ScopedVector<win::BluetoothLowEnergyDeviceInfo> btle_devices; | 584 std::vector<std::unique_ptr<win::BluetoothLowEnergyDeviceInfo>> btle_devices; |
585 std::string error; | 585 std::string error; |
586 bool success = | 586 bool success = |
587 win::BluetoothLowEnergyWrapper::GetInstance() | 587 win::BluetoothLowEnergyWrapper::GetInstance() |
588 ->EnumerateKnownBluetoothLowEnergyDevices(&btle_devices, &error); | 588 ->EnumerateKnownBluetoothLowEnergyDevices(&btle_devices, &error); |
589 if (!success) { | 589 if (!success) { |
590 LogPollingError(error.c_str(), 0); | 590 LogPollingError(error.c_str(), 0); |
591 return false; | 591 return false; |
592 } | 592 } |
593 | 593 |
594 for (ScopedVector<win::BluetoothLowEnergyDeviceInfo>::iterator iter = | 594 for (auto& device : btle_devices) { |
595 btle_devices.begin(); | 595 win::BluetoothLowEnergyDeviceInfo* device_info = device; |
596 iter != btle_devices.end(); | |
597 ++iter) { | |
598 win::BluetoothLowEnergyDeviceInfo* device_info = (*iter); | |
599 DeviceState* device_state = new DeviceState(); | 596 DeviceState* device_state = new DeviceState(); |
600 device_state->name = device_info->friendly_name; | 597 device_state->name = device_info->friendly_name; |
601 device_state->address = | 598 device_state->address = |
602 BluetoothAddressToCanonicalString(device_info->address); | 599 BluetoothAddressToCanonicalString(device_info->address); |
603 device_state->visible = device_info->visible; | 600 device_state->visible = device_info->visible; |
604 device_state->authenticated = device_info->authenticated; | 601 device_state->authenticated = device_info->authenticated; |
605 device_state->connected = device_info->connected; | 602 device_state->connected = device_info->connected; |
606 device_state->path = device_info->path; | 603 device_state->path = device_info->path; |
607 device_list->push_back(device_state); | 604 device_list->push_back(device_state); |
608 } | 605 } |
609 return true; | 606 return true; |
610 } | 607 } |
611 | 608 |
612 bool BluetoothTaskManagerWin::DiscoverServices( | 609 bool BluetoothTaskManagerWin::DiscoverServices( |
613 ScopedVector<DeviceState>* device_list, | 610 std::vector<std::unique_ptr<DeviceState>>& device_list, |
614 bool search_cached_services_only) { | 611 bool search_cached_services_only) { |
615 DCHECK(bluetooth_task_runner_->RunsTasksOnCurrentThread()); | 612 DCHECK(bluetooth_task_runner_->RunsTasksOnCurrentThread()); |
616 net::EnsureWinsockInit(); | 613 net::EnsureWinsockInit(); |
617 for (ScopedVector<DeviceState>::iterator iter = device_list->begin(); | 614 for (auto& device : device_list) { |
618 iter != device_list->end(); | 615 std::vector<std::unique_ptr<ServiceRecordState>>& service_record_states = |
619 ++iter) { | 616 &device->service_record_states; |
620 DeviceState* device = (*iter); | |
621 ScopedVector<ServiceRecordState>* service_record_states = | |
622 &(*iter)->service_record_states; | |
623 | 617 |
624 if ((*iter)->is_bluetooth_classic()) { | 618 if ((*iter)->is_bluetooth_classic()) { |
625 if (!DiscoverClassicDeviceServices(device->address, | 619 if (!DiscoverClassicDeviceServices(device->address, |
626 L2CAP_PROTOCOL_UUID, | 620 L2CAP_PROTOCOL_UUID, |
627 search_cached_services_only, | 621 search_cached_services_only, |
628 service_record_states)) { | 622 service_record_states)) { |
629 return false; | 623 return false; |
630 } | 624 } |
631 } else { | 625 } else { |
632 if (!DiscoverLowEnergyDeviceServices(device->path, | 626 if (!DiscoverLowEnergyDeviceServices(device->path, |
633 service_record_states)) { | 627 service_record_states)) { |
634 return false; | 628 return false; |
635 } | 629 } |
636 if (!SearchForGattServiceDevicePaths(device->address, | 630 if (!SearchForGattServiceDevicePaths(device->address, |
637 service_record_states)) { | 631 service_record_states)) { |
638 return false; | 632 return false; |
639 } | 633 } |
640 } | 634 } |
641 } | 635 } |
642 return true; | 636 return true; |
643 } | 637 } |
644 | 638 |
645 bool BluetoothTaskManagerWin::DiscoverClassicDeviceServices( | 639 bool BluetoothTaskManagerWin::DiscoverClassicDeviceServices( |
646 const std::string& device_address, | 640 const std::string& device_address, |
647 const GUID& protocol_uuid, | 641 const GUID& protocol_uuid, |
648 bool search_cached_services_only, | 642 bool search_cached_services_only, |
649 ScopedVector<ServiceRecordState>* service_record_states) { | 643 std::vector<std::unique_ptr<ServiceRecordState>>& service_record_states) { |
650 int error_code = | 644 int error_code = |
651 DiscoverClassicDeviceServicesWorker(device_address, | 645 DiscoverClassicDeviceServicesWorker(device_address, |
652 protocol_uuid, | 646 protocol_uuid, |
653 search_cached_services_only, | 647 search_cached_services_only, |
654 service_record_states); | 648 service_record_states); |
655 // If the device is "offline", no services are returned when specifying | 649 // If the device is "offline", no services are returned when specifying |
656 // "LUP_FLUSHCACHE". Try again without flushing the cache so that the list | 650 // "LUP_FLUSHCACHE". Try again without flushing the cache so that the list |
657 // of previously known services is returned. | 651 // of previously known services is returned. |
658 if (!search_cached_services_only && | 652 if (!search_cached_services_only && |
659 (error_code == WSASERVICE_NOT_FOUND || error_code == WSANO_DATA)) { | 653 (error_code == WSASERVICE_NOT_FOUND || error_code == WSANO_DATA)) { |
660 error_code = DiscoverClassicDeviceServicesWorker( | 654 error_code = DiscoverClassicDeviceServicesWorker( |
661 device_address, protocol_uuid, true, service_record_states); | 655 device_address, protocol_uuid, true, service_record_states); |
662 } | 656 } |
663 | 657 |
664 return (error_code == ERROR_SUCCESS); | 658 return (error_code == ERROR_SUCCESS); |
665 } | 659 } |
666 | 660 |
667 int BluetoothTaskManagerWin::DiscoverClassicDeviceServicesWorker( | 661 int BluetoothTaskManagerWin::DiscoverClassicDeviceServicesWorker( |
668 const std::string& device_address, | 662 const std::string& device_address, |
669 const GUID& protocol_uuid, | 663 const GUID& protocol_uuid, |
670 bool search_cached_services_only, | 664 bool search_cached_services_only, |
671 ScopedVector<ServiceRecordState>* service_record_states) { | 665 Sstd::vector<std::unique_ptr<ServiceRecordState>>& service_record_states) { |
672 // Bluetooth and WSAQUERYSET for Service Inquiry. See http://goo.gl/2v9pyt. | 666 // Bluetooth and WSAQUERYSET for Service Inquiry. See http://goo.gl/2v9pyt. |
673 WSAQUERYSET sdp_query; | 667 WSAQUERYSET sdp_query; |
674 ZeroMemory(&sdp_query, sizeof(sdp_query)); | 668 ZeroMemory(&sdp_query, sizeof(sdp_query)); |
675 sdp_query.dwSize = sizeof(sdp_query); | 669 sdp_query.dwSize = sizeof(sdp_query); |
676 GUID protocol = protocol_uuid; | 670 GUID protocol = protocol_uuid; |
677 sdp_query.lpServiceClassId = &protocol; | 671 sdp_query.lpServiceClassId = &protocol; |
678 sdp_query.dwNameSpace = NS_BTH; | 672 sdp_query.dwNameSpace = NS_BTH; |
679 wchar_t device_address_context[kMaxNumDeviceAddressChar]; | 673 wchar_t device_address_context[kMaxNumDeviceAddressChar]; |
680 std::size_t length = base::SysUTF8ToWide("(" + device_address + ")").copy( | 674 std::size_t length = base::SysUTF8ToWide("(" + device_address + ")").copy( |
681 device_address_context, kMaxNumDeviceAddressChar); | 675 device_address_context, kMaxNumDeviceAddressChar); |
(...skipping 50 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
732 int last_error = WSAGetLastError(); | 726 int last_error = WSAGetLastError(); |
733 LogPollingError("Error calling WSALookupServiceEnd", last_error); | 727 LogPollingError("Error calling WSALookupServiceEnd", last_error); |
734 return last_error; | 728 return last_error; |
735 } | 729 } |
736 | 730 |
737 return ERROR_SUCCESS; | 731 return ERROR_SUCCESS; |
738 } | 732 } |
739 | 733 |
740 bool BluetoothTaskManagerWin::DiscoverLowEnergyDeviceServices( | 734 bool BluetoothTaskManagerWin::DiscoverLowEnergyDeviceServices( |
741 const base::FilePath& device_path, | 735 const base::FilePath& device_path, |
742 ScopedVector<ServiceRecordState>* service_record_states) { | 736 std::vector<std::unique_ptr<ServiceRecordState>>& service_record_states) { |
743 if (!win::BluetoothLowEnergyWrapper::GetInstance() | 737 if (!win::BluetoothLowEnergyWrapper::GetInstance() |
744 ->IsBluetoothLowEnergySupported()) { | 738 ->IsBluetoothLowEnergySupported()) { |
745 return true; // Bluetooth LE not supported is not an error. | 739 return true; // Bluetooth LE not supported is not an error. |
746 } | 740 } |
747 | 741 |
748 std::string error; | 742 std::string error; |
749 ScopedVector<win::BluetoothLowEnergyServiceInfo> services; | 743 std::vector<std::unique_ptr<win::BluetoothLowEnergyServiceInfo>> services; |
750 bool success = win::BluetoothLowEnergyWrapper::GetInstance() | 744 bool success = win::BluetoothLowEnergyWrapper::GetInstance() |
751 ->EnumerateKnownBluetoothLowEnergyServices( | 745 ->EnumerateKnownBluetoothLowEnergyServices( |
752 device_path, &services, &error); | 746 device_path, &services, &error); |
753 if (!success) { | 747 if (!success) { |
754 LogPollingError(error.c_str(), 0); | 748 LogPollingError(error.c_str(), 0); |
755 return false; | 749 return false; |
756 } | 750 } |
757 | 751 |
758 for (ScopedVector<win::BluetoothLowEnergyServiceInfo>::iterator iter2 = | 752 for (auto& service : services) { |
759 services.begin(); | |
760 iter2 != services.end(); | |
761 ++iter2) { | |
762 ServiceRecordState* service_state = new ServiceRecordState(); | 753 ServiceRecordState* service_state = new ServiceRecordState(); |
763 service_state->gatt_uuid = | 754 service_state->gatt_uuid = |
764 BluetoothLowEnergyUuidToBluetoothUuid((*iter2)->uuid); | 755 BluetoothLowEnergyUuidToBluetoothUuid(service->uuid); |
765 service_state->attribute_handle = (*iter2)->attribute_handle; | 756 service_state->attribute_handle = service->attribute_handle; |
766 service_record_states->push_back(service_state); | 757 service_record_states->push_back(service_state); |
767 } | 758 } |
768 return true; | 759 return true; |
769 } | 760 } |
770 | 761 |
771 // Each GATT service of a BLE device will be listed on the machine as a BLE | 762 // Each GATT service of a BLE device will be listed on the machine as a BLE |
772 // device interface with a matching service attribute handle. This interface | 763 // device interface with a matching service attribute handle. This interface |
773 // lists all GATT service devices and matches them back to correspond GATT | 764 // lists all GATT service devices and matches them back to correspond GATT |
774 // service of the BLE device according to their address and included service | 765 // service of the BLE device according to their address and included service |
775 // attribute handles, as we did not find a more neat way to bond them. | 766 // attribute handles, as we did not find a more neat way to bond them. |
776 bool BluetoothTaskManagerWin::SearchForGattServiceDevicePaths( | 767 bool BluetoothTaskManagerWin::SearchForGattServiceDevicePaths( |
777 const std::string device_address, | 768 const std::string device_address, |
778 ScopedVector<ServiceRecordState>* service_record_states) { | 769 std::vector<std::unique_ptr<ServiceRecordState>>& service_record_states) { |
779 std::string error; | 770 std::string error; |
780 | 771 |
781 // List all known GATT service devices on the machine. | 772 // List all known GATT service devices on the machine. |
782 ScopedVector<win::BluetoothLowEnergyDeviceInfo> gatt_service_devices; | 773 std::vector<std::unqiue_ptr<win::BluetoothLowEnergyDeviceInfo>> |
| 774 gatt_service_devices; |
783 bool success = win::BluetoothLowEnergyWrapper::GetInstance() | 775 bool success = win::BluetoothLowEnergyWrapper::GetInstance() |
784 ->EnumerateKnownBluetoothLowEnergyGattServiceDevices( | 776 ->EnumerateKnownBluetoothLowEnergyGattServiceDevices( |
785 &gatt_service_devices, &error); | 777 &gatt_service_devices, &error); |
786 if (!success) { | 778 if (!success) { |
787 LogPollingError(error.c_str(), 0); | 779 LogPollingError(error.c_str(), 0); |
788 return false; | 780 return false; |
789 } | 781 } |
790 | 782 |
791 for (auto* gatt_service_device : gatt_service_devices) { | 783 for (auto& gatt_service_device : gatt_service_devices) { |
792 // Only care about the service devices with |device_address|. | 784 // Only care about the service devices with |device_address|. |
793 if (BluetoothAddressToCanonicalString(gatt_service_device->address) != | 785 if (BluetoothAddressToCanonicalString(gatt_service_device->address) != |
794 device_address) { | 786 device_address) { |
795 continue; | 787 continue; |
796 } | 788 } |
797 | 789 |
798 // Discover this service device's contained services. | 790 // Discover this service device's contained services. |
799 ScopedVector<win::BluetoothLowEnergyServiceInfo> gatt_services; | 791 std::vector<std::unqiue_ptr<win::BluetoothLowEnergyServiceInfo>> |
| 792 gatt_services; |
800 if (!win::BluetoothLowEnergyWrapper::GetInstance() | 793 if (!win::BluetoothLowEnergyWrapper::GetInstance() |
801 ->EnumerateKnownBluetoothLowEnergyServices( | 794 ->EnumerateKnownBluetoothLowEnergyServices( |
802 gatt_service_device->path, &gatt_services, &error)) { | 795 gatt_service_device->path, &gatt_services, &error)) { |
803 LogPollingError(error.c_str(), 0); | 796 LogPollingError(error.c_str(), 0); |
804 continue; | 797 continue; |
805 } | 798 } |
806 | 799 |
807 // Usually each service device correspond to one Gatt service. | 800 // Usually each service device correspond to one Gatt service. |
808 if (gatt_services.size() > 1) { | 801 if (gatt_services.size() > 1) { |
809 LOG(WARNING) << "This GATT service device contains more than one (" | 802 LOG(WARNING) << "This GATT service device contains more than one (" |
810 << gatt_services.size() << ") services"; | 803 << gatt_services.size() << ") services"; |
811 } | 804 } |
812 | 805 |
813 // Associate service device to corresponding service record. Attribute | 806 // Associate service device to corresponding service record. Attribute |
814 // handle is unique on one device. | 807 // handle is unique on one device. |
815 for (auto* gatt_service : gatt_services) { | 808 for (auto& gatt_service : gatt_services) { |
816 for (auto* service_record_state : *service_record_states) { | 809 for (auto& service_record_state : service_record_states) { |
817 if (service_record_state->attribute_handle == | 810 if (service_record_state->attribute_handle == |
818 gatt_service->attribute_handle) { | 811 gatt_service->attribute_handle) { |
819 service_record_state->path = gatt_service_device->path; | 812 service_record_state->path = gatt_service_device->path; |
820 break; | 813 break; |
821 } | 814 } |
822 } | 815 } |
823 } | 816 } |
824 } | 817 } |
825 | 818 |
826 return true; | 819 return true; |
(...skipping 207 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1034 void BluetoothTaskManagerWin::PostUnregisterGattCharacteristicValueChangedEvent( | 1027 void BluetoothTaskManagerWin::PostUnregisterGattCharacteristicValueChangedEvent( |
1035 PVOID event_handle) { | 1028 PVOID event_handle) { |
1036 DCHECK(ui_task_runner_->RunsTasksOnCurrentThread()); | 1029 DCHECK(ui_task_runner_->RunsTasksOnCurrentThread()); |
1037 bluetooth_task_runner_->PostTask( | 1030 bluetooth_task_runner_->PostTask( |
1038 FROM_HERE, base::Bind(&BluetoothTaskManagerWin:: | 1031 FROM_HERE, base::Bind(&BluetoothTaskManagerWin:: |
1039 UnregisterGattCharacteristicValueChangedEvent, | 1032 UnregisterGattCharacteristicValueChangedEvent, |
1040 this, event_handle)); | 1033 this, event_handle)); |
1041 } | 1034 } |
1042 | 1035 |
1043 } // namespace device | 1036 } // namespace device |
OLD | NEW |