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 |
11 #include <memory> | 11 #include <memory> |
12 #include <sstream> | 12 #include <sstream> |
13 | 13 |
14 #include "base/bind.h" | 14 #include "base/bind.h" |
15 #include "base/macros.h" | 15 #include "base/macros.h" |
16 #include "base/stl_util.h" | 16 #include "base/memory/ptr_util.h" |
17 #include "device/bluetooth/dbus/bluetooth_media_client.h" | 17 #include "device/bluetooth/dbus/bluetooth_media_client.h" |
18 #include "device/bluetooth/dbus/bluez_dbus_manager.h" | 18 #include "device/bluetooth/dbus/bluez_dbus_manager.h" |
19 #include "device/bluetooth/dbus/fake_bluetooth_adapter_client.h" | 19 #include "device/bluetooth/dbus/fake_bluetooth_adapter_client.h" |
20 #include "device/bluetooth/dbus/fake_bluetooth_media_client.h" | 20 #include "device/bluetooth/dbus/fake_bluetooth_media_client.h" |
21 #include "device/bluetooth/dbus/fake_bluetooth_media_endpoint_service_provider.h
" | 21 #include "device/bluetooth/dbus/fake_bluetooth_media_endpoint_service_provider.h
" |
22 | 22 |
23 using dbus::ObjectPath; | 23 using dbus::ObjectPath; |
24 | 24 |
25 namespace { | 25 namespace { |
26 | 26 |
(...skipping 58 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
85 | 85 |
86 void FakeBluetoothMediaTransportClient::Properties::Set( | 86 void FakeBluetoothMediaTransportClient::Properties::Set( |
87 dbus::PropertyBase* property, | 87 dbus::PropertyBase* property, |
88 dbus::PropertySet::SetCallback callback) { | 88 dbus::PropertySet::SetCallback callback) { |
89 VLOG(1) << "Set " << property->name(); | 89 VLOG(1) << "Set " << property->name(); |
90 callback.Run(false); | 90 callback.Run(false); |
91 } | 91 } |
92 | 92 |
93 FakeBluetoothMediaTransportClient::Transport::Transport( | 93 FakeBluetoothMediaTransportClient::Transport::Transport( |
94 const ObjectPath& transport_path, | 94 const ObjectPath& transport_path, |
95 Properties* transport_properties) | 95 std::unique_ptr<Properties> transport_properties) |
96 : path(transport_path) { | 96 : path(transport_path), properties(std::move(transport_properties)) {} |
97 properties.reset(transport_properties); | |
98 } | |
99 | 97 |
100 FakeBluetoothMediaTransportClient::Transport::~Transport() {} | 98 FakeBluetoothMediaTransportClient::Transport::~Transport() {} |
101 | 99 |
102 FakeBluetoothMediaTransportClient::FakeBluetoothMediaTransportClient() {} | 100 FakeBluetoothMediaTransportClient::FakeBluetoothMediaTransportClient() {} |
103 | 101 |
104 FakeBluetoothMediaTransportClient::~FakeBluetoothMediaTransportClient() { | 102 FakeBluetoothMediaTransportClient::~FakeBluetoothMediaTransportClient() {} |
105 base::STLDeleteValues(&endpoint_to_transport_map_); | |
106 } | |
107 | 103 |
108 // DBusClient override. | 104 // DBusClient override. |
109 void FakeBluetoothMediaTransportClient::Init(dbus::Bus* bus) {} | 105 void FakeBluetoothMediaTransportClient::Init(dbus::Bus* bus) {} |
110 | 106 |
111 void FakeBluetoothMediaTransportClient::AddObserver( | 107 void FakeBluetoothMediaTransportClient::AddObserver( |
112 BluetoothMediaTransportClient::Observer* observer) { | 108 BluetoothMediaTransportClient::Observer* observer) { |
113 observers_.AddObserver(observer); | 109 observers_.AddObserver(observer); |
114 } | 110 } |
115 | 111 |
116 void FakeBluetoothMediaTransportClient::RemoveObserver( | 112 void FakeBluetoothMediaTransportClient::RemoveObserver( |
(...skipping 58 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
175 properties->uuid.ReplaceValue( | 171 properties->uuid.ReplaceValue( |
176 BluetoothMediaClient::kBluetoothAudioSinkUUID); | 172 BluetoothMediaClient::kBluetoothAudioSinkUUID); |
177 properties->codec.ReplaceValue(kTransportCodec); | 173 properties->codec.ReplaceValue(kTransportCodec); |
178 properties->configuration.ReplaceValue( | 174 properties->configuration.ReplaceValue( |
179 UINT8_VECTOR_FROM_ARRAY(kTransportConfiguration)); | 175 UINT8_VECTOR_FROM_ARRAY(kTransportConfiguration)); |
180 properties->state.ReplaceValue(BluetoothMediaTransportClient::kStateIdle); | 176 properties->state.ReplaceValue(BluetoothMediaTransportClient::kStateIdle); |
181 properties->delay.ReplaceValue(kTransportDelay); | 177 properties->delay.ReplaceValue(kTransportDelay); |
182 properties->volume.ReplaceValue(kTransportVolume); | 178 properties->volume.ReplaceValue(kTransportVolume); |
183 | 179 |
184 endpoint_to_transport_map_[endpoint_path] = | 180 endpoint_to_transport_map_[endpoint_path] = |
185 new Transport(transport_path, properties.release()); | 181 base::MakeUnique<Transport>(transport_path, std::move(properties)); |
186 transport_to_endpoint_map_[transport_path] = endpoint_path; | 182 transport_to_endpoint_map_[transport_path] = endpoint_path; |
187 return; | 183 return; |
188 } | 184 } |
189 | 185 |
190 Transport* transport = GetTransport(endpoint_path); | 186 Transport* transport = GetTransport(endpoint_path); |
191 if (!transport) | 187 if (!transport) |
192 return; | 188 return; |
193 ObjectPath transport_path = transport->path; | 189 ObjectPath transport_path = transport->path; |
194 | 190 |
195 // Notifies observers about the state change of the transport. | 191 // Notifies observers about the state change of the transport. |
196 for (auto& observer : observers_) | 192 for (auto& observer : observers_) |
197 observer.MediaTransportRemoved(transport_path); | 193 observer.MediaTransportRemoved(transport_path); |
198 | 194 |
199 endpoint->ClearConfiguration(transport_path); | 195 endpoint->ClearConfiguration(transport_path); |
200 delete transport; | |
201 endpoint_to_transport_map_.erase(endpoint_path); | 196 endpoint_to_transport_map_.erase(endpoint_path); |
202 transport_to_endpoint_map_.erase(transport_path); | 197 transport_to_endpoint_map_.erase(transport_path); |
203 } | 198 } |
204 | 199 |
205 void FakeBluetoothMediaTransportClient::SetState( | 200 void FakeBluetoothMediaTransportClient::SetState( |
206 const ObjectPath& endpoint_path, | 201 const ObjectPath& endpoint_path, |
207 const std::string& state) { | 202 const std::string& state) { |
208 VLOG(1) << "SetState - state: " << state; | 203 VLOG(1) << "SetState - state: " << state; |
209 | 204 |
210 Transport* transport = GetTransport(endpoint_path); | 205 Transport* transport = GetTransport(endpoint_path); |
(...skipping 64 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
275 ObjectPath FakeBluetoothMediaTransportClient::GetEndpointPath( | 270 ObjectPath FakeBluetoothMediaTransportClient::GetEndpointPath( |
276 const ObjectPath& transport_path) { | 271 const ObjectPath& transport_path) { |
277 const auto& it = transport_to_endpoint_map_.find(transport_path); | 272 const auto& it = transport_to_endpoint_map_.find(transport_path); |
278 return it != transport_to_endpoint_map_.end() ? it->second : ObjectPath(""); | 273 return it != transport_to_endpoint_map_.end() ? it->second : ObjectPath(""); |
279 } | 274 } |
280 | 275 |
281 FakeBluetoothMediaTransportClient::Transport* | 276 FakeBluetoothMediaTransportClient::Transport* |
282 FakeBluetoothMediaTransportClient::GetTransport( | 277 FakeBluetoothMediaTransportClient::GetTransport( |
283 const ObjectPath& endpoint_path) { | 278 const ObjectPath& endpoint_path) { |
284 const auto& it = endpoint_to_transport_map_.find(endpoint_path); | 279 const auto& it = endpoint_to_transport_map_.find(endpoint_path); |
285 return (it != endpoint_to_transport_map_.end()) ? it->second : nullptr; | 280 return (it != endpoint_to_transport_map_.end()) ? it->second.get() : nullptr; |
286 } | 281 } |
287 | 282 |
288 FakeBluetoothMediaTransportClient::Transport* | 283 FakeBluetoothMediaTransportClient::Transport* |
289 FakeBluetoothMediaTransportClient::GetTransportByPath( | 284 FakeBluetoothMediaTransportClient::GetTransportByPath( |
290 const dbus::ObjectPath& transport_path) { | 285 const dbus::ObjectPath& transport_path) { |
291 return GetTransport(GetEndpointPath(transport_path)); | 286 return GetTransport(GetEndpointPath(transport_path)); |
292 } | 287 } |
293 | 288 |
294 void FakeBluetoothMediaTransportClient::AcquireInternal( | 289 void FakeBluetoothMediaTransportClient::AcquireInternal( |
295 bool try_flag, | 290 bool try_flag, |
(...skipping 25 matching lines...) Expand all Loading... |
321 } | 316 } |
322 DCHECK((fds[0] > kInvalidFd) && (fds[1] > kInvalidFd)); | 317 DCHECK((fds[0] > kInvalidFd) && (fds[1] > kInvalidFd)); |
323 transport->input_fd.reset(new base::File(fds[0])); | 318 transport->input_fd.reset(new base::File(fds[0])); |
324 | 319 |
325 base::ScopedFD out_fd(fds[1]); | 320 base::ScopedFD out_fd(fds[1]); |
326 callback.Run(std::move(out_fd), kDefaultReadMtu, kDefaultWriteMtu); | 321 callback.Run(std::move(out_fd), kDefaultReadMtu, kDefaultWriteMtu); |
327 SetState(endpoint_path, "active"); | 322 SetState(endpoint_path, "active"); |
328 } | 323 } |
329 | 324 |
330 } // namespace bluez | 325 } // namespace bluez |
OLD | NEW |