| OLD | NEW |
| 1 // Copyright 2014 The Chromium Authors. All rights reserved. | 1 // Copyright 2014 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 "device/bluetooth/dbus/fake_bluetooth_media_transport_client.h" | 5 #include "device/bluetooth/dbus/fake_bluetooth_media_transport_client.h" |
| 6 | 6 |
| 7 #include <stddef.h> | 7 #include <stddef.h> |
| 8 #include <sys/socket.h> | 8 #include <sys/socket.h> |
| 9 #include <unistd.h> | 9 #include <unistd.h> |
| 10 | 10 |
| (...skipping 175 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 186 transport_to_endpoint_map_[transport_path] = endpoint_path; | 186 transport_to_endpoint_map_[transport_path] = endpoint_path; |
| 187 return; | 187 return; |
| 188 } | 188 } |
| 189 | 189 |
| 190 Transport* transport = GetTransport(endpoint_path); | 190 Transport* transport = GetTransport(endpoint_path); |
| 191 if (!transport) | 191 if (!transport) |
| 192 return; | 192 return; |
| 193 ObjectPath transport_path = transport->path; | 193 ObjectPath transport_path = transport->path; |
| 194 | 194 |
| 195 // Notifies observers about the state change of the transport. | 195 // Notifies observers about the state change of the transport. |
| 196 FOR_EACH_OBSERVER(BluetoothMediaTransportClient::Observer, observers_, | 196 for (auto& observer : observers_) |
| 197 MediaTransportRemoved(transport_path)); | 197 observer.MediaTransportRemoved(transport_path); |
| 198 | 198 |
| 199 endpoint->ClearConfiguration(transport_path); | 199 endpoint->ClearConfiguration(transport_path); |
| 200 delete transport; | 200 delete transport; |
| 201 endpoint_to_transport_map_.erase(endpoint_path); | 201 endpoint_to_transport_map_.erase(endpoint_path); |
| 202 transport_to_endpoint_map_.erase(transport_path); | 202 transport_to_endpoint_map_.erase(transport_path); |
| 203 } | 203 } |
| 204 | 204 |
| 205 void FakeBluetoothMediaTransportClient::SetState( | 205 void FakeBluetoothMediaTransportClient::SetState( |
| 206 const ObjectPath& endpoint_path, | 206 const ObjectPath& endpoint_path, |
| 207 const std::string& state) { | 207 const std::string& state) { |
| 208 VLOG(1) << "SetState - state: " << state; | 208 VLOG(1) << "SetState - state: " << state; |
| 209 | 209 |
| 210 Transport* transport = GetTransport(endpoint_path); | 210 Transport* transport = GetTransport(endpoint_path); |
| 211 if (!transport) | 211 if (!transport) |
| 212 return; | 212 return; |
| 213 | 213 |
| 214 transport->properties->state.ReplaceValue(state); | 214 transport->properties->state.ReplaceValue(state); |
| 215 FOR_EACH_OBSERVER( | 215 for (auto& observer : observers_) { |
| 216 BluetoothMediaTransportClient::Observer, observers_, | 216 observer.MediaTransportPropertyChanged( |
| 217 MediaTransportPropertyChanged( | 217 transport->path, BluetoothMediaTransportClient::kStateProperty); |
| 218 transport->path, BluetoothMediaTransportClient::kStateProperty)); | 218 } |
| 219 } | 219 } |
| 220 | 220 |
| 221 void FakeBluetoothMediaTransportClient::SetVolume( | 221 void FakeBluetoothMediaTransportClient::SetVolume( |
| 222 const ObjectPath& endpoint_path, | 222 const ObjectPath& endpoint_path, |
| 223 const uint16_t& volume) { | 223 const uint16_t& volume) { |
| 224 Transport* transport = GetTransport(endpoint_path); | 224 Transport* transport = GetTransport(endpoint_path); |
| 225 if (!transport) | 225 if (!transport) |
| 226 return; | 226 return; |
| 227 | 227 |
| 228 transport->properties->volume.ReplaceValue(volume); | 228 transport->properties->volume.ReplaceValue(volume); |
| 229 FOR_EACH_OBSERVER( | 229 for (auto& observer : observers_) { |
| 230 BluetoothMediaTransportClient::Observer, observers_, | 230 observer.MediaTransportPropertyChanged( |
| 231 MediaTransportPropertyChanged( | 231 transport->path, BluetoothMediaTransportClient::kVolumeProperty); |
| 232 transport->path, BluetoothMediaTransportClient::kVolumeProperty)); | 232 } |
| 233 } | 233 } |
| 234 | 234 |
| 235 void FakeBluetoothMediaTransportClient::WriteData( | 235 void FakeBluetoothMediaTransportClient::WriteData( |
| 236 const ObjectPath& endpoint_path, | 236 const ObjectPath& endpoint_path, |
| 237 const std::vector<char>& bytes) { | 237 const std::vector<char>& bytes) { |
| 238 VLOG(1) << "WriteData - write " << bytes.size() << " bytes"; | 238 VLOG(1) << "WriteData - write " << bytes.size() << " bytes"; |
| 239 | 239 |
| 240 Transport* transport = GetTransport(endpoint_path); | 240 Transport* transport = GetTransport(endpoint_path); |
| 241 | 241 |
| 242 if (!transport || transport->properties->state.value() != "active") { | 242 if (!transport || transport->properties->state.value() != "active") { |
| (...skipping 78 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 321 } | 321 } |
| 322 DCHECK((fds[0] > kInvalidFd) && (fds[1] > kInvalidFd)); | 322 DCHECK((fds[0] > kInvalidFd) && (fds[1] > kInvalidFd)); |
| 323 transport->input_fd.reset(new base::File(fds[0])); | 323 transport->input_fd.reset(new base::File(fds[0])); |
| 324 | 324 |
| 325 base::ScopedFD out_fd(fds[1]); | 325 base::ScopedFD out_fd(fds[1]); |
| 326 callback.Run(std::move(out_fd), kDefaultReadMtu, kDefaultWriteMtu); | 326 callback.Run(std::move(out_fd), kDefaultReadMtu, kDefaultWriteMtu); |
| 327 SetState(endpoint_path, "active"); | 327 SetState(endpoint_path, "active"); |
| 328 } | 328 } |
| 329 | 329 |
| 330 } // namespace bluez | 330 } // namespace bluez |
| OLD | NEW |