OLD | NEW |
---|---|
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" |
10 #include "chromeos/dbus/fake_bluetooth_media_client.h" | 13 #include "chromeos/dbus/fake_bluetooth_media_client.h" |
14 #include "chromeos/dbus/fake_bluetooth_media_endpoint_service_provider.h" | |
11 | 15 |
12 using dbus::ObjectPath; | 16 using dbus::ObjectPath; |
13 | 17 |
14 namespace { | 18 namespace { |
15 | 19 |
16 // TODO(mcchou): Remove this constants once it is in cros_system_api. | 20 // TODO(mcchou): Remove this constants once it is in cros_system_api. |
17 const char kBluetoothMediaTransportInterface[] = "org.bluez.MediaTransport1"; | 21 const char kBluetoothMediaTransportInterface[] = "org.bluez.MediaTransport1"; |
18 const char kNotImplemented[] = "org.bluez.NotImplemented"; | 22 const char kNotImplemented[] = "org.bluez.NotImplemented"; |
19 | 23 |
24 ObjectPath GenerateTransportPath() { | |
25 static unsigned int sequence_number = 0; | |
26 ++sequence_number; | |
27 std::stringstream path; | |
28 path << "fake/hci0/dev_00_00_00_00_00_00/fd" << sequence_number; | |
armansito
2015/02/23 22:07:06
nit: if you want to truly simulate bluez's behavio
Miao
2015/02/24 01:12:12
Referred to chromeos::FakeBluetoothAdapterClient::
| |
29 return ObjectPath(path.str()); | |
30 } | |
31 | |
20 } // namespace | 32 } // namespace |
21 | 33 |
22 namespace chromeos { | 34 namespace chromeos { |
23 | 35 |
24 // static | 36 // static |
25 const char FakeBluetoothMediaTransportClient::kTransportPath[] = | |
26 "/fake/hci0/dev_00_00_00_00_00_00/fd0"; | |
27 const char FakeBluetoothMediaTransportClient::kTransportDevicePath[] = | 37 const char FakeBluetoothMediaTransportClient::kTransportDevicePath[] = |
28 "/fake/hci0/dev_00_00_00_00_00_00"; | 38 "/fake/hci0/dev_00_00_00_00_00_00"; |
armansito
2015/02/23 22:07:06
nit: How about "*/fake_audio_source"? Also, can th
Miao
2015/02/24 01:12:12
Done.
| |
29 const uint8_t FakeBluetoothMediaTransportClient::kTransportCodec = 0x00; | 39 const uint8_t FakeBluetoothMediaTransportClient::kTransportCodec = 0x00; |
30 const std::vector<uint8_t> | 40 const std::vector<uint8_t> |
31 FakeBluetoothMediaTransportClient::kTransportConfiguration = { | 41 FakeBluetoothMediaTransportClient::kTransportConfiguration = { |
32 0x21, 0x15, 0x33, 0x2C}; | 42 0x21, 0x15, 0x33, 0x2C}; |
33 const uint16_t FakeBluetoothMediaTransportClient::kTransportDelay = 5; | 43 const uint16_t FakeBluetoothMediaTransportClient::kTransportDelay = 5; |
34 const uint16_t FakeBluetoothMediaTransportClient::kTransportVolume = 10; | 44 const uint16_t FakeBluetoothMediaTransportClient::kTransportVolume = 10; |
35 | 45 |
36 FakeBluetoothMediaTransportClient::Properties::Properties( | 46 FakeBluetoothMediaTransportClient::Properties::Properties( |
37 const PropertyChangedCallback& callback) | 47 const PropertyChangedCallback& callback) |
38 : BluetoothMediaTransportClient::Properties( | 48 : BluetoothMediaTransportClient::Properties( |
(...skipping 18 matching lines...) Expand all Loading... | |
57 VLOG(1) << "GetAll called."; | 67 VLOG(1) << "GetAll called."; |
58 } | 68 } |
59 | 69 |
60 void FakeBluetoothMediaTransportClient::Properties::Set( | 70 void FakeBluetoothMediaTransportClient::Properties::Set( |
61 dbus::PropertyBase* property, | 71 dbus::PropertyBase* property, |
62 dbus::PropertySet::SetCallback callback) { | 72 dbus::PropertySet::SetCallback callback) { |
63 VLOG(1) << "Set " << property->name(); | 73 VLOG(1) << "Set " << property->name(); |
64 callback.Run(false); | 74 callback.Run(false); |
65 } | 75 } |
66 | 76 |
67 FakeBluetoothMediaTransportClient::FakeBluetoothMediaTransportClient() | 77 FakeBluetoothMediaTransportClient::FakeBluetoothMediaTransportClient() { |
68 : object_path_(ObjectPath(kTransportPath)) { | |
69 // TODO(mcchou): Multiple endpoints are sharing one property set for now. | 78 // TODO(mcchou): Multiple endpoints are sharing one property set for now. |
70 // Add property sets accordingly to separate the | 79 // Add property sets accordingly to separate the |
71 // MediaTransportPropertiesChanged events for different endpoints. | 80 // MediaTransportPropertiesChanged events for different endpoints. |
72 | 81 |
73 // Sets fake property set with default values. | 82 // Sets fake property set with default values. |
74 properties_.reset(new Properties( | 83 properties_.reset(new Properties( |
75 base::Bind(&FakeBluetoothMediaTransportClient::OnPropertyChanged, | 84 base::Bind(&FakeBluetoothMediaTransportClient::OnPropertyChanged, |
76 base::Unretained(this)))); | 85 base::Unretained(this)))); |
77 properties_->device.ReplaceValue(ObjectPath(kTransportDevicePath)); | 86 properties_->device.ReplaceValue(ObjectPath(kTransportDevicePath)); |
78 properties_->uuid.ReplaceValue(BluetoothMediaClient::kBluetoothAudioSinkUUID); | 87 properties_->uuid.ReplaceValue(BluetoothMediaClient::kBluetoothAudioSinkUUID); |
(...skipping 44 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
123 } | 132 } |
124 | 133 |
125 void FakeBluetoothMediaTransportClient::Release( | 134 void FakeBluetoothMediaTransportClient::Release( |
126 const ObjectPath& object_path, | 135 const ObjectPath& object_path, |
127 const base::Closure& callback, | 136 const base::Closure& callback, |
128 const ErrorCallback& error_callback) { | 137 const ErrorCallback& error_callback) { |
129 error_callback.Run(kNotImplemented, ""); | 138 error_callback.Run(kNotImplemented, ""); |
130 } | 139 } |
131 | 140 |
132 void FakeBluetoothMediaTransportClient::SetValid( | 141 void FakeBluetoothMediaTransportClient::SetValid( |
133 const ObjectPath& endpoint_path, | 142 FakeBluetoothMediaEndpointServiceProvider* endpoint, |
134 bool valid) { | 143 bool valid) { |
144 FakeBluetoothMediaClient* media = static_cast<FakeBluetoothMediaClient*>( | |
145 DBusThreadManager::Get()->GetBluetoothMediaClient()); | |
146 DCHECK(media); | |
147 | |
148 ObjectPath endpoint_path(endpoint->object_path()); | |
149 if (!media->IsRegistered(endpoint_path)) | |
150 return; | |
151 | |
135 if (valid) { | 152 if (valid) { |
136 endpoints_[endpoint_path] = valid; | 153 ObjectPath transport_path = GenerateTransportPath(); |
154 VLOG(1) << "New transport, " << transport_path.value() | |
155 << " is created for endpoint " << endpoint_path.value(); | |
156 endpoints_[endpoint_path] = transport_path; | |
137 return; | 157 return; |
138 } | 158 } |
139 endpoints_.erase(endpoint_path); | |
140 | |
141 // TODO(mcchou): Since there is only one transport path, all observers will | |
142 // be notified. Shades irrelevant observers. | |
143 | 159 |
144 // Notifies observers about the state change of the transport. | 160 // Notifies observers about the state change of the transport. |
145 FOR_EACH_OBSERVER(BluetoothMediaTransportClient::Observer, observers_, | 161 FOR_EACH_OBSERVER(BluetoothMediaTransportClient::Observer, observers_, |
146 MediaTransportRemoved(object_path_)); | 162 MediaTransportRemoved(endpoints_[endpoint_path])); |
163 endpoints_.erase(endpoint_path); | |
164 endpoint->ClearConfiguration(GetTransportPath(endpoint_path)); | |
165 } | |
166 | |
167 ObjectPath FakeBluetoothMediaTransportClient::GetTransportPath( | |
168 ObjectPath endpoint_path) { | |
169 if (ContainsKey(endpoints_, endpoint_path)) | |
170 return endpoints_[endpoint_path]; | |
171 return ObjectPath(""); | |
147 } | 172 } |
148 | 173 |
149 void FakeBluetoothMediaTransportClient::OnPropertyChanged( | 174 void FakeBluetoothMediaTransportClient::OnPropertyChanged( |
150 const std::string& property_name) { | 175 const std::string& property_name) { |
151 VLOG(1) << "Property " << property_name << " changed"; | 176 VLOG(1) << "Property " << property_name << " changed"; |
152 } | 177 } |
153 | 178 |
154 } // namespace chromeos | 179 } // namespace chromeos |
OLD | NEW |