blob: 3d6e45b32fe0e766f8169ae74c0b7cff13eec32c [file] [log] [blame]
Darin Petkova9b1fed2012-02-29 11:49:05 +01001// Copyright (c) 2012 The Chromium OS Authors. All rights reserved.
Paul Stewart75897df2011-04-27 09:05:53 -07002// Use of this source code is governed by a BSD-style license that can be
3// found in the LICENSE file.
4
Darin Petkova9b1fed2012-02-29 11:49:05 +01005#include "shill/dbus_control.h"
6
Paul Stewart75897df2011-04-27 09:05:53 -07007#include <string>
8
Paul Stewart8dc5e7b2014-12-11 19:24:50 -08009#include <dbus-c++/dbus.h>
Chris Masoned7732e42011-05-20 11:08:56 -070010
Chris Masoned7732e42011-05-20 11:08:56 -070011#include "shill/device_dbus_adaptor.h"
Chris Masonec6c6c132011-06-30 11:29:52 -070012#include "shill/ipconfig_dbus_adaptor.h"
Christopher Wileyb691efd2012-08-09 13:51:51 -070013#include "shill/logging.h"
Chris Masoned7732e42011-05-20 11:08:56 -070014#include "shill/manager_dbus_adaptor.h"
Chris Masone52cd19b2011-06-29 17:23:04 -070015#include "shill/profile_dbus_adaptor.h"
Darin Petkova9b1fed2012-02-29 11:49:05 +010016#include "shill/rpc_task_dbus_adaptor.h"
Chris Masoned7732e42011-05-20 11:08:56 -070017#include "shill/service_dbus_adaptor.h"
Paul Stewart8dc5e7b2014-12-11 19:24:50 -080018#include "shill/shared_dbus_connection.h"
Ben Chan2240e8c2014-11-06 13:37:18 -080019#include "shill/vpn/third_party_vpn_dbus_adaptor.h"
Paul Stewart75897df2011-04-27 09:05:53 -070020
21namespace shill {
Darin Petkova9b1fed2012-02-29 11:49:05 +010022
Chris Masoned7732e42011-05-20 11:08:56 -070023DBusControl::DBusControl() {}
Paul Stewart75897df2011-04-27 09:05:53 -070024
Chris Masoned7732e42011-05-20 11:08:56 -070025DBusControl::~DBusControl() {}
Paul Stewart75897df2011-04-27 09:05:53 -070026
Ben Chan3d0e8d22014-07-10 23:40:47 -070027template <typename Object, typename AdaptorInterface, typename Adaptor>
28AdaptorInterface *DBusControl::CreateAdaptor(Object *object) {
Ben Chancc225ef2014-09-30 13:26:51 -070029 AdaptorInterface *adaptor = nullptr;
Wade Guthriee2e29242012-05-08 08:58:56 -070030 try {
Paul Stewart8dc5e7b2014-12-11 19:24:50 -080031 adaptor = new Adaptor(GetConnection(), object);
Ben Chan3d0e8d22014-07-10 23:40:47 -070032 } catch(const DBus::ErrorObjectPathInUse &error) {
33 LOG(FATAL) << error.message() << " (object path in use)";
34 } catch(const DBus::ErrorNoMemory &error) {
35 LOG(FATAL) << error.message() << " (no memory)";
Wade Guthriee2e29242012-05-08 08:58:56 -070036 } catch(const DBus::Error &error) {
Ben Chan7fe43b82014-03-06 15:36:33 -080037 LOG(FATAL) << error.message();
Wade Guthriee2e29242012-05-08 08:58:56 -070038 }
Ben Chan3d0e8d22014-07-10 23:40:47 -070039 return adaptor;
40}
41
42DeviceAdaptorInterface *DBusControl::CreateDeviceAdaptor(Device *device) {
43 return CreateAdaptor<Device, DeviceAdaptorInterface, DeviceDBusAdaptor>(
44 device);
Paul Stewart75897df2011-04-27 09:05:53 -070045}
46
Chris Masonec6c6c132011-06-30 11:29:52 -070047IPConfigAdaptorInterface *DBusControl::CreateIPConfigAdaptor(IPConfig *config) {
Ben Chan3d0e8d22014-07-10 23:40:47 -070048 return CreateAdaptor<IPConfig, IPConfigAdaptorInterface, IPConfigDBusAdaptor>(
49 config);
Chris Masonec6c6c132011-06-30 11:29:52 -070050}
51
52ManagerAdaptorInterface *DBusControl::CreateManagerAdaptor(Manager *manager) {
Ben Chan3d0e8d22014-07-10 23:40:47 -070053 return CreateAdaptor<Manager, ManagerAdaptorInterface, ManagerDBusAdaptor>(
54 manager);
Chris Masonec6c6c132011-06-30 11:29:52 -070055}
56
Chris Masone52cd19b2011-06-29 17:23:04 -070057ProfileAdaptorInterface *DBusControl::CreateProfileAdaptor(Profile *profile) {
Ben Chan3d0e8d22014-07-10 23:40:47 -070058 return CreateAdaptor<Profile, ProfileAdaptorInterface, ProfileDBusAdaptor>(
59 profile);
Chris Masone52cd19b2011-06-29 17:23:04 -070060}
61
Darin Petkova9b1fed2012-02-29 11:49:05 +010062RPCTaskAdaptorInterface *DBusControl::CreateRPCTaskAdaptor(RPCTask *task) {
Ben Chan3d0e8d22014-07-10 23:40:47 -070063 return CreateAdaptor<RPCTask, RPCTaskAdaptorInterface, RPCTaskDBusAdaptor>(
64 task);
Darin Petkova9b1fed2012-02-29 11:49:05 +010065}
66
Chris Masonec6c6c132011-06-30 11:29:52 -070067ServiceAdaptorInterface *DBusControl::CreateServiceAdaptor(Service *service) {
Ben Chan3d0e8d22014-07-10 23:40:47 -070068 return CreateAdaptor<Service, ServiceAdaptorInterface, ServiceDBusAdaptor>(
69 service);
Chris Masonec6c6c132011-06-30 11:29:52 -070070}
71
Prabhu Kaliamoorthi127b3412014-10-16 13:00:25 +020072#ifndef DISABLE_VPN
73ThirdPartyVpnAdaptorInterface *DBusControl::CreateThirdPartyVpnAdaptor(
74 ThirdPartyVpnDriver *driver) {
75 return CreateAdaptor<ThirdPartyVpnDriver, ThirdPartyVpnAdaptorInterface,
76 ThirdPartyVpnAdaptor>(driver);
77}
78#endif
79
Darin Petkovd1b715b2011-06-02 21:21:22 -070080void DBusControl::Init() {
Paul Stewart8dc5e7b2014-12-11 19:24:50 -080081 if (!GetConnection()->acquire_name(SHILL_INTERFACE)) {
mukesh agrawal4041a1c2014-04-15 14:49:59 -070082 LOG(FATAL) << "Failed to acquire D-Bus name " << SHILL_INTERFACE << ". "
83 << "Is another shill running?";
84 }
Chris Masoned7732e42011-05-20 11:08:56 -070085}
Paul Stewart75897df2011-04-27 09:05:53 -070086
Paul Stewart8dc5e7b2014-12-11 19:24:50 -080087DBus::Connection *DBusControl::GetConnection() const {
Paul Stewart04f00c62015-01-08 15:59:10 -080088 return SharedDBusConnection::GetInstance()->GetAdaptorConnection();
Paul Stewart8dc5e7b2014-12-11 19:24:50 -080089}
90
Paul Stewart75897df2011-04-27 09:05:53 -070091} // namespace shill