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