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

Side by Side Diff: chromeos/dbus/bluetooth_gatt_characteristic_client.cc

Issue 402303002: bluetoothLowEnergy: Send onServiceAdded after all characteristics are discovered (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Created 6 years, 5 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 | Annotate | Revision Log
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 "chromeos/dbus/bluetooth_gatt_characteristic_client.h" 5 #include "chromeos/dbus/bluetooth_gatt_characteristic_client.h"
6 6
7 #include "base/bind.h" 7 #include "base/bind.h"
8 #include "base/memory/weak_ptr.h" 8 #include "base/memory/weak_ptr.h"
9 #include "base/observer_list.h" 9 #include "base/observer_list.h"
10 #include "dbus/bus.h" 10 #include "dbus/bus.h"
11 #include "dbus/object_manager.h" 11 #include "dbus/object_manager.h"
12 #include "third_party/cros_system_api/dbus/service_constants.h" 12 #include "third_party/cros_system_api/dbus/service_constants.h"
13 13
14 namespace chromeos { 14 namespace chromeos {
15 15
16 namespace {
17
18 // TODO(armansito): Move these to service_constants.h later.
19 const char kNotifyingProperty[] = "Notifying";
20 const char kStartNotify[] = "StartNotify";
21 const char kStopNotify[] = "StopNotify";
22
23 } // namespace
24
25 // static 16 // static
26 const char BluetoothGattCharacteristicClient::kNoResponseError[] = 17 const char BluetoothGattCharacteristicClient::kNoResponseError[] =
27 "org.chromium.Error.NoResponse"; 18 "org.chromium.Error.NoResponse";
28 // static 19 // static
29 const char BluetoothGattCharacteristicClient::kUnknownCharacteristicError[] = 20 const char BluetoothGattCharacteristicClient::kUnknownCharacteristicError[] =
30 "org.chromium.Error.UnknownCharacteristic"; 21 "org.chromium.Error.UnknownCharacteristic";
31 22
32 BluetoothGattCharacteristicClient::Properties::Properties( 23 BluetoothGattCharacteristicClient::Properties::Properties(
33 dbus::ObjectProxy* object_proxy, 24 dbus::ObjectProxy* object_proxy,
34 const std::string& interface_name, 25 const std::string& interface_name,
35 const PropertyChangedCallback& callback) 26 const PropertyChangedCallback& callback)
36 : dbus::PropertySet(object_proxy, interface_name, callback) { 27 : dbus::PropertySet(object_proxy, interface_name, callback) {
37 RegisterProperty(bluetooth_gatt_characteristic::kUUIDProperty, &uuid); 28 RegisterProperty(bluetooth_gatt_characteristic::kUUIDProperty, &uuid);
38 RegisterProperty(bluetooth_gatt_characteristic::kServiceProperty, &service); 29 RegisterProperty(bluetooth_gatt_characteristic::kServiceProperty, &service);
39 RegisterProperty(kNotifyingProperty, &notifying); 30 RegisterProperty(bluetooth_gatt_characteristic::kNotifyingProperty,
31 &notifying);
40 RegisterProperty(bluetooth_gatt_characteristic::kFlagsProperty, &flags); 32 RegisterProperty(bluetooth_gatt_characteristic::kFlagsProperty, &flags);
33 RegisterProperty(bluetooth_gatt_characteristic::kDescriptorsProperty,
34 &descriptors);
41 } 35 }
42 36
43 BluetoothGattCharacteristicClient::Properties::~Properties() { 37 BluetoothGattCharacteristicClient::Properties::~Properties() {
44 } 38 }
45 39
46 // The BluetoothGattCharacteristicClient implementation used in production. 40 // The BluetoothGattCharacteristicClient implementation used in production.
47 class BluetoothGattCharacteristicClientImpl 41 class BluetoothGattCharacteristicClientImpl
48 : public BluetoothGattCharacteristicClient, 42 : public BluetoothGattCharacteristicClient,
49 public dbus::ObjectManager::Interface { 43 public dbus::ObjectManager::Interface {
50 public: 44 public:
(...skipping 100 matching lines...) Expand 10 before | Expand all | Expand 10 after
151 const ErrorCallback& error_callback) OVERRIDE { 145 const ErrorCallback& error_callback) OVERRIDE {
152 dbus::ObjectProxy* object_proxy = 146 dbus::ObjectProxy* object_proxy =
153 object_manager_->GetObjectProxy(object_path); 147 object_manager_->GetObjectProxy(object_path);
154 if (!object_proxy) { 148 if (!object_proxy) {
155 error_callback.Run(kUnknownCharacteristicError, ""); 149 error_callback.Run(kUnknownCharacteristicError, "");
156 return; 150 return;
157 } 151 }
158 152
159 dbus::MethodCall method_call( 153 dbus::MethodCall method_call(
160 bluetooth_gatt_characteristic::kBluetoothGattCharacteristicInterface, 154 bluetooth_gatt_characteristic::kBluetoothGattCharacteristicInterface,
161 kStartNotify); 155 bluetooth_gatt_characteristic::kStartNotify);
162 156
163 object_proxy->CallMethodWithErrorCallback( 157 object_proxy->CallMethodWithErrorCallback(
164 &method_call, 158 &method_call,
165 dbus::ObjectProxy::TIMEOUT_USE_DEFAULT, 159 dbus::ObjectProxy::TIMEOUT_USE_DEFAULT,
166 base::Bind(&BluetoothGattCharacteristicClientImpl::OnSuccess, 160 base::Bind(&BluetoothGattCharacteristicClientImpl::OnSuccess,
167 weak_ptr_factory_.GetWeakPtr(), 161 weak_ptr_factory_.GetWeakPtr(),
168 callback), 162 callback),
169 base::Bind(&BluetoothGattCharacteristicClientImpl::OnError, 163 base::Bind(&BluetoothGattCharacteristicClientImpl::OnError,
170 weak_ptr_factory_.GetWeakPtr(), 164 weak_ptr_factory_.GetWeakPtr(),
171 error_callback)); 165 error_callback));
172 } 166 }
173 167
174 // BluetoothGattCharacteristicClient override. 168 // BluetoothGattCharacteristicClient override.
175 virtual void StopNotify(const dbus::ObjectPath& object_path, 169 virtual void StopNotify(const dbus::ObjectPath& object_path,
176 const base::Closure& callback, 170 const base::Closure& callback,
177 const ErrorCallback& error_callback) OVERRIDE { 171 const ErrorCallback& error_callback) OVERRIDE {
178 dbus::ObjectProxy* object_proxy = 172 dbus::ObjectProxy* object_proxy =
179 object_manager_->GetObjectProxy(object_path); 173 object_manager_->GetObjectProxy(object_path);
180 if (!object_proxy) { 174 if (!object_proxy) {
181 error_callback.Run(kUnknownCharacteristicError, ""); 175 error_callback.Run(kUnknownCharacteristicError, "");
182 return; 176 return;
183 } 177 }
184 178
185 dbus::MethodCall method_call( 179 dbus::MethodCall method_call(
186 bluetooth_gatt_characteristic::kBluetoothGattCharacteristicInterface, 180 bluetooth_gatt_characteristic::kBluetoothGattCharacteristicInterface,
187 kStopNotify); 181 bluetooth_gatt_characteristic::kStopNotify);
188 182
189 object_proxy->CallMethodWithErrorCallback( 183 object_proxy->CallMethodWithErrorCallback(
190 &method_call, 184 &method_call,
191 dbus::ObjectProxy::TIMEOUT_USE_DEFAULT, 185 dbus::ObjectProxy::TIMEOUT_USE_DEFAULT,
192 base::Bind(&BluetoothGattCharacteristicClientImpl::OnSuccess, 186 base::Bind(&BluetoothGattCharacteristicClientImpl::OnSuccess,
193 weak_ptr_factory_.GetWeakPtr(), 187 weak_ptr_factory_.GetWeakPtr(),
194 callback), 188 callback),
195 base::Bind(&BluetoothGattCharacteristicClientImpl::OnError, 189 base::Bind(&BluetoothGattCharacteristicClientImpl::OnError,
196 weak_ptr_factory_.GetWeakPtr(), 190 weak_ptr_factory_.GetWeakPtr(),
197 error_callback)); 191 error_callback));
(...skipping 161 matching lines...) Expand 10 before | Expand all | Expand 10 after
359 353
360 BluetoothGattCharacteristicClient::~BluetoothGattCharacteristicClient() { 354 BluetoothGattCharacteristicClient::~BluetoothGattCharacteristicClient() {
361 } 355 }
362 356
363 // static 357 // static
364 BluetoothGattCharacteristicClient* BluetoothGattCharacteristicClient::Create() { 358 BluetoothGattCharacteristicClient* BluetoothGattCharacteristicClient::Create() {
365 return new BluetoothGattCharacteristicClientImpl(); 359 return new BluetoothGattCharacteristicClientImpl();
366 } 360 }
367 361
368 } // namespace chromeos 362 } // namespace chromeos
OLDNEW
« no previous file with comments | « chromeos/dbus/bluetooth_gatt_characteristic_client.h ('k') | chromeos/dbus/bluetooth_gatt_service_client.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698