blob: 393420151eada84e4a840e4b46a41476a411866e [file] [log] [blame]
Paul Stewart8dc5e7b2014-12-11 19:24:50 -08001// 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
10namespace shill {
11
12namespace {
13base::LazyInstance<SharedDBusConnection> g_shared_dbus_connection =
14 LAZY_INSTANCE_INITIALIZER;
15} // namespace
16
Paul Stewart1a212a62015-06-16 13:13:10 -070017SharedDBusConnection* SharedDBusConnection::GetInstance() {
Paul Stewart8dc5e7b2014-12-11 19:24:50 -080018 return g_shared_dbus_connection.Pointer();
19}
20
21void 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 Stewart04f00c62015-01-08 15:59:10 -080026 adaptor_connection_.reset(new DBus::Connection(
27 DBus::Connection::SystemBus()));
28 proxy_connection_.reset(new DBus::Connection(DBus::Connection::SystemBus()));
Paul Stewart8dc5e7b2014-12-11 19:24:50 -080029}
30
Paul Stewart1a212a62015-06-16 13:13:10 -070031DBus::Connection* SharedDBusConnection::GetAdaptorConnection() {
Paul Stewart04f00c62015-01-08 15:59:10 -080032 CHECK(adaptor_connection_.get());
33 return adaptor_connection_.get();
34}
35
Paul Stewart1a212a62015-06-16 13:13:10 -070036DBus::Connection* SharedDBusConnection::GetProxyConnection() {
Paul Stewart04f00c62015-01-08 15:59:10 -080037 CHECK(proxy_connection_.get());
38 return proxy_connection_.get();
Paul Stewart8dc5e7b2014-12-11 19:24:50 -080039}
40
41} // namespace shill