bluez_dbus_thread_manager.h 1.6 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455
  1. // Copyright (c) 2012 The Chromium 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. #ifndef DEVICE_BLUETOOTH_DBUS_BLUEZ_DBUS_THREAD_MANAGER_H_
  5. #define DEVICE_BLUETOOTH_DBUS_BLUEZ_DBUS_THREAD_MANAGER_H_
  6. #include <memory>
  7. #include "base/callback.h"
  8. #include "base/memory/ref_counted.h"
  9. #include "device/bluetooth/bluetooth_export.h"
  10. namespace base {
  11. class Thread;
  12. } // namespace base
  13. namespace dbus {
  14. class Bus;
  15. } // namespace dbus
  16. namespace bluez {
  17. // BluezDBusThreadManager manages the D-Bus thread, the thread dedicated to
  18. // handling asynchronous D-Bus operations.
  19. class DEVICE_BLUETOOTH_EXPORT BluezDBusThreadManager {
  20. public:
  21. // Sets the global instance. Must be called before any calls to Get().
  22. // We explicitly initialize and shut down the global object, rather than
  23. // making it a Singleton, to ensure clean startup and shutdown.
  24. static void Initialize();
  25. // Destroys the global instance.
  26. static void Shutdown();
  27. // Gets the global instance. Initialize() must be called first.
  28. static BluezDBusThreadManager* Get();
  29. BluezDBusThreadManager(const BluezDBusThreadManager&) = delete;
  30. BluezDBusThreadManager& operator=(const BluezDBusThreadManager&) = delete;
  31. // Returns various D-Bus bus instances, owned by BluezDBusThreadManager.
  32. dbus::Bus* GetSystemBus();
  33. private:
  34. explicit BluezDBusThreadManager();
  35. ~BluezDBusThreadManager();
  36. std::unique_ptr<base::Thread> dbus_thread_;
  37. scoped_refptr<dbus::Bus> system_bus_;
  38. };
  39. } // namespace bluez
  40. #endif // DEVICE_BLUETOOTH_DBUS_BLUEZ_DBUS_THREAD_MANAGER_H_