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

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: 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
32 } // namespace 31 } // namespace
33 32
34 namespace chromeos { 33 namespace chromeos {
35 34
36 // The BluetoothMediaEndopintServiceProvider implementation used in production. 35 // The BluetoothMediaEndopintServiceProvider implementation used in production.
(...skipping 74 matching lines...) Expand 10 before | Expand all | Expand 10 after
111 } 110 }
112 111
113 // Called by dbus:: when the remote device connects to the Media Endpoint. 112 // Called by dbus:: when the remote device connects to the Media Endpoint.
114 void SetConfiguration(dbus::MethodCall* method_call, 113 void SetConfiguration(dbus::MethodCall* method_call,
115 dbus::ExportedObject::ResponseSender response_sender) { 114 dbus::ExportedObject::ResponseSender response_sender) {
116 DCHECK(OnOriginThread()); 115 DCHECK(OnOriginThread());
117 DCHECK(delegate_); 116 DCHECK(delegate_);
118 117
119 dbus::MessageReader reader(method_call); 118 dbus::MessageReader reader(method_call);
120 dbus::ObjectPath transport_path; 119 dbus::ObjectPath transport_path;
121 dbus::MessageReader properties(method_call); 120 dbus::MessageReader property_reader(method_call);
122 if (!reader.PopObjectPath(&transport_path) || 121 if (!reader.PopObjectPath(&transport_path) ||
123 !reader.PopArray(&properties)) { 122 !reader.PopArray(&property_reader)) {
124 LOG(WARNING) << "SetConfiguration called with incorrect parameters: " 123 LOG(WARNING) << "SetConfiguration called with incorrect parameters: "
125 << method_call->ToString(); 124 << method_call->ToString();
126 return; 125 return;
127 } 126 }
128 127
128 // Parses |properties| and passes the property set as a
129 // Delegate::TransportProperties structure to |delegate_|.
armansito 2015/02/10 00:17:01 Some of the properties below are mandatory and som
Miao 2015/02/10 22:15:21 Done.
130 Delegate::TransportProperties properties;
131 while (property_reader.HasMoreData()) {
132 dbus::MessageReader dict_entry_reader(nullptr);
133 std::string key;
134 if (!property_reader.PopDictEntry(&dict_entry_reader) ||
135 !dict_entry_reader.PopString(&key)) {
136 LOG(WARNING) << "SetConfiguration called with incorrect parameters: "
137 << method_call->ToString();
138 } else {
armansito 2015/02/10 00:17:01 nit: you can just continue with "else-if" here ins
Miao 2015/02/10 22:15:21 Done.
139 if (key == BluetoothMediaTransportClient::kDeviceProperty) {
140 dict_entry_reader.PopVariantOfObjectPath(&properties.device);
141 } else if (key == BluetoothMediaTransportClient::kUUIDProperty) {
142 dict_entry_reader.PopVariantOfString(&properties.uuid);
143 } else if (key == BluetoothMediaTransportClient::kCodecProperty) {
144 dict_entry_reader.PopVariantOfByte(&properties.codec);
145 } else if (key ==
146 BluetoothMediaTransportClient::kConfigurationProperty) {
147 dbus::MessageReader variant_reader(nullptr);
148 const uint8_t* bytes = nullptr;
149 size_t length = 0;
150 dict_entry_reader.PopVariant(&variant_reader);
151 variant_reader.PopArrayOfBytes(&bytes, &length);
152 properties.configuration =
153 std::vector<uint8_t>(bytes, bytes + length);
154 } else if (key == BluetoothMediaTransportClient::kStateProperty) {
155 dict_entry_reader.PopVariantOfString(&properties.state);
156 } else if (key == BluetoothMediaTransportClient::kDelayProperty) {
157 dict_entry_reader.PopVariantOfUint16(properties.delay.get());
armansito 2015/02/10 00:17:01 These two won't work! You're passing a NULL pointe
Miao 2015/02/10 22:15:21 Done.
158 } else if (key == BluetoothMediaTransportClient::kVolumeProperty) {
159 dict_entry_reader.PopVariantOfUint16(properties.volume.get());
160 }
161 }
162 }
163
129 delegate_->SetConfiguration(transport_path, properties); 164 delegate_->SetConfiguration(transport_path, properties);
130 165
131 response_sender.Run(dbus::Response::FromMethodCall(method_call)); 166 response_sender.Run(dbus::Response::FromMethodCall(method_call));
132 } 167 }
133 168
134 // Called by dbus:: when the remote device receives the configuration for 169 // Called by dbus:: when the remote device receives the configuration for
135 // media transport. 170 // media transport.
136 void SelectConfiguration( 171 void SelectConfiguration(
137 dbus::MethodCall* method_call, 172 dbus::MethodCall* method_call,
138 dbus::ExportedObject::ResponseSender response_sender) { 173 dbus::ExportedObject::ResponseSender response_sender) {
(...skipping 42 matching lines...) Expand 10 before | Expand all | Expand 10 after
181 response_sender.Run(dbus::Response::FromMethodCall(method_call)); 216 response_sender.Run(dbus::Response::FromMethodCall(method_call));
182 } 217 }
183 218
184 // Called by Bluetooth daemon to do the clean up after unregistering the Media 219 // Called by Bluetooth daemon to do the clean up after unregistering the Media
185 // Endpoint. 220 // Endpoint.
186 void Release(dbus::MethodCall* method_call, 221 void Release(dbus::MethodCall* method_call,
187 dbus::ExportedObject::ResponseSender response_sender) { 222 dbus::ExportedObject::ResponseSender response_sender) {
188 DCHECK(OnOriginThread()); 223 DCHECK(OnOriginThread());
189 DCHECK(delegate_); 224 DCHECK(delegate_);
190 225
191 delegate_->Release(); 226 delegate_->Released();
192 227
193 response_sender.Run(dbus::Response::FromMethodCall(method_call)); 228 response_sender.Run(dbus::Response::FromMethodCall(method_call));
194 } 229 }
195 230
196 // Called by Delegate to response to a method requiring transport 231 // Called by Delegate to response to a method requiring transport
197 // configuration. 232 // configuration.
198 void OnConfiguration(dbus::MethodCall* method_call, 233 void OnConfiguration(dbus::MethodCall* method_call,
199 dbus::ExportedObject::ResponseSender response_sender, 234 dbus::ExportedObject::ResponseSender response_sender,
200 const std::vector<uint8_t>& configuration) { 235 const std::vector<uint8_t>& configuration) {
201 DCHECK(OnOriginThread()); 236 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 269 // Weak pointer factory for generating 'this' printers that might live longer
235 // than we do. 270 // than we do.
236 // Note This should remain the last member so it'll be destroyed and 271 // 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. 272 // invalidate it's weak pointers before any other members are destroyed.
238 base::WeakPtrFactory<BluetoothMediaEndpointServiceProviderImpl> 273 base::WeakPtrFactory<BluetoothMediaEndpointServiceProviderImpl>
239 weak_ptr_factory_; 274 weak_ptr_factory_;
240 275
241 DISALLOW_COPY_AND_ASSIGN(BluetoothMediaEndpointServiceProviderImpl); 276 DISALLOW_COPY_AND_ASSIGN(BluetoothMediaEndpointServiceProviderImpl);
242 }; 277 };
243 278
279 BluetoothMediaEndpointServiceProvider::Delegate::TransportProperties::
280 TransportProperties() : delay(nullptr), volume(nullptr) {
armansito 2015/02/10 00:17:01 You should assign a default value for codec and st
Miao 2015/02/10 22:15:21 Done. These default value can be used to check whe
281 }
282
283 BluetoothMediaEndpointServiceProvider::Delegate::TransportProperties::
284 ~TransportProperties() {
285 }
286
244 BluetoothMediaEndpointServiceProvider::BluetoothMediaEndpointServiceProvider() { 287 BluetoothMediaEndpointServiceProvider::BluetoothMediaEndpointServiceProvider() {
245 } 288 }
246 289
247 BluetoothMediaEndpointServiceProvider::~BluetoothMediaEndpointServiceProvider() 290 BluetoothMediaEndpointServiceProvider::
248 {} 291 ~BluetoothMediaEndpointServiceProvider() {
292 }
249 293
250 BluetoothMediaEndpointServiceProvider* 294 BluetoothMediaEndpointServiceProvider*
251 BluetoothMediaEndpointServiceProvider::Create( 295 BluetoothMediaEndpointServiceProvider::Create(
252 dbus::Bus* bus, 296 dbus::Bus* bus,
253 const dbus::ObjectPath& object_path, 297 const dbus::ObjectPath& object_path,
254 Delegate* delegate) { 298 Delegate* delegate) {
255 // Returns a real implementation. 299 // Returns a real implementation.
256 if (!DBusThreadManager::Get()->IsUsingStub(DBusClientBundle::BLUETOOTH)) { 300 if (!DBusThreadManager::Get()->IsUsingStub(DBusClientBundle::BLUETOOTH)) {
257 return new BluetoothMediaEndpointServiceProviderImpl( 301 return new BluetoothMediaEndpointServiceProviderImpl(
258 bus, object_path, delegate); 302 bus, object_path, delegate);
259 } 303 }
260 // Returns a fake implementation. 304 // Returns a fake implementation.
261 return new FakeBluetoothMediaEndpointServiceProvider(object_path, delegate); 305 return new FakeBluetoothMediaEndpointServiceProvider(object_path, delegate);
262 } 306 }
263 307
264 } // namespace chromeos 308 } // namespace chromeos
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698