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
3 // found in the LICENSE file.
5 #include "chromeos/dbus/fake_bluetooth_media_transport_client.h"
8 #include "chromeos/dbus/bluetooth_media_client.h"
9 #include "chromeos/dbus/dbus_thread_manager.h"
10 #include "chromeos/dbus/fake_bluetooth_media_client.h"
12 using dbus::ObjectPath
;
16 // TODO(mcchou): Remove this constants once it is in cros_system_api.
17 const char kBluetoothMediaTransportInterface
[] = "org.bluez.MediaTransport1";
18 const char kNotImplemented
[] = "org.bluez.NotImplemented";
25 const char FakeBluetoothMediaTransportClient::kTransportPath
[] =
26 "/fake/hci0/dev_00_00_00_00_00_00/fd0";
27 const char FakeBluetoothMediaTransportClient::kTransportDevicePath
[] =
28 "/fake/hci0/dev_00_00_00_00_00_00";
29 const uint8_t FakeBluetoothMediaTransportClient::kTransportCodec
= 0x00;
30 const std::vector
<uint8_t>
31 FakeBluetoothMediaTransportClient::kTransportConfiguration
= {
32 0x21, 0x15, 0x33, 0x2C};
33 const uint16_t FakeBluetoothMediaTransportClient::kTransportDelay
= 5;
34 const uint16_t FakeBluetoothMediaTransportClient::kTransportVolume
= 10;
36 FakeBluetoothMediaTransportClient::Properties::Properties(
37 const PropertyChangedCallback
& callback
)
38 : BluetoothMediaTransportClient::Properties(
40 kBluetoothMediaTransportInterface
,
44 FakeBluetoothMediaTransportClient::Properties::~Properties() {
47 // dbus::PropertySet overrides.
49 void FakeBluetoothMediaTransportClient::Properties::Get(
50 dbus::PropertyBase
* property
,
51 dbus::PropertySet::GetCallback callback
) {
52 VLOG(1) << "Get " << property
->name();
56 void FakeBluetoothMediaTransportClient::Properties::GetAll() {
57 VLOG(1) << "GetAll called.";
60 void FakeBluetoothMediaTransportClient::Properties::Set(
61 dbus::PropertyBase
* property
,
62 dbus::PropertySet::SetCallback callback
) {
63 VLOG(1) << "Set " << property
->name();
67 FakeBluetoothMediaTransportClient::FakeBluetoothMediaTransportClient()
68 : object_path_(ObjectPath(kTransportPath
)) {
69 // TODO(mcchou): Multiple endpoints are sharing one property set for now.
70 // Add property sets accordingly to separate the
71 // MediaTransportPropertiesChanged events for different endpoints.
73 // Sets fake property set with default values.
74 properties_
.reset(new Properties(
75 base::Bind(&FakeBluetoothMediaTransportClient::OnPropertyChanged
,
76 base::Unretained(this))));
77 properties_
->device
.ReplaceValue(ObjectPath(kTransportDevicePath
));
78 properties_
->uuid
.ReplaceValue(BluetoothMediaClient::kBluetoothAudioSinkUUID
);
79 properties_
->codec
.ReplaceValue(kTransportCodec
);
80 properties_
->configuration
.ReplaceValue(kTransportConfiguration
);
81 properties_
->state
.ReplaceValue(BluetoothMediaTransportClient::kStateIdle
);
82 properties_
->delay
.ReplaceValue(kTransportDelay
);
83 properties_
->volume
.ReplaceValue(kTransportVolume
);
86 FakeBluetoothMediaTransportClient::~FakeBluetoothMediaTransportClient() {
89 // DBusClient override.
90 void FakeBluetoothMediaTransportClient::Init(dbus::Bus
* bus
) {
93 // BluetoothMediaTransportClient overrides.
95 void FakeBluetoothMediaTransportClient::AddObserver(
96 BluetoothMediaTransportClient::Observer
* observer
) {
97 observers_
.AddObserver(observer
);
100 void FakeBluetoothMediaTransportClient::RemoveObserver(
101 BluetoothMediaTransportClient::Observer
* observer
) {
102 observers_
.RemoveObserver(observer
);
105 FakeBluetoothMediaTransportClient::Properties
*
106 FakeBluetoothMediaTransportClient::GetProperties(
107 const ObjectPath
& object_path
) {
111 void FakeBluetoothMediaTransportClient::Acquire(
112 const ObjectPath
& object_path
,
113 const AcquireCallback
& callback
,
114 const ErrorCallback
& error_callback
) {
115 error_callback
.Run(kNotImplemented
, "");
118 void FakeBluetoothMediaTransportClient::TryAcquire(
119 const ObjectPath
& object_path
,
120 const AcquireCallback
& callback
,
121 const ErrorCallback
& error_callback
) {
122 error_callback
.Run(kNotImplemented
, "");
125 void FakeBluetoothMediaTransportClient::Release(
126 const ObjectPath
& object_path
,
127 const base::Closure
& callback
,
128 const ErrorCallback
& error_callback
) {
129 error_callback
.Run(kNotImplemented
, "");
132 void FakeBluetoothMediaTransportClient::SetValid(
133 const ObjectPath
& endpoint_path
,
136 endpoints_
[endpoint_path
] = valid
;
139 endpoints_
.erase(endpoint_path
);
141 // TODO(mcchou): Since there is only one transport path, all observers will
142 // be notified. Shades irrelevant observers.
144 // Notifies observers about the state change of the transport.
145 FOR_EACH_OBSERVER(BluetoothMediaTransportClient::Observer
, observers_
,
146 MediaTransportRemoved(object_path_
));
149 void FakeBluetoothMediaTransportClient::OnPropertyChanged(
150 const std::string
& property_name
) {
151 VLOG(1) << "Property " << property_name
<< " changed";
154 } // namespace chromeos