blob: 86c2d8c53bb850d6b5a26962c8a39721e4001db5 [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
17SharedDBusConnection *SharedDBusConnection::GetInstance() {
18 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 Stewart04f00c62015-01-08 15:59:10 -080031DBus::Connection *SharedDBusConnection::GetAdaptorConnection() {
32 CHECK(adaptor_connection_.get());
33 return adaptor_connection_.get();
34}
35
36DBus::Connection *SharedDBusConnection::GetProxyConnection() {
37 CHECK(proxy_connection_.get());
38 return proxy_connection_.get();
Paul Stewart8dc5e7b2014-12-11 19:24:50 -080039}
40
41} // namespace shill