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

Side by Side Diff: device/bluetooth/dbus/bluez_dbus_manager.cc

Issue 1347193004: Refactor DBusThreadManager to split away BT clients. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Created 5 years, 3 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
(Empty)
1 // Copyright (c) 2012 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.
4
5 #include "device/bluetooth/dbus/bluez_dbus_manager.h"
6
7 #include "base/command_line.h"
8 #include "base/sys_info.h"
9 #include "base/threading/thread.h"
10 #include "dbus/bus.h"
11 #include "dbus/dbus_statistics.h"
12 #include "device/bluetooth/dbus/bluetooth_adapter_client.h"
13 #include "device/bluetooth/dbus/bluetooth_agent_manager_client.h"
14 #include "device/bluetooth/dbus/bluetooth_device_client.h"
15 #include "device/bluetooth/dbus/bluetooth_gatt_characteristic_client.h"
16 #include "device/bluetooth/dbus/bluetooth_gatt_descriptor_client.h"
17 #include "device/bluetooth/dbus/bluetooth_gatt_manager_client.h"
18 #include "device/bluetooth/dbus/bluetooth_gatt_service_client.h"
19 #include "device/bluetooth/dbus/bluetooth_input_client.h"
20 #include "device/bluetooth/dbus/bluetooth_le_advertising_manager_client.h"
21 #include "device/bluetooth/dbus/bluetooth_media_client.h"
22 #include "device/bluetooth/dbus/bluetooth_media_transport_client.h"
23 #include "device/bluetooth/dbus/bluetooth_profile_manager_client.h"
24
25 namespace bluez {
26
27 static BluezDBusManager* g_bluez_dbus_manager = NULL;
stevenjb 2015/09/21 20:38:53 nullptr (throughout)
rkc 2015/09/21 20:56:25 Done.
28 static bool g_using_bluez_dbus_manager_for_testing = false;
29
30 BluezDBusManager::BluezDBusManager(
31 dbus::Bus* bus,
32 scoped_ptr<BluetoothDBusClientBundle> client_bundle)
33 : bus_(bus), client_bundle_(client_bundle.Pass()) {}
34
35 BluezDBusManager::~BluezDBusManager() {
36 // Delete all D-Bus clients before shutting down the system bus.
37 client_bundle_.reset();
38 }
39
40 dbus::Bus* bluez::BluezDBusManager::GetSystemBus() {
41 return bus_;
42 }
43
44 BluetoothAdapterClient* bluez::BluezDBusManager::GetBluetoothAdapterClient() {
45 return client_bundle_->bluetooth_adapter_client();
46 }
47
48 BluetoothLEAdvertisingManagerClient*
49 bluez::BluezDBusManager::GetBluetoothLEAdvertisingManagerClient() {
50 return client_bundle_->bluetooth_le_advertising_manager_client();
51 }
52
53 BluetoothAgentManagerClient*
54 bluez::BluezDBusManager::GetBluetoothAgentManagerClient() {
55 return client_bundle_->bluetooth_agent_manager_client();
56 }
57
58 BluetoothDeviceClient* bluez::BluezDBusManager::GetBluetoothDeviceClient() {
59 return client_bundle_->bluetooth_device_client();
60 }
61
62 BluetoothGattCharacteristicClient*
63 bluez::BluezDBusManager::GetBluetoothGattCharacteristicClient() {
64 return client_bundle_->bluetooth_gatt_characteristic_client();
65 }
66
67 BluetoothGattDescriptorClient*
68 bluez::BluezDBusManager::GetBluetoothGattDescriptorClient() {
69 return client_bundle_->bluetooth_gatt_descriptor_client();
70 }
71
72 BluetoothGattManagerClient*
73 bluez::BluezDBusManager::GetBluetoothGattManagerClient() {
74 return client_bundle_->bluetooth_gatt_manager_client();
75 }
76
77 BluetoothGattServiceClient*
78 bluez::BluezDBusManager::GetBluetoothGattServiceClient() {
79 return client_bundle_->bluetooth_gatt_service_client();
80 }
81
82 BluetoothInputClient* bluez::BluezDBusManager::GetBluetoothInputClient() {
83 return client_bundle_->bluetooth_input_client();
84 }
85
86 BluetoothMediaClient* bluez::BluezDBusManager::GetBluetoothMediaClient() {
87 return client_bundle_->bluetooth_media_client();
88 }
89
90 BluetoothMediaTransportClient*
91 bluez::BluezDBusManager::GetBluetoothMediaTransportClient() {
92 return client_bundle_->bluetooth_media_transport_client();
93 }
94
95 BluetoothProfileManagerClient*
96 bluez::BluezDBusManager::GetBluetoothProfileManagerClient() {
97 return client_bundle_->bluetooth_profile_manager_client();
98 }
99
100 void BluezDBusManager::InitializeClients() {
101 GetBluetoothAdapterClient()->Init(GetSystemBus());
102 GetBluetoothAgentManagerClient()->Init(GetSystemBus());
103 GetBluetoothDeviceClient()->Init(GetSystemBus());
104 GetBluetoothGattCharacteristicClient()->Init(GetSystemBus());
105 GetBluetoothGattDescriptorClient()->Init(GetSystemBus());
106 GetBluetoothGattManagerClient()->Init(GetSystemBus());
107 GetBluetoothGattServiceClient()->Init(GetSystemBus());
108 GetBluetoothInputClient()->Init(GetSystemBus());
109 GetBluetoothLEAdvertisingManagerClient()->Init(GetSystemBus());
110 GetBluetoothMediaClient()->Init(GetSystemBus());
111 GetBluetoothMediaTransportClient()->Init(GetSystemBus());
112 GetBluetoothProfileManagerClient()->Init(GetSystemBus());
113
114 // This must be called after the list of clients so they've each had a
115 // chance to register with their object g_dbus_thread_managers.
116 if (GetSystemBus())
117 GetSystemBus()->GetManagedObjects();
118 }
119
120 // static
121 void BluezDBusManager::Initialize(dbus::Bus* bus, bool use_dbus_stub) {
122 // If we initialize BluezDBusManager twice we may also be shutting it down
123 // early; do not allow that.
124 if (g_using_bluez_dbus_manager_for_testing)
125 return;
126
127 CHECK(!g_bluez_dbus_manager);
128 CreateGlobalInstance(bus, use_dbus_stub);
129 }
130
131 // static
132 scoped_ptr<BluezDBusManagerSetter>
133 bluez::BluezDBusManager::GetSetterForTesting() {
134 if (!g_using_bluez_dbus_manager_for_testing) {
135 g_using_bluez_dbus_manager_for_testing = true;
136 CreateGlobalInstance(NULL, true);
137 }
138
139 return make_scoped_ptr(new BluezDBusManagerSetter());
140 }
141
142 // static
143 void BluezDBusManager::CreateGlobalInstance(dbus::Bus* bus, bool use_stubs) {
144 CHECK(!g_bluez_dbus_manager);
145 g_bluez_dbus_manager = new BluezDBusManager(
146 bus, make_scoped_ptr(new BluetoothDBusClientBundle(use_stubs)));
147 g_bluez_dbus_manager->InitializeClients();
148 }
149
150 // static
151 bool BluezDBusManager::IsInitialized() {
152 return g_bluez_dbus_manager != NULL;
153 }
154
155 // static
156 void BluezDBusManager::Shutdown() {
157 // Ensure that we only shutdown BluezDBusManager once.
158 CHECK(g_bluez_dbus_manager);
159 BluezDBusManager* dbus_manager = g_bluez_dbus_manager;
160 g_bluez_dbus_manager = NULL;
161 g_using_bluez_dbus_manager_for_testing = false;
162 delete dbus_manager;
163 VLOG(1) << "BluezDBusManager Shutdown completed";
164 }
165
166 // static
167 BluezDBusManager* bluez::BluezDBusManager::Get() {
168 CHECK(g_bluez_dbus_manager)
169 << "bluez::BluezDBusManager::Get() called before Initialize()";
170 return g_bluez_dbus_manager;
171 }
172
173 BluezDBusManagerSetter::BluezDBusManagerSetter() {}
174
175 BluezDBusManagerSetter::~BluezDBusManagerSetter() {}
176
177 void BluezDBusManagerSetter::SetBluetoothAdapterClient(
178 scoped_ptr<BluetoothAdapterClient> client) {
179 bluez::BluezDBusManager::Get()->client_bundle_->bluetooth_adapter_client_ =
180 client.Pass();
181 }
182
183 void BluezDBusManagerSetter::SetBluetoothLEAdvertisingManagerClient(
184 scoped_ptr<BluetoothLEAdvertisingManagerClient> client) {
185 bluez::BluezDBusManager::Get()
186 ->client_bundle_->bluetooth_le_advertising_manager_client_ =
187 client.Pass();
188 }
189
190 void BluezDBusManagerSetter::SetBluetoothAgentManagerClient(
191 scoped_ptr<BluetoothAgentManagerClient> client) {
192 bluez::BluezDBusManager::Get()
193 ->client_bundle_->bluetooth_agent_manager_client_ = client.Pass();
194 }
195
196 void BluezDBusManagerSetter::SetBluetoothDeviceClient(
197 scoped_ptr<BluetoothDeviceClient> client) {
198 bluez::BluezDBusManager::Get()->client_bundle_->bluetooth_device_client_ =
199 client.Pass();
200 }
201
202 void BluezDBusManagerSetter::SetBluetoothGattCharacteristicClient(
203 scoped_ptr<BluetoothGattCharacteristicClient> client) {
204 bluez::BluezDBusManager::Get()
205 ->client_bundle_->bluetooth_gatt_characteristic_client_ = client.Pass();
206 }
207
208 void BluezDBusManagerSetter::SetBluetoothGattDescriptorClient(
209 scoped_ptr<BluetoothGattDescriptorClient> client) {
210 bluez::BluezDBusManager::Get()
211 ->client_bundle_->bluetooth_gatt_descriptor_client_ = client.Pass();
212 }
213
214 void BluezDBusManagerSetter::SetBluetoothGattManagerClient(
215 scoped_ptr<BluetoothGattManagerClient> client) {
216 bluez::BluezDBusManager::Get()
217 ->client_bundle_->bluetooth_gatt_manager_client_ = client.Pass();
218 }
219
220 void BluezDBusManagerSetter::SetBluetoothGattServiceClient(
221 scoped_ptr<BluetoothGattServiceClient> client) {
222 bluez::BluezDBusManager::Get()
223 ->client_bundle_->bluetooth_gatt_service_client_ = client.Pass();
224 }
225
226 void BluezDBusManagerSetter::SetBluetoothInputClient(
227 scoped_ptr<BluetoothInputClient> client) {
228 bluez::BluezDBusManager::Get()->client_bundle_->bluetooth_input_client_ =
229 client.Pass();
230 }
231
232 void BluezDBusManagerSetter::SetBluetoothMediaClient(
233 scoped_ptr<BluetoothMediaClient> client) {
234 bluez::BluezDBusManager::Get()->client_bundle_->bluetooth_media_client_ =
235 client.Pass();
236 }
237
238 void BluezDBusManagerSetter::SetBluetoothMediaTransportClient(
239 scoped_ptr<BluetoothMediaTransportClient> client) {
240 bluez::BluezDBusManager::Get()
241 ->client_bundle_->bluetooth_media_transport_client_ = client.Pass();
242 }
243
244 void BluezDBusManagerSetter::SetBluetoothProfileManagerClient(
245 scoped_ptr<BluetoothProfileManagerClient> client) {
246 bluez::BluezDBusManager::Get()
247 ->client_bundle_->bluetooth_profile_manager_client_ = client.Pass();
248 }
249
250 } // namespace bluez
OLDNEW
« no previous file with comments | « device/bluetooth/dbus/bluez_dbus_manager.h ('k') | device/bluetooth/dbus/fake_bluetooth_adapter_client.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698