| 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 <stdint.h> | 7 #include <stdint.h> |
| 8 | 8 |
| 9 #include "base/bind.h" | 9 #include "base/bind.h" |
| 10 #include "base/format_macros.h" | 10 #include "base/format_macros.h" |
| (...skipping 261 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 272 // Called when the cras signal is initially connected. | 272 // Called when the cras signal is initially connected. |
| 273 void SignalConnected(const std::string& interface_name, | 273 void SignalConnected(const std::string& interface_name, |
| 274 const std::string& signal_name, | 274 const std::string& signal_name, |
| 275 bool success) { | 275 bool success) { |
| 276 LOG_IF(ERROR, !success) | 276 LOG_IF(ERROR, !success) |
| 277 << "Failed to connect to cras signal:" << signal_name; | 277 << "Failed to connect to cras signal:" << signal_name; |
| 278 } | 278 } |
| 279 | 279 |
| 280 void NameOwnerChangedReceived(const std::string& old_owner, | 280 void NameOwnerChangedReceived(const std::string& old_owner, |
| 281 const std::string& new_owner) { | 281 const std::string& new_owner) { |
| 282 FOR_EACH_OBSERVER(Observer, observers_, AudioClientRestarted()); | 282 for (auto& observer : observers_) |
| 283 observer.AudioClientRestarted(); |
| 283 } | 284 } |
| 284 | 285 |
| 285 // Called when a OutputMuteChanged signal is received. | 286 // Called when a OutputMuteChanged signal is received. |
| 286 void OutputMuteChangedReceived(dbus::Signal* signal) { | 287 void OutputMuteChangedReceived(dbus::Signal* signal) { |
| 287 // Chrome should always call SetOutputUserMute api to set the output | 288 // Chrome should always call SetOutputUserMute api to set the output |
| 288 // mute state and monitor user_mute state from OutputMuteChanged signal. | 289 // mute state and monitor user_mute state from OutputMuteChanged signal. |
| 289 dbus::MessageReader reader(signal); | 290 dbus::MessageReader reader(signal); |
| 290 bool system_mute, user_mute; | 291 bool system_mute, user_mute; |
| 291 if (!reader.PopBool(&system_mute) || !reader.PopBool(&user_mute)) { | 292 if (!reader.PopBool(&system_mute) || !reader.PopBool(&user_mute)) { |
| 292 LOG(ERROR) << "Error reading signal from cras:" | 293 LOG(ERROR) << "Error reading signal from cras:" |
| 293 << signal->ToString(); | 294 << signal->ToString(); |
| 294 } | 295 } |
| 295 FOR_EACH_OBSERVER(Observer, observers_, OutputMuteChanged(user_mute)); | 296 for (auto& observer : observers_) |
| 297 observer.OutputMuteChanged(user_mute); |
| 296 } | 298 } |
| 297 | 299 |
| 298 // Called when a InputMuteChanged signal is received. | 300 // Called when a InputMuteChanged signal is received. |
| 299 void InputMuteChangedReceived(dbus::Signal* signal) { | 301 void InputMuteChangedReceived(dbus::Signal* signal) { |
| 300 dbus::MessageReader reader(signal); | 302 dbus::MessageReader reader(signal); |
| 301 bool mute; | 303 bool mute; |
| 302 if (!reader.PopBool(&mute)) { | 304 if (!reader.PopBool(&mute)) { |
| 303 LOG(ERROR) << "Error reading signal from cras:" | 305 LOG(ERROR) << "Error reading signal from cras:" |
| 304 << signal->ToString(); | 306 << signal->ToString(); |
| 305 } | 307 } |
| 306 FOR_EACH_OBSERVER(Observer, observers_, InputMuteChanged(mute)); | 308 for (auto& observer : observers_) |
| 309 observer.InputMuteChanged(mute); |
| 307 } | 310 } |
| 308 | 311 |
| 309 void NodesChangedReceived(dbus::Signal* signal) { | 312 void NodesChangedReceived(dbus::Signal* signal) { |
| 310 FOR_EACH_OBSERVER(Observer, observers_, NodesChanged()); | 313 for (auto& observer : observers_) |
| 314 observer.NodesChanged(); |
| 311 } | 315 } |
| 312 | 316 |
| 313 void ActiveOutputNodeChangedReceived(dbus::Signal* signal) { | 317 void ActiveOutputNodeChangedReceived(dbus::Signal* signal) { |
| 314 dbus::MessageReader reader(signal); | 318 dbus::MessageReader reader(signal); |
| 315 uint64_t node_id; | 319 uint64_t node_id; |
| 316 if (!reader.PopUint64(&node_id)) { | 320 if (!reader.PopUint64(&node_id)) { |
| 317 LOG(ERROR) << "Error reading signal from cras:" | 321 LOG(ERROR) << "Error reading signal from cras:" |
| 318 << signal->ToString(); | 322 << signal->ToString(); |
| 319 } | 323 } |
| 320 FOR_EACH_OBSERVER(Observer, observers_, ActiveOutputNodeChanged(node_id)); | 324 for (auto& observer : observers_) |
| 325 observer.ActiveOutputNodeChanged(node_id); |
| 321 } | 326 } |
| 322 | 327 |
| 323 void ActiveInputNodeChangedReceived(dbus::Signal* signal) { | 328 void ActiveInputNodeChangedReceived(dbus::Signal* signal) { |
| 324 dbus::MessageReader reader(signal); | 329 dbus::MessageReader reader(signal); |
| 325 uint64_t node_id; | 330 uint64_t node_id; |
| 326 if (!reader.PopUint64(&node_id)) { | 331 if (!reader.PopUint64(&node_id)) { |
| 327 LOG(ERROR) << "Error reading signal from cras:" | 332 LOG(ERROR) << "Error reading signal from cras:" |
| 328 << signal->ToString(); | 333 << signal->ToString(); |
| 329 } | 334 } |
| 330 FOR_EACH_OBSERVER(Observer, observers_, ActiveInputNodeChanged(node_id)); | 335 for (auto& observer : observers_) |
| 336 observer.ActiveInputNodeChanged(node_id); |
| 331 } | 337 } |
| 332 | 338 |
| 333 void OutputNodeVolumeChangedReceived(dbus::Signal* signal) { | 339 void OutputNodeVolumeChangedReceived(dbus::Signal* signal) { |
| 334 dbus::MessageReader reader(signal); | 340 dbus::MessageReader reader(signal); |
| 335 uint64_t node_id; | 341 uint64_t node_id; |
| 336 int volume; | 342 int volume; |
| 337 | 343 |
| 338 if (!reader.PopUint64(&node_id)) { | 344 if (!reader.PopUint64(&node_id)) { |
| 339 LOG(ERROR) << "Error eading signal from cras:" << signal->ToString(); | 345 LOG(ERROR) << "Error eading signal from cras:" << signal->ToString(); |
| 340 } | 346 } |
| 341 if (!reader.PopInt32(&volume)) { | 347 if (!reader.PopInt32(&volume)) { |
| 342 LOG(ERROR) << "Error eading signal from cras:" << signal->ToString(); | 348 LOG(ERROR) << "Error eading signal from cras:" << signal->ToString(); |
| 343 } | 349 } |
| 344 FOR_EACH_OBSERVER(Observer, observers_, | 350 for (auto& observer : observers_) |
| 345 OutputNodeVolumeChanged(node_id, volume)); | 351 observer.OutputNodeVolumeChanged(node_id, volume); |
| 346 } | 352 } |
| 347 | 353 |
| 348 void OnGetVolumeState(const GetVolumeStateCallback& callback, | 354 void OnGetVolumeState(const GetVolumeStateCallback& callback, |
| 349 dbus::Response* response) { | 355 dbus::Response* response) { |
| 350 bool success = true; | 356 bool success = true; |
| 351 VolumeState volume_state; | 357 VolumeState volume_state; |
| 352 if (response) { | 358 if (response) { |
| 353 dbus::MessageReader reader(response); | 359 dbus::MessageReader reader(response); |
| 354 if (!reader.PopInt32(&volume_state.output_volume) || | 360 if (!reader.PopInt32(&volume_state.output_volume) || |
| 355 !reader.PopBool(&volume_state.output_system_mute) || | 361 !reader.PopBool(&volume_state.output_system_mute) || |
| (...skipping 146 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 502 | 508 |
| 503 CrasAudioClient::~CrasAudioClient() { | 509 CrasAudioClient::~CrasAudioClient() { |
| 504 } | 510 } |
| 505 | 511 |
| 506 // static | 512 // static |
| 507 CrasAudioClient* CrasAudioClient::Create() { | 513 CrasAudioClient* CrasAudioClient::Create() { |
| 508 return new CrasAudioClientImpl(); | 514 return new CrasAudioClientImpl(); |
| 509 } | 515 } |
| 510 | 516 |
| 511 } // namespace chromeos | 517 } // namespace chromeos |
| OLD | NEW |