OLD | NEW |
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 "device/bluetooth/bluetooth_remote_gatt_descriptor_android.h" | 5 #include "device/bluetooth/bluetooth_remote_gatt_descriptor_android.h" |
6 | 6 |
7 #include <memory> | 7 #include <memory> |
8 | 8 |
9 #include "base/android/jni_android.h" | 9 #include "base/android/jni_android.h" |
10 #include "base/android/jni_array.h" | 10 #include "base/android/jni_array.h" |
(...skipping 47 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
58 std::string BluetoothRemoteGattDescriptorAndroid::GetIdentifier() const { | 58 std::string BluetoothRemoteGattDescriptorAndroid::GetIdentifier() const { |
59 return instance_id_; | 59 return instance_id_; |
60 } | 60 } |
61 | 61 |
62 BluetoothUUID BluetoothRemoteGattDescriptorAndroid::GetUUID() const { | 62 BluetoothUUID BluetoothRemoteGattDescriptorAndroid::GetUUID() const { |
63 return device::BluetoothUUID( | 63 return device::BluetoothUUID( |
64 ConvertJavaStringToUTF8(Java_ChromeBluetoothRemoteGattDescriptor_getUUID( | 64 ConvertJavaStringToUTF8(Java_ChromeBluetoothRemoteGattDescriptor_getUUID( |
65 AttachCurrentThread(), j_descriptor_.obj()))); | 65 AttachCurrentThread(), j_descriptor_.obj()))); |
66 } | 66 } |
67 | 67 |
68 bool BluetoothRemoteGattDescriptorAndroid::IsLocal() const { | |
69 return false; | |
70 } | |
71 | |
72 const std::vector<uint8_t>& BluetoothRemoteGattDescriptorAndroid::GetValue() | 68 const std::vector<uint8_t>& BluetoothRemoteGattDescriptorAndroid::GetValue() |
73 const { | 69 const { |
74 return value_; | 70 return value_; |
75 } | 71 } |
76 | 72 |
77 BluetoothGattCharacteristic* | 73 BluetoothRemoteGattCharacteristic* |
78 BluetoothRemoteGattDescriptorAndroid::GetCharacteristic() const { | 74 BluetoothRemoteGattDescriptorAndroid::GetCharacteristic() const { |
79 NOTIMPLEMENTED(); | 75 NOTIMPLEMENTED(); |
80 return nullptr; | 76 return nullptr; |
81 } | 77 } |
82 | 78 |
83 BluetoothGattCharacteristic::Permissions | 79 BluetoothRemoteGattCharacteristic::Permissions |
84 BluetoothRemoteGattDescriptorAndroid::GetPermissions() const { | 80 BluetoothRemoteGattDescriptorAndroid::GetPermissions() const { |
85 NOTIMPLEMENTED(); | 81 NOTIMPLEMENTED(); |
86 return 0; | 82 return 0; |
87 } | 83 } |
88 | 84 |
89 void BluetoothRemoteGattDescriptorAndroid::ReadRemoteDescriptor( | 85 void BluetoothRemoteGattDescriptorAndroid::ReadRemoteDescriptor( |
90 const ValueCallback& callback, | 86 const ValueCallback& callback, |
91 const ErrorCallback& error_callback) { | 87 const ErrorCallback& error_callback) { |
92 if (read_pending_ || write_pending_) { | 88 if (read_pending_ || write_pending_) { |
93 base::MessageLoop::current()->PostTask( | 89 base::MessageLoop::current()->PostTask( |
94 FROM_HERE, base::Bind(error_callback, | 90 FROM_HERE, |
95 BluetoothGattService::GATT_ERROR_IN_PROGRESS)); | 91 base::Bind(error_callback, |
| 92 BluetoothRemoteGattService::GATT_ERROR_IN_PROGRESS)); |
96 return; | 93 return; |
97 } | 94 } |
98 | 95 |
99 if (!Java_ChromeBluetoothRemoteGattDescriptor_readRemoteDescriptor( | 96 if (!Java_ChromeBluetoothRemoteGattDescriptor_readRemoteDescriptor( |
100 AttachCurrentThread(), j_descriptor_.obj())) { | 97 AttachCurrentThread(), j_descriptor_.obj())) { |
101 base::MessageLoop::current()->PostTask( | 98 base::MessageLoop::current()->PostTask( |
102 FROM_HERE, | 99 FROM_HERE, |
103 base::Bind(error_callback, | 100 base::Bind(error_callback, |
104 BluetoothRemoteGattServiceAndroid::GATT_ERROR_FAILED)); | 101 BluetoothRemoteGattServiceAndroid::GATT_ERROR_FAILED)); |
105 return; | 102 return; |
106 } | 103 } |
107 | 104 |
108 read_pending_ = true; | 105 read_pending_ = true; |
109 read_callback_ = callback; | 106 read_callback_ = callback; |
110 read_error_callback_ = error_callback; | 107 read_error_callback_ = error_callback; |
111 } | 108 } |
112 | 109 |
113 void BluetoothRemoteGattDescriptorAndroid::WriteRemoteDescriptor( | 110 void BluetoothRemoteGattDescriptorAndroid::WriteRemoteDescriptor( |
114 const std::vector<uint8_t>& new_value, | 111 const std::vector<uint8_t>& new_value, |
115 const base::Closure& callback, | 112 const base::Closure& callback, |
116 const ErrorCallback& error_callback) { | 113 const ErrorCallback& error_callback) { |
117 if (read_pending_ || write_pending_) { | 114 if (read_pending_ || write_pending_) { |
118 base::MessageLoop::current()->PostTask( | 115 base::MessageLoop::current()->PostTask( |
119 FROM_HERE, base::Bind(error_callback, | 116 FROM_HERE, |
120 BluetoothGattService::GATT_ERROR_IN_PROGRESS)); | 117 base::Bind(error_callback, |
| 118 BluetoothRemoteGattService::GATT_ERROR_IN_PROGRESS)); |
121 return; | 119 return; |
122 } | 120 } |
123 | 121 |
124 JNIEnv* env = AttachCurrentThread(); | 122 JNIEnv* env = AttachCurrentThread(); |
125 if (!Java_ChromeBluetoothRemoteGattDescriptor_writeRemoteDescriptor( | 123 if (!Java_ChromeBluetoothRemoteGattDescriptor_writeRemoteDescriptor( |
126 env, j_descriptor_.obj(), | 124 env, j_descriptor_.obj(), |
127 base::android::ToJavaByteArray(env, new_value).obj())) { | 125 base::android::ToJavaByteArray(env, new_value).obj())) { |
128 base::MessageLoop::current()->PostTask( | 126 base::MessageLoop::current()->PostTask( |
129 FROM_HERE, | 127 FROM_HERE, |
130 base::Bind(error_callback, | 128 base::Bind(error_callback, |
(...skipping 50 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
181 write_error_callback.Run( | 179 write_error_callback.Run( |
182 BluetoothRemoteGattServiceAndroid::GetGattErrorCode(status)); | 180 BluetoothRemoteGattServiceAndroid::GetGattErrorCode(status)); |
183 } | 181 } |
184 } | 182 } |
185 | 183 |
186 BluetoothRemoteGattDescriptorAndroid::BluetoothRemoteGattDescriptorAndroid( | 184 BluetoothRemoteGattDescriptorAndroid::BluetoothRemoteGattDescriptorAndroid( |
187 const std::string& instance_id) | 185 const std::string& instance_id) |
188 : instance_id_(instance_id) {} | 186 : instance_id_(instance_id) {} |
189 | 187 |
190 } // namespace device | 188 } // namespace device |
OLD | NEW |