OLD | NEW |
---|---|
(Empty) | |
1 // Copyright (c) 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. | |
4 | |
5 #include "chromeos/dbus/dbus_client_bundle.h" | |
6 | |
7 #include "base/strings/string_split.h" | |
8 #include "base/strings/string_util.h" | |
9 #include "chromeos/dbus/bluetooth_adapter_client.h" | |
10 #include "chromeos/dbus/bluetooth_agent_manager_client.h" | |
11 #include "chromeos/dbus/bluetooth_device_client.h" | |
12 #include "chromeos/dbus/bluetooth_gatt_characteristic_client.h" | |
13 #include "chromeos/dbus/bluetooth_gatt_descriptor_client.h" | |
14 #include "chromeos/dbus/bluetooth_gatt_manager_client.h" | |
15 #include "chromeos/dbus/bluetooth_gatt_service_client.h" | |
16 #include "chromeos/dbus/bluetooth_input_client.h" | |
17 #include "chromeos/dbus/bluetooth_profile_manager_client.h" | |
18 #include "chromeos/dbus/cras_audio_client.h" | |
19 #include "chromeos/dbus/cros_disks_client.h" | |
20 #include "chromeos/dbus/cryptohome_client.h" | |
21 #include "chromeos/dbus/debug_daemon_client.h" | |
22 #include "chromeos/dbus/easy_unlock_client.h" | |
23 #include "chromeos/dbus/gsm_sms_client.h" | |
24 #include "chromeos/dbus/image_burner_client.h" | |
25 #include "chromeos/dbus/introspectable_client.h" | |
26 #include "chromeos/dbus/lorgnette_manager_client.h" | |
27 #include "chromeos/dbus/modem_messaging_client.h" | |
28 #include "chromeos/dbus/nfc_adapter_client.h" | |
29 #include "chromeos/dbus/nfc_device_client.h" | |
30 #include "chromeos/dbus/nfc_manager_client.h" | |
31 #include "chromeos/dbus/nfc_record_client.h" | |
32 #include "chromeos/dbus/nfc_tag_client.h" | |
33 #include "chromeos/dbus/permission_broker_client.h" | |
34 #include "chromeos/dbus/power_manager_client.h" | |
35 #include "chromeos/dbus/power_policy_controller.h" | |
36 #include "chromeos/dbus/session_manager_client.h" | |
37 #include "chromeos/dbus/shill_device_client.h" | |
38 #include "chromeos/dbus/shill_ipconfig_client.h" | |
39 #include "chromeos/dbus/shill_manager_client.h" | |
40 #include "chromeos/dbus/shill_profile_client.h" | |
41 #include "chromeos/dbus/shill_service_client.h" | |
42 #include "chromeos/dbus/sms_client.h" | |
43 #include "chromeos/dbus/system_clock_client.h" | |
44 #include "chromeos/dbus/update_engine_client.h" | |
45 | |
46 namespace chromeos { | |
47 | |
48 namespace { | |
49 | |
50 // Command line switch mapping for --dbus-unstub-clients. | |
51 struct { | |
52 const char* param_name; | |
53 DBusClientBundle::DBusClientType client_type; | |
54 } client_type_map[] = { | |
55 { "bluetooth", DBusClientBundle::BLUETOOTH }, | |
56 { "bluetoothlowenergy", DBusClientBundle::BLUETOOTH_LOW_ENERGY }, | |
57 { "cras", DBusClientBundle::CRAS }, | |
58 { "crosdisks", DBusClientBundle::CROS_DISKS }, | |
59 { "cryptohome", DBusClientBundle::CRYPTOHOME }, | |
60 { "debugdaemon", DBusClientBundle::DEBUG_DAEMON }, | |
61 { "easyunlock", DBusClientBundle::EASY_UNLOCK }, | |
62 { "lorgnettemanager", DBusClientBundle::LORGNETTE_MANAGER }, | |
63 { "shill", DBusClientBundle::SHILL }, | |
64 { "gsmsms", DBusClientBundle::GSM_SMS }, | |
65 { "imageburner", DBusClientBundle::IMAGE_BURNER }, | |
66 { "introspectable", DBusClientBundle::INTROSPECTABLE }, | |
67 { "modemmessaging", DBusClientBundle::MODEM_MESSAGING }, | |
68 { "nfc", DBusClientBundle::NFC }, | |
69 { "permissionbroker", DBusClientBundle::PERMISSION_BROKER }, | |
70 { "powermanager", DBusClientBundle::POWER_MANAGER }, | |
71 { "powerpolicy", DBusClientBundle::POWER_POLICY }, | |
72 { "sessionmanager", DBusClientBundle::SESSION_MANAGER }, | |
73 { "sms", DBusClientBundle::SMS }, | |
74 { "systemclock", DBusClientBundle::SYSTEM_CLOCK }, | |
75 { "updateengine", DBusClientBundle::UPDATE_ENGINE }, | |
76 }; | |
77 | |
78 // Parses single command line param value for dbus subsystem and returns its | |
79 // enum representation. DBusClientType::UNKWNOWN is returned if |client_type| | |
80 // does not match any known dbus client. | |
81 DBusClientBundle::DBusClientType GetDBusClientType( | |
82 const std::string& client_type) { | |
83 for (size_t i = 0; i < arraysize(client_type_map); i++) { | |
84 if (LowerCaseEqualsASCII(client_type, client_type_map[i].param_name)) | |
85 return client_type_map[i].client_type; | |
86 } | |
87 return DBusClientBundle::UNKNOWN; | |
88 } | |
89 | |
90 } // namespace | |
91 DBusClientBundle::DBusClientBundle(unsigned int client_mask) { | |
92 const DBusClientImplementationType type = REAL_DBUS_CLIENT_IMPLEMENTATION; | |
93 | |
94 if (client_mask & BLUETOOTH) { | |
95 bluetooth_adapter_client_.reset(BluetoothAdapterClient::Create()); | |
96 bluetooth_agent_manager_client_.reset( | |
97 BluetoothAgentManagerClient::Create()); | |
98 bluetooth_device_client_.reset(BluetoothDeviceClient::Create()); | |
99 bluetooth_input_client_.reset(BluetoothInputClient::Create()); | |
100 bluetooth_profile_manager_client_.reset( | |
101 BluetoothProfileManagerClient::Create()); | |
102 } | |
103 | |
104 if (client_mask & BLUETOOTH_LOW_ENERGY) { | |
105 bluetooth_gatt_characteristic_client_.reset( | |
106 BluetoothGattCharacteristicClient::Create()); | |
107 bluetooth_gatt_descriptor_client_.reset( | |
108 BluetoothGattDescriptorClient::Create()); | |
109 bluetooth_gatt_manager_client_.reset( | |
110 BluetoothGattManagerClient::Create()); | |
111 bluetooth_gatt_service_client_.reset( | |
112 BluetoothGattServiceClient::Create()); | |
113 } | |
114 | |
115 if (client_mask & CRAS) | |
116 cras_audio_client_.reset(CrasAudioClient::Create()); | |
117 | |
118 if (client_mask & CROS_DISKS) | |
119 cros_disks_client_.reset(CrosDisksClient::Create(type)); | |
120 | |
121 if (client_mask & CRYPTOHOME) | |
122 cryptohome_client_.reset(CryptohomeClient::Create()); | |
hashimoto
2014/08/08 02:06:15
nit: indent.
zel
2014/08/08 19:00:14
Done.
| |
123 | |
124 if (client_mask & DEBUG_DAEMON) | |
125 debug_daemon_client_.reset(DebugDaemonClient::Create()); | |
hashimoto
2014/08/08 02:06:15
ditto.
zel
2014/08/08 19:00:14
Done.
| |
126 | |
127 if (client_mask & EASY_UNLOCK) | |
128 easy_unlock_client_.reset(EasyUnlockClient::Create()); | |
hashimoto
2014/08/08 02:06:15
ditto.
zel
2014/08/08 19:00:14
Done.
| |
129 | |
130 if (client_mask & LORGNETTE_MANAGER) | |
131 lorgnette_manager_client_.reset(LorgnetteManagerClient::Create()); | |
132 | |
133 if (client_mask & SHILL) { | |
134 shill_manager_client_.reset(ShillManagerClient::Create()); | |
135 shill_device_client_.reset(ShillDeviceClient::Create()); | |
136 shill_ipconfig_client_.reset(ShillIPConfigClient::Create()); | |
137 shill_service_client_.reset(ShillServiceClient::Create()); | |
138 shill_profile_client_.reset(ShillProfileClient::Create()); | |
139 } | |
140 | |
141 if (client_mask & GSM_SMS) | |
142 gsm_sms_client_.reset(GsmSMSClient::Create()); | |
143 | |
144 if (client_mask & IMAGE_BURNER) | |
145 image_burner_client_.reset(ImageBurnerClient::Create()); | |
146 | |
147 if (client_mask & INTROSPECTABLE) | |
148 introspectable_client_.reset(IntrospectableClient::Create()); | |
149 | |
150 if (client_mask & MODEM_MESSAGING) | |
151 modem_messaging_client_.reset(ModemMessagingClient::Create()); | |
152 | |
153 // Create the NFC clients in the correct order based on their dependencies. | |
154 if (client_mask & NFC) { | |
155 nfc_manager_client_.reset(NfcManagerClient::Create()); | |
156 nfc_adapter_client_.reset( | |
157 NfcAdapterClient::Create(nfc_manager_client_.get())); | |
158 nfc_device_client_.reset( | |
159 NfcDeviceClient::Create(nfc_adapter_client_.get())); | |
160 nfc_tag_client_.reset(NfcTagClient::Create(nfc_adapter_client_.get())); | |
161 nfc_record_client_.reset(NfcRecordClient::Create(nfc_device_client_.get(), | |
162 nfc_tag_client_.get())); | |
hashimoto
2014/08/08 02:06:15
nit: indent.
zel
2014/08/08 19:00:14
Done.
| |
163 } | |
164 | |
165 if (client_mask & PERMISSION_BROKER) | |
166 permission_broker_client_.reset(PermissionBrokerClient::Create()); | |
167 | |
168 if (client_mask & POWER_MANAGER) | |
169 power_manager_client_.reset(PowerManagerClient::Create(type)); | |
170 | |
171 if (client_mask & SESSION_MANAGER) | |
172 session_manager_client_.reset(SessionManagerClient::Create(type)); | |
173 | |
174 if (client_mask & SMS) | |
175 sms_client_.reset(SMSClient::Create()); | |
176 | |
177 if (client_mask & SYSTEM_CLOCK) | |
178 system_clock_client_.reset(SystemClockClient::Create()); | |
179 | |
180 if (client_mask & UPDATE_ENGINE) | |
181 update_engine_client_.reset(UpdateEngineClient::Create(type)); | |
hashimoto
2014/08/08 07:08:44
It seems POWER_POLICY is not handled.
zel
2014/08/08 19:00:14
POWER_POLICY client is for some reasons owned in D
satorux1
2014/08/11 01:52:09
hashimoto: good catch: Let's remove POWER_POLICY.
zel
2014/08/12 17:32:32
Done.
| |
182 } | |
183 | |
184 DBusClientBundle::~DBusClientBundle() { | |
185 } | |
186 | |
187 // static | |
188 unsigned int DBusClientBundle::ParseUnstubList(const std::string& unstub_list) { | |
189 unsigned int unstub_mask = 0; | |
190 std::vector<std::string> unstub_components; | |
191 base::SplitString(unstub_list, ',', &unstub_components); | |
192 for (std::vector<std::string>::const_iterator iter = | |
193 unstub_components.begin(); | |
194 iter != unstub_components.end(); ++iter) { | |
195 DBusClientBundle::DBusClientType client = GetDBusClientType(*iter); | |
196 if (client != DBusClientBundle::UNKNOWN) { | |
197 LOG(WARNING) << "Unstubbing dbus client for " << *iter; | |
198 unstub_mask |= client; | |
199 } | |
hashimoto
2014/08/08 02:06:15
nit: How about emitting an ERROR when client==UNKN
zel
2014/08/08 19:00:14
Done.
| |
200 } | |
201 | |
202 return unstub_mask; | |
203 } | |
204 | |
205 BluetoothAdapterClient* DBusClientBundle::bluetooth_adapter_client() { | |
206 return bluetooth_adapter_client_.get(); | |
hashimoto
2014/08/08 02:06:15
How about inlining these getters in the header?
zel
2014/08/08 19:00:14
Done.
| |
207 } | |
208 | |
209 BluetoothAgentManagerClient* | |
210 DBusClientBundle::bluetooth_agent_manager_client() { | |
211 return bluetooth_agent_manager_client_.get(); | |
212 } | |
213 | |
214 BluetoothDeviceClient* DBusClientBundle::bluetooth_device_client() { | |
215 return bluetooth_device_client_.get(); | |
216 } | |
217 | |
218 BluetoothGattCharacteristicClient* | |
219 DBusClientBundle::bluetooth_gatt_characteristic_client() { | |
220 return bluetooth_gatt_characteristic_client_.get(); | |
221 } | |
222 | |
223 BluetoothGattDescriptorClient* | |
224 DBusClientBundle::bluetooth_gatt_descriptor_client() { | |
225 return bluetooth_gatt_descriptor_client_.get(); | |
226 | |
227 } | |
228 BluetoothGattManagerClient* DBusClientBundle::bluetooth_gatt_manager_client() { | |
229 return bluetooth_gatt_manager_client_.get(); | |
230 } | |
231 | |
232 BluetoothGattServiceClient* DBusClientBundle::bluetooth_gatt_service_client() { | |
233 return bluetooth_gatt_service_client_.get(); | |
234 } | |
235 | |
236 BluetoothInputClient* DBusClientBundle::bluetooth_input_client() { | |
237 return bluetooth_input_client_.get(); | |
238 } | |
239 | |
240 BluetoothProfileManagerClient* | |
241 DBusClientBundle::bluetooth_profile_manager_client() { | |
242 return bluetooth_profile_manager_client_.get(); | |
243 } | |
244 | |
245 CrasAudioClient* DBusClientBundle::cras_audio_client() { | |
246 return cras_audio_client_.get(); | |
247 } | |
248 | |
249 CrosDisksClient* DBusClientBundle::cros_disks_client() { | |
250 return cros_disks_client_.get(); | |
251 } | |
252 | |
253 CryptohomeClient* DBusClientBundle::cryptohome_client() { | |
254 return cryptohome_client_.get(); | |
255 } | |
256 | |
257 DebugDaemonClient* DBusClientBundle::debug_daemon_client() { | |
258 return debug_daemon_client_.get(); | |
259 } | |
260 | |
261 EasyUnlockClient* DBusClientBundle::easy_unlock_client() { | |
262 return easy_unlock_client_.get(); | |
263 } | |
264 | |
265 LorgnetteManagerClient* DBusClientBundle::lorgnette_manager_client() { | |
266 return lorgnette_manager_client_.get(); | |
267 } | |
268 | |
269 ShillDeviceClient* DBusClientBundle::shill_device_client() { | |
270 return shill_device_client_.get(); | |
271 } | |
272 | |
273 ShillIPConfigClient* DBusClientBundle::shill_ipconfig_client() { | |
274 return shill_ipconfig_client_.get(); | |
275 } | |
276 | |
277 ShillManagerClient* DBusClientBundle::shill_manager_client() { | |
278 return shill_manager_client_.get(); | |
279 } | |
280 | |
281 ShillServiceClient* DBusClientBundle::shill_service_client() { | |
282 return shill_service_client_.get(); | |
283 } | |
284 | |
285 ShillProfileClient* DBusClientBundle::shill_profile_client() { | |
286 return shill_profile_client_.get(); | |
287 } | |
288 | |
289 GsmSMSClient* DBusClientBundle::gsm_sms_client() { | |
290 return gsm_sms_client_.get(); | |
291 } | |
292 | |
293 ImageBurnerClient* DBusClientBundle::image_burner_client() { | |
294 return image_burner_client_.get(); | |
295 } | |
296 | |
297 IntrospectableClient* DBusClientBundle::introspectable_client() { | |
298 return introspectable_client_.get(); | |
299 } | |
300 | |
301 ModemMessagingClient* DBusClientBundle::modem_messaging_client() { | |
302 return modem_messaging_client_.get(); | |
303 } | |
304 | |
305 NfcManagerClient* DBusClientBundle::nfc_manager_client() { | |
306 return nfc_manager_client_.get(); | |
307 } | |
308 | |
309 NfcAdapterClient* DBusClientBundle::nfc_adapter_client() { | |
310 return nfc_adapter_client_.get(); | |
311 } | |
312 | |
313 NfcDeviceClient* DBusClientBundle::nfc_device_client() { | |
314 return nfc_device_client_.get(); | |
315 } | |
316 | |
317 NfcTagClient* DBusClientBundle::nfc_tag_client() { | |
318 return nfc_tag_client_.get(); | |
319 } | |
320 | |
321 NfcRecordClient* DBusClientBundle::nfc_record_client() { | |
322 return nfc_record_client_.get(); | |
323 } | |
324 | |
325 PermissionBrokerClient* DBusClientBundle::permission_broker_client() { | |
326 return permission_broker_client_.get(); | |
327 } | |
328 | |
329 SystemClockClient* DBusClientBundle::system_clock_client() { | |
330 return system_clock_client_.get(); | |
331 } | |
332 | |
333 PowerManagerClient* DBusClientBundle::power_manager_client() { | |
334 return power_manager_client_.get(); | |
335 } | |
336 | |
337 SessionManagerClient* DBusClientBundle::session_manager_client() { | |
338 return session_manager_client_.get(); | |
339 } | |
340 | |
341 SMSClient* DBusClientBundle::sms_client() { | |
342 return sms_client_.get(); | |
343 } | |
344 | |
345 UpdateEngineClient* DBusClientBundle::update_engine_client() { | |
346 return update_engine_client_.get(); | |
347 } | |
348 | |
349 } // namespace chromeos | |
OLD | NEW |