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_characteristic_win.h" |
| 6 |
| 7 #include "device/bluetooth/bluetooth_adapter_win.h" |
| 8 #include "device/bluetooth/bluetooth_remote_gatt_service_win.h" |
| 9 #include "device/bluetooth/bluetooth_task_manager_win.h" |
| 10 |
| 11 namespace device { |
| 12 |
| 13 BluetoothRemoteGattCharacteristicWin::BluetoothRemoteGattCharacteristicWin( |
| 14 BluetoothRemoteGattServiceWin* parent_service, |
| 15 BTH_LE_GATT_CHARACTERISTIC* characteristic_info, |
| 16 scoped_refptr<base::SequencedTaskRunner>& ui_task_runner) |
| 17 : parent_service_(parent_service), |
| 18 characteristic_info_(characteristic_info), |
| 19 ui_task_runner_(ui_task_runner), |
| 20 weak_ptr_factory_(this) { |
| 21 DCHECK(ui_task_runner_->RunsTasksOnCurrentThread()); |
| 22 DCHECK(parent_service_); |
| 23 DCHECK(characteristic_info_); |
| 24 |
| 25 adapter_ = static_cast<BluetoothAdapterWin*>( |
| 26 parent_service_->GetDevice()->GetAdapter()); |
| 27 DCHECK(adapter_); |
| 28 task_manager_ = adapter_->GetWinBluetoothTaskManager(); |
| 29 DCHECK(task_manager_); |
| 30 |
| 31 characteristic_uuid_ = task_manager_->BluetoothLowEnergyUuidToBluetoothUuid( |
| 32 characteristic_info_->CharacteristicUuid); |
| 33 characteristic_identifier_ = |
| 34 parent_service_->GetIdentifier() + |
| 35 std::to_string(characteristic_info_->AttributeHandle); |
| 36 Update(); |
| 37 } |
| 38 |
| 39 BluetoothRemoteGattCharacteristicWin::~BluetoothRemoteGattCharacteristicWin() { |
| 40 DCHECK(ui_task_runner_->RunsTasksOnCurrentThread()); |
| 41 |
| 42 adapter_->NotifyGattCharacteristicRemoved(this); |
| 43 } |
| 44 |
| 45 std::string BluetoothRemoteGattCharacteristicWin::GetIdentifier() const { |
| 46 return characteristic_identifier_; |
| 47 } |
| 48 |
| 49 BluetoothUUID BluetoothRemoteGattCharacteristicWin::GetUUID() const { |
| 50 return characteristic_uuid_; |
| 51 } |
| 52 |
| 53 bool BluetoothRemoteGattCharacteristicWin::IsLocal() const { |
| 54 return false; |
| 55 } |
| 56 |
| 57 std::vector<uint8_t>& BluetoothRemoteGattCharacteristicWin::GetValue() const { |
| 58 NOTIMPLEMENTED(); |
| 59 return const_cast<std::vector<uint8_t>&>(characteristic_value_); |
| 60 } |
| 61 |
| 62 BluetoothGattService* BluetoothRemoteGattCharacteristicWin::GetService() const { |
| 63 return parent_service_; |
| 64 } |
| 65 |
| 66 BluetoothGattCharacteristic::Properties |
| 67 BluetoothRemoteGattCharacteristicWin::GetProperties() const { |
| 68 BluetoothGattCharacteristic::Properties properties = PROPERTY_NONE; |
| 69 |
| 70 if (characteristic_info_->IsBroadcastable) |
| 71 properties = properties | PROPERTY_BROADCAST; |
| 72 if (characteristic_info_->IsReadable) |
| 73 properties = properties | PROPERTY_READ; |
| 74 if (characteristic_info_->IsWritableWithoutResponse) |
| 75 properties = properties | PROPERTY_WRITE_WITHOUT_RESPONSE; |
| 76 if (characteristic_info_->IsWritable) |
| 77 properties = properties | PROPERTY_WRITE; |
| 78 if (characteristic_info_->IsNotifiable) |
| 79 properties = properties | PROPERTY_NOTIFY; |
| 80 if (characteristic_info_->IsIndicatable) |
| 81 properties = properties | PROPERTY_INDICATE; |
| 82 if (characteristic_info_->IsSignedWritable) |
| 83 properties = properties | PROPERTY_AUTHENTICATED_SIGNED_WRITES; |
| 84 if (characteristic_info_->HasExtendedProperties) |
| 85 properties = properties | PROPERTY_EXTENDED_PROPERTIES; |
| 86 |
| 87 // TODO(crbug.com/589304): Information about PROPERTY_RELIABLE_WRITE and |
| 88 // PROPERTY_WRITABLE_AUXILIARIES is not available in characteristic_info_ |
| 89 // (BTH_LE_GATT_CHARACTERISTIC). |
| 90 |
| 91 return properties; |
| 92 } |
| 93 |
| 94 BluetoothGattCharacteristic::Permissions |
| 95 BluetoothRemoteGattCharacteristicWin::GetPermissions() const { |
| 96 BluetoothGattCharacteristic::Permissions permissions = PERMISSION_NONE; |
| 97 |
| 98 if (characteristic_info_->IsReadable) |
| 99 permissions = permissions | PERMISSION_READ; |
| 100 if (characteristic_info_->IsWritable) |
| 101 permissions = permissions | PERMISSION_WRITE; |
| 102 |
| 103 return permissions; |
| 104 } |
| 105 |
| 106 bool BluetoothRemoteGattCharacteristicWin::IsNotifying() const { |
| 107 NOTIMPLEMENTED(); |
| 108 return false; |
| 109 } |
| 110 |
| 111 std::vector<BluetoothGattDescriptor*> |
| 112 BluetoothRemoteGattCharacteristicWin::GetDescriptors() const { |
| 113 NOTIMPLEMENTED(); |
| 114 return std::vector<BluetoothGattDescriptor*>(); |
| 115 } |
| 116 |
| 117 BluetoothGattDescriptor* BluetoothRemoteGattCharacteristicWin::GetDescriptor( |
| 118 const std::string& identifier) const { |
| 119 NOTIMPLEMENTED(); |
| 120 return nullptr; |
| 121 } |
| 122 |
| 123 bool BluetoothRemoteGattCharacteristicWin::AddDescriptor( |
| 124 BluetoothGattDescriptor* descriptor) { |
| 125 NOTIMPLEMENTED(); |
| 126 return false; |
| 127 } |
| 128 |
| 129 bool BluetoothRemoteGattCharacteristicWin::UpdateValue( |
| 130 const std::vector<uint8_t>& value) { |
| 131 NOTIMPLEMENTED(); |
| 132 return false; |
| 133 } |
| 134 |
| 135 void BluetoothRemoteGattCharacteristicWin::StartNotifySession( |
| 136 const NotifySessionCallback& callback, |
| 137 const ErrorCallback& error_callback) { |
| 138 NOTIMPLEMENTED(); |
| 139 error_callback.Run(BluetoothGattService::GATT_ERROR_NOT_SUPPORTED); |
| 140 } |
| 141 |
| 142 void BluetoothRemoteGattCharacteristicWin::ReadRemoteCharacteristic( |
| 143 const ValueCallback& callback, |
| 144 const ErrorCallback& error_callback) { |
| 145 NOTIMPLEMENTED(); |
| 146 error_callback.Run(BluetoothGattService::GATT_ERROR_NOT_SUPPORTED); |
| 147 } |
| 148 |
| 149 void BluetoothRemoteGattCharacteristicWin::WriteRemoteCharacteristic( |
| 150 const std::vector<uint8_t>& new_value, |
| 151 const base::Closure& callback, |
| 152 const ErrorCallback& error_callback) { |
| 153 NOTIMPLEMENTED(); |
| 154 error_callback.Run(BluetoothGattService::GATT_ERROR_NOT_SUPPORTED); |
| 155 } |
| 156 |
| 157 void BluetoothRemoteGattCharacteristicWin::Update() { |
| 158 DCHECK(ui_task_runner_->RunsTasksOnCurrentThread()); |
| 159 NOTIMPLEMENTED(); |
| 160 } |
| 161 |
| 162 uint16_t BluetoothRemoteGattCharacteristicWin::GetAttributeHandle() const { |
| 163 return characteristic_info_->AttributeHandle; |
| 164 } |
| 165 |
| 166 } // namespace device. |
OLD | NEW |