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 "chromeos/dbus/bluetooth_media_endpoint_service_provider.h" | 5 #include "chromeos/dbus/bluetooth_media_endpoint_service_provider.h" |
6 | 6 |
7 #include "base/bind.h" | 7 #include "base/bind.h" |
8 #include "base/logging.h" | 8 #include "base/logging.h" |
9 #include "base/memory/ref_counted.h" | 9 #include "base/memory/ref_counted.h" |
10 #include "base/memory/scoped_ptr.h" | 10 #include "base/memory/scoped_ptr.h" |
(...skipping 88 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
99 // Returns true if the current thread is on the origin thread, false | 99 // Returns true if the current thread is on the origin thread, false |
100 // otherwise. | 100 // otherwise. |
101 bool OnOriginThread() const { | 101 bool OnOriginThread() const { |
102 return base::PlatformThread::CurrentId() == origin_thread_id_; | 102 return base::PlatformThread::CurrentId() == origin_thread_id_; |
103 } | 103 } |
104 | 104 |
105 // Called by dbus:: when a method is exported. | 105 // Called by dbus:: when a method is exported. |
106 void OnExported(const std::string& interface_name, | 106 void OnExported(const std::string& interface_name, |
107 const std::string& method_name, | 107 const std::string& method_name, |
108 bool success) { | 108 bool success) { |
109 LOG_IF(WARNING, !success) << "Failed to export " | 109 LOG_IF(ERROR, !success) << "Failed to export " << interface_name << "." |
110 << interface_name << "." << method_name; | 110 << method_name; |
111 } | 111 } |
112 | 112 |
113 // Called by dbus:: when the remote device connects to the Media Endpoint. | 113 // Called by dbus:: when the remote device connects to the Media Endpoint. |
114 void SetConfiguration(dbus::MethodCall* method_call, | 114 void SetConfiguration(dbus::MethodCall* method_call, |
115 dbus::ExportedObject::ResponseSender response_sender) { | 115 dbus::ExportedObject::ResponseSender response_sender) { |
| 116 VLOG(1) << "SetConfiuration"; |
| 117 |
116 DCHECK(OnOriginThread()); | 118 DCHECK(OnOriginThread()); |
117 DCHECK(delegate_); | 119 DCHECK(delegate_); |
118 | 120 |
119 dbus::MessageReader reader(method_call); | 121 dbus::MessageReader reader(method_call); |
120 dbus::ObjectPath transport_path; | 122 dbus::ObjectPath transport_path; |
121 dbus::MessageReader property_reader(method_call); | 123 dbus::MessageReader property_reader(method_call); |
122 if (!reader.PopObjectPath(&transport_path) || | 124 if (!reader.PopObjectPath(&transport_path) || |
123 !reader.PopArray(&property_reader)) { | 125 !reader.PopArray(&property_reader)) { |
124 LOG(WARNING) << "SetConfiguration called with incorrect parameters: " | 126 LOG(ERROR) << "SetConfiguration called with incorrect parameters: " |
125 << method_call->ToString(); | 127 << method_call->ToString(); |
126 return; | 128 return; |
127 } | 129 } |
128 | 130 |
129 // Parses |properties| and passes the property set as a | 131 // Parses |properties| and passes the property set as a |
130 // Delegate::TransportProperties structure to |delegate_|. | 132 // Delegate::TransportProperties structure to |delegate_|. |
131 Delegate::TransportProperties properties; | 133 Delegate::TransportProperties properties; |
132 while (property_reader.HasMoreData()) { | 134 while (property_reader.HasMoreData()) { |
133 dbus::MessageReader dict_entry_reader(nullptr); | 135 dbus::MessageReader dict_entry_reader(nullptr); |
134 std::string key; | 136 std::string key; |
135 if (!property_reader.PopDictEntry(&dict_entry_reader) || | 137 if (!property_reader.PopDictEntry(&dict_entry_reader) || |
136 !dict_entry_reader.PopString(&key)) { | 138 !dict_entry_reader.PopString(&key)) { |
137 LOG(WARNING) << "SetConfiguration called with incorrect parameters: " | 139 LOG(ERROR) << "SetConfiguration called with incorrect parameters: " |
138 << method_call->ToString(); | 140 << method_call->ToString(); |
139 } else if (key == BluetoothMediaTransportClient::kDeviceProperty) { | 141 } else if (key == BluetoothMediaTransportClient::kDeviceProperty) { |
140 dict_entry_reader.PopVariantOfObjectPath(&properties.device); | 142 dict_entry_reader.PopVariantOfObjectPath(&properties.device); |
141 } else if (key == BluetoothMediaTransportClient::kUUIDProperty) { | 143 } else if (key == BluetoothMediaTransportClient::kUUIDProperty) { |
142 dict_entry_reader.PopVariantOfString(&properties.uuid); | 144 dict_entry_reader.PopVariantOfString(&properties.uuid); |
143 } else if (key == BluetoothMediaTransportClient::kCodecProperty) { | 145 } else if (key == BluetoothMediaTransportClient::kCodecProperty) { |
144 dict_entry_reader.PopVariantOfByte(&properties.codec); | 146 dict_entry_reader.PopVariantOfByte(&properties.codec); |
145 } else if (key == BluetoothMediaTransportClient::kConfigurationProperty) { | 147 } else if (key == BluetoothMediaTransportClient::kConfigurationProperty) { |
146 dbus::MessageReader variant_reader(nullptr); | 148 dbus::MessageReader variant_reader(nullptr); |
147 const uint8_t* bytes = nullptr; | 149 const uint8_t* bytes = nullptr; |
148 size_t length = 0; | 150 size_t length = 0; |
149 dict_entry_reader.PopVariant(&variant_reader); | 151 dict_entry_reader.PopVariant(&variant_reader); |
150 variant_reader.PopArrayOfBytes(&bytes, &length); | 152 variant_reader.PopArrayOfBytes(&bytes, &length); |
151 properties.configuration.assign(bytes, bytes + length); | 153 properties.configuration.assign(bytes, bytes + length); |
152 } else if (key == BluetoothMediaTransportClient::kStateProperty) { | 154 } else if (key == BluetoothMediaTransportClient::kStateProperty) { |
153 dict_entry_reader.PopVariantOfString(&properties.state); | 155 dict_entry_reader.PopVariantOfString(&properties.state); |
154 } else if (key == BluetoothMediaTransportClient::kDelayProperty) { | 156 } else if (key == BluetoothMediaTransportClient::kDelayProperty) { |
155 properties.delay.reset(new uint16_t()); | 157 properties.delay.reset(new uint16_t()); |
156 dict_entry_reader.PopVariantOfUint16(properties.delay.get()); | 158 dict_entry_reader.PopVariantOfUint16(properties.delay.get()); |
157 } else if (key == BluetoothMediaTransportClient::kVolumeProperty) { | 159 } else if (key == BluetoothMediaTransportClient::kVolumeProperty) { |
158 properties.volume.reset(new uint16_t()); | 160 properties.volume.reset(new uint16_t()); |
159 dict_entry_reader.PopVariantOfUint16(properties.volume.get()); | 161 dict_entry_reader.PopVariantOfUint16(properties.volume.get()); |
160 } | 162 } |
161 } | 163 } |
162 | 164 |
163 if (properties.codec != kInvalidCodec && | 165 if (properties.codec != kInvalidCodec && |
164 properties.state != kInvalidState) { | 166 properties.state != kInvalidState) { |
165 delegate_->SetConfiguration(transport_path, properties); | 167 delegate_->SetConfiguration(transport_path, properties); |
166 } else { | 168 } else { |
167 LOG(WARNING) << "SetConfiguration called with incorrect parameters: " | 169 LOG(ERROR) << "SetConfiguration called with incorrect parameters: " |
168 << method_call->ToString(); | 170 << method_call->ToString(); |
169 } | 171 } |
170 | 172 |
171 response_sender.Run(dbus::Response::FromMethodCall(method_call)); | 173 response_sender.Run(dbus::Response::FromMethodCall(method_call)); |
172 } | 174 } |
173 | 175 |
174 // Called by dbus:: when the remote device receives the configuration for | 176 // Called by dbus:: when the remote device receives the configuration for |
175 // media transport. | 177 // media transport. |
176 void SelectConfiguration( | 178 void SelectConfiguration( |
177 dbus::MethodCall* method_call, | 179 dbus::MethodCall* method_call, |
178 dbus::ExportedObject::ResponseSender response_sender) { | 180 dbus::ExportedObject::ResponseSender response_sender) { |
| 181 VLOG(1) << "SelectConfiguration"; |
| 182 |
179 DCHECK(OnOriginThread()); | 183 DCHECK(OnOriginThread()); |
180 DCHECK(delegate_); | 184 DCHECK(delegate_); |
181 | 185 |
182 dbus::MessageReader reader(method_call); | 186 dbus::MessageReader reader(method_call); |
183 const uint8_t* capabilities = nullptr; | 187 const uint8_t* capabilities = nullptr; |
184 size_t length = 0; | 188 size_t length = 0; |
185 if (!reader.PopArrayOfBytes(&capabilities, &length)) { | 189 if (!reader.PopArrayOfBytes(&capabilities, &length)) { |
186 LOG(WARNING) << "SelectConfiguration called with incorrect parameters: " | 190 LOG(ERROR) << "SelectConfiguration called with incorrect parameters: " |
187 << method_call->ToString(); | 191 << method_call->ToString(); |
188 return; | 192 return; |
189 } | 193 } |
190 | 194 |
191 std::vector<uint8_t> configuration(capabilities, capabilities + length); | 195 std::vector<uint8_t> configuration(capabilities, capabilities + length); |
192 | 196 |
193 // |delegate_| generates the response to |SelectConfiguration| and sends it | 197 // |delegate_| generates the response to |SelectConfiguration| and sends it |
194 // back via |callback|. | 198 // back via |callback|. |
195 Delegate::SelectConfigurationCallback callback = base::Bind( | 199 Delegate::SelectConfigurationCallback callback = base::Bind( |
196 &BluetoothMediaEndpointServiceProviderImpl::OnConfiguration, | 200 &BluetoothMediaEndpointServiceProviderImpl::OnConfiguration, |
197 weak_ptr_factory_.GetWeakPtr(), | 201 weak_ptr_factory_.GetWeakPtr(), |
198 method_call, | 202 method_call, |
199 response_sender); | 203 response_sender); |
200 | 204 |
201 delegate_->SelectConfiguration(configuration, callback); | 205 delegate_->SelectConfiguration(configuration, callback); |
202 } | 206 } |
203 | 207 |
204 // Called by dbus:: when the remote device is about to close the connection. | 208 // Called by dbus:: when the remote device is about to close the connection. |
205 void ClearConfiguration( | 209 void ClearConfiguration( |
206 dbus::MethodCall* method_call, | 210 dbus::MethodCall* method_call, |
207 dbus::ExportedObject::ResponseSender response_sender) { | 211 dbus::ExportedObject::ResponseSender response_sender) { |
| 212 VLOG(1) << "ClearConfiguration"; |
| 213 |
208 DCHECK(OnOriginThread()); | 214 DCHECK(OnOriginThread()); |
209 DCHECK(delegate_); | 215 DCHECK(delegate_); |
210 | 216 |
211 dbus::MessageReader reader(method_call); | 217 dbus::MessageReader reader(method_call); |
212 dbus::ObjectPath transport_path; | 218 dbus::ObjectPath transport_path; |
213 if (!reader.PopObjectPath(&transport_path)) { | 219 if (!reader.PopObjectPath(&transport_path)) { |
214 LOG(WARNING) << "ClearConfiguration called with incorrect parameters: " | 220 LOG(ERROR) << "ClearConfiguration called with incorrect parameters: " |
215 << method_call->ToString(); | 221 << method_call->ToString(); |
216 return; | 222 return; |
217 } | 223 } |
218 | 224 |
219 delegate_->ClearConfiguration(transport_path); | 225 delegate_->ClearConfiguration(transport_path); |
220 | 226 |
221 response_sender.Run(dbus::Response::FromMethodCall(method_call)); | 227 response_sender.Run(dbus::Response::FromMethodCall(method_call)); |
222 } | 228 } |
223 | 229 |
224 // Called by Bluetooth daemon to do the clean up after unregistering the Media | 230 // Called by Bluetooth daemon to do the clean up after unregistering the Media |
225 // Endpoint. | 231 // Endpoint. |
226 void Release(dbus::MethodCall* method_call, | 232 void Release(dbus::MethodCall* method_call, |
227 dbus::ExportedObject::ResponseSender response_sender) { | 233 dbus::ExportedObject::ResponseSender response_sender) { |
| 234 VLOG(1) << "Release"; |
| 235 |
228 DCHECK(OnOriginThread()); | 236 DCHECK(OnOriginThread()); |
229 DCHECK(delegate_); | 237 DCHECK(delegate_); |
230 | 238 |
231 delegate_->Released(); | 239 delegate_->Released(); |
232 | 240 |
233 response_sender.Run(dbus::Response::FromMethodCall(method_call)); | 241 response_sender.Run(dbus::Response::FromMethodCall(method_call)); |
234 } | 242 } |
235 | 243 |
236 // Called by Delegate to response to a method requiring transport | 244 // Called by Delegate to response to a method requiring transport |
237 // configuration. | 245 // configuration. |
238 void OnConfiguration(dbus::MethodCall* method_call, | 246 void OnConfiguration(dbus::MethodCall* method_call, |
239 dbus::ExportedObject::ResponseSender response_sender, | 247 dbus::ExportedObject::ResponseSender response_sender, |
240 const std::vector<uint8_t>& configuration) { | 248 const std::vector<uint8_t>& configuration) { |
| 249 VLOG(1) << "OnConfiguration"; |
| 250 |
241 DCHECK(OnOriginThread()); | 251 DCHECK(OnOriginThread()); |
242 | 252 |
243 // Generates the response to the method call. | 253 // Generates the response to the method call. |
244 scoped_ptr<dbus::Response> response( | 254 scoped_ptr<dbus::Response> response( |
245 dbus::Response::FromMethodCall(method_call)); | 255 dbus::Response::FromMethodCall(method_call)); |
246 dbus::MessageWriter writer(response.get()); | 256 dbus::MessageWriter writer(response.get()); |
247 if (configuration.empty()) { | 257 if (configuration.empty()) { |
248 LOG(WARNING) << "OnConfiguration called with empty configuration."; | 258 LOG(ERROR) << "OnConfiguration called with empty configuration."; |
249 writer.AppendArrayOfBytes(nullptr, 0); | 259 writer.AppendArrayOfBytes(nullptr, 0); |
250 } else { | 260 } else { |
251 writer.AppendArrayOfBytes(&configuration[0], configuration.size()); | 261 writer.AppendArrayOfBytes(&configuration[0], configuration.size()); |
252 } | 262 } |
253 response_sender.Run(response.Pass()); | 263 response_sender.Run(response.Pass()); |
254 } | 264 } |
255 | 265 |
256 // Origin thread (i.e. the UI thread in production). | 266 // Origin thread (i.e. the UI thread in production). |
257 base::PlatformThreadId origin_thread_id_; | 267 base::PlatformThreadId origin_thread_id_; |
258 | 268 |
(...skipping 47 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
306 // Returns a real implementation. | 316 // Returns a real implementation. |
307 if (!DBusThreadManager::Get()->IsUsingStub(DBusClientBundle::BLUETOOTH)) { | 317 if (!DBusThreadManager::Get()->IsUsingStub(DBusClientBundle::BLUETOOTH)) { |
308 return new BluetoothMediaEndpointServiceProviderImpl( | 318 return new BluetoothMediaEndpointServiceProviderImpl( |
309 bus, object_path, delegate); | 319 bus, object_path, delegate); |
310 } | 320 } |
311 // Returns a fake implementation. | 321 // Returns a fake implementation. |
312 return new FakeBluetoothMediaEndpointServiceProvider(object_path, delegate); | 322 return new FakeBluetoothMediaEndpointServiceProvider(object_path, delegate); |
313 } | 323 } |
314 | 324 |
315 } // namespace chromeos | 325 } // namespace chromeos |
OLD | NEW |