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

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

Issue 1974633002: Implement DBus changes needed for notifications. (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
« no previous file with comments | « device/bluetooth/dbus/fake_bluetooth_gatt_characteristic_service_provider.h ('k') | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
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> 7 #include <algorithm>
8 #include <iterator> 8 #include <iterator>
9 9
10 #include "base/callback.h" 10 #include "base/callback.h"
(...skipping 36 matching lines...) Expand 10 before | Expand all | Expand 10 after
47 if (find(flags.begin(), flags.end(), 47 if (find(flags.begin(), flags.end(),
48 bluetooth_gatt_characteristic::kFlagEncryptRead) != flags.end()) 48 bluetooth_gatt_characteristic::kFlagEncryptRead) != flags.end())
49 return true; 49 return true;
50 if (find(flags.begin(), flags.end(), 50 if (find(flags.begin(), flags.end(),
51 bluetooth_gatt_characteristic::kFlagEncryptAuthenticatedRead) != 51 bluetooth_gatt_characteristic::kFlagEncryptAuthenticatedRead) !=
52 flags.end()) 52 flags.end())
53 return true; 53 return true;
54 return false; 54 return false;
55 } 55 }
56 56
57 bool CanNotify(const std::vector<std::string>& flags) {
58 if (find(flags.begin(), flags.end(),
59 bluetooth_gatt_characteristic::kFlagNotify) != flags.end())
60 return true;
61 if (find(flags.begin(), flags.end(),
62 bluetooth_gatt_characteristic::kFlagIndicate) != flags.end())
63 return true;
64 return false;
65 }
66
57 } // namespace 67 } // namespace
58 68
59 FakeBluetoothGattCharacteristicServiceProvider:: 69 FakeBluetoothGattCharacteristicServiceProvider::
60 FakeBluetoothGattCharacteristicServiceProvider( 70 FakeBluetoothGattCharacteristicServiceProvider(
61 const dbus::ObjectPath& object_path, 71 const dbus::ObjectPath& object_path,
62 std::unique_ptr<BluetoothGattAttributeValueDelegate> delegate, 72 std::unique_ptr<BluetoothGattAttributeValueDelegate> delegate,
63 const std::string& uuid, 73 const std::string& uuid,
64 const std::vector<std::string>& flags, 74 const std::vector<std::string>& flags,
65 const dbus::ObjectPath& service_path) 75 const dbus::ObjectPath& service_path)
66 : object_path_(object_path), 76 : object_path_(object_path),
(...skipping 25 matching lines...) Expand all
92 static_cast<FakeBluetoothGattManagerClient*>( 102 static_cast<FakeBluetoothGattManagerClient*>(
93 bluez::BluezDBusManager::Get()->GetBluetoothGattManagerClient()); 103 bluez::BluezDBusManager::Get()->GetBluetoothGattManagerClient());
94 fake_bluetooth_gatt_manager_client->UnregisterCharacteristicServiceProvider( 104 fake_bluetooth_gatt_manager_client->UnregisterCharacteristicServiceProvider(
95 this); 105 this);
96 } 106 }
97 107
98 void FakeBluetoothGattCharacteristicServiceProvider::SendValueChanged( 108 void FakeBluetoothGattCharacteristicServiceProvider::SendValueChanged(
99 const std::vector<uint8_t>& value) { 109 const std::vector<uint8_t>& value) {
100 VLOG(1) << "Sent characteristic value changed: " << object_path_.value() 110 VLOG(1) << "Sent characteristic value changed: " << object_path_.value()
101 << " UUID: " << uuid_; 111 << " UUID: " << uuid_;
112 sent_value_ = value;
102 } 113 }
103 114
104 void FakeBluetoothGattCharacteristicServiceProvider::GetValue( 115 void FakeBluetoothGattCharacteristicServiceProvider::GetValue(
105 const device::BluetoothLocalGattService::Delegate::ValueCallback& callback, 116 const device::BluetoothLocalGattService::Delegate::ValueCallback& callback,
106 const device::BluetoothLocalGattService::Delegate::ErrorCallback& 117 const device::BluetoothLocalGattService::Delegate::ErrorCallback&
107 error_callback) { 118 error_callback) {
108 VLOG(1) << "GATT characteristic value Get request: " << object_path_.value() 119 VLOG(1) << "GATT characteristic value Get request: " << object_path_.value()
109 << " UUID: " << uuid_; 120 << " UUID: " << uuid_;
110 // Check if this characteristic is registered. 121 // Check if this characteristic is registered.
111 FakeBluetoothGattManagerClient* fake_bluetooth_gatt_manager_client = 122 FakeBluetoothGattManagerClient* fake_bluetooth_gatt_manager_client =
(...skipping 37 matching lines...) Expand 10 before | Expand all | Expand 10 after
149 VLOG(1) << "GATT characteristic not writeable."; 160 VLOG(1) << "GATT characteristic not writeable.";
150 error_callback.Run(); 161 error_callback.Run();
151 return; 162 return;
152 } 163 }
153 164
154 // Pass on to the delegate. 165 // Pass on to the delegate.
155 DCHECK(delegate_); 166 DCHECK(delegate_);
156 delegate_->SetValue(value, callback, error_callback); 167 delegate_->SetValue(value, callback, error_callback);
157 } 168 }
158 169
170 bool FakeBluetoothGattCharacteristicServiceProvider::NotificationsChange(
171 bool start) {
172 VLOG(1) << "GATT characteristic value notification request: "
173 << object_path_.value() << " UUID: " << uuid_ << " start=" << start;
174 // Check if this characteristic is registered.
175 FakeBluetoothGattManagerClient* fake_bluetooth_gatt_manager_client =
176 static_cast<FakeBluetoothGattManagerClient*>(
177 bluez::BluezDBusManager::Get()->GetBluetoothGattManagerClient());
178 if (!fake_bluetooth_gatt_manager_client->IsServiceRegistered(service_path_)) {
179 VLOG(1) << "GATT characteristic not registered.";
180 return false;
181 }
182
183 if (!CanNotify(flags_)) {
184 VLOG(1) << "GATT characteristic not notifiable.";
185 return false;
186 }
187
188 // Pass on to the delegate.
189 DCHECK(delegate_);
190 start ? delegate_->StartNotifications() : delegate_->StopNotifications();
191
192 return true;
193 }
194
159 const dbus::ObjectPath& 195 const dbus::ObjectPath&
160 FakeBluetoothGattCharacteristicServiceProvider::object_path() const { 196 FakeBluetoothGattCharacteristicServiceProvider::object_path() const {
161 return object_path_; 197 return object_path_;
162 } 198 }
163 199
164 } // namespace bluez 200 } // namespace bluez
OLDNEW
« no previous file with comments | « device/bluetooth/dbus/fake_bluetooth_gatt_characteristic_service_provider.h ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698