| OLD | NEW |
| 1 // Copyright (c) 2013 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2013 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/experimental_bluetooth_adapter_client.h" | 5 #include "chromeos/dbus/experimental_bluetooth_adapter_client.h" |
| 6 | 6 |
| 7 #include <map> | |
| 8 | |
| 9 #include "base/bind.h" | 7 #include "base/bind.h" |
| 10 #include "base/logging.h" | 8 #include "base/logging.h" |
| 11 #include "chromeos/dbus/bluetooth_property.h" | 9 #include "chromeos/dbus/fake_bluetooth_adapter_client.h" |
| 12 #include "dbus/bus.h" | 10 #include "dbus/bus.h" |
| 13 #include "dbus/message.h" | 11 #include "dbus/message.h" |
| 14 #include "dbus/object_manager.h" | 12 #include "dbus/object_manager.h" |
| 15 #include "dbus/object_path.h" | 13 #include "dbus/object_path.h" |
| 16 #include "dbus/object_proxy.h" | 14 #include "dbus/object_proxy.h" |
| 17 #include "third_party/cros_system_api/dbus/service_constants.h" | 15 #include "third_party/cros_system_api/dbus/service_constants.h" |
| 18 | 16 |
| 19 namespace chromeos { | 17 namespace chromeos { |
| 20 | 18 |
| 21 const char ExperimentalBluetoothAdapterClient::kNoResponseError[] = | 19 const char ExperimentalBluetoothAdapterClient::kNoResponseError[] = |
| (...skipping 223 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 245 // Weak pointer factory for generating 'this' pointers that might live longer | 243 // Weak pointer factory for generating 'this' pointers that might live longer |
| 246 // than we do. | 244 // than we do. |
| 247 // Note: This should remain the last member so it'll be destroyed and | 245 // Note: This should remain the last member so it'll be destroyed and |
| 248 // invalidate its weak pointers before any other members are destroyed. | 246 // invalidate its weak pointers before any other members are destroyed. |
| 249 base::WeakPtrFactory<ExperimentalBluetoothAdapterClientImpl> | 247 base::WeakPtrFactory<ExperimentalBluetoothAdapterClientImpl> |
| 250 weak_ptr_factory_; | 248 weak_ptr_factory_; |
| 251 | 249 |
| 252 DISALLOW_COPY_AND_ASSIGN(ExperimentalBluetoothAdapterClientImpl); | 250 DISALLOW_COPY_AND_ASSIGN(ExperimentalBluetoothAdapterClientImpl); |
| 253 }; | 251 }; |
| 254 | 252 |
| 255 // The ExperimentalBluetoothAdapterClient implementation used on Linux desktop, | |
| 256 // which does nothing. | |
| 257 class ExperimentalBluetoothAdapterClientStubImpl | |
| 258 : public ExperimentalBluetoothAdapterClient { | |
| 259 public: | |
| 260 struct Properties : public ExperimentalBluetoothAdapterClient::Properties { | |
| 261 explicit Properties(const PropertyChangedCallback& callback) | |
| 262 : ExperimentalBluetoothAdapterClient::Properties( | |
| 263 NULL, | |
| 264 bluetooth_adapter::kExperimentalBluetoothAdapterInterface, | |
| 265 callback) { | |
| 266 } | |
| 267 | |
| 268 virtual ~Properties() { | |
| 269 } | |
| 270 | |
| 271 virtual void Get(dbus::PropertyBase* property, | |
| 272 dbus::PropertySet::GetCallback callback) OVERRIDE { | |
| 273 VLOG(1) << "Get " << property->name(); | |
| 274 callback.Run(false); | |
| 275 } | |
| 276 | |
| 277 virtual void GetAll() OVERRIDE { | |
| 278 VLOG(1) << "GetAll"; | |
| 279 } | |
| 280 | |
| 281 virtual void Set(dbus::PropertyBase *property, | |
| 282 dbus::PropertySet::SetCallback callback) OVERRIDE { | |
| 283 VLOG(1) << "Set " << property->name(); | |
| 284 if (property->name() == "Powered") { | |
| 285 property->ReplaceValueWithSetValue(); | |
| 286 NotifyPropertyChanged(property->name()); | |
| 287 callback.Run(true); | |
| 288 } else { | |
| 289 callback.Run(false); | |
| 290 } | |
| 291 } | |
| 292 }; | |
| 293 | |
| 294 ExperimentalBluetoothAdapterClientStubImpl() { | |
| 295 properties_.reset(new Properties(base::Bind( | |
| 296 &ExperimentalBluetoothAdapterClientStubImpl::OnPropertyChanged, | |
| 297 base::Unretained(this)))); | |
| 298 | |
| 299 properties_->address.ReplaceValue("hci0"); | |
| 300 properties_->name.ReplaceValue("Fake Adapter"); | |
| 301 properties_->pairable.ReplaceValue(true); | |
| 302 } | |
| 303 | |
| 304 // ExperimentalBluetoothAdapterClient override. | |
| 305 virtual void AddObserver(Observer* observer) OVERRIDE { | |
| 306 observers_.AddObserver(observer); | |
| 307 } | |
| 308 | |
| 309 // ExperimentalBluetoothAdapterClient override. | |
| 310 virtual void RemoveObserver(Observer* observer) OVERRIDE { | |
| 311 observers_.RemoveObserver(observer); | |
| 312 } | |
| 313 | |
| 314 // ExperimentalBluetoothAdapterClient override. | |
| 315 virtual std::vector<dbus::ObjectPath> GetAdapters() OVERRIDE { | |
| 316 std::vector<dbus::ObjectPath> object_paths; | |
| 317 object_paths.push_back(dbus::ObjectPath("/fake/hci0")); | |
| 318 return object_paths; | |
| 319 } | |
| 320 | |
| 321 // ExperimentalBluetoothAdapterClient override. | |
| 322 virtual Properties* GetProperties(const dbus::ObjectPath& object_path) | |
| 323 OVERRIDE { | |
| 324 VLOG(1) << "GetProperties: " << object_path.value(); | |
| 325 if (object_path.value() == "/fake/hci0") | |
| 326 return properties_.get(); | |
| 327 else | |
| 328 return NULL; | |
| 329 } | |
| 330 | |
| 331 // ExperimentalBluetoothAdapterClient override. | |
| 332 virtual void StartDiscovery(const dbus::ObjectPath& object_path, | |
| 333 const base::Closure& callback, | |
| 334 const ErrorCallback& error_callback) OVERRIDE { | |
| 335 VLOG(1) << "StartDiscovery: " << object_path.value(); | |
| 336 error_callback.Run(kNoResponseError, ""); | |
| 337 } | |
| 338 | |
| 339 // ExperimentalBluetoothAdapterClient override. | |
| 340 virtual void StopDiscovery(const dbus::ObjectPath& object_path, | |
| 341 const base::Closure& callback, | |
| 342 const ErrorCallback& error_callback) OVERRIDE { | |
| 343 VLOG(1) << "StopDiscovery: " << object_path.value(); | |
| 344 error_callback.Run(kNoResponseError, ""); | |
| 345 } | |
| 346 | |
| 347 // ExperimentalBluetoothAdapterClient override. | |
| 348 virtual void RemoveDevice(const dbus::ObjectPath& object_path, | |
| 349 const dbus::ObjectPath& device_path, | |
| 350 const base::Closure& callback, | |
| 351 const ErrorCallback& error_callback) OVERRIDE { | |
| 352 VLOG(1) << "RemoveDevice: " << object_path.value() | |
| 353 << " " << device_path.value(); | |
| 354 error_callback.Run(kNoResponseError, ""); | |
| 355 } | |
| 356 | |
| 357 private: | |
| 358 void OnPropertyChanged(const std::string& property_name) { | |
| 359 FOR_EACH_OBSERVER(ExperimentalBluetoothAdapterClient::Observer, observers_, | |
| 360 AdapterPropertyChanged(dbus::ObjectPath("/fake/hci0"), | |
| 361 property_name)); | |
| 362 } | |
| 363 | |
| 364 // List of observers interested in event notifications from us. | |
| 365 ObserverList<Observer> observers_; | |
| 366 | |
| 367 // Static properties we return. | |
| 368 scoped_ptr<Properties> properties_; | |
| 369 }; | |
| 370 | |
| 371 ExperimentalBluetoothAdapterClient::ExperimentalBluetoothAdapterClient() { | 253 ExperimentalBluetoothAdapterClient::ExperimentalBluetoothAdapterClient() { |
| 372 } | 254 } |
| 373 | 255 |
| 374 ExperimentalBluetoothAdapterClient::~ExperimentalBluetoothAdapterClient() { | 256 ExperimentalBluetoothAdapterClient::~ExperimentalBluetoothAdapterClient() { |
| 375 } | 257 } |
| 376 | 258 |
| 377 ExperimentalBluetoothAdapterClient* ExperimentalBluetoothAdapterClient::Create( | 259 ExperimentalBluetoothAdapterClient* ExperimentalBluetoothAdapterClient::Create( |
| 378 DBusClientImplementationType type, | 260 DBusClientImplementationType type, |
| 379 dbus::Bus* bus) { | 261 dbus::Bus* bus) { |
| 380 if (type == REAL_DBUS_CLIENT_IMPLEMENTATION) | 262 if (type == REAL_DBUS_CLIENT_IMPLEMENTATION) |
| 381 return new ExperimentalBluetoothAdapterClientImpl(bus); | 263 return new ExperimentalBluetoothAdapterClientImpl(bus); |
| 382 DCHECK_EQ(STUB_DBUS_CLIENT_IMPLEMENTATION, type); | 264 DCHECK_EQ(STUB_DBUS_CLIENT_IMPLEMENTATION, type); |
| 383 return new ExperimentalBluetoothAdapterClientStubImpl(); | 265 return new FakeBluetoothAdapterClient(); |
| 384 } | 266 } |
| 385 | 267 |
| 386 } // namespace chromeos | 268 } // namespace chromeos |
| OLD | NEW |