Paul Stewart | 75897df | 2011-04-27 09:05:53 -0700 | [diff] [blame] | 1 | // Copyright (c) 2011 The Chromium OS 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 | |
Paul Stewart | 75897df | 2011-04-27 09:05:53 -0700 | [diff] [blame] | 5 | #include <string> |
| 6 | |
Chris Masone | d7732e4 | 2011-05-20 11:08:56 -0700 | [diff] [blame] | 7 | #include <base/logging.h> |
| 8 | #include <dbus-c++/glib-integration.h> |
| 9 | #include <dbus-c++/util.h> |
| 10 | |
Paul Stewart | 75897df | 2011-04-27 09:05:53 -0700 | [diff] [blame] | 11 | #include "shill/dbus_control.h" |
Chris Masone | d7732e4 | 2011-05-20 11:08:56 -0700 | [diff] [blame] | 12 | #include "shill/device_dbus_adaptor.h" |
| 13 | #include "shill/manager_dbus_adaptor.h" |
| 14 | #include "shill/service_dbus_adaptor.h" |
Paul Stewart | 75897df | 2011-04-27 09:05:53 -0700 | [diff] [blame] | 15 | |
| 16 | namespace shill { |
Chris Masone | d7732e4 | 2011-05-20 11:08:56 -0700 | [diff] [blame] | 17 | DBusControl::DBusControl() {} |
Paul Stewart | 75897df | 2011-04-27 09:05:53 -0700 | [diff] [blame] | 18 | |
Chris Masone | d7732e4 | 2011-05-20 11:08:56 -0700 | [diff] [blame] | 19 | DBusControl::~DBusControl() {} |
Paul Stewart | 75897df | 2011-04-27 09:05:53 -0700 | [diff] [blame] | 20 | |
Chris Masone | 413a319 | 2011-05-09 17:10:05 -0700 | [diff] [blame] | 21 | ManagerAdaptorInterface *DBusControl::CreateManagerAdaptor(Manager *manager) { |
Paul Stewart | 28fbfdf | 2011-05-31 09:37:38 -0700 | [diff] [blame] | 22 | connection_->request_name(ManagerDBusAdaptor::kInterfaceName); |
Chris Masone | d0ceb8c | 2011-06-02 10:05:39 -0700 | [diff] [blame] | 23 | return new(std::nothrow) ManagerDBusAdaptor(connection_.get(), manager); |
Paul Stewart | 75897df | 2011-04-27 09:05:53 -0700 | [diff] [blame] | 24 | } |
| 25 | |
Chris Masone | 413a319 | 2011-05-09 17:10:05 -0700 | [diff] [blame] | 26 | ServiceAdaptorInterface *DBusControl::CreateServiceAdaptor(Service *service) { |
Paul Stewart | 28fbfdf | 2011-05-31 09:37:38 -0700 | [diff] [blame] | 27 | connection_->request_name(ServiceDBusAdaptor::kInterfaceName); |
Chris Masone | d0ceb8c | 2011-06-02 10:05:39 -0700 | [diff] [blame] | 28 | return new(std::nothrow) ServiceDBusAdaptor(connection_.get(), service); |
Paul Stewart | 75897df | 2011-04-27 09:05:53 -0700 | [diff] [blame] | 29 | } |
| 30 | |
Chris Masone | 413a319 | 2011-05-09 17:10:05 -0700 | [diff] [blame] | 31 | DeviceAdaptorInterface *DBusControl::CreateDeviceAdaptor(Device *device) { |
Paul Stewart | 28fbfdf | 2011-05-31 09:37:38 -0700 | [diff] [blame] | 32 | connection_->request_name(DeviceDBusAdaptor::kInterfaceName); |
Chris Masone | d0ceb8c | 2011-06-02 10:05:39 -0700 | [diff] [blame] | 33 | return new(std::nothrow) DeviceDBusAdaptor(connection_.get(), device); |
Paul Stewart | 75897df | 2011-04-27 09:05:53 -0700 | [diff] [blame] | 34 | } |
| 35 | |
Darin Petkov | d1b715b | 2011-06-02 21:21:22 -0700 | [diff] [blame] | 36 | void DBusControl::Init() { |
| 37 | CHECK(!connection_.get()); |
| 38 | dispatcher_.reset(new(std::nothrow) DBus::Glib::BusDispatcher()); |
| 39 | CHECK(dispatcher_.get()) << "Failed to create a dbus-dispatcher"; |
| 40 | DBus::default_dispatcher = dispatcher_.get(); |
| 41 | dispatcher_->attach(NULL); |
| 42 | connection_.reset(new DBus::Connection(DBus::Connection::SystemBus())); |
Chris Masone | d7732e4 | 2011-05-20 11:08:56 -0700 | [diff] [blame] | 43 | } |
Paul Stewart | 75897df | 2011-04-27 09:05:53 -0700 | [diff] [blame] | 44 | |
| 45 | } // namespace shill |