Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(221)

Side by Side Diff: device/bluetooth/dbus/fake_bluetooth_gatt_characteristic_service_provider.cc

Issue 1920693002: Complete //device/bt implementation for hosting local GATT attributes. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Created 4 years, 7 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
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/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_manager_client.h" 10 #include "device/bluetooth/dbus/fake_bluetooth_gatt_manager_client.h"
11 11
12 namespace bluez { 12 namespace bluez {
13 13
14 FakeBluetoothGattCharacteristicServiceProvider:: 14 FakeBluetoothGattCharacteristicServiceProvider::
15 FakeBluetoothGattCharacteristicServiceProvider( 15 FakeBluetoothGattCharacteristicServiceProvider(
16 const dbus::ObjectPath& object_path, 16 const dbus::ObjectPath& object_path,
17 Delegate* delegate, 17 std::unique_ptr<BluetoothGattServiceBlueZ::AttributeValueDelegate>
18 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 base::CompareCase::SENSITIVE));
34 33
35 // TODO(armansito): Do something with |flags| and |permissions|. 34 // TODO(armansito): Do something with |flags| and |permissions|.
36
37 FakeBluetoothGattManagerClient* fake_bluetooth_gatt_manager_client = 35 FakeBluetoothGattManagerClient* fake_bluetooth_gatt_manager_client =
38 static_cast<FakeBluetoothGattManagerClient*>( 36 static_cast<FakeBluetoothGattManagerClient*>(
39 bluez::BluezDBusManager::Get()->GetBluetoothGattManagerClient()); 37 bluez::BluezDBusManager::Get()->GetBluetoothGattManagerClient());
40 fake_bluetooth_gatt_manager_client->RegisterCharacteristicServiceProvider( 38 fake_bluetooth_gatt_manager_client->RegisterCharacteristicServiceProvider(
41 this); 39 this);
42 } 40 }
43 41
44 FakeBluetoothGattCharacteristicServiceProvider:: 42 FakeBluetoothGattCharacteristicServiceProvider::
45 ~FakeBluetoothGattCharacteristicServiceProvider() { 43 ~FakeBluetoothGattCharacteristicServiceProvider() {
46 VLOG(1) << "Cleaning up Bluetooth GATT characteristic: " 44 VLOG(1) << "Cleaning up Bluetooth GATT characteristic: "
47 << object_path_.value(); 45 << object_path_.value();
48
49 FakeBluetoothGattManagerClient* fake_bluetooth_gatt_manager_client = 46 FakeBluetoothGattManagerClient* fake_bluetooth_gatt_manager_client =
50 static_cast<FakeBluetoothGattManagerClient*>( 47 static_cast<FakeBluetoothGattManagerClient*>(
51 bluez::BluezDBusManager::Get()->GetBluetoothGattManagerClient()); 48 bluez::BluezDBusManager::Get()->GetBluetoothGattManagerClient());
52 fake_bluetooth_gatt_manager_client->UnregisterCharacteristicServiceProvider( 49 fake_bluetooth_gatt_manager_client->UnregisterCharacteristicServiceProvider(
53 this); 50 this);
54 } 51 }
55 52
56 void FakeBluetoothGattCharacteristicServiceProvider::SendValueChanged( 53 void FakeBluetoothGattCharacteristicServiceProvider::SendValueChanged(
57 const std::vector<uint8_t>& value) { 54 const std::vector<uint8_t>& value) {
58 VLOG(1) << "Sent characteristic value changed: " << object_path_.value() 55 VLOG(1) << "Sent characteristic value changed: " << object_path_.value()
59 << " UUID: " << uuid_; 56 << " UUID: " << uuid_;
60 } 57 }
61 58
62 void FakeBluetoothGattCharacteristicServiceProvider::GetValue( 59 void FakeBluetoothGattCharacteristicServiceProvider::GetValue(
63 const Delegate::ValueCallback& callback, 60 const device::BluetoothLocalGattService::Delegate::ValueCallback& callback,
64 const Delegate::ErrorCallback& error_callback) { 61 const device::BluetoothLocalGattService::Delegate::ErrorCallback&
62 error_callback) {
65 VLOG(1) << "GATT characteristic value Get request: " << object_path_.value() 63 VLOG(1) << "GATT characteristic value Get request: " << object_path_.value()
66 << " UUID: " << uuid_; 64 << " UUID: " << uuid_;
67
68 // Check if this characteristic is registered. 65 // Check if this characteristic is registered.
69 FakeBluetoothGattManagerClient* fake_bluetooth_gatt_manager_client = 66 FakeBluetoothGattManagerClient* fake_bluetooth_gatt_manager_client =
70 static_cast<FakeBluetoothGattManagerClient*>( 67 static_cast<FakeBluetoothGattManagerClient*>(
71 bluez::BluezDBusManager::Get()->GetBluetoothGattManagerClient()); 68 bluez::BluezDBusManager::Get()->GetBluetoothGattManagerClient());
72 if (!fake_bluetooth_gatt_manager_client->IsServiceRegistered(service_path_)) { 69 if (!fake_bluetooth_gatt_manager_client->IsServiceRegistered(service_path_)) {
73 VLOG(1) << "GATT characteristic not registered."; 70 VLOG(1) << "GATT characteristic not registered.";
74 error_callback.Run(); 71 error_callback.Run();
75 return; 72 return;
76 } 73 }
77 74
78 // Pass on to the delegate. 75 // Pass on to the delegate.
79 DCHECK(delegate_); 76 DCHECK(delegate_);
80 delegate_->GetCharacteristicValue(callback, error_callback); 77 delegate_->GetValue(callback, error_callback);
81 } 78 }
82 79
83 void FakeBluetoothGattCharacteristicServiceProvider::SetValue( 80 void FakeBluetoothGattCharacteristicServiceProvider::SetValue(
84 const std::vector<uint8_t>& value, 81 const std::vector<uint8_t>& value,
85 const base::Closure& callback, 82 const base::Closure& callback,
86 const Delegate::ErrorCallback& error_callback) { 83 const device::BluetoothLocalGattService::Delegate::ErrorCallback&
84 error_callback) {
87 VLOG(1) << "GATT characteristic value Set request: " << object_path_.value() 85 VLOG(1) << "GATT characteristic value Set request: " << object_path_.value()
88 << " UUID: " << uuid_; 86 << " UUID: " << uuid_;
89
90 // Check if this characteristic is registered. 87 // Check if this characteristic is registered.
91 FakeBluetoothGattManagerClient* fake_bluetooth_gatt_manager_client = 88 FakeBluetoothGattManagerClient* fake_bluetooth_gatt_manager_client =
92 static_cast<FakeBluetoothGattManagerClient*>( 89 static_cast<FakeBluetoothGattManagerClient*>(
93 bluez::BluezDBusManager::Get()->GetBluetoothGattManagerClient()); 90 bluez::BluezDBusManager::Get()->GetBluetoothGattManagerClient());
94 if (!fake_bluetooth_gatt_manager_client->IsServiceRegistered(service_path_)) { 91 if (!fake_bluetooth_gatt_manager_client->IsServiceRegistered(service_path_)) {
95 VLOG(1) << "GATT characteristic not registered."; 92 VLOG(1) << "GATT characteristic not registered.";
96 error_callback.Run(); 93 error_callback.Run();
97 return; 94 return;
98 } 95 }
99 96
100 // Pass on to the delegate. 97 // Pass on to the delegate.
101 DCHECK(delegate_); 98 DCHECK(delegate_);
102 delegate_->SetCharacteristicValue(value, callback, error_callback); 99 delegate_->SetValue(value, callback, error_callback);
100 }
101
102 const dbus::ObjectPath&
103 FakeBluetoothGattCharacteristicServiceProvider::object_path() const {
104 return object_path_;
103 } 105 }
104 106
105 } // namespace bluez 107 } // namespace bluez
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698