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