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

Side by Side Diff: device/bluetooth/bluetooth_remote_gatt_descriptor_chromeos.cc

Issue 788193004: chromeos/dbus: Update Bluetooth GATT API clients to upstream definition (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: rebase & tbr Created 5 years, 10 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/bluetooth_remote_gatt_descriptor_chromeos.h" 5 #include "device/bluetooth/bluetooth_remote_gatt_descriptor_chromeos.h"
6 6
7 #include "base/bind.h" 7 #include "base/bind.h"
8 #include "base/logging.h" 8 #include "base/logging.h"
9 #include "base/strings/stringprintf.h" 9 #include "base/strings/stringprintf.h"
10 #include "chromeos/dbus/bluetooth_gatt_descriptor_client.h" 10 #include "chromeos/dbus/bluetooth_gatt_descriptor_client.h"
(...skipping 42 matching lines...) Expand 10 before | Expand all | Expand 10 after
53 DCHECK(properties); 53 DCHECK(properties);
54 return device::BluetoothUUID(properties->uuid.value()); 54 return device::BluetoothUUID(properties->uuid.value());
55 } 55 }
56 56
57 bool BluetoothRemoteGattDescriptorChromeOS::IsLocal() const { 57 bool BluetoothRemoteGattDescriptorChromeOS::IsLocal() const {
58 return false; 58 return false;
59 } 59 }
60 60
61 const std::vector<uint8>& 61 const std::vector<uint8>&
62 BluetoothRemoteGattDescriptorChromeOS::GetValue() const { 62 BluetoothRemoteGattDescriptorChromeOS::GetValue() const {
63 return cached_value_; 63 BluetoothGattDescriptorClient::Properties* properties =
64 DBusThreadManager::Get()
65 ->GetBluetoothGattDescriptorClient()
66 ->GetProperties(object_path_);
67
68 DCHECK(properties);
69
70 return properties->value.value();
64 } 71 }
65 72
66 device::BluetoothGattCharacteristic* 73 device::BluetoothGattCharacteristic*
67 BluetoothRemoteGattDescriptorChromeOS::GetCharacteristic() const { 74 BluetoothRemoteGattDescriptorChromeOS::GetCharacteristic() const {
68 return characteristic_; 75 return characteristic_;
69 } 76 }
70 77
71 device::BluetoothGattCharacteristic::Permissions 78 device::BluetoothGattCharacteristic::Permissions
72 BluetoothRemoteGattDescriptorChromeOS::GetPermissions() const { 79 BluetoothRemoteGattDescriptorChromeOS::GetPermissions() const {
73 // TODO(armansito): Once BlueZ defines the permissions, return the correct 80 // TODO(armansito): Once BlueZ defines the permissions, return the correct
74 // values here. 81 // values here.
75 return device::BluetoothGattCharacteristic::PERMISSION_NONE; 82 return device::BluetoothGattCharacteristic::PERMISSION_NONE;
76 } 83 }
77 84
78 void BluetoothRemoteGattDescriptorChromeOS::ReadRemoteDescriptor( 85 void BluetoothRemoteGattDescriptorChromeOS::ReadRemoteDescriptor(
79 const ValueCallback& callback, 86 const ValueCallback& callback,
80 const ErrorCallback& error_callback) { 87 const ErrorCallback& error_callback) {
81 VLOG(1) << "Sending GATT characteristic descriptor read request to " 88 VLOG(1) << "Sending GATT characteristic descriptor read request to "
82 << "descriptor: " << GetIdentifier() << ", UUID: " 89 << "descriptor: " << GetIdentifier() << ", UUID: "
83 << GetUUID().canonical_value(); 90 << GetUUID().canonical_value();
84 91
85 DBusThreadManager::Get()->GetBluetoothGattDescriptorClient()->ReadValue( 92 DBusThreadManager::Get()->GetBluetoothGattDescriptorClient()->ReadValue(
86 object_path_, 93 object_path_, callback,
87 base::Bind(&BluetoothRemoteGattDescriptorChromeOS::OnValueSuccess,
88 weak_ptr_factory_.GetWeakPtr(),
89 callback),
90 base::Bind(&BluetoothRemoteGattDescriptorChromeOS::OnError, 94 base::Bind(&BluetoothRemoteGattDescriptorChromeOS::OnError,
91 weak_ptr_factory_.GetWeakPtr(), 95 weak_ptr_factory_.GetWeakPtr(), error_callback));
92 error_callback));
93 } 96 }
94 97
95 void BluetoothRemoteGattDescriptorChromeOS::WriteRemoteDescriptor( 98 void BluetoothRemoteGattDescriptorChromeOS::WriteRemoteDescriptor(
96 const std::vector<uint8>& new_value, 99 const std::vector<uint8>& new_value,
97 const base::Closure& callback, 100 const base::Closure& callback,
98 const ErrorCallback& error_callback) { 101 const ErrorCallback& error_callback) {
99 VLOG(1) << "Sending GATT characteristic descriptor write request to " 102 VLOG(1) << "Sending GATT characteristic descriptor write request to "
100 << "characteristic: " << GetIdentifier() << ", UUID: " 103 << "characteristic: " << GetIdentifier() << ", UUID: "
101 << GetUUID().canonical_value() << ", with value: " 104 << GetUUID().canonical_value() << ", with value: "
102 << new_value << "."; 105 << new_value << ".";
103 106
104 DBusThreadManager::Get()->GetBluetoothGattDescriptorClient()->WriteValue( 107 DBusThreadManager::Get()->GetBluetoothGattDescriptorClient()->WriteValue(
105 object_path_, 108 object_path_,
106 new_value, 109 new_value,
107 callback, 110 callback,
108 base::Bind(&BluetoothRemoteGattDescriptorChromeOS::OnError, 111 base::Bind(&BluetoothRemoteGattDescriptorChromeOS::OnError,
109 weak_ptr_factory_.GetWeakPtr(), 112 weak_ptr_factory_.GetWeakPtr(),
110 error_callback)); 113 error_callback));
111 } 114 }
112 115
113 void BluetoothRemoteGattDescriptorChromeOS::OnValueSuccess(
114 const ValueCallback& callback,
115 const std::vector<uint8>& value) {
116 VLOG(1) << "Descriptor value read: " << value;
117 cached_value_ = value;
118
119 DCHECK(characteristic_);
120 BluetoothRemoteGattServiceChromeOS* service =
121 static_cast<BluetoothRemoteGattServiceChromeOS*>(
122 characteristic_->GetService());
123 DCHECK(service);
124 service->NotifyDescriptorValueChanged(characteristic_, this, value);
125 callback.Run(value);
126 }
127
128 void BluetoothRemoteGattDescriptorChromeOS::OnError( 116 void BluetoothRemoteGattDescriptorChromeOS::OnError(
129 const ErrorCallback& error_callback, 117 const ErrorCallback& error_callback,
130 const std::string& error_name, 118 const std::string& error_name,
131 const std::string& error_message) { 119 const std::string& error_message) {
132 VLOG(1) << "Operation failed: " << error_name 120 VLOG(1) << "Operation failed: " << error_name
133 << ", message: " << error_message; 121 << ", message: " << error_message;
134 122
135 error_callback.Run( 123 error_callback.Run(
136 BluetoothRemoteGattServiceChromeOS::DBusErrorToServiceError(error_name)); 124 BluetoothRemoteGattServiceChromeOS::DBusErrorToServiceError(error_name));
137 } 125 }
138 126
139 } // namespace chromeos 127 } // namespace chromeos
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698