Fix compilation error triggered with -Werror=sign-compare
[chromium-blink-merge.git] / chromeos / dbus / cras_audio_client_stub_impl.cc
blob58ac8a8118d5af19620a1455bd1d3e55bda49abf
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
3 // found in the LICENSE file.
5 #include "chromeos/dbus/cras_audio_client_stub_impl.h"
7 namespace chromeos {
9 CrasAudioClientStubImpl::CrasAudioClientStubImpl()
10 : active_input_node_id_(0),
11 active_output_node_id_(0) {
14 void CrasAudioClientStubImpl::Init(dbus::Bus* bus) {
15 VLOG(1) << "CrasAudioClientStubImpl is created";
17 // Fake audio output nodes.
18 AudioNode node_1;
19 node_1.is_input = false;
20 node_1.id = 10001;
21 node_1.device_name = "Fake Speaker";
22 node_1.type = "INTERNAL_SPEAKER";
23 node_1.name = "Speaker";
24 node_list_.push_back(node_1);
26 AudioNode node_2;
27 node_2.is_input = false;
28 node_2.id = 10002;
29 node_2.device_name = "Fake Headphone";
30 node_2.type = "HEADPHONE";
31 node_2.name = "Headphone";
32 node_list_.push_back(node_2);
34 AudioNode node_3;
35 node_3.is_input = false;
36 node_3.id = 10003;
37 node_3.device_name = "Fake Bluetooth Headphone";
38 node_3.type = "BLUETOOTH";
39 node_3.name = "Headphone";
40 node_list_.push_back(node_3);
42 // Fake audio input ndoes
43 AudioNode node_4;
44 node_4.is_input = true;
45 node_4.id = 10004;
46 node_4.device_name = "Fake Internal Mic";
47 node_4.type = "INTERNAL_MIC";
48 node_4.name = "Internal Mic";
49 node_list_.push_back(node_4);
51 AudioNode node_5;
52 node_5.is_input = true;
53 node_5.id = 10005;
54 node_5.device_name = "Fake USB Mic";
55 node_5.type = "USB";
56 node_5.name = "Mic";
57 node_list_.push_back(node_5);
60 CrasAudioClientStubImpl::~CrasAudioClientStubImpl() {
63 void CrasAudioClientStubImpl::AddObserver(Observer* observer) {
64 observers_.AddObserver(observer);
67 void CrasAudioClientStubImpl::RemoveObserver(Observer* observer) {
68 observers_.RemoveObserver(observer);
71 bool CrasAudioClientStubImpl::HasObserver(Observer* observer) {
72 return observers_.HasObserver(observer);
75 void CrasAudioClientStubImpl::GetVolumeState(
76 const GetVolumeStateCallback& callback) {
77 callback.Run(volume_state_, true);
80 void CrasAudioClientStubImpl::GetNodes(const GetNodesCallback& callback,
81 const ErrorCallback& error_callback) {
82 callback.Run(node_list_, true);
85 void CrasAudioClientStubImpl::SetOutputNodeVolume(uint64 node_id,
86 int32 volume) {
89 void CrasAudioClientStubImpl::SetOutputUserMute(bool mute_on) {
90 volume_state_.output_user_mute = mute_on;
91 FOR_EACH_OBSERVER(Observer,
92 observers_,
93 OutputMuteChanged(volume_state_.output_user_mute));
96 void CrasAudioClientStubImpl::SetInputNodeGain(uint64 node_id,
97 int32 input_gain) {
100 void CrasAudioClientStubImpl::SetInputMute(bool mute_on) {
101 volume_state_.input_mute = mute_on;
102 FOR_EACH_OBSERVER(Observer,
103 observers_,
104 InputMuteChanged(volume_state_.input_mute));
107 void CrasAudioClientStubImpl::SetActiveOutputNode(uint64 node_id) {
108 if (active_output_node_id_ == node_id)
109 return;
111 for (size_t i = 0; i < node_list_.size(); ++i) {
112 if (node_list_[i].id == active_output_node_id_)
113 node_list_[i].active = false;
114 else if (node_list_[i].id == node_id)
115 node_list_[i].active = true;
117 active_output_node_id_ = node_id;
118 FOR_EACH_OBSERVER(Observer,
119 observers_,
120 ActiveOutputNodeChanged(node_id));
123 void CrasAudioClientStubImpl::SetActiveInputNode(uint64 node_id) {
124 if (active_input_node_id_ == node_id)
125 return;
127 for (size_t i = 0; i < node_list_.size(); ++i) {
128 if (node_list_[i].id == active_input_node_id_)
129 node_list_[i].active = false;
130 else if (node_list_[i].id == node_id)
131 node_list_[i].active = true;
133 active_input_node_id_ = node_id;
134 FOR_EACH_OBSERVER(Observer,
135 observers_,
136 ActiveInputNodeChanged(node_id));
139 void CrasAudioClientStubImpl::SetAudioDevices(
140 const AudioNodeList& audio_nodes) {
141 node_list_.clear();
142 for (size_t i = 0; i < audio_nodes.size(); ++i)
143 node_list_.push_back(audio_nodes[i]);
146 void CrasAudioClientStubImpl::ChangeAudioNodes(const AudioNodeList& new_nodes) {
147 SetAudioDevices(new_nodes);
148 FOR_EACH_OBSERVER(Observer, observers_, NodesChanged());
151 } // namespace chromeos