blob: 2a457780ed6458caf90b13900c010c82ae5f2bfd [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
Chris Masoned7732e42011-05-20 11:08:56 -07009#include <dbus-c++/glib-integration.h>
10#include <dbus-c++/util.h>
11
Chris Masoned7732e42011-05-20 11:08:56 -070012#include "shill/device_dbus_adaptor.h"
Chris Masonec6c6c132011-06-30 11:29:52 -070013#include "shill/ipconfig_dbus_adaptor.h"
Christopher Wileyb691efd2012-08-09 13:51:51 -070014#include "shill/logging.h"
Chris Masoned7732e42011-05-20 11:08:56 -070015#include "shill/manager_dbus_adaptor.h"
Chris Masone52cd19b2011-06-29 17:23:04 -070016#include "shill/profile_dbus_adaptor.h"
Darin Petkova9b1fed2012-02-29 11:49:05 +010017#include "shill/rpc_task_dbus_adaptor.h"
Chris Masoned7732e42011-05-20 11:08:56 -070018#include "shill/service_dbus_adaptor.h"
Paul Stewart75897df2011-04-27 09:05:53 -070019
20namespace shill {
Darin Petkova9b1fed2012-02-29 11:49:05 +010021
Chris Masoned7732e42011-05-20 11:08:56 -070022DBusControl::DBusControl() {}
Paul Stewart75897df2011-04-27 09:05:53 -070023
Chris Masoned7732e42011-05-20 11:08:56 -070024DBusControl::~DBusControl() {}
Paul Stewart75897df2011-04-27 09:05:53 -070025
Chris Masone413a3192011-05-09 17:10:05 -070026DeviceAdaptorInterface *DBusControl::CreateDeviceAdaptor(Device *device) {
Wade Guthriee2e29242012-05-08 08:58:56 -070027 DeviceAdaptorInterface *result = NULL;
28 try {
29 result = new DeviceDBusAdaptor(connection_.get(), device);
30 } catch(const DBus::Error &error) {
31 LOG(ERROR) << error.message();
32 }
33 return result;
Paul Stewart75897df2011-04-27 09:05:53 -070034}
35
Chris Masonec6c6c132011-06-30 11:29:52 -070036IPConfigAdaptorInterface *DBusControl::CreateIPConfigAdaptor(IPConfig *config) {
Wade Guthriee2e29242012-05-08 08:58:56 -070037 IPConfigAdaptorInterface *result = NULL;
38 try {
39 result = new IPConfigDBusAdaptor(connection_.get(), config);
40 } catch(const DBus::Error &error) {
41 LOG(ERROR) << error.message();
42 }
43 return result;
Chris Masonec6c6c132011-06-30 11:29:52 -070044}
45
46ManagerAdaptorInterface *DBusControl::CreateManagerAdaptor(Manager *manager) {
Wade Guthriee2e29242012-05-08 08:58:56 -070047 ManagerAdaptorInterface *result = NULL;
48 try {
49 result = new ManagerDBusAdaptor(connection_.get(), manager);
50 } catch(const DBus::Error &error) {
51 LOG(ERROR) << error.message();
52 }
53 return result;
Chris Masonec6c6c132011-06-30 11:29:52 -070054}
55
Chris Masone52cd19b2011-06-29 17:23:04 -070056ProfileAdaptorInterface *DBusControl::CreateProfileAdaptor(Profile *profile) {
Wade Guthriee2e29242012-05-08 08:58:56 -070057 ProfileAdaptorInterface *result = NULL;
58 try {
59 result = new ProfileDBusAdaptor(connection_.get(), profile);
60 } catch(const DBus::Error &error) {
61 LOG(ERROR) << error.message();
62 }
63 return result;
Chris Masone52cd19b2011-06-29 17:23:04 -070064}
65
Darin Petkova9b1fed2012-02-29 11:49:05 +010066RPCTaskAdaptorInterface *DBusControl::CreateRPCTaskAdaptor(RPCTask *task) {
Wade Guthriee2e29242012-05-08 08:58:56 -070067 RPCTaskAdaptorInterface *result = NULL;
68 try {
69 result = new RPCTaskDBusAdaptor(connection_.get(), task);
70 } catch(const DBus::Error &error) {
71 LOG(ERROR) << error.message();
72 }
73 return result;
Darin Petkova9b1fed2012-02-29 11:49:05 +010074}
75
Chris Masonec6c6c132011-06-30 11:29:52 -070076ServiceAdaptorInterface *DBusControl::CreateServiceAdaptor(Service *service) {
Wade Guthriee2e29242012-05-08 08:58:56 -070077 ServiceAdaptorInterface *result = NULL;
78 try {
79 result = new ServiceDBusAdaptor(connection_.get(), service);
80 } catch(const DBus::Error &error) {
81 LOG(ERROR) << error.message();
82 }
83 return result;
Chris Masonec6c6c132011-06-30 11:29:52 -070084}
85
Darin Petkovd1b715b2011-06-02 21:21:22 -070086void DBusControl::Init() {
87 CHECK(!connection_.get());
88 dispatcher_.reset(new(std::nothrow) DBus::Glib::BusDispatcher());
89 CHECK(dispatcher_.get()) << "Failed to create a dbus-dispatcher";
90 DBus::default_dispatcher = dispatcher_.get();
91 dispatcher_->attach(NULL);
92 connection_.reset(new DBus::Connection(DBus::Connection::SystemBus()));
mukesh agrawald1511fe2012-03-14 17:12:27 -070093 connection_->request_name(SHILL_INTERFACE);
Chris Masoned7732e42011-05-20 11:08:56 -070094}
Paul Stewart75897df2011-04-27 09:05:53 -070095
96} // namespace shill