| 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 "chromeos/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 "chromeos/dbus/dbus_thread_manager.h" | 9 #include "device/bluetooth/dbus/bluez_dbus_manager.h" |
| 10 #include "chromeos/dbus/fake_bluetooth_gatt_characteristic_service_provider.h" | 10 #include "device/bluetooth/dbus/fake_bluetooth_gatt_characteristic_service_provi
der.h" |
| 11 #include "chromeos/dbus/fake_bluetooth_gatt_manager_client.h" | 11 #include "device/bluetooth/dbus/fake_bluetooth_gatt_manager_client.h" |
| 12 | 12 |
| 13 namespace chromeos { | 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 Delegate* 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(), | 32 DCHECK(base::StartsWith(object_path_.value(), |
| 33 characteristic_path_.value() + "/", | 33 characteristic_path_.value() + "/", |
| 34 base::CompareCase::SENSITIVE)); | 34 base::CompareCase::SENSITIVE)); |
| 35 | 35 |
| 36 // TODO(armansito): Do something with |permissions|. | 36 // TODO(armansito): Do something with |permissions|. |
| 37 | 37 |
| 38 FakeBluetoothGattManagerClient* fake_bluetooth_gatt_manager_client = | 38 FakeBluetoothGattManagerClient* fake_bluetooth_gatt_manager_client = |
| 39 static_cast<FakeBluetoothGattManagerClient*>( | 39 static_cast<FakeBluetoothGattManagerClient*>( |
| 40 DBusThreadManager::Get()->GetBluetoothGattManagerClient()); | 40 bluez::BluezDBusManager::Get()->GetBluetoothGattManagerClient()); |
| 41 fake_bluetooth_gatt_manager_client-> | 41 fake_bluetooth_gatt_manager_client->RegisterDescriptorServiceProvider(this); |
| 42 RegisterDescriptorServiceProvider(this); | |
| 43 } | 42 } |
| 44 | 43 |
| 45 FakeBluetoothGattDescriptorServiceProvider:: | 44 FakeBluetoothGattDescriptorServiceProvider:: |
| 46 ~FakeBluetoothGattDescriptorServiceProvider() { | 45 ~FakeBluetoothGattDescriptorServiceProvider() { |
| 47 VLOG(1) << "Cleaning up Bluetooth GATT descriptor: " | 46 VLOG(1) << "Cleaning up Bluetooth GATT descriptor: " << object_path_.value(); |
| 48 << object_path_.value(); | |
| 49 | 47 |
| 50 FakeBluetoothGattManagerClient* fake_bluetooth_gatt_manager_client = | 48 FakeBluetoothGattManagerClient* fake_bluetooth_gatt_manager_client = |
| 51 static_cast<FakeBluetoothGattManagerClient*>( | 49 static_cast<FakeBluetoothGattManagerClient*>( |
| 52 DBusThreadManager::Get()->GetBluetoothGattManagerClient()); | 50 bluez::BluezDBusManager::Get()->GetBluetoothGattManagerClient()); |
| 53 fake_bluetooth_gatt_manager_client-> | 51 fake_bluetooth_gatt_manager_client->UnregisterDescriptorServiceProvider(this); |
| 54 UnregisterDescriptorServiceProvider(this); | |
| 55 } | 52 } |
| 56 | 53 |
| 57 void FakeBluetoothGattDescriptorServiceProvider::SendValueChanged( | 54 void FakeBluetoothGattDescriptorServiceProvider::SendValueChanged( |
| 58 const std::vector<uint8>& value) { | 55 const std::vector<uint8>& value) { |
| 59 VLOG(1) << "Sent descriptor value changed: " << object_path_.value() | 56 VLOG(1) << "Sent descriptor value changed: " << object_path_.value() |
| 60 << " UUID: " << uuid_; | 57 << " UUID: " << uuid_; |
| 61 } | 58 } |
| 62 | 59 |
| 63 void FakeBluetoothGattDescriptorServiceProvider::GetValue( | 60 void FakeBluetoothGattDescriptorServiceProvider::GetValue( |
| 64 const Delegate::ValueCallback& callback, | 61 const Delegate::ValueCallback& callback, |
| 65 const Delegate::ErrorCallback& error_callback) { | 62 const Delegate::ErrorCallback& error_callback) { |
| 66 VLOG(1) << "GATT descriptor value Get request: " << object_path_.value() | 63 VLOG(1) << "GATT descriptor value Get request: " << object_path_.value() |
| 67 << " UUID: " << uuid_; | 64 << " UUID: " << uuid_; |
| 68 | 65 |
| 69 // Check if this descriptor is registered. | 66 // Check if this descriptor is registered. |
| 70 FakeBluetoothGattManagerClient* fake_bluetooth_gatt_manager_client = | 67 FakeBluetoothGattManagerClient* fake_bluetooth_gatt_manager_client = |
| 71 static_cast<FakeBluetoothGattManagerClient*>( | 68 static_cast<FakeBluetoothGattManagerClient*>( |
| 72 DBusThreadManager::Get()->GetBluetoothGattManagerClient()); | 69 bluez::BluezDBusManager::Get()->GetBluetoothGattManagerClient()); |
| 73 FakeBluetoothGattCharacteristicServiceProvider* characteristic = | 70 FakeBluetoothGattCharacteristicServiceProvider* characteristic = |
| 74 fake_bluetooth_gatt_manager_client->GetCharacteristicServiceProvider( | 71 fake_bluetooth_gatt_manager_client->GetCharacteristicServiceProvider( |
| 75 characteristic_path_); | 72 characteristic_path_); |
| 76 if (!characteristic) { | 73 if (!characteristic) { |
| 77 VLOG(1) << "GATT characteristic for descriptor does not exist: " | 74 VLOG(1) << "GATT characteristic for descriptor does not exist: " |
| 78 << characteristic_path_.value(); | 75 << characteristic_path_.value(); |
| 79 return; | 76 return; |
| 80 } | 77 } |
| 81 if (!fake_bluetooth_gatt_manager_client->IsServiceRegistered( | 78 if (!fake_bluetooth_gatt_manager_client->IsServiceRegistered( |
| 82 characteristic->service_path())) { | 79 characteristic->service_path())) { |
| (...skipping 10 matching lines...) Expand all Loading... |
| 93 void FakeBluetoothGattDescriptorServiceProvider::SetValue( | 90 void FakeBluetoothGattDescriptorServiceProvider::SetValue( |
| 94 const std::vector<uint8>& value, | 91 const std::vector<uint8>& value, |
| 95 const base::Closure& callback, | 92 const base::Closure& callback, |
| 96 const Delegate::ErrorCallback& error_callback) { | 93 const Delegate::ErrorCallback& error_callback) { |
| 97 VLOG(1) << "GATT descriptor value Set request: " << object_path_.value() | 94 VLOG(1) << "GATT descriptor value Set request: " << object_path_.value() |
| 98 << " UUID: " << uuid_; | 95 << " UUID: " << uuid_; |
| 99 | 96 |
| 100 // Check if this descriptor is registered. | 97 // Check if this descriptor is registered. |
| 101 FakeBluetoothGattManagerClient* fake_bluetooth_gatt_manager_client = | 98 FakeBluetoothGattManagerClient* fake_bluetooth_gatt_manager_client = |
| 102 static_cast<FakeBluetoothGattManagerClient*>( | 99 static_cast<FakeBluetoothGattManagerClient*>( |
| 103 DBusThreadManager::Get()->GetBluetoothGattManagerClient()); | 100 bluez::BluezDBusManager::Get()->GetBluetoothGattManagerClient()); |
| 104 FakeBluetoothGattCharacteristicServiceProvider* characteristic = | 101 FakeBluetoothGattCharacteristicServiceProvider* characteristic = |
| 105 fake_bluetooth_gatt_manager_client->GetCharacteristicServiceProvider( | 102 fake_bluetooth_gatt_manager_client->GetCharacteristicServiceProvider( |
| 106 characteristic_path_); | 103 characteristic_path_); |
| 107 if (!characteristic) { | 104 if (!characteristic) { |
| 108 VLOG(1) << "GATT characteristic for descriptor does not exist: " | 105 VLOG(1) << "GATT characteristic for descriptor does not exist: " |
| 109 << characteristic_path_.value(); | 106 << characteristic_path_.value(); |
| 110 return; | 107 return; |
| 111 } | 108 } |
| 112 if (!fake_bluetooth_gatt_manager_client->IsServiceRegistered( | 109 if (!fake_bluetooth_gatt_manager_client->IsServiceRegistered( |
| 113 characteristic->service_path())) { | 110 characteristic->service_path())) { |
| 114 VLOG(1) << "GATT descriptor not registered."; | 111 VLOG(1) << "GATT descriptor not registered."; |
| 115 error_callback.Run(); | 112 error_callback.Run(); |
| 116 return; | 113 return; |
| 117 } | 114 } |
| 118 | 115 |
| 119 // Pass on to the delegate. | 116 // Pass on to the delegate. |
| 120 DCHECK(delegate_); | 117 DCHECK(delegate_); |
| 121 delegate_->SetDescriptorValue(value, callback, error_callback); | 118 delegate_->SetDescriptorValue(value, callback, error_callback); |
| 122 } | 119 } |
| 123 | 120 |
| 124 } // namespace chromeos | 121 } // namespace bluez |
| OLD | NEW |