| OLD | NEW |
| (Empty) | |
| 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 |
| 3 // found in the LICENSE file. |
| 4 |
| 5 #include "device/bluetooth/bluetooth_remote_gatt_descriptor_android.h" |
| 6 |
| 7 #include "base/android/jni_android.h" |
| 8 #include "base/android/jni_array.h" |
| 9 #include "base/android/jni_string.h" |
| 10 #include "base/bind.h" |
| 11 #include "base/logging.h" |
| 12 #include "base/message_loop/message_loop.h" |
| 13 #include "device/bluetooth/bluetooth_adapter_android.h" |
| 14 #include "device/bluetooth/bluetooth_gatt_notify_session_android.h" |
| 15 #include "device/bluetooth/bluetooth_remote_gatt_service_android.h" |
| 16 #include "jni/ChromeBluetoothRemoteGattDescriptor_jni.h" |
| 17 |
| 18 using base::android::AttachCurrentThread; |
| 19 |
| 20 namespace device { |
| 21 |
| 22 // static |
| 23 scoped_ptr<BluetoothRemoteGattDescriptorAndroid> |
| 24 BluetoothRemoteGattDescriptorAndroid::Create( |
| 25 BluetoothAdapterAndroid* adapter, |
| 26 const std::string& instance_id, |
| 27 jobject /* BluetoothGattDescriptorWrapper */ |
| 28 bluetooth_gatt_descriptor_wrapper, |
| 29 jobject /* chromeBluetoothDevice */ |
| 30 chrome_bluetooth_device) { |
| 31 scoped_ptr<BluetoothRemoteGattDescriptorAndroid> descriptor( |
| 32 new BluetoothRemoteGattDescriptorAndroid(adapter, instance_id)); |
| 33 |
| 34 descriptor->j_descriptor_.Reset( |
| 35 Java_ChromeBluetoothRemoteGattDescriptor_create( |
| 36 AttachCurrentThread(), |
| 37 // TODO(scheib) Will eventually need to pass c++ pointer: |
| 38 // reinterpret_cast<intptr_t>(descriptor.get()), |
| 39 bluetooth_gatt_descriptor_wrapper, chrome_bluetooth_device)); |
| 40 |
| 41 return descriptor; |
| 42 } |
| 43 |
| 44 BluetoothRemoteGattDescriptorAndroid::~BluetoothRemoteGattDescriptorAndroid() { |
| 45 Java_ChromeBluetoothRemoteGattDescriptor_onBluetoothRemoteGattDescriptorAndroi
dDestruction( |
| 46 AttachCurrentThread(), j_descriptor_.obj()); |
| 47 } |
| 48 |
| 49 // static |
| 50 bool BluetoothRemoteGattDescriptorAndroid::RegisterJNI(JNIEnv* env) { |
| 51 return RegisterNativesImpl( |
| 52 env); // Generated in ChromeBluetoothRemoteGattDescriptor_jni.h |
| 53 } |
| 54 |
| 55 base::android::ScopedJavaLocalRef<jobject> |
| 56 BluetoothRemoteGattDescriptorAndroid::GetJavaObject() { |
| 57 return base::android::ScopedJavaLocalRef<jobject>(j_descriptor_); |
| 58 } |
| 59 |
| 60 std::string BluetoothRemoteGattDescriptorAndroid::GetIdentifier() const { |
| 61 return instance_id_; |
| 62 } |
| 63 |
| 64 BluetoothUUID BluetoothRemoteGattDescriptorAndroid::GetUUID() const { |
| 65 return device::BluetoothUUID( |
| 66 ConvertJavaStringToUTF8(Java_ChromeBluetoothRemoteGattDescriptor_getUUID( |
| 67 AttachCurrentThread(), j_descriptor_.obj()))); |
| 68 } |
| 69 |
| 70 bool BluetoothRemoteGattDescriptorAndroid::IsLocal() const { |
| 71 return false; |
| 72 } |
| 73 |
| 74 const std::vector<uint8_t>& BluetoothRemoteGattDescriptorAndroid::GetValue() |
| 75 const { |
| 76 NOTIMPLEMENTED(); |
| 77 static std::vector<uint8_t> empty_value; |
| 78 return empty_value; |
| 79 } |
| 80 |
| 81 BluetoothGattCharacteristic* |
| 82 BluetoothRemoteGattDescriptorAndroid::GetCharacteristic() const { |
| 83 NOTIMPLEMENTED(); |
| 84 return nullptr; |
| 85 } |
| 86 |
| 87 BluetoothGattCharacteristic::Permissions |
| 88 BluetoothRemoteGattDescriptorAndroid::GetPermissions() const { |
| 89 NOTIMPLEMENTED(); |
| 90 return 0; |
| 91 } |
| 92 |
| 93 void BluetoothRemoteGattDescriptorAndroid::ReadRemoteDescriptor( |
| 94 const ValueCallback& callback, |
| 95 const ErrorCallback& error_callback) { |
| 96 NOTIMPLEMENTED(); |
| 97 base::MessageLoop::current()->PostTask( |
| 98 FROM_HERE, |
| 99 base::Bind(error_callback, BluetoothGattService::GATT_ERROR_FAILED)); |
| 100 } |
| 101 |
| 102 void BluetoothRemoteGattDescriptorAndroid::WriteRemoteDescriptor( |
| 103 const std::vector<uint8_t>& new_value, |
| 104 const base::Closure& callback, |
| 105 const ErrorCallback& error_callback) { |
| 106 NOTIMPLEMENTED(); |
| 107 base::MessageLoop::current()->PostTask( |
| 108 FROM_HERE, |
| 109 base::Bind(error_callback, BluetoothGattService::GATT_ERROR_FAILED)); |
| 110 } |
| 111 |
| 112 BluetoothRemoteGattDescriptorAndroid::BluetoothRemoteGattDescriptorAndroid( |
| 113 BluetoothAdapterAndroid* adapter, |
| 114 const std::string& instance_id) |
| 115 : adapter_(adapter), instance_id_(instance_id) {} |
| 116 |
| 117 } // namespace device |
| OLD | NEW |