Chromium Code Reviews| Index: chromeos/dbus/bluetooth_media_endpoint_service_provider.cc |
| diff --git a/chromeos/dbus/bluetooth_media_endpoint_service_provider.cc b/chromeos/dbus/bluetooth_media_endpoint_service_provider.cc |
| index 6a2de74643d084b8057a91a686d397f5b599cb2d..79ede94bce6a98c5eef4f12e9a86e0298e5b7968 100644 |
| --- a/chromeos/dbus/bluetooth_media_endpoint_service_provider.cc |
| +++ b/chromeos/dbus/bluetooth_media_endpoint_service_provider.cc |
| @@ -4,13 +4,12 @@ |
| #include "chromeos/dbus/bluetooth_media_endpoint_service_provider.h" |
| -#include <string> |
| - |
| #include "base/bind.h" |
| #include "base/logging.h" |
| #include "base/memory/ref_counted.h" |
| #include "base/memory/scoped_ptr.h" |
| #include "base/threading/platform_thread.h" |
| +#include "chromeos/dbus/bluetooth_media_transport_client.h" |
| #include "chromeos/dbus/dbus_thread_manager.h" |
| #include "chromeos/dbus/fake_bluetooth_media_endpoint_service_provider.h" |
| #include "dbus/bus.h" |
| @@ -23,12 +22,15 @@ namespace { |
| // Bluetooth Media Endpoint service identifier. |
| const char kBluetoothMediaEndpointInterface[] = "org.bluez.MediaEndpoint1"; |
| -// Bluetooth Media Endpoint methods. |
| +// Method names in Bluetooth Media Endpoint interface. |
| const char kSetConfiguration[] = "SetConfiguration"; |
| const char kSelectConfiguration[] = "SelectConfiguration"; |
| const char kClearConfiguration[] = "ClearConfiguration"; |
| const char kRelease[] = "Release"; |
| +const uint8_t kInvalidCodec = 0xff; |
| +const char kInvalidState[] = "unknown"; |
|
armansito
2015/02/12 05:20:44
I would move these two to the header as static cla
Miao
2015/02/12 19:08:03
In SetConfiguration, we compare the values of stat
|
| + |
| } // namespace |
| namespace chromeos { |
| @@ -118,15 +120,52 @@ class CHROMEOS_EXPORT BluetoothMediaEndpointServiceProviderImpl |
| dbus::MessageReader reader(method_call); |
| dbus::ObjectPath transport_path; |
| - dbus::MessageReader properties(method_call); |
| + dbus::MessageReader property_reader(method_call); |
| if (!reader.PopObjectPath(&transport_path) || |
| - !reader.PopArray(&properties)) { |
| + !reader.PopArray(&property_reader)) { |
| LOG(WARNING) << "SetConfiguration called with incorrect parameters: " |
| << method_call->ToString(); |
| return; |
| } |
| - delegate_->SetConfiguration(transport_path, properties); |
| + // Parses |properties| and passes the property set as a |
| + // Delegate::TransportProperties structure to |delegate_|. |
| + Delegate::TransportProperties properties; |
| + while (property_reader.HasMoreData()) { |
| + dbus::MessageReader dict_entry_reader(nullptr); |
| + std::string key; |
| + if (!property_reader.PopDictEntry(&dict_entry_reader) || |
| + !dict_entry_reader.PopString(&key)) { |
| + LOG(WARNING) << "SetConfiguration called with incorrect parameters: " |
| + << method_call->ToString(); |
| + } else if (key == BluetoothMediaTransportClient::kDeviceProperty) { |
| + dict_entry_reader.PopVariantOfObjectPath(&properties.device); |
| + } else if (key == BluetoothMediaTransportClient::kUUIDProperty) { |
| + dict_entry_reader.PopVariantOfString(&properties.uuid); |
| + } else if (key == BluetoothMediaTransportClient::kCodecProperty) { |
| + dict_entry_reader.PopVariantOfByte(&properties.codec); |
| + } else if (key == BluetoothMediaTransportClient::kConfigurationProperty) { |
| + dbus::MessageReader variant_reader(nullptr); |
| + const uint8_t* bytes = nullptr; |
| + size_t length = 0; |
| + dict_entry_reader.PopVariant(&variant_reader); |
| + variant_reader.PopArrayOfBytes(&bytes, &length); |
| + properties.configuration.assign(bytes, bytes + length); |
| + } else if (key == BluetoothMediaTransportClient::kStateProperty) { |
| + dict_entry_reader.PopVariantOfString(&properties.state); |
| + } else if (key == BluetoothMediaTransportClient::kDelayProperty) { |
| + properties.delay.reset(new uint16_t()); |
| + dict_entry_reader.PopVariantOfUint16(properties.delay.get()); |
| + } else if (key == BluetoothMediaTransportClient::kVolumeProperty) { |
| + properties.volume.reset(new uint16_t()); |
| + dict_entry_reader.PopVariantOfUint16(properties.volume.get()); |
| + } |
| + } |
| + |
| + if (properties.codec != kInvalidCodec && |
| + properties.state != kInvalidState) { |
|
armansito
2015/02/12 05:20:44
nit: You should log something here in the case of
Miao
2015/02/12 19:08:03
Done.
|
| + delegate_->SetConfiguration(transport_path, properties); |
| + } |
| response_sender.Run(dbus::Response::FromMethodCall(method_call)); |
|
armansito
2015/02/12 05:20:44
I thought this method had no response?
Miao
2015/02/12 19:08:03
It is an empty response, just like the response of
|
| } |
| @@ -188,7 +227,7 @@ class CHROMEOS_EXPORT BluetoothMediaEndpointServiceProviderImpl |
| DCHECK(OnOriginThread()); |
| DCHECK(delegate_); |
| - delegate_->Release(); |
| + delegate_->Released(); |
| response_sender.Run(dbus::Response::FromMethodCall(method_call)); |
| } |
| @@ -241,11 +280,22 @@ class CHROMEOS_EXPORT BluetoothMediaEndpointServiceProviderImpl |
| DISALLOW_COPY_AND_ASSIGN(BluetoothMediaEndpointServiceProviderImpl); |
| }; |
| +BluetoothMediaEndpointServiceProvider::Delegate::TransportProperties:: |
| + TransportProperties() |
| + : codec(kInvalidCodec), |
| + state(kInvalidState) { |
| +} |
| + |
| +BluetoothMediaEndpointServiceProvider::Delegate::TransportProperties:: |
| + ~TransportProperties() { |
| +} |
| + |
| BluetoothMediaEndpointServiceProvider::BluetoothMediaEndpointServiceProvider() { |
| } |
| -BluetoothMediaEndpointServiceProvider::~BluetoothMediaEndpointServiceProvider() |
| -{} |
| +BluetoothMediaEndpointServiceProvider:: |
| + ~BluetoothMediaEndpointServiceProvider() { |
| +} |
| BluetoothMediaEndpointServiceProvider* |
| BluetoothMediaEndpointServiceProvider::Create( |