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

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

Issue 1347193004: Refactor DBusThreadManager to split away BT clients. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Created 5 years, 2 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 "chromeos/dbus/fake_bluetooth_gatt_characteristic_service_provider.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 "chromeos/dbus/dbus_thread_manager.h" 9 #include "device/bluetooth/dbus/bluez_dbus_manager.h"
10 #include "chromeos/dbus/fake_bluetooth_gatt_manager_client.h" 10 #include "device/bluetooth/dbus/fake_bluetooth_gatt_manager_client.h"
11 11
12 namespace chromeos { 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 Delegate* delegate,
18 const std::string& uuid, 18 const std::string& uuid,
19 const std::vector<std::string>& flags, 19 const std::vector<std::string>& flags,
20 const std::vector<std::string>& permissions, 20 const std::vector<std::string>& permissions,
21 const dbus::ObjectPath& service_path) 21 const dbus::ObjectPath& service_path)
22 : object_path_(object_path), 22 : object_path_(object_path),
23 uuid_(uuid), 23 uuid_(uuid),
24 service_path_(service_path), 24 service_path_(service_path),
25 delegate_(delegate) { 25 delegate_(delegate) {
26 VLOG(1) << "Creating Bluetooth GATT characteristic: " << object_path_.value(); 26 VLOG(1) << "Creating Bluetooth GATT characteristic: " << object_path_.value();
27 27
28 DCHECK(object_path_.IsValid()); 28 DCHECK(object_path_.IsValid());
29 DCHECK(service_path_.IsValid()); 29 DCHECK(service_path_.IsValid());
30 DCHECK(!uuid.empty()); 30 DCHECK(!uuid.empty());
31 DCHECK(delegate_); 31 DCHECK(delegate_);
32 DCHECK(base::StartsWith(object_path_.value(), 32 DCHECK(base::StartsWith(object_path_.value(), service_path_.value() + "/",
33 service_path_.value() + "/",
34 base::CompareCase::SENSITIVE)); 33 base::CompareCase::SENSITIVE));
35 34
36 // TODO(armansito): Do something with |flags| and |permissions|. 35 // TODO(armansito): Do something with |flags| and |permissions|.
37 36
38 FakeBluetoothGattManagerClient* fake_bluetooth_gatt_manager_client = 37 FakeBluetoothGattManagerClient* fake_bluetooth_gatt_manager_client =
39 static_cast<FakeBluetoothGattManagerClient*>( 38 static_cast<FakeBluetoothGattManagerClient*>(
40 DBusThreadManager::Get()->GetBluetoothGattManagerClient()); 39 bluez::BluezDBusManager::Get()->GetBluetoothGattManagerClient());
41 fake_bluetooth_gatt_manager_client-> 40 fake_bluetooth_gatt_manager_client->RegisterCharacteristicServiceProvider(
42 RegisterCharacteristicServiceProvider(this); 41 this);
43 } 42 }
44 43
45 FakeBluetoothGattCharacteristicServiceProvider:: 44 FakeBluetoothGattCharacteristicServiceProvider::
46 ~FakeBluetoothGattCharacteristicServiceProvider() { 45 ~FakeBluetoothGattCharacteristicServiceProvider() {
47 VLOG(1) << "Cleaning up Bluetooth GATT characteristic: " 46 VLOG(1) << "Cleaning up Bluetooth GATT characteristic: "
48 << object_path_.value(); 47 << object_path_.value();
49 48
50 FakeBluetoothGattManagerClient* fake_bluetooth_gatt_manager_client = 49 FakeBluetoothGattManagerClient* fake_bluetooth_gatt_manager_client =
51 static_cast<FakeBluetoothGattManagerClient*>( 50 static_cast<FakeBluetoothGattManagerClient*>(
52 DBusThreadManager::Get()->GetBluetoothGattManagerClient()); 51 bluez::BluezDBusManager::Get()->GetBluetoothGattManagerClient());
53 fake_bluetooth_gatt_manager_client-> 52 fake_bluetooth_gatt_manager_client->UnregisterCharacteristicServiceProvider(
54 UnregisterCharacteristicServiceProvider(this); 53 this);
55 } 54 }
56 55
57 void FakeBluetoothGattCharacteristicServiceProvider::SendValueChanged( 56 void FakeBluetoothGattCharacteristicServiceProvider::SendValueChanged(
58 const std::vector<uint8>& value) { 57 const std::vector<uint8>& value) {
59 VLOG(1) << "Sent characteristic value changed: " << object_path_.value() 58 VLOG(1) << "Sent characteristic value changed: " << object_path_.value()
60 << " UUID: " << uuid_; 59 << " UUID: " << uuid_;
61 } 60 }
62 61
63 void FakeBluetoothGattCharacteristicServiceProvider::GetValue( 62 void FakeBluetoothGattCharacteristicServiceProvider::GetValue(
64 const Delegate::ValueCallback& callback, 63 const Delegate::ValueCallback& callback,
65 const Delegate::ErrorCallback& error_callback) { 64 const Delegate::ErrorCallback& error_callback) {
66 VLOG(1) << "GATT characteristic value Get request: " << object_path_.value() 65 VLOG(1) << "GATT characteristic value Get request: " << object_path_.value()
67 << " UUID: " << uuid_; 66 << " UUID: " << uuid_;
68 67
69 // Check if this characteristic is registered. 68 // Check if this characteristic is registered.
70 FakeBluetoothGattManagerClient* fake_bluetooth_gatt_manager_client = 69 FakeBluetoothGattManagerClient* fake_bluetooth_gatt_manager_client =
71 static_cast<FakeBluetoothGattManagerClient*>( 70 static_cast<FakeBluetoothGattManagerClient*>(
72 DBusThreadManager::Get()->GetBluetoothGattManagerClient()); 71 bluez::BluezDBusManager::Get()->GetBluetoothGattManagerClient());
73 if (!fake_bluetooth_gatt_manager_client->IsServiceRegistered(service_path_)) { 72 if (!fake_bluetooth_gatt_manager_client->IsServiceRegistered(service_path_)) {
74 VLOG(1) << "GATT characteristic not registered."; 73 VLOG(1) << "GATT characteristic not registered.";
75 error_callback.Run(); 74 error_callback.Run();
76 return; 75 return;
77 } 76 }
78 77
79 // Pass on to the delegate. 78 // Pass on to the delegate.
80 DCHECK(delegate_); 79 DCHECK(delegate_);
81 delegate_->GetCharacteristicValue(callback, error_callback); 80 delegate_->GetCharacteristicValue(callback, error_callback);
82 } 81 }
83 82
84 void FakeBluetoothGattCharacteristicServiceProvider::SetValue( 83 void FakeBluetoothGattCharacteristicServiceProvider::SetValue(
85 const std::vector<uint8>& value, 84 const std::vector<uint8>& value,
86 const base::Closure& callback, 85 const base::Closure& callback,
87 const Delegate::ErrorCallback& error_callback) { 86 const Delegate::ErrorCallback& error_callback) {
88 VLOG(1) << "GATT characteristic value Set request: " << object_path_.value() 87 VLOG(1) << "GATT characteristic value Set request: " << object_path_.value()
89 << " UUID: " << uuid_; 88 << " UUID: " << uuid_;
90 89
91 // Check if this characteristic is registered. 90 // Check if this characteristic is registered.
92 FakeBluetoothGattManagerClient* fake_bluetooth_gatt_manager_client = 91 FakeBluetoothGattManagerClient* fake_bluetooth_gatt_manager_client =
93 static_cast<FakeBluetoothGattManagerClient*>( 92 static_cast<FakeBluetoothGattManagerClient*>(
94 DBusThreadManager::Get()->GetBluetoothGattManagerClient()); 93 bluez::BluezDBusManager::Get()->GetBluetoothGattManagerClient());
95 if (!fake_bluetooth_gatt_manager_client->IsServiceRegistered(service_path_)) { 94 if (!fake_bluetooth_gatt_manager_client->IsServiceRegistered(service_path_)) {
96 VLOG(1) << "GATT characteristic not registered."; 95 VLOG(1) << "GATT characteristic not registered.";
97 error_callback.Run(); 96 error_callback.Run();
98 return; 97 return;
99 } 98 }
100 99
101 // Pass on to the delegate. 100 // Pass on to the delegate.
102 DCHECK(delegate_); 101 DCHECK(delegate_);
103 delegate_->SetCharacteristicValue(value, callback, error_callback); 102 delegate_->SetCharacteristicValue(value, callback, error_callback);
104 } 103 }
105 104
106 } // namespace chromeos 105 } // namespace bluez
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698