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

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

Issue 2104043002: arc: bluetooth: Implement Gatt Server add/delete/start/stop service (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@gs1
Patch Set: Created 4 years, 5 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
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 <fcntl.h> 7 #include <fcntl.h>
8 #include <stddef.h> 8 #include <stddef.h>
9 9
10 #include <iomanip> 10 #include <iomanip>
(...skipping 35 matching lines...) Expand 10 before | Expand all | Expand 10 after
46 using device::BluetoothLocalGattDescriptor; 46 using device::BluetoothLocalGattDescriptor;
47 using device::BluetoothLocalGattService; 47 using device::BluetoothLocalGattService;
48 using device::BluetoothRemoteGattCharacteristic; 48 using device::BluetoothRemoteGattCharacteristic;
49 using device::BluetoothRemoteGattDescriptor; 49 using device::BluetoothRemoteGattDescriptor;
50 using device::BluetoothRemoteGattService; 50 using device::BluetoothRemoteGattService;
51 using device::BluetoothUUID; 51 using device::BluetoothUUID;
52 52
53 namespace { 53 namespace {
54 constexpr int32_t kMinBtleVersion = 1; 54 constexpr int32_t kMinBtleVersion = 1;
55 constexpr int32_t kMinBtleNotifyVersion = 2; 55 constexpr int32_t kMinBtleNotifyVersion = 2;
56 constexpr int32_t kMinGattServerVersion = 3;
56 constexpr uint32_t kGattReadPermission = 57 constexpr uint32_t kGattReadPermission =
57 BluetoothGattCharacteristic::Permission::PERMISSION_READ | 58 BluetoothGattCharacteristic::Permission::PERMISSION_READ |
58 BluetoothGattCharacteristic::Permission::PERMISSION_READ_ENCRYPTED | 59 BluetoothGattCharacteristic::Permission::PERMISSION_READ_ENCRYPTED |
59 BluetoothGattCharacteristic::Permission:: 60 BluetoothGattCharacteristic::Permission::
60 PERMISSION_READ_ENCRYPTED_AUTHENTICATED; 61 PERMISSION_READ_ENCRYPTED_AUTHENTICATED;
61 constexpr uint32_t kGattWritePermission = 62 constexpr uint32_t kGattWritePermission =
62 BluetoothGattCharacteristic::Permission::PERMISSION_WRITE | 63 BluetoothGattCharacteristic::Permission::PERMISSION_WRITE |
63 BluetoothGattCharacteristic::Permission::PERMISSION_WRITE_ENCRYPTED | 64 BluetoothGattCharacteristic::Permission::PERMISSION_WRITE_ENCRYPTED |
64 BluetoothGattCharacteristic::Permission:: 65 BluetoothGattCharacteristic::Permission::
65 PERMISSION_WRITE_ENCRYPTED_AUTHENTICATED; 66 PERMISSION_WRITE_ENCRYPTED_AUTHENTICATED;
67 constexpr int32_t kInvalidGattAttributeHandle = -1;
66 } // namespace 68 } // namespace
67 69
68 namespace arc { 70 namespace arc {
69 71
70 ArcBluetoothBridge::ArcBluetoothBridge(ArcBridgeService* bridge_service) 72 ArcBluetoothBridge::ArcBluetoothBridge(ArcBridgeService* bridge_service)
71 : ArcService(bridge_service), binding_(this), weak_factory_(this) { 73 : ArcService(bridge_service), binding_(this), weak_factory_(this) {
72 if (BluetoothAdapterFactory::IsBluetoothAdapterAvailable()) { 74 if (BluetoothAdapterFactory::IsBluetoothAdapterAvailable()) {
73 VLOG(1) << "registering bluetooth adapter"; 75 VLOG(1) << "registering bluetooth adapter";
74 BluetoothAdapterFactory::GetAdapter(base::Bind( 76 BluetoothAdapterFactory::GetAdapter(base::Bind(
75 &ArcBluetoothBridge::OnAdapterInitialized, weak_factory_.GetWeakPtr())); 77 &ArcBluetoothBridge::OnAdapterInitialized, weak_factory_.GetWeakPtr()));
(...skipping 784 matching lines...) Expand 10 before | Expand all | Expand 10 after
860 mojom::BluetoothGattIDPtr desc_id) const { 862 mojom::BluetoothGattIDPtr desc_id) const {
861 BluetoothRemoteGattCharacteristic* characteristic = FindGattCharacteristic( 863 BluetoothRemoteGattCharacteristic* characteristic = FindGattCharacteristic(
862 std::move(remote_addr), std::move(service_id), std::move(char_id)); 864 std::move(remote_addr), std::move(service_id), std::move(char_id));
863 if (!characteristic) 865 if (!characteristic)
864 return nullptr; 866 return nullptr;
865 867
866 return FindGattObjectFromUuid<BluetoothRemoteGattDescriptor>( 868 return FindGattObjectFromUuid<BluetoothRemoteGattDescriptor>(
867 characteristic->GetDescriptors(), desc_id->uuid.To<BluetoothUUID>()); 869 characteristic->GetDescriptors(), desc_id->uuid.To<BluetoothUUID>());
868 } 870 }
869 871
872 // Common callback function for Gatt operation that only need to report
873 // Gatt status back to Android.
874 void ArcBluetoothBridge::OnGattOperationDone(
875 const GattStatusCallback& callback) const {
876 callback.Run(mojom::BluetoothGattStatus::GATT_SUCCESS);
877 }
878
879 void ArcBluetoothBridge::OnGattOperationError(
880 const GattStatusCallback& callback,
881 BluetoothGattService::GattErrorCode error_code) const {
882 callback.Run(mojo::ConvertTo<mojom::BluetoothGattStatus>(error_code));
883 }
884
870 // Same callback for both ReadGattCharacteristic and ReadGattDescriptor 885 // Same callback for both ReadGattCharacteristic and ReadGattDescriptor
871 void ArcBluetoothBridge::OnGattReadDone( 886 void ArcBluetoothBridge::OnGattReadDone(
872 const GattReadCallback& callback, 887 const GattReadCallback& callback,
873 const std::vector<uint8_t>& result) const { 888 const std::vector<uint8_t>& result) const {
874 mojom::BluetoothGattValuePtr gattValue = mojom::BluetoothGattValue::New(); 889 mojom::BluetoothGattValuePtr gattValue = mojom::BluetoothGattValue::New();
875 gattValue->status = mojom::BluetoothGattStatus::GATT_SUCCESS; 890 gattValue->status = mojom::BluetoothGattStatus::GATT_SUCCESS;
876 gattValue->value = mojo::Array<uint8_t>::From(result); 891 gattValue->value = mojo::Array<uint8_t>::From(result);
877 callback.Run(std::move(gattValue)); 892 callback.Run(std::move(gattValue));
878 } 893 }
879 894
880 void ArcBluetoothBridge::OnGattReadError( 895 void ArcBluetoothBridge::OnGattReadError(
881 const GattReadCallback& callback, 896 const GattReadCallback& callback,
882 BluetoothGattService::GattErrorCode error_code) const { 897 BluetoothGattService::GattErrorCode error_code) const {
883 mojom::BluetoothGattValuePtr gattValue = mojom::BluetoothGattValue::New(); 898 mojom::BluetoothGattValuePtr gattValue = mojom::BluetoothGattValue::New();
884 gattValue->status = mojo::ConvertTo<mojom::BluetoothGattStatus>(error_code); 899 gattValue->status = mojo::ConvertTo<mojom::BluetoothGattStatus>(error_code);
885 gattValue->value = nullptr; 900 gattValue->value = nullptr;
886 901
887 callback.Run(std::move(gattValue)); 902 callback.Run(std::move(gattValue));
888 } 903 }
889 904
890 // Same callback for both WriteGattCharacteristic and WriteGattDescriptor
891 void ArcBluetoothBridge::OnGattWriteDone(
892 const GattWriteCallback& callback) const {
893 callback.Run(mojom::BluetoothGattStatus::GATT_SUCCESS);
894 }
895
896 void ArcBluetoothBridge::OnGattWriteError(
897 const GattWriteCallback& callback,
898 BluetoothGattService::GattErrorCode error_code) const {
899 callback.Run(mojo::ConvertTo<mojom::BluetoothGattStatus>(error_code));
900 }
901
902 void ArcBluetoothBridge::ReadGattCharacteristic( 905 void ArcBluetoothBridge::ReadGattCharacteristic(
903 mojom::BluetoothAddressPtr remote_addr, 906 mojom::BluetoothAddressPtr remote_addr,
904 mojom::BluetoothGattServiceIDPtr service_id, 907 mojom::BluetoothGattServiceIDPtr service_id,
905 mojom::BluetoothGattIDPtr char_id, 908 mojom::BluetoothGattIDPtr char_id,
906 const ReadGattCharacteristicCallback& callback) { 909 const ReadGattCharacteristicCallback& callback) {
907 BluetoothRemoteGattCharacteristic* characteristic = FindGattCharacteristic( 910 BluetoothRemoteGattCharacteristic* characteristic = FindGattCharacteristic(
908 std::move(remote_addr), std::move(service_id), std::move(char_id)); 911 std::move(remote_addr), std::move(service_id), std::move(char_id));
909 DCHECK(characteristic); 912 DCHECK(characteristic);
910 DCHECK(characteristic->GetPermissions() & kGattReadPermission); 913 DCHECK(characteristic->GetPermissions() & kGattReadPermission);
911 914
(...skipping 10 matching lines...) Expand all
922 mojom::BluetoothGattIDPtr char_id, 925 mojom::BluetoothGattIDPtr char_id,
923 mojom::BluetoothGattValuePtr value, 926 mojom::BluetoothGattValuePtr value,
924 const WriteGattCharacteristicCallback& callback) { 927 const WriteGattCharacteristicCallback& callback) {
925 BluetoothRemoteGattCharacteristic* characteristic = FindGattCharacteristic( 928 BluetoothRemoteGattCharacteristic* characteristic = FindGattCharacteristic(
926 std::move(remote_addr), std::move(service_id), std::move(char_id)); 929 std::move(remote_addr), std::move(service_id), std::move(char_id));
927 DCHECK(characteristic); 930 DCHECK(characteristic);
928 DCHECK(characteristic->GetPermissions() & kGattWritePermission); 931 DCHECK(characteristic->GetPermissions() & kGattWritePermission);
929 932
930 characteristic->WriteRemoteCharacteristic( 933 characteristic->WriteRemoteCharacteristic(
931 value->value.To<std::vector<uint8_t>>(), 934 value->value.To<std::vector<uint8_t>>(),
932 base::Bind(&ArcBluetoothBridge::OnGattWriteDone, 935 base::Bind(&ArcBluetoothBridge::OnGattOperationDone,
933 weak_factory_.GetWeakPtr(), callback), 936 weak_factory_.GetWeakPtr(), callback),
934 base::Bind(&ArcBluetoothBridge::OnGattWriteError, 937 base::Bind(&ArcBluetoothBridge::OnGattOperationError,
935 weak_factory_.GetWeakPtr(), callback)); 938 weak_factory_.GetWeakPtr(), callback));
936 } 939 }
937 940
938 void ArcBluetoothBridge::ReadGattDescriptor( 941 void ArcBluetoothBridge::ReadGattDescriptor(
939 mojom::BluetoothAddressPtr remote_addr, 942 mojom::BluetoothAddressPtr remote_addr,
940 mojom::BluetoothGattServiceIDPtr service_id, 943 mojom::BluetoothGattServiceIDPtr service_id,
941 mojom::BluetoothGattIDPtr char_id, 944 mojom::BluetoothGattIDPtr char_id,
942 mojom::BluetoothGattIDPtr desc_id, 945 mojom::BluetoothGattIDPtr desc_id,
943 const ReadGattDescriptorCallback& callback) { 946 const ReadGattDescriptorCallback& callback) {
944 BluetoothRemoteGattDescriptor* descriptor = 947 BluetoothRemoteGattDescriptor* descriptor =
(...skipping 24 matching lines...) Expand all
969 972
970 // To register / deregister GATT notification, we need to 973 // To register / deregister GATT notification, we need to
971 // 1) Write to CCC Descriptor to enable/disable the notification 974 // 1) Write to CCC Descriptor to enable/disable the notification
972 // 2) Ask BT hw to register / deregister the notification 975 // 2) Ask BT hw to register / deregister the notification
973 // The Chrome API groups both steps into one API, and does not support writing 976 // The Chrome API groups both steps into one API, and does not support writing
974 // directly to the CCC Descriptor. Therefore, until we fix 977 // directly to the CCC Descriptor. Therefore, until we fix
975 // https://crbug.com/622832, we return successfully when we encounter this. 978 // https://crbug.com/622832, we return successfully when we encounter this.
976 // TODO(http://crbug.com/622832) 979 // TODO(http://crbug.com/622832)
977 if (descriptor->GetUUID() == 980 if (descriptor->GetUUID() ==
978 BluetoothGattDescriptor::ClientCharacteristicConfigurationUuid()) { 981 BluetoothGattDescriptor::ClientCharacteristicConfigurationUuid()) {
979 OnGattWriteDone(callback); 982 OnGattOperationDone(callback);
980 return; 983 return;
981 } 984 }
982 985
983 descriptor->WriteRemoteDescriptor( 986 descriptor->WriteRemoteDescriptor(
984 value->value.To<std::vector<uint8_t>>(), 987 value->value.To<std::vector<uint8_t>>(),
985 base::Bind(&ArcBluetoothBridge::OnGattWriteDone, 988 base::Bind(&ArcBluetoothBridge::OnGattOperationDone,
986 weak_factory_.GetWeakPtr(), callback), 989 weak_factory_.GetWeakPtr(), callback),
987 base::Bind(&ArcBluetoothBridge::OnGattWriteError, 990 base::Bind(&ArcBluetoothBridge::OnGattOperationError,
988 weak_factory_.GetWeakPtr(), callback)); 991 weak_factory_.GetWeakPtr(), callback));
989 } 992 }
990 993
991 void ArcBluetoothBridge::OnGattNotifyStartDone( 994 void ArcBluetoothBridge::OnGattNotifyStartDone(
992 const RegisterForGattNotificationCallback& callback, 995 const RegisterForGattNotificationCallback& callback,
993 const std::string char_string_id, 996 const std::string char_string_id,
994 std::unique_ptr<BluetoothGattNotifySession> notify_session) { 997 std::unique_ptr<BluetoothGattNotifySession> notify_session) {
995 notification_session_[char_string_id] = std::move(notify_session); 998 notification_session_[char_string_id] = std::move(notify_session);
996 callback.Run(mojom::BluetoothGattStatus::GATT_SUCCESS); 999 callback.Run(mojom::BluetoothGattStatus::GATT_SUCCESS);
997 } 1000 }
998 1001
999 void ArcBluetoothBridge::OnGattNotifyStartError(
1000 const RegisterForGattNotificationCallback& callback,
1001 BluetoothGattService::GattErrorCode error_code) const {
1002 callback.Run(mojo::ConvertTo<mojom::BluetoothGattStatus>(error_code));
1003 }
1004
1005 void ArcBluetoothBridge::OnGattNotifyStopDone(
1006 const DeregisterForGattNotificationCallback& callback) const {
1007 callback.Run(mojom::BluetoothGattStatus::GATT_SUCCESS);
1008 }
1009
1010 void ArcBluetoothBridge::RegisterForGattNotification( 1002 void ArcBluetoothBridge::RegisterForGattNotification(
1011 mojom::BluetoothAddressPtr remote_addr, 1003 mojom::BluetoothAddressPtr remote_addr,
1012 mojom::BluetoothGattServiceIDPtr service_id, 1004 mojom::BluetoothGattServiceIDPtr service_id,
1013 mojom::BluetoothGattIDPtr char_id, 1005 mojom::BluetoothGattIDPtr char_id,
1014 const RegisterForGattNotificationCallback& callback) { 1006 const RegisterForGattNotificationCallback& callback) {
1015 BluetoothRemoteGattCharacteristic* characteristic = FindGattCharacteristic( 1007 BluetoothRemoteGattCharacteristic* characteristic = FindGattCharacteristic(
1016 std::move(remote_addr), std::move(service_id), std::move(char_id)); 1008 std::move(remote_addr), std::move(service_id), std::move(char_id));
1017 1009
1018 if (!characteristic) { 1010 if (!characteristic) {
1019 LOG(WARNING) << __func__ << " Characteristic is not existed."; 1011 LOG(WARNING) << __func__ << " Characteristic is not existed.";
1020 return; 1012 return;
1021 } 1013 }
1022 1014
1023 if (characteristic->IsNotifying()) { 1015 if (characteristic->IsNotifying()) {
1024 callback.Run(mojom::BluetoothGattStatus::GATT_SUCCESS); 1016 callback.Run(mojom::BluetoothGattStatus::GATT_SUCCESS);
1025 return; 1017 return;
1026 } 1018 }
1027 1019
1028 characteristic->StartNotifySession( 1020 characteristic->StartNotifySession(
1029 base::Bind(&ArcBluetoothBridge::OnGattNotifyStartDone, 1021 base::Bind(&ArcBluetoothBridge::OnGattNotifyStartDone,
1030 weak_factory_.GetWeakPtr(), callback, 1022 weak_factory_.GetWeakPtr(), callback,
1031 characteristic->GetIdentifier()), 1023 characteristic->GetIdentifier()),
1032 base::Bind(&ArcBluetoothBridge::OnGattNotifyStartError, 1024 base::Bind(&ArcBluetoothBridge::OnGattOperationError,
1033 weak_factory_.GetWeakPtr(), callback)); 1025 weak_factory_.GetWeakPtr(), callback));
1034 } 1026 }
1035 1027
1036 void ArcBluetoothBridge::DeregisterForGattNotification( 1028 void ArcBluetoothBridge::DeregisterForGattNotification(
1037 mojom::BluetoothAddressPtr remote_addr, 1029 mojom::BluetoothAddressPtr remote_addr,
1038 mojom::BluetoothGattServiceIDPtr service_id, 1030 mojom::BluetoothGattServiceIDPtr service_id,
1039 mojom::BluetoothGattIDPtr char_id, 1031 mojom::BluetoothGattIDPtr char_id,
1040 const DeregisterForGattNotificationCallback& callback) { 1032 const DeregisterForGattNotificationCallback& callback) {
1041 BluetoothRemoteGattCharacteristic* characteristic = FindGattCharacteristic( 1033 BluetoothRemoteGattCharacteristic* characteristic = FindGattCharacteristic(
1042 std::move(remote_addr), std::move(service_id), std::move(char_id)); 1034 std::move(remote_addr), std::move(service_id), std::move(char_id));
1043 1035
1044 if (!characteristic) { 1036 if (!characteristic) {
1045 LOG(WARNING) << __func__ << " Characteristic is not existed."; 1037 LOG(WARNING) << __func__ << " Characteristic is not existed.";
1046 return; 1038 return;
1047 } 1039 }
1048 1040
1049 if (!characteristic->IsNotifying()) { 1041 if (!characteristic->IsNotifying()) {
1050 callback.Run(mojom::BluetoothGattStatus::GATT_SUCCESS); 1042 callback.Run(mojom::BluetoothGattStatus::GATT_SUCCESS);
1051 return; 1043 return;
1052 } 1044 }
1053 1045
1054 std::string char_id_str = characteristic->GetIdentifier(); 1046 std::string char_id_str = characteristic->GetIdentifier();
1055 std::unique_ptr<BluetoothGattNotifySession> notify = 1047 std::unique_ptr<BluetoothGattNotifySession> notify =
1056 std::move(notification_session_[char_id_str]); 1048 std::move(notification_session_[char_id_str]);
1057 notification_session_.erase(char_id_str); 1049 notification_session_.erase(char_id_str);
1058 notify->Stop(base::Bind(&ArcBluetoothBridge::OnGattNotifyStopDone, 1050 notify->Stop(base::Bind(&ArcBluetoothBridge::OnGattOperationDone,
1059 weak_factory_.GetWeakPtr(), callback)); 1051 weak_factory_.GetWeakPtr(), callback));
1060 } 1052 }
1061 1053
1062 void ArcBluetoothBridge::ReadRemoteRssi( 1054 void ArcBluetoothBridge::ReadRemoteRssi(
1063 mojom::BluetoothAddressPtr remote_addr, 1055 mojom::BluetoothAddressPtr remote_addr,
1064 const ReadRemoteRssiCallback& callback) { 1056 const ReadRemoteRssiCallback& callback) {
1065 BluetoothDevice* device = 1057 BluetoothDevice* device =
1066 bluetooth_adapter_->GetDevice(remote_addr->To<std::string>()); 1058 bluetooth_adapter_->GetDevice(remote_addr->To<std::string>());
1067 int rssi = device->GetInquiryRSSI(); 1059 int rssi = device->GetInquiryRSSI();
1068 callback.Run(rssi); 1060 callback.Run(rssi);
1069 } 1061 }
1070 1062
1063 template <class T>
1064 int32_t ArcBluetoothBridge::CreateGattAttributeHandle(T* gatt_obj) {
1065 if (!gatt_obj)
1066 return kInvalidGattAttributeHandle;
1067 std::string identifier = gatt_obj->GetIdentifier();
1068 int32_t id = ConvertGattIdentifierToId(identifier);
rkc 2016/07/01 22:21:46 This function won't work with IDs returned by gatt
puthik_chromium 2016/07/14 19:01:47 I added the incremental handle count.
1069 DCHECK(gatt_identifier_.find(id) == gatt_identifier_.end());
1070 gatt_identifier_[id] = identifier;
1071 return id;
1072 }
1073
1071 void ArcBluetoothBridge::AddService(mojom::BluetoothGattServiceIDPtr service_id, 1074 void ArcBluetoothBridge::AddService(mojom::BluetoothGattServiceIDPtr service_id,
1072 int32_t num_handles, 1075 int32_t num_handles,
1073 const AddServiceCallback& callback) {} 1076 const AddServiceCallback& callback) {
1077 base::WeakPtr<BluetoothLocalGattService> service =
1078 BluetoothLocalGattService::Create(
1079 bluetooth_adapter_.get(), service_id->id->uuid.To<BluetoothUUID>(),
1080 service_id->is_primary, nullptr /*included_service */,
1081 this /* delegate*/);
1082 callback.Run(
1083 CreateGattAttributeHandle<BluetoothLocalGattService>(service.get()));
1084 }
1074 1085
1075 void ArcBluetoothBridge::AddCharacteristic( 1086 void ArcBluetoothBridge::AddCharacteristic(
1076 int32_t service_handle, 1087 int32_t service_handle,
1077 mojom::BluetoothUUIDPtr uuid, 1088 mojom::BluetoothUUIDPtr uuid,
1078 int32_t properties, 1089 int32_t properties,
1079 int32_t permissions, 1090 int32_t permissions,
1080 const AddCharacteristicCallback& callback) {} 1091 const AddCharacteristicCallback& callback) {
1092 base::WeakPtr<BluetoothLocalGattCharacteristic> characteristic =
1093 BluetoothLocalGattCharacteristic::Create(
1094 uuid.To<BluetoothUUID>(), properties, permissions,
1095 bluetooth_adapter_->GetGattService(gatt_identifier_[service_handle]));
1096 callback.Run(CreateGattAttributeHandle<BluetoothLocalGattCharacteristic>(
1097 characteristic.get()));
1098 }
1081 1099
1082 void ArcBluetoothBridge::AddDescriptor(int32_t service_handle, 1100 void ArcBluetoothBridge::AddDescriptor(int32_t service_handle,
1083 mojom::BluetoothUUIDPtr uuid, 1101 mojom::BluetoothUUIDPtr uuid,
1084 int32_t permissions, 1102 int32_t permissions,
1085 const AddDescriptorCallback& callback) {} 1103 const AddDescriptorCallback& callback) {
1104 // TODO(next patch version) Android send service handle not characteristic.
rkc 2016/07/01 22:21:45 TODO(puthik)? So this is because on Android, you
puthik_chromium 2016/07/14 19:01:47 I add the descriptor to the last added characteris
rkc 2016/07/14 23:15:25 Have you read through the Android code to verify t
1105 // That's not make sense.
1106 }
1086 1107
1087 void ArcBluetoothBridge::StartService(int32_t service_handle, 1108 void ArcBluetoothBridge::StartService(int32_t service_handle,
1088 int32_t transport, 1109 int32_t transport,
1089 const StartServiceCallback& callback) {} 1110 const StartServiceCallback& callback) {
1111 BluetoothLocalGattService* service =
1112 bluetooth_adapter_->GetGattService(gatt_identifier_[service_handle]);
1113 service->Register(base::Bind(&ArcBluetoothBridge::OnGattOperationDone,
1114 weak_factory_.GetWeakPtr(), callback),
1115 base::Bind(&ArcBluetoothBridge::OnGattOperationError,
1116 weak_factory_.GetWeakPtr(), callback));
1117 }
1090 1118
1091 void ArcBluetoothBridge::StopService(int32_t service_handle, 1119 void ArcBluetoothBridge::StopService(int32_t service_handle,
1092 const StopServiceCallback& callback) {} 1120 const StopServiceCallback& callback) {
1121 BluetoothLocalGattService* service =
1122 bluetooth_adapter_->GetGattService(gatt_identifier_[service_handle]);
1123 service->Unregister(base::Bind(&ArcBluetoothBridge::OnGattOperationDone,
1124 weak_factory_.GetWeakPtr(), callback),
1125 base::Bind(&ArcBluetoothBridge::OnGattOperationError,
1126 weak_factory_.GetWeakPtr(), callback));
1127 }
1093 1128
1094 void ArcBluetoothBridge::DeleteService(int32_t service_handle, 1129 void ArcBluetoothBridge::DeleteService(int32_t service_handle,
1095 const DeleteServiceCallback& callback) {} 1130 const DeleteServiceCallback& callback) {
1131 BluetoothLocalGattService* service =
1132 bluetooth_adapter_->GetGattService(gatt_identifier_[service_handle]);
1133 service->Delete();
1134 gatt_identifier_.erase(service_handle);
1135 OnGattOperationDone(callback);
1136 }
1096 1137
1097 void ArcBluetoothBridge::SendIndication( 1138 void ArcBluetoothBridge::SendIndication(
1098 int32_t attribute_handle, 1139 int32_t attribute_handle,
1099 mojom::BluetoothAddressPtr address, 1140 mojom::BluetoothAddressPtr address,
1100 int32_t confirm, 1141 int32_t confirm,
1101 mojo::Array<uint8_t> value, 1142 mojo::Array<uint8_t> value,
1102 const SendIndicationCallback& callback) {} 1143 const SendIndicationCallback& callback) {}
1103 1144
1104 void ArcBluetoothBridge::SendResponse(int32_t trans_id, 1145 void ArcBluetoothBridge::SendResponse(int32_t trans_id,
1105 int32_t status, 1146 int32_t status,
(...skipping 331 matching lines...) Expand 10 before | Expand all | Expand 10 after
1437 int32_t version_need) const { 1478 int32_t version_need) const {
1438 int32_t version = arc_bridge_service()->bluetooth_version(); 1479 int32_t version = arc_bridge_service()->bluetooth_version();
1439 if (version >= version_need) 1480 if (version >= version_need)
1440 return true; 1481 return true;
1441 LOG(WARNING) << "Bluetooth instance is too old (version " << version 1482 LOG(WARNING) << "Bluetooth instance is too old (version " << version
1442 << ") need version " << version_need; 1483 << ") need version " << version_need;
1443 return false; 1484 return false;
1444 } 1485 }
1445 1486
1446 } // namespace arc 1487 } // namespace arc
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698