Paul Stewart | 8dc5e7b | 2014-12-11 19:24:50 -0800 | [diff] [blame] | 1 | // Copyright 2015 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 | |
| 5 | #include "shill/shared_dbus_connection.h" |
| 6 | |
| 7 | #include <dbus-c++/glib-integration.h> |
| 8 | #include <dbus-c++/util.h> |
| 9 | |
| 10 | namespace shill { |
| 11 | |
| 12 | namespace { |
| 13 | base::LazyInstance<SharedDBusConnection> g_shared_dbus_connection = |
| 14 | LAZY_INSTANCE_INITIALIZER; |
| 15 | } // namespace |
| 16 | |
Paul Stewart | 1a212a6 | 2015-06-16 13:13:10 -0700 | [diff] [blame] | 17 | SharedDBusConnection* SharedDBusConnection::GetInstance() { |
Paul Stewart | 8dc5e7b | 2014-12-11 19:24:50 -0800 | [diff] [blame] | 18 | return g_shared_dbus_connection.Pointer(); |
| 19 | } |
| 20 | |
| 21 | void SharedDBusConnection::Init() { |
| 22 | dispatcher_.reset(new(std::nothrow) DBus::Glib::BusDispatcher()); |
| 23 | CHECK(dispatcher_.get()) << "Failed to create a dbus-dispatcher"; |
| 24 | DBus::default_dispatcher = dispatcher_.get(); |
| 25 | dispatcher_->attach(nullptr); |
Paul Stewart | 04f00c6 | 2015-01-08 15:59:10 -0800 | [diff] [blame] | 26 | adaptor_connection_.reset(new DBus::Connection( |
| 27 | DBus::Connection::SystemBus())); |
| 28 | proxy_connection_.reset(new DBus::Connection(DBus::Connection::SystemBus())); |
Paul Stewart | 8dc5e7b | 2014-12-11 19:24:50 -0800 | [diff] [blame] | 29 | } |
| 30 | |
Paul Stewart | 1a212a6 | 2015-06-16 13:13:10 -0700 | [diff] [blame] | 31 | DBus::Connection* SharedDBusConnection::GetAdaptorConnection() { |
Paul Stewart | 04f00c6 | 2015-01-08 15:59:10 -0800 | [diff] [blame] | 32 | CHECK(adaptor_connection_.get()); |
| 33 | return adaptor_connection_.get(); |
| 34 | } |
| 35 | |
Paul Stewart | 1a212a6 | 2015-06-16 13:13:10 -0700 | [diff] [blame] | 36 | DBus::Connection* SharedDBusConnection::GetProxyConnection() { |
Paul Stewart | 04f00c6 | 2015-01-08 15:59:10 -0800 | [diff] [blame] | 37 | CHECK(proxy_connection_.get()); |
| 38 | return proxy_connection_.get(); |
Paul Stewart | 8dc5e7b | 2014-12-11 19:24:50 -0800 | [diff] [blame] | 39 | } |
| 40 | |
| 41 | } // namespace shill |