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 | #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 | |
| 13 | namespace DBus { |
| 14 | class Connection; |
| 15 | namespace Glib { |
| 16 | class BusDispatcher; |
| 17 | } // namespace Glib |
| 18 | } // namespace DBus |
| 19 | |
| 20 | namespace shill { |
| 21 | |
| 22 | class SharedDBusConnection { |
| 23 | public: |
| 24 | ~SharedDBusConnection() = default; |
| 25 | |
| 26 | // Since this is a singleton, use SharedDBusConnection::GetInstance()->Foo(). |
| 27 | static SharedDBusConnection *GetInstance(); |
| 28 | |
| 29 | void Init(); |
| 30 | |
| 31 | DBus::Connection *GetConnection(); |
| 32 | |
| 33 | protected: |
| 34 | SharedDBusConnection() = default; |
| 35 | |
| 36 | private: |
| 37 | friend struct base::DefaultLazyInstanceTraits<SharedDBusConnection>; |
| 38 | |
| 39 | std::unique_ptr<DBus::Glib::BusDispatcher> dispatcher_; |
| 40 | std::unique_ptr<DBus::Connection> connection_; |
| 41 | |
| 42 | DISALLOW_COPY_AND_ASSIGN(SharedDBusConnection); |
| 43 | }; |
| 44 | |
| 45 | } // namespace shill |
| 46 | |
| 47 | #endif // SHILL_SHARED_DBUS_CONNECTION_H_ |