| OLD | NEW |
| 1 // Copyright 2014 The Chromium Authors. All rights reserved. | 1 // Copyright 2014 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/dbus/fake_bluetooth_gatt_descriptor_service_provider.
h" | 5 #include "device/bluetooth/dbus/fake_bluetooth_gatt_descriptor_service_provider.
h" |
| 6 | 6 |
| 7 #include "base/logging.h" | 7 #include "base/logging.h" |
| 8 #include "base/strings/string_util.h" | 8 #include "base/strings/string_util.h" |
| 9 #include "device/bluetooth/dbus/bluez_dbus_manager.h" | 9 #include "device/bluetooth/dbus/bluez_dbus_manager.h" |
| 10 #include "device/bluetooth/dbus/fake_bluetooth_gatt_characteristic_service_provi
der.h" | 10 #include "device/bluetooth/dbus/fake_bluetooth_gatt_characteristic_service_provi
der.h" |
| 11 #include "device/bluetooth/dbus/fake_bluetooth_gatt_manager_client.h" | 11 #include "device/bluetooth/dbus/fake_bluetooth_gatt_manager_client.h" |
| 12 | 12 |
| 13 namespace bluez { | 13 namespace bluez { |
| 14 | 14 |
| 15 FakeBluetoothGattDescriptorServiceProvider:: | 15 FakeBluetoothGattDescriptorServiceProvider:: |
| 16 FakeBluetoothGattDescriptorServiceProvider( | 16 FakeBluetoothGattDescriptorServiceProvider( |
| 17 const dbus::ObjectPath& object_path, | 17 const dbus::ObjectPath& object_path, |
| 18 Delegate* delegate, | 18 BluetoothGattServiceBlueZ::AttributeValueDelegate* delegate, |
| 19 const std::string& uuid, | 19 const std::string& uuid, |
| 20 const std::vector<std::string>& permissions, | 20 const std::vector<std::string>& permissions, |
| 21 const dbus::ObjectPath& characteristic_path) | 21 const dbus::ObjectPath& characteristic_path) |
| 22 : object_path_(object_path), | 22 : object_path_(object_path), |
| 23 uuid_(uuid), | 23 uuid_(uuid), |
| 24 characteristic_path_(characteristic_path), | 24 characteristic_path_(characteristic_path), |
| 25 delegate_(delegate) { | 25 delegate_(delegate) { |
| 26 VLOG(1) << "Creating Bluetooth GATT descriptor: " << object_path_.value(); | 26 VLOG(1) << "Creating Bluetooth GATT descriptor: " << object_path_.value(); |
| 27 | 27 |
| 28 DCHECK(object_path_.IsValid()); | 28 DCHECK(object_path_.IsValid()); |
| 29 DCHECK(characteristic_path_.IsValid()); | 29 DCHECK(characteristic_path_.IsValid()); |
| 30 DCHECK(!uuid.empty()); | 30 DCHECK(!uuid.empty()); |
| 31 DCHECK(delegate_); | 31 DCHECK(delegate_); |
| 32 DCHECK(base::StartsWith(object_path_.value(), | |
| 33 characteristic_path_.value() + "/", | |
| 34 base::CompareCase::SENSITIVE)); | |
| 35 | 32 |
| 36 // TODO(armansito): Do something with |permissions|. | 33 // TODO(armansito): Do something with |permissions|. |
| 37 | 34 |
| 38 FakeBluetoothGattManagerClient* fake_bluetooth_gatt_manager_client = | 35 FakeBluetoothGattManagerClient* fake_bluetooth_gatt_manager_client = |
| 39 static_cast<FakeBluetoothGattManagerClient*>( | 36 static_cast<FakeBluetoothGattManagerClient*>( |
| 40 bluez::BluezDBusManager::Get()->GetBluetoothGattManagerClient()); | 37 bluez::BluezDBusManager::Get()->GetBluetoothGattManagerClient()); |
| 41 fake_bluetooth_gatt_manager_client->RegisterDescriptorServiceProvider(this); | 38 fake_bluetooth_gatt_manager_client->RegisterDescriptorServiceProvider(this); |
| 42 } | 39 } |
| 43 | 40 |
| 44 FakeBluetoothGattDescriptorServiceProvider:: | 41 FakeBluetoothGattDescriptorServiceProvider:: |
| 45 ~FakeBluetoothGattDescriptorServiceProvider() { | 42 ~FakeBluetoothGattDescriptorServiceProvider() { |
| 46 VLOG(1) << "Cleaning up Bluetooth GATT descriptor: " << object_path_.value(); | 43 VLOG(1) << "Cleaning up Bluetooth GATT descriptor: " << object_path_.value(); |
| 47 | 44 |
| 48 FakeBluetoothGattManagerClient* fake_bluetooth_gatt_manager_client = | 45 FakeBluetoothGattManagerClient* fake_bluetooth_gatt_manager_client = |
| 49 static_cast<FakeBluetoothGattManagerClient*>( | 46 static_cast<FakeBluetoothGattManagerClient*>( |
| 50 bluez::BluezDBusManager::Get()->GetBluetoothGattManagerClient()); | 47 bluez::BluezDBusManager::Get()->GetBluetoothGattManagerClient()); |
| 51 fake_bluetooth_gatt_manager_client->UnregisterDescriptorServiceProvider(this); | 48 fake_bluetooth_gatt_manager_client->UnregisterDescriptorServiceProvider(this); |
| 52 } | 49 } |
| 53 | 50 |
| 54 void FakeBluetoothGattDescriptorServiceProvider::SendValueChanged( | 51 void FakeBluetoothGattDescriptorServiceProvider::SendValueChanged( |
| 55 const std::vector<uint8_t>& value) { | 52 const std::vector<uint8_t>& value) { |
| 56 VLOG(1) << "Sent descriptor value changed: " << object_path_.value() | 53 VLOG(1) << "Sent descriptor value changed: " << object_path_.value() |
| 57 << " UUID: " << uuid_; | 54 << " UUID: " << uuid_; |
| 58 } | 55 } |
| 59 | 56 |
| 60 void FakeBluetoothGattDescriptorServiceProvider::GetValue( | 57 void FakeBluetoothGattDescriptorServiceProvider::GetValue( |
| 61 const Delegate::ValueCallback& callback, | 58 const device::BluetoothLocalGattService::Delegate::ValueCallback& callback, |
| 62 const Delegate::ErrorCallback& error_callback) { | 59 const device::BluetoothLocalGattService::Delegate::ErrorCallback& |
| 60 error_callback) { |
| 63 VLOG(1) << "GATT descriptor value Get request: " << object_path_.value() | 61 VLOG(1) << "GATT descriptor value Get request: " << object_path_.value() |
| 64 << " UUID: " << uuid_; | 62 << " UUID: " << uuid_; |
| 65 | |
| 66 // Check if this descriptor is registered. | 63 // Check if this descriptor is registered. |
| 67 FakeBluetoothGattManagerClient* fake_bluetooth_gatt_manager_client = | 64 FakeBluetoothGattManagerClient* fake_bluetooth_gatt_manager_client = |
| 68 static_cast<FakeBluetoothGattManagerClient*>( | 65 static_cast<FakeBluetoothGattManagerClient*>( |
| 69 bluez::BluezDBusManager::Get()->GetBluetoothGattManagerClient()); | 66 bluez::BluezDBusManager::Get()->GetBluetoothGattManagerClient()); |
| 70 FakeBluetoothGattCharacteristicServiceProvider* characteristic = | 67 FakeBluetoothGattCharacteristicServiceProvider* characteristic = |
| 71 fake_bluetooth_gatt_manager_client->GetCharacteristicServiceProvider( | 68 fake_bluetooth_gatt_manager_client->GetCharacteristicServiceProvider( |
| 72 characteristic_path_); | 69 characteristic_path_); |
| 73 if (!characteristic) { | 70 if (!characteristic) { |
| 74 VLOG(1) << "GATT characteristic for descriptor does not exist: " | 71 VLOG(1) << "GATT characteristic for descriptor does not exist: " |
| 75 << characteristic_path_.value(); | 72 << characteristic_path_.value(); |
| 76 return; | 73 return; |
| 77 } | 74 } |
| 78 if (!fake_bluetooth_gatt_manager_client->IsServiceRegistered( | 75 if (!fake_bluetooth_gatt_manager_client->IsServiceRegistered( |
| 79 characteristic->service_path())) { | 76 characteristic->service_path())) { |
| 80 VLOG(1) << "GATT descriptor not registered."; | 77 VLOG(1) << "GATT descriptor not registered."; |
| 81 error_callback.Run(); | 78 error_callback.Run(); |
| 82 return; | 79 return; |
| 83 } | 80 } |
| 84 | 81 |
| 85 // Pass on to the delegate. | 82 // Pass on to the delegate. |
| 86 DCHECK(delegate_); | 83 DCHECK(delegate_); |
| 87 delegate_->GetDescriptorValue(callback, error_callback); | 84 delegate_->GetValue(callback, error_callback); |
| 88 } | 85 } |
| 89 | 86 |
| 90 void FakeBluetoothGattDescriptorServiceProvider::SetValue( | 87 void FakeBluetoothGattDescriptorServiceProvider::SetValue( |
| 91 const std::vector<uint8_t>& value, | 88 const std::vector<uint8_t>& value, |
| 92 const base::Closure& callback, | 89 const base::Closure& callback, |
| 93 const Delegate::ErrorCallback& error_callback) { | 90 const device::BluetoothLocalGattService::Delegate::ErrorCallback& |
| 91 error_callback) { |
| 94 VLOG(1) << "GATT descriptor value Set request: " << object_path_.value() | 92 VLOG(1) << "GATT descriptor value Set request: " << object_path_.value() |
| 95 << " UUID: " << uuid_; | 93 << " UUID: " << uuid_; |
| 96 | 94 |
| 97 // Check if this descriptor is registered. | 95 // Check if this descriptor is registered. |
| 98 FakeBluetoothGattManagerClient* fake_bluetooth_gatt_manager_client = | 96 FakeBluetoothGattManagerClient* fake_bluetooth_gatt_manager_client = |
| 99 static_cast<FakeBluetoothGattManagerClient*>( | 97 static_cast<FakeBluetoothGattManagerClient*>( |
| 100 bluez::BluezDBusManager::Get()->GetBluetoothGattManagerClient()); | 98 bluez::BluezDBusManager::Get()->GetBluetoothGattManagerClient()); |
| 101 FakeBluetoothGattCharacteristicServiceProvider* characteristic = | 99 FakeBluetoothGattCharacteristicServiceProvider* characteristic = |
| 102 fake_bluetooth_gatt_manager_client->GetCharacteristicServiceProvider( | 100 fake_bluetooth_gatt_manager_client->GetCharacteristicServiceProvider( |
| 103 characteristic_path_); | 101 characteristic_path_); |
| 104 if (!characteristic) { | 102 if (!characteristic) { |
| 105 VLOG(1) << "GATT characteristic for descriptor does not exist: " | 103 VLOG(1) << "GATT characteristic for descriptor does not exist: " |
| 106 << characteristic_path_.value(); | 104 << characteristic_path_.value(); |
| 107 return; | 105 return; |
| 108 } | 106 } |
| 109 if (!fake_bluetooth_gatt_manager_client->IsServiceRegistered( | 107 if (!fake_bluetooth_gatt_manager_client->IsServiceRegistered( |
| 110 characteristic->service_path())) { | 108 characteristic->service_path())) { |
| 111 VLOG(1) << "GATT descriptor not registered."; | 109 VLOG(1) << "GATT descriptor not registered."; |
| 112 error_callback.Run(); | 110 error_callback.Run(); |
| 113 return; | 111 return; |
| 114 } | 112 } |
| 115 | 113 |
| 116 // Pass on to the delegate. | 114 // Pass on to the delegate. |
| 117 DCHECK(delegate_); | 115 DCHECK(delegate_); |
| 118 delegate_->SetDescriptorValue(value, callback, error_callback); | 116 delegate_->SetValue(value, callback, error_callback); |
| 117 } |
| 118 |
| 119 const dbus::ObjectPath& |
| 120 FakeBluetoothGattDescriptorServiceProvider::object_path() const { |
| 121 return object_path_; |
| 119 } | 122 } |
| 120 | 123 |
| 121 } // namespace bluez | 124 } // namespace bluez |
| OLD | NEW |