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

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

Issue 1947353002: //device/bluetooth support for attribute properties and permissions. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@properties
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 <algorithm>
8 #include <iterator>
9
7 #include "base/callback.h" 10 #include "base/callback.h"
8 #include "base/logging.h" 11 #include "base/logging.h"
9 #include "base/strings/string_util.h" 12 #include "base/strings/string_util.h"
13 #include "device/bluetooth/dbus/bluetooth_gatt_attribute_value_delegate.h"
10 #include "device/bluetooth/dbus/bluez_dbus_manager.h" 14 #include "device/bluetooth/dbus/bluez_dbus_manager.h"
11 #include "device/bluetooth/dbus/fake_bluetooth_gatt_manager_client.h" 15 #include "device/bluetooth/dbus/fake_bluetooth_gatt_manager_client.h"
16 #include "third_party/cros_system_api/dbus/service_constants.h"
12 17
13 namespace bluez { 18 namespace bluez {
14 19
20 namespace {
21
22 bool CanWrite(const std::vector<std::string>& flags) {
23 if (find(flags.begin(), flags.end(),
24 bluetooth_gatt_characteristic::kFlagWrite) != flags.end())
25 return true;
26 if (find(flags.begin(), flags.end(),
27 bluetooth_gatt_characteristic::kFlagWriteWithoutResponse) !=
28 flags.end())
29 return true;
30 if (find(flags.begin(), flags.end(),
31 bluetooth_gatt_characteristic::kFlagReliableWrite) != flags.end())
32 return true;
33 if (find(flags.begin(), flags.end(),
34 bluetooth_gatt_characteristic::kFlagEncryptWrite) != flags.end())
35 return true;
36 if (find(flags.begin(), flags.end(),
37 bluetooth_gatt_characteristic::kFlagEncryptAuthenticatedWrite) !=
38 flags.end())
39 return true;
40 return false;
41 }
42
43 bool CanRead(const std::vector<std::string>& flags) {
44 if (find(flags.begin(), flags.end(),
45 bluetooth_gatt_characteristic::kFlagRead) != flags.end())
46 return true;
47 if (find(flags.begin(), flags.end(),
48 bluetooth_gatt_characteristic::kFlagEncryptRead) != flags.end())
49 return true;
50 if (find(flags.begin(), flags.end(),
51 bluetooth_gatt_characteristic::kFlagEncryptAuthenticatedRead) !=
52 flags.end())
53 return true;
54 return false;
55 }
56
57 } // namespace
58
15 FakeBluetoothGattCharacteristicServiceProvider:: 59 FakeBluetoothGattCharacteristicServiceProvider::
16 FakeBluetoothGattCharacteristicServiceProvider( 60 FakeBluetoothGattCharacteristicServiceProvider(
17 const dbus::ObjectPath& object_path, 61 const dbus::ObjectPath& object_path,
18 std::unique_ptr<BluetoothGattAttributeValueDelegate> delegate, 62 std::unique_ptr<BluetoothGattAttributeValueDelegate> delegate,
19 const std::string& uuid, 63 const std::string& uuid,
20 const std::vector<std::string>& flags, 64 const std::vector<std::string>& flags,
21 const dbus::ObjectPath& service_path) 65 const dbus::ObjectPath& service_path)
22 : object_path_(object_path), 66 : object_path_(object_path),
23 uuid_(uuid), 67 uuid_(uuid),
68 flags_(flags),
24 service_path_(service_path), 69 service_path_(service_path),
25 delegate_(std::move(delegate)) { 70 delegate_(std::move(delegate)) {
26 VLOG(1) << "Creating Bluetooth GATT characteristic: " << object_path_.value(); 71 VLOG(1) << "Creating Bluetooth GATT characteristic: " << object_path_.value();
27 72
28 DCHECK(object_path_.IsValid()); 73 DCHECK(object_path_.IsValid());
29 DCHECK(service_path_.IsValid()); 74 DCHECK(service_path_.IsValid());
30 DCHECK(!uuid.empty()); 75 DCHECK(!uuid.empty());
31 DCHECK(delegate_); 76 DCHECK(delegate_);
32 DCHECK(base::StartsWith(object_path_.value(), service_path_.value() + "/", 77 DCHECK(base::StartsWith(object_path_.value(), service_path_.value() + "/",
33 base::CompareCase::SENSITIVE)); 78 base::CompareCase::SENSITIVE));
34 79
35 // TODO(rkc): Do something with |flags|.
36 FakeBluetoothGattManagerClient* fake_bluetooth_gatt_manager_client = 80 FakeBluetoothGattManagerClient* fake_bluetooth_gatt_manager_client =
37 static_cast<FakeBluetoothGattManagerClient*>( 81 static_cast<FakeBluetoothGattManagerClient*>(
38 bluez::BluezDBusManager::Get()->GetBluetoothGattManagerClient()); 82 bluez::BluezDBusManager::Get()->GetBluetoothGattManagerClient());
39 fake_bluetooth_gatt_manager_client->RegisterCharacteristicServiceProvider( 83 fake_bluetooth_gatt_manager_client->RegisterCharacteristicServiceProvider(
40 this); 84 this);
41 } 85 }
42 86
43 FakeBluetoothGattCharacteristicServiceProvider:: 87 FakeBluetoothGattCharacteristicServiceProvider::
44 ~FakeBluetoothGattCharacteristicServiceProvider() { 88 ~FakeBluetoothGattCharacteristicServiceProvider() {
45 VLOG(1) << "Cleaning up Bluetooth GATT characteristic: " 89 VLOG(1) << "Cleaning up Bluetooth GATT characteristic: "
(...skipping 20 matching lines...) Expand all
66 // Check if this characteristic is registered. 110 // Check if this characteristic is registered.
67 FakeBluetoothGattManagerClient* fake_bluetooth_gatt_manager_client = 111 FakeBluetoothGattManagerClient* fake_bluetooth_gatt_manager_client =
68 static_cast<FakeBluetoothGattManagerClient*>( 112 static_cast<FakeBluetoothGattManagerClient*>(
69 bluez::BluezDBusManager::Get()->GetBluetoothGattManagerClient()); 113 bluez::BluezDBusManager::Get()->GetBluetoothGattManagerClient());
70 if (!fake_bluetooth_gatt_manager_client->IsServiceRegistered(service_path_)) { 114 if (!fake_bluetooth_gatt_manager_client->IsServiceRegistered(service_path_)) {
71 VLOG(1) << "GATT characteristic not registered."; 115 VLOG(1) << "GATT characteristic not registered.";
72 error_callback.Run(); 116 error_callback.Run();
73 return; 117 return;
74 } 118 }
75 119
120 if (!CanRead(flags_)) {
121 VLOG(1) << "GATT characteristic not readable.";
122 error_callback.Run();
123 return;
124 }
125
76 // Pass on to the delegate. 126 // Pass on to the delegate.
77 DCHECK(delegate_); 127 DCHECK(delegate_);
78 delegate_->GetValue(callback, error_callback); 128 delegate_->GetValue(callback, error_callback);
79 } 129 }
80 130
81 void FakeBluetoothGattCharacteristicServiceProvider::SetValue( 131 void FakeBluetoothGattCharacteristicServiceProvider::SetValue(
82 const std::vector<uint8_t>& value, 132 const std::vector<uint8_t>& value,
83 const base::Closure& callback, 133 const base::Closure& callback,
84 const device::BluetoothLocalGattService::Delegate::ErrorCallback& 134 const device::BluetoothLocalGattService::Delegate::ErrorCallback&
85 error_callback) { 135 error_callback) {
86 VLOG(1) << "GATT characteristic value Set request: " << object_path_.value() 136 VLOG(1) << "GATT characteristic value Set request: " << object_path_.value()
87 << " UUID: " << uuid_; 137 << " UUID: " << uuid_;
88 // Check if this characteristic is registered. 138 // Check if this characteristic is registered.
89 FakeBluetoothGattManagerClient* fake_bluetooth_gatt_manager_client = 139 FakeBluetoothGattManagerClient* fake_bluetooth_gatt_manager_client =
90 static_cast<FakeBluetoothGattManagerClient*>( 140 static_cast<FakeBluetoothGattManagerClient*>(
91 bluez::BluezDBusManager::Get()->GetBluetoothGattManagerClient()); 141 bluez::BluezDBusManager::Get()->GetBluetoothGattManagerClient());
92 if (!fake_bluetooth_gatt_manager_client->IsServiceRegistered(service_path_)) { 142 if (!fake_bluetooth_gatt_manager_client->IsServiceRegistered(service_path_)) {
93 VLOG(1) << "GATT characteristic not registered."; 143 VLOG(1) << "GATT characteristic not registered.";
94 error_callback.Run(); 144 error_callback.Run();
95 return; 145 return;
96 } 146 }
97 147
148 if (!CanWrite(flags_)) {
149 VLOG(1) << "GATT characteristic not writeable.";
150 error_callback.Run();
151 return;
152 }
153
98 // Pass on to the delegate. 154 // Pass on to the delegate.
99 DCHECK(delegate_); 155 DCHECK(delegate_);
100 delegate_->SetValue(value, callback, error_callback); 156 delegate_->SetValue(value, callback, error_callback);
101 } 157 }
102 158
103 const dbus::ObjectPath& 159 const dbus::ObjectPath&
104 FakeBluetoothGattCharacteristicServiceProvider::object_path() const { 160 FakeBluetoothGattCharacteristicServiceProvider::object_path() const {
105 return object_path_; 161 return object_path_;
106 } 162 }
107 163
108 } // namespace bluez 164 } // namespace bluez
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698