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

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

Issue 939753004: device/bluetooth: Implement Unregister() of BlueotoothAudioSinkChromeOS and disconnection-related c… (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Defined Transport structure, added two setters for state/volume, and modified GetProperties(). 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/fake_bluetooth_media_transport_client.h" 5 #include "chromeos/dbus/fake_bluetooth_media_transport_client.h"
6 6
7 #include <sstream>
8
7 #include "base/bind.h" 9 #include "base/bind.h"
10 #include "base/stl_util.h"
8 #include "chromeos/dbus/bluetooth_media_client.h" 11 #include "chromeos/dbus/bluetooth_media_client.h"
9 #include "chromeos/dbus/dbus_thread_manager.h" 12 #include "chromeos/dbus/dbus_thread_manager.h"
13 #include "chromeos/dbus/fake_bluetooth_adapter_client.h"
10 #include "chromeos/dbus/fake_bluetooth_media_client.h" 14 #include "chromeos/dbus/fake_bluetooth_media_client.h"
15 #include "chromeos/dbus/fake_bluetooth_media_endpoint_service_provider.h"
11 16
12 using dbus::ObjectPath; 17 using dbus::ObjectPath;
13 18
14 namespace { 19 namespace {
15 20
16 // TODO(mcchou): Remove this constants once it is in cros_system_api. 21 // TODO(mcchou): Remove this constants once it is in cros_system_api.
17 const char kBluetoothMediaTransportInterface[] = "org.bluez.MediaTransport1"; 22 const char kBluetoothMediaTransportInterface[] = "org.bluez.MediaTransport1";
18 const char kNotImplemented[] = "org.bluez.NotImplemented"; 23 const char kNotImplemented[] = "org.bluez.NotImplemented";
19 24
25 ObjectPath GenerateTransportPath() {
26 static unsigned int sequence_number = 0;
27 ++sequence_number;
28 std::stringstream path;
29 path << chromeos::FakeBluetoothAdapterClient::kAdapterPath
30 << chromeos::FakeBluetoothMediaTransportClient::kTransportDevicePath
31 << "/fd" << sequence_number;
32 return ObjectPath(path.str());
33 }
34
20 } // namespace 35 } // namespace
21 36
22 namespace chromeos { 37 namespace chromeos {
23 38
24 // static 39 // static
25 const char FakeBluetoothMediaTransportClient::kTransportPath[] =
26 "/fake/hci0/dev_00_00_00_00_00_00/fd0";
27 const char FakeBluetoothMediaTransportClient::kTransportDevicePath[] = 40 const char FakeBluetoothMediaTransportClient::kTransportDevicePath[] =
28 "/fake/hci0/dev_00_00_00_00_00_00"; 41 "/fake_audio_source";
29 const uint8_t FakeBluetoothMediaTransportClient::kTransportCodec = 0x00; 42 const uint8_t FakeBluetoothMediaTransportClient::kTransportCodec = 0x00;
30 const std::vector<uint8_t> 43 const std::vector<uint8_t>
31 FakeBluetoothMediaTransportClient::kTransportConfiguration = { 44 FakeBluetoothMediaTransportClient::kTransportConfiguration = {
32 0x21, 0x15, 0x33, 0x2C}; 45 0x21, 0x15, 0x33, 0x2C};
33 const uint16_t FakeBluetoothMediaTransportClient::kTransportDelay = 5; 46 const uint16_t FakeBluetoothMediaTransportClient::kTransportDelay = 5;
34 const uint16_t FakeBluetoothMediaTransportClient::kTransportVolume = 10; 47 const uint16_t FakeBluetoothMediaTransportClient::kTransportVolume = 50;
35 48
36 FakeBluetoothMediaTransportClient::Properties::Properties( 49 FakeBluetoothMediaTransportClient::Properties::Properties(
37 const PropertyChangedCallback& callback) 50 const PropertyChangedCallback& callback)
38 : BluetoothMediaTransportClient::Properties( 51 : BluetoothMediaTransportClient::Properties(
39 nullptr, 52 nullptr,
40 kBluetoothMediaTransportInterface, 53 kBluetoothMediaTransportInterface,
41 callback) { 54 callback) {
42 } 55 }
43 56
44 FakeBluetoothMediaTransportClient::Properties::~Properties() { 57 FakeBluetoothMediaTransportClient::Properties::~Properties() {
45 } 58 }
46 59
47 // dbus::PropertySet overrides.
48
49 void FakeBluetoothMediaTransportClient::Properties::Get( 60 void FakeBluetoothMediaTransportClient::Properties::Get(
50 dbus::PropertyBase* property, 61 dbus::PropertyBase* property,
51 dbus::PropertySet::GetCallback callback) { 62 dbus::PropertySet::GetCallback callback) {
52 VLOG(1) << "Get " << property->name(); 63 VLOG(1) << "Get " << property->name();
53 callback.Run(false); 64 callback.Run(false);
54 } 65 }
55 66
56 void FakeBluetoothMediaTransportClient::Properties::GetAll() { 67 void FakeBluetoothMediaTransportClient::Properties::GetAll() {
57 VLOG(1) << "GetAll called."; 68 VLOG(1) << "GetAll called.";
58 } 69 }
59 70
60 void FakeBluetoothMediaTransportClient::Properties::Set( 71 void FakeBluetoothMediaTransportClient::Properties::Set(
61 dbus::PropertyBase* property, 72 dbus::PropertyBase* property,
62 dbus::PropertySet::SetCallback callback) { 73 dbus::PropertySet::SetCallback callback) {
63 VLOG(1) << "Set " << property->name(); 74 VLOG(1) << "Set " << property->name();
64 callback.Run(false); 75 callback.Run(false);
65 } 76 }
66 77
67 FakeBluetoothMediaTransportClient::FakeBluetoothMediaTransportClient() 78 FakeBluetoothMediaTransportClient::Transport::Transport(
68 : object_path_(ObjectPath(kTransportPath)) { 79 const ObjectPath& transport_path,
69 // TODO(mcchou): Multiple endpoints are sharing one property set for now. 80 Properties* transport_properties)
70 // Add property sets accordingly to separate the 81 : path(transport_path) {
71 // MediaTransportPropertiesChanged events for different endpoints. 82 properties.reset(transport_properties);
83 }
72 84
73 // Sets fake property set with default values. 85 FakeBluetoothMediaTransportClient::Transport::~Transport() {
74 properties_.reset(new Properties( 86 }
75 base::Bind(&FakeBluetoothMediaTransportClient::OnPropertyChanged, 87
76 base::Unretained(this)))); 88 FakeBluetoothMediaTransportClient::FakeBluetoothMediaTransportClient() {
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);
84 } 89 }
85 90
86 FakeBluetoothMediaTransportClient::~FakeBluetoothMediaTransportClient() { 91 FakeBluetoothMediaTransportClient::~FakeBluetoothMediaTransportClient() {
armansito 2015/02/26 02:27:34 You have to clean up the data in |endpoints_| here
Miao 2015/02/26 04:02:53 Done.
87 } 92 }
88 93
89 // DBusClient override. 94 // DBusClient override.
90 void FakeBluetoothMediaTransportClient::Init(dbus::Bus* bus) { 95 void FakeBluetoothMediaTransportClient::Init(dbus::Bus* bus) {
91 } 96 }
92 97
93 // BluetoothMediaTransportClient overrides.
94
95 void FakeBluetoothMediaTransportClient::AddObserver( 98 void FakeBluetoothMediaTransportClient::AddObserver(
96 BluetoothMediaTransportClient::Observer* observer) { 99 BluetoothMediaTransportClient::Observer* observer) {
97 observers_.AddObserver(observer); 100 observers_.AddObserver(observer);
98 } 101 }
99 102
100 void FakeBluetoothMediaTransportClient::RemoveObserver( 103 void FakeBluetoothMediaTransportClient::RemoveObserver(
101 BluetoothMediaTransportClient::Observer* observer) { 104 BluetoothMediaTransportClient::Observer* observer) {
102 observers_.RemoveObserver(observer); 105 observers_.RemoveObserver(observer);
103 } 106 }
104 107
105 FakeBluetoothMediaTransportClient::Properties* 108 FakeBluetoothMediaTransportClient::Properties*
106 FakeBluetoothMediaTransportClient::GetProperties( 109 FakeBluetoothMediaTransportClient::GetProperties(
107 const ObjectPath& object_path) { 110 const ObjectPath& object_path) {
108 return nullptr; 111 ObjectPath endpoint_path = GetEndpointPath(object_path);
112 if (endpoint_path.value() == "" || !ContainsKey(endpoints_, endpoint_path))
113 return nullptr;
114 return endpoints_[endpoint_path]->properties.get();
109 } 115 }
110 116
111 void FakeBluetoothMediaTransportClient::Acquire( 117 void FakeBluetoothMediaTransportClient::Acquire(
112 const ObjectPath& object_path, 118 const ObjectPath& object_path,
113 const AcquireCallback& callback, 119 const AcquireCallback& callback,
114 const ErrorCallback& error_callback) { 120 const ErrorCallback& error_callback) {
115 error_callback.Run(kNotImplemented, ""); 121 error_callback.Run(kNotImplemented, "");
116 } 122 }
117 123
118 void FakeBluetoothMediaTransportClient::TryAcquire( 124 void FakeBluetoothMediaTransportClient::TryAcquire(
119 const ObjectPath& object_path, 125 const ObjectPath& object_path,
120 const AcquireCallback& callback, 126 const AcquireCallback& callback,
121 const ErrorCallback& error_callback) { 127 const ErrorCallback& error_callback) {
122 error_callback.Run(kNotImplemented, ""); 128 error_callback.Run(kNotImplemented, "");
123 } 129 }
124 130
125 void FakeBluetoothMediaTransportClient::Release( 131 void FakeBluetoothMediaTransportClient::Release(
126 const ObjectPath& object_path, 132 const ObjectPath& object_path,
127 const base::Closure& callback, 133 const base::Closure& callback,
128 const ErrorCallback& error_callback) { 134 const ErrorCallback& error_callback) {
129 error_callback.Run(kNotImplemented, ""); 135 error_callback.Run(kNotImplemented, "");
130 } 136 }
131 137
132 void FakeBluetoothMediaTransportClient::SetValid( 138 void FakeBluetoothMediaTransportClient::SetValid(
133 const ObjectPath& endpoint_path, 139 FakeBluetoothMediaEndpointServiceProvider* endpoint,
134 bool valid) { 140 bool valid) {
141 FakeBluetoothMediaClient* media = static_cast<FakeBluetoothMediaClient*>(
142 DBusThreadManager::Get()->GetBluetoothMediaClient());
143 DCHECK(media);
144
145 ObjectPath endpoint_path(endpoint->object_path());
146 if (!media->IsRegistered(endpoint_path))
147 return;
148
135 if (valid) { 149 if (valid) {
136 endpoints_[endpoint_path] = valid; 150 ObjectPath transport_path = GenerateTransportPath();
151 VLOG(1) << "New transport, " << transport_path.value()
152 << " is created for endpoint " << endpoint_path.value();
153
154 // Sets the fake property set with default values.
155 scoped_ptr<Properties> properties(new Properties(
156 base::Bind(&FakeBluetoothMediaTransportClient::OnPropertyChanged,
157 base::Unretained(this))));
158 properties->device.ReplaceValue(ObjectPath(kTransportDevicePath));
159 properties->uuid.ReplaceValue(
160 BluetoothMediaClient::kBluetoothAudioSinkUUID);
161 properties->codec.ReplaceValue(kTransportCodec);
162 properties->configuration.ReplaceValue(kTransportConfiguration);
163 properties->state.ReplaceValue(BluetoothMediaTransportClient::kStateIdle);
164 properties->delay.ReplaceValue(kTransportDelay);
165 properties->volume.ReplaceValue(kTransportVolume);
166
167 endpoints_[endpoint_path] =
168 new Transport(transport_path, properties.release());
169 transports_[transport_path] = endpoint_path;
137 return; 170 return;
138 } 171 }
139 endpoints_.erase(endpoint_path);
140 172
141 // TODO(mcchou): Since there is only one transport path, all observers will 173 if (!ContainsKey(endpoints_, endpoint_path))
142 // be notified. Shades irrelevant observers. 174 return;
143 175
144 // Notifies observers about the state change of the transport. 176 // Notifies observers about the state change of the transport.
145 FOR_EACH_OBSERVER(BluetoothMediaTransportClient::Observer, observers_, 177 FOR_EACH_OBSERVER(BluetoothMediaTransportClient::Observer, observers_,
146 MediaTransportRemoved(object_path_)); 178 MediaTransportRemoved(GetTransportPath(endpoint_path)));
179
180 endpoint->ClearConfiguration(GetTransportPath(endpoint_path));
181 transports_.erase(GetTransportPath(endpoint_path));
182 delete endpoints_[endpoint_path];
183 endpoints_.erase(endpoint_path);
184 }
185
186 void FakeBluetoothMediaTransportClient::SetState(
187 const dbus::ObjectPath& endpoint_path,
188 const std::string& state) {
189 if (!ContainsKey(endpoints_, endpoint_path))
190 return;
191
192 endpoints_[endpoint_path]->properties->state.ReplaceValue(state);
193 FOR_EACH_OBSERVER(BluetoothMediaTransportClient::Observer, observers_,
194 MediaTransportPropertyChanged(
195 GetTransportPath(endpoint_path),
196 BluetoothMediaTransportClient::kStateProperty));
197 }
198
199 void FakeBluetoothMediaTransportClient::SetVolume(
200 const dbus::ObjectPath& endpoint_path,
201 const uint16_t& volume) {
202 if (!ContainsKey(endpoints_, endpoint_path))
203 return;
204
205 endpoints_[endpoint_path]->properties->volume.ReplaceValue(volume);
206 FOR_EACH_OBSERVER(BluetoothMediaTransportClient::Observer, observers_,
207 MediaTransportPropertyChanged(
208 GetTransportPath(endpoint_path),
209 BluetoothMediaTransportClient::kVolumeProperty));
210 }
211
212 ObjectPath FakeBluetoothMediaTransportClient::GetTransportPath(
213 const ObjectPath& endpoint_path) {
214 if (ContainsKey(endpoints_, endpoint_path))
215 return endpoints_[endpoint_path]->path;
216 return ObjectPath("");
217 }
218
219 ObjectPath FakeBluetoothMediaTransportClient::GetEndpointPath(
220 const ObjectPath& transport_path) {
221 if (ContainsKey(transports_, transport_path))
222 return transports_[transport_path];
223 return ObjectPath("");
147 } 224 }
148 225
149 void FakeBluetoothMediaTransportClient::OnPropertyChanged( 226 void FakeBluetoothMediaTransportClient::OnPropertyChanged(
150 const std::string& property_name) { 227 const std::string& property_name) {
151 VLOG(1) << "Property " << property_name << " changed"; 228 VLOG(1) << "Property " << property_name << " changed";
152 } 229 }
153 230
154 } // namespace chromeos 231 } // namespace chromeos
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698