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

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

Issue 11075006: Moved bluetooth adapter files to device/bluetooth/. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: renamed 'bluetooth' target to 'device_bluetooth'. Created 8 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 | Annotate | Revision Log
OLDNEW
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2012 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_out_of_band_client.h" 5 #include "chromeos/dbus/bluetooth_out_of_band_client.h"
6 6
7 #include <map> 7 #include <map>
8 #include <string> 8 #include <string>
9 9
10 #include "base/bind.h" 10 #include "base/bind.h"
11 #include "base/logging.h" 11 #include "base/logging.h"
12 #include "chromeos/dbus/bluetooth_adapter_client.h" 12 #include "chromeos/dbus/bluetooth_adapter_client.h"
13 #include "chromeos/dbus/bluetooth_out_of_band_pairing_data.h"
14 #include "dbus/bus.h" 13 #include "dbus/bus.h"
15 #include "dbus/message.h" 14 #include "dbus/message.h"
16 #include "dbus/object_path.h" 15 #include "dbus/object_path.h"
17 #include "dbus/object_proxy.h" 16 #include "dbus/object_proxy.h"
17 #include "device/bluetooth/bluetooth_out_of_band_pairing_data.h"
18 #include "third_party/cros_system_api/dbus/service_constants.h" 18 #include "third_party/cros_system_api/dbus/service_constants.h"
19 19
20 namespace chromeos { 20 namespace chromeos {
21 21
22 // The BluetoothOutOfBandClient implementation used in production. 22 // The BluetoothOutOfBandClient implementation used in production.
23 class BluetoothOutOfBandClientImpl: public BluetoothOutOfBandClient { 23 class BluetoothOutOfBandClientImpl: public BluetoothOutOfBandClient {
24 public: 24 public:
25 explicit BluetoothOutOfBandClientImpl(dbus::Bus* bus) 25 explicit BluetoothOutOfBandClientImpl(dbus::Bus* bus)
26 : bus_(bus), 26 : bus_(bus),
27 weak_ptr_factory_(this) {} 27 weak_ptr_factory_(this) {}
(...skipping 14 matching lines...) Expand all
42 &method_call, 42 &method_call,
43 dbus::ObjectProxy::TIMEOUT_USE_DEFAULT, 43 dbus::ObjectProxy::TIMEOUT_USE_DEFAULT,
44 base::Bind(&BluetoothOutOfBandClientImpl::OnReadLocalData, 44 base::Bind(&BluetoothOutOfBandClientImpl::OnReadLocalData,
45 weak_ptr_factory_.GetWeakPtr(), callback)); 45 weak_ptr_factory_.GetWeakPtr(), callback));
46 } 46 }
47 47
48 // BluetoothOutOfBandClient override. 48 // BluetoothOutOfBandClient override.
49 virtual void AddRemoteData( 49 virtual void AddRemoteData(
50 const dbus::ObjectPath& object_path, 50 const dbus::ObjectPath& object_path,
51 const std::string& address, 51 const std::string& address,
52 const BluetoothOutOfBandPairingData& data, 52 const device::BluetoothOutOfBandPairingData& data,
53 const SuccessCallback& callback) OVERRIDE { 53 const SuccessCallback& callback) OVERRIDE {
54 dbus::MethodCall method_call( 54 dbus::MethodCall method_call(
55 bluetooth_outofband::kBluetoothOutOfBandInterface, 55 bluetooth_outofband::kBluetoothOutOfBandInterface,
56 bluetooth_outofband::kAddRemoteData); 56 bluetooth_outofband::kAddRemoteData);
57 57
58 dbus::MessageWriter writer(&method_call); 58 dbus::MessageWriter writer(&method_call);
59 writer.AppendString(address); 59 writer.AppendString(address);
60 writer.AppendArrayOfBytes(data.hash, kBluetoothOutOfBandPairingDataSize); 60 writer.AppendArrayOfBytes(
61 writer.AppendArrayOfBytes(data.randomizer, 61 data.hash, device::kBluetoothOutOfBandPairingDataSize);
62 kBluetoothOutOfBandPairingDataSize); 62 writer.AppendArrayOfBytes(
63 data.randomizer, device::kBluetoothOutOfBandPairingDataSize);
63 64
64 dbus::ObjectProxy* object_proxy = GetObjectProxy(object_path); 65 dbus::ObjectProxy* object_proxy = GetObjectProxy(object_path);
65 66
66 object_proxy->CallMethod( 67 object_proxy->CallMethod(
67 &method_call, 68 &method_call,
68 dbus::ObjectProxy::TIMEOUT_USE_DEFAULT, 69 dbus::ObjectProxy::TIMEOUT_USE_DEFAULT,
69 base::Bind(&BluetoothOutOfBandClientImpl::ResponseToSuccessCallback, 70 base::Bind(&BluetoothOutOfBandClientImpl::ResponseToSuccessCallback,
70 weak_ptr_factory_.GetWeakPtr(), callback)); 71 weak_ptr_factory_.GetWeakPtr(), callback));
71 } 72 }
72 73
(...skipping 35 matching lines...) Expand 10 before | Expand all | Expand 10 after
108 bluetooth_outofband::kBluetoothOutOfBandServiceName, object_path); 109 bluetooth_outofband::kBluetoothOutOfBandServiceName, object_path);
109 110
110 object_map_[object_path] = object_proxy; 111 object_map_[object_path] = object_proxy;
111 return object_proxy; 112 return object_proxy;
112 } 113 }
113 114
114 // Called when a response from ReadLocalOutOfBandPairingData() is received. 115 // Called when a response from ReadLocalOutOfBandPairingData() is received.
115 void OnReadLocalData(const DataCallback& callback, 116 void OnReadLocalData(const DataCallback& callback,
116 dbus::Response* response) { 117 dbus::Response* response) {
117 bool success = false; 118 bool success = false;
118 BluetoothOutOfBandPairingData data; 119 device::BluetoothOutOfBandPairingData data;
119 if (response != NULL) { 120 if (response != NULL) {
120 dbus::MessageReader reader(response); 121 dbus::MessageReader reader(response);
121 uint8_t* bytes = NULL; 122 uint8_t* bytes = NULL;
122 size_t length = kBluetoothOutOfBandPairingDataSize; 123 size_t length = device::kBluetoothOutOfBandPairingDataSize;
123 if (reader.PopArrayOfBytes(&bytes, &length)) { 124 if (reader.PopArrayOfBytes(&bytes, &length)) {
124 if (length == kBluetoothOutOfBandPairingDataSize) { 125 if (length == device::kBluetoothOutOfBandPairingDataSize) {
125 memcpy(&data.hash, bytes, length); 126 memcpy(&data.hash, bytes, length);
126 if (reader.PopArrayOfBytes(&bytes, &length)) { 127 if (reader.PopArrayOfBytes(&bytes, &length)) {
127 if (length == kBluetoothOutOfBandPairingDataSize) { 128 if (length == device::kBluetoothOutOfBandPairingDataSize) {
128 memcpy(&data.randomizer, bytes, length); 129 memcpy(&data.randomizer, bytes, length);
129 success = true; 130 success = true;
130 } 131 }
131 } 132 }
132 } 133 }
133 } 134 }
134 } 135 }
135 callback.Run(data, success); 136 callback.Run(data, success);
136 } 137 }
137 138
(...skipping 17 matching lines...) Expand all
155 156
156 // The BluetoothOutOfBandClient implementation used on Linux desktop, which does 157 // The BluetoothOutOfBandClient implementation used on Linux desktop, which does
157 // nothing. 158 // nothing.
158 class BluetoothOutOfBandClientStubImpl : public BluetoothOutOfBandClient { 159 class BluetoothOutOfBandClientStubImpl : public BluetoothOutOfBandClient {
159 public: 160 public:
160 // BluetoothOutOfBandClient override. 161 // BluetoothOutOfBandClient override.
161 virtual void ReadLocalData( 162 virtual void ReadLocalData(
162 const dbus::ObjectPath& object_path, 163 const dbus::ObjectPath& object_path,
163 const DataCallback& callback) OVERRIDE { 164 const DataCallback& callback) OVERRIDE {
164 VLOG(1) << "ReadLocalData: " << object_path.value(); 165 VLOG(1) << "ReadLocalData: " << object_path.value();
165 BluetoothOutOfBandPairingData data; 166 device::BluetoothOutOfBandPairingData data;
166 callback.Run(data, false); 167 callback.Run(data, false);
167 } 168 }
168 169
169 // BluetoothOutOfBandClient override. 170 // BluetoothOutOfBandClient override.
170 virtual void AddRemoteData( 171 virtual void AddRemoteData(
171 const dbus::ObjectPath& object_path, 172 const dbus::ObjectPath& object_path,
172 const std::string& address, 173 const std::string& address,
173 const BluetoothOutOfBandPairingData& data, 174 const device::BluetoothOutOfBandPairingData& data,
174 const SuccessCallback& callback) OVERRIDE { 175 const SuccessCallback& callback) OVERRIDE {
175 VLOG(1) << "AddRemoteData: " << object_path.value(); 176 VLOG(1) << "AddRemoteData: " << object_path.value();
176 callback.Run(false); 177 callback.Run(false);
177 } 178 }
178 179
179 // BluetoothOutOfBandClient override. 180 // BluetoothOutOfBandClient override.
180 virtual void RemoveRemoteData( 181 virtual void RemoveRemoteData(
181 const dbus::ObjectPath& object_path, 182 const dbus::ObjectPath& object_path,
182 const std::string& address, 183 const std::string& address,
183 const SuccessCallback& callback) OVERRIDE { 184 const SuccessCallback& callback) OVERRIDE {
184 VLOG(1) << "RemoveRemoteData: " << object_path.value(); 185 VLOG(1) << "RemoveRemoteData: " << object_path.value();
185 callback.Run(false); 186 callback.Run(false);
186 } 187 }
187 }; 188 };
188 189
189 BluetoothOutOfBandClient::BluetoothOutOfBandClient() {} 190 BluetoothOutOfBandClient::BluetoothOutOfBandClient() {}
190 191
191 BluetoothOutOfBandClient::~BluetoothOutOfBandClient() {} 192 BluetoothOutOfBandClient::~BluetoothOutOfBandClient() {}
192 193
193 BluetoothOutOfBandClient* BluetoothOutOfBandClient::Create( 194 BluetoothOutOfBandClient* BluetoothOutOfBandClient::Create(
194 DBusClientImplementationType type, 195 DBusClientImplementationType type,
195 dbus::Bus* bus) { 196 dbus::Bus* bus) {
196 if (type == REAL_DBUS_CLIENT_IMPLEMENTATION) 197 if (type == REAL_DBUS_CLIENT_IMPLEMENTATION)
197 return new BluetoothOutOfBandClientImpl(bus); 198 return new BluetoothOutOfBandClientImpl(bus);
198 DCHECK_EQ(STUB_DBUS_CLIENT_IMPLEMENTATION, type); 199 DCHECK_EQ(STUB_DBUS_CLIENT_IMPLEMENTATION, type);
199 return new BluetoothOutOfBandClientStubImpl(); 200 return new BluetoothOutOfBandClientStubImpl();
200 } 201 }
201 202
202 } // namespace chromeos 203 } // namespace chromeos
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698