blob: ee7e961cb57cb3196e2ce5f1cf475cccaf5f79a2 [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#ifndef SHILL_SHARED_DBUS_CONNECTION_H_
6#define SHILL_SHARED_DBUS_CONNECTION_H_
7
8#include <memory>
9
10#include <base/lazy_instance.h>
11#include <base/macros.h>
12
13namespace DBus {
14class Connection;
15namespace Glib {
16class BusDispatcher;
17} // namespace Glib
18} // namespace DBus
19
20namespace shill {
21
22class SharedDBusConnection {
23 public:
24 ~SharedDBusConnection() = default;
25
26 // Since this is a singleton, use SharedDBusConnection::GetInstance()->Foo().
Paul Stewart1a212a62015-06-16 13:13:10 -070027 static SharedDBusConnection* GetInstance();
Paul Stewart8dc5e7b2014-12-11 19:24:50 -080028
29 void Init();
30
Paul Stewart04f00c62015-01-08 15:59:10 -080031 // Returns a DBus connection that may be attached to a name instance.
32 // This is useful for adaptor instances which handle incoming method calls.
Paul Stewart1a212a62015-06-16 13:13:10 -070033 DBus::Connection* GetAdaptorConnection();
Paul Stewart04f00c62015-01-08 15:59:10 -080034
35 // Returns a DBus connection that is not associated with an acquired name.
36 // This is useful for proxy instances which handle incoming signals and
37 // outgoing method calls.
Paul Stewart1a212a62015-06-16 13:13:10 -070038 DBus::Connection* GetProxyConnection();
Paul Stewart8dc5e7b2014-12-11 19:24:50 -080039
40 protected:
41 SharedDBusConnection() = default;
42
43 private:
44 friend struct base::DefaultLazyInstanceTraits<SharedDBusConnection>;
45
46 std::unique_ptr<DBus::Glib::BusDispatcher> dispatcher_;
Paul Stewart04f00c62015-01-08 15:59:10 -080047 std::unique_ptr<DBus::Connection> adaptor_connection_;
48 std::unique_ptr<DBus::Connection> proxy_connection_;
Paul Stewart8dc5e7b2014-12-11 19:24:50 -080049
50 DISALLOW_COPY_AND_ASSIGN(SharedDBusConnection);
51};
52
53} // namespace shill
54
55#endif // SHILL_SHARED_DBUS_CONNECTION_H_