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 struct { | |
53 const char* param_name; | |
54 DBusClientBundle::DBusClientType client_type; | |
55 } client_type_map[] = { | |
hashimoto
2014/08/13 06:14:48
This should be const.
zel
2014/08/13 17:57:43
Done.
| |
56 { "bluetooth", DBusClientBundle::BLUETOOTH }, | |
57 { "bluetooth_low_energy", DBusClientBundle::BLUETOOTH_LOW_ENERGY }, | |
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 | |
hashimoto
2014/08/13 06:14:48
nit: Here should be a blank line.
zel
2014/08/13 17:57:43
Done.
| |
91 DBusClientBundle::DBusClientBundle() { | |
92 const DBusClientImplementationType type = REAL_DBUS_CLIENT_IMPLEMENTATION; | |
93 | |
94 if (!DBusThreadManager::IsUsingStub(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 (!DBusThreadManager::IsUsingStub(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 (!DBusThreadManager::IsUsingStub(CRAS)) | |
116 cras_audio_client_.reset(CrasAudioClient::Create()); | |
117 | |
118 if (!DBusThreadManager::IsUsingStub(CROS_DISKS)) | |
119 cros_disks_client_.reset(CrosDisksClient::Create(type)); | |
120 | |
121 if (!DBusThreadManager::IsUsingStub(CRYPTOHOME)) | |
122 cryptohome_client_.reset(CryptohomeClient::Create()); | |
123 | |
124 if (!DBusThreadManager::IsUsingStub(DEBUG_DAEMON)) | |
125 debug_daemon_client_.reset(DebugDaemonClient::Create()); | |
126 | |
127 if (!DBusThreadManager::IsUsingStub(EASY_UNLOCK)) | |
128 easy_unlock_client_.reset(EasyUnlockClient::Create()); | |
129 | |
130 if (!DBusThreadManager::IsUsingStub(LORGNETTE_MANAGER)) | |
131 lorgnette_manager_client_.reset(LorgnetteManagerClient::Create()); | |
132 | |
133 if (!DBusThreadManager::IsUsingStub(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 (!DBusThreadManager::IsUsingStub(GSM_SMS)) | |
142 gsm_sms_client_.reset(GsmSMSClient::Create()); | |
143 | |
144 if (!DBusThreadManager::IsUsingStub(IMAGE_BURNER)) | |
145 image_burner_client_.reset(ImageBurnerClient::Create()); | |
146 | |
147 if (!DBusThreadManager::IsUsingStub(INTROSPECTABLE)) | |
148 introspectable_client_.reset(IntrospectableClient::Create()); | |
149 | |
150 if (!DBusThreadManager::IsUsingStub(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 (!DBusThreadManager::IsUsingStub(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())); | |
163 } | |
164 | |
165 if (!DBusThreadManager::IsUsingStub(PERMISSION_BROKER)) | |
166 permission_broker_client_.reset(PermissionBrokerClient::Create()); | |
167 | |
168 if (!DBusThreadManager::IsUsingStub(POWER_MANAGER)) | |
169 power_manager_client_.reset(PowerManagerClient::Create(type)); | |
170 | |
171 if (!DBusThreadManager::IsUsingStub(SESSION_MANAGER)) | |
172 session_manager_client_.reset(SessionManagerClient::Create(type)); | |
173 | |
174 if (!DBusThreadManager::IsUsingStub(SMS)) | |
175 sms_client_.reset(SMSClient::Create()); | |
176 | |
177 if (!DBusThreadManager::IsUsingStub(SYSTEM_CLOCK)) | |
178 system_clock_client_.reset(SystemClockClient::Create()); | |
179 | |
180 if (!DBusThreadManager::IsUsingStub(UPDATE_ENGINE)) | |
181 update_engine_client_.reset(UpdateEngineClient::Create(type)); | |
182 } | |
183 | |
184 DBusClientBundle::~DBusClientBundle() { | |
185 } | |
186 | |
187 // static | |
188 DBusClientBundle::DBusClientTypeMask DBusClientBundle::ParseUnstubList( | |
189 const std::string& unstub_list) { | |
190 DBusClientTypeMask unstub_mask = 0; | |
191 std::vector<std::string> unstub_components; | |
192 base::SplitString(unstub_list, ',', &unstub_components); | |
193 for (std::vector<std::string>::const_iterator iter = | |
194 unstub_components.begin(); | |
195 iter != unstub_components.end(); ++iter) { | |
196 DBusClientBundle::DBusClientType client = GetDBusClientType(*iter); | |
197 if (client != DBusClientBundle::UNKNOWN) { | |
198 LOG(WARNING) << "Unstubbing dbus client for " << *iter; | |
199 unstub_mask |= client; | |
200 } else { | |
201 LOG(ERROR) << "Unknown dbus client: " << *iter; | |
202 } | |
203 } | |
204 | |
205 return unstub_mask; | |
206 } | |
207 | |
208 } // namespace chromeos | |
OLD | NEW |