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 | |
Paul Stewart | 04f00c6 | 2015-01-08 15:59:10 -0800 | [diff] [blame^] | 31 | // Returns a DBus connection that may be attached to a name instance. |
| 32 | // This is useful for adaptor instances which handle incoming method calls. |
| 33 | DBus::Connection *GetAdaptorConnection(); |
| 34 | |
| 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. |
| 38 | DBus::Connection *GetProxyConnection(); |
Paul Stewart | 8dc5e7b | 2014-12-11 19:24:50 -0800 | [diff] [blame] | 39 | |
| 40 | protected: |
| 41 | SharedDBusConnection() = default; |
| 42 | |
| 43 | private: |
| 44 | friend struct base::DefaultLazyInstanceTraits<SharedDBusConnection>; |
| 45 | |
| 46 | std::unique_ptr<DBus::Glib::BusDispatcher> dispatcher_; |
Paul Stewart | 04f00c6 | 2015-01-08 15:59:10 -0800 | [diff] [blame^] | 47 | std::unique_ptr<DBus::Connection> adaptor_connection_; |
| 48 | std::unique_ptr<DBus::Connection> proxy_connection_; |
Paul Stewart | 8dc5e7b | 2014-12-11 19:24:50 -0800 | [diff] [blame] | 49 | |
| 50 | DISALLOW_COPY_AND_ASSIGN(SharedDBusConnection); |
| 51 | }; |
| 52 | |
| 53 | } // namespace shill |
| 54 | |
| 55 | #endif // SHILL_SHARED_DBUS_CONNECTION_H_ |