Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(141)

Side by Side Diff: chromeos/dbus/bluetooth_media_endpoint_service_provider.cc

Issue 910023002: device/bluetooth:Implement BluetoothMediaEndpointServiceProvider delegate and media-related overrid… (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Removed SetVisible from FakeBluetoothMediaEndpointServiceProvider and fixed nits. Created 5 years, 10 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
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 <string>
8
9 #include "base/bind.h" 7 #include "base/bind.h"
10 #include "base/logging.h" 8 #include "base/logging.h"
11 #include "base/memory/ref_counted.h" 9 #include "base/memory/ref_counted.h"
12 #include "base/memory/scoped_ptr.h" 10 #include "base/memory/scoped_ptr.h"
13 #include "base/threading/platform_thread.h" 11 #include "base/threading/platform_thread.h"
12 #include "chromeos/dbus/bluetooth_media_transport_client.h"
14 #include "chromeos/dbus/dbus_thread_manager.h" 13 #include "chromeos/dbus/dbus_thread_manager.h"
15 #include "chromeos/dbus/fake_bluetooth_media_endpoint_service_provider.h" 14 #include "chromeos/dbus/fake_bluetooth_media_endpoint_service_provider.h"
16 #include "dbus/bus.h" 15 #include "dbus/bus.h"
17 #include "dbus/exported_object.h" 16 #include "dbus/exported_object.h"
18 #include "dbus/message.h" 17 #include "dbus/message.h"
19 18
20 namespace { 19 namespace {
21 20
22 // TODO(mcchou): Move these constants to dbus/service_constants.h. 21 // TODO(mcchou): Move these constants to dbus/service_constants.h.
23 // Bluetooth Media Endpoint service identifier. 22 // Bluetooth Media Endpoint service identifier.
24 const char kBluetoothMediaEndpointInterface[] = "org.bluez.MediaEndpoint1"; 23 const char kBluetoothMediaEndpointInterface[] = "org.bluez.MediaEndpoint1";
25 24
26 // Bluetooth Media Endpoint methods. 25 // Method names in Bluetooth Media Endpoint interface.
27 const char kSetConfiguration[] = "SetConfiguration"; 26 const char kSetConfiguration[] = "SetConfiguration";
28 const char kSelectConfiguration[] = "SelectConfiguration"; 27 const char kSelectConfiguration[] = "SelectConfiguration";
29 const char kClearConfiguration[] = "ClearConfiguration"; 28 const char kClearConfiguration[] = "ClearConfiguration";
30 const char kRelease[] = "Release"; 29 const char kRelease[] = "Release";
31 30
31 const uint8_t kInvalidCodec = 0xff;
32 const char kInvalidState[] = "unknown";
33
32 } // namespace 34 } // namespace
33 35
34 namespace chromeos { 36 namespace chromeos {
35 37
36 // The BluetoothMediaEndopintServiceProvider implementation used in production. 38 // The BluetoothMediaEndopintServiceProvider implementation used in production.
37 class CHROMEOS_EXPORT BluetoothMediaEndpointServiceProviderImpl 39 class CHROMEOS_EXPORT BluetoothMediaEndpointServiceProviderImpl
38 : public BluetoothMediaEndpointServiceProvider { 40 : public BluetoothMediaEndpointServiceProvider {
39 public: 41 public:
40 BluetoothMediaEndpointServiceProviderImpl(dbus::Bus* bus, 42 BluetoothMediaEndpointServiceProviderImpl(dbus::Bus* bus,
41 const dbus::ObjectPath& object_path, 43 const dbus::ObjectPath& object_path,
(...skipping 69 matching lines...) Expand 10 before | Expand all | Expand 10 after
111 } 113 }
112 114
113 // Called by dbus:: when the remote device connects to the Media Endpoint. 115 // Called by dbus:: when the remote device connects to the Media Endpoint.
114 void SetConfiguration(dbus::MethodCall* method_call, 116 void SetConfiguration(dbus::MethodCall* method_call,
115 dbus::ExportedObject::ResponseSender response_sender) { 117 dbus::ExportedObject::ResponseSender response_sender) {
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 properties(method_call); 123 dbus::MessageReader property_reader(method_call);
122 if (!reader.PopObjectPath(&transport_path) || 124 if (!reader.PopObjectPath(&transport_path) ||
123 !reader.PopArray(&properties)) { 125 !reader.PopArray(&property_reader)) {
124 LOG(WARNING) << "SetConfiguration called with incorrect parameters: " 126 LOG(WARNING) << "SetConfiguration called with incorrect parameters: "
125 << method_call->ToString(); 127 << method_call->ToString();
126 return; 128 return;
127 } 129 }
128 130
129 delegate_->SetConfiguration(transport_path, properties); 131 // Parses |properties| and passes the property set as a
132 // Delegate::TransportProperties structure to |delegate_|.
133 Delegate::TransportProperties properties;
134 while (property_reader.HasMoreData()) {
135 dbus::MessageReader dict_entry_reader(nullptr);
136 std::string key;
137 if (!property_reader.PopDictEntry(&dict_entry_reader) ||
138 !dict_entry_reader.PopString(&key)) {
139 LOG(WARNING) << "SetConfiguration called with incorrect parameters: "
140 << method_call->ToString();
141 } else if (key == BluetoothMediaTransportClient::kDeviceProperty) {
142 dict_entry_reader.PopVariantOfObjectPath(&properties.device);
143 } else if (key == BluetoothMediaTransportClient::kUUIDProperty) {
144 dict_entry_reader.PopVariantOfString(&properties.uuid);
145 } else if (key == BluetoothMediaTransportClient::kCodecProperty) {
146 dict_entry_reader.PopVariantOfByte(&properties.codec);
147 } else if (key == BluetoothMediaTransportClient::kConfigurationProperty) {
148 dbus::MessageReader variant_reader(nullptr);
149 const uint8_t* bytes = nullptr;
150 size_t length = 0;
151 dict_entry_reader.PopVariant(&variant_reader);
152 variant_reader.PopArrayOfBytes(&bytes, &length);
153 properties.configuration = std::vector<uint8_t>(bytes, bytes + length);
Ben Chan 2015/02/11 20:36:23 perhaps simply: properties.configuration.assign
Miao 2015/02/11 23:17:17 Done.
154 } else if (key == BluetoothMediaTransportClient::kStateProperty) {
155 dict_entry_reader.PopVariantOfString(&properties.state);
156 } else if (key == BluetoothMediaTransportClient::kDelayProperty) {
157 properties.delay.reset(new uint16_t());
158 dict_entry_reader.PopVariantOfUint16(properties.delay.get());
159 } else if (key == BluetoothMediaTransportClient::kVolumeProperty) {
160 properties.volume.reset(new uint16_t());
161 dict_entry_reader.PopVariantOfUint16(properties.volume.get());
162 }
163 }
164
165 if (properties.codec != kInvalidCodec &&
166 properties.state.compare(kInvalidState) != 0) {
Ben Chan 2015/02/11 20:36:23 perhaps simply (string implements operator != (con
Miao 2015/02/11 23:17:17 Done.
167 delegate_->SetConfiguration(transport_path, properties);
168 }
130 169
131 response_sender.Run(dbus::Response::FromMethodCall(method_call)); 170 response_sender.Run(dbus::Response::FromMethodCall(method_call));
132 } 171 }
133 172
134 // Called by dbus:: when the remote device receives the configuration for 173 // Called by dbus:: when the remote device receives the configuration for
135 // media transport. 174 // media transport.
136 void SelectConfiguration( 175 void SelectConfiguration(
137 dbus::MethodCall* method_call, 176 dbus::MethodCall* method_call,
138 dbus::ExportedObject::ResponseSender response_sender) { 177 dbus::ExportedObject::ResponseSender response_sender) {
139 DCHECK(OnOriginThread()); 178 DCHECK(OnOriginThread());
(...skipping 41 matching lines...) Expand 10 before | Expand all | Expand 10 after
181 response_sender.Run(dbus::Response::FromMethodCall(method_call)); 220 response_sender.Run(dbus::Response::FromMethodCall(method_call));
182 } 221 }
183 222
184 // Called by Bluetooth daemon to do the clean up after unregistering the Media 223 // Called by Bluetooth daemon to do the clean up after unregistering the Media
185 // Endpoint. 224 // Endpoint.
186 void Release(dbus::MethodCall* method_call, 225 void Release(dbus::MethodCall* method_call,
187 dbus::ExportedObject::ResponseSender response_sender) { 226 dbus::ExportedObject::ResponseSender response_sender) {
188 DCHECK(OnOriginThread()); 227 DCHECK(OnOriginThread());
189 DCHECK(delegate_); 228 DCHECK(delegate_);
190 229
191 delegate_->Release(); 230 delegate_->Released();
192 231
193 response_sender.Run(dbus::Response::FromMethodCall(method_call)); 232 response_sender.Run(dbus::Response::FromMethodCall(method_call));
194 } 233 }
195 234
196 // Called by Delegate to response to a method requiring transport 235 // Called by Delegate to response to a method requiring transport
197 // configuration. 236 // configuration.
198 void OnConfiguration(dbus::MethodCall* method_call, 237 void OnConfiguration(dbus::MethodCall* method_call,
199 dbus::ExportedObject::ResponseSender response_sender, 238 dbus::ExportedObject::ResponseSender response_sender,
200 const std::vector<uint8_t>& configuration) { 239 const std::vector<uint8_t>& configuration) {
201 DCHECK(OnOriginThread()); 240 DCHECK(OnOriginThread());
(...skipping 32 matching lines...) Expand 10 before | Expand all | Expand 10 after
234 // Weak pointer factory for generating 'this' printers that might live longer 273 // Weak pointer factory for generating 'this' printers that might live longer
235 // than we do. 274 // than we do.
236 // Note This should remain the last member so it'll be destroyed and 275 // Note This should remain the last member so it'll be destroyed and
237 // invalidate it's weak pointers before any other members are destroyed. 276 // invalidate it's weak pointers before any other members are destroyed.
238 base::WeakPtrFactory<BluetoothMediaEndpointServiceProviderImpl> 277 base::WeakPtrFactory<BluetoothMediaEndpointServiceProviderImpl>
239 weak_ptr_factory_; 278 weak_ptr_factory_;
240 279
241 DISALLOW_COPY_AND_ASSIGN(BluetoothMediaEndpointServiceProviderImpl); 280 DISALLOW_COPY_AND_ASSIGN(BluetoothMediaEndpointServiceProviderImpl);
242 }; 281 };
243 282
283 BluetoothMediaEndpointServiceProvider::Delegate::TransportProperties::
284 TransportProperties()
285 : codec(kInvalidCodec),
286 state(kInvalidState),
287 delay(nullptr),
Ben Chan 2015/02/11 20:36:23 scoped_ptr is default constructed to nullptr, so t
Miao 2015/02/11 23:17:17 Removed, and also removed those in bluetooth_audio
288 volume(nullptr) {
289 }
290
291 BluetoothMediaEndpointServiceProvider::Delegate::TransportProperties::
292 ~TransportProperties() {
293 }
294
244 BluetoothMediaEndpointServiceProvider::BluetoothMediaEndpointServiceProvider() { 295 BluetoothMediaEndpointServiceProvider::BluetoothMediaEndpointServiceProvider() {
245 } 296 }
246 297
247 BluetoothMediaEndpointServiceProvider::~BluetoothMediaEndpointServiceProvider() 298 BluetoothMediaEndpointServiceProvider::
248 {} 299 ~BluetoothMediaEndpointServiceProvider() {
300 }
249 301
250 BluetoothMediaEndpointServiceProvider* 302 BluetoothMediaEndpointServiceProvider*
251 BluetoothMediaEndpointServiceProvider::Create( 303 BluetoothMediaEndpointServiceProvider::Create(
252 dbus::Bus* bus, 304 dbus::Bus* bus,
253 const dbus::ObjectPath& object_path, 305 const dbus::ObjectPath& object_path,
254 Delegate* delegate) { 306 Delegate* delegate) {
255 // Returns a real implementation. 307 // Returns a real implementation.
256 if (!DBusThreadManager::Get()->IsUsingStub(DBusClientBundle::BLUETOOTH)) { 308 if (!DBusThreadManager::Get()->IsUsingStub(DBusClientBundle::BLUETOOTH)) {
257 return new BluetoothMediaEndpointServiceProviderImpl( 309 return new BluetoothMediaEndpointServiceProviderImpl(
258 bus, object_path, delegate); 310 bus, object_path, delegate);
259 } 311 }
260 // Returns a fake implementation. 312 // Returns a fake implementation.
261 return new FakeBluetoothMediaEndpointServiceProvider(object_path, delegate); 313 return new FakeBluetoothMediaEndpointServiceProvider(object_path, delegate);
262 } 314 }
263 315
264 } // namespace chromeos 316 } // namespace chromeos
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698