| 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/bluetooth_media_client.h" | 5 #include "device/bluetooth/dbus/bluetooth_media_client.h" |
| 6 | 6 |
| 7 #include "base/bind.h" | 7 #include "base/bind.h" |
| 8 #include "base/logging.h" | 8 #include "base/logging.h" |
| 9 #include "base/memory/ref_counted.h" | 9 #include "base/memory/ref_counted.h" |
| 10 #include "base/observer_list.h" | 10 #include "base/observer_list.h" |
| 11 #include "dbus/bus.h" | 11 #include "dbus/bus.h" |
| 12 #include "dbus/message.h" | 12 #include "dbus/message.h" |
| 13 #include "dbus/object_manager.h" | 13 #include "dbus/object_manager.h" |
| 14 #include "dbus/object_proxy.h" | 14 #include "dbus/object_proxy.h" |
| 15 #include "third_party/cros_system_api/dbus/service_constants.h" | 15 #include "third_party/cros_system_api/dbus/service_constants.h" |
| 16 | 16 |
| 17 namespace { | 17 namespace { |
| 18 | 18 |
| 19 // Since there is no property associated with Media objects, an empty callback | 19 // Since there is no property associated with Media objects, an empty callback |
| 20 // is used. | 20 // is used. |
| 21 void DoNothing(const std::string& property_name) { | 21 void DoNothing(const std::string& property_name) {} |
| 22 } | |
| 23 | 22 |
| 24 // TODO(mcchou): Add these service constants into dbus/service_constants.h | 23 // TODO(mcchou): Add these service constants into dbus/service_constants.h |
| 25 // later. | 24 // later. |
| 26 const char kBluetoothMediaInterface[] = "org.bluez.Media1"; | 25 const char kBluetoothMediaInterface[] = "org.bluez.Media1"; |
| 27 | 26 |
| 28 // Method names supported by Media Interface. | 27 // Method names supported by Media Interface. |
| 29 const char kRegisterEndpoint[] = "RegisterEndpoint"; | 28 const char kRegisterEndpoint[] = "RegisterEndpoint"; |
| 30 const char kUnregisterEndpoint[] = "UnregisterEndpoint"; | 29 const char kUnregisterEndpoint[] = "UnregisterEndpoint"; |
| 31 | 30 |
| 32 // The set of properties which are used to register a media endpoint. | 31 // The set of properties which are used to register a media endpoint. |
| 33 const char kUUIDEndpointProperty[] = "UUID"; | 32 const char kUUIDEndpointProperty[] = "UUID"; |
| 34 const char kCodecEndpointProperty[] = "Codec"; | 33 const char kCodecEndpointProperty[] = "Codec"; |
| 35 const char kCapabilitiesEndpointProperty[] = "Capabilities"; | 34 const char kCapabilitiesEndpointProperty[] = "Capabilities"; |
| 36 | 35 |
| 37 } // namespace | 36 } // namespace |
| 38 | 37 |
| 39 namespace chromeos { | 38 namespace bluez { |
| 40 | 39 |
| 41 // static | 40 // static |
| 42 const char BluetoothMediaClient::kNoResponseError[] = | 41 const char BluetoothMediaClient::kNoResponseError[] = |
| 43 "org.chromium.Error.NoResponse"; | 42 "org.chromium.Error.NoResponse"; |
| 44 | 43 |
| 45 // static | 44 // static |
| 46 const char BluetoothMediaClient::kBluetoothAudioSinkUUID[] = | 45 const char BluetoothMediaClient::kBluetoothAudioSinkUUID[] = |
| 47 "0000110b-0000-1000-8000-00805f9b34fb"; | 46 "0000110b-0000-1000-8000-00805f9b34fb"; |
| 48 | 47 |
| 49 BluetoothMediaClient::EndpointProperties::EndpointProperties() : codec(0x00) { | 48 BluetoothMediaClient::EndpointProperties::EndpointProperties() : codec(0x00) {} |
| 50 } | |
| 51 | 49 |
| 52 BluetoothMediaClient::EndpointProperties::~EndpointProperties() { | 50 BluetoothMediaClient::EndpointProperties::~EndpointProperties() {} |
| 53 } | |
| 54 | 51 |
| 55 class BluetoothMediaClientImpl | 52 class BluetoothMediaClientImpl : public BluetoothMediaClient, |
| 56 : public BluetoothMediaClient, dbus::ObjectManager::Interface { | 53 dbus::ObjectManager::Interface { |
| 57 public: | 54 public: |
| 58 BluetoothMediaClientImpl() | 55 BluetoothMediaClientImpl() |
| 59 : object_manager_(nullptr), weak_ptr_factory_(this) {} | 56 : object_manager_(nullptr), weak_ptr_factory_(this) {} |
| 60 | 57 |
| 61 ~BluetoothMediaClientImpl() override { | 58 ~BluetoothMediaClientImpl() override { |
| 62 object_manager_->UnregisterInterface(kBluetoothMediaInterface); | 59 object_manager_->UnregisterInterface(kBluetoothMediaInterface); |
| 63 } | 60 } |
| 64 | 61 |
| 65 // dbus::ObjectManager::Interface overrides. | 62 // dbus::ObjectManager::Interface overrides. |
| 66 | 63 |
| (...skipping 71 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 138 dict_entry_writer.CloseContainer(&variant_writer); | 135 dict_entry_writer.CloseContainer(&variant_writer); |
| 139 array_writer.CloseContainer(&dict_entry_writer); | 136 array_writer.CloseContainer(&dict_entry_writer); |
| 140 | 137 |
| 141 writer.CloseContainer(&array_writer); | 138 writer.CloseContainer(&array_writer); |
| 142 | 139 |
| 143 // Get Object Proxy based on the service name and the service path and call | 140 // Get Object Proxy based on the service name and the service path and call |
| 144 // RegisterEndpoint medthod. | 141 // RegisterEndpoint medthod. |
| 145 scoped_refptr<dbus::ObjectProxy> object_proxy( | 142 scoped_refptr<dbus::ObjectProxy> object_proxy( |
| 146 object_manager_->GetObjectProxy(object_path)); | 143 object_manager_->GetObjectProxy(object_path)); |
| 147 object_proxy->CallMethodWithErrorCallback( | 144 object_proxy->CallMethodWithErrorCallback( |
| 148 &method_call, | 145 &method_call, dbus::ObjectProxy::TIMEOUT_USE_DEFAULT, |
| 149 dbus::ObjectProxy::TIMEOUT_USE_DEFAULT, | |
| 150 base::Bind(&BluetoothMediaClientImpl::OnSuccess, | 146 base::Bind(&BluetoothMediaClientImpl::OnSuccess, |
| 151 weak_ptr_factory_.GetWeakPtr(), callback), | 147 weak_ptr_factory_.GetWeakPtr(), callback), |
| 152 base::Bind(&BluetoothMediaClientImpl::OnError, | 148 base::Bind(&BluetoothMediaClientImpl::OnError, |
| 153 weak_ptr_factory_.GetWeakPtr(), error_callback)); | 149 weak_ptr_factory_.GetWeakPtr(), error_callback)); |
| 154 } | 150 } |
| 155 | 151 |
| 156 void UnregisterEndpoint(const dbus::ObjectPath& object_path, | 152 void UnregisterEndpoint(const dbus::ObjectPath& object_path, |
| 157 const dbus::ObjectPath& endpoint_path, | 153 const dbus::ObjectPath& endpoint_path, |
| 158 const base::Closure& callback, | 154 const base::Closure& callback, |
| 159 const ErrorCallback& error_callback) override { | 155 const ErrorCallback& error_callback) override { |
| 160 VLOG(1) << "UnregisterEndpoint - endpoint: " << endpoint_path.value(); | 156 VLOG(1) << "UnregisterEndpoint - endpoint: " << endpoint_path.value(); |
| 161 | 157 |
| 162 dbus::MethodCall method_call(kBluetoothMediaInterface, kUnregisterEndpoint); | 158 dbus::MethodCall method_call(kBluetoothMediaInterface, kUnregisterEndpoint); |
| 163 | 159 |
| 164 // Send the path to the endpoint. | 160 // Send the path to the endpoint. |
| 165 dbus::MessageWriter writer(&method_call); | 161 dbus::MessageWriter writer(&method_call); |
| 166 writer.AppendObjectPath(endpoint_path); | 162 writer.AppendObjectPath(endpoint_path); |
| 167 | 163 |
| 168 // Get Object Proxy based on the service name and the service path and call | 164 // Get Object Proxy based on the service name and the service path and call |
| 169 // RegisterEndpoint medthod. | 165 // RegisterEndpoint medthod. |
| 170 scoped_refptr<dbus::ObjectProxy> object_proxy( | 166 scoped_refptr<dbus::ObjectProxy> object_proxy( |
| 171 object_manager_->GetObjectProxy(object_path)); | 167 object_manager_->GetObjectProxy(object_path)); |
| 172 object_proxy->CallMethodWithErrorCallback( | 168 object_proxy->CallMethodWithErrorCallback( |
| 173 &method_call, | 169 &method_call, dbus::ObjectProxy::TIMEOUT_USE_DEFAULT, |
| 174 dbus::ObjectProxy::TIMEOUT_USE_DEFAULT, | |
| 175 base::Bind(&BluetoothMediaClientImpl::OnSuccess, | 170 base::Bind(&BluetoothMediaClientImpl::OnSuccess, |
| 176 weak_ptr_factory_.GetWeakPtr(), callback), | 171 weak_ptr_factory_.GetWeakPtr(), callback), |
| 177 base::Bind(&BluetoothMediaClientImpl::OnError, | 172 base::Bind(&BluetoothMediaClientImpl::OnError, |
| 178 weak_ptr_factory_.GetWeakPtr(), error_callback)); | 173 weak_ptr_factory_.GetWeakPtr(), error_callback)); |
| 179 } | 174 } |
| 180 | 175 |
| 181 protected: | 176 protected: |
| 182 void Init(dbus::Bus* bus) override { | 177 void Init(dbus::Bus* bus) override { |
| 183 DCHECK(bus); | 178 DCHECK(bus); |
| 184 object_manager_ = bus->GetObjectManager( | 179 object_manager_ = bus->GetObjectManager( |
| 185 bluetooth_object_manager::kBluetoothObjectManagerServiceName, | 180 bluetooth_object_manager::kBluetoothObjectManagerServiceName, |
| 186 dbus::ObjectPath( | 181 dbus::ObjectPath( |
| 187 bluetooth_object_manager::kBluetoothObjectManagerServicePath)); | 182 bluetooth_object_manager::kBluetoothObjectManagerServicePath)); |
| 188 object_manager_->RegisterInterface(kBluetoothMediaInterface, this); | 183 object_manager_->RegisterInterface(kBluetoothMediaInterface, this); |
| 189 } | 184 } |
| 190 | 185 |
| 191 private: | 186 private: |
| 192 // Called when a response for successful method call is received. | 187 // Called when a response for successful method call is received. |
| 193 void OnSuccess(const base::Closure& callback, | 188 void OnSuccess(const base::Closure& callback, dbus::Response* response) { |
| 194 dbus::Response* response) { | |
| 195 DCHECK(response); | 189 DCHECK(response); |
| 196 callback.Run(); | 190 callback.Run(); |
| 197 } | 191 } |
| 198 | 192 |
| 199 // Called when a response for a failed method call is received. | 193 // Called when a response for a failed method call is received. |
| 200 void OnError(const ErrorCallback& error_callback, | 194 void OnError(const ErrorCallback& error_callback, |
| 201 dbus::ErrorResponse* response) { | 195 dbus::ErrorResponse* response) { |
| 202 // Error response has an optional error message argument. | 196 // Error response has an optional error message argument. |
| 203 std::string error_name; | 197 std::string error_name; |
| 204 std::string error_message; | 198 std::string error_message; |
| (...skipping 10 matching lines...) Expand all Loading... |
| 215 dbus::ObjectManager* object_manager_; | 209 dbus::ObjectManager* object_manager_; |
| 216 | 210 |
| 217 // List of observers interested in event notifications from us. | 211 // List of observers interested in event notifications from us. |
| 218 base::ObserverList<BluetoothMediaClient::Observer> observers_; | 212 base::ObserverList<BluetoothMediaClient::Observer> observers_; |
| 219 | 213 |
| 220 base::WeakPtrFactory<BluetoothMediaClientImpl> weak_ptr_factory_; | 214 base::WeakPtrFactory<BluetoothMediaClientImpl> weak_ptr_factory_; |
| 221 | 215 |
| 222 DISALLOW_COPY_AND_ASSIGN(BluetoothMediaClientImpl); | 216 DISALLOW_COPY_AND_ASSIGN(BluetoothMediaClientImpl); |
| 223 }; | 217 }; |
| 224 | 218 |
| 225 BluetoothMediaClient::BluetoothMediaClient() { | 219 BluetoothMediaClient::BluetoothMediaClient() {} |
| 226 } | |
| 227 | 220 |
| 228 BluetoothMediaClient::~BluetoothMediaClient() { | 221 BluetoothMediaClient::~BluetoothMediaClient() {} |
| 229 } | |
| 230 | 222 |
| 231 BluetoothMediaClient* BluetoothMediaClient::Create() { | 223 BluetoothMediaClient* BluetoothMediaClient::Create() { |
| 232 return new BluetoothMediaClientImpl(); | 224 return new BluetoothMediaClientImpl(); |
| 233 } | 225 } |
| 234 | 226 |
| 235 } // namespace chromeos | 227 } // namespace bluez |
| OLD | NEW |