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 "base/bind.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" | |
11 | |
12 using dbus::ObjectPath; | |
13 | |
7 namespace { | 14 namespace { |
8 | 15 |
9 // TODO(mcchou): Remove this constants once it is in cros_system_api. | 16 // TODO(mcchou): Remove this constants once it is in cros_system_api. |
10 const char kBluetoothMediaTransportInterface[] = "org.bluez.MediaTransport1"; | 17 const char kBluetoothMediaTransportInterface[] = "org.bluez.MediaTransport1"; |
11 const char kNotImplemented[] = "org.bluez.NotImplemented"; | 18 const char kNotImplemented[] = "org.bluez.NotImplemented"; |
12 | 19 |
13 } // namespace | 20 } // namespace |
14 | 21 |
15 namespace chromeos { | 22 namespace chromeos { |
16 | 23 |
24 // static | |
25 const char FakeBluetoothMediaTransportClient::kTransportPath[] = | |
26 "/fake/hci0/dev_00_00_00_00_00_00/fd0"; | |
27 | |
28 // static | |
29 const char FakeBluetoothMediaTransportClient::kTransportDevicePath[] = | |
30 "/fake/hci0/dev_00_00_00_00_00_00"; | |
31 const uint8_t FakeBluetoothMediaTransportClient::kTransportCodec = 0x00; | |
32 const std::vector<uint8_t> | |
33 FakeBluetoothMediaTransportClient::kTransportConfiguration = { | |
34 0x21, 0x15, 0x33, 0x2C}; | |
35 const uint16_t FakeBluetoothMediaTransportClient::kTransportDelay = 5; | |
36 const uint16_t FakeBluetoothMediaTransportClient::kTransportVolume = 10; | |
37 | |
17 FakeBluetoothMediaTransportClient::Properties::Properties( | 38 FakeBluetoothMediaTransportClient::Properties::Properties( |
18 const PropertyChangedCallback& callback) | 39 const PropertyChangedCallback& callback) |
19 : BluetoothMediaTransportClient::Properties( | 40 : BluetoothMediaTransportClient::Properties( |
20 nullptr, | 41 nullptr, |
21 kBluetoothMediaTransportInterface, | 42 kBluetoothMediaTransportInterface, |
22 callback) { | 43 callback) { |
23 } | 44 } |
24 | 45 |
25 FakeBluetoothMediaTransportClient::Properties::~Properties() { | 46 FakeBluetoothMediaTransportClient::Properties::~Properties() { |
26 } | 47 } |
(...skipping 11 matching lines...) Expand all Loading... | |
38 VLOG(1) << "GetAll called."; | 59 VLOG(1) << "GetAll called."; |
39 } | 60 } |
40 | 61 |
41 void FakeBluetoothMediaTransportClient::Properties::Set( | 62 void FakeBluetoothMediaTransportClient::Properties::Set( |
42 dbus::PropertyBase* property, | 63 dbus::PropertyBase* property, |
43 dbus::PropertySet::SetCallback callback) { | 64 dbus::PropertySet::SetCallback callback) { |
44 VLOG(1) << "Set " << property->name(); | 65 VLOG(1) << "Set " << property->name(); |
45 callback.Run(false); | 66 callback.Run(false); |
46 } | 67 } |
47 | 68 |
48 FakeBluetoothMediaTransportClient::FakeBluetoothMediaTransportClient() { | 69 FakeBluetoothMediaTransportClient::FakeBluetoothMediaTransportClient() |
70 : object_path_(ObjectPath(kTransportPath)) { | |
71 // TODO(mcchou): Multiple endpoints are sharing one property set for now. | |
72 // Add property sets accordingly to separate the | |
73 // MediaTransportPropertiesChanged events for different endpoints. | |
74 | |
75 // Sets fake property set with default values. | |
76 properties_.reset(new Properties( | |
77 base::Bind(&FakeBluetoothMediaTransportClient::OnPropertyChanged, | |
78 base::Unretained(this)))); | |
79 properties_->device.ReplaceValue(ObjectPath(kTransportDevicePath)); | |
80 properties_->uuid.ReplaceValue(BluetoothMediaClient::kBluetoothAudioSinkUUID); | |
81 properties_->codec.ReplaceValue(kTransportCodec); | |
82 properties_->configuration.ReplaceValue(kTransportConfiguration); | |
83 properties_->state.ReplaceValue(BluetoothMediaTransportClient::kStateIdle); | |
84 properties_->delay.ReplaceValue(kTransportDelay); | |
85 properties_->volume.ReplaceValue(kTransportVolume); | |
49 } | 86 } |
50 | 87 |
51 FakeBluetoothMediaTransportClient::~FakeBluetoothMediaTransportClient() { | 88 FakeBluetoothMediaTransportClient::~FakeBluetoothMediaTransportClient() { |
52 } | 89 } |
53 | 90 |
54 // DBusClient override. | 91 // DBusClient override. |
55 void FakeBluetoothMediaTransportClient::Init(dbus::Bus* bus) { | 92 void FakeBluetoothMediaTransportClient::Init(dbus::Bus* bus) { |
56 } | 93 } |
57 | 94 |
58 // BluetoothMediaTransportClient overrides. | 95 // BluetoothMediaTransportClient overrides. |
59 | 96 |
60 void FakeBluetoothMediaTransportClient::AddObserver( | 97 void FakeBluetoothMediaTransportClient::AddObserver( |
61 BluetoothMediaTransportClient::Observer* observer) { | 98 BluetoothMediaTransportClient::Observer* observer) { |
62 observers_.AddObserver(observer); | 99 observers_.AddObserver(observer); |
63 } | 100 } |
64 | 101 |
65 void FakeBluetoothMediaTransportClient::RemoveObserver( | 102 void FakeBluetoothMediaTransportClient::RemoveObserver( |
66 BluetoothMediaTransportClient::Observer* observer) { | 103 BluetoothMediaTransportClient::Observer* observer) { |
67 observers_.RemoveObserver(observer); | 104 observers_.RemoveObserver(observer); |
68 } | 105 } |
69 | 106 |
70 FakeBluetoothMediaTransportClient::Properties* | 107 FakeBluetoothMediaTransportClient::Properties* |
71 FakeBluetoothMediaTransportClient::GetProperties( | 108 FakeBluetoothMediaTransportClient::GetProperties( |
72 const dbus::ObjectPath& object_path) { | 109 const ObjectPath& object_path) { |
73 return nullptr; | 110 return nullptr; |
74 } | 111 } |
75 | 112 |
76 void FakeBluetoothMediaTransportClient::Acquire( | 113 void FakeBluetoothMediaTransportClient::Acquire( |
77 const dbus::ObjectPath& object_path, | 114 const ObjectPath& object_path, |
78 const AcquireCallback& callback, | 115 const AcquireCallback& callback, |
79 const ErrorCallback& error_callback) { | 116 const ErrorCallback& error_callback) { |
80 error_callback.Run(kNotImplemented, ""); | 117 error_callback.Run(kNotImplemented, ""); |
81 } | 118 } |
82 | 119 |
83 void FakeBluetoothMediaTransportClient::TryAcquire( | 120 void FakeBluetoothMediaTransportClient::TryAcquire( |
84 const dbus::ObjectPath& object_path, | 121 const ObjectPath& object_path, |
85 const AcquireCallback& callback, | 122 const AcquireCallback& callback, |
86 const ErrorCallback& error_callback) { | 123 const ErrorCallback& error_callback) { |
87 error_callback.Run(kNotImplemented, ""); | 124 error_callback.Run(kNotImplemented, ""); |
88 } | 125 } |
89 | 126 |
90 void FakeBluetoothMediaTransportClient::Release( | 127 void FakeBluetoothMediaTransportClient::Release( |
91 const dbus::ObjectPath& object_path, | 128 const ObjectPath& object_path, |
92 const base::Closure& callback, | 129 const base::Closure& callback, |
93 const ErrorCallback& error_callback) { | 130 const ErrorCallback& error_callback) { |
94 error_callback.Run(kNotImplemented, ""); | 131 error_callback.Run(kNotImplemented, ""); |
95 } | 132 } |
96 | 133 |
134 void FakeBluetoothMediaTransportClient::SetValid( | |
135 const ObjectPath& endpoint_path, | |
136 bool valid) { | |
137 if (valid) { | |
138 endpoints_[endpoint_path] = valid; | |
armansito
2015/02/12 05:20:44
nit: early return.
Miao
2015/02/12 19:08:03
Done.
| |
139 } else { | |
140 endpoints_.erase(endpoint_path); | |
141 | |
142 // TODO(mcchou): Since there is only one transport path, all observers will | |
143 // be notified. Shades irrelevant observers. | |
144 | |
145 // Notifies observers about the state change of the transport. | |
146 FOR_EACH_OBSERVER(BluetoothMediaTransportClient::Observer, observers_, | |
147 MediaTransportRemoved(object_path_)); | |
148 } | |
149 } | |
150 | |
151 void FakeBluetoothMediaTransportClient::OnPropertyChanged( | |
152 const std::string& property_name) { | |
153 VLOG(1) << "Property " << property_name << " changed"; | |
154 } | |
155 | |
97 } // namespace chromeos | 156 } // namespace chromeos |
OLD | NEW |