blob: 12a89a4fba8d01c9ada8211d86aed6921ebcaf0f [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 <base/logging.h>
10#include <dbus-c++/glib-integration.h>
11#include <dbus-c++/util.h>
12
Chris Masoned7732e42011-05-20 11:08:56 -070013#include "shill/device_dbus_adaptor.h"
Chris Masonec6c6c132011-06-30 11:29:52 -070014#include "shill/ipconfig_dbus_adaptor.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) {
Chris Masoned0ceb8c2011-06-02 10:05:39 -070027 return new(std::nothrow) DeviceDBusAdaptor(connection_.get(), device);
Paul Stewart75897df2011-04-27 09:05:53 -070028}
29
Chris Masonec6c6c132011-06-30 11:29:52 -070030IPConfigAdaptorInterface *DBusControl::CreateIPConfigAdaptor(IPConfig *config) {
Chris Masonec6c6c132011-06-30 11:29:52 -070031 return new(std::nothrow) IPConfigDBusAdaptor(connection_.get(), config);
32}
33
34ManagerAdaptorInterface *DBusControl::CreateManagerAdaptor(Manager *manager) {
Chris Masonec6c6c132011-06-30 11:29:52 -070035 return new(std::nothrow) ManagerDBusAdaptor(connection_.get(), manager);
36}
37
Chris Masone52cd19b2011-06-29 17:23:04 -070038ProfileAdaptorInterface *DBusControl::CreateProfileAdaptor(Profile *profile) {
Chris Masone52cd19b2011-06-29 17:23:04 -070039 return new(std::nothrow) ProfileDBusAdaptor(connection_.get(), profile);
40}
41
Darin Petkova9b1fed2012-02-29 11:49:05 +010042RPCTaskAdaptorInterface *DBusControl::CreateRPCTaskAdaptor(RPCTask *task) {
Darin Petkova9b1fed2012-02-29 11:49:05 +010043 return new(std::nothrow) RPCTaskDBusAdaptor(connection_.get(), task);
44}
45
Chris Masonec6c6c132011-06-30 11:29:52 -070046ServiceAdaptorInterface *DBusControl::CreateServiceAdaptor(Service *service) {
Chris Masonec6c6c132011-06-30 11:29:52 -070047 return new(std::nothrow) ServiceDBusAdaptor(connection_.get(), service);
48}
49
Darin Petkovd1b715b2011-06-02 21:21:22 -070050void DBusControl::Init() {
51 CHECK(!connection_.get());
52 dispatcher_.reset(new(std::nothrow) DBus::Glib::BusDispatcher());
53 CHECK(dispatcher_.get()) << "Failed to create a dbus-dispatcher";
54 DBus::default_dispatcher = dispatcher_.get();
55 dispatcher_->attach(NULL);
56 connection_.reset(new DBus::Connection(DBus::Connection::SystemBus()));
mukesh agrawald1511fe2012-03-14 17:12:27 -070057 connection_->request_name(SHILL_INTERFACE);
Chris Masoned7732e42011-05-20 11:08:56 -070058}
Paul Stewart75897df2011-04-27 09:05:53 -070059
60} // namespace shill