1 // Copyright 2016 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 LIBBRILLO_BRILLO_DBUS_DBUS_CONNECTION_H_ 6 #define LIBBRILLO_BRILLO_DBUS_DBUS_CONNECTION_H_ 7 8 #include <base/memory/ref_counted.h> 9 #include <base/time/time.h> 10 #include <dbus/bus.h> 11 12 #include <brillo/brillo_export.h> 13 14 namespace brillo { 15 16 // DBusConnection adds D-Bus support to Daemon. 17 class BRILLO_EXPORT DBusConnection final { 18 public: 19 DBusConnection(); 20 ~DBusConnection(); 21 22 // Instantiates dbus::Bus and establishes a D-Bus connection. Returns a 23 // reference to the connected bus, or an empty pointer in case of error. 24 scoped_refptr<dbus::Bus> Connect(); 25 26 // Instantiates dbus::Bus and tries to establish a D-Bus connection for up to 27 // |timeout|. If the connection can't be established after the timeout, fails 28 // returning an empty pointer. 29 scoped_refptr<dbus::Bus> ConnectWithTimeout(base::TimeDelta timeout); 30 31 private: 32 scoped_refptr<dbus::Bus> bus_; 33 34 private: 35 DISALLOW_COPY_AND_ASSIGN(DBusConnection); 36 }; 37 38 } // namespace brillo 39 40 #endif // LIBBRILLO_BRILLO_DAEMONS_DBUS_DAEMON_H_ 41