Chromium Code Reviews| Index: chromeos/dbus/dbus_client_bundle.cc |
| diff --git a/chromeos/dbus/dbus_client_bundle.cc b/chromeos/dbus/dbus_client_bundle.cc |
| new file mode 100644 |
| index 0000000000000000000000000000000000000000..bbf61bfad3a8e7d357e00155db13d885696dc4eb |
| --- /dev/null |
| +++ b/chromeos/dbus/dbus_client_bundle.cc |
| @@ -0,0 +1,349 @@ |
| +// Copyright (c) 2014 The Chromium Authors. All rights reserved. |
| +// Use of this source code is governed by a BSD-style license that can be |
| +// found in the LICENSE file. |
| + |
| +#include "chromeos/dbus/dbus_client_bundle.h" |
| + |
| +#include "base/strings/string_split.h" |
| +#include "base/strings/string_util.h" |
| +#include "chromeos/dbus/bluetooth_adapter_client.h" |
| +#include "chromeos/dbus/bluetooth_agent_manager_client.h" |
| +#include "chromeos/dbus/bluetooth_device_client.h" |
| +#include "chromeos/dbus/bluetooth_gatt_characteristic_client.h" |
| +#include "chromeos/dbus/bluetooth_gatt_descriptor_client.h" |
| +#include "chromeos/dbus/bluetooth_gatt_manager_client.h" |
| +#include "chromeos/dbus/bluetooth_gatt_service_client.h" |
| +#include "chromeos/dbus/bluetooth_input_client.h" |
| +#include "chromeos/dbus/bluetooth_profile_manager_client.h" |
| +#include "chromeos/dbus/cras_audio_client.h" |
| +#include "chromeos/dbus/cros_disks_client.h" |
| +#include "chromeos/dbus/cryptohome_client.h" |
| +#include "chromeos/dbus/debug_daemon_client.h" |
| +#include "chromeos/dbus/easy_unlock_client.h" |
| +#include "chromeos/dbus/gsm_sms_client.h" |
| +#include "chromeos/dbus/image_burner_client.h" |
| +#include "chromeos/dbus/introspectable_client.h" |
| +#include "chromeos/dbus/lorgnette_manager_client.h" |
| +#include "chromeos/dbus/modem_messaging_client.h" |
| +#include "chromeos/dbus/nfc_adapter_client.h" |
| +#include "chromeos/dbus/nfc_device_client.h" |
| +#include "chromeos/dbus/nfc_manager_client.h" |
| +#include "chromeos/dbus/nfc_record_client.h" |
| +#include "chromeos/dbus/nfc_tag_client.h" |
| +#include "chromeos/dbus/permission_broker_client.h" |
| +#include "chromeos/dbus/power_manager_client.h" |
| +#include "chromeos/dbus/power_policy_controller.h" |
| +#include "chromeos/dbus/session_manager_client.h" |
| +#include "chromeos/dbus/shill_device_client.h" |
| +#include "chromeos/dbus/shill_ipconfig_client.h" |
| +#include "chromeos/dbus/shill_manager_client.h" |
| +#include "chromeos/dbus/shill_profile_client.h" |
| +#include "chromeos/dbus/shill_service_client.h" |
| +#include "chromeos/dbus/sms_client.h" |
| +#include "chromeos/dbus/system_clock_client.h" |
| +#include "chromeos/dbus/update_engine_client.h" |
| + |
| +namespace chromeos { |
| + |
| +namespace { |
| + |
| +// Command line switch mapping for --dbus-unstub-clients. |
| +struct { |
| + const char* param_name; |
| + DBusClientBundle::DBusClientType client_type; |
| +} client_type_map[] = { |
| + { "bluetooth", DBusClientBundle::BLUETOOTH }, |
| + { "bluetoothlowenergy", DBusClientBundle::BLUETOOTH_LOW_ENERGY }, |
| + { "cras", DBusClientBundle::CRAS }, |
| + { "crosdisks", DBusClientBundle::CROS_DISKS }, |
| + { "cryptohome", DBusClientBundle::CRYPTOHOME }, |
| + { "debugdaemon", DBusClientBundle::DEBUG_DAEMON }, |
| + { "easyunlock", DBusClientBundle::EASY_UNLOCK }, |
| + { "lorgnettemanager", DBusClientBundle::LORGNETTE_MANAGER }, |
| + { "shill", DBusClientBundle::SHILL }, |
| + { "gsmsms", DBusClientBundle::GSM_SMS }, |
| + { "imageburner", DBusClientBundle::IMAGE_BURNER }, |
| + { "introspectable", DBusClientBundle::INTROSPECTABLE }, |
| + { "modemmessaging", DBusClientBundle::MODEM_MESSAGING }, |
| + { "nfc", DBusClientBundle::NFC }, |
| + { "permissionbroker", DBusClientBundle::PERMISSION_BROKER }, |
| + { "powermanager", DBusClientBundle::POWER_MANAGER }, |
| + { "powerpolicy", DBusClientBundle::POWER_POLICY }, |
| + { "sessionmanager", DBusClientBundle::SESSION_MANAGER }, |
| + { "sms", DBusClientBundle::SMS }, |
| + { "systemclock", DBusClientBundle::SYSTEM_CLOCK }, |
| + { "updateengine", DBusClientBundle::UPDATE_ENGINE }, |
| +}; |
| + |
| +// Parses single command line param value for dbus subsystem and returns its |
| +// enum representation. DBusClientType::UNKWNOWN is returned if |client_type| |
| +// does not match any known dbus client. |
| +DBusClientBundle::DBusClientType GetDBusClientType( |
| + const std::string& client_type) { |
| + for (size_t i = 0; i < arraysize(client_type_map); i++) { |
| + if (LowerCaseEqualsASCII(client_type, client_type_map[i].param_name)) |
| + return client_type_map[i].client_type; |
| + } |
| + return DBusClientBundle::UNKNOWN; |
| +} |
| + |
| +} // namespace |
| +DBusClientBundle::DBusClientBundle(unsigned int client_mask) { |
| + const DBusClientImplementationType type = REAL_DBUS_CLIENT_IMPLEMENTATION; |
| + |
| + if (client_mask & BLUETOOTH) { |
| + bluetooth_adapter_client_.reset(BluetoothAdapterClient::Create()); |
| + bluetooth_agent_manager_client_.reset( |
| + BluetoothAgentManagerClient::Create()); |
| + bluetooth_device_client_.reset(BluetoothDeviceClient::Create()); |
| + bluetooth_input_client_.reset(BluetoothInputClient::Create()); |
| + bluetooth_profile_manager_client_.reset( |
| + BluetoothProfileManagerClient::Create()); |
| + } |
| + |
| + if (client_mask & BLUETOOTH_LOW_ENERGY) { |
| + bluetooth_gatt_characteristic_client_.reset( |
| + BluetoothGattCharacteristicClient::Create()); |
| + bluetooth_gatt_descriptor_client_.reset( |
| + BluetoothGattDescriptorClient::Create()); |
| + bluetooth_gatt_manager_client_.reset( |
| + BluetoothGattManagerClient::Create()); |
| + bluetooth_gatt_service_client_.reset( |
| + BluetoothGattServiceClient::Create()); |
| + } |
| + |
| + if (client_mask & CRAS) |
| + cras_audio_client_.reset(CrasAudioClient::Create()); |
| + |
| + if (client_mask & CROS_DISKS) |
| + cros_disks_client_.reset(CrosDisksClient::Create(type)); |
| + |
| + if (client_mask & CRYPTOHOME) |
| + cryptohome_client_.reset(CryptohomeClient::Create()); |
|
hashimoto
2014/08/08 02:06:15
nit: indent.
zel
2014/08/08 19:00:14
Done.
|
| + |
| + if (client_mask & DEBUG_DAEMON) |
| + debug_daemon_client_.reset(DebugDaemonClient::Create()); |
|
hashimoto
2014/08/08 02:06:15
ditto.
zel
2014/08/08 19:00:14
Done.
|
| + |
| + if (client_mask & EASY_UNLOCK) |
| + easy_unlock_client_.reset(EasyUnlockClient::Create()); |
|
hashimoto
2014/08/08 02:06:15
ditto.
zel
2014/08/08 19:00:14
Done.
|
| + |
| + if (client_mask & LORGNETTE_MANAGER) |
| + lorgnette_manager_client_.reset(LorgnetteManagerClient::Create()); |
| + |
| + if (client_mask & SHILL) { |
| + shill_manager_client_.reset(ShillManagerClient::Create()); |
| + shill_device_client_.reset(ShillDeviceClient::Create()); |
| + shill_ipconfig_client_.reset(ShillIPConfigClient::Create()); |
| + shill_service_client_.reset(ShillServiceClient::Create()); |
| + shill_profile_client_.reset(ShillProfileClient::Create()); |
| + } |
| + |
| + if (client_mask & GSM_SMS) |
| + gsm_sms_client_.reset(GsmSMSClient::Create()); |
| + |
| + if (client_mask & IMAGE_BURNER) |
| + image_burner_client_.reset(ImageBurnerClient::Create()); |
| + |
| + if (client_mask & INTROSPECTABLE) |
| + introspectable_client_.reset(IntrospectableClient::Create()); |
| + |
| + if (client_mask & MODEM_MESSAGING) |
| + modem_messaging_client_.reset(ModemMessagingClient::Create()); |
| + |
| + // Create the NFC clients in the correct order based on their dependencies. |
| + if (client_mask & NFC) { |
| + nfc_manager_client_.reset(NfcManagerClient::Create()); |
| + nfc_adapter_client_.reset( |
| + NfcAdapterClient::Create(nfc_manager_client_.get())); |
| + nfc_device_client_.reset( |
| + NfcDeviceClient::Create(nfc_adapter_client_.get())); |
| + nfc_tag_client_.reset(NfcTagClient::Create(nfc_adapter_client_.get())); |
| + nfc_record_client_.reset(NfcRecordClient::Create(nfc_device_client_.get(), |
| + nfc_tag_client_.get())); |
|
hashimoto
2014/08/08 02:06:15
nit: indent.
zel
2014/08/08 19:00:14
Done.
|
| + } |
| + |
| + if (client_mask & PERMISSION_BROKER) |
| + permission_broker_client_.reset(PermissionBrokerClient::Create()); |
| + |
| + if (client_mask & POWER_MANAGER) |
| + power_manager_client_.reset(PowerManagerClient::Create(type)); |
| + |
| + if (client_mask & SESSION_MANAGER) |
| + session_manager_client_.reset(SessionManagerClient::Create(type)); |
| + |
| + if (client_mask & SMS) |
| + sms_client_.reset(SMSClient::Create()); |
| + |
| + if (client_mask & SYSTEM_CLOCK) |
| + system_clock_client_.reset(SystemClockClient::Create()); |
| + |
| + if (client_mask & UPDATE_ENGINE) |
| + 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.
|
| +} |
| + |
| +DBusClientBundle::~DBusClientBundle() { |
| +} |
| + |
| +// static |
| +unsigned int DBusClientBundle::ParseUnstubList(const std::string& unstub_list) { |
| + unsigned int unstub_mask = 0; |
| + std::vector<std::string> unstub_components; |
| + base::SplitString(unstub_list, ',', &unstub_components); |
| + for (std::vector<std::string>::const_iterator iter = |
| + unstub_components.begin(); |
| + iter != unstub_components.end(); ++iter) { |
| + DBusClientBundle::DBusClientType client = GetDBusClientType(*iter); |
| + if (client != DBusClientBundle::UNKNOWN) { |
| + LOG(WARNING) << "Unstubbing dbus client for " << *iter; |
| + unstub_mask |= client; |
| + } |
|
hashimoto
2014/08/08 02:06:15
nit: How about emitting an ERROR when client==UNKN
zel
2014/08/08 19:00:14
Done.
|
| + } |
| + |
| + return unstub_mask; |
| +} |
| + |
| +BluetoothAdapterClient* DBusClientBundle::bluetooth_adapter_client() { |
| + 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.
|
| +} |
| + |
| +BluetoothAgentManagerClient* |
| +DBusClientBundle::bluetooth_agent_manager_client() { |
| + return bluetooth_agent_manager_client_.get(); |
| +} |
| + |
| +BluetoothDeviceClient* DBusClientBundle::bluetooth_device_client() { |
| + return bluetooth_device_client_.get(); |
| +} |
| + |
| +BluetoothGattCharacteristicClient* |
| +DBusClientBundle::bluetooth_gatt_characteristic_client() { |
| + return bluetooth_gatt_characteristic_client_.get(); |
| +} |
| + |
| +BluetoothGattDescriptorClient* |
| +DBusClientBundle::bluetooth_gatt_descriptor_client() { |
| + return bluetooth_gatt_descriptor_client_.get(); |
| + |
| +} |
| +BluetoothGattManagerClient* DBusClientBundle::bluetooth_gatt_manager_client() { |
| + return bluetooth_gatt_manager_client_.get(); |
| +} |
| + |
| +BluetoothGattServiceClient* DBusClientBundle::bluetooth_gatt_service_client() { |
| + return bluetooth_gatt_service_client_.get(); |
| +} |
| + |
| +BluetoothInputClient* DBusClientBundle::bluetooth_input_client() { |
| + return bluetooth_input_client_.get(); |
| +} |
| + |
| +BluetoothProfileManagerClient* |
| +DBusClientBundle::bluetooth_profile_manager_client() { |
| + return bluetooth_profile_manager_client_.get(); |
| +} |
| + |
| +CrasAudioClient* DBusClientBundle::cras_audio_client() { |
| + return cras_audio_client_.get(); |
| +} |
| + |
| +CrosDisksClient* DBusClientBundle::cros_disks_client() { |
| + return cros_disks_client_.get(); |
| +} |
| + |
| +CryptohomeClient* DBusClientBundle::cryptohome_client() { |
| + return cryptohome_client_.get(); |
| +} |
| + |
| +DebugDaemonClient* DBusClientBundle::debug_daemon_client() { |
| + return debug_daemon_client_.get(); |
| +} |
| + |
| +EasyUnlockClient* DBusClientBundle::easy_unlock_client() { |
| + return easy_unlock_client_.get(); |
| +} |
| + |
| +LorgnetteManagerClient* DBusClientBundle::lorgnette_manager_client() { |
| + return lorgnette_manager_client_.get(); |
| +} |
| + |
| +ShillDeviceClient* DBusClientBundle::shill_device_client() { |
| + return shill_device_client_.get(); |
| +} |
| + |
| +ShillIPConfigClient* DBusClientBundle::shill_ipconfig_client() { |
| + return shill_ipconfig_client_.get(); |
| +} |
| + |
| +ShillManagerClient* DBusClientBundle::shill_manager_client() { |
| + return shill_manager_client_.get(); |
| +} |
| + |
| +ShillServiceClient* DBusClientBundle::shill_service_client() { |
| + return shill_service_client_.get(); |
| +} |
| + |
| +ShillProfileClient* DBusClientBundle::shill_profile_client() { |
| + return shill_profile_client_.get(); |
| +} |
| + |
| +GsmSMSClient* DBusClientBundle::gsm_sms_client() { |
| + return gsm_sms_client_.get(); |
| +} |
| + |
| +ImageBurnerClient* DBusClientBundle::image_burner_client() { |
| + return image_burner_client_.get(); |
| +} |
| + |
| +IntrospectableClient* DBusClientBundle::introspectable_client() { |
| + return introspectable_client_.get(); |
| +} |
| + |
| +ModemMessagingClient* DBusClientBundle::modem_messaging_client() { |
| + return modem_messaging_client_.get(); |
| +} |
| + |
| +NfcManagerClient* DBusClientBundle::nfc_manager_client() { |
| + return nfc_manager_client_.get(); |
| +} |
| + |
| +NfcAdapterClient* DBusClientBundle::nfc_adapter_client() { |
| + return nfc_adapter_client_.get(); |
| +} |
| + |
| +NfcDeviceClient* DBusClientBundle::nfc_device_client() { |
| + return nfc_device_client_.get(); |
| +} |
| + |
| +NfcTagClient* DBusClientBundle::nfc_tag_client() { |
| + return nfc_tag_client_.get(); |
| +} |
| + |
| +NfcRecordClient* DBusClientBundle::nfc_record_client() { |
| + return nfc_record_client_.get(); |
| +} |
| + |
| +PermissionBrokerClient* DBusClientBundle::permission_broker_client() { |
| + return permission_broker_client_.get(); |
| +} |
| + |
| +SystemClockClient* DBusClientBundle::system_clock_client() { |
| + return system_clock_client_.get(); |
| +} |
| + |
| +PowerManagerClient* DBusClientBundle::power_manager_client() { |
| + return power_manager_client_.get(); |
| +} |
| + |
| +SessionManagerClient* DBusClientBundle::session_manager_client() { |
| + return session_manager_client_.get(); |
| +} |
| + |
| +SMSClient* DBusClientBundle::sms_client() { |
| + return sms_client_.get(); |
| +} |
| + |
| +UpdateEngineClient* DBusClientBundle::update_engine_client() { |
| + return update_engine_client_.get(); |
| +} |
| + |
| +} // namespace chromeos |