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_client.h"
9 #include "chromeos/dbus/dbus_thread_manager.h"
10 #include "chromeos/dbus/fake_bluetooth_adapter_client.h"
11 #include "chromeos/dbus/fake_bluetooth_media_transport_client.h"
13 using dbus::ObjectPath
;
17 // Except for |kFailedError|, the other error is defined in BlueZ D-Bus Media
19 const char kFailedError
[] = "org.chromium.Error.Failed";
20 const char kInvalidArgumentsError
[] = "org.chromium.Error.InvalidArguments";
27 const uint8_t FakeBluetoothMediaClient::kDefaultCodec
= 0x00;
29 FakeBluetoothMediaClient::FakeBluetoothMediaClient()
31 object_path_(ObjectPath(FakeBluetoothAdapterClient::kAdapterPath
)) {
34 FakeBluetoothMediaClient::~FakeBluetoothMediaClient() {
37 void FakeBluetoothMediaClient::Init(dbus::Bus
* bus
) {
40 void FakeBluetoothMediaClient::AddObserver(
41 BluetoothMediaClient::Observer
* observer
) {
43 observers_
.AddObserver(observer
);
46 void FakeBluetoothMediaClient::RemoveObserver(
47 BluetoothMediaClient::Observer
* observer
) {
49 observers_
.RemoveObserver(observer
);
52 void FakeBluetoothMediaClient::RegisterEndpoint(
53 const ObjectPath
& object_path
,
54 const ObjectPath
& endpoint_path
,
55 const EndpointProperties
& properties
,
56 const base::Closure
& callback
,
57 const ErrorCallback
& error_callback
) {
61 VLOG(1) << "RegisterEndpoint: " << endpoint_path
.value();
63 // The media client and adapter client should have the same object path.
64 if (object_path
!= object_path_
||
65 properties
.uuid
!= BluetoothMediaClient::kBluetoothAudioSinkUUID
||
66 properties
.codec
!= kDefaultCodec
|| properties
.capabilities
.empty()) {
67 error_callback
.Run(kInvalidArgumentsError
, "");
71 // Sets the state of a given endpoint path to true if it is registered.
72 SetEndpointRegistered(endpoint_path
, true);
77 void FakeBluetoothMediaClient::UnregisterEndpoint(
78 const ObjectPath
& object_path
,
79 const ObjectPath
& endpoint_path
,
80 const base::Closure
& callback
,
81 const ErrorCallback
& error_callback
) {
82 // TODO(mcchou): Come up with some corresponding actions.
83 error_callback
.Run(kFailedError
, "");
86 void FakeBluetoothMediaClient::SetVisible(bool visible
) {
92 // If the media object becomes invisible, an update chain will
93 // unregister all endpoints and set the associated transport
94 // objects to be invalid.
95 for (std::map
<ObjectPath
, bool>::iterator it
= endpoints_
.begin();
96 it
!= endpoints_
.end(); ++it
) {
97 SetEndpointRegistered(it
->first
, false);
101 // Notifies observers about the change on |visible_|.
102 FOR_EACH_OBSERVER(BluetoothMediaClient::Observer
, observers_
,
103 MediaRemoved(object_path_
));
106 void FakeBluetoothMediaClient::SetEndpointRegistered(
107 const ObjectPath
& endpoint_path
,
110 endpoints_
[endpoint_path
] = registered
;
112 // Once a media endpoint object becomes invalid, the associated transport
114 FakeBluetoothMediaTransportClient
* transport
=
115 static_cast<FakeBluetoothMediaTransportClient
*>(
116 DBusThreadManager::Get()->GetBluetoothMediaTransportClient());
117 transport
->SetValid(endpoint_path
, true);
121 } // namespace chromeos