1*1a96fba6SXin Li // Copyright 2016 The Chromium OS Authors. All rights reserved. 2*1a96fba6SXin Li // Use of this source code is governed by a BSD-style license that can be 3*1a96fba6SXin Li // found in the LICENSE file. 4*1a96fba6SXin Li 5*1a96fba6SXin Li #ifndef LIBBRILLO_BRILLO_DBUS_DBUS_CONNECTION_H_ 6*1a96fba6SXin Li #define LIBBRILLO_BRILLO_DBUS_DBUS_CONNECTION_H_ 7*1a96fba6SXin Li 8*1a96fba6SXin Li #include <base/memory/ref_counted.h> 9*1a96fba6SXin Li #include <base/time/time.h> 10*1a96fba6SXin Li #include <dbus/bus.h> 11*1a96fba6SXin Li 12*1a96fba6SXin Li #include <brillo/brillo_export.h> 13*1a96fba6SXin Li 14*1a96fba6SXin Li namespace brillo { 15*1a96fba6SXin Li 16*1a96fba6SXin Li // DBusConnection adds D-Bus support to Daemon. 17*1a96fba6SXin Li class BRILLO_EXPORT DBusConnection final { 18*1a96fba6SXin Li public: 19*1a96fba6SXin Li DBusConnection(); 20*1a96fba6SXin Li ~DBusConnection(); 21*1a96fba6SXin Li 22*1a96fba6SXin Li // Instantiates dbus::Bus and establishes a D-Bus connection. Returns a 23*1a96fba6SXin Li // reference to the connected bus, or an empty pointer in case of error. 24*1a96fba6SXin Li scoped_refptr<::dbus::Bus> Connect(); 25*1a96fba6SXin Li 26*1a96fba6SXin Li // Instantiates dbus::Bus and tries to establish a D-Bus connection for up to 27*1a96fba6SXin Li // |timeout|. If the connection can't be established after the timeout, fails 28*1a96fba6SXin Li // returning an empty pointer. 29*1a96fba6SXin Li scoped_refptr<::dbus::Bus> ConnectWithTimeout(base::TimeDelta timeout); 30*1a96fba6SXin Li 31*1a96fba6SXin Li private: 32*1a96fba6SXin Li scoped_refptr<::dbus::Bus> bus_; 33*1a96fba6SXin Li 34*1a96fba6SXin Li private: 35*1a96fba6SXin Li DISALLOW_COPY_AND_ASSIGN(DBusConnection); 36*1a96fba6SXin Li }; 37*1a96fba6SXin Li 38*1a96fba6SXin Li } // namespace brillo 39*1a96fba6SXin Li 40*1a96fba6SXin Li #endif // LIBBRILLO_BRILLO_DBUS_DBUS_CONNECTION_H_ 41