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/dbus_thread_manager.h" | |
22 #include "chromeos/dbus/debug_daemon_client.h" | |
23 #include "chromeos/dbus/easy_unlock_client.h" | |
24 #include "chromeos/dbus/gsm_sms_client.h" | |
25 #include "chromeos/dbus/image_burner_client.h" | |
26 #include "chromeos/dbus/introspectable_client.h" | |
27 #include "chromeos/dbus/lorgnette_manager_client.h" | |
28 #include "chromeos/dbus/modem_messaging_client.h" | |
29 #include "chromeos/dbus/nfc_adapter_client.h" | |
30 #include "chromeos/dbus/nfc_device_client.h" | |
31 #include "chromeos/dbus/nfc_manager_client.h" | |
32 #include "chromeos/dbus/nfc_record_client.h" | |
33 #include "chromeos/dbus/nfc_tag_client.h" | |
34 #include "chromeos/dbus/permission_broker_client.h" | |
35 #include "chromeos/dbus/power_manager_client.h" | |
36 #include "chromeos/dbus/power_policy_controller.h" | |
37 #include "chromeos/dbus/session_manager_client.h" | |
38 #include "chromeos/dbus/shill_device_client.h" | |
39 #include "chromeos/dbus/shill_ipconfig_client.h" | |
40 #include "chromeos/dbus/shill_manager_client.h" | |
41 #include "chromeos/dbus/shill_profile_client.h" | |
42 #include "chromeos/dbus/shill_service_client.h" | |
43 #include "chromeos/dbus/sms_client.h" | |
44 #include "chromeos/dbus/system_clock_client.h" | |
45 #include "chromeos/dbus/update_engine_client.h" | |
46 | |
47 namespace chromeos { | |
48 | |
49 namespace { | |
50 | |
51 // Command line switch mapping for --dbus-unstub-clients. | |
52 const struct { | |
53 const char* param_name; | |
54 DBusClientBundle::DBusClientType client_type; | |
55 } client_type_map[] = { | |
56 { "bluetooth", DBusClientBundle::BLUETOOTH }, | |
57 { "bluetooth_low_energy", DBusClientBundle::BLUETOOTH_LOW_ENERGY }, | |
armansito
2014/08/13 21:09:13
What's the reason for having two separate flags fo
zel
2014/08/13 22:22:40
I was suspecting that some systems might support B
armansito
2014/08/13 22:28:46
Per our offline discussion, let's merge these two
zel
2014/08/13 22:35:54
Done.
| |
58 { "cras", DBusClientBundle::CRAS }, | |
59 { "cros_disks", DBusClientBundle::CROS_DISKS }, | |
60 { "cryptohome", DBusClientBundle::CRYPTOHOME }, | |
61 { "debug_daemon", DBusClientBundle::DEBUG_DAEMON }, | |
62 { "easy_unlock", DBusClientBundle::EASY_UNLOCK }, | |
63 { "lorgnette_manager", DBusClientBundle::LORGNETTE_MANAGER }, | |
64 { "shill", DBusClientBundle::SHILL }, | |
65 { "gsm_sms", DBusClientBundle::GSM_SMS }, | |
66 { "image_burner", DBusClientBundle::IMAGE_BURNER }, | |
67 { "introspectable", DBusClientBundle::INTROSPECTABLE }, | |
68 { "modem_messaging", DBusClientBundle::MODEM_MESSAGING }, | |
69 { "nfc", DBusClientBundle::NFC }, | |
70 { "permission_broker", DBusClientBundle::PERMISSION_BROKER }, | |
71 { "power_manager", DBusClientBundle::POWER_MANAGER }, | |
72 { "session_manager", DBusClientBundle::SESSION_MANAGER }, | |
73 { "sms", DBusClientBundle::SMS }, | |
74 { "system_clock", DBusClientBundle::SYSTEM_CLOCK }, | |
75 { "update_engine", 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 | |
92 DBusClientBundle::DBusClientBundle() { | |
93 const DBusClientImplementationType type = REAL_DBUS_CLIENT_IMPLEMENTATION; | |
94 | |
95 if (!DBusThreadManager::IsUsingStub(BLUETOOTH)) { | |
96 bluetooth_adapter_client_.reset(BluetoothAdapterClient::Create()); | |
97 bluetooth_agent_manager_client_.reset( | |
98 BluetoothAgentManagerClient::Create()); | |
99 bluetooth_device_client_.reset(BluetoothDeviceClient::Create()); | |
100 bluetooth_input_client_.reset(BluetoothInputClient::Create()); | |
101 bluetooth_profile_manager_client_.reset( | |
102 BluetoothProfileManagerClient::Create()); | |
103 } | |
104 | |
105 if (!DBusThreadManager::IsUsingStub(BLUETOOTH_LOW_ENERGY)) { | |
106 bluetooth_gatt_characteristic_client_.reset( | |
107 BluetoothGattCharacteristicClient::Create()); | |
108 bluetooth_gatt_descriptor_client_.reset( | |
109 BluetoothGattDescriptorClient::Create()); | |
110 bluetooth_gatt_manager_client_.reset( | |
111 BluetoothGattManagerClient::Create()); | |
112 bluetooth_gatt_service_client_.reset( | |
113 BluetoothGattServiceClient::Create()); | |
114 } | |
115 | |
116 if (!DBusThreadManager::IsUsingStub(CRAS)) | |
117 cras_audio_client_.reset(CrasAudioClient::Create()); | |
118 | |
119 if (!DBusThreadManager::IsUsingStub(CROS_DISKS)) | |
120 cros_disks_client_.reset(CrosDisksClient::Create(type)); | |
121 | |
122 if (!DBusThreadManager::IsUsingStub(CRYPTOHOME)) | |
123 cryptohome_client_.reset(CryptohomeClient::Create()); | |
124 | |
125 if (!DBusThreadManager::IsUsingStub(DEBUG_DAEMON)) | |
126 debug_daemon_client_.reset(DebugDaemonClient::Create()); | |
127 | |
128 if (!DBusThreadManager::IsUsingStub(EASY_UNLOCK)) | |
129 easy_unlock_client_.reset(EasyUnlockClient::Create()); | |
130 | |
131 if (!DBusThreadManager::IsUsingStub(LORGNETTE_MANAGER)) | |
132 lorgnette_manager_client_.reset(LorgnetteManagerClient::Create()); | |
133 | |
134 if (!DBusThreadManager::IsUsingStub(SHILL)) { | |
135 shill_manager_client_.reset(ShillManagerClient::Create()); | |
136 shill_device_client_.reset(ShillDeviceClient::Create()); | |
137 shill_ipconfig_client_.reset(ShillIPConfigClient::Create()); | |
138 shill_service_client_.reset(ShillServiceClient::Create()); | |
139 shill_profile_client_.reset(ShillProfileClient::Create()); | |
140 } | |
141 | |
142 if (!DBusThreadManager::IsUsingStub(GSM_SMS)) | |
143 gsm_sms_client_.reset(GsmSMSClient::Create()); | |
144 | |
145 if (!DBusThreadManager::IsUsingStub(IMAGE_BURNER)) | |
146 image_burner_client_.reset(ImageBurnerClient::Create()); | |
147 | |
148 if (!DBusThreadManager::IsUsingStub(INTROSPECTABLE)) | |
149 introspectable_client_.reset(IntrospectableClient::Create()); | |
150 | |
151 if (!DBusThreadManager::IsUsingStub(MODEM_MESSAGING)) | |
152 modem_messaging_client_.reset(ModemMessagingClient::Create()); | |
153 | |
154 // Create the NFC clients in the correct order based on their dependencies. | |
155 if (!DBusThreadManager::IsUsingStub(NFC)) { | |
156 nfc_manager_client_.reset(NfcManagerClient::Create()); | |
157 nfc_adapter_client_.reset( | |
158 NfcAdapterClient::Create(nfc_manager_client_.get())); | |
159 nfc_device_client_.reset( | |
160 NfcDeviceClient::Create(nfc_adapter_client_.get())); | |
161 nfc_tag_client_.reset(NfcTagClient::Create(nfc_adapter_client_.get())); | |
162 nfc_record_client_.reset(NfcRecordClient::Create(nfc_device_client_.get(), | |
163 nfc_tag_client_.get())); | |
164 } | |
165 | |
166 if (!DBusThreadManager::IsUsingStub(PERMISSION_BROKER)) | |
167 permission_broker_client_.reset(PermissionBrokerClient::Create()); | |
168 | |
169 if (!DBusThreadManager::IsUsingStub(POWER_MANAGER)) | |
170 power_manager_client_.reset(PowerManagerClient::Create(type)); | |
171 | |
172 if (!DBusThreadManager::IsUsingStub(SESSION_MANAGER)) | |
173 session_manager_client_.reset(SessionManagerClient::Create(type)); | |
174 | |
175 if (!DBusThreadManager::IsUsingStub(SMS)) | |
176 sms_client_.reset(SMSClient::Create()); | |
177 | |
178 if (!DBusThreadManager::IsUsingStub(SYSTEM_CLOCK)) | |
179 system_clock_client_.reset(SystemClockClient::Create()); | |
180 | |
181 if (!DBusThreadManager::IsUsingStub(UPDATE_ENGINE)) | |
182 update_engine_client_.reset(UpdateEngineClient::Create(type)); | |
183 } | |
184 | |
185 DBusClientBundle::~DBusClientBundle() { | |
186 } | |
187 | |
188 // static | |
189 DBusClientBundle::DBusClientTypeMask DBusClientBundle::ParseUnstubList( | |
190 const std::string& unstub_list) { | |
191 DBusClientTypeMask unstub_mask = 0; | |
192 std::vector<std::string> unstub_components; | |
193 base::SplitString(unstub_list, ',', &unstub_components); | |
194 for (std::vector<std::string>::const_iterator iter = | |
195 unstub_components.begin(); | |
196 iter != unstub_components.end(); ++iter) { | |
197 DBusClientBundle::DBusClientType client = GetDBusClientType(*iter); | |
198 if (client != DBusClientBundle::UNKNOWN) { | |
199 LOG(WARNING) << "Unstubbing dbus client for " << *iter; | |
200 unstub_mask |= client; | |
201 } else { | |
202 LOG(ERROR) << "Unknown dbus client: " << *iter; | |
203 } | |
204 } | |
205 | |
206 return unstub_mask; | |
207 } | |
208 | |
209 } // namespace chromeos | |
OLD | NEW |