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/fake_cras_audio_client.h" | 5 #include "chromeos/dbus/fake_cras_audio_client.h" |
6 | 6 |
7 namespace chromeos { | 7 namespace chromeos { |
8 | 8 |
9 FakeCrasAudioClient::FakeCrasAudioClient() | 9 FakeCrasAudioClient::FakeCrasAudioClient() |
10 : active_input_node_id_(0), | 10 : active_input_node_id_(0), |
(...skipping 80 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
91 void FakeCrasAudioClient::GetVolumeState( | 91 void FakeCrasAudioClient::GetVolumeState( |
92 const GetVolumeStateCallback& callback) { | 92 const GetVolumeStateCallback& callback) { |
93 callback.Run(volume_state_, true); | 93 callback.Run(volume_state_, true); |
94 } | 94 } |
95 | 95 |
96 void FakeCrasAudioClient::GetNodes(const GetNodesCallback& callback, | 96 void FakeCrasAudioClient::GetNodes(const GetNodesCallback& callback, |
97 const ErrorCallback& error_callback) { | 97 const ErrorCallback& error_callback) { |
98 callback.Run(node_list_, true); | 98 callback.Run(node_list_, true); |
99 } | 99 } |
100 | 100 |
101 void FakeCrasAudioClient::SetOutputNodeVolume(uint64 node_id, | 101 void FakeCrasAudioClient::SetOutputNodeVolume(uint64 node_id, int32 volume) {} |
102 int32 volume) { | |
103 } | |
104 | 102 |
105 void FakeCrasAudioClient::SetOutputUserMute(bool mute_on) { | 103 void FakeCrasAudioClient::SetOutputUserMute(bool mute_on) { |
106 volume_state_.output_user_mute = mute_on; | 104 volume_state_.output_user_mute = mute_on; |
107 FOR_EACH_OBSERVER(Observer, | 105 FOR_EACH_OBSERVER(Observer, observers_, |
108 observers_, | |
109 OutputMuteChanged(volume_state_.output_user_mute)); | 106 OutputMuteChanged(volume_state_.output_user_mute)); |
110 } | 107 } |
111 | 108 |
112 void FakeCrasAudioClient::SetInputNodeGain(uint64 node_id, | 109 void FakeCrasAudioClient::SetInputNodeGain(uint64 node_id, int32 input_gain) {} |
113 int32 input_gain) { | |
114 } | |
115 | 110 |
116 void FakeCrasAudioClient::SetInputMute(bool mute_on) { | 111 void FakeCrasAudioClient::SetInputMute(bool mute_on) { |
117 volume_state_.input_mute = mute_on; | 112 volume_state_.input_mute = mute_on; |
118 FOR_EACH_OBSERVER(Observer, | 113 FOR_EACH_OBSERVER(Observer, observers_, |
119 observers_, | |
120 InputMuteChanged(volume_state_.input_mute)); | 114 InputMuteChanged(volume_state_.input_mute)); |
121 } | 115 } |
122 | 116 |
123 void FakeCrasAudioClient::SetActiveOutputNode(uint64 node_id) { | 117 void FakeCrasAudioClient::SetActiveOutputNode(uint64 node_id) { |
124 if (active_output_node_id_ == node_id) | 118 if (active_output_node_id_ == node_id) |
125 return; | 119 return; |
126 | 120 |
127 for (size_t i = 0; i < node_list_.size(); ++i) { | 121 for (size_t i = 0; i < node_list_.size(); ++i) { |
128 if (node_list_[i].id == active_output_node_id_) | 122 if (node_list_[i].id == active_output_node_id_) |
129 node_list_[i].active = false; | 123 node_list_[i].active = false; |
130 else if (node_list_[i].id == node_id) | 124 else if (node_list_[i].id == node_id) |
131 node_list_[i].active = true; | 125 node_list_[i].active = true; |
132 } | 126 } |
133 active_output_node_id_ = node_id; | 127 active_output_node_id_ = node_id; |
134 FOR_EACH_OBSERVER(Observer, | 128 FOR_EACH_OBSERVER(Observer, observers_, ActiveOutputNodeChanged(node_id)); |
135 observers_, | |
136 ActiveOutputNodeChanged(node_id)); | |
137 } | 129 } |
138 | 130 |
139 void FakeCrasAudioClient::SetActiveInputNode(uint64 node_id) { | 131 void FakeCrasAudioClient::SetActiveInputNode(uint64 node_id) { |
140 if (active_input_node_id_ == node_id) | 132 if (active_input_node_id_ == node_id) |
141 return; | 133 return; |
142 | 134 |
143 for (size_t i = 0; i < node_list_.size(); ++i) { | 135 for (size_t i = 0; i < node_list_.size(); ++i) { |
144 if (node_list_[i].id == active_input_node_id_) | 136 if (node_list_[i].id == active_input_node_id_) |
145 node_list_[i].active = false; | 137 node_list_[i].active = false; |
146 else if (node_list_[i].id == node_id) | 138 else if (node_list_[i].id == node_id) |
147 node_list_[i].active = true; | 139 node_list_[i].active = true; |
148 } | 140 } |
149 active_input_node_id_ = node_id; | 141 active_input_node_id_ = node_id; |
150 FOR_EACH_OBSERVER(Observer, | 142 FOR_EACH_OBSERVER(Observer, observers_, ActiveInputNodeChanged(node_id)); |
151 observers_, | |
152 ActiveInputNodeChanged(node_id)); | |
153 } | 143 } |
154 | 144 |
155 void FakeCrasAudioClient::AddActiveInputNode(uint64 node_id) { | 145 void FakeCrasAudioClient::AddActiveInputNode(uint64 node_id) { |
156 for (size_t i = 0; i < node_list_.size(); ++i) { | 146 for (size_t i = 0; i < node_list_.size(); ++i) { |
157 if (node_list_[i].id == node_id) | 147 if (node_list_[i].id == node_id) |
158 node_list_[i].active = true; | 148 node_list_[i].active = true; |
159 } | 149 } |
160 } | 150 } |
161 | 151 |
162 void FakeCrasAudioClient::RemoveActiveInputNode(uint64 node_id) { | 152 void FakeCrasAudioClient::RemoveActiveInputNode(uint64 node_id) { |
(...skipping 13 matching lines...) Expand all Loading... | |
176 } | 166 } |
177 } | 167 } |
178 | 168 |
179 void FakeCrasAudioClient::RemoveActiveOutputNode(uint64 node_id) { | 169 void FakeCrasAudioClient::RemoveActiveOutputNode(uint64 node_id) { |
180 for (size_t i = 0; i < node_list_.size(); ++i) { | 170 for (size_t i = 0; i < node_list_.size(); ++i) { |
181 if (node_list_[i].id == node_id) | 171 if (node_list_[i].id == node_id) |
182 node_list_[i].active = false; | 172 node_list_[i].active = false; |
183 } | 173 } |
184 } | 174 } |
185 | 175 |
176 void FakeCrasAudioClient::InsertAudioNodeToList(const AudioNode& audio_node) { | |
177 auto iter = FindNode(audio_node.id); | |
178 if (iter != node_list_.end()) | |
179 (*iter) = audio_node; | |
180 else | |
181 node_list_.push_back(audio_node); | |
182 | |
183 FOR_EACH_OBSERVER(Observer, observers_, NodesChanged()); | |
184 } | |
185 | |
186 void FakeCrasAudioClient::RemoveAudioNodeFromList(const uint64& node_id) { | |
187 auto iter = FindNode(node_id); | |
188 if (iter != node_list_.end()) | |
189 node_list_.erase(iter); | |
190 | |
191 FOR_EACH_OBSERVER(Observer, observers_, NodesChanged()); | |
xiyuan
2015/08/07 20:17:12
Move this with node_list_.erase() so that we only
mozartalouis
2015/08/07 22:44:07
Done.
| |
192 } | |
193 | |
186 void FakeCrasAudioClient::SetAudioNodesForTesting( | 194 void FakeCrasAudioClient::SetAudioNodesForTesting( |
187 const AudioNodeList& audio_nodes) { | 195 const AudioNodeList& audio_nodes) { |
188 node_list_ = audio_nodes; | 196 node_list_ = audio_nodes; |
189 } | 197 } |
190 | 198 |
191 void FakeCrasAudioClient::SetAudioNodesAndNotifyObserversForTesting( | 199 void FakeCrasAudioClient::SetAudioNodesAndNotifyObserversForTesting( |
192 const AudioNodeList& new_nodes) { | 200 const AudioNodeList& new_nodes) { |
193 SetAudioNodesForTesting(new_nodes); | 201 SetAudioNodesForTesting(new_nodes); |
194 FOR_EACH_OBSERVER(Observer, observers_, NodesChanged()); | 202 FOR_EACH_OBSERVER(Observer, observers_, NodesChanged()); |
195 } | 203 } |
196 | 204 |
205 AudioNodeList::iterator FakeCrasAudioClient::FindNode(uint64 node_id) { | |
206 return std::find_if( | |
207 node_list_.begin(), node_list_.end(), | |
208 [node_id](const AudioNode& node) { return node_id == node.id; }); | |
209 } | |
210 | |
197 } // namespace chromeos | 211 } // namespace chromeos |
OLD | NEW |