| 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/cras_audio_client.h" | 5 #include "chromeos/dbus/cras_audio_client.h" |
| 6 | 6 |
| 7 #include "base/bind.h" | 7 #include "base/bind.h" |
| 8 #include "dbus/bus.h" | 8 #include "dbus/bus.h" |
| 9 #include "dbus/message.h" | 9 #include "dbus/message.h" |
| 10 #include "dbus/object_path.h" | 10 #include "dbus/object_path.h" |
| 11 #include "dbus/object_proxy.h" | 11 #include "dbus/object_proxy.h" |
| 12 #include "third_party/cros_system_api/dbus/service_constants.h" | 12 #include "third_party/cros_system_api/dbus/service_constants.h" |
| 13 | 13 |
| 14 namespace { | |
| 15 | |
| 16 // TODO(jennyz): Remove this section and use the dbus properties constants | |
| 17 // defined in service_constants.h, once the change is done in cros side for | |
| 18 // service_constants.h and rolled down to chrome. | |
| 19 const char kIsInputProperty[] = "IsInput"; | |
| 20 const char kIdProperty[] = "Id"; | |
| 21 const char kDeviceNameProperty[] = "DeviceName"; | |
| 22 const char kTypeProperty[] = "Type"; | |
| 23 const char kNameProperty[] = "Name"; | |
| 24 const char kActiveProperty[] = "Active"; | |
| 25 | |
| 26 } // namespace | |
| 27 | |
| 28 namespace chromeos { | 14 namespace chromeos { |
| 29 | 15 |
| 30 // The CrasAudioClient implementation used in production. | 16 // The CrasAudioClient implementation used in production. |
| 31 class CrasAudioClientImpl : public CrasAudioClient { | 17 class CrasAudioClientImpl : public CrasAudioClient { |
| 32 public: | 18 public: |
| 33 explicit CrasAudioClientImpl(dbus::Bus* bus) | 19 explicit CrasAudioClientImpl(dbus::Bus* bus) |
| 34 : cras_proxy_(NULL), | 20 : cras_proxy_(NULL), |
| 35 weak_ptr_factory_(this) { | 21 weak_ptr_factory_(this) { |
| 36 cras_proxy_ = bus->GetObjectProxy( | 22 cras_proxy_ = bus->GetObjectProxy( |
| 37 cras::kCrasServiceName, | 23 cras::kCrasServiceName, |
| (...skipping 303 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 341 while (array_reader->HasMoreData()) { | 327 while (array_reader->HasMoreData()) { |
| 342 dbus::MessageReader dict_entry_reader(response); | 328 dbus::MessageReader dict_entry_reader(response); |
| 343 dbus::MessageReader value_reader(response); | 329 dbus::MessageReader value_reader(response); |
| 344 std::string key; | 330 std::string key; |
| 345 if (!array_reader->PopDictEntry(&dict_entry_reader) || | 331 if (!array_reader->PopDictEntry(&dict_entry_reader) || |
| 346 !dict_entry_reader.PopString(&key) || | 332 !dict_entry_reader.PopString(&key) || |
| 347 !dict_entry_reader.PopVariant(&value_reader)) { | 333 !dict_entry_reader.PopVariant(&value_reader)) { |
| 348 return false; | 334 return false; |
| 349 } | 335 } |
| 350 | 336 |
| 351 if (key == kIsInputProperty) { | 337 if (key == cras::kIsInputProperty) { |
| 352 if (!value_reader.PopBool(&node->is_input)) | 338 if (!value_reader.PopBool(&node->is_input)) |
| 353 return false; | 339 return false; |
| 354 } else if (key == kIdProperty) { | 340 } else if (key == cras::kIdProperty) { |
| 355 if (!value_reader.PopUint64(&node->id)) | 341 if (!value_reader.PopUint64(&node->id)) |
| 356 return false; | 342 return false; |
| 357 } else if (key == kDeviceNameProperty) { | 343 } else if (key == cras::kDeviceNameProperty) { |
| 358 if (!value_reader.PopString(&node->device_name)) | 344 if (!value_reader.PopString(&node->device_name)) |
| 359 return false; | 345 return false; |
| 360 } else if (key == kTypeProperty) { | 346 } else if (key == cras::kTypeProperty) { |
| 361 if (!value_reader.PopString(&node->type)) | 347 if (!value_reader.PopString(&node->type)) |
| 362 return false; | 348 return false; |
| 363 } else if (key == kNameProperty) { | 349 } else if (key == cras::kNameProperty) { |
| 364 if (!value_reader.PopString(&node->name)) | 350 if (!value_reader.PopString(&node->name)) |
| 365 return false; | 351 return false; |
| 366 } else if (key == kActiveProperty) { | 352 } else if (key == cras::kActiveProperty) { |
| 367 if (!value_reader.PopBool(&node->active)) | 353 if (!value_reader.PopBool(&node->active)) |
| 368 return false; | 354 return false; |
| 369 } | 355 } |
| 370 } | 356 } |
| 371 | 357 |
| 372 return true; | 358 return true; |
| 373 } | 359 } |
| 374 | 360 |
| 375 dbus::ObjectProxy* cras_proxy_; | 361 dbus::ObjectProxy* cras_proxy_; |
| 376 ObserverList<Observer> observers_; | 362 ObserverList<Observer> observers_; |
| (...skipping 69 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 446 DBusClientImplementationType type, | 432 DBusClientImplementationType type, |
| 447 dbus::Bus* bus) { | 433 dbus::Bus* bus) { |
| 448 if (type == REAL_DBUS_CLIENT_IMPLEMENTATION) { | 434 if (type == REAL_DBUS_CLIENT_IMPLEMENTATION) { |
| 449 return new CrasAudioClientImpl(bus); | 435 return new CrasAudioClientImpl(bus); |
| 450 } | 436 } |
| 451 DCHECK_EQ(STUB_DBUS_CLIENT_IMPLEMENTATION, type); | 437 DCHECK_EQ(STUB_DBUS_CLIENT_IMPLEMENTATION, type); |
| 452 return new CrasAudioClientStubImpl(); | 438 return new CrasAudioClientStubImpl(); |
| 453 } | 439 } |
| 454 | 440 |
| 455 } // namespace chromeos | 441 } // namespace chromeos |
| OLD | NEW |