OLD | NEW |
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_manager_client.h" | 5 #include "chromeos/dbus/bluetooth_manager_client.h" |
6 | 6 |
| 7 #include <vector> |
| 8 |
7 #include "base/bind.h" | 9 #include "base/bind.h" |
8 #include "base/logging.h" | 10 #include "base/logging.h" |
| 11 #include "base/memory/scoped_ptr.h" |
9 #include "chromeos/dbus/bluetooth_property.h" | 12 #include "chromeos/dbus/bluetooth_property.h" |
10 #include "dbus/bus.h" | 13 #include "dbus/bus.h" |
11 #include "dbus/message.h" | 14 #include "dbus/message.h" |
12 #include "dbus/object_path.h" | 15 #include "dbus/object_path.h" |
13 #include "dbus/object_proxy.h" | 16 #include "dbus/object_proxy.h" |
14 #include "third_party/cros_system_api/dbus/service_constants.h" | 17 #include "third_party/cros_system_api/dbus/service_constants.h" |
15 | 18 |
16 namespace chromeos { | 19 namespace chromeos { |
17 | 20 |
18 BluetoothManagerClient::Properties::Properties(dbus::ObjectProxy* object_proxy, | 21 BluetoothManagerClient::Properties::Properties( |
19 PropertyChangedCallback callback) | 22 dbus::ObjectProxy* object_proxy, |
| 23 const PropertyChangedCallback& callback) |
20 : BluetoothPropertySet(object_proxy, | 24 : BluetoothPropertySet(object_proxy, |
21 bluetooth_manager::kBluetoothManagerInterface, | 25 bluetooth_manager::kBluetoothManagerInterface, |
22 callback) { | 26 callback) { |
23 RegisterProperty(bluetooth_manager::kAdaptersProperty, &adapters); | 27 RegisterProperty(bluetooth_manager::kAdaptersProperty, &adapters); |
24 } | 28 } |
25 | 29 |
26 BluetoothManagerClient::Properties::~Properties() { | 30 BluetoothManagerClient::Properties::~Properties() { |
27 } | 31 } |
28 | 32 |
29 | 33 |
(...skipping 233 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
263 // List of observers interested in event notifications from us. | 267 // List of observers interested in event notifications from us. |
264 ObserverList<Observer> observers_; | 268 ObserverList<Observer> observers_; |
265 | 269 |
266 DISALLOW_COPY_AND_ASSIGN(BluetoothManagerClientImpl); | 270 DISALLOW_COPY_AND_ASSIGN(BluetoothManagerClientImpl); |
267 }; | 271 }; |
268 | 272 |
269 // The BluetoothManagerClient implementation used on Linux desktop, which does | 273 // The BluetoothManagerClient implementation used on Linux desktop, which does |
270 // nothing. | 274 // nothing. |
271 class BluetoothManagerClientStubImpl : public BluetoothManagerClient { | 275 class BluetoothManagerClientStubImpl : public BluetoothManagerClient { |
272 public: | 276 public: |
| 277 struct Properties : public BluetoothManagerClient::Properties { |
| 278 explicit Properties(const PropertyChangedCallback& callback) |
| 279 : BluetoothManagerClient::Properties(NULL, callback) { |
| 280 } |
| 281 |
| 282 virtual ~Properties() { |
| 283 } |
| 284 |
| 285 virtual void Get(dbus::PropertyBase* property, |
| 286 dbus::PropertySet::GetCallback callback) OVERRIDE { |
| 287 VLOG(1) << "Get " << property->name(); |
| 288 callback.Run(false); |
| 289 } |
| 290 |
| 291 virtual void GetAll() OVERRIDE { |
| 292 VLOG(1) << "GetAll"; |
| 293 } |
| 294 |
| 295 virtual void Set(dbus::PropertyBase* property, |
| 296 dbus::PropertySet::SetCallback callback) OVERRIDE { |
| 297 VLOG(1) << "Set " << property->name(); |
| 298 callback.Run(false); |
| 299 } |
| 300 }; |
| 301 |
| 302 BluetoothManagerClientStubImpl() { |
| 303 properties_.reset(new Properties(base::Bind( |
| 304 &BluetoothManagerClientStubImpl::OnPropertyChanged, |
| 305 base::Unretained(this)))); |
| 306 |
| 307 std::vector<dbus::ObjectPath> adapters; |
| 308 adapters.push_back(dbus::ObjectPath("/fake/hci0")); |
| 309 properties_->adapters.ReplaceValue(adapters); |
| 310 } |
| 311 |
273 // BluetoothManagerClient override. | 312 // BluetoothManagerClient override. |
274 virtual void AddObserver(Observer* observer) OVERRIDE { | 313 virtual void AddObserver(Observer* observer) OVERRIDE { |
| 314 observers_.AddObserver(observer); |
275 } | 315 } |
276 | 316 |
277 // BluetoothManagerClient override. | 317 // BluetoothManagerClient override. |
278 virtual void RemoveObserver(Observer* observer) OVERRIDE { | 318 virtual void RemoveObserver(Observer* observer) OVERRIDE { |
| 319 observers_.RemoveObserver(observer); |
279 } | 320 } |
280 | 321 |
281 // BluetoothManagerClient override. | 322 // BluetoothManagerClient override. |
282 virtual Properties* GetProperties() OVERRIDE { | 323 virtual Properties* GetProperties() OVERRIDE { |
283 VLOG(1) << "GetProperties"; | 324 VLOG(1) << "GetProperties"; |
284 return NULL; | 325 return properties_.get(); |
285 } | 326 } |
286 | 327 |
287 // BluetoothManagerClient override. | 328 // BluetoothManagerClient override. |
288 virtual void DefaultAdapter(const AdapterCallback& callback) OVERRIDE { | 329 virtual void DefaultAdapter(const AdapterCallback& callback) OVERRIDE { |
289 VLOG(1) << "DefaultAdapter."; | 330 VLOG(1) << "DefaultAdapter."; |
290 callback.Run(dbus::ObjectPath(), false); | 331 callback.Run(dbus::ObjectPath("/fake/hci0"), true); |
291 } | 332 } |
292 | 333 |
293 // BluetoothManagerClient override. | 334 // BluetoothManagerClient override. |
294 virtual void FindAdapter(const std::string& address, | 335 virtual void FindAdapter(const std::string& address, |
295 const AdapterCallback& callback) { | 336 const AdapterCallback& callback) { |
296 VLOG(1) << "FindAdapter: " << address; | 337 VLOG(1) << "FindAdapter: " << address; |
297 callback.Run(dbus::ObjectPath(), false); | 338 if (address == "hci0") |
| 339 callback.Run(dbus::ObjectPath("/fake/hci0"), true); |
| 340 else |
| 341 callback.Run(dbus::ObjectPath(), false); |
298 } | 342 } |
| 343 |
| 344 private: |
| 345 void OnPropertyChanged(const std::string& property_name) { |
| 346 FOR_EACH_OBSERVER(BluetoothManagerClient::Observer, observers_, |
| 347 ManagerPropertyChanged(property_name)); |
| 348 } |
| 349 |
| 350 // List of observers interested in event notifications from us. |
| 351 ObserverList<Observer> observers_; |
| 352 |
| 353 // Static properties we return. |
| 354 scoped_ptr<Properties> properties_; |
299 }; | 355 }; |
300 | 356 |
301 BluetoothManagerClient::BluetoothManagerClient() { | 357 BluetoothManagerClient::BluetoothManagerClient() { |
302 } | 358 } |
303 | 359 |
304 BluetoothManagerClient::~BluetoothManagerClient() { | 360 BluetoothManagerClient::~BluetoothManagerClient() { |
305 } | 361 } |
306 | 362 |
307 BluetoothManagerClient* BluetoothManagerClient::Create( | 363 BluetoothManagerClient* BluetoothManagerClient::Create( |
308 DBusClientImplementationType type, | 364 DBusClientImplementationType type, |
309 dbus::Bus* bus) { | 365 dbus::Bus* bus) { |
310 if (type == REAL_DBUS_CLIENT_IMPLEMENTATION) | 366 if (type == REAL_DBUS_CLIENT_IMPLEMENTATION) |
311 return new BluetoothManagerClientImpl(bus); | 367 return new BluetoothManagerClientImpl(bus); |
312 DCHECK_EQ(STUB_DBUS_CLIENT_IMPLEMENTATION, type); | 368 DCHECK_EQ(STUB_DBUS_CLIENT_IMPLEMENTATION, type); |
313 return new BluetoothManagerClientStubImpl(); | 369 return new BluetoothManagerClientStubImpl(); |
314 } | 370 } |
315 | 371 |
316 } // namespace chromeos | 372 } // namespace chromeos |
OLD | NEW |